opencode-github-sync 3.1.0 → 3.2.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 +340 -219
- package/README.zh-CN.md +242 -198
- 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 +368 -0
- package/dist/cli/i18n.d.ts.map +1 -0
- package/dist/cli/i18n.js +773 -0
- package/dist/cli/i18n.js.map +1 -0
- package/dist/cli/index.js +312 -114
- 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 +134 -0
- package/dist/core/autosync.d.ts.map +1 -0
- package/dist/core/autosync.js +507 -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/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/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/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/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/repo.d.ts +19 -1
- package/dist/core/repo.d.ts.map +1 -1
- package/dist/core/repo.js +61 -2
- package/dist/core/repo.js.map +1 -1
- 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/settings.d.ts +61 -0
- package/dist/core/settings.d.ts.map +1 -1
- package/dist/core/settings.js +44 -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/stage.d.ts +5 -0
- package/dist/core/stage.d.ts.map +1 -1
- package/dist/core/stage.js +94 -8
- 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 +295 -37
- 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 +4 -3
- package/dist/plugin/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -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"] },
|
|
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,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AAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACxD,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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,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,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAsB9D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACvB,MAAM;IACN,QAAQ;IACR,SAAS;IACT,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,aAAa;IACb,cAAc;IACd,qBAAqB;IACrB,gDAAgD;IAChD,YAAY;IACZ,gBAAgB;CACjB,CAAC,CAAC;AACH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1F,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC;AAElF,0EAA0E;AAC1E,MAAM,UAAU,SAAS,CAAC,OAA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C,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IACvC,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment handed to child processes (git, gh, npm).
|
|
3
|
+
*
|
|
4
|
+
* A proxy configured in the local settings must reach every network-touching
|
|
5
|
+
* child, but must never leak into the parent process or into OpenCode itself,
|
|
6
|
+
* so it is kept here and merged in only when a child is spawned.
|
|
7
|
+
*/
|
|
8
|
+
/** Environment variables that express a proxy to git, gh, curl and npm alike. */
|
|
9
|
+
export declare function proxyEnv(proxy: string | undefined): Record<string, string>;
|
|
10
|
+
/** Set (or clear, with `undefined`) the proxy used by every child process. */
|
|
11
|
+
export declare function setChildProxy(proxy: string | undefined): void;
|
|
12
|
+
/** `process.env` plus the child-only additions plus caller-specific overrides. */
|
|
13
|
+
export declare function childEnv(overrides?: Record<string, string>): NodeJS.ProcessEnv;
|
|
14
|
+
/** Prepend directories to PATH (whatever its casing is on this platform). */
|
|
15
|
+
export declare function prependPath(env: NodeJS.ProcessEnv, dirs: string[]): NodeJS.ProcessEnv;
|
|
16
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/core/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,iFAAiF;AACjF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAW1E;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAE7D;AAED,kFAAkF;AAClF,wBAAgB,QAAQ,CAAC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,MAAM,CAAC,UAAU,CAElF;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,CAgBrF"}
|
package/dist/core/env.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment handed to child processes (git, gh, npm).
|
|
3
|
+
*
|
|
4
|
+
* A proxy configured in the local settings must reach every network-touching
|
|
5
|
+
* child, but must never leak into the parent process or into OpenCode itself,
|
|
6
|
+
* so it is kept here and merged in only when a child is spawned.
|
|
7
|
+
*/
|
|
8
|
+
let extra = {};
|
|
9
|
+
/** Environment variables that express a proxy to git, gh, curl and npm alike. */
|
|
10
|
+
export function proxyEnv(proxy) {
|
|
11
|
+
const value = (proxy ?? "").trim();
|
|
12
|
+
if (!value)
|
|
13
|
+
return {};
|
|
14
|
+
return {
|
|
15
|
+
HTTP_PROXY: value,
|
|
16
|
+
HTTPS_PROXY: value,
|
|
17
|
+
http_proxy: value,
|
|
18
|
+
https_proxy: value,
|
|
19
|
+
npm_config_proxy: value,
|
|
20
|
+
npm_config_https_proxy: value,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Set (or clear, with `undefined`) the proxy used by every child process. */
|
|
24
|
+
export function setChildProxy(proxy) {
|
|
25
|
+
extra = proxyEnv(proxy);
|
|
26
|
+
}
|
|
27
|
+
/** `process.env` plus the child-only additions plus caller-specific overrides. */
|
|
28
|
+
export function childEnv(overrides = {}) {
|
|
29
|
+
return { ...process.env, ...extra, ...overrides };
|
|
30
|
+
}
|
|
31
|
+
/** Prepend directories to PATH (whatever its casing is on this platform). */
|
|
32
|
+
export function prependPath(env, dirs) {
|
|
33
|
+
if (dirs.length === 0)
|
|
34
|
+
return env;
|
|
35
|
+
const key = Object.keys(env).find((k) => k.toLowerCase() === "path") ?? "PATH";
|
|
36
|
+
const sep = process.platform === "win32" ? ";" : ":";
|
|
37
|
+
const current = String(env[key] ?? "");
|
|
38
|
+
const present = new Set(current
|
|
39
|
+
.split(sep)
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.map((p) => (process.platform === "win32" ? p.toLowerCase() : p)));
|
|
42
|
+
const missing = dirs.filter((d) => d && !present.has(process.platform === "win32" ? d.toLowerCase() : d));
|
|
43
|
+
if (missing.length === 0)
|
|
44
|
+
return env;
|
|
45
|
+
return { ...env, [key]: [...missing, current].filter(Boolean).join(sep) };
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/core/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,IAAI,KAAK,GAA2B,EAAE,CAAC;AAEvC,iFAAiF;AACjF,MAAM,UAAU,QAAQ,CAAC,KAAyB;IAChD,MAAM,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACnC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,KAAK;QAClB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,KAAK;QAClB,gBAAgB,EAAE,KAAK;QACvB,sBAAsB,EAAE,KAAK;KAC9B,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,QAAQ,CAAC,YAAoC,EAAE;IAC7D,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,KA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AC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAC5E,CAAC"}
|
package/dist/core/git.d.ts
CHANGED
|
@@ -48,6 +48,12 @@ export declare function toGitError(operation: string, result: GitResult): Error;
|
|
|
48
48
|
* what exists afterwards.
|
|
49
49
|
*/
|
|
50
50
|
export declare function parsePorcelainPaths(output: string): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Parse `git status -z --porcelain`: `XY path` records separated by NUL, with
|
|
53
|
+
* a rename's original path in the following record. Every path is returned,
|
|
54
|
+
* the original of a rename included, since both are local bytes.
|
|
55
|
+
*/
|
|
56
|
+
export declare function parsePorcelainZ(output: string): string[];
|
|
51
57
|
export interface NameStatusEntry {
|
|
52
58
|
kind: "added" | "modified" | "deleted" | "renamed";
|
|
53
59
|
path: string;
|
package/dist/core/git.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/core/git.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/core/git.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,4EAA4E;IAC5E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAmBD;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,CAmBlE;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAkBtF;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO9C;AAgBD,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAExD;AAED,qBAAa,YAAa,SAAQ,KAAK;IAGnC,QAAQ,CAAC,MAAM,EAAE,SAAS;gBAD1B,SAAS,EAAE,MAAM,EACR,MAAM,EAAE,SAAS;CAQ7B;AAED,qBAAa,QAAS,SAAQ,KAAK;IAG/B,QAAQ,CAAC,MAAM,EAAE,SAAS;gBAD1B,SAAS,EAAE,MAAM,EACR,MAAM,EAAE,SAAS;CAO7B;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,KAAK,CAItE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAY5D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBxD;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;IACnD,IAAI,EAAE,MAAM,CAAC;CACd;AAWD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,EAAE,CAajE"}
|
package/dist/core/git.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { execFile, execFileSync } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
|
+
import { childEnv } from "./env.js";
|
|
3
4
|
const execFileAsync = promisify(execFile);
|
|
4
5
|
const NO_PROMPT_ENV = {
|
|
5
6
|
GIT_TERMINAL_PROMPT: "0",
|
|
6
7
|
GIT_ASKPASS: "",
|
|
7
8
|
GCM_INTERACTIVE: "never",
|
|
9
|
+
// Failures are classified by matching git's English messages; a localized
|
|
10
|
+
// git would make a lost push race look like a hard failure.
|
|
11
|
+
LC_ALL: "C",
|
|
12
|
+
LANGUAGE: "C",
|
|
8
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Paths are parsed from git's output and then opened on disk. With the
|
|
16
|
+
* default `core.quotepath`, a non-ASCII name such as `技能.md` comes back as
|
|
17
|
+
* an octal-escaped string that names no real file.
|
|
18
|
+
*/
|
|
19
|
+
const BASE_ARGS = ["-c", "core.quotepath=off"];
|
|
9
20
|
/**
|
|
10
21
|
* Run git and never throw.
|
|
11
22
|
*
|
|
@@ -16,12 +27,13 @@ const NO_PROMPT_ENV = {
|
|
|
16
27
|
*/
|
|
17
28
|
export function git(args, options) {
|
|
18
29
|
try {
|
|
19
|
-
const stdout = execFileSync("git", args, {
|
|
30
|
+
const stdout = execFileSync("git", [...BASE_ARGS, ...args], {
|
|
20
31
|
cwd: options.cwd,
|
|
21
32
|
encoding: "utf8",
|
|
22
33
|
stdio: "pipe",
|
|
23
34
|
timeout: options.timeoutMs ?? 0,
|
|
24
|
-
|
|
35
|
+
windowsHide: true,
|
|
36
|
+
env: options.interactive ? childEnv() : childEnv(NO_PROMPT_ENV),
|
|
25
37
|
});
|
|
26
38
|
return { ok: true, stdout: stdout.trim(), stderr: "", code: 0 };
|
|
27
39
|
}
|
|
@@ -36,11 +48,12 @@ export function git(args, options) {
|
|
|
36
48
|
}
|
|
37
49
|
export async function gitAsync(args, options) {
|
|
38
50
|
try {
|
|
39
|
-
const { stdout, stderr } = await execFileAsync("git", args, {
|
|
51
|
+
const { stdout, stderr } = await execFileAsync("git", [...BASE_ARGS, ...args], {
|
|
40
52
|
cwd: options.cwd,
|
|
41
53
|
encoding: "utf8",
|
|
42
54
|
maxBuffer: 64 * 1024 * 1024,
|
|
43
|
-
|
|
55
|
+
windowsHide: true,
|
|
56
|
+
env: options.interactive ? childEnv() : childEnv(NO_PROMPT_ENV),
|
|
44
57
|
});
|
|
45
58
|
return { ok: true, stdout: stdout.trim(), stderr: stderr.trim(), code: 0 };
|
|
46
59
|
}
|
|
@@ -128,6 +141,33 @@ export function parsePorcelainPaths(output) {
|
|
|
128
141
|
}
|
|
129
142
|
return paths;
|
|
130
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Parse `git status -z --porcelain`: `XY path` records separated by NUL, with
|
|
146
|
+
* a rename's original path in the following record. Every path is returned,
|
|
147
|
+
* the original of a rename included, since both are local bytes.
|
|
148
|
+
*/
|
|
149
|
+
export function parsePorcelainZ(output) {
|
|
150
|
+
const records = String(output ?? "").split("\0");
|
|
151
|
+
const paths = [];
|
|
152
|
+
for (let i = 0; i < records.length; i++) {
|
|
153
|
+
const record = records[i] ?? "";
|
|
154
|
+
if (record.length < 3)
|
|
155
|
+
continue;
|
|
156
|
+
// Each record is `XY path`, so the third character is always a space.
|
|
157
|
+
// `git()` trims its output, which drops the leading space of a first
|
|
158
|
+
// record such as ` M file`; that shows as a non-space third character.
|
|
159
|
+
const start = record[2] === " " ? 3 : record[1] === " " ? 2 : -1;
|
|
160
|
+
if (start === -1)
|
|
161
|
+
continue;
|
|
162
|
+
paths.push(record.slice(start));
|
|
163
|
+
if (/^[RC]/.test(record)) {
|
|
164
|
+
const original = records[++i];
|
|
165
|
+
if (original)
|
|
166
|
+
paths.push(original);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return paths;
|
|
170
|
+
}
|
|
131
171
|
const STATUS_MAP = {
|
|
132
172
|
A: "added",
|
|
133
173
|
M: "modified",
|
package/dist/core/git.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/core/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+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
|
+
*
|
|
6
|
+
* The usual way a sync repository gets ruined is not a conflict but an
|
|
7
|
+
* accident: a virtualenv created inside a skill, a build output dropped into
|
|
8
|
+
* the config directory, a log that grew to a gigabyte. Each is one `git add`
|
|
9
|
+
* away from being in the history of every machine for ever. A push that adds
|
|
10
|
+
* an unusual amount of data is therefore held back until a person confirms it.
|
|
11
|
+
* The unattended scheduler never confirms; it records a failure instead.
|
|
12
|
+
*/
|
|
13
|
+
export interface GuardReport {
|
|
14
|
+
addedFiles: number;
|
|
15
|
+
totalBytes: number;
|
|
16
|
+
largest?: {
|
|
17
|
+
path: string;
|
|
18
|
+
bytes: number;
|
|
19
|
+
};
|
|
20
|
+
/** Files above the single-file limit, largest first. */
|
|
21
|
+
oversized: {
|
|
22
|
+
path: string;
|
|
23
|
+
bytes: number;
|
|
24
|
+
}[];
|
|
25
|
+
/** Human-readable reasons; empty when the push is within limits. */
|
|
26
|
+
reasons: ("files" | "bytes" | "file")[];
|
|
27
|
+
}
|
|
28
|
+
export declare function evaluateGuard(root: string, files: ChangedFile[], limits: GuardSettings): GuardReport;
|
|
29
|
+
export declare class LargeChangeError extends Error {
|
|
30
|
+
readonly report: GuardReport;
|
|
31
|
+
constructor(report: GuardReport);
|
|
32
|
+
}
|
|
33
|
+
/** Patterns written to `.git/info/exclude` so generated trees are never staged. */
|
|
34
|
+
export declare function excludeFileContent(skipDirs: string[]): string;
|
|
35
|
+
export declare function writeLocalExcludes(root: string, skipDirs: string[]): void;
|
|
36
|
+
//# sourceMappingURL=guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/core/guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;;;;;;GASG;AAEH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,wDAAwD;IACxD,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7C,oEAAoE;IACpE,OAAO,EAAE,CAAC,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC,EAAE,CAAC;CACzC;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,EAAE,EACpB,MAAM,EAAE,aAAa,GACpB,WAAW,CA0Bb;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IAC7B,QAAQ,CAAC,MAAM,EAAE,WAAW;gBAAnB,MAAM,EAAE,WAAW;CAOzC;AAED,mFAAmF;AACnF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAM7D;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAWzE"}
|