opencode-github-sync 3.1.1 → 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.
- package/README.md +535 -220
- package/README.zh-CN.md +387 -197
- package/dist/cli/app.d.ts +39 -0
- package/dist/cli/app.d.ts.map +1 -0
- package/dist/cli/app.js +179 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +39 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/i18n.d.ts +378 -0
- package/dist/cli/i18n.d.ts.map +1 -0
- package/dist/cli/i18n.js +793 -0
- package/dist/cli/i18n.js.map +1 -0
- package/dist/cli/index.js +362 -115
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/menu.d.ts +52 -0
- package/dist/cli/menu.d.ts.map +1 -0
- package/dist/cli/menu.js +1126 -0
- package/dist/cli/menu.js.map +1 -0
- package/dist/cli/render.d.ts +3 -0
- package/dist/cli/render.d.ts.map +1 -1
- package/dist/cli/render.js +6 -1
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/ui.d.ts +62 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +383 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/core/autosync.d.ts +136 -0
- package/dist/core/autosync.d.ts.map +1 -0
- package/dist/core/autosync.js +516 -0
- package/dist/core/autosync.js.map +1 -0
- package/dist/core/bundle.d.ts +11 -0
- package/dist/core/bundle.d.ts.map +1 -0
- package/dist/core/bundle.js +87 -0
- package/dist/core/bundle.js.map +1 -0
- package/dist/core/categories.d.ts +37 -0
- package/dist/core/categories.d.ts.map +1 -0
- package/dist/core/categories.js +115 -0
- package/dist/core/categories.js.map +1 -0
- package/dist/core/compare.d.ts +21 -0
- package/dist/core/compare.d.ts.map +1 -0
- package/dist/core/compare.js +124 -0
- package/dist/core/compare.js.map +1 -0
- package/dist/core/credentials.d.ts +40 -0
- package/dist/core/credentials.d.ts.map +1 -0
- package/dist/core/credentials.js +364 -0
- package/dist/core/credentials.js.map +1 -0
- package/dist/core/env.d.ts +16 -0
- package/dist/core/env.d.ts.map +1 -0
- package/dist/core/env.js +47 -0
- package/dist/core/env.js.map +1 -0
- package/dist/core/fsx.d.ts +2 -0
- package/dist/core/fsx.d.ts.map +1 -1
- package/dist/core/fsx.js +6 -0
- package/dist/core/fsx.js.map +1 -1
- package/dist/core/git.d.ts +6 -0
- package/dist/core/git.d.ts.map +1 -1
- package/dist/core/git.js +44 -4
- package/dist/core/git.js.map +1 -1
- package/dist/core/guard.d.ts +36 -0
- package/dist/core/guard.d.ts.map +1 -0
- package/dist/core/guard.js +65 -0
- package/dist/core/guard.js.map +1 -0
- package/dist/core/history.d.ts +38 -0
- package/dist/core/history.d.ts.map +1 -0
- package/dist/core/history.js +98 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/lease.d.ts +52 -0
- package/dist/core/lease.d.ts.map +1 -0
- package/dist/core/lease.js +235 -0
- package/dist/core/lease.js.map +1 -0
- package/dist/core/notify.d.ts +9 -0
- package/dist/core/notify.d.ts.map +1 -0
- package/dist/core/notify.js +69 -0
- package/dist/core/notify.js.map +1 -0
- package/dist/core/projects.d.ts +79 -0
- package/dist/core/projects.d.ts.map +1 -0
- package/dist/core/projects.js +192 -0
- package/dist/core/projects.js.map +1 -0
- package/dist/core/recovery.d.ts +26 -0
- package/dist/core/recovery.d.ts.map +1 -0
- package/dist/core/recovery.js +56 -0
- package/dist/core/recovery.js.map +1 -0
- package/dist/core/repair.d.ts +44 -0
- package/dist/core/repair.d.ts.map +1 -0
- package/dist/core/repair.js +81 -0
- package/dist/core/repair.js.map +1 -0
- package/dist/core/repo.d.ts +34 -2
- package/dist/core/repo.d.ts.map +1 -1
- package/dist/core/repo.js +87 -5
- package/dist/core/repo.js.map +1 -1
- package/dist/core/rows.d.ts +36 -0
- package/dist/core/rows.d.ts.map +1 -0
- package/dist/core/rows.js +75 -0
- package/dist/core/rows.js.map +1 -0
- package/dist/core/scheduler.d.ts +138 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +531 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/sessions.d.ts +32 -4
- package/dist/core/sessions.d.ts.map +1 -1
- package/dist/core/sessions.js +316 -104
- package/dist/core/sessions.js.map +1 -1
- package/dist/core/settings.d.ts +67 -0
- package/dist/core/settings.d.ts.map +1 -1
- package/dist/core/settings.js +45 -2
- package/dist/core/settings.js.map +1 -1
- package/dist/core/setup.d.ts +20 -0
- package/dist/core/setup.d.ts.map +1 -1
- package/dist/core/setup.js +87 -4
- package/dist/core/setup.js.map +1 -1
- package/dist/core/sqlite.d.ts +2 -0
- package/dist/core/sqlite.d.ts.map +1 -1
- package/dist/core/sqlite.js +14 -0
- package/dist/core/sqlite.js.map +1 -1
- package/dist/core/stage.d.ts +18 -0
- package/dist/core/stage.d.ts.map +1 -1
- package/dist/core/stage.js +133 -4
- package/dist/core/stage.js.map +1 -1
- package/dist/core/sync.d.ts +25 -0
- package/dist/core/sync.d.ts.map +1 -1
- package/dist/core/sync.js +283 -43
- package/dist/core/sync.js.map +1 -1
- package/dist/core/update.d.ts +21 -0
- package/dist/core/update.d.ts.map +1 -0
- package/dist/core/update.js +75 -0
- package/dist/core/update.js.map +1 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +6 -5
- package/dist/plugin/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cli/index.js
CHANGED
|
@@ -1,140 +1,148 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import
|
|
4
|
+
import { appendLog, backoffRemainingMs, failureCount, readState, runAutosync, writeState, } from "../core/autosync.js";
|
|
5
|
+
import { LargeChangeError } from "../core/guard.js";
|
|
5
6
|
import { withSyncLock } from "../core/lock.js";
|
|
6
7
|
import { getDatabasePath, getRoots } from "../core/paths.js";
|
|
8
|
+
import { repairSessions } from "../core/repair.js";
|
|
7
9
|
import { listSessions } from "../core/sessions.js";
|
|
8
10
|
import { OVERRIDES_TEMPLATE, loadSettings, overridesPath, saveSettings, settingsPath, } from "../core/settings.js";
|
|
9
|
-
import { SetupError, discoverSyncRepos, initSync, linkSync } from "../core/setup.js";
|
|
11
|
+
import { SetupError, discoverSyncRepos, initSync, isRepoUrl, linkByUrl, linkSync, } from "../core/setup.js";
|
|
10
12
|
import { sqliteAvailable } from "../core/sqlite.js";
|
|
11
13
|
import { SyncError, formatBytes, pull, push, status } from "../core/sync.js";
|
|
14
|
+
import { applyLocalSettings, autosyncDeps, formatTime, realScheduler, safeLoadSettings, tomorrowMorning, } from "./app.js";
|
|
15
|
+
import { parseArgs } from "./args.js";
|
|
16
|
+
import { ago, t } from "./i18n.js";
|
|
17
|
+
import { disableAutosync, enableAutosync, runMenu, runSetup } from "./menu.js";
|
|
12
18
|
import { Spinner, banner, createCliReporter, detail, fail, heading, info, keyValue, ok, outcome, rule, warn, write, } from "./render.js";
|
|
13
19
|
import { glyph, paint, style } from "./theme.js";
|
|
20
|
+
import { Ui } from "./ui.js";
|
|
14
21
|
const LOCK_WAIT_MS = 5 * 60 * 1000;
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
positional.push(arg);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
const clean = arg.replace(/^--?/, "");
|
|
25
|
-
const eq = clean.indexOf("=");
|
|
26
|
-
if (eq !== -1)
|
|
27
|
-
values.set(clean.slice(0, eq), clean.slice(eq + 1));
|
|
28
|
-
else
|
|
29
|
-
flags.add(clean);
|
|
30
|
-
}
|
|
31
|
-
return { command: positional.shift() ?? "help", positional, flags, values };
|
|
22
|
+
function newUi() {
|
|
23
|
+
return new Ui({
|
|
24
|
+
input: process.stdin,
|
|
25
|
+
output: process.stdout,
|
|
26
|
+
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
27
|
+
});
|
|
32
28
|
}
|
|
33
|
-
async function
|
|
34
|
-
if (
|
|
29
|
+
async function confirmForce(action, lines, args) {
|
|
30
|
+
if (args.flags.has("yes") || args.flags.has("y"))
|
|
31
|
+
return true;
|
|
32
|
+
if (!process.stdin.isTTY) {
|
|
33
|
+
fail(t("cliNeedTty"));
|
|
35
34
|
return false;
|
|
35
|
+
}
|
|
36
36
|
write();
|
|
37
|
-
write(` ${paint(" FORCE ", style.bold, style.red)} ${paint(
|
|
37
|
+
write(` ${paint(" FORCE ", style.bold, style.red)} ${paint(t("cliForceTitle", { action }), style.bold, style.text)}`);
|
|
38
38
|
for (const line of lines)
|
|
39
39
|
write(` ${paint(`${glyph.bullet} ${line}`, style.muted)}`);
|
|
40
40
|
write();
|
|
41
|
-
const
|
|
42
|
-
const answer = await
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
rl.close();
|
|
46
|
-
write();
|
|
47
|
-
return answer.trim().toLowerCase() === "yes";
|
|
41
|
+
const ui = newUi();
|
|
42
|
+
const answer = await ui.text(t("cliTypeYes"));
|
|
43
|
+
ui.close();
|
|
44
|
+
return answer?.trim().toLowerCase() === "yes";
|
|
48
45
|
}
|
|
49
46
|
// ── Commands ────────────────────────────────────────────────────────────────
|
|
50
47
|
async function runSync(action, args) {
|
|
51
48
|
const force = args.flags.has("force") || args.flags.has("f");
|
|
52
49
|
const dryRun = args.flags.has("dry-run") || args.flags.has("n");
|
|
50
|
+
const allowLarge = args.flags.has("allow-large");
|
|
53
51
|
const roots = getRoots();
|
|
54
|
-
banner(action === "push" ? "
|
|
52
|
+
banner(action === "push" ? t("cliPushTitle") : t("cliPullTitle"), force ? "FORCE" : undefined);
|
|
55
53
|
if (force && !dryRun) {
|
|
56
|
-
const consequences = action === "push"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"Uncommitted local changes will be discarded.",
|
|
60
|
-
"Skills and state directories will be rewritten from the repository.",
|
|
61
|
-
];
|
|
62
|
-
if (!(await confirm(`Force ${action}?`, consequences))) {
|
|
63
|
-
info("Cancelled.");
|
|
54
|
+
const consequences = action === "push" ? [t("cliForcePushWarn")] : [t("cliForcePullWarn")];
|
|
55
|
+
if (!(await confirmForce(action, consequences, args))) {
|
|
56
|
+
info(t("cancelled"));
|
|
64
57
|
return;
|
|
65
58
|
}
|
|
66
59
|
}
|
|
67
|
-
const spinner = new Spinner(action === "push" ? "
|
|
60
|
+
const spinner = new Spinner(action === "push" ? t("cliPreparingPush") : t("cliPreparingPull"));
|
|
68
61
|
spinner.start();
|
|
69
62
|
const reporter = createCliReporter(spinner);
|
|
70
63
|
try {
|
|
71
64
|
const result = await withSyncLock(roots.config, { waitMs: LOCK_WAIT_MS }, () => action === "push"
|
|
72
|
-
? push({ force, dryRun, reporter, roots })
|
|
65
|
+
? push({ force, dryRun, reporter, roots, allowLarge })
|
|
73
66
|
: pull({ force, dryRun, reporter, roots }));
|
|
74
67
|
spinner.stop();
|
|
75
68
|
if (result.sessions) {
|
|
76
69
|
const bits = [];
|
|
77
70
|
if (result.sessions.exported !== undefined)
|
|
78
|
-
bits.push(
|
|
71
|
+
bits.push(t("cliExported", { n: result.sessions.exported }));
|
|
79
72
|
if (result.sessions.imported !== undefined)
|
|
80
|
-
bits.push(
|
|
73
|
+
bits.push(t("cliImported", { n: result.sessions.imported }));
|
|
81
74
|
if (result.sessions.skipped)
|
|
82
|
-
bits.push(
|
|
75
|
+
bits.push(t("cliSkipped", { n: result.sessions.skipped }));
|
|
83
76
|
if (bits.length > 0)
|
|
84
|
-
detail(
|
|
77
|
+
detail(t("cliSessionsLine", { text: bits.join(", ") }));
|
|
85
78
|
}
|
|
86
|
-
|
|
79
|
+
if (result.guard) {
|
|
80
|
+
warn(t("largeTitle"));
|
|
81
|
+
detail(`${result.guard.addedFiles} / ${formatBytes(result.guard.totalBytes)}`);
|
|
82
|
+
}
|
|
83
|
+
outcome(dryRun ? t("cliDryRun", { message: result.message }) : result.message, result.changed);
|
|
87
84
|
if (result.restartRequired && result.changed) {
|
|
88
|
-
info("
|
|
85
|
+
info(t("restartHint"));
|
|
89
86
|
write();
|
|
90
87
|
}
|
|
91
88
|
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (error instanceof LargeChangeError) {
|
|
91
|
+
spinner.stop();
|
|
92
|
+
fail(`${t("largeRefused")}\n${error.message}`);
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
92
98
|
finally {
|
|
93
99
|
spinner.stop();
|
|
94
100
|
}
|
|
95
101
|
}
|
|
96
102
|
function runStatus() {
|
|
97
|
-
banner("
|
|
103
|
+
banner(t("stTitle"));
|
|
98
104
|
const roots = getRoots();
|
|
99
105
|
const state = status({ roots });
|
|
100
106
|
if (!state.configured) {
|
|
101
|
-
fail("
|
|
107
|
+
fail(t("cliNoRepo"));
|
|
102
108
|
write();
|
|
103
|
-
info("
|
|
109
|
+
info(t("cliRunInit"));
|
|
104
110
|
const found = discoverSyncRepos();
|
|
105
111
|
if (found.length > 0) {
|
|
106
112
|
write();
|
|
107
|
-
detail(
|
|
108
|
-
detail("
|
|
113
|
+
detail(t("cliFoundRepos", { list: found.slice(0, 5).join(", ") }));
|
|
114
|
+
detail(t("cliLinkHint"));
|
|
109
115
|
}
|
|
110
116
|
write();
|
|
111
117
|
return;
|
|
112
118
|
}
|
|
113
|
-
keyValue("
|
|
114
|
-
keyValue("
|
|
115
|
-
keyValue("
|
|
119
|
+
keyValue(t("stRepository"), paint(state.remote ?? "-", style.text));
|
|
120
|
+
keyValue(t("stBranch"), paint(state.branch, style.text));
|
|
121
|
+
keyValue(t("stMachine"), paint(state.machineAlias, style.text));
|
|
116
122
|
if (!state.initialized) {
|
|
117
123
|
write();
|
|
118
|
-
warn("
|
|
124
|
+
warn(t("cliNotInitialised"));
|
|
119
125
|
write();
|
|
120
126
|
return;
|
|
121
127
|
}
|
|
122
128
|
const sync = state.ahead === 0 && state.behind === 0
|
|
123
|
-
? paint("
|
|
129
|
+
? paint(t("stInSync"), style.green)
|
|
124
130
|
: [
|
|
125
|
-
state.ahead > 0 ? paint(
|
|
126
|
-
state.behind > 0 ? paint(
|
|
131
|
+
state.ahead > 0 ? paint(t("stToPush", { n: state.ahead }), style.yellow) : "",
|
|
132
|
+
state.behind > 0 ? paint(t("stToPull", { n: state.behind }), style.cyan) : "",
|
|
127
133
|
]
|
|
128
134
|
.filter(Boolean)
|
|
129
135
|
.join(paint(" ", style.faint));
|
|
130
|
-
keyValue("
|
|
131
|
-
keyValue("
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
keyValue(t("stState"), sync);
|
|
137
|
+
keyValue(t("stUncommitted"), state.dirty === 0
|
|
138
|
+
? paint(t("stClean"), style.green)
|
|
139
|
+
: paint(t("stFiles", { n: state.dirty }), style.yellow));
|
|
140
|
+
keyValue(t("stOverrides"), state.overridesActive ? paint(t("stActive"), style.accent) : paint(t("none"), style.muted));
|
|
141
|
+
keyValue(t("stSessions"), state.sessionsEnabled
|
|
142
|
+
? paint(t("stSessionsOn", { n: state.sessionShards }), style.text)
|
|
143
|
+
: paint(t("stDisabled"), style.muted));
|
|
136
144
|
if (state.lastCommit) {
|
|
137
|
-
heading("
|
|
145
|
+
heading(t("stLastCommit"));
|
|
138
146
|
detail(state.lastCommit);
|
|
139
147
|
if (state.lastCommitDate)
|
|
140
148
|
detail(state.lastCommitDate);
|
|
@@ -142,7 +150,7 @@ function runStatus() {
|
|
|
142
150
|
write();
|
|
143
151
|
}
|
|
144
152
|
function runInit(args, mode) {
|
|
145
|
-
banner(mode === "init" ? "
|
|
153
|
+
banner(mode === "init" ? t("initTitle") : t("linkTitleCli"));
|
|
146
154
|
const reporter = createCliReporter();
|
|
147
155
|
const options = {
|
|
148
156
|
repo: args.positional[0],
|
|
@@ -150,15 +158,22 @@ function runInit(args, mode) {
|
|
|
150
158
|
includeCredentials: args.flags.has("credentials"),
|
|
151
159
|
includeSessions: args.flags.has("sessions"),
|
|
152
160
|
};
|
|
153
|
-
const result = mode === "
|
|
161
|
+
const result = mode === "link" && isRepoUrl(options.repo)
|
|
162
|
+
? linkByUrl({ ...options, url: options.repo })
|
|
163
|
+
: mode === "init"
|
|
164
|
+
? initSync(options)
|
|
165
|
+
: linkSync(options);
|
|
166
|
+
const label = result.target.owner
|
|
167
|
+
? `${result.target.owner}/${result.target.name}`
|
|
168
|
+
: result.target.name;
|
|
154
169
|
ok(result.created
|
|
155
|
-
?
|
|
156
|
-
:
|
|
157
|
-
detail(
|
|
158
|
-
detail(
|
|
159
|
-
heading("
|
|
170
|
+
? t("initCreated", { repo: paint(label, style.bold, style.text) })
|
|
171
|
+
: t("initLinked", { repo: paint(label, style.bold, style.text) }));
|
|
172
|
+
detail(t("initSettings", { file: result.settingsFile }));
|
|
173
|
+
detail(t("initOverrides", { file: result.overridesFile }));
|
|
174
|
+
heading(t("initNext"));
|
|
160
175
|
write(` ${paint("1.", style.faint)} ${mode === "init" ? "opencode-sync push" : "opencode-sync pull"}`);
|
|
161
|
-
write(` ${paint("2.", style.faint)}
|
|
176
|
+
write(` ${paint("2.", style.faint)} ${t("initRestart")}`);
|
|
162
177
|
write();
|
|
163
178
|
}
|
|
164
179
|
async function runSessions(args) {
|
|
@@ -166,78 +181,124 @@ async function runSessions(args) {
|
|
|
166
181
|
const roots = getRoots();
|
|
167
182
|
const settings = loadSettings(roots.config);
|
|
168
183
|
if (sub === "list") {
|
|
169
|
-
banner("
|
|
184
|
+
banner(t("sesTitle"));
|
|
170
185
|
if (!(await sqliteAvailable())) {
|
|
171
|
-
fail("
|
|
186
|
+
fail(t("sesNoSqlite"));
|
|
172
187
|
write();
|
|
173
188
|
return;
|
|
174
189
|
}
|
|
175
190
|
const limit = Number(args.values.get("limit") ?? 20);
|
|
176
191
|
const sessions = await listSessions(getDatabasePath(roots), limit);
|
|
177
192
|
if (sessions.length === 0) {
|
|
178
|
-
info("
|
|
193
|
+
info(t("sesNone"));
|
|
179
194
|
write();
|
|
180
195
|
return;
|
|
181
196
|
}
|
|
182
197
|
for (const session of sessions) {
|
|
183
198
|
const when = new Date(session.timeUpdated).toISOString().slice(0, 16).replace("T", " ");
|
|
184
|
-
const title = session.title || paint("
|
|
199
|
+
const title = session.title || paint(t("sesUntitled"), style.faint);
|
|
185
200
|
write(` ${paint(when, style.faint)} ${title}`);
|
|
186
201
|
write(` ${paint(" ".repeat(16), style.faint)} ${paint(session.id, style.faint)}`);
|
|
187
202
|
}
|
|
188
203
|
write();
|
|
189
|
-
detail(
|
|
204
|
+
detail(t("sesPinHint"));
|
|
190
205
|
write();
|
|
191
206
|
return;
|
|
192
207
|
}
|
|
193
208
|
if (sub === "include" || sub === "exclude") {
|
|
194
209
|
const id = args.positional[1];
|
|
195
210
|
if (!id)
|
|
196
|
-
throw new SyncError(
|
|
211
|
+
throw new SyncError(t("sesUsage", { sub }));
|
|
197
212
|
const list = sub === "include" ? settings.sessions.include : settings.sessions.exclude;
|
|
198
213
|
if (!list.includes(id))
|
|
199
214
|
list.push(id);
|
|
200
215
|
saveSettings(settings, roots.config);
|
|
201
|
-
banner("
|
|
202
|
-
ok(
|
|
216
|
+
banner(t("sesTitle"));
|
|
217
|
+
ok(sub === "include"
|
|
218
|
+
? t("sesPinned", { id: paint(id, style.text) })
|
|
219
|
+
: t("sesExcluded", { id: paint(id, style.text) }));
|
|
203
220
|
write();
|
|
204
221
|
return;
|
|
205
222
|
}
|
|
206
223
|
if (sub === "enable" || sub === "disable") {
|
|
207
224
|
settings.sessions.enabled = sub === "enable";
|
|
208
225
|
saveSettings(settings, roots.config);
|
|
209
|
-
banner("
|
|
210
|
-
ok(
|
|
226
|
+
banner(t("sesTitle"));
|
|
227
|
+
ok(sub === "enable" ? t("sesEnabled") : t("sesDisabled"));
|
|
211
228
|
if (sub === "enable") {
|
|
212
|
-
detail(
|
|
213
|
-
detail(
|
|
214
|
-
warn("
|
|
229
|
+
detail(t("sesWindow", { days: settings.sessions.days, max: settings.sessions.maxSessions }));
|
|
230
|
+
detail(t("sesCap", { size: formatBytes(settings.sessions.maxSessionBytes) }));
|
|
231
|
+
warn(t("sessionsWarn"));
|
|
215
232
|
}
|
|
216
233
|
write();
|
|
217
234
|
return;
|
|
218
235
|
}
|
|
219
|
-
throw new SyncError(
|
|
236
|
+
throw new SyncError(t("sesUnknown", { sub }));
|
|
237
|
+
}
|
|
238
|
+
async function runRepair(args) {
|
|
239
|
+
banner(t("rpTitle"));
|
|
240
|
+
if (!(await sqliteAvailable())) {
|
|
241
|
+
fail(t("sesNoSqlite"));
|
|
242
|
+
write();
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const apply = args.flags.has("apply");
|
|
246
|
+
const result = await repairSessions(getDatabasePath(getRoots()), { apply });
|
|
247
|
+
if (!result.supported) {
|
|
248
|
+
info(t("rpNotV2"));
|
|
249
|
+
write();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (result.moves.length === 0 && result.unresolved.length === 0) {
|
|
253
|
+
ok(t("rpNothing"));
|
|
254
|
+
write();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
info(t("rpSummary", { sessions: result.sessions, moves: result.moves.length }));
|
|
258
|
+
const groups = new Map();
|
|
259
|
+
let parked = 0;
|
|
260
|
+
for (const move of result.moves) {
|
|
261
|
+
if (move.parked)
|
|
262
|
+
parked++;
|
|
263
|
+
const key = `${move.from}\u0000${move.to}`;
|
|
264
|
+
groups.set(key, (groups.get(key) ?? 0) + 1);
|
|
265
|
+
}
|
|
266
|
+
for (const [key, n] of groups) {
|
|
267
|
+
const [from, to] = key.split("\u0000");
|
|
268
|
+
detail(t("rpMove", { n, from: from ?? "", to: to ?? "" }));
|
|
269
|
+
}
|
|
270
|
+
if (parked > 0)
|
|
271
|
+
detail(t("rpParked", { n: parked }));
|
|
272
|
+
for (const u of result.unresolved) {
|
|
273
|
+
detail(t("rpUnresolved", { n: u.count, directory: u.directory }));
|
|
274
|
+
}
|
|
275
|
+
write();
|
|
276
|
+
if (apply)
|
|
277
|
+
ok(t("rpApplied", { n: result.applied }));
|
|
278
|
+
else if (result.moves.length > 0)
|
|
279
|
+
info(t("rpDryRun"));
|
|
280
|
+
write();
|
|
220
281
|
}
|
|
221
282
|
function runOverrides() {
|
|
222
|
-
banner("
|
|
283
|
+
banner(t("ovCliTitle"));
|
|
223
284
|
const roots = getRoots();
|
|
224
285
|
const file = overridesPath(roots.config);
|
|
225
286
|
if (!fs.existsSync(file)) {
|
|
226
287
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
227
288
|
fs.writeFileSync(file, OVERRIDES_TEMPLATE);
|
|
228
|
-
ok("
|
|
289
|
+
ok(t("ovCreated"));
|
|
229
290
|
}
|
|
230
291
|
detail(file);
|
|
231
292
|
write();
|
|
232
|
-
info("
|
|
293
|
+
info(t("ovCliInfo"));
|
|
233
294
|
write();
|
|
234
295
|
}
|
|
235
296
|
function runConfig() {
|
|
236
|
-
banner("
|
|
297
|
+
banner(t("cfgTitle"));
|
|
237
298
|
const roots = getRoots();
|
|
238
299
|
const file = settingsPath(roots.config);
|
|
239
300
|
if (!fs.existsSync(file)) {
|
|
240
|
-
fail("
|
|
301
|
+
fail(t("cfgMissing"));
|
|
241
302
|
write();
|
|
242
303
|
return;
|
|
243
304
|
}
|
|
@@ -246,39 +307,219 @@ function runConfig() {
|
|
|
246
307
|
write(fs.readFileSync(file, "utf8").trimEnd());
|
|
247
308
|
write();
|
|
248
309
|
}
|
|
310
|
+
async function runAutosyncCommand(args) {
|
|
311
|
+
const sub = args.positional[0] ?? "status";
|
|
312
|
+
const roots = getRoots();
|
|
313
|
+
const ctx = { roots, scheduler: realScheduler };
|
|
314
|
+
switch (sub) {
|
|
315
|
+
case "run": {
|
|
316
|
+
// Called by the scheduler: no banner, no colour noise, one log line.
|
|
317
|
+
const trigger = args.values.get("trigger") ?? "scheduled";
|
|
318
|
+
const outcomeResult = await runAutosync(autosyncDeps(roots), trigger);
|
|
319
|
+
write(outcomeResult.action === "skip"
|
|
320
|
+
? t("asRunSkipped", { reason: outcomeResult.reason })
|
|
321
|
+
: t("asRunDone", {
|
|
322
|
+
action: outcomeResult.action,
|
|
323
|
+
message: outcomeResult.message ?? outcomeResult.reason,
|
|
324
|
+
}));
|
|
325
|
+
if (!outcomeResult.ok)
|
|
326
|
+
process.exitCode = 1;
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
case "install": {
|
|
330
|
+
banner(t("asTitle"));
|
|
331
|
+
const settings = loadSettings(roots.config);
|
|
332
|
+
const result = realScheduler.install(roots, settings);
|
|
333
|
+
if (!result.ok) {
|
|
334
|
+
fail(t("autoInstallFailed", { error: result.detail.join("; ") }));
|
|
335
|
+
process.exitCode = 1;
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
ok(t("asInstalled", { kind: result.kind }));
|
|
339
|
+
for (const d of result.detail)
|
|
340
|
+
detail(d);
|
|
341
|
+
for (const w of result.warnings)
|
|
342
|
+
warn(t("autoWarning", { text: w }));
|
|
343
|
+
if (!settings.autosync.enabled)
|
|
344
|
+
warn(`${t("autoOff")} opencode-sync autosync enable`);
|
|
345
|
+
write();
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
case "uninstall": {
|
|
349
|
+
banner(t("asTitle"));
|
|
350
|
+
const result = realScheduler.uninstall(roots);
|
|
351
|
+
ok(result.removed ? t("asUninstalled") : t("asNotInstalled"));
|
|
352
|
+
write();
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
case "enable": {
|
|
356
|
+
banner(t("asTitle"));
|
|
357
|
+
const interval = Number(args.values.get("interval"));
|
|
358
|
+
if (Number.isFinite(interval) && interval >= 2) {
|
|
359
|
+
const s = loadSettings(roots.config);
|
|
360
|
+
s.autosync.intervalMinutes = Math.floor(interval);
|
|
361
|
+
saveSettings(s, roots.config);
|
|
362
|
+
}
|
|
363
|
+
if (!(await enableAutosync(ctx)))
|
|
364
|
+
process.exitCode = 1;
|
|
365
|
+
write();
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
case "disable":
|
|
369
|
+
banner(t("asTitle"));
|
|
370
|
+
disableAutosync(ctx);
|
|
371
|
+
write();
|
|
372
|
+
return;
|
|
373
|
+
case "reset": {
|
|
374
|
+
banner(t("asTitle"));
|
|
375
|
+
const before = failureCount(readState(roots));
|
|
376
|
+
writeState(roots, {
|
|
377
|
+
consecutiveFailures: 0,
|
|
378
|
+
lastError: null,
|
|
379
|
+
failureNotifiedAt: null,
|
|
380
|
+
lastAttemptAt: 0,
|
|
381
|
+
});
|
|
382
|
+
appendLog(roots, `reset: cleared ${before} failure(s)`);
|
|
383
|
+
ok(t("resetDone", { n: before }));
|
|
384
|
+
write();
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
case "pause":
|
|
388
|
+
case "resume": {
|
|
389
|
+
banner(t("asTitle"));
|
|
390
|
+
const s = loadSettings(roots.config);
|
|
391
|
+
if (sub === "resume") {
|
|
392
|
+
s.autosync.pausedUntil = 0;
|
|
393
|
+
saveSettings(s, roots.config);
|
|
394
|
+
ok(t("resumed"));
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
const arg = args.positional[1] ?? "1";
|
|
398
|
+
const until = arg === "tomorrow" ? tomorrowMorning() : Date.now() + Number(arg) * 3600_000;
|
|
399
|
+
if (!Number.isFinite(until) || until <= Date.now())
|
|
400
|
+
throw new SyncError(t("asPauseUsage"));
|
|
401
|
+
s.autosync.pausedUntil = until;
|
|
402
|
+
saveSettings(s, roots.config);
|
|
403
|
+
ok(t("pausedUntil", { time: formatTime(until) }));
|
|
404
|
+
}
|
|
405
|
+
write();
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
case "status": {
|
|
409
|
+
banner(t("asTitle"));
|
|
410
|
+
const s = loadSettings(roots.config);
|
|
411
|
+
const state = readState(roots);
|
|
412
|
+
const sched = realScheduler.status();
|
|
413
|
+
keyValue(t("asEnabled"), s.autosync.enabled ? paint(t("on"), style.green) : paint(t("off"), style.muted), 20);
|
|
414
|
+
keyValue(t("asInterval"), t("intervalMinutes", { n: s.autosync.intervalMinutes }), 20);
|
|
415
|
+
keyValue(t("asScheduler"), sched.installed
|
|
416
|
+
? `${t("diagRegistered", { kind: sched.kind })}${sched.nextRun ? ` · ${sched.nextRun}` : ""}`
|
|
417
|
+
: t("diagNotRegistered"), 20);
|
|
418
|
+
if (s.autosync.pausedUntil > Date.now())
|
|
419
|
+
keyValue(t("asPaused"), formatTime(s.autosync.pausedUntil), 20);
|
|
420
|
+
keyValue(t("asLastRun"), ago(state.lastRunAt), 20);
|
|
421
|
+
keyValue(t("asLastSuccess"), ago(state.lastSuccessAt), 20);
|
|
422
|
+
if (state.lastOutcome)
|
|
423
|
+
keyValue(t("asOutcome"), state.lastOutcome, 20);
|
|
424
|
+
const failures = failureCount(state);
|
|
425
|
+
if (failures)
|
|
426
|
+
keyValue(t("asFailures"), String(failures), 20);
|
|
427
|
+
const wait = backoffRemainingMs(state, Date.now());
|
|
428
|
+
if (wait > 0)
|
|
429
|
+
keyValue(t("asNextAttempt"), t("inMinutes", { n: Math.ceil(wait / 60000) }), 20);
|
|
430
|
+
if (state.lastError)
|
|
431
|
+
keyValue(t("asLastError"), paint(state.lastError, style.red), 20);
|
|
432
|
+
write();
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
default:
|
|
436
|
+
throw new SyncError(t("asUsage"));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function setupFlags(args) {
|
|
440
|
+
const mode = (args.values.get("mode") ?? "cli");
|
|
441
|
+
if (!["cli", "link", "auto"].includes(mode))
|
|
442
|
+
throw new SetupError(t("invalidValue", { value: mode }));
|
|
443
|
+
const interval = args.values.get("interval");
|
|
444
|
+
const prefer = args.values.get("prefer");
|
|
445
|
+
return {
|
|
446
|
+
mode,
|
|
447
|
+
repo: args.values.get("repo") ?? args.positional[0],
|
|
448
|
+
interval: interval ? Number(interval) : undefined,
|
|
449
|
+
lang: args.values.get("lang"),
|
|
450
|
+
proxy: args.values.get("proxy"),
|
|
451
|
+
prefer: prefer === "local" ? "local" : prefer === "repo" ? "repo" : undefined,
|
|
452
|
+
};
|
|
453
|
+
}
|
|
249
454
|
function runHelp() {
|
|
250
|
-
banner("
|
|
251
|
-
heading("
|
|
252
|
-
command("
|
|
253
|
-
command("
|
|
254
|
-
|
|
255
|
-
command("
|
|
256
|
-
|
|
257
|
-
command("
|
|
258
|
-
|
|
259
|
-
command("
|
|
260
|
-
|
|
261
|
-
command("
|
|
262
|
-
command("
|
|
263
|
-
|
|
264
|
-
command("
|
|
265
|
-
command("
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
command("
|
|
455
|
+
banner(t("helpTitle"));
|
|
456
|
+
heading(t("helpSetup"));
|
|
457
|
+
command("(no arguments) | menu", t("helpMenu"));
|
|
458
|
+
command("init [name|owner/repo]", t("helpInit"));
|
|
459
|
+
command("link <owner/repo|url>", t("helpLink"));
|
|
460
|
+
command("setup --mode cli|link|auto", t("helpSetupCmd"));
|
|
461
|
+
heading(t("helpSync"));
|
|
462
|
+
command("push", t("helpPush"));
|
|
463
|
+
command("pull", t("helpPull"));
|
|
464
|
+
command("status", t("helpStatus"));
|
|
465
|
+
heading(t("helpAutosync"));
|
|
466
|
+
command("autosync install | uninstall", t("helpAsInstall"));
|
|
467
|
+
command("autosync enable | disable", t("helpAsToggle"));
|
|
468
|
+
command("autosync status", t("helpAsStatus"));
|
|
469
|
+
command("autosync run", t("helpAsRun"));
|
|
470
|
+
command("autosync pause <h> | resume", t("helpAsPause"));
|
|
471
|
+
command("autosync reset", t("helpAsReset"));
|
|
472
|
+
heading(t("helpSessions"));
|
|
473
|
+
command("sessions list", t("helpSesList"));
|
|
474
|
+
command("sessions enable | disable", t("helpSesToggle"));
|
|
475
|
+
command("sessions include <id>", t("helpSesInclude"));
|
|
476
|
+
command("sessions exclude <id>", t("helpSesExclude"));
|
|
477
|
+
command("repair-sessions [--apply]", t("helpRepair"));
|
|
478
|
+
heading(t("helpLocal"));
|
|
479
|
+
command("overrides", t("helpOverrides"));
|
|
480
|
+
command("config", t("helpConfig"));
|
|
481
|
+
heading(t("helpFlags"));
|
|
482
|
+
command("--force", t("helpForce"));
|
|
483
|
+
command("--dry-run", t("helpDryRun"));
|
|
484
|
+
command("--allow-large", t("helpAllowLarge"));
|
|
485
|
+
command("--yes", t("helpYes"));
|
|
486
|
+
command("--prefer repo|local", t("helpPrefer"));
|
|
487
|
+
command("--lang en|zh-CN", t("helpLang"));
|
|
269
488
|
write();
|
|
270
489
|
rule();
|
|
271
|
-
write(` ${paint("docs", style.faint)} ${paint("https://github.com/
|
|
490
|
+
write(` ${paint("docs", style.faint)} ${paint("https://github.com/lazyalex616/opencode-github-sync", style.muted)}`);
|
|
272
491
|
write();
|
|
273
492
|
}
|
|
274
493
|
function command(name, description) {
|
|
275
|
-
const padded = name.padEnd(
|
|
494
|
+
const padded = name.padEnd(32);
|
|
276
495
|
write(` ${paint(padded, style.cyan)}${paint(description, style.muted)}`);
|
|
277
496
|
}
|
|
278
497
|
// ── Entry point ─────────────────────────────────────────────────────────────
|
|
279
498
|
async function main() {
|
|
280
499
|
const args = parseArgs(process.argv.slice(2));
|
|
500
|
+
const roots = getRoots();
|
|
501
|
+
applyLocalSettings(safeLoadSettings(roots), args.values.get("lang"));
|
|
281
502
|
switch (args.command) {
|
|
503
|
+
case "menu": {
|
|
504
|
+
const ui = newUi();
|
|
505
|
+
try {
|
|
506
|
+
await runMenu({ ui, roots });
|
|
507
|
+
}
|
|
508
|
+
finally {
|
|
509
|
+
ui.close();
|
|
510
|
+
}
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
case "setup": {
|
|
514
|
+
const ui = newUi();
|
|
515
|
+
try {
|
|
516
|
+
await runSetup(setupFlags(args), { ui, roots });
|
|
517
|
+
}
|
|
518
|
+
finally {
|
|
519
|
+
ui.close();
|
|
520
|
+
}
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
282
523
|
case "push":
|
|
283
524
|
case "pull":
|
|
284
525
|
await runSync(args.command, args);
|
|
@@ -295,6 +536,12 @@ async function main() {
|
|
|
295
536
|
case "sessions":
|
|
296
537
|
await runSessions(args);
|
|
297
538
|
return;
|
|
539
|
+
case "repair-sessions":
|
|
540
|
+
await runRepair(args);
|
|
541
|
+
return;
|
|
542
|
+
case "autosync":
|
|
543
|
+
await runAutosyncCommand(args);
|
|
544
|
+
return;
|
|
298
545
|
case "overrides":
|
|
299
546
|
runOverrides();
|
|
300
547
|
return;
|
|
@@ -308,9 +555,9 @@ async function main() {
|
|
|
308
555
|
return;
|
|
309
556
|
default:
|
|
310
557
|
banner();
|
|
311
|
-
fail(
|
|
558
|
+
fail(t("cliUnknown", { cmd: args.command }));
|
|
312
559
|
write();
|
|
313
|
-
info("
|
|
560
|
+
info(t("cliHelpHint"));
|
|
314
561
|
write();
|
|
315
562
|
process.exitCode = 1;
|
|
316
563
|
}
|