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.
- package/LICENSE +21 -0
- package/README.md +353 -0
- package/README.zh-CN.md +332 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +334 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/render.d.ts +45 -0
- package/dist/cli/render.d.ts.map +1 -0
- package/dist/cli/render.js +167 -0
- package/dist/cli/render.js.map +1 -0
- package/dist/cli/theme.d.ts +45 -0
- package/dist/cli/theme.d.ts.map +1 -0
- package/dist/cli/theme.js +88 -0
- package/dist/cli/theme.js.map +1 -0
- package/dist/core/fsx.d.ts +81 -0
- package/dist/core/fsx.d.ts.map +1 -0
- package/dist/core/fsx.js +353 -0
- package/dist/core/fsx.js.map +1 -0
- package/dist/core/git.d.ts +48 -0
- package/dist/core/git.d.ts.map +1 -0
- package/dist/core/git.js +133 -0
- package/dist/core/git.js.map +1 -0
- package/dist/core/host.d.ts +20 -0
- package/dist/core/host.d.ts.map +1 -0
- package/dist/core/host.js +50 -0
- package/dist/core/host.js.map +1 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +16 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/jsonc.d.ts +20 -0
- package/dist/core/jsonc.d.ts.map +1 -0
- package/dist/core/jsonc.js +115 -0
- package/dist/core/jsonc.js.map +1 -0
- package/dist/core/lock.d.ts +14 -0
- package/dist/core/lock.d.ts.map +1 -0
- package/dist/core/lock.js +111 -0
- package/dist/core/lock.js.map +1 -0
- package/dist/core/overrides.d.ts +30 -0
- package/dist/core/overrides.d.ts.map +1 -0
- package/dist/core/overrides.js +126 -0
- package/dist/core/overrides.js.map +1 -0
- package/dist/core/paths.d.ts +36 -0
- package/dist/core/paths.d.ts.map +1 -0
- package/dist/core/paths.js +55 -0
- package/dist/core/paths.js.map +1 -0
- package/dist/core/repo.d.ts +57 -0
- package/dist/core/repo.d.ts.map +1 -0
- package/dist/core/repo.js +184 -0
- package/dist/core/repo.js.map +1 -0
- package/dist/core/reporter.d.ts +50 -0
- package/dist/core/reporter.d.ts.map +1 -0
- package/dist/core/reporter.js +63 -0
- package/dist/core/reporter.js.map +1 -0
- package/dist/core/sessions.d.ts +61 -0
- package/dist/core/sessions.d.ts.map +1 -0
- package/dist/core/sessions.js +321 -0
- package/dist/core/sessions.js.map +1 -0
- package/dist/core/settings.d.ts +59 -0
- package/dist/core/settings.d.ts.map +1 -0
- package/dist/core/settings.js +120 -0
- package/dist/core/settings.js.map +1 -0
- package/dist/core/setup.d.ts +48 -0
- package/dist/core/setup.d.ts.map +1 -0
- package/dist/core/setup.js +186 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/core/sqlite.d.ts +37 -0
- package/dist/core/sqlite.d.ts.map +1 -0
- package/dist/core/sqlite.js +106 -0
- package/dist/core/sqlite.js.map +1 -0
- package/dist/core/stage.d.ts +44 -0
- package/dist/core/stage.d.ts.map +1 -0
- package/dist/core/stage.js +297 -0
- package/dist/core/stage.js.map +1 -0
- package/dist/core/sync.d.ts +50 -0
- package/dist/core/sync.d.ts.map +1 -0
- package/dist/core/sync.js +360 -0
- package/dist/core/sync.js.map +1 -0
- package/dist/plugin/index.d.ts +31 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +132 -0
- package/dist/plugin/index.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { git, isGitRepo, parseNameStatus, toGitError } from "./git.js";
|
|
4
|
+
import { commitMessage, hostAlias } from "./host.js";
|
|
5
|
+
import { applyOverrides } from "./overrides.js";
|
|
6
|
+
import { getDatabasePath, getRoots } from "./paths.js";
|
|
7
|
+
import { LOCAL_RUNTIME_PATHS, assertPushLanded, assertRemoteReachable, ensureRepo, excludePathspecs, isLocalRuntimePath, unstageLocalRuntimePaths, writeRepoMetadata, } from "./repo.js";
|
|
8
|
+
import { emptySummary, silentReporter, summarize, totalChanges, } from "./reporter.js";
|
|
9
|
+
import { exportSessions, importSessions } from "./sessions.js";
|
|
10
|
+
import { loadSettings, repoBranch, repoUrl } from "./settings.js";
|
|
11
|
+
import { sqliteAvailable } from "./sqlite.js";
|
|
12
|
+
import { createStageContext, normalizeConfigForRepo, prunePluginCache, stageIn, stageOut, } from "./stage.js";
|
|
13
|
+
class SyncError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "SyncError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function prepare(options) {
|
|
20
|
+
const roots = options.roots ?? getRoots();
|
|
21
|
+
const settings = options.settings ?? loadSettings(roots.config);
|
|
22
|
+
const remote = repoUrl(settings);
|
|
23
|
+
if (!remote) {
|
|
24
|
+
throw new SyncError("No sync repository configured.\n" +
|
|
25
|
+
"Run `opencode-sync init` to create one, or `opencode-sync link <owner/repo>` to use an existing one.");
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
root: roots.config,
|
|
29
|
+
branch: repoBranch(settings),
|
|
30
|
+
remote,
|
|
31
|
+
settings,
|
|
32
|
+
roots,
|
|
33
|
+
reporter: options.reporter ?? silentReporter,
|
|
34
|
+
force: options.force ?? false,
|
|
35
|
+
dryRun: options.dryRun ?? false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function toChangedFiles(result, excludeRuntime) {
|
|
39
|
+
return parseNameStatus(result.ok ? result.stdout : "")
|
|
40
|
+
.filter((entry) => !excludeRuntime || !isLocalRuntimePath(entry.path))
|
|
41
|
+
.map((entry) => ({ kind: entry.kind, path: entry.path }));
|
|
42
|
+
}
|
|
43
|
+
// ── Push ────────────────────────────────────────────────────────────────────
|
|
44
|
+
export async function push(options = {}) {
|
|
45
|
+
const ctx = prepare(options);
|
|
46
|
+
const { root, branch, reporter } = ctx;
|
|
47
|
+
if (!fs.existsSync(root))
|
|
48
|
+
throw new SyncError(`Config directory not found: ${root}`);
|
|
49
|
+
ensureRepo({ root, remote: ctx.remote, branch });
|
|
50
|
+
assertRemoteReachable(root, branch, "Push", true);
|
|
51
|
+
writeRepoMetadata(root);
|
|
52
|
+
try {
|
|
53
|
+
return await runPush(ctx);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
// Staging rewrites the on-disk config into its shareable form. Whatever
|
|
57
|
+
// happens next — success, conflict, network failure — this machine must be
|
|
58
|
+
// left with its own effective configuration, not the stripped one.
|
|
59
|
+
applyOverrides(ctx.roots.config);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function runPush(ctx) {
|
|
63
|
+
const { root, branch, reporter } = ctx;
|
|
64
|
+
reporter.step("Staging local files");
|
|
65
|
+
stageIn(createStageContext(root, ctx.settings, reporter, ctx.force, ctx.roots));
|
|
66
|
+
const sessions = await maybeExportSessions(ctx);
|
|
67
|
+
git(["add", "-A"], { cwd: root });
|
|
68
|
+
unstageLocalRuntimePaths(root);
|
|
69
|
+
const staged = git(["diff", "--cached", "--name-status"], { cwd: root });
|
|
70
|
+
const files = toChangedFiles(staged, true);
|
|
71
|
+
const summary = summarize(files);
|
|
72
|
+
if (files.length === 0) {
|
|
73
|
+
// No file changes, but a previous push may have failed after committing.
|
|
74
|
+
git(["fetch", "origin", branch], { cwd: root });
|
|
75
|
+
const ahead = countCommits(root, `origin/${branch}..HEAD`);
|
|
76
|
+
if (ahead > 0) {
|
|
77
|
+
if (ctx.dryRun) {
|
|
78
|
+
return done("push", false, summary, files, `${ahead} local commit(s) waiting to be pushed`, sessions);
|
|
79
|
+
}
|
|
80
|
+
reporter.step(`Pushing ${ahead} pending commit(s)`);
|
|
81
|
+
pushBranch(ctx, true);
|
|
82
|
+
return done("push", true, summary, files, `Pushed ${ahead} pending commit(s)`, sessions);
|
|
83
|
+
}
|
|
84
|
+
return done("push", false, summary, files, "Already up to date", sessions);
|
|
85
|
+
}
|
|
86
|
+
reporter.changes(summary, files);
|
|
87
|
+
if (ctx.dryRun) {
|
|
88
|
+
return done("push", true, summary, files, `${totalChanges(summary)} change(s) would be pushed`, sessions);
|
|
89
|
+
}
|
|
90
|
+
const alias = hostAlias(ctx.settings.machineAlias);
|
|
91
|
+
const commit = git(["commit", "-m", commitMessage("sync", alias)], { cwd: root });
|
|
92
|
+
if (!commit.ok)
|
|
93
|
+
throw toGitError("Commit", commit);
|
|
94
|
+
pushBranch(ctx, false);
|
|
95
|
+
return done("push", true, summary, files, `Pushed ${totalChanges(summary)} change(s)`, sessions);
|
|
96
|
+
}
|
|
97
|
+
function pushBranch(ctx, alreadyCommitted) {
|
|
98
|
+
const { root, branch, force, reporter } = ctx;
|
|
99
|
+
const hasRemoteBranch = git(["rev-parse", `origin/${branch}`], { cwd: root }).ok;
|
|
100
|
+
if (!hasRemoteBranch) {
|
|
101
|
+
const result = git(["push", "-u", "origin", branch], { cwd: root });
|
|
102
|
+
if (!result.ok)
|
|
103
|
+
throw toGitError("Push", result);
|
|
104
|
+
assertPushLanded(root, branch, "Push");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (force) {
|
|
108
|
+
// Refresh the tracking ref first. `--force-with-lease` compares against the
|
|
109
|
+
// local idea of the remote, so a stale ref makes it refuse the very
|
|
110
|
+
// overwrite the user explicitly asked for.
|
|
111
|
+
if (git(["fetch", "origin", branch], { cwd: root }).ok) {
|
|
112
|
+
const behind = countCommits(root, `HEAD..origin/${branch}`);
|
|
113
|
+
if (behind > 0) {
|
|
114
|
+
reporter.warn(`Overwriting ${behind} remote commit(s) that this machine does not have`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const result = git(["push", "--force-with-lease", "origin", branch], { cwd: root });
|
|
118
|
+
if (!result.ok)
|
|
119
|
+
throw toGitError("Force push", result);
|
|
120
|
+
assertPushLanded(root, branch, "Force push");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const rebase = git(["pull", "--rebase", "origin", branch], { cwd: root });
|
|
124
|
+
if (!rebase.ok) {
|
|
125
|
+
git(["rebase", "--abort"], { cwd: root });
|
|
126
|
+
throw new SyncError("The remote has changes that conflict with this machine.\n" +
|
|
127
|
+
"Run `opencode-sync pull` to take the remote version, or `opencode-sync push --force` to overwrite it.");
|
|
128
|
+
}
|
|
129
|
+
const result = git(["push", "origin", branch], { cwd: root });
|
|
130
|
+
if (!result.ok)
|
|
131
|
+
throw toGitError("Push", result);
|
|
132
|
+
assertPushLanded(root, branch, "Push");
|
|
133
|
+
void alreadyCommitted;
|
|
134
|
+
}
|
|
135
|
+
// ── Pull ────────────────────────────────────────────────────────────────────
|
|
136
|
+
export async function pull(options = {}) {
|
|
137
|
+
const ctx = prepare(options);
|
|
138
|
+
const { root, branch, reporter, force } = ctx;
|
|
139
|
+
fs.mkdirSync(root, { recursive: true });
|
|
140
|
+
if (!isGitRepo(root)) {
|
|
141
|
+
const state = ensureRepo({ root, remote: ctx.remote, branch });
|
|
142
|
+
if (state === "fresh") {
|
|
143
|
+
return done("pull", false, emptySummary(), [], "The sync repository is empty — push from another machine first.");
|
|
144
|
+
}
|
|
145
|
+
stageOut(createStageContext(root, ctx.settings, reporter, force, ctx.roots));
|
|
146
|
+
const sessions = await maybeImportSessions(ctx);
|
|
147
|
+
const count = git(["ls-files"], { cwd: root }).stdout.split("\n").filter(Boolean).length;
|
|
148
|
+
finishPull(ctx);
|
|
149
|
+
return done("pull", true, emptySummary(), [], `First pull complete — ${count} file(s)`, sessions, true);
|
|
150
|
+
}
|
|
151
|
+
ensureRepo({ root, remote: ctx.remote, branch });
|
|
152
|
+
reporter.step("Fetching from GitHub");
|
|
153
|
+
const fetched = git(["fetch", "origin", branch], { cwd: root });
|
|
154
|
+
if (!fetched.ok)
|
|
155
|
+
throw toGitError("Fetch", fetched);
|
|
156
|
+
const ahead = countCommits(root, `origin/${branch}..HEAD`);
|
|
157
|
+
if (!force && ahead > 0) {
|
|
158
|
+
throw new SyncError(`This machine has ${ahead} commit(s) that were never pushed.\n` +
|
|
159
|
+
"Run `opencode-sync push` first, or `opencode-sync pull --force` to discard them.");
|
|
160
|
+
}
|
|
161
|
+
const behind = countCommits(root, `HEAD..origin/${branch}`);
|
|
162
|
+
if (!force && behind === 0) {
|
|
163
|
+
// Nothing incoming, so the worktree does not need to be touched at all.
|
|
164
|
+
// Skipping the stash cycle here is what keeps a no-op pull fast on Windows.
|
|
165
|
+
return done("pull", false, emptySummary(), [], "Already up to date", undefined, false);
|
|
166
|
+
}
|
|
167
|
+
const stageCtx = createStageContext(root, ctx.settings, reporter, force, ctx.roots);
|
|
168
|
+
// The config file on disk carries this machine's overrides, so it always
|
|
169
|
+
// differs from HEAD. Rewinding it to the committed form first means the
|
|
170
|
+
// worktree is clean and the pull never has to stash-and-merge the one file
|
|
171
|
+
// that would conflict on every single run.
|
|
172
|
+
normalizeConfigForRepo(stageCtx);
|
|
173
|
+
const stashed = prepareWorktree(ctx);
|
|
174
|
+
const nameStatus = git(["diff", "--name-status", "HEAD", `origin/${branch}`], { cwd: root });
|
|
175
|
+
const files = toChangedFiles(nameStatus, true);
|
|
176
|
+
const summary = summarize(files);
|
|
177
|
+
if (ctx.dryRun) {
|
|
178
|
+
if (stashed)
|
|
179
|
+
restoreStash(ctx);
|
|
180
|
+
return done("pull", files.length > 0, summary, files, `${totalChanges(summary)} change(s) would be pulled`);
|
|
181
|
+
}
|
|
182
|
+
const reset = git(["reset", "--hard", `origin/${branch}`], { cwd: root });
|
|
183
|
+
if (!reset.ok) {
|
|
184
|
+
if (stashed)
|
|
185
|
+
restoreStash(ctx);
|
|
186
|
+
throw toGitError("Reset", reset);
|
|
187
|
+
}
|
|
188
|
+
if (stashed)
|
|
189
|
+
restoreStash(ctx);
|
|
190
|
+
stageOut(createStageContext(root, ctx.settings, reporter, force, ctx.roots));
|
|
191
|
+
const sessions = await maybeImportSessions(ctx);
|
|
192
|
+
finishPull(ctx);
|
|
193
|
+
reporter.changes(summary, files);
|
|
194
|
+
return done("pull", files.length > 0, summary, files, files.length > 0 ? `Pulled ${totalChanges(summary)} change(s)` : "Already up to date", sessions, true);
|
|
195
|
+
}
|
|
196
|
+
/** Re-apply machine-local settings and clean up caches after a pull. */
|
|
197
|
+
function finishPull(ctx) {
|
|
198
|
+
if (applyOverrides(ctx.roots.config)) {
|
|
199
|
+
ctx.reporter.detail("Re-applied per-machine overrides");
|
|
200
|
+
}
|
|
201
|
+
const pruned = prunePluginCache(ctx.roots.config, ctx.roots.cache);
|
|
202
|
+
if (pruned > 0)
|
|
203
|
+
ctx.reporter.detail(`Removed ${pruned} stale plugin package(s) from the cache`);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get the worktree into a state where a hard reset is safe.
|
|
207
|
+
*
|
|
208
|
+
* Without `force` local edits are stashed and restored afterwards. With
|
|
209
|
+
* `force` they are discarded — but the runtime paths are still protected,
|
|
210
|
+
* because `git clean` would otherwise happily delete the user's database.
|
|
211
|
+
*/
|
|
212
|
+
function prepareWorktree(ctx) {
|
|
213
|
+
const { root, force } = ctx;
|
|
214
|
+
git(["add", "-A"], { cwd: root });
|
|
215
|
+
unstageLocalRuntimePaths(root);
|
|
216
|
+
const hasStaged = git(["diff", "--cached", "--stat"], { cwd: root }).stdout.length > 0;
|
|
217
|
+
const untracked = git(["ls-files", "--others", "--exclude-standard", "--", ".", ...excludePathspecs()], { cwd: root });
|
|
218
|
+
const hasUntracked = untracked.ok && untracked.stdout.length > 0;
|
|
219
|
+
if (!hasStaged && !hasUntracked)
|
|
220
|
+
return false;
|
|
221
|
+
git(["reset", "HEAD"], { cwd: root });
|
|
222
|
+
if (force) {
|
|
223
|
+
git(["checkout", "--", "."], { cwd: root });
|
|
224
|
+
// `-e` takes gitignore-style patterns and *keeps* the matches. Using
|
|
225
|
+
// `:(exclude)` pathspecs here would invert the meaning and delete
|
|
226
|
+
// everything except the runtime paths.
|
|
227
|
+
git(["clean", "-fd", ...LOCAL_RUNTIME_PATHS.flatMap((p) => ["-e", p])], { cwd: root });
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
git(["add", "-A"], { cwd: root });
|
|
231
|
+
unstageLocalRuntimePaths(root);
|
|
232
|
+
const stash = git([
|
|
233
|
+
"stash",
|
|
234
|
+
"push",
|
|
235
|
+
"--include-untracked",
|
|
236
|
+
"-m",
|
|
237
|
+
"opencode-sync auto-stash",
|
|
238
|
+
"--",
|
|
239
|
+
".",
|
|
240
|
+
...excludePathspecs(),
|
|
241
|
+
], { cwd: root });
|
|
242
|
+
if (!stash.ok)
|
|
243
|
+
throw toGitError("Stash", stash);
|
|
244
|
+
return !/No local changes to save/i.test(stash.stdout);
|
|
245
|
+
}
|
|
246
|
+
function restoreStash(ctx) {
|
|
247
|
+
const { root } = ctx;
|
|
248
|
+
const pop = git(["stash", "pop"], { cwd: root });
|
|
249
|
+
if (pop.ok)
|
|
250
|
+
return;
|
|
251
|
+
// A conflicting pop leaves the stash in place and the worktree half-merged.
|
|
252
|
+
// A half-merged opencode.jsonc stops OpenCode from starting, so reset to a
|
|
253
|
+
// known-good tree and tell the user exactly where their work still is.
|
|
254
|
+
git(["reset", "--hard", "HEAD"], { cwd: root });
|
|
255
|
+
throw new SyncError("Local changes conflicted with the incoming version.\n" +
|
|
256
|
+
"The worktree was rolled back to a clean state and your changes are still saved in the stash:\n" +
|
|
257
|
+
` cd "${root}"\n` +
|
|
258
|
+
" git stash list\n" +
|
|
259
|
+
" git stash show -p stash@{0} # inspect\n" +
|
|
260
|
+
" git stash apply --index stash@{0} # restore manually\n" +
|
|
261
|
+
" git stash drop stash@{0} # discard\n" +
|
|
262
|
+
"Or re-run with --force to take the remote version.");
|
|
263
|
+
}
|
|
264
|
+
// ── Sessions ────────────────────────────────────────────────────────────────
|
|
265
|
+
async function maybeExportSessions(ctx) {
|
|
266
|
+
if (!ctx.settings.sessions.enabled)
|
|
267
|
+
return undefined;
|
|
268
|
+
if (!(await sqliteAvailable())) {
|
|
269
|
+
ctx.reporter.warn("Session sync is enabled but no SQLite driver is available — skipping.");
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
const database = getDatabasePath(ctx.roots);
|
|
273
|
+
ctx.reporter.step("Exporting sessions");
|
|
274
|
+
const result = await exportSessions(database, ctx.root, ctx.settings.sessions, ctx.reporter);
|
|
275
|
+
for (const skipped of result.skippedTooLarge) {
|
|
276
|
+
ctx.reporter.warn(`Skipped "${skipped.title || skipped.id}" — ${formatBytes(skipped.bytes)} exceeds maxSessionBytes`);
|
|
277
|
+
}
|
|
278
|
+
if (result.written.length > 0) {
|
|
279
|
+
ctx.reporter.detail(`Exported ${result.written.length} session(s)`);
|
|
280
|
+
}
|
|
281
|
+
return { exported: result.written.length, skipped: result.skippedTooLarge.length };
|
|
282
|
+
}
|
|
283
|
+
async function maybeImportSessions(ctx) {
|
|
284
|
+
if (!ctx.settings.sessions.enabled)
|
|
285
|
+
return undefined;
|
|
286
|
+
if (!fs.existsSync(path.join(ctx.root, "_sessions")))
|
|
287
|
+
return undefined;
|
|
288
|
+
if (!(await sqliteAvailable())) {
|
|
289
|
+
ctx.reporter.warn("Session shards were pulled but no SQLite driver is available to import them.");
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
ctx.reporter.step("Importing sessions");
|
|
293
|
+
const result = await importSessions(getDatabasePath(ctx.roots), ctx.root, ctx.reporter);
|
|
294
|
+
for (const failure of result.failed) {
|
|
295
|
+
ctx.reporter.warn(`Could not import ${failure.file}: ${failure.reason}`);
|
|
296
|
+
}
|
|
297
|
+
if (result.imported > 0)
|
|
298
|
+
ctx.reporter.detail(`Imported ${result.imported} session(s)`);
|
|
299
|
+
return { imported: result.imported, skipped: result.skippedOlder };
|
|
300
|
+
}
|
|
301
|
+
export function status(options = {}) {
|
|
302
|
+
const roots = options.roots ?? getRoots();
|
|
303
|
+
const settings = options.settings ?? loadSettings(roots.config);
|
|
304
|
+
const branch = repoBranch(settings);
|
|
305
|
+
const remote = repoUrl(settings);
|
|
306
|
+
const root = roots.config;
|
|
307
|
+
const base = {
|
|
308
|
+
configured: Boolean(remote),
|
|
309
|
+
remote,
|
|
310
|
+
branch,
|
|
311
|
+
initialized: false,
|
|
312
|
+
ahead: 0,
|
|
313
|
+
behind: 0,
|
|
314
|
+
dirty: 0,
|
|
315
|
+
sessionsEnabled: settings.sessions.enabled,
|
|
316
|
+
sessionShards: countShards(root),
|
|
317
|
+
overridesActive: fs.existsSync(path.join(root, "opencode-sync.overrides.jsonc")),
|
|
318
|
+
machineAlias: hostAlias(settings.machineAlias),
|
|
319
|
+
};
|
|
320
|
+
if (!remote || !isGitRepo(root))
|
|
321
|
+
return base;
|
|
322
|
+
base.initialized = true;
|
|
323
|
+
git(["fetch", "origin", branch], { cwd: root });
|
|
324
|
+
base.ahead = countCommits(root, `origin/${branch}..HEAD`);
|
|
325
|
+
base.behind = countCommits(root, `HEAD..origin/${branch}`);
|
|
326
|
+
const dirty = git(["status", "--porcelain", "--", ".", ...excludePathspecs()], { cwd: root });
|
|
327
|
+
base.dirty = dirty.ok ? dirty.stdout.split("\n").filter(Boolean).length : 0;
|
|
328
|
+
const log = git(["log", "-1", "--format=%s%n%cI"], { cwd: root });
|
|
329
|
+
if (log.ok) {
|
|
330
|
+
const [subject, date] = log.stdout.split("\n");
|
|
331
|
+
base.lastCommit = subject;
|
|
332
|
+
base.lastCommitDate = date;
|
|
333
|
+
}
|
|
334
|
+
return base;
|
|
335
|
+
}
|
|
336
|
+
function countShards(root) {
|
|
337
|
+
const dir = path.join(root, "_sessions");
|
|
338
|
+
if (!fs.existsSync(dir))
|
|
339
|
+
return 0;
|
|
340
|
+
return fs.readdirSync(dir).filter((f) => f.endsWith(".json.gz")).length;
|
|
341
|
+
}
|
|
342
|
+
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
343
|
+
function countCommits(root, range) {
|
|
344
|
+
const result = git(["rev-list", "--count", range], { cwd: root });
|
|
345
|
+
return result.ok ? Number(result.stdout) || 0 : 0;
|
|
346
|
+
}
|
|
347
|
+
function done(action, changed, summary, files, message, sessions, restartRequired = false) {
|
|
348
|
+
return { action, changed, summary, files, message, sessions, restartRequired };
|
|
349
|
+
}
|
|
350
|
+
export function formatBytes(bytes) {
|
|
351
|
+
if (bytes < 1024)
|
|
352
|
+
return `${bytes} B`;
|
|
353
|
+
if (bytes < 1024 * 1024)
|
|
354
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
355
|
+
if (bytes < 1024 * 1024 * 1024)
|
|
356
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
357
|
+
return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
|
358
|
+
}
|
|
359
|
+
export { SyncError };
|
|
360
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/core/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAkB,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAc,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EAGL,YAAY,EACZ,cAAc,EACd,SAAS,EACT,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAA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G,IAAI,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IAChF,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AACzD,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface PluginContext {
|
|
2
|
+
client?: any;
|
|
3
|
+
directory?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const OpencodeGithubSync: (ctx: PluginContext) => Promise<{
|
|
6
|
+
event?: undefined;
|
|
7
|
+
tool?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
event: ({ event }: {
|
|
10
|
+
event: {
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
tool: {
|
|
15
|
+
opencode_sync: {
|
|
16
|
+
description: string;
|
|
17
|
+
args: {
|
|
18
|
+
action: {
|
|
19
|
+
type: string;
|
|
20
|
+
enum: string[];
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
execute(args: {
|
|
25
|
+
action?: string;
|
|
26
|
+
}): Promise<string>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
export default OpencodeGithubSync;
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AA0BA,UAAU,aAAa;IACrB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAwED,eAAO,MAAM,kBAAkB,GAAU,KAAK,aAAa;;;;uBAsB9B;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE;;;;;;;;;;;0BAmB5B;gBAAE,MAAM,CAAC,EAAE,MAAM,CAAA;aAAE;;;EAmC9C,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { withSyncLock } from "../core/lock.js";
|
|
3
|
+
import { getRoots } from "../core/paths.js";
|
|
4
|
+
import { CollectingReporter } from "../core/reporter.js";
|
|
5
|
+
import { loadSettings, repoUrl, settingsPath } from "../core/settings.js";
|
|
6
|
+
import { pull, push, status } from "../core/sync.js";
|
|
7
|
+
async function toast(client, message, variant) {
|
|
8
|
+
try {
|
|
9
|
+
await client?.tui?.showToast?.({ body: { message, variant } });
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// The TUI is not attached (headless run) — nothing to show.
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async function log(client, level, message, extra) {
|
|
16
|
+
try {
|
|
17
|
+
await client?.app?.log?.({
|
|
18
|
+
body: { service: "opencode-github-sync", level, message, extra },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Logging must never break a sync.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function isConfigured() {
|
|
26
|
+
const roots = getRoots();
|
|
27
|
+
if (!fs.existsSync(settingsPath(roots.config)))
|
|
28
|
+
return false;
|
|
29
|
+
try {
|
|
30
|
+
return Boolean(repoUrl(loadSettings(roots.config)));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function runPull(client, announce) {
|
|
37
|
+
const roots = getRoots();
|
|
38
|
+
const reporter = new CollectingReporter();
|
|
39
|
+
try {
|
|
40
|
+
const result = await withSyncLock(roots.config, { waitMs: 30_000 }, () => pull({ reporter, roots }));
|
|
41
|
+
await log(client, "info", `pull: ${result.message}`, { summary: result.summary });
|
|
42
|
+
if (result.changed) {
|
|
43
|
+
await toast(client, `Config updated from GitHub (${result.files.length} file(s)). Restart OpenCode to apply.`, "success");
|
|
44
|
+
}
|
|
45
|
+
else if (announce) {
|
|
46
|
+
await toast(client, "Config already up to date.", "info");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const message = error.message;
|
|
51
|
+
await log(client, "warn", `pull failed: ${message}`);
|
|
52
|
+
if (announce)
|
|
53
|
+
await toast(client, `Sync pull failed: ${message}`, "error");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function runPush(client, announce) {
|
|
57
|
+
const roots = getRoots();
|
|
58
|
+
const reporter = new CollectingReporter();
|
|
59
|
+
try {
|
|
60
|
+
const result = await withSyncLock(roots.config, { waitMs: 30_000 }, () => push({ reporter, roots }));
|
|
61
|
+
await log(client, "info", `push: ${result.message}`);
|
|
62
|
+
if (announce) {
|
|
63
|
+
await toast(client, result.message, result.changed ? "success" : "info");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const message = error.message;
|
|
68
|
+
await log(client, "warn", `push failed: ${message}`);
|
|
69
|
+
if (announce)
|
|
70
|
+
await toast(client, `Sync push failed: ${message}`, "error");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export const OpencodeGithubSync = async (ctx) => {
|
|
74
|
+
const client = ctx?.client;
|
|
75
|
+
const roots = getRoots();
|
|
76
|
+
if (!isConfigured()) {
|
|
77
|
+
await log(client, "info", "opencode-github-sync is installed but no repository is configured. Run `opencode-sync init`.");
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
const settings = loadSettings(roots.config);
|
|
81
|
+
if (settings.autoPullOnStartup) {
|
|
82
|
+
// Deliberately not awaited: OpenCode should finish starting even when the
|
|
83
|
+
// network is slow or GitHub is unreachable.
|
|
84
|
+
void runPull(client, false);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
event: async ({ event }) => {
|
|
88
|
+
if (event.type === "session.idle" && settings.autoPushOnIdle) {
|
|
89
|
+
void runPush(client, false);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
tool: {
|
|
93
|
+
opencode_sync: {
|
|
94
|
+
description: "Sync OpenCode configuration with the GitHub sync repository. " +
|
|
95
|
+
"Use action 'push' to upload this machine's configuration, 'pull' to apply the shared " +
|
|
96
|
+
"configuration, or 'status' to report what is out of sync.",
|
|
97
|
+
args: {
|
|
98
|
+
action: {
|
|
99
|
+
type: "string",
|
|
100
|
+
enum: ["push", "pull", "status"],
|
|
101
|
+
description: "Which sync operation to run.",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
async execute(args) {
|
|
105
|
+
const action = args?.action ?? "status";
|
|
106
|
+
const reporter = new CollectingReporter();
|
|
107
|
+
if (action === "status") {
|
|
108
|
+
const state = status({ roots });
|
|
109
|
+
return JSON.stringify(state, null, 2);
|
|
110
|
+
}
|
|
111
|
+
const result = await withSyncLock(roots.config, { waitMs: 60_000 }, () => action === "push" ? push({ reporter, roots }) : pull({ reporter, roots }));
|
|
112
|
+
const lines = [result.message];
|
|
113
|
+
if (result.files.length > 0) {
|
|
114
|
+
lines.push(`Files: ${result.files
|
|
115
|
+
.slice(0, 20)
|
|
116
|
+
.map((f) => `${f.kind[0]} ${f.path}`)
|
|
117
|
+
.join(", ")}`);
|
|
118
|
+
}
|
|
119
|
+
if (result.restartRequired && result.changed) {
|
|
120
|
+
lines.push("Restart OpenCode for the new configuration to take effect.");
|
|
121
|
+
}
|
|
122
|
+
if (reporter.lines.length > 0) {
|
|
123
|
+
lines.push(...reporter.lines.filter((l) => l.level === "warn").map((l) => `! ${l.message}`));
|
|
124
|
+
}
|
|
125
|
+
return lines.join("\n");
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export default OpencodeGithubSync;
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skills, and selected sessions across machines via a private GitHub repo — as a plugin or a CLI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "doomsday616",
|
|
8
|
+
"homepage": "https://github.com/doomsday616/opencode-github-sync#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/doomsday616/opencode-github-sync.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/doomsday616/opencode-github-sync/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"opencode",
|
|
18
|
+
"opencode-plugin",
|
|
19
|
+
"sync",
|
|
20
|
+
"config-sync",
|
|
21
|
+
"dotfiles",
|
|
22
|
+
"github",
|
|
23
|
+
"cli"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/plugin/index.js",
|
|
29
|
+
"types": "./dist/plugin/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/plugin/index.d.ts",
|
|
33
|
+
"default": "./dist/plugin/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./core": {
|
|
36
|
+
"types": "./dist/core/index.d.ts",
|
|
37
|
+
"default": "./dist/core/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"bin": {
|
|
42
|
+
"opencode-sync": "./dist/cli/index.js"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"README.md",
|
|
47
|
+
"README.zh-CN.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -p tsconfig.build.json",
|
|
52
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:watch": "vitest",
|
|
55
|
+
"lint": "biome check src tests",
|
|
56
|
+
"lint:fix": "biome check --write src tests",
|
|
57
|
+
"typecheck": "tsc --noEmit",
|
|
58
|
+
"check": "npm run lint && npm run typecheck && npm run test",
|
|
59
|
+
"prepublishOnly": "npm run build"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@biomejs/biome": "^1.9.4",
|
|
63
|
+
"@types/node": "^22.10.2",
|
|
64
|
+
"typescript": "^5.7.2",
|
|
65
|
+
"vitest": "^2.1.8"
|
|
66
|
+
}
|
|
67
|
+
}
|