opencode-github-sync 3.0.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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -0
  3. package/README.zh-CN.md +332 -0
  4. package/dist/cli/index.d.ts +3 -0
  5. package/dist/cli/index.d.ts.map +1 -0
  6. package/dist/cli/index.js +334 -0
  7. package/dist/cli/index.js.map +1 -0
  8. package/dist/cli/render.d.ts +45 -0
  9. package/dist/cli/render.d.ts.map +1 -0
  10. package/dist/cli/render.js +167 -0
  11. package/dist/cli/render.js.map +1 -0
  12. package/dist/cli/theme.d.ts +45 -0
  13. package/dist/cli/theme.d.ts.map +1 -0
  14. package/dist/cli/theme.js +88 -0
  15. package/dist/cli/theme.js.map +1 -0
  16. package/dist/core/fsx.d.ts +81 -0
  17. package/dist/core/fsx.d.ts.map +1 -0
  18. package/dist/core/fsx.js +353 -0
  19. package/dist/core/fsx.js.map +1 -0
  20. package/dist/core/git.d.ts +48 -0
  21. package/dist/core/git.d.ts.map +1 -0
  22. package/dist/core/git.js +133 -0
  23. package/dist/core/git.js.map +1 -0
  24. package/dist/core/host.d.ts +20 -0
  25. package/dist/core/host.d.ts.map +1 -0
  26. package/dist/core/host.js +50 -0
  27. package/dist/core/host.js.map +1 -0
  28. package/dist/core/index.d.ts +16 -0
  29. package/dist/core/index.d.ts.map +1 -0
  30. package/dist/core/index.js +16 -0
  31. package/dist/core/index.js.map +1 -0
  32. package/dist/core/jsonc.d.ts +20 -0
  33. package/dist/core/jsonc.d.ts.map +1 -0
  34. package/dist/core/jsonc.js +115 -0
  35. package/dist/core/jsonc.js.map +1 -0
  36. package/dist/core/lock.d.ts +14 -0
  37. package/dist/core/lock.d.ts.map +1 -0
  38. package/dist/core/lock.js +111 -0
  39. package/dist/core/lock.js.map +1 -0
  40. package/dist/core/overrides.d.ts +30 -0
  41. package/dist/core/overrides.d.ts.map +1 -0
  42. package/dist/core/overrides.js +126 -0
  43. package/dist/core/overrides.js.map +1 -0
  44. package/dist/core/paths.d.ts +36 -0
  45. package/dist/core/paths.d.ts.map +1 -0
  46. package/dist/core/paths.js +55 -0
  47. package/dist/core/paths.js.map +1 -0
  48. package/dist/core/repo.d.ts +57 -0
  49. package/dist/core/repo.d.ts.map +1 -0
  50. package/dist/core/repo.js +184 -0
  51. package/dist/core/repo.js.map +1 -0
  52. package/dist/core/reporter.d.ts +50 -0
  53. package/dist/core/reporter.d.ts.map +1 -0
  54. package/dist/core/reporter.js +63 -0
  55. package/dist/core/reporter.js.map +1 -0
  56. package/dist/core/sessions.d.ts +61 -0
  57. package/dist/core/sessions.d.ts.map +1 -0
  58. package/dist/core/sessions.js +321 -0
  59. package/dist/core/sessions.js.map +1 -0
  60. package/dist/core/settings.d.ts +59 -0
  61. package/dist/core/settings.d.ts.map +1 -0
  62. package/dist/core/settings.js +120 -0
  63. package/dist/core/settings.js.map +1 -0
  64. package/dist/core/setup.d.ts +48 -0
  65. package/dist/core/setup.d.ts.map +1 -0
  66. package/dist/core/setup.js +186 -0
  67. package/dist/core/setup.js.map +1 -0
  68. package/dist/core/sqlite.d.ts +37 -0
  69. package/dist/core/sqlite.d.ts.map +1 -0
  70. package/dist/core/sqlite.js +106 -0
  71. package/dist/core/sqlite.js.map +1 -0
  72. package/dist/core/stage.d.ts +44 -0
  73. package/dist/core/stage.d.ts.map +1 -0
  74. package/dist/core/stage.js +297 -0
  75. package/dist/core/stage.js.map +1 -0
  76. package/dist/core/sync.d.ts +50 -0
  77. package/dist/core/sync.d.ts.map +1 -0
  78. package/dist/core/sync.js +360 -0
  79. package/dist/core/sync.js.map +1 -0
  80. package/dist/plugin/index.d.ts +31 -0
  81. package/dist/plugin/index.d.ts.map +1 -0
  82. package/dist/plugin/index.js +132 -0
  83. package/dist/plugin/index.js.map +1 -0
  84. package/package.json +67 -0
@@ -0,0 +1,184 @@
1
+ import path from "node:path";
2
+ import { ensureFile, writeIfDiffers } from "./fsx.js";
3
+ import { git, isGitRepo, toGitError } from "./git.js";
4
+ import { AGENTS_DIR, DATA_DIR, SESSIONS_DIR, STATE_DIR } from "./paths.js";
5
+ import { OVERRIDES_FILE, SETTINGS_FILE } from "./settings.js";
6
+ /**
7
+ * Files the sync repository must never track.
8
+ *
9
+ * Three categories:
10
+ * - local-only settings (`opencode-sync*.jsonc`)
11
+ * - the SQLite database and its journals, which are gigabytes and are
12
+ * represented instead by the shards in `_sessions/`
13
+ * - caches, logs and OS junk
14
+ */
15
+ export const DEFAULT_GITIGNORE = `# opencode-github-sync — machine-local, never committed
16
+ ${SETTINGS_FILE}
17
+ ${OVERRIDES_FILE}
18
+ .opencode-sync.lock
19
+
20
+ # Runtime / generated
21
+ node_modules/
22
+ bun.lock
23
+ logs/
24
+ **/__pycache__/
25
+ *.pyc
26
+
27
+ # Session storage lives in ${SESSIONS_DIR}/ as portable shards.
28
+ # The raw database is far too large for git and cannot be merged.
29
+ ${DATA_DIR}/opencode.db
30
+ ${DATA_DIR}/opencode.db-shm
31
+ ${DATA_DIR}/opencode.db-wal
32
+ ${DATA_DIR}/bin/
33
+ ${DATA_DIR}/log/
34
+ ${DATA_DIR}/tool-output/
35
+ ${DATA_DIR}/snapshot/
36
+ ${DATA_DIR}/storage/session
37
+ ${DATA_DIR}/storage/session_diff
38
+
39
+ # Machine-local UI state
40
+ ${STATE_DIR}/session.json
41
+
42
+ # Empty directories recreated by OpenCode at runtime
43
+ plugin/
44
+
45
+ # OS files
46
+ .DS_Store
47
+ Thumbs.db
48
+ desktop.ini
49
+ `;
50
+ export const DEFAULT_GITATTRIBUTES = `# Store and check out everything with LF.
51
+ # "text=auto" alone would rewrite files to CRLF on Windows, which silently
52
+ # breaks shell scripts shipped inside skills and makes every cross-platform
53
+ # pull look like a whole-file change.
54
+ * text=auto eol=lf
55
+
56
+ # Append-only history files merge cleanly by taking both sides
57
+ ${STATE_DIR}/prompt-history.jsonl text eol=lf merge=union
58
+
59
+ # Session shards are gzipped JSON — binary, and never line-merged
60
+ ${SESSIONS_DIR}/*.json.gz binary
61
+ `;
62
+ /**
63
+ * Paths that exist inside the worktree but must stay out of every commit.
64
+ *
65
+ * These are runtime artefacts of the machine, not configuration. They are
66
+ * excluded from `add`, from stashing and from `clean`, so a sync can never
67
+ * delete a user's local database or tool output.
68
+ */
69
+ export const LOCAL_RUNTIME_PATHS = [
70
+ `${DATA_DIR}/opencode.db`,
71
+ `${DATA_DIR}/opencode.db-shm`,
72
+ `${DATA_DIR}/opencode.db-wal`,
73
+ `${DATA_DIR}/storage/session`,
74
+ `${DATA_DIR}/storage/session_diff`,
75
+ `${DATA_DIR}/tool-output`,
76
+ `${DATA_DIR}/snapshot`,
77
+ ];
78
+ export function isLocalRuntimePath(candidate) {
79
+ const normalized = String(candidate ?? "").replace(/\\/g, "/");
80
+ return LOCAL_RUNTIME_PATHS.some((prefix) => {
81
+ const clean = prefix.replace(/\/$/, "");
82
+ return normalized === clean || normalized.startsWith(`${clean}/`);
83
+ });
84
+ }
85
+ export function excludePathspecs() {
86
+ return LOCAL_RUNTIME_PATHS.map((p) => `:(exclude)${p}`);
87
+ }
88
+ /** Unstage runtime paths in a single git call — subprocesses are slow on Windows. */
89
+ export function unstageLocalRuntimePaths(root) {
90
+ git(["reset", "-q", "HEAD", "--", ...LOCAL_RUNTIME_PATHS], { cwd: root });
91
+ }
92
+ /** Configure identity and metadata files. Safe to call repeatedly. */
93
+ export function ensureGitIdentity(root) {
94
+ const name = git(["config", "user.name"], { cwd: root });
95
+ if (!name.ok || !name.stdout) {
96
+ git(["config", "user.name", "OpenCode Sync"], { cwd: root });
97
+ }
98
+ const email = git(["config", "user.email"], { cwd: root });
99
+ if (!email.ok || !email.stdout) {
100
+ git(["config", "user.email", "sync@opencode.local"], { cwd: root });
101
+ }
102
+ }
103
+ export function writeRepoMetadata(root) {
104
+ writeIfDiffers(path.join(root, ".gitignore"), DEFAULT_GITIGNORE);
105
+ writeIfDiffers(path.join(root, ".gitattributes"), DEFAULT_GITATTRIBUTES);
106
+ }
107
+ /**
108
+ * Make `root` a git worktree pointing at `remote`.
109
+ *
110
+ * Returns `adopted` when the remote already had commits (they become the local
111
+ * state) and `fresh` when the remote exists but is empty.
112
+ */
113
+ export function initRepo(options) {
114
+ const { root, remote, branch } = options;
115
+ ensureFile(path.join(root, ".gitignore"), DEFAULT_GITIGNORE);
116
+ ensureFile(path.join(root, ".gitattributes"), DEFAULT_GITATTRIBUTES);
117
+ git(["init", "-b", branch], { cwd: root });
118
+ const existingRemote = git(["remote", "get-url", "origin"], { cwd: root });
119
+ if (existingRemote.ok) {
120
+ if (existingRemote.stdout !== remote) {
121
+ git(["remote", "set-url", "origin", remote], { cwd: root });
122
+ }
123
+ }
124
+ else {
125
+ git(["remote", "add", "origin", remote], { cwd: root });
126
+ }
127
+ ensureGitIdentity(root);
128
+ const fetched = git(["fetch", "origin", branch], { cwd: root });
129
+ if (fetched.ok && git(["rev-parse", `origin/${branch}`], { cwd: root }).ok) {
130
+ git(["reset", "--hard", `origin/${branch}`], { cwd: root });
131
+ git(["branch", `--set-upstream-to=origin/${branch}`, branch], { cwd: root });
132
+ return "adopted";
133
+ }
134
+ if (!fetched.ok && !isMissingBranch(fetched))
135
+ throw toGitError("Initial fetch", fetched);
136
+ return "fresh";
137
+ }
138
+ function isMissingBranch(result) {
139
+ return /couldn't find remote ref|remote branch .* not found/i.test(`${result.stderr}\n${result.stdout}`);
140
+ }
141
+ export function ensureRepo(options) {
142
+ if (!isGitRepo(options.root))
143
+ return initRepo(options);
144
+ ensureGitIdentity(options.root);
145
+ const remote = git(["remote", "get-url", "origin"], { cwd: options.root });
146
+ if (!remote.ok) {
147
+ git(["remote", "add", "origin", options.remote], { cwd: options.root });
148
+ }
149
+ else if (remote.stdout !== options.remote) {
150
+ git(["remote", "set-url", "origin", options.remote], { cwd: options.root });
151
+ }
152
+ return "ready";
153
+ }
154
+ /** Fail fast when the remote is unreachable, distinguishing auth from network. */
155
+ export function assertRemoteReachable(root, branch, operation, allowMissingBranch = false) {
156
+ const result = git(["ls-remote", "--exit-code", "origin", `refs/heads/${branch}`], { cwd: root });
157
+ if (result.ok)
158
+ return;
159
+ if (allowMissingBranch && git(["ls-remote", "origin"], { cwd: root }).ok)
160
+ return;
161
+ throw toGitError(operation, result);
162
+ }
163
+ /**
164
+ * Verify the commit really landed on the remote.
165
+ *
166
+ * `git push` can exit zero against a misconfigured proxy or a stale credential
167
+ * helper without the remote actually moving, so success is confirmed by reading
168
+ * the remote head back.
169
+ */
170
+ export function assertPushLanded(root, branch, operation) {
171
+ const local = git(["rev-parse", "HEAD"], { cwd: root });
172
+ const remote = git(["ls-remote", "origin", `refs/heads/${branch}`], { cwd: root });
173
+ if (!remote.ok)
174
+ throw toGitError(operation, remote);
175
+ if (!local.ok)
176
+ throw toGitError(operation, local);
177
+ const remoteHead = remote.stdout.split(/\s+/)[0] ?? "";
178
+ if (remoteHead === local.stdout)
179
+ return;
180
+ throw new Error(`${operation} reported success but the remote did not move.\n` +
181
+ ` local: ${local.stdout}\n remote: ${remoteHead || "(empty)"}`);
182
+ }
183
+ export const REPO_DIRS = { DATA_DIR, STATE_DIR, AGENTS_DIR, SESSIONS_DIR };
184
+ //# sourceMappingURL=repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo.js","sourceRoot":"","sources":["../../src/core/repo.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAkB,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;EAC/B,aAAa;E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AE,CACpE,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Terminal presentation layer.
3
+ *
4
+ * The core never writes to stdout directly. It emits structured events through
5
+ * a `Reporter`, so the same sync logic can render as a pretty CLI, as silent
6
+ * JSON, or as OpenCode toast notifications from inside the plugin.
7
+ */
8
+ export type ChangeKind = "added" | "modified" | "deleted" | "renamed";
9
+ export interface ChangeSummary {
10
+ added: number;
11
+ modified: number;
12
+ deleted: number;
13
+ renamed: number;
14
+ }
15
+ export interface ChangedFile {
16
+ kind: ChangeKind;
17
+ path: string;
18
+ }
19
+ export interface Reporter {
20
+ step(message: string): void;
21
+ info(message: string): void;
22
+ success(message: string): void;
23
+ warn(message: string): void;
24
+ error(message: string): void;
25
+ detail(message: string): void;
26
+ changes(summary: ChangeSummary, files: ChangedFile[]): void;
27
+ }
28
+ export declare const silentReporter: Reporter;
29
+ /** Collects everything for later inspection — used by the plugin and tests. */
30
+ export declare class CollectingReporter implements Reporter {
31
+ readonly lines: {
32
+ level: string;
33
+ message: string;
34
+ }[];
35
+ summary: ChangeSummary;
36
+ files: ChangedFile[];
37
+ private push;
38
+ step(message: string): void;
39
+ info(message: string): void;
40
+ success(message: string): void;
41
+ warn(message: string): void;
42
+ error(message: string): void;
43
+ detail(message: string): void;
44
+ changes(summary: ChangeSummary, files: ChangedFile[]): void;
45
+ get text(): string;
46
+ }
47
+ export declare function emptySummary(): ChangeSummary;
48
+ export declare function summarize(files: ChangedFile[]): ChangeSummary;
49
+ export declare function totalChanges(summary: ChangeSummary): number;
50
+ //# sourceMappingURL=reporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../../src/core/reporter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,UAAU,GAAG,OA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,CAAC,OAAO,EAAE,MAAM;IAGtB,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE;IAKpD,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF;AAED,wBAAgB,YAAY,IAAI,aAAa,CAE5C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,aAAa,CAI7D;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAE3D"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Terminal presentation layer.
3
+ *
4
+ * The core never writes to stdout directly. It emits structured events through
5
+ * a `Reporter`, so the same sync logic can render as a pretty CLI, as silent
6
+ * JSON, or as OpenCode toast notifications from inside the plugin.
7
+ */
8
+ export const silentReporter = {
9
+ step() { },
10
+ info() { },
11
+ success() { },
12
+ warn() { },
13
+ error() { },
14
+ detail() { },
15
+ changes() { },
16
+ };
17
+ /** Collects everything for later inspection — used by the plugin and tests. */
18
+ export class CollectingReporter {
19
+ lines = [];
20
+ summary = { added: 0, modified: 0, deleted: 0, renamed: 0 };
21
+ files = [];
22
+ push(level, message) {
23
+ this.lines.push({ level, message });
24
+ }
25
+ step(message) {
26
+ this.push("step", message);
27
+ }
28
+ info(message) {
29
+ this.push("info", message);
30
+ }
31
+ success(message) {
32
+ this.push("success", message);
33
+ }
34
+ warn(message) {
35
+ this.push("warn", message);
36
+ }
37
+ error(message) {
38
+ this.push("error", message);
39
+ }
40
+ detail(message) {
41
+ this.push("detail", message);
42
+ }
43
+ changes(summary, files) {
44
+ this.summary = summary;
45
+ this.files = files;
46
+ }
47
+ get text() {
48
+ return this.lines.map((l) => l.message).join("\n");
49
+ }
50
+ }
51
+ export function emptySummary() {
52
+ return { added: 0, modified: 0, deleted: 0, renamed: 0 };
53
+ }
54
+ export function summarize(files) {
55
+ const summary = emptySummary();
56
+ for (const file of files)
57
+ summary[file.kind]++;
58
+ return summary;
59
+ }
60
+ export function totalChanges(summary) {
61
+ return summary.added + summary.modified + summary.deleted + summary.renamed;
62
+ }
63
+ //# sourceMappingURL=reporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporter.js","sourceRoot":"","sources":["../../src/core/reporter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA0BH,MAAM,CAAC,MAAM,cAAc,GAAa;IACtC,IAAI,KAAI,CAAC;IACT,IAAI,KAAI,CAAC;IACT,OAAO,KAAI,CAAC;IACZ,IAAI,KAAI,CAAC;IACT,KAAK,KAAI,CAAC;IACV,MAAM,KAAI,CAAC;IACX,OAAO,KAAI,CAAC;CACb,CAAC;AAEF,+EAA+E;AAC/E,MAAM,OAAO,kBAAkB;IACpB,KAAK,GAAyC,EAAE,CAAC;IAC1D,OAAO,GAAkB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IAC3E,KAAK,GAAkB,EAAE,CAAC;IAElB,IAAI,CAAC,KAAa,EAAE,OAAe;QACzC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,CAAC,OAAe;QACrB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IACD,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC;IACD,KAAK,CAAC,OAAe;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IACD,MAAM,CAAC,OAAe;QACpB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,CAAC,OAAsB,EAAE,KAAoB;QAClD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;CACF;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAoB;IAC5C,MAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC/C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,OAAO,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,61 @@
1
+ import type { Reporter } from "./reporter.js";
2
+ import type { SessionSettings } from "./settings.js";
3
+ import { type SqliteDatabase } from "./sqlite.js";
4
+ /**
5
+ * `event` and `event_sequence` are deliberately excluded. They are an internal
6
+ * append-only runtime log, they dwarf everything else in row count, and nothing
7
+ * about resuming a conversation on another machine depends on them.
8
+ */
9
+ export interface SessionRecord {
10
+ id: string;
11
+ title: string;
12
+ directory: string;
13
+ timeUpdated: number;
14
+ timeCreated: number;
15
+ projectId: string;
16
+ }
17
+ export interface SessionShard {
18
+ formatVersion: 1;
19
+ session: Record<string, unknown>;
20
+ project?: Record<string, unknown>;
21
+ workspace?: Record<string, unknown>;
22
+ tables: Record<string, Record<string, unknown>[]>;
23
+ exportedAt: number;
24
+ }
25
+ export interface SelectOptions extends SessionSettings {
26
+ now?: number;
27
+ }
28
+ export interface ExportResult {
29
+ written: string[];
30
+ skippedTooLarge: {
31
+ id: string;
32
+ title: string;
33
+ bytes: number;
34
+ }[];
35
+ considered: number;
36
+ }
37
+ export interface ImportResult {
38
+ imported: number;
39
+ skippedOlder: number;
40
+ failed: {
41
+ file: string;
42
+ reason: string;
43
+ }[];
44
+ }
45
+ /** Session ids are opaque; keep them filesystem-safe without losing identity. */
46
+ export declare function sanitizeId(id: string): string;
47
+ /**
48
+ * Choose which sessions to export.
49
+ *
50
+ * Explicitly included ids always win, even when they fall outside the window.
51
+ * Everything else must be inside the time window, pass the directory filter and
52
+ * survive the count cap, which keeps the newest sessions.
53
+ */
54
+ export declare function selectSessions(db: SqliteDatabase, options: SelectOptions): SessionRecord[];
55
+ /** Export the selected sessions into `<repo>/_sessions`. */
56
+ export declare function exportSessions(databaseFile: string, repoRoot: string, options: SelectOptions, reporter: Reporter): Promise<ExportResult>;
57
+ /** Import every shard from `<repo>/_sessions` into the local database. */
58
+ export declare function importSessions(databaseFile: string, repoRoot: string, reporter: Reporter): Promise<ImportResult>;
59
+ /** List sessions available locally, newest first — powers `sessions list`. */
60
+ export declare function listSessions(databaseFile: string, limit: number): Promise<SessionRecord[]>;
61
+ //# sourceMappingURL=sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../src/core/sessions.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAA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