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
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SyncCategories } from "./settings.js";
|
|
2
|
+
/**
|
|
3
|
+
* Optional parts of the config directory.
|
|
4
|
+
*
|
|
5
|
+
* The repository worktree is `~/.config/opencode` itself, so a category is a
|
|
6
|
+
* set of paths at its root. Turning a category off makes those paths local to
|
|
7
|
+
* this machine in both directions: they are never committed from here, and an
|
|
8
|
+
* incoming version never replaces them.
|
|
9
|
+
*/
|
|
10
|
+
export type CategoryKey = keyof SyncCategories;
|
|
11
|
+
interface CategoryPaths {
|
|
12
|
+
files?: string[];
|
|
13
|
+
dirs?: string[];
|
|
14
|
+
/** Match root-level files by extension. */
|
|
15
|
+
rootExtensions?: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare const CATEGORY_PATHS: Record<CategoryKey, CategoryPaths>;
|
|
18
|
+
export declare function disabledCategories(categories: SyncCategories | undefined): CategoryKey[];
|
|
19
|
+
/** True when a repository-relative path belongs to a disabled category. */
|
|
20
|
+
export declare function isDisabledPath(rel: string, disabled: CategoryKey[]): boolean;
|
|
21
|
+
/** Git pathspecs (top-level, literal) covering the disabled categories. */
|
|
22
|
+
export declare function disabledPathspecs(disabled: CategoryKey[]): string[];
|
|
23
|
+
/** Every existing file under `root` that belongs to a disabled category. */
|
|
24
|
+
export declare function listDisabledFiles(root: string, disabled: CategoryKey[]): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Copy the disabled categories aside, so they can be put back exactly as they
|
|
27
|
+
* were after the worktree is reset to the remote.
|
|
28
|
+
*/
|
|
29
|
+
export interface CategorySnapshot {
|
|
30
|
+
dir: string;
|
|
31
|
+
files: string[];
|
|
32
|
+
}
|
|
33
|
+
export declare function snapshotDisabled(root: string, disabled: CategoryKey[]): CategorySnapshot | null;
|
|
34
|
+
/** Put the snapshot back: incoming files in those categories are removed. */
|
|
35
|
+
export declare function restoreDisabled(root: string, disabled: CategoryKey[], snapshot: CategorySnapshot | null): void;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=categories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categories.d.ts","sourceRoot":"","sources":["../../src/core/categories.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;GAOG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC;AAE/C,UAAU,aAAa;IACrB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,aAAa,CAM7D,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,cAAc,GAAG,SAAS,GAAG,WAAW,EAAE,CAGxF;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAe5E;AAED,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,CASnE;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,CAyBjF;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,gBAAgB,GAAG,IAAI,CAU/F;AAED,6EAA6E;AAC7E,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,EAAE,EACvB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,GAChC,IAAI,CAeN"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export const CATEGORY_PATHS = {
|
|
5
|
+
config: { files: ["opencode.json", "opencode.jsonc", "tui.json", "tui.jsonc", "cli.json"] },
|
|
6
|
+
instructions: { rootExtensions: [".md"] },
|
|
7
|
+
agents: { dirs: ["agent", "agents"] },
|
|
8
|
+
commands: { dirs: ["command", "commands"] },
|
|
9
|
+
plugins: { dirs: ["plugin", "plugins"] },
|
|
10
|
+
};
|
|
11
|
+
export function disabledCategories(categories) {
|
|
12
|
+
if (!categories)
|
|
13
|
+
return [];
|
|
14
|
+
return Object.keys(CATEGORY_PATHS).filter((key) => categories[key] === false);
|
|
15
|
+
}
|
|
16
|
+
/** True when a repository-relative path belongs to a disabled category. */
|
|
17
|
+
export function isDisabledPath(rel, disabled) {
|
|
18
|
+
const clean = rel.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
19
|
+
for (const key of disabled) {
|
|
20
|
+
const spec = CATEGORY_PATHS[key];
|
|
21
|
+
if (spec.files?.includes(clean))
|
|
22
|
+
return true;
|
|
23
|
+
if (spec.dirs?.some((d) => clean === d || clean.startsWith(`${d}/`)))
|
|
24
|
+
return true;
|
|
25
|
+
if (spec.rootExtensions &&
|
|
26
|
+
!clean.includes("/") &&
|
|
27
|
+
spec.rootExtensions.some((ext) => clean.toLowerCase().endsWith(ext))) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/** Git pathspecs (top-level, literal) covering the disabled categories. */
|
|
34
|
+
export function disabledPathspecs(disabled) {
|
|
35
|
+
const specs = [];
|
|
36
|
+
for (const key of disabled) {
|
|
37
|
+
const spec = CATEGORY_PATHS[key];
|
|
38
|
+
for (const f of spec.files ?? [])
|
|
39
|
+
specs.push(`:(top,literal)${f}`);
|
|
40
|
+
for (const d of spec.dirs ?? [])
|
|
41
|
+
specs.push(`:(top,literal)${d}`);
|
|
42
|
+
for (const ext of spec.rootExtensions ?? [])
|
|
43
|
+
specs.push(`:(top,glob)*${ext}`);
|
|
44
|
+
}
|
|
45
|
+
return specs;
|
|
46
|
+
}
|
|
47
|
+
/** Every existing file under `root` that belongs to a disabled category. */
|
|
48
|
+
export function listDisabledFiles(root, disabled) {
|
|
49
|
+
if (disabled.length === 0 || !fs.existsSync(root))
|
|
50
|
+
return [];
|
|
51
|
+
const out = [];
|
|
52
|
+
const walk = (rel) => {
|
|
53
|
+
const abs = path.join(root, rel);
|
|
54
|
+
let entries;
|
|
55
|
+
try {
|
|
56
|
+
entries = fs.readdirSync(abs, { withFileTypes: true });
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
63
|
+
if (entry.isSymbolicLink())
|
|
64
|
+
continue;
|
|
65
|
+
if (entry.isDirectory())
|
|
66
|
+
walk(childRel);
|
|
67
|
+
else
|
|
68
|
+
out.push(childRel);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
72
|
+
if (entry.name === ".git" || entry.isSymbolicLink())
|
|
73
|
+
continue;
|
|
74
|
+
if (!isDisabledPath(entry.name, disabled))
|
|
75
|
+
continue;
|
|
76
|
+
if (entry.isDirectory())
|
|
77
|
+
walk(entry.name);
|
|
78
|
+
else
|
|
79
|
+
out.push(entry.name);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
export function snapshotDisabled(root, disabled) {
|
|
84
|
+
if (disabled.length === 0)
|
|
85
|
+
return null;
|
|
86
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ogs-keep-"));
|
|
87
|
+
const files = listDisabledFiles(root, disabled);
|
|
88
|
+
for (const rel of files) {
|
|
89
|
+
const target = path.join(dir, rel);
|
|
90
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
91
|
+
fs.copyFileSync(path.join(root, rel), target);
|
|
92
|
+
}
|
|
93
|
+
return { dir, files };
|
|
94
|
+
}
|
|
95
|
+
/** Put the snapshot back: incoming files in those categories are removed. */
|
|
96
|
+
export function restoreDisabled(root, disabled, snapshot) {
|
|
97
|
+
if (!snapshot)
|
|
98
|
+
return;
|
|
99
|
+
try {
|
|
100
|
+
const keep = new Set(snapshot.files);
|
|
101
|
+
for (const rel of listDisabledFiles(root, disabled)) {
|
|
102
|
+
if (!keep.has(rel))
|
|
103
|
+
fs.rmSync(path.join(root, rel), { force: true });
|
|
104
|
+
}
|
|
105
|
+
for (const rel of snapshot.files) {
|
|
106
|
+
const target = path.join(root, rel);
|
|
107
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
108
|
+
fs.copyFileSync(path.join(snapshot.dir, rel), target);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
fs.rmSync(snapshot.dir, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=categories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categories.js","sourceRoot":"","sources":["../../src/core/categories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAqB7B,MAAM,CAAC,MAAM,cAAc,GAAuC;IAChE,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE;IAC3F,YAAY,EAAE,EAAE,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE;IACzC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE;IACrC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE;IAC3C,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE;CACzC,CAAC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Compare this machine's config directory with a remote branch without
|
|
3
|
+
* touching either: the remote is fetched into a throwaway bare repository and
|
|
4
|
+
* local files are hashed in-process the way git would store them.
|
|
5
|
+
*
|
|
6
|
+
* Used before the first link, so the user can choose which side wins knowing
|
|
7
|
+
* what would change.
|
|
8
|
+
*/
|
|
9
|
+
export interface FileDifference {
|
|
10
|
+
path: string;
|
|
11
|
+
kind: "onlyLocal" | "different" | "onlyRemote";
|
|
12
|
+
}
|
|
13
|
+
export interface CompareResult {
|
|
14
|
+
/** The remote branch has no commits yet. */
|
|
15
|
+
empty: boolean;
|
|
16
|
+
differences: FileDifference[];
|
|
17
|
+
}
|
|
18
|
+
/** The blob id git would assign to this content once normalised to LF. */
|
|
19
|
+
export declare function gitBlobId(content: Buffer): string;
|
|
20
|
+
export declare function compareWithRemote(root: string, remote: string, branch: string, skipDirs?: string[]): CompareResult;
|
|
21
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../src/core/compare.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC;CAChD;AAED,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,cAAc,EAAE,CAAC;CAC/B;AAmBD,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIjD;AA8CD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,MAAM,EAAO,GACtB,aAAa,CAoCf"}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 { git } from "./git.js";
|
|
6
|
+
import { AGENTS_DIR, DATA_DIR, SESSIONS_DIR, STATE_DIR } from "./paths.js";
|
|
7
|
+
import { OVERRIDES_FILE, SETTINGS_FILE } from "./settings.js";
|
|
8
|
+
const SKIP_TOP = new Set([
|
|
9
|
+
".git",
|
|
10
|
+
DATA_DIR,
|
|
11
|
+
STATE_DIR,
|
|
12
|
+
AGENTS_DIR,
|
|
13
|
+
SESSIONS_DIR,
|
|
14
|
+
"_extra",
|
|
15
|
+
SETTINGS_FILE,
|
|
16
|
+
OVERRIDES_FILE,
|
|
17
|
+
".opencode-sync.lock",
|
|
18
|
+
// Written by the tool itself on the first sync.
|
|
19
|
+
".gitignore",
|
|
20
|
+
".gitattributes",
|
|
21
|
+
]);
|
|
22
|
+
const SKIP_ANY = new Set(["node_modules", "logs", "log", "__pycache__", ".venv", "venv"]);
|
|
23
|
+
const SKIP_FILES = new Set([".DS_Store", "Thumbs.db", "desktop.ini", "bun.lock"]);
|
|
24
|
+
/** The blob id git would assign to this content once normalised to LF. */
|
|
25
|
+
export function gitBlobId(content) {
|
|
26
|
+
const binary = content.includes(0);
|
|
27
|
+
const data = binary ? content : Buffer.from(content.toString("utf8").replace(/\r\n/g, "\n"));
|
|
28
|
+
return createHash("sha1").update(`blob ${data.length}\0`).update(data).digest("hex");
|
|
29
|
+
}
|
|
30
|
+
function localFiles(root, skipDirs) {
|
|
31
|
+
const files = new Map();
|
|
32
|
+
const skipAny = new Set([...SKIP_ANY, ...skipDirs]);
|
|
33
|
+
const walk = (rel, depth) => {
|
|
34
|
+
if (depth > 12)
|
|
35
|
+
return;
|
|
36
|
+
let entries;
|
|
37
|
+
try {
|
|
38
|
+
entries = fs.readdirSync(path.join(root, rel), { withFileTypes: true });
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (entry.isSymbolicLink())
|
|
45
|
+
continue;
|
|
46
|
+
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
47
|
+
if (!rel && SKIP_TOP.has(entry.name))
|
|
48
|
+
continue;
|
|
49
|
+
if (entry.isDirectory()) {
|
|
50
|
+
if (!skipAny.has(entry.name))
|
|
51
|
+
walk(childRel, depth + 1);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (SKIP_FILES.has(entry.name) || entry.name.endsWith(".pyc"))
|
|
55
|
+
continue;
|
|
56
|
+
try {
|
|
57
|
+
files.set(childRel, gitBlobId(fs.readFileSync(path.join(root, childRel))));
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Unreadable files cannot be compared; skip them.
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (fs.existsSync(root))
|
|
65
|
+
walk("", 0);
|
|
66
|
+
return files;
|
|
67
|
+
}
|
|
68
|
+
function remoteFiles(tree) {
|
|
69
|
+
const files = new Map();
|
|
70
|
+
for (const line of tree.split("\n")) {
|
|
71
|
+
const match = /^\d+ blob ([0-9a-f]{40})\t(.+)$/.exec(line);
|
|
72
|
+
if (!match)
|
|
73
|
+
continue;
|
|
74
|
+
const [, id, rel] = match;
|
|
75
|
+
const top = rel.split("/")[0];
|
|
76
|
+
if (SKIP_TOP.has(top))
|
|
77
|
+
continue;
|
|
78
|
+
files.set(rel.replace(/^"(.*)"$/, "$1"), id);
|
|
79
|
+
}
|
|
80
|
+
return files;
|
|
81
|
+
}
|
|
82
|
+
export function compareWithRemote(root, remote, branch, skipDirs = []) {
|
|
83
|
+
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), "ogs-compare-"));
|
|
84
|
+
try {
|
|
85
|
+
git(["init", "--bare", "-q", scratch], { cwd: os.tmpdir() });
|
|
86
|
+
const fetched = git(["fetch", "-q", "--depth=1", remote, branch], {
|
|
87
|
+
cwd: scratch,
|
|
88
|
+
timeoutMs: 120_000,
|
|
89
|
+
});
|
|
90
|
+
if (!fetched.ok) {
|
|
91
|
+
if (/couldn't find remote ref|not found|does not appear/i.test(fetched.stderr)) {
|
|
92
|
+
return { empty: true, differences: [] };
|
|
93
|
+
}
|
|
94
|
+
// An empty repository answers the fetch with a missing ref as well.
|
|
95
|
+
const listed = git(["ls-remote", remote], { cwd: scratch, timeoutMs: 60_000 });
|
|
96
|
+
if (listed.ok && listed.stdout.trim() === "")
|
|
97
|
+
return { empty: true, differences: [] };
|
|
98
|
+
throw new Error(`Cannot read ${remote}: ${fetched.stderr.split("\n")[0]}`);
|
|
99
|
+
}
|
|
100
|
+
const tree = git(["-c", "core.quotepath=off", "ls-tree", "-r", "FETCH_HEAD"], {
|
|
101
|
+
cwd: scratch,
|
|
102
|
+
});
|
|
103
|
+
const theirs = remoteFiles(tree.ok ? tree.stdout : "");
|
|
104
|
+
const ours = localFiles(root, skipDirs);
|
|
105
|
+
const differences = [];
|
|
106
|
+
for (const [rel, id] of ours) {
|
|
107
|
+
const other = theirs.get(rel);
|
|
108
|
+
if (other === undefined)
|
|
109
|
+
differences.push({ path: rel, kind: "onlyLocal" });
|
|
110
|
+
else if (other !== id)
|
|
111
|
+
differences.push({ path: rel, kind: "different" });
|
|
112
|
+
}
|
|
113
|
+
for (const rel of theirs.keys()) {
|
|
114
|
+
if (!ours.has(rel))
|
|
115
|
+
differences.push({ path: rel, kind: "onlyRemote" });
|
|
116
|
+
}
|
|
117
|
+
differences.sort((a, b) => a.path.localeCompare(b.path));
|
|
118
|
+
return { empty: false, differences };
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
fs.rmSync(scratch, { recursive: true, force: true });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../src/core/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAA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Code 1 reads `auth.json` directly, so syncing the file was enough.
|
|
5
|
+
* OpenCode 2 keeps accounts in the `credential` table of `opencode.db` and
|
|
6
|
+
* reads `auth.json` at most once — and a database created fresh by 2.x marks
|
|
7
|
+
* that import as done without running it, so on a new machine a synced
|
|
8
|
+
* `auth.json` is never read at all. This bridge copies between the two around
|
|
9
|
+
* every sync, only when credential sync is turned on:
|
|
10
|
+
*
|
|
11
|
+
* - before a push, an account chosen or a token refreshed in OpenCode reaches
|
|
12
|
+
* `auth.json` and from there the other machines;
|
|
13
|
+
* - after a pull, what other machines published reaches the database. A
|
|
14
|
+
* running OpenCode sees the change on its next request.
|
|
15
|
+
*
|
|
16
|
+
* Which side changed is decided against a fingerprint of the last value
|
|
17
|
+
* bridged per integration, kept in a machine-local file next to the database
|
|
18
|
+
* (a hash, never the secret). When both changed, a later OAuth expiry wins;
|
|
19
|
+
* otherwise the database wins before a push and the file wins after a pull.
|
|
20
|
+
*
|
|
21
|
+
* Logging out in OpenCode removes the entry from `auth.json`, as it did with
|
|
22
|
+
* OpenCode 1. An entry missing from an incoming `auth.json` never logs this
|
|
23
|
+
* machine out. Integrations OpenCode 2 manages itself (`external`) and
|
|
24
|
+
* entries it cannot represent are left alone. Nothing here prints a secret.
|
|
25
|
+
*/
|
|
26
|
+
export declare const BRIDGE_STATE_FILE = "opencode-sync-credentials.json";
|
|
27
|
+
export type BridgePreference = "database" | "file";
|
|
28
|
+
export interface BridgeResult {
|
|
29
|
+
/** Integrations whose value was written into `auth.json`. */
|
|
30
|
+
toFile: string[];
|
|
31
|
+
/** Integrations whose value was written into the database. */
|
|
32
|
+
toDatabase: string[];
|
|
33
|
+
/** Integrations removed from `auth.json` after a logout here. */
|
|
34
|
+
removed: string[];
|
|
35
|
+
}
|
|
36
|
+
/** True when this database belongs to OpenCode 2 (has the credential table). */
|
|
37
|
+
export declare function hasCredentialTable(databaseFile: string): Promise<boolean>;
|
|
38
|
+
/** Reconcile `auth.json` and the credential table of one data directory. */
|
|
39
|
+
export declare function bridgeCredentials(dataRoot: string, prefer: BridgePreference, now?: number): Promise<BridgeResult>;
|
|
40
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/core/credentials.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,eAAO,MAAM,iBAAiB,mCAAmC,CAAC;AAElE,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,MAAM,CAAC;AAEnD,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,8DAA8D;IAC9D,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,iEAAiE;IACjE,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAuOD,gFAAgF;AAChF,wBAAsB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQ/E;AAED,4EAA4E;AAC5E,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,gBAAgB,EACxB,GAAG,SAAa,GACf,OAAO,CAAC,YAAY,CAAC,CA8GvB"}
|