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.
- package/README.md +353 -159
- package/README.zh-CN.md +246 -100
- package/dist/cli/i18n.d.ts +10 -0
- package/dist/cli/i18n.d.ts.map +1 -1
- package/dist/cli/i18n.js +24 -4
- package/dist/cli/i18n.js.map +1 -1
- package/dist/cli/index.js +50 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/core/autosync.d.ts +2 -0
- package/dist/core/autosync.d.ts.map +1 -1
- package/dist/core/autosync.js +9 -0
- package/dist/core/autosync.js.map +1 -1
- package/dist/core/categories.js +1 -1
- package/dist/core/categories.js.map +1 -1
- 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/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/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/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/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 +20 -2
- package/dist/core/repo.d.ts.map +1 -1
- package/dist/core/repo.js +65 -3
- 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/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 +6 -0
- package/dist/core/settings.d.ts.map +1 -1
- package/dist/core/settings.js +1 -0
- package/dist/core/settings.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 +14 -1
- package/dist/core/stage.d.ts.map +1 -1
- package/dist/core/stage.js +63 -3
- package/dist/core/stage.js.map +1 -1
- package/dist/core/sync.d.ts.map +1 -1
- package/dist/core/sync.js +66 -16
- package/dist/core/sync.js.map +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +2 -2
- package/dist/plugin/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { bridgeCredentials, hasCredentialTable } from "./credentials.js";
|
|
5
|
+
import { childEnv } from "./env.js";
|
|
6
|
+
import { git } from "./git.js";
|
|
7
|
+
import { hostAlias } from "./host.js";
|
|
8
|
+
import { DATA_DIR, getDatabasePath } from "./paths.js";
|
|
9
|
+
import { repoBranch } from "./settings.js";
|
|
10
|
+
import { sqliteAvailable } from "./sqlite.js";
|
|
11
|
+
/**
|
|
12
|
+
* One machine renews the shared ChatGPT (OpenAI OAuth) login, never several.
|
|
13
|
+
*
|
|
14
|
+
* With credential sync on, every machine holds the same OpenAI login. A
|
|
15
|
+
* refresh returns a new refresh token and invalidates the old one, so when two
|
|
16
|
+
* machines refresh the same login the second one is left with a dead token —
|
|
17
|
+
* machines log each other out. This lease makes exactly one machine refresh
|
|
18
|
+
* per expiry window, three days before the token would expire; the next sync
|
|
19
|
+
* carries the new token to everyone else long before they would need it.
|
|
20
|
+
*
|
|
21
|
+
* The lease is a dedicated git ref, `refs/leases/openai`, in the sync
|
|
22
|
+
* repository. Pushing it with `--force-with-lease` is an atomic
|
|
23
|
+
* compare-and-swap on the server: of two machines claiming at the same moment,
|
|
24
|
+
* one push is rejected. The claim never touches a branch or the worktree, so
|
|
25
|
+
* it cannot conflict with an ordinary sync. A claim older than the TTL is
|
|
26
|
+
* stale (its owner crashed or lost the network) and may be taken over.
|
|
27
|
+
*
|
|
28
|
+
* Runs only from the scheduled job, and only when credential sync is on and
|
|
29
|
+
* this machine has an OpenAI login with a refresh token.
|
|
30
|
+
*/
|
|
31
|
+
export const LEASE_REF = "refs/leases/openai";
|
|
32
|
+
export const MARGIN_MS = 3 * 24 * 60 * 60 * 1000;
|
|
33
|
+
export const LEASE_TTL_MS = 15 * 60 * 1000;
|
|
34
|
+
const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
35
|
+
const DEFAULT_TOKEN_URL = "https://auth.openai.com/oauth/token";
|
|
36
|
+
function authFile(roots) {
|
|
37
|
+
return path.join(roots.data, "auth.json");
|
|
38
|
+
}
|
|
39
|
+
function readAuth(roots) {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(fs.readFileSync(authFile(roots), "utf8").replace(/^\uFEFF/, ""));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Expiry of the OpenAI login in a credential map, or undefined when there is none to renew. */
|
|
48
|
+
export function openaiExpiry(auth) {
|
|
49
|
+
const entry = auth?.openai;
|
|
50
|
+
if (!entry || entry.type !== "oauth" || typeof entry.refresh !== "string")
|
|
51
|
+
return undefined;
|
|
52
|
+
return typeof entry.expires === "number" ? entry.expires : 0;
|
|
53
|
+
}
|
|
54
|
+
/** Due when neither this machine nor the published copy is safely in date. */
|
|
55
|
+
export function isDue(now, live, published) {
|
|
56
|
+
if (live === undefined)
|
|
57
|
+
return false;
|
|
58
|
+
return Math.max(live, published ?? 0) - now < MARGIN_MS;
|
|
59
|
+
}
|
|
60
|
+
function publishedExpiry(root, branch) {
|
|
61
|
+
const shown = git(["show", `origin/${branch}:${DATA_DIR}/auth.json`], { cwd: root });
|
|
62
|
+
if (!shown.ok)
|
|
63
|
+
return undefined;
|
|
64
|
+
try {
|
|
65
|
+
return openaiExpiry(JSON.parse(shown.stdout));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function readLease(root) {
|
|
72
|
+
const fetched = git(["fetch", "-q", "origin", `+${LEASE_REF}:${LEASE_REF}`], {
|
|
73
|
+
cwd: root,
|
|
74
|
+
timeoutMs: 60_000,
|
|
75
|
+
});
|
|
76
|
+
if (!fetched.ok) {
|
|
77
|
+
if (/couldn't find remote ref|no such ref|not our ref/i.test(fetched.stderr)) {
|
|
78
|
+
git(["update-ref", "-d", LEASE_REF], { cwd: root });
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`lease fetch failed: ${fetched.stderr.split("\n")[0]}`);
|
|
82
|
+
}
|
|
83
|
+
const sha = git(["rev-parse", LEASE_REF], { cwd: root }).stdout;
|
|
84
|
+
let body = {};
|
|
85
|
+
try {
|
|
86
|
+
body = JSON.parse(git(["log", "-1", "--format=%B", sha], { cwd: root }).stdout);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// An unreadable claim counts as stale.
|
|
90
|
+
}
|
|
91
|
+
return { sha, machine: body.machine, at: Number(body.at) || 0 };
|
|
92
|
+
}
|
|
93
|
+
/** Try to take the lease. True only when this machine's push won the compare-and-swap. */
|
|
94
|
+
function claim(root, previous, machine, now) {
|
|
95
|
+
const tree = git(["mktree"], { cwd: root });
|
|
96
|
+
if (!tree.ok)
|
|
97
|
+
return false;
|
|
98
|
+
const message = JSON.stringify({ machine, at: now });
|
|
99
|
+
const commit = git(["commit-tree", tree.stdout, "-m", message], { cwd: root });
|
|
100
|
+
if (!commit.ok)
|
|
101
|
+
return false;
|
|
102
|
+
const expect = `--force-with-lease=${LEASE_REF}:${previous ? previous.sha : ""}`;
|
|
103
|
+
return git(["push", "-q", expect, "origin", `${commit.stdout}:${LEASE_REF}`], {
|
|
104
|
+
cwd: root,
|
|
105
|
+
timeoutMs: 60_000,
|
|
106
|
+
}).ok;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Run the token request in a child Node process. Node's built-in `fetch`
|
|
110
|
+
* ignores proxy variables unless `NODE_USE_ENV_PROXY` is set at start-up, and
|
|
111
|
+
* the configured proxy must reach this request like every git call. The
|
|
112
|
+
* refresh token travels on stdin, never on a command line.
|
|
113
|
+
*/
|
|
114
|
+
const CHILD_SCRIPT = `
|
|
115
|
+
let input = "";
|
|
116
|
+
process.stdin.on("data", (c) => (input += c));
|
|
117
|
+
process.stdin.on("end", async () => {
|
|
118
|
+
const { url, body } = JSON.parse(input);
|
|
119
|
+
try {
|
|
120
|
+
const r = await fetch(url, {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers: { "content-type": "application/json" },
|
|
123
|
+
body: JSON.stringify(body),
|
|
124
|
+
signal: AbortSignal.timeout(30000),
|
|
125
|
+
});
|
|
126
|
+
const text = await r.text();
|
|
127
|
+
process.stdout.write(JSON.stringify({ status: r.status, text }));
|
|
128
|
+
} catch (e) {
|
|
129
|
+
process.stdout.write(JSON.stringify({ error: String(e && e.message || e) }));
|
|
130
|
+
}
|
|
131
|
+
});`;
|
|
132
|
+
export function refreshInChild(refreshToken) {
|
|
133
|
+
const url = process.env.OPENCODE_OPENAI_TOKEN_URL || DEFAULT_TOKEN_URL;
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
const child = spawn(process.execPath, ["-e", CHILD_SCRIPT], {
|
|
136
|
+
env: childEnv({ NODE_USE_ENV_PROXY: "1" }),
|
|
137
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
138
|
+
windowsHide: true,
|
|
139
|
+
});
|
|
140
|
+
let out = "";
|
|
141
|
+
const timer = setTimeout(() => child.kill(), 60_000);
|
|
142
|
+
child.stdout.on("data", (chunk) => {
|
|
143
|
+
out += chunk;
|
|
144
|
+
});
|
|
145
|
+
child.on("error", (err) => {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
reject(err);
|
|
148
|
+
});
|
|
149
|
+
child.on("close", () => {
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
try {
|
|
152
|
+
const result = JSON.parse(out);
|
|
153
|
+
if (result.error)
|
|
154
|
+
return reject(new Error(result.error));
|
|
155
|
+
if (result.status < 200 || result.status >= 300) {
|
|
156
|
+
return reject(new Error(`HTTP ${result.status}`));
|
|
157
|
+
}
|
|
158
|
+
const token = JSON.parse(result.text);
|
|
159
|
+
if (!token.access_token)
|
|
160
|
+
return reject(new Error("no access_token in response"));
|
|
161
|
+
resolve(token);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
reject(new Error("no response from the token endpoint"));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
child.stdin.end(JSON.stringify({
|
|
168
|
+
url,
|
|
169
|
+
body: { grant_type: "refresh_token", refresh_token: refreshToken, client_id: CLIENT_ID },
|
|
170
|
+
}));
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function writeOpenai(roots, fields) {
|
|
174
|
+
// Re-read right before writing so a concurrent change to other providers is kept.
|
|
175
|
+
const current = readAuth(roots) ?? {};
|
|
176
|
+
current.openai = { ...current.openai, ...fields };
|
|
177
|
+
const file = authFile(roots);
|
|
178
|
+
const temp = `${file}.lease-${process.pid}.tmp`;
|
|
179
|
+
fs.writeFileSync(temp, `${JSON.stringify(current, null, 2)}\n`, { mode: 0o600 });
|
|
180
|
+
fs.renameSync(temp, file);
|
|
181
|
+
}
|
|
182
|
+
/** Whether the lease applies to this machine at all. */
|
|
183
|
+
export function leaseEnabled(settings) {
|
|
184
|
+
return settings.includeCredentials && settings.openaiRefreshLease !== false;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* One check. Returns a short outcome for the autosync log; never throws and
|
|
188
|
+
* never includes a token.
|
|
189
|
+
*/
|
|
190
|
+
export async function maybeRefreshOpenai(deps) {
|
|
191
|
+
const { roots, settings } = deps;
|
|
192
|
+
if (!leaseEnabled(settings))
|
|
193
|
+
return "off";
|
|
194
|
+
const now = (deps.now ?? Date.now)();
|
|
195
|
+
try {
|
|
196
|
+
const v2 = (await sqliteAvailable()) && (await hasCredentialTable(getDatabasePath(roots)));
|
|
197
|
+
// On OpenCode 2 the database is the newer truth: OpenCode may have
|
|
198
|
+
// refreshed the token by itself since the last sync.
|
|
199
|
+
if (v2)
|
|
200
|
+
await bridgeCredentials(roots.data, "database", now);
|
|
201
|
+
const auth = readAuth(roots);
|
|
202
|
+
const live = openaiExpiry(auth);
|
|
203
|
+
if (live === undefined)
|
|
204
|
+
return "no OpenAI login here";
|
|
205
|
+
if (!isDue(now, live, publishedExpiry(roots.config, repoBranch(settings))))
|
|
206
|
+
return "not due";
|
|
207
|
+
const machine = hostAlias(settings.machineAlias);
|
|
208
|
+
const lease = readLease(roots.config);
|
|
209
|
+
if (lease && lease.machine !== machine && now - lease.at < LEASE_TTL_MS) {
|
|
210
|
+
return `held by ${lease.machine ?? "another machine"}`;
|
|
211
|
+
}
|
|
212
|
+
if (!claim(roots.config, lease, machine, now))
|
|
213
|
+
return "lost the claim to another machine";
|
|
214
|
+
let token;
|
|
215
|
+
try {
|
|
216
|
+
token = await (deps.refresh ?? refreshInChild)(auth.openai.refresh);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
return `claimed; refresh failed (${error.message})`;
|
|
220
|
+
}
|
|
221
|
+
const expires = now + (token.expires_in ?? 864_000) * 1000;
|
|
222
|
+
writeOpenai(roots, {
|
|
223
|
+
access: token.access_token,
|
|
224
|
+
refresh: token.refresh_token ?? auth.openai.refresh,
|
|
225
|
+
expires,
|
|
226
|
+
});
|
|
227
|
+
if (v2)
|
|
228
|
+
await bridgeCredentials(roots.data, "file", now);
|
|
229
|
+
return `claimed; refreshed, valid until ${new Date(expires).toISOString()}`;
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
return `error (${String(error.message).split("\n")[0]})`;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=lease.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease.js","sourceRoot":"","sources":["../../src/core/lease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAc,eAAe,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAiB,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,oBAAoB,CAAC;AAC9C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACjD,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,MAAM,SAAS,GAAG,8BAA8B,CAAC;AACjD,MAAM,iBAAiB,GAAG,qCAAqC,CAAC;AAkBhE,SAAS,QAAQ,CAAC,KAAY;IAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAC5C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KAAK,EAAE,OAAO,EAAE,GAAG,CAAC;YAAE,OAAO,mCAAmC,CAAC;QAE1F,IAAI,KAAoB,CAAC;QACzB,IAAI,CAAC;YACH,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,cAAc,CAAC,CAAC,IAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,4BAA6B,KAAe,CAAC,OAAO,GAAG,CAAC;QACjE,CAAC;QACD,MAAM,OAAO,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,IAAI,CAAC;QAC3D,WAAW,CAAC,KAAK,EAAE;YACjB,MAAM,EAAE,KAAK,CAAC,YAAY;YAC1B,OAAO,EAAE,KAAK,CAAC,aAAa,IAAI,IAAK,CAAC,MAAM,CAAC,OAAO;YACpD,OAAO;SACR,CAAC,CAAC;QACH,IAAI,EAAE;YAAE,MAAM,iBAAiB,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACzD,OAAO,mCAAmC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;IAC9E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,UAAU,MAAM,CAAE,KAAe,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACtE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type Row } from "./rows.js";
|
|
2
|
+
import type { SqliteDatabase } from "./sqlite.js";
|
|
3
|
+
/**
|
|
4
|
+
* Where an OpenCode 2 session belongs.
|
|
5
|
+
*
|
|
6
|
+
* OpenCode 2 lists only the sessions of the project it resolves for the
|
|
7
|
+
* current directory. A session whose `project_id` this machine would resolve
|
|
8
|
+
* differently exists in the database but never shows up in `/session`. Every
|
|
9
|
+
* imported session, and every session OpenCode itself migrated from 1.x, is
|
|
10
|
+
* therefore placed the way OpenCode 2 would place it here:
|
|
11
|
+
*
|
|
12
|
+
* - the newest project whose worktree is the session directory, or the
|
|
13
|
+
* deepest git worktree that contains it;
|
|
14
|
+
* - otherwise a project created with the id OpenCode 2 derives itself
|
|
15
|
+
* (`sha1("directory:" + path)` for a plain directory);
|
|
16
|
+
* - otherwise, for a directory this machine does not have, the home
|
|
17
|
+
* directory's project, which is where `/session` is normally opened.
|
|
18
|
+
*
|
|
19
|
+
* Project ids are deterministic in OpenCode 2 (git remote, root commit or
|
|
20
|
+
* directory path), so a project row from another machine is reused as is when
|
|
21
|
+
* its worktree also exists here.
|
|
22
|
+
*/
|
|
23
|
+
export declare const GLOBAL_PROJECT_ID = "global";
|
|
24
|
+
export interface Placement {
|
|
25
|
+
projectId: string;
|
|
26
|
+
directory: string;
|
|
27
|
+
path: string | null;
|
|
28
|
+
/** Parked in the home project because no project matches the directory. */
|
|
29
|
+
parked: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface PlacementInput {
|
|
32
|
+
directory: string;
|
|
33
|
+
projectId: string;
|
|
34
|
+
path: string | null;
|
|
35
|
+
/** The exporting machine's home directory, to map paths under it. */
|
|
36
|
+
originHome?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface PlacementOptions {
|
|
39
|
+
/** This machine's home directory. */
|
|
40
|
+
home: string;
|
|
41
|
+
/** Create project rows OpenCode 2 would create itself. */
|
|
42
|
+
createProjects: boolean;
|
|
43
|
+
now: number;
|
|
44
|
+
/** Test seam: whether a directory exists on this machine. */
|
|
45
|
+
exists?: (dir: string) => boolean;
|
|
46
|
+
}
|
|
47
|
+
interface ProjectRow {
|
|
48
|
+
id: string;
|
|
49
|
+
worktree: string;
|
|
50
|
+
vcs: string | null;
|
|
51
|
+
time_created: number;
|
|
52
|
+
}
|
|
53
|
+
/** OpenCode 2 stores Windows paths with forward slashes. */
|
|
54
|
+
export declare function storedPath(p: string): string;
|
|
55
|
+
/** The project id OpenCode 2 gives a directory outside any repository. */
|
|
56
|
+
export declare function directoryProjectId(directory: string): string;
|
|
57
|
+
export declare function homeDir(): string;
|
|
58
|
+
/** Relative path from a worktree to a directory, the way OpenCode 2 writes it. */
|
|
59
|
+
export declare function relativePath(directory: string, worktree: string, fallback: string | null): string | null;
|
|
60
|
+
export declare class ProjectResolver {
|
|
61
|
+
private readonly db;
|
|
62
|
+
private readonly options;
|
|
63
|
+
private projects;
|
|
64
|
+
private readonly exists;
|
|
65
|
+
constructor(db: SqliteDatabase, options: PlacementOptions);
|
|
66
|
+
private load;
|
|
67
|
+
/** The project OpenCode 2 resolves today for a directory, if it has one. */
|
|
68
|
+
resolve(directory: string): ProjectRow | undefined;
|
|
69
|
+
/** Insert another machine's project row when its worktree exists here too. */
|
|
70
|
+
adopt(project: Row | undefined, insert: (row: Row) => void): void;
|
|
71
|
+
private createDirectoryProject;
|
|
72
|
+
private home;
|
|
73
|
+
/** Map a directory under the exporting machine's home onto this machine's home. */
|
|
74
|
+
private translate;
|
|
75
|
+
/** Where a session belongs on this machine. */
|
|
76
|
+
place(session: PlacementInput): Placement;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=projects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/core/projects.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,iBAAiB,WAAW,CAAC;AAE1C,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,2EAA2E;IAC3E,MAAM,EAAE,O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AE,MAAM,GAAG,UAAU,GAAG,SAAS;IAiBlD,8EAA8E;IAC9E,KAAK,CAAC,OAAO,EAAE,GAAG,GAAG,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IASjE,OAAO,CAAC,sBAAsB;IAe9B,OAAO,CAAC,IAAI;IAKZ,mFAAmF;IACnF,OAAO,CAAC,SAAS;IAUjB,+CAA+C;IAC/C,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS;CAiC1C"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { readRows } from "./rows.js";
|
|
6
|
+
/**
|
|
7
|
+
* Where an OpenCode 2 session belongs.
|
|
8
|
+
*
|
|
9
|
+
* OpenCode 2 lists only the sessions of the project it resolves for the
|
|
10
|
+
* current directory. A session whose `project_id` this machine would resolve
|
|
11
|
+
* differently exists in the database but never shows up in `/session`. Every
|
|
12
|
+
* imported session, and every session OpenCode itself migrated from 1.x, is
|
|
13
|
+
* therefore placed the way OpenCode 2 would place it here:
|
|
14
|
+
*
|
|
15
|
+
* - the newest project whose worktree is the session directory, or the
|
|
16
|
+
* deepest git worktree that contains it;
|
|
17
|
+
* - otherwise a project created with the id OpenCode 2 derives itself
|
|
18
|
+
* (`sha1("directory:" + path)` for a plain directory);
|
|
19
|
+
* - otherwise, for a directory this machine does not have, the home
|
|
20
|
+
* directory's project, which is where `/session` is normally opened.
|
|
21
|
+
*
|
|
22
|
+
* Project ids are deterministic in OpenCode 2 (git remote, root commit or
|
|
23
|
+
* directory path), so a project row from another machine is reused as is when
|
|
24
|
+
* its worktree also exists here.
|
|
25
|
+
*/
|
|
26
|
+
export const GLOBAL_PROJECT_ID = "global";
|
|
27
|
+
const caseInsensitive = process.platform !== "linux";
|
|
28
|
+
/** OpenCode 2 stores Windows paths with forward slashes. */
|
|
29
|
+
export function storedPath(p) {
|
|
30
|
+
let out = process.platform === "win32" ? p.replace(/\\/g, "/") : p;
|
|
31
|
+
while (out.length > 1 && out.endsWith("/") && !/^[A-Za-z]:\/$/.test(out))
|
|
32
|
+
out = out.slice(0, -1);
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function key(p) {
|
|
36
|
+
const s = String(p ?? "")
|
|
37
|
+
.replace(/\\/g, "/")
|
|
38
|
+
.replace(/\/+$/, "");
|
|
39
|
+
return caseInsensitive ? s.toLowerCase() : s;
|
|
40
|
+
}
|
|
41
|
+
/** The project id OpenCode 2 gives a directory outside any repository. */
|
|
42
|
+
export function directoryProjectId(directory) {
|
|
43
|
+
return createHash("sha1")
|
|
44
|
+
.update(`directory:${path.resolve(directory)}`)
|
|
45
|
+
.digest("hex");
|
|
46
|
+
}
|
|
47
|
+
export function homeDir() {
|
|
48
|
+
return process.env.SYNC_HOME || os.homedir();
|
|
49
|
+
}
|
|
50
|
+
/** Relative path from a worktree to a directory, the way OpenCode 2 writes it. */
|
|
51
|
+
export function relativePath(directory, worktree, fallback) {
|
|
52
|
+
const d = key(directory);
|
|
53
|
+
const w = key(worktree);
|
|
54
|
+
if (d === w)
|
|
55
|
+
return "";
|
|
56
|
+
if (d.startsWith(`${w}/`))
|
|
57
|
+
return storedPath(directory).slice(storedPath(worktree).length + 1);
|
|
58
|
+
const rel = path.relative(path.resolve(worktree), path.resolve(directory));
|
|
59
|
+
if (!rel || path.isAbsolute(rel))
|
|
60
|
+
return fallback;
|
|
61
|
+
return rel.replace(/\\/g, "/");
|
|
62
|
+
}
|
|
63
|
+
function insideRepository(directory, exists) {
|
|
64
|
+
let current = path.resolve(directory);
|
|
65
|
+
for (;;) {
|
|
66
|
+
if (exists(path.join(current, ".git")) || exists(path.join(current, ".hg")))
|
|
67
|
+
return true;
|
|
68
|
+
const parent = path.dirname(current);
|
|
69
|
+
if (parent === current)
|
|
70
|
+
return false;
|
|
71
|
+
current = parent;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export class ProjectResolver {
|
|
75
|
+
db;
|
|
76
|
+
options;
|
|
77
|
+
projects;
|
|
78
|
+
exists;
|
|
79
|
+
constructor(db, options) {
|
|
80
|
+
this.db = db;
|
|
81
|
+
this.options = options;
|
|
82
|
+
this.exists = options.exists ?? ((dir) => fs.existsSync(dir));
|
|
83
|
+
this.projects = this.load();
|
|
84
|
+
}
|
|
85
|
+
load() {
|
|
86
|
+
return readRows(this.db, "SELECT id, worktree, vcs, time_created FROM project WHERE id <> ?", [
|
|
87
|
+
GLOBAL_PROJECT_ID,
|
|
88
|
+
]).map((row) => ({
|
|
89
|
+
id: String(row.id),
|
|
90
|
+
worktree: String(row.worktree ?? ""),
|
|
91
|
+
vcs: row.vcs == null ? null : String(row.vcs),
|
|
92
|
+
time_created: Number(row.time_created ?? 0),
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
/** The project OpenCode 2 resolves today for a directory, if it has one. */
|
|
96
|
+
resolve(directory) {
|
|
97
|
+
const d = key(directory);
|
|
98
|
+
const newest = new Map();
|
|
99
|
+
for (const p of this.projects) {
|
|
100
|
+
const k = key(p.worktree);
|
|
101
|
+
if (!k || k === "/")
|
|
102
|
+
continue;
|
|
103
|
+
const prev = newest.get(k);
|
|
104
|
+
if (!prev || p.time_created > prev.time_created)
|
|
105
|
+
newest.set(k, p);
|
|
106
|
+
}
|
|
107
|
+
let best;
|
|
108
|
+
for (const [k, p] of newest) {
|
|
109
|
+
const match = d === k || (p.vcs && d.startsWith(`${k}/`));
|
|
110
|
+
if (match && (!best || k.length > key(best.worktree).length))
|
|
111
|
+
best = p;
|
|
112
|
+
}
|
|
113
|
+
return best;
|
|
114
|
+
}
|
|
115
|
+
/** Insert another machine's project row when its worktree exists here too. */
|
|
116
|
+
adopt(project, insert) {
|
|
117
|
+
if (!project || String(project.id) === GLOBAL_PROJECT_ID)
|
|
118
|
+
return;
|
|
119
|
+
const worktree = String(project.worktree ?? "");
|
|
120
|
+
if (!worktree || !this.exists(worktree))
|
|
121
|
+
return;
|
|
122
|
+
if (this.projects.some((p) => p.id === String(project.id)))
|
|
123
|
+
return;
|
|
124
|
+
insert(project);
|
|
125
|
+
this.projects = this.load();
|
|
126
|
+
}
|
|
127
|
+
createDirectoryProject(directory) {
|
|
128
|
+
if (!this.options.createProjects)
|
|
129
|
+
return undefined;
|
|
130
|
+
if (!this.exists(directory) || insideRepository(directory, this.exists))
|
|
131
|
+
return undefined;
|
|
132
|
+
const id = directoryProjectId(directory);
|
|
133
|
+
const now = this.options.now;
|
|
134
|
+
this.db
|
|
135
|
+
.prepare(`INSERT INTO project (id, worktree, vcs, sandboxes, time_created, time_updated, time_active)
|
|
136
|
+
VALUES (?, ?, NULL, '[]', ?, ?, ?) ON CONFLICT DO NOTHING`)
|
|
137
|
+
.run(id, storedPath(path.resolve(directory)), now, now, now);
|
|
138
|
+
this.projects = this.load();
|
|
139
|
+
return this.projects.find((p) => p.id === id);
|
|
140
|
+
}
|
|
141
|
+
home() {
|
|
142
|
+
const home = this.options.home;
|
|
143
|
+
return this.resolve(storedPath(path.resolve(home))) ?? this.createDirectoryProject(home);
|
|
144
|
+
}
|
|
145
|
+
/** Map a directory under the exporting machine's home onto this machine's home. */
|
|
146
|
+
translate(directory, originHome) {
|
|
147
|
+
if (this.exists(directory) || !originHome)
|
|
148
|
+
return directory;
|
|
149
|
+
const from = key(originHome);
|
|
150
|
+
const d = key(directory);
|
|
151
|
+
if (!d.startsWith(`${from}/`))
|
|
152
|
+
return directory;
|
|
153
|
+
const rest = storedPath(directory).slice(storedPath(originHome).length + 1);
|
|
154
|
+
const candidate = path.join(this.options.home, ...rest.split("/"));
|
|
155
|
+
return this.exists(candidate) ? storedPath(candidate) : directory;
|
|
156
|
+
}
|
|
157
|
+
/** Where a session belongs on this machine. */
|
|
158
|
+
place(session) {
|
|
159
|
+
const directory = this.translate(session.directory, session.originHome);
|
|
160
|
+
const target = this.resolve(directory) ?? this.createDirectoryProject(directory);
|
|
161
|
+
if (target) {
|
|
162
|
+
const exact = key(directory) === key(target.worktree);
|
|
163
|
+
return {
|
|
164
|
+
projectId: target.id,
|
|
165
|
+
directory: exact ? target.worktree : storedPath(directory),
|
|
166
|
+
path: relativePath(directory, target.worktree, session.path),
|
|
167
|
+
parked: false,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const home = this.home();
|
|
171
|
+
if (!home) {
|
|
172
|
+
return {
|
|
173
|
+
projectId: session.projectId,
|
|
174
|
+
directory: session.directory,
|
|
175
|
+
path: session.path,
|
|
176
|
+
parked: false,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
// A directory this machine does not have would reopen in a missing
|
|
180
|
+
// folder, so the session moves to the home worktree itself.
|
|
181
|
+
if (!this.exists(directory)) {
|
|
182
|
+
return { projectId: home.id, directory: home.worktree, path: "", parked: true };
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
projectId: home.id,
|
|
186
|
+
directory: storedPath(directory),
|
|
187
|
+
path: relativePath(directory, home.worktree, session.path),
|
|
188
|
+
parked: true,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=projects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/core/projects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAY,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAmC1C,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAA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AmE;QACnE,4DAA4D;QAC5D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5B,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAClF,CAAC;QACD,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,EAAE;YAClB,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC;YAChC,IAAI,EAAE,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC;YAC1D,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Move OpenCode 2 sessions into the project OpenCode 2 resolves for them.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode 2 lists only the current project's sessions. Two kinds of session
|
|
5
|
+
* end up listed nowhere after an upgrade from 1.x, although their content is
|
|
6
|
+
* intact:
|
|
7
|
+
*
|
|
8
|
+
* - OpenCode 1 put every session outside a repository in the synthetic
|
|
9
|
+
* `global` project. OpenCode 2 gives such a directory its own project, so
|
|
10
|
+
* migrated `global` sessions are invisible.
|
|
11
|
+
* - A repository can have several project rows for one worktree (a new id
|
|
12
|
+
* after its history changed). OpenCode 2 uses the newest; sessions under
|
|
13
|
+
* the older rows are invisible.
|
|
14
|
+
*
|
|
15
|
+
* Only the project, directory spelling and relative path of a session change.
|
|
16
|
+
* Sessions already in the right project are not touched. A `global` session
|
|
17
|
+
* whose directory has no project yet is parked in the home project; any other
|
|
18
|
+
* unresolved session is left alone and reported. No project rows are created:
|
|
19
|
+
* OpenCode creates them itself the first time it opens a directory.
|
|
20
|
+
*/
|
|
21
|
+
export interface RepairMove {
|
|
22
|
+
id: string;
|
|
23
|
+
from: string;
|
|
24
|
+
to: string;
|
|
25
|
+
parked: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface RepairResult {
|
|
28
|
+
/** False when the database is not an OpenCode 2 database. */
|
|
29
|
+
supported: boolean;
|
|
30
|
+
sessions: number;
|
|
31
|
+
moves: RepairMove[];
|
|
32
|
+
/** `global` sessions with no project to move to, by directory. */
|
|
33
|
+
unresolved: {
|
|
34
|
+
directory: string;
|
|
35
|
+
count: number;
|
|
36
|
+
}[];
|
|
37
|
+
applied: number;
|
|
38
|
+
}
|
|
39
|
+
export interface RepairOptions {
|
|
40
|
+
apply: boolean;
|
|
41
|
+
home?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function repairSessions(databaseFile: string, options: RepairOptions): Promise<RepairResult>;
|
|
44
|
+
//# sourceMappingURL=repair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repair.d.ts","sourceRoot":"","sources":["../../src/core/repair.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,kEAAkE;IAClE,UAAU,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CA2EvB"}
|