opencode-github-sync 3.0.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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -0
  3. package/README.zh-CN.md +332 -0
  4. package/dist/cli/index.d.ts +3 -0
  5. package/dist/cli/index.d.ts.map +1 -0
  6. package/dist/cli/index.js +334 -0
  7. package/dist/cli/index.js.map +1 -0
  8. package/dist/cli/render.d.ts +45 -0
  9. package/dist/cli/render.d.ts.map +1 -0
  10. package/dist/cli/render.js +167 -0
  11. package/dist/cli/render.js.map +1 -0
  12. package/dist/cli/theme.d.ts +45 -0
  13. package/dist/cli/theme.d.ts.map +1 -0
  14. package/dist/cli/theme.js +88 -0
  15. package/dist/cli/theme.js.map +1 -0
  16. package/dist/core/fsx.d.ts +81 -0
  17. package/dist/core/fsx.d.ts.map +1 -0
  18. package/dist/core/fsx.js +353 -0
  19. package/dist/core/fsx.js.map +1 -0
  20. package/dist/core/git.d.ts +48 -0
  21. package/dist/core/git.d.ts.map +1 -0
  22. package/dist/core/git.js +133 -0
  23. package/dist/core/git.js.map +1 -0
  24. package/dist/core/host.d.ts +20 -0
  25. package/dist/core/host.d.ts.map +1 -0
  26. package/dist/core/host.js +50 -0
  27. package/dist/core/host.js.map +1 -0
  28. package/dist/core/index.d.ts +16 -0
  29. package/dist/core/index.d.ts.map +1 -0
  30. package/dist/core/index.js +16 -0
  31. package/dist/core/index.js.map +1 -0
  32. package/dist/core/jsonc.d.ts +20 -0
  33. package/dist/core/jsonc.d.ts.map +1 -0
  34. package/dist/core/jsonc.js +115 -0
  35. package/dist/core/jsonc.js.map +1 -0
  36. package/dist/core/lock.d.ts +14 -0
  37. package/dist/core/lock.d.ts.map +1 -0
  38. package/dist/core/lock.js +111 -0
  39. package/dist/core/lock.js.map +1 -0
  40. package/dist/core/overrides.d.ts +30 -0
  41. package/dist/core/overrides.d.ts.map +1 -0
  42. package/dist/core/overrides.js +126 -0
  43. package/dist/core/overrides.js.map +1 -0
  44. package/dist/core/paths.d.ts +36 -0
  45. package/dist/core/paths.d.ts.map +1 -0
  46. package/dist/core/paths.js +55 -0
  47. package/dist/core/paths.js.map +1 -0
  48. package/dist/core/repo.d.ts +57 -0
  49. package/dist/core/repo.d.ts.map +1 -0
  50. package/dist/core/repo.js +184 -0
  51. package/dist/core/repo.js.map +1 -0
  52. package/dist/core/reporter.d.ts +50 -0
  53. package/dist/core/reporter.d.ts.map +1 -0
  54. package/dist/core/reporter.js +63 -0
  55. package/dist/core/reporter.js.map +1 -0
  56. package/dist/core/sessions.d.ts +61 -0
  57. package/dist/core/sessions.d.ts.map +1 -0
  58. package/dist/core/sessions.js +321 -0
  59. package/dist/core/sessions.js.map +1 -0
  60. package/dist/core/settings.d.ts +59 -0
  61. package/dist/core/settings.d.ts.map +1 -0
  62. package/dist/core/settings.js +120 -0
  63. package/dist/core/settings.js.map +1 -0
  64. package/dist/core/setup.d.ts +48 -0
  65. package/dist/core/setup.d.ts.map +1 -0
  66. package/dist/core/setup.js +186 -0
  67. package/dist/core/setup.js.map +1 -0
  68. package/dist/core/sqlite.d.ts +37 -0
  69. package/dist/core/sqlite.d.ts.map +1 -0
  70. package/dist/core/sqlite.js +106 -0
  71. package/dist/core/sqlite.js.map +1 -0
  72. package/dist/core/stage.d.ts +44 -0
  73. package/dist/core/stage.d.ts.map +1 -0
  74. package/dist/core/stage.js +297 -0
  75. package/dist/core/stage.js.map +1 -0
  76. package/dist/core/sync.d.ts +50 -0
  77. package/dist/core/sync.d.ts.map +1 -0
  78. package/dist/core/sync.js +360 -0
  79. package/dist/core/sync.js.map +1 -0
  80. package/dist/plugin/index.d.ts +31 -0
  81. package/dist/plugin/index.d.ts.map +1 -0
  82. package/dist/plugin/index.js +132 -0
  83. package/dist/plugin/index.js.map +1 -0
  84. package/package.json +67 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 doomsday616
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,353 @@
1
+ <p align="center">
2
+ <img src="docs/banner.svg" alt="opencode-github-sync" width="820">
3
+ </p>
4
+
5
+ <p align="center">
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="./LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT-bb9af7?style=flat-square&labelColor=1a1e2b"></a>
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
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="./README.zh-CN.md">简体中文</a>
14
+ &nbsp;·&nbsp;
15
+ <a href="#quick-start">Quick start</a>
16
+ &nbsp;·&nbsp;
17
+ <a href="#per-machine-overrides">Overrides</a>
18
+ &nbsp;·&nbsp;
19
+ <a href="#session-sync">Sessions</a>
20
+ &nbsp;·&nbsp;
21
+ <a href="#command-reference">Commands</a>
22
+ </p>
23
+
24
+ ---
25
+
26
+ You use OpenCode on more than one machine. Your config, agents, commands, skills
27
+ and MCP servers live on whichever one you touched last.
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 |
54
+
55
+ Plus the boring things that turn out to matter:
56
+
57
+ - **Symlinks are refused, not followed.** No copying files out of the machine by accident, no junction turning a delete into the wrong delete.
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.
63
+
64
+ ---
65
+
66
+ ## Install
67
+
68
+ ### As an OpenCode plugin
69
+
70
+ ```jsonc
71
+ // ~/.config/opencode/opencode.json
72
+ {
73
+ "$schema": "https://opencode.ai/config.json",
74
+ "plugin": ["opencode-github-sync"]
75
+ }
76
+ ```
77
+
78
+ OpenCode installs it on the next start. The plugin adds a pull on startup, an
79
+ optional push when a session goes idle, and an `opencode_sync` tool so you can
80
+ just ask for a sync in plain language.
81
+
82
+ ### As a CLI
83
+
84
+ ```bash
85
+ npm install -g opencode-github-sync
86
+ ```
87
+
88
+ Keep the CLI even if you use the plugin. A plugin cannot fix the configuration
89
+ that stops OpenCode from loading the plugin.
90
+
91
+ **Requirements** — git, and [`gh`](https://cli.github.com) for automatic setup.
92
+ Node 18+ for config sync; Node 22.5+ or Bun for [session sync](#session-sync).
93
+
94
+ ---
95
+
96
+ ## Quick start
97
+
98
+ ### First machine
99
+
100
+ ```bash
101
+ opencode-sync init # → <you>/my-opencode-config
102
+ opencode-sync init team-config # custom name
103
+ opencode-sync init my-org/shared # inside an organisation
104
+ opencode-sync push
105
+ ```
106
+
107
+ `init` creates a **private** repository, writes
108
+ `~/.config/opencode/opencode-sync.jsonc`, and leaves an empty overrides file
109
+ ready for you.
110
+
111
+ ### Every other machine
112
+
113
+ ```bash
114
+ opencode-sync link doomsday616/my-opencode-config
115
+ opencode-sync pull
116
+ ```
117
+
118
+ Then restart OpenCode.
119
+
120
+ ### Day to day
121
+
122
+ ```bash
123
+ opencode-sync push # share what changed here
124
+ opencode-sync pull # take what changed elsewhere
125
+ opencode-sync status # what is in sync, what is not
126
+ ```
127
+
128
+ ---
129
+
130
+ ## What gets synced
131
+
132
+ <p align="center">
133
+ <img src="docs/architecture.svg" alt="Architecture" width="880">
134
+ </p>
135
+
136
+ | Source | In the repo | Contents |
137
+ | -------------------------- | ----------- | -------------------------------------------- |
138
+ | `~/.config/opencode/` | repo root | config, agents, commands, skills, themes, MCP |
139
+ | `~/.local/share/opencode/` | `_data/` | project metadata, optional credentials |
140
+ | `~/.local/state/opencode/` | `_state/` | frecency, model cache, prompt history |
141
+ | `~/.agents/skills/` | `_agents/` | skills installed by the `skills` CLI |
142
+ | selected sessions | `_sessions/`| one gzipped shard per session |
143
+
144
+ **Never synced:** `opencode.db` and its journals, tool output, snapshots, logs,
145
+ and your local settings and overrides files.
146
+
147
+ Add anything else with `extraPaths`:
148
+
149
+ ```jsonc
150
+ {
151
+ "extraPaths": [".tavily", ".config/gh/config.yml"]
152
+ }
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Per-machine overrides
158
+
159
+ A synced repository makes every machine identical. That is exactly wrong for the
160
+ settings that are genuinely machine-specific: a corporate proxy, a local
161
+ toolchain path, an MCP server that only exists on one box.
162
+
163
+ Put those in `~/.config/opencode/opencode-sync.overrides.jsonc`:
164
+
165
+ ```jsonc
166
+ {
167
+ "model": "github-copilot/claude-sonnet-4",
168
+ "mcp": {
169
+ "playwright": { "enabled": true }
170
+ }
171
+ }
172
+ ```
173
+
174
+ ```
175
+ repo opencode.jsonc shared baseline, committed
176
+ + overrides.jsonc this machine only, never committed
177
+ ───────────────────────── deep merge
178
+ = effective opencode.jsonc what OpenCode actually reads
179
+ ```
180
+
181
+ Merge rules: objects merge key by key, arrays and scalars replace, `null`
182
+ deletes a key.
183
+
184
+ The half that other tools get wrong is **push**. Because the effective file is
185
+ what sits on disk, a naive push uploads your overrides to everyone. Here, any
186
+ key the overrides file claims is restored to the value the repository already
187
+ had before committing — so an overridden key is invisible to sync in both
188
+ directions, and your machine keeps its own settings the whole time.
189
+
190
+ > With no overrides file the config is copied byte for byte and your comments
191
+ > and formatting are untouched. The structural rewrite only happens once you
192
+ > actually opt in.
193
+
194
+ ---
195
+
196
+ ## Session sync
197
+
198
+ Off by default. Turn it on only for a private repository — conversations are
199
+ private data.
200
+
201
+ ```bash
202
+ opencode-sync sessions enable
203
+ opencode-sync sessions list
204
+ opencode-sync sessions include ses_065cad1caffeN3lf1RgLZno30 # pin one forever
205
+ opencode-sync sessions exclude ses_0ba19b4e7ffeMbSmWYi3Nj6xfZ # never sync this one
206
+ ```
207
+
208
+ ### Why not just commit the database
209
+
210
+ A real OpenCode database reaches several gigabytes, almost all of it tool output
211
+ inside `part.data`. Git cannot delta-compress it, GitHub's LFS free tier is one
212
+ gigabyte, and copying a live database alongside its write-ahead log can capture
213
+ a torn state that only shows up much later.
214
+
215
+ So sessions are exported **one at a time**. Each becomes an independent gzipped
216
+ JSON shard holding its own rows plus the project and workspace rows it needs:
217
+
218
+ - **No large files.** Shards are small and compress well.
219
+ - **Conflicts isolate themselves.** Two machines working on different sessions
220
+ touch different files, so git merges them with no special handling. The only
221
+ real conflict is one session edited in two places, and there the newer
222
+ `time_updated` wins — an in-progress conversation is never clobbered by a
223
+ stale copy.
224
+ - **You choose what travels.** A time window, an explicit include list, a
225
+ project filter and a per-session size cap. Ancient sessions stay where they
226
+ are.
227
+
228
+ Import is an upsert inside a transaction, so a failure leaves your database
229
+ exactly as it was.
230
+
231
+ ```jsonc
232
+ {
233
+ "sessions": {
234
+ "enabled": true,
235
+ "days": 7, // only sessions touched this recently
236
+ "maxSessions": 50, // hard cap per push, newest first
237
+ "maxSessionBytes": 5242880, // skip any single runaway session
238
+ "include": [], // always sync these, whatever the window says
239
+ "exclude": [], // never sync these
240
+ "directories": [] // only sessions under these project directories
241
+ }
242
+ }
243
+ ```
244
+
245
+ > The internal `event` log is deliberately excluded. It is the largest table by
246
+ > row count and nothing about resuming a conversation depends on it.
247
+
248
+ ---
249
+
250
+ ## Command reference
251
+
252
+ | Command | What it does |
253
+ | ---------------------------------- | ------------------------------------------------ |
254
+ | `opencode-sync init [name]` | Create a private sync repository |
255
+ | `opencode-sync link <owner/repo>` | Point this machine at an existing one |
256
+ | `opencode-sync push` | Share this machine's configuration |
257
+ | `opencode-sync pull` | Apply the shared configuration |
258
+ | `opencode-sync status` | Show what is in sync and what is not |
259
+ | `opencode-sync sessions list` | Recent sessions and their ids |
260
+ | `opencode-sync sessions enable` | Turn selective session sync on |
261
+ | `opencode-sync sessions include` | Pin a session, ignoring the time window |
262
+ | `opencode-sync overrides` | Create/locate the per-machine patch |
263
+ | `opencode-sync config` | Print the current settings |
264
+
265
+ | Flag | Effect |
266
+ | ----------- | ----------------------------------------------- |
267
+ | `--force` | Overwrite the other side on conflict (confirmed) |
268
+ | `--dry-run` | Report what would change, write nothing |
269
+
270
+ | Environment variable | Effect |
271
+ | ---------------------------- | ---------------------------------------- |
272
+ | `OPENCODE_SYNC_HOST_ALIAS` | Name this machine in commit messages |
273
+ | `OPENCODE_SYNC_VERBOSE=1` | Full file list and stack traces |
274
+ | `NO_COLOR` | Disable colour |
275
+ | `SYNC_REMOTE_URL` | Override the repository URL |
276
+
277
+ ---
278
+
279
+ ## Settings
280
+
281
+ `~/.config/opencode/opencode-sync.jsonc` — never committed.
282
+
283
+ ```jsonc
284
+ {
285
+ "repo": { "owner": "you", "name": "my-opencode-config", "branch": "main" },
286
+
287
+ "machineAlias": "laptop", // optional; otherwise a stable pseudonym
288
+
289
+ "includeCredentials": false, // auth.json / account.json — private repos only
290
+ "includeSkills": true,
291
+ "includeState": true,
292
+ "extraPaths": [],
293
+
294
+ "sessions": { "enabled": false },
295
+
296
+ "autoPullOnStartup": true, // plugin only
297
+ "autoPushOnIdle": false // plugin only
298
+ }
299
+ ```
300
+
301
+ ---
302
+
303
+ ## When something goes wrong
304
+
305
+ **A pull conflicted with local edits.** The worktree is rolled back to a clean
306
+ state and your changes stay in the stash. The exact recovery commands are
307
+ printed. Nothing is lost.
308
+
309
+ ```bash
310
+ cd ~/.config/opencode
311
+ git stash list
312
+ git stash show -p stash@{0}
313
+ ```
314
+
315
+ **"This machine has N commits that were never pushed."** Deliberate — pulling
316
+ would destroy them. Run `opencode-sync push`, or `pull --force` to discard.
317
+
318
+ **Authentication failed.** `gh auth login -h github.com`. The token needs the
319
+ `repo` scope for private repositories.
320
+
321
+ **Session sync says no SQLite driver.** Node 22.5+ or Bun. Config sync is
322
+ unaffected.
323
+
324
+ **Everything is broken and OpenCode will not start.** This is why the CLI
325
+ exists:
326
+
327
+ ```bash
328
+ opencode-sync pull --force
329
+ ```
330
+
331
+ ---
332
+
333
+ ## Development
334
+
335
+ ```bash
336
+ npm install
337
+ npm run check # lint + typecheck + tests
338
+ npm run build
339
+ ```
340
+
341
+ The test suite runs against a real bare git repository on disk and simulates two
342
+ separate machines, so push, pull, force, rebase, stashing and the override
343
+ round-trip are all exercised end to end.
344
+
345
+ ---
346
+
347
+ ## License
348
+
349
+ [MIT](./LICENSE)
350
+
351
+ <p align="center">
352
+ <sub>If this saved you some time, a ⭐ is appreciated.</sub>
353
+ </p>