opencode-github-sync 3.2.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +379 -160
  2. package/README.zh-CN.md +261 -101
  3. package/dist/cli/i18n.d.ts +10 -0
  4. package/dist/cli/i18n.d.ts.map +1 -1
  5. package/dist/cli/i18n.js +24 -4
  6. package/dist/cli/i18n.js.map +1 -1
  7. package/dist/cli/index.js +50 -1
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/core/autosync.d.ts +2 -0
  10. package/dist/core/autosync.d.ts.map +1 -1
  11. package/dist/core/autosync.js +9 -0
  12. package/dist/core/autosync.js.map +1 -1
  13. package/dist/core/categories.js +1 -1
  14. package/dist/core/categories.js.map +1 -1
  15. package/dist/core/credentials.d.ts +40 -0
  16. package/dist/core/credentials.d.ts.map +1 -0
  17. package/dist/core/credentials.js +364 -0
  18. package/dist/core/credentials.js.map +1 -0
  19. package/dist/core/fsx.d.ts +2 -0
  20. package/dist/core/fsx.d.ts.map +1 -1
  21. package/dist/core/fsx.js +6 -0
  22. package/dist/core/fsx.js.map +1 -1
  23. package/dist/core/lease.d.ts +52 -0
  24. package/dist/core/lease.d.ts.map +1 -0
  25. package/dist/core/lease.js +235 -0
  26. package/dist/core/lease.js.map +1 -0
  27. package/dist/core/projects.d.ts +90 -0
  28. package/dist/core/projects.d.ts.map +1 -0
  29. package/dist/core/projects.js +225 -0
  30. package/dist/core/projects.js.map +1 -0
  31. package/dist/core/repair.d.ts +44 -0
  32. package/dist/core/repair.d.ts.map +1 -0
  33. package/dist/core/repair.js +81 -0
  34. package/dist/core/repair.js.map +1 -0
  35. package/dist/core/repo.d.ts +20 -2
  36. package/dist/core/repo.d.ts.map +1 -1
  37. package/dist/core/repo.js +65 -3
  38. package/dist/core/repo.js.map +1 -1
  39. package/dist/core/rows.d.ts +36 -0
  40. package/dist/core/rows.d.ts.map +1 -0
  41. package/dist/core/rows.js +75 -0
  42. package/dist/core/rows.js.map +1 -0
  43. package/dist/core/sessions.d.ts +34 -4
  44. package/dist/core/sessions.d.ts.map +1 -1
  45. package/dist/core/sessions.js +352 -104
  46. package/dist/core/sessions.js.map +1 -1
  47. package/dist/core/settings.d.ts +6 -0
  48. package/dist/core/settings.d.ts.map +1 -1
  49. package/dist/core/settings.js +1 -0
  50. package/dist/core/settings.js.map +1 -1
  51. package/dist/core/sqlite.d.ts +2 -0
  52. package/dist/core/sqlite.d.ts.map +1 -1
  53. package/dist/core/sqlite.js +14 -0
  54. package/dist/core/sqlite.js.map +1 -1
  55. package/dist/core/stage.d.ts +14 -1
  56. package/dist/core/stage.d.ts.map +1 -1
  57. package/dist/core/stage.js +63 -3
  58. package/dist/core/stage.js.map +1 -1
  59. package/dist/core/sync.d.ts.map +1 -1
  60. package/dist/core/sync.js +69 -16
  61. package/dist/core/sync.js.map +1 -1
  62. package/dist/plugin/index.d.ts.map +1 -1
  63. package/dist/plugin/index.js +2 -2
  64. package/dist/plugin/index.js.map +1 -1
  65. package/package.json +4 -4
@@ -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,oBAA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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,90 @@
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 the project with the session's own id, when this machine has
15
+ * it: the same repository checked out at a different path;
16
+ * - otherwise a project created with the id OpenCode 2 derives itself
17
+ * (`sha1("directory:" + path)` for a plain directory);
18
+ * - otherwise, for a directory this machine does not have, the home
19
+ * directory's project, which is where `/session` is normally opened.
20
+ *
21
+ * Project ids are deterministic in OpenCode 2 (git remote URL, then
22
+ * `.git/opencode`, then root commit; directory path outside a repository), so
23
+ * one repository has the same id on every machine wherever it is checked out,
24
+ * and a project row from another machine is reused as is when its worktree
25
+ * also exists here.
26
+ */
27
+ export declare const GLOBAL_PROJECT_ID = "global";
28
+ export interface Placement {
29
+ projectId: string;
30
+ directory: string;
31
+ path: string | null;
32
+ /** Parked in the home project because no project matches the directory. */
33
+ parked: boolean;
34
+ }
35
+ export interface PlacementInput {
36
+ directory: string;
37
+ projectId: string;
38
+ path: string | null;
39
+ /** The exporting machine's home directory, to map paths under it. */
40
+ originHome?: string;
41
+ }
42
+ export interface PlacementOptions {
43
+ /** This machine's home directory. */
44
+ home: string;
45
+ /** Create project rows OpenCode 2 would create itself. */
46
+ createProjects: boolean;
47
+ now: number;
48
+ /** Test seam: whether a directory exists on this machine. */
49
+ exists?: (dir: string) => boolean;
50
+ }
51
+ interface ProjectRow {
52
+ id: string;
53
+ worktree: string;
54
+ vcs: string | null;
55
+ time_created: number;
56
+ }
57
+ /** OpenCode 2 stores Windows paths with forward slashes. */
58
+ export declare function storedPath(p: string): string;
59
+ /** The project id OpenCode 2 gives a directory outside any repository. */
60
+ export declare function directoryProjectId(directory: string): string;
61
+ export declare function homeDir(): string;
62
+ /** Relative path from a worktree to a directory, the way OpenCode 2 writes it. */
63
+ export declare function relativePath(directory: string, worktree: string, fallback: string | null): string | null;
64
+ export declare class ProjectResolver {
65
+ private readonly db;
66
+ private readonly options;
67
+ private projects;
68
+ private readonly exists;
69
+ constructor(db: SqliteDatabase, options: PlacementOptions);
70
+ private load;
71
+ /** The project OpenCode 2 resolves today for a directory, if it has one. */
72
+ resolve(directory: string): ProjectRow | undefined;
73
+ /** Insert another machine's project row when its worktree exists here too. */
74
+ adopt(project: Row | undefined, insert: (row: Row) => void): void;
75
+ private createDirectoryProject;
76
+ private home;
77
+ /** The project sessions are parked in, if this machine has one. */
78
+ homeProjectId(): string | undefined;
79
+ /** This machine's row for a project id, when its worktree exists here. */
80
+ private byId;
81
+ /** The session's subfolder inside this machine's checkout, or the checkout itself. */
82
+ private within;
83
+ private inside;
84
+ /** Map a directory under the exporting machine's home onto this machine's home. */
85
+ private translate;
86
+ /** Where a session belongs on this machine. */
87
+ place(session: PlacementInput): Placement;
88
+ }
89
+ export {};
90
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;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,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,cAAc,EAAE,OAAO,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,6DAA6D;IAC7D,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CACnC;AAED,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAID,4DAA4D;AAC5D,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAI5C;AASD,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED,wBAAgB,OAAO,IAAI,MAAM,CAEhC;AAED,kFAAkF;AAClF,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,GAAG,IAAI,CAQf;AAYD,qBAAa,eAAe;IAKxB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;gBAG/B,EAAE,EAAE,cAAc,EAClB,OAAO,EAAE,gBAAgB;IAM5C,OAAO,CAAC,IAAI;IAWZ,4EAA4E;IAC5E,OAAO,CAAC,SAAS,EAAE,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,mEAAmE;IACnE,aAAa,IAAI,MAAM,GAAG,SAAS;IAInC,0EAA0E;IAC1E,OAAO,CAAC,IAAI;IAMZ,sFAAsF;IACtF,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,MAAM;IAUd,mFAAmF;IACnF,OAAO,CAAC,SAAS;IAUjB,+CAA+C;IAC/C,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS;CA8B1C"}
@@ -0,0 +1,225 @@
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 the project with the session's own id, when this machine has
18
+ * it: the same repository checked out at a different path;
19
+ * - otherwise a project created with the id OpenCode 2 derives itself
20
+ * (`sha1("directory:" + path)` for a plain directory);
21
+ * - otherwise, for a directory this machine does not have, the home
22
+ * directory's project, which is where `/session` is normally opened.
23
+ *
24
+ * Project ids are deterministic in OpenCode 2 (git remote URL, then
25
+ * `.git/opencode`, then root commit; directory path outside a repository), so
26
+ * one repository has the same id on every machine wherever it is checked out,
27
+ * and a project row from another machine is reused as is when its worktree
28
+ * also exists here.
29
+ */
30
+ export const GLOBAL_PROJECT_ID = "global";
31
+ const caseInsensitive = process.platform !== "linux";
32
+ /** OpenCode 2 stores Windows paths with forward slashes. */
33
+ export function storedPath(p) {
34
+ let out = process.platform === "win32" ? p.replace(/\\/g, "/") : p;
35
+ while (out.length > 1 && out.endsWith("/") && !/^[A-Za-z]:\/$/.test(out))
36
+ out = out.slice(0, -1);
37
+ return out;
38
+ }
39
+ function key(p) {
40
+ const s = String(p ?? "")
41
+ .replace(/\\/g, "/")
42
+ .replace(/\/+$/, "");
43
+ return caseInsensitive ? s.toLowerCase() : s;
44
+ }
45
+ /** The project id OpenCode 2 gives a directory outside any repository. */
46
+ export function directoryProjectId(directory) {
47
+ return createHash("sha1")
48
+ .update(`directory:${path.resolve(directory)}`)
49
+ .digest("hex");
50
+ }
51
+ export function homeDir() {
52
+ return process.env.SYNC_HOME || os.homedir();
53
+ }
54
+ /** Relative path from a worktree to a directory, the way OpenCode 2 writes it. */
55
+ export function relativePath(directory, worktree, fallback) {
56
+ const d = key(directory);
57
+ const w = key(worktree);
58
+ if (d === w)
59
+ return "";
60
+ if (d.startsWith(`${w}/`))
61
+ return storedPath(directory).slice(storedPath(worktree).length + 1);
62
+ const rel = path.relative(path.resolve(worktree), path.resolve(directory));
63
+ if (!rel || path.isAbsolute(rel))
64
+ return fallback;
65
+ return rel.replace(/\\/g, "/");
66
+ }
67
+ function insideRepository(directory, exists) {
68
+ let current = path.resolve(directory);
69
+ for (;;) {
70
+ if (exists(path.join(current, ".git")) || exists(path.join(current, ".hg")))
71
+ return true;
72
+ const parent = path.dirname(current);
73
+ if (parent === current)
74
+ return false;
75
+ current = parent;
76
+ }
77
+ }
78
+ export class ProjectResolver {
79
+ db;
80
+ options;
81
+ projects;
82
+ exists;
83
+ constructor(db, options) {
84
+ this.db = db;
85
+ this.options = options;
86
+ this.exists = options.exists ?? ((dir) => fs.existsSync(dir));
87
+ this.projects = this.load();
88
+ }
89
+ load() {
90
+ return readRows(this.db, "SELECT id, worktree, vcs, time_created FROM project WHERE id <> ?", [
91
+ GLOBAL_PROJECT_ID,
92
+ ]).map((row) => ({
93
+ id: String(row.id),
94
+ worktree: String(row.worktree ?? ""),
95
+ vcs: row.vcs == null ? null : String(row.vcs),
96
+ time_created: Number(row.time_created ?? 0),
97
+ }));
98
+ }
99
+ /** The project OpenCode 2 resolves today for a directory, if it has one. */
100
+ resolve(directory) {
101
+ const d = key(directory);
102
+ const newest = new Map();
103
+ for (const p of this.projects) {
104
+ const k = key(p.worktree);
105
+ if (!k || k === "/")
106
+ continue;
107
+ const prev = newest.get(k);
108
+ if (!prev || p.time_created > prev.time_created)
109
+ newest.set(k, p);
110
+ }
111
+ let best;
112
+ for (const [k, p] of newest) {
113
+ const match = d === k || (p.vcs && d.startsWith(`${k}/`));
114
+ if (match && (!best || k.length > key(best.worktree).length))
115
+ best = p;
116
+ }
117
+ return best;
118
+ }
119
+ /** Insert another machine's project row when its worktree exists here too. */
120
+ adopt(project, insert) {
121
+ if (!project || String(project.id) === GLOBAL_PROJECT_ID)
122
+ return;
123
+ const worktree = String(project.worktree ?? "");
124
+ if (!worktree || !this.exists(worktree))
125
+ return;
126
+ if (this.projects.some((p) => p.id === String(project.id)))
127
+ return;
128
+ insert(project);
129
+ this.projects = this.load();
130
+ }
131
+ createDirectoryProject(directory) {
132
+ if (!this.options.createProjects)
133
+ return undefined;
134
+ if (!this.exists(directory) || insideRepository(directory, this.exists))
135
+ return undefined;
136
+ const id = directoryProjectId(directory);
137
+ const now = this.options.now;
138
+ this.db
139
+ .prepare(`INSERT INTO project (id, worktree, vcs, sandboxes, time_created, time_updated, time_active)
140
+ VALUES (?, ?, NULL, '[]', ?, ?, ?) ON CONFLICT DO NOTHING`)
141
+ .run(id, storedPath(path.resolve(directory)), now, now, now);
142
+ this.projects = this.load();
143
+ return this.projects.find((p) => p.id === id);
144
+ }
145
+ home() {
146
+ const home = this.options.home;
147
+ return this.resolve(storedPath(path.resolve(home))) ?? this.createDirectoryProject(home);
148
+ }
149
+ /** The project sessions are parked in, if this machine has one. */
150
+ homeProjectId() {
151
+ return this.resolve(storedPath(path.resolve(this.options.home)))?.id;
152
+ }
153
+ /** This machine's row for a project id, when its worktree exists here. */
154
+ byId(projectId) {
155
+ if (!projectId || projectId === GLOBAL_PROJECT_ID)
156
+ return undefined;
157
+ const project = this.projects.find((p) => p.id === projectId);
158
+ return project?.worktree && this.exists(project.worktree) ? project : undefined;
159
+ }
160
+ /** The session's subfolder inside this machine's checkout, or the checkout itself. */
161
+ within(project, subpath) {
162
+ const rel = (subpath ?? "").replace(/\\/g, "/");
163
+ if (!rel || rel.startsWith("..") || path.isAbsolute(rel) || /^[A-Za-z]:/.test(rel)) {
164
+ return project.worktree;
165
+ }
166
+ const candidate = path.join(project.worktree, ...rel.split("/"));
167
+ return this.exists(candidate) ? storedPath(candidate) : project.worktree;
168
+ }
169
+ inside(target, directory, fallback) {
170
+ const exact = key(directory) === key(target.worktree);
171
+ return {
172
+ projectId: target.id,
173
+ directory: exact ? target.worktree : storedPath(directory),
174
+ path: relativePath(directory, target.worktree, fallback),
175
+ parked: false,
176
+ };
177
+ }
178
+ /** Map a directory under the exporting machine's home onto this machine's home. */
179
+ translate(directory, originHome) {
180
+ if (this.exists(directory) || !originHome)
181
+ return directory;
182
+ const from = key(originHome);
183
+ const d = key(directory);
184
+ if (!d.startsWith(`${from}/`))
185
+ return directory;
186
+ const rest = storedPath(directory).slice(storedPath(originHome).length + 1);
187
+ const candidate = path.join(this.options.home, ...rest.split("/"));
188
+ return this.exists(candidate) ? storedPath(candidate) : directory;
189
+ }
190
+ /** Where a session belongs on this machine. */
191
+ place(session) {
192
+ const directory = this.translate(session.directory, session.originHome);
193
+ const resolved = this.resolve(directory);
194
+ if (resolved)
195
+ return this.inside(resolved, directory, session.path);
196
+ // The same repository checked out somewhere else on this machine.
197
+ const same = this.byId(session.projectId);
198
+ if (same)
199
+ return this.inside(same, this.within(same, session.path), "");
200
+ const created = this.createDirectoryProject(directory);
201
+ if (created)
202
+ return this.inside(created, directory, session.path);
203
+ const home = this.home();
204
+ if (!home) {
205
+ return {
206
+ projectId: session.projectId,
207
+ directory: session.directory,
208
+ path: session.path,
209
+ parked: false,
210
+ };
211
+ }
212
+ // A directory this machine does not have would reopen in a missing
213
+ // folder, so the session moves to the home worktree itself.
214
+ if (!this.exists(directory)) {
215
+ return { projectId: home.id, directory: home.worktree, path: "", parked: true };
216
+ }
217
+ return {
218
+ projectId: home.id,
219
+ directory: storedPath(directory),
220
+ path: relativePath(directory, home.worktree, session.path),
221
+ parked: true,
222
+ };
223
+ }
224
+ }
225
+ //# 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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ode 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"}