@infinite-room-labs/claudesync-core 0.3.0 → 0.4.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/dist/client/client.d.ts +3 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +2 -2
- package/dist/client/client.js.map +1 -1
- package/dist/client/endpoints.d.ts +3 -1
- package/dist/client/endpoints.d.ts.map +1 -1
- package/dist/client/endpoints.js +1 -1
- package/dist/client/endpoints.js.map +1 -1
- package/dist/export/__tests__/bundle-builder.test.js +23 -0
- package/dist/export/__tests__/bundle-builder.test.js.map +1 -1
- package/dist/export/__tests__/git-exporter.test.d.ts +2 -0
- package/dist/export/__tests__/git-exporter.test.d.ts.map +1 -0
- package/dist/export/__tests__/git-exporter.test.js +115 -0
- package/dist/export/__tests__/git-exporter.test.js.map +1 -0
- package/dist/export/bundle-builder.d.ts +15 -7
- package/dist/export/bundle-builder.d.ts.map +1 -1
- package/dist/export/bundle-builder.js +71 -26
- package/dist/export/bundle-builder.js.map +1 -1
- package/dist/export/git-exporter.d.ts +20 -4
- package/dist/export/git-exporter.d.ts.map +1 -1
- package/dist/export/git-exporter.js +188 -39
- package/dist/export/git-exporter.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/models/schemas.d.ts +24 -24
- package/dist/models/schemas.js +3 -3
- package/dist/models/schemas.js.map +1 -1
- package/dist/sync/__tests__/changelog.test.d.ts +2 -0
- package/dist/sync/__tests__/changelog.test.d.ts.map +1 -0
- package/dist/sync/__tests__/changelog.test.js +114 -0
- package/dist/sync/__tests__/changelog.test.js.map +1 -0
- package/dist/sync/__tests__/diff.test.d.ts +2 -0
- package/dist/sync/__tests__/diff.test.d.ts.map +1 -0
- package/dist/sync/__tests__/diff.test.js +154 -0
- package/dist/sync/__tests__/diff.test.js.map +1 -0
- package/dist/sync/__tests__/state.test.d.ts +2 -0
- package/dist/sync/__tests__/state.test.d.ts.map +1 -0
- package/dist/sync/__tests__/state.test.js +53 -0
- package/dist/sync/__tests__/state.test.js.map +1 -0
- package/dist/sync/changelog.d.ts +19 -0
- package/dist/sync/changelog.d.ts.map +1 -0
- package/dist/sync/changelog.js +138 -0
- package/dist/sync/changelog.js.map +1 -0
- package/dist/sync/diff.d.ts +66 -0
- package/dist/sync/diff.d.ts.map +1 -0
- package/dist/sync/diff.js +125 -0
- package/dist/sync/diff.js.map +1 -0
- package/dist/sync/incremental.d.ts +36 -0
- package/dist/sync/incremental.d.ts.map +1 -0
- package/dist/sync/incremental.js +229 -0
- package/dist/sync/incremental.js.map +1 -0
- package/dist/sync/state.d.ts +108 -0
- package/dist/sync/state.d.ts.map +1 -0
- package/dist/sync/state.js +52 -0
- package/dist/sync/state.js.map +1 -0
- package/dist/tree/__tests__/message-tree.test.js +61 -1
- package/dist/tree/__tests__/message-tree.test.js.map +1 -1
- package/dist/tree/message-tree.d.ts +19 -0
- package/dist/tree/message-tree.d.ts.map +1 -1
- package/dist/tree/message-tree.js +50 -0
- package/dist/tree/message-tree.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { appendChangelog, renderChangelogSection, CHANGELOG_FILENAME, } from "../changelog.js";
|
|
6
|
+
let dir;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), "csync-changelog-"));
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
12
|
+
});
|
|
13
|
+
const initialDiff = {
|
|
14
|
+
isInitial: true,
|
|
15
|
+
isUnchanged: false,
|
|
16
|
+
branches: [
|
|
17
|
+
{
|
|
18
|
+
leafUuid: "leaf-1",
|
|
19
|
+
shortLabel: "leaf-1",
|
|
20
|
+
isMain: true,
|
|
21
|
+
isNew: true,
|
|
22
|
+
hasNewMessages: false,
|
|
23
|
+
newMessageIndices: [0, 1],
|
|
24
|
+
messages: [
|
|
25
|
+
{ uuid: "a", parent_message_uuid: "00000000", index: 0, sender: "human", text: "", created_at: "", updated_at: "", attachments: [], files_v2: [], sync_sources: [] },
|
|
26
|
+
{ uuid: "b", parent_message_uuid: "a", index: 1, sender: "assistant", text: "", created_at: "", updated_at: "", attachments: [], files_v2: [], sync_sources: [] },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
artifacts: { added: [{ path: "/mnt/user-data/outputs/x.md", size: 10, created_at: "" }], changed: [], removed: [] },
|
|
31
|
+
metadata: {},
|
|
32
|
+
};
|
|
33
|
+
const incrementalDiff = {
|
|
34
|
+
isInitial: false,
|
|
35
|
+
isUnchanged: false,
|
|
36
|
+
branches: [
|
|
37
|
+
{
|
|
38
|
+
leafUuid: "leaf-1",
|
|
39
|
+
shortLabel: "leaf-1",
|
|
40
|
+
isMain: true,
|
|
41
|
+
isNew: false,
|
|
42
|
+
hasNewMessages: true,
|
|
43
|
+
newMessageIndices: [2, 3],
|
|
44
|
+
messages: [],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
leafUuid: "leaf-2",
|
|
48
|
+
shortLabel: "leaf-2",
|
|
49
|
+
isMain: false,
|
|
50
|
+
isNew: true,
|
|
51
|
+
hasNewMessages: false,
|
|
52
|
+
newMessageIndices: [4],
|
|
53
|
+
messages: [
|
|
54
|
+
{ uuid: "z", parent_message_uuid: "a", index: 4, sender: "assistant", text: "", created_at: "", updated_at: "", attachments: [], files_v2: [], sync_sources: [] },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
artifacts: {
|
|
59
|
+
added: [],
|
|
60
|
+
changed: [{ path: "/mnt/user-data/outputs/x.md", size: 20, created_at: "", prev_size: 10, prev_created_at: "" }],
|
|
61
|
+
removed: [],
|
|
62
|
+
},
|
|
63
|
+
metadata: { renamed: { from: "old", to: "new" } },
|
|
64
|
+
};
|
|
65
|
+
describe("renderChangelogSection", () => {
|
|
66
|
+
it("returns initial export section for first sync", () => {
|
|
67
|
+
const out = renderChangelogSection(initialDiff, new Date("2026-04-30T00:00:00Z"));
|
|
68
|
+
expect(out).toContain("## 2026-04-30");
|
|
69
|
+
expect(out).toContain("### Initial export");
|
|
70
|
+
expect(out).toContain("1 branch(es)");
|
|
71
|
+
});
|
|
72
|
+
it("returns added/changed sections for incremental", () => {
|
|
73
|
+
const out = renderChangelogSection(incrementalDiff, new Date("2026-04-30T00:00:00Z"));
|
|
74
|
+
expect(out).toContain("### Added");
|
|
75
|
+
expect(out).toContain("Branch `alt-leaf-2`");
|
|
76
|
+
expect(out).toContain("### Changed");
|
|
77
|
+
expect(out).toContain("2 new message(s) on current branch (indices 2-3)");
|
|
78
|
+
expect(out).toContain("Conversation renamed: `old` -> `new`");
|
|
79
|
+
expect(out).toContain("Artifact `x.md` updated (10 -> 20 bytes)");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("appendChangelog", () => {
|
|
83
|
+
it("creates a new CHANGELOG.md with header on first call", () => {
|
|
84
|
+
const section = renderChangelogSection(initialDiff, new Date("2026-04-30T00:00:00Z"));
|
|
85
|
+
expect(appendChangelog(dir, section)).toBe(true);
|
|
86
|
+
const content = fs.readFileSync(path.join(dir, CHANGELOG_FILENAME), "utf-8");
|
|
87
|
+
expect(content.startsWith("# Changelog")).toBe(true);
|
|
88
|
+
expect(content).toContain("## 2026-04-30");
|
|
89
|
+
expect(content).toContain("### Initial export");
|
|
90
|
+
});
|
|
91
|
+
it("prepends new dates above older entries", () => {
|
|
92
|
+
appendChangelog(dir, renderChangelogSection(initialDiff, new Date("2026-04-29T00:00:00Z")));
|
|
93
|
+
appendChangelog(dir, renderChangelogSection(incrementalDiff, new Date("2026-04-30T00:00:00Z")));
|
|
94
|
+
const content = fs.readFileSync(path.join(dir, CHANGELOG_FILENAME), "utf-8");
|
|
95
|
+
const i30 = content.indexOf("## 2026-04-30");
|
|
96
|
+
const i29 = content.indexOf("## 2026-04-29");
|
|
97
|
+
expect(i30).toBeGreaterThan(-1);
|
|
98
|
+
expect(i29).toBeGreaterThan(i30);
|
|
99
|
+
});
|
|
100
|
+
it("merges same-day calls into a single date heading", () => {
|
|
101
|
+
appendChangelog(dir, renderChangelogSection(initialDiff, new Date("2026-04-30T00:00:00Z")));
|
|
102
|
+
appendChangelog(dir, renderChangelogSection(incrementalDiff, new Date("2026-04-30T01:00:00Z")));
|
|
103
|
+
const content = fs.readFileSync(path.join(dir, CHANGELOG_FILENAME), "utf-8");
|
|
104
|
+
const occurrences = content.match(/^## 2026-04-30$/gm) ?? [];
|
|
105
|
+
expect(occurrences.length).toBe(1);
|
|
106
|
+
expect(content).toContain("### Initial export");
|
|
107
|
+
expect(content).toContain("### Added");
|
|
108
|
+
});
|
|
109
|
+
it("returns false and writes nothing for empty sections", () => {
|
|
110
|
+
expect(appendChangelog(dir, "")).toBe(false);
|
|
111
|
+
expect(fs.existsSync(path.join(dir, CHANGELOG_FILENAME))).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
//# sourceMappingURL=changelog.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog.test.js","sourceRoot":"","sources":["../../../src/sync/__tests__/changelog.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AA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,WAAW,EAAE,IAAI,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;QAC5F,eAAe,CAAC,GAAG,EAAE,sBAAsB,CAAC,eAAe,EAAE,IAAI,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;QAChG,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC,CAAC;QAC7E,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC;QAC7D,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QAChD,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7C,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.test.d.ts","sourceRoot":"","sources":["../../../src/sync/__tests__/diff.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { diffConversation } from "../diff.js";
|
|
3
|
+
function msg(uuid, parent, index, text = "") {
|
|
4
|
+
return {
|
|
5
|
+
uuid,
|
|
6
|
+
parent_message_uuid: parent,
|
|
7
|
+
index,
|
|
8
|
+
sender: index % 2 === 0 ? "human" : "assistant",
|
|
9
|
+
text: text || `m${index}`,
|
|
10
|
+
created_at: `2026-04-30T13:50:0${index}Z`,
|
|
11
|
+
updated_at: `2026-04-30T13:50:0${index}Z`,
|
|
12
|
+
attachments: [],
|
|
13
|
+
files_v2: [],
|
|
14
|
+
sync_sources: [],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function conv(messages, leaf, name = "c") {
|
|
18
|
+
return {
|
|
19
|
+
uuid: "conv-1",
|
|
20
|
+
name,
|
|
21
|
+
model: "claude-haiku-4-5",
|
|
22
|
+
created_at: "2026-04-30T13:50:00Z",
|
|
23
|
+
updated_at: messages[messages.length - 1].created_at,
|
|
24
|
+
current_leaf_message_uuid: leaf,
|
|
25
|
+
chat_messages: messages,
|
|
26
|
+
is_starred: false,
|
|
27
|
+
is_temporary: false,
|
|
28
|
+
summary: "",
|
|
29
|
+
settings: {},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const noArtifacts = {
|
|
33
|
+
success: true,
|
|
34
|
+
files: [],
|
|
35
|
+
files_metadata: [],
|
|
36
|
+
};
|
|
37
|
+
describe("diffConversation", () => {
|
|
38
|
+
it("treats missing prevState as initial sync", () => {
|
|
39
|
+
const c = conv([msg("a", "00000000", 0), msg("b", "a", 1)], "b");
|
|
40
|
+
const d = diffConversation(undefined, c, noArtifacts);
|
|
41
|
+
expect(d.isInitial).toBe(true);
|
|
42
|
+
expect(d.isUnchanged).toBe(false);
|
|
43
|
+
expect(d.branches).toHaveLength(1);
|
|
44
|
+
expect(d.branches[0].isMain).toBe(true);
|
|
45
|
+
expect(d.branches[0].isNew).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it("flags unchanged when nothing differs", () => {
|
|
48
|
+
const c = conv([msg("a", "00000000", 0), msg("b", "a", 1)], "b");
|
|
49
|
+
const prev = {
|
|
50
|
+
schema_version: 1,
|
|
51
|
+
conversation_uuid: "conv-1",
|
|
52
|
+
conversation_name: "c",
|
|
53
|
+
updated_at: c.updated_at,
|
|
54
|
+
current_leaf_message_uuid: "b",
|
|
55
|
+
leaves: [{ uuid: "b", last_message_index: 1 }],
|
|
56
|
+
artifacts: [],
|
|
57
|
+
last_sync_at: "2026-04-30T13:55:00Z",
|
|
58
|
+
last_sync_action: "full",
|
|
59
|
+
};
|
|
60
|
+
const d = diffConversation(prev, c, noArtifacts);
|
|
61
|
+
expect(d.isUnchanged).toBe(true);
|
|
62
|
+
expect(d.branches[0].hasNewMessages).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
it("treats a forward-moving leaf as 'new messages on existing branch', not a new branch", () => {
|
|
65
|
+
const c = conv([msg("a", "00000000", 0), msg("b", "a", 1), msg("c", "b", 2)], "c");
|
|
66
|
+
const prev = {
|
|
67
|
+
schema_version: 1,
|
|
68
|
+
conversation_uuid: "conv-1",
|
|
69
|
+
conversation_name: "c",
|
|
70
|
+
updated_at: "2026-04-30T13:50:01Z",
|
|
71
|
+
current_leaf_message_uuid: "b",
|
|
72
|
+
leaves: [{ uuid: "b", last_message_index: 1 }],
|
|
73
|
+
artifacts: [],
|
|
74
|
+
last_sync_at: "2026-04-30T13:55:00Z",
|
|
75
|
+
last_sync_action: "full",
|
|
76
|
+
};
|
|
77
|
+
const d = diffConversation(prev, c, noArtifacts);
|
|
78
|
+
expect(d.isUnchanged).toBe(false);
|
|
79
|
+
const cBranch = d.branches.find((br) => br.leafUuid === "c");
|
|
80
|
+
expect(cBranch.isNew).toBe(false);
|
|
81
|
+
expect(cBranch.hasNewMessages).toBe(true);
|
|
82
|
+
expect(cBranch.newMessageIndices).toEqual([2]);
|
|
83
|
+
});
|
|
84
|
+
it("detects new orphan branch when the tree gains a sibling", () => {
|
|
85
|
+
// Initial: a -> b. New: a -> b (orphan), a -> c (current).
|
|
86
|
+
const c = conv([
|
|
87
|
+
msg("a", "00000000", 0),
|
|
88
|
+
msg("b", "a", 1),
|
|
89
|
+
msg("c", "a", 2),
|
|
90
|
+
], "c");
|
|
91
|
+
const prev = {
|
|
92
|
+
schema_version: 1,
|
|
93
|
+
conversation_uuid: "conv-1",
|
|
94
|
+
conversation_name: "c",
|
|
95
|
+
updated_at: "2026-04-30T13:50:01Z",
|
|
96
|
+
current_leaf_message_uuid: "b",
|
|
97
|
+
leaves: [{ uuid: "b", last_message_index: 1 }],
|
|
98
|
+
artifacts: [],
|
|
99
|
+
last_sync_at: "2026-04-30T13:55:00Z",
|
|
100
|
+
last_sync_action: "full",
|
|
101
|
+
};
|
|
102
|
+
const d = diffConversation(prev, c, noArtifacts);
|
|
103
|
+
expect(d.isUnchanged).toBe(false);
|
|
104
|
+
// c is the new main; b is now an alt that already existed -> not "new".
|
|
105
|
+
expect(d.branches.find((br) => br.leafUuid === "c").isNew).toBe(true);
|
|
106
|
+
expect(d.branches.find((br) => br.leafUuid === "b").isNew).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
it("detects added/changed/removed artifacts", () => {
|
|
109
|
+
const c = conv([msg("a", "00000000", 0)], "a");
|
|
110
|
+
const artifacts = {
|
|
111
|
+
success: true,
|
|
112
|
+
files: ["/mnt/user-data/outputs/new.md", "/mnt/user-data/outputs/changed.md"],
|
|
113
|
+
files_metadata: [
|
|
114
|
+
{ path: "/mnt/user-data/outputs/new.md", size: 10, content_type: "text/plain", created_at: "2026-04-30T00:00:01Z", custom_metadata: { filename: "new.md" } },
|
|
115
|
+
{ path: "/mnt/user-data/outputs/changed.md", size: 50, content_type: "text/plain", created_at: "2026-04-30T00:00:02Z", custom_metadata: { filename: "changed.md" } },
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
const prev = {
|
|
119
|
+
schema_version: 1,
|
|
120
|
+
conversation_uuid: "conv-1",
|
|
121
|
+
conversation_name: "c",
|
|
122
|
+
updated_at: "2026-04-30T13:50:00Z",
|
|
123
|
+
current_leaf_message_uuid: "a",
|
|
124
|
+
leaves: [{ uuid: "a", last_message_index: 0 }],
|
|
125
|
+
artifacts: [
|
|
126
|
+
{ path: "/mnt/user-data/outputs/changed.md", size: 25, created_at: "2026-04-30T00:00:00Z" },
|
|
127
|
+
{ path: "/mnt/user-data/outputs/gone.md", size: 5, created_at: "2026-04-30T00:00:00Z" },
|
|
128
|
+
],
|
|
129
|
+
last_sync_at: "2026-04-30T13:55:00Z",
|
|
130
|
+
last_sync_action: "full",
|
|
131
|
+
};
|
|
132
|
+
const d = diffConversation(prev, c, artifacts);
|
|
133
|
+
expect(d.artifacts.added.map((a) => a.path)).toEqual(["/mnt/user-data/outputs/new.md"]);
|
|
134
|
+
expect(d.artifacts.changed.map((a) => a.path)).toEqual(["/mnt/user-data/outputs/changed.md"]);
|
|
135
|
+
expect(d.artifacts.removed.map((a) => a.path)).toEqual(["/mnt/user-data/outputs/gone.md"]);
|
|
136
|
+
});
|
|
137
|
+
it("detects rename in metadata", () => {
|
|
138
|
+
const c = conv([msg("a", "00000000", 0)], "a", "new name");
|
|
139
|
+
const prev = {
|
|
140
|
+
schema_version: 1,
|
|
141
|
+
conversation_uuid: "conv-1",
|
|
142
|
+
conversation_name: "old name",
|
|
143
|
+
updated_at: "2026-04-30T13:50:00Z",
|
|
144
|
+
current_leaf_message_uuid: "a",
|
|
145
|
+
leaves: [{ uuid: "a", last_message_index: 0 }],
|
|
146
|
+
artifacts: [],
|
|
147
|
+
last_sync_at: "2026-04-30T13:55:00Z",
|
|
148
|
+
last_sync_action: "full",
|
|
149
|
+
};
|
|
150
|
+
const d = diffConversation(prev, c, noArtifacts);
|
|
151
|
+
expect(d.metadata.renamed).toEqual({ from: "old name", to: "new name" });
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=diff.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.test.js","sourceRoot":"","sources":["../../../src/sync/__tests__/diff.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAA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AM,CAAC,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;QACjD,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.test.d.ts","sourceRoot":"","sources":["../../../src/sync/__tests__/state.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { readSyncState, writeSyncState, STATE_FILENAME, } from "../state.js";
|
|
6
|
+
let dir;
|
|
7
|
+
function sample() {
|
|
8
|
+
return {
|
|
9
|
+
schema_version: 1,
|
|
10
|
+
conversation_uuid: "conv-1",
|
|
11
|
+
conversation_name: "test",
|
|
12
|
+
updated_at: "2026-04-30T13:55:03.195890Z",
|
|
13
|
+
current_leaf_message_uuid: "leaf-1",
|
|
14
|
+
leaves: [{ uuid: "leaf-1", last_message_index: 13 }],
|
|
15
|
+
artifacts: [
|
|
16
|
+
{ path: "/mnt/user-data/outputs/x.md", size: 10, created_at: "2026-04-30T00:00:00Z" },
|
|
17
|
+
],
|
|
18
|
+
last_sync_at: "2026-04-30T14:00:00Z",
|
|
19
|
+
last_sync_action: "full",
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), "csync-state-"));
|
|
24
|
+
});
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
27
|
+
});
|
|
28
|
+
describe("sync state", () => {
|
|
29
|
+
it("returns undefined when state file does not exist", () => {
|
|
30
|
+
expect(readSyncState(dir)).toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
it("round-trips a state object", () => {
|
|
33
|
+
const s = sample();
|
|
34
|
+
writeSyncState(dir, s);
|
|
35
|
+
const loaded = readSyncState(dir);
|
|
36
|
+
expect(loaded).toEqual(s);
|
|
37
|
+
});
|
|
38
|
+
it("writes atomically (no .tmp left behind on success)", () => {
|
|
39
|
+
writeSyncState(dir, sample());
|
|
40
|
+
const entries = fs.readdirSync(dir);
|
|
41
|
+
expect(entries).toContain(STATE_FILENAME);
|
|
42
|
+
expect(entries).not.toContain(STATE_FILENAME + ".tmp");
|
|
43
|
+
});
|
|
44
|
+
it("throws on corrupted JSON rather than silently bootstrapping", () => {
|
|
45
|
+
fs.writeFileSync(path.join(dir, STATE_FILENAME), "{not json", "utf-8");
|
|
46
|
+
expect(() => readSyncState(dir)).toThrow();
|
|
47
|
+
});
|
|
48
|
+
it("rejects state with wrong schema version", () => {
|
|
49
|
+
fs.writeFileSync(path.join(dir, STATE_FILENAME), JSON.stringify({ ...sample(), schema_version: 99 }), "utf-8");
|
|
50
|
+
expect(() => readSyncState(dir)).toThrow();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=state.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.test.js","sourceRoot":"","sources":["../../../src/sync/__tests__/state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,GAEf,MAAM,aAAa,CAAC;AAErB,IAAI,GAAW,CAAC;AAEhB,SAAS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,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9B,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QAC1C,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,GAAG,MAAM,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QACvE,MAAM,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAC9B,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC,EACnD,OAAO,CACR,CAAC;QACF,MAAM,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConversationDiff } from "./diff.js";
|
|
2
|
+
export declare const CHANGELOG_FILENAME = "CHANGELOG.md";
|
|
3
|
+
/**
|
|
4
|
+
* Renders a single dated section for a sync diff. Returns an empty string if
|
|
5
|
+
* there is nothing to record. Caller is expected to gate isUnchanged.
|
|
6
|
+
*
|
|
7
|
+
* Date is taken as the UTC date (YYYY-MM-DD) of `at`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderChangelogSection(diff: ConversationDiff, at: Date): string;
|
|
10
|
+
/**
|
|
11
|
+
* Appends a section to CHANGELOG.md inside `dir`, creating the file (with
|
|
12
|
+
* header) if missing. Newest entries go directly after the header so the file
|
|
13
|
+
* reads newest-first. If a section for the same date already exists, the new
|
|
14
|
+
* entries are inserted at the top of that date's section.
|
|
15
|
+
*
|
|
16
|
+
* Returns true if the file was modified, false if section was empty.
|
|
17
|
+
*/
|
|
18
|
+
export declare function appendChangelog(dir: string, section: string): boolean;
|
|
19
|
+
//# sourceMappingURL=changelog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog.d.ts","sourceRoot":"","sources":["../../src/sync/changelog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AASjD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,gBAAgB,EACtB,EAAE,EAAE,IAAI,GACP,MAAM,CAyFR;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAwCrE"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export const CHANGELOG_FILENAME = "CHANGELOG.md";
|
|
4
|
+
const CHANGELOG_HEADER = [
|
|
5
|
+
"# Changelog",
|
|
6
|
+
"",
|
|
7
|
+
"All sync activity for this conversation, newest first.",
|
|
8
|
+
"",
|
|
9
|
+
].join("\n");
|
|
10
|
+
/**
|
|
11
|
+
* Renders a single dated section for a sync diff. Returns an empty string if
|
|
12
|
+
* there is nothing to record. Caller is expected to gate isUnchanged.
|
|
13
|
+
*
|
|
14
|
+
* Date is taken as the UTC date (YYYY-MM-DD) of `at`.
|
|
15
|
+
*/
|
|
16
|
+
export function renderChangelogSection(diff, at) {
|
|
17
|
+
const date = at.toISOString().slice(0, 10);
|
|
18
|
+
const lines = [];
|
|
19
|
+
lines.push(`## ${date}`);
|
|
20
|
+
lines.push("");
|
|
21
|
+
if (diff.isInitial) {
|
|
22
|
+
lines.push("### Initial export");
|
|
23
|
+
lines.push("");
|
|
24
|
+
const branchCount = diff.branches.length;
|
|
25
|
+
const altCount = diff.branches.filter((b) => !b.isMain).length;
|
|
26
|
+
const totalMsgs = diff.branches.reduce((sum, b) => sum + b.messages.length, 0);
|
|
27
|
+
lines.push(`- ${branchCount} branch(es) (${altCount} alternate).`);
|
|
28
|
+
lines.push(`- ${totalMsgs} message(s) across all branches.`);
|
|
29
|
+
if (diff.artifacts.added.length > 0) {
|
|
30
|
+
lines.push(`- ${diff.artifacts.added.length} artifact(s).`);
|
|
31
|
+
}
|
|
32
|
+
lines.push("");
|
|
33
|
+
return lines.join("\n");
|
|
34
|
+
}
|
|
35
|
+
const added = [];
|
|
36
|
+
const changed = [];
|
|
37
|
+
const removed = [];
|
|
38
|
+
for (const b of diff.branches) {
|
|
39
|
+
if (b.isNew) {
|
|
40
|
+
const branchTag = b.isMain ? "main" : `alt-${b.shortLabel}`;
|
|
41
|
+
added.push(`- Branch \`${branchTag}\` discovered (${b.messages.length} message(s), leaf \`${b.leafUuid}\`).`);
|
|
42
|
+
}
|
|
43
|
+
else if (b.hasNewMessages) {
|
|
44
|
+
const branchTag = b.isMain ? "current branch" : `branch alt-${b.shortLabel}`;
|
|
45
|
+
const range = b.newMessageIndices.length === 1
|
|
46
|
+
? `index ${b.newMessageIndices[0]}`
|
|
47
|
+
: `indices ${b.newMessageIndices[0]}-${b.newMessageIndices[b.newMessageIndices.length - 1]}`;
|
|
48
|
+
changed.push(`- ${b.newMessageIndices.length} new message(s) on ${branchTag} (${range}).`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const a of diff.artifacts.added) {
|
|
52
|
+
added.push(`- Artifact \`${basenameOf(a.path)}\` (${a.size} bytes).`);
|
|
53
|
+
}
|
|
54
|
+
for (const a of diff.artifacts.changed) {
|
|
55
|
+
changed.push(`- Artifact \`${basenameOf(a.path)}\` updated (${a.prev_size} -> ${a.size} bytes).`);
|
|
56
|
+
}
|
|
57
|
+
for (const a of diff.artifacts.removed) {
|
|
58
|
+
removed.push(`- Artifact \`${basenameOf(a.path)}\` removed.`);
|
|
59
|
+
}
|
|
60
|
+
if (diff.metadata.renamed) {
|
|
61
|
+
changed.push(`- Conversation renamed: \`${diff.metadata.renamed.from}\` -> \`${diff.metadata.renamed.to}\`.`);
|
|
62
|
+
}
|
|
63
|
+
if (diff.metadata.modelChanged) {
|
|
64
|
+
changed.push(`- Model changed: \`${diff.metadata.modelChanged.from ?? "unknown"}\` -> \`${diff.metadata.modelChanged.to ?? "unknown"}\`.`);
|
|
65
|
+
}
|
|
66
|
+
if (added.length === 0 && changed.length === 0 && removed.length === 0) {
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
if (added.length > 0) {
|
|
70
|
+
lines.push("### Added");
|
|
71
|
+
lines.push(...added);
|
|
72
|
+
lines.push("");
|
|
73
|
+
}
|
|
74
|
+
if (changed.length > 0) {
|
|
75
|
+
lines.push("### Changed");
|
|
76
|
+
lines.push(...changed);
|
|
77
|
+
lines.push("");
|
|
78
|
+
}
|
|
79
|
+
if (removed.length > 0) {
|
|
80
|
+
lines.push("### Removed");
|
|
81
|
+
lines.push(...removed);
|
|
82
|
+
lines.push("");
|
|
83
|
+
}
|
|
84
|
+
return lines.join("\n");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Appends a section to CHANGELOG.md inside `dir`, creating the file (with
|
|
88
|
+
* header) if missing. Newest entries go directly after the header so the file
|
|
89
|
+
* reads newest-first. If a section for the same date already exists, the new
|
|
90
|
+
* entries are inserted at the top of that date's section.
|
|
91
|
+
*
|
|
92
|
+
* Returns true if the file was modified, false if section was empty.
|
|
93
|
+
*/
|
|
94
|
+
export function appendChangelog(dir, section) {
|
|
95
|
+
if (!section.trim())
|
|
96
|
+
return false;
|
|
97
|
+
const filePath = path.join(dir, CHANGELOG_FILENAME);
|
|
98
|
+
const existing = fs.existsSync(filePath)
|
|
99
|
+
? fs.readFileSync(filePath, "utf-8")
|
|
100
|
+
: CHANGELOG_HEADER;
|
|
101
|
+
const headerEnd = existing.indexOf("\n## ");
|
|
102
|
+
let head;
|
|
103
|
+
let rest;
|
|
104
|
+
if (headerEnd === -1) {
|
|
105
|
+
head = existing.endsWith("\n") ? existing : existing + "\n";
|
|
106
|
+
rest = "";
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
head = existing.slice(0, headerEnd + 1);
|
|
110
|
+
rest = existing.slice(headerEnd + 1);
|
|
111
|
+
}
|
|
112
|
+
// Section starts with "## YYYY-MM-DD\n\n...". Extract date.
|
|
113
|
+
const dateMatch = section.match(/^## (\d{4}-\d{2}-\d{2})\n/);
|
|
114
|
+
if (!dateMatch) {
|
|
115
|
+
// Defensive: just prepend.
|
|
116
|
+
fs.writeFileSync(filePath, head + section + rest, "utf-8");
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
const date = dateMatch[1];
|
|
120
|
+
// If rest already starts with the same date heading, merge the bodies so we
|
|
121
|
+
// do not stack multiple "## 2026-04-30" sections in a single day.
|
|
122
|
+
const sameDayPrefix = `## ${date}\n`;
|
|
123
|
+
if (rest.startsWith(sameDayPrefix)) {
|
|
124
|
+
const sectionBody = section.slice(`## ${date}\n\n`.length);
|
|
125
|
+
const restWithoutHeading = rest.slice(sameDayPrefix.length).replace(/^\n/, "");
|
|
126
|
+
const merged = `## ${date}\n\n${sectionBody.trimEnd()}\n\n${restWithoutHeading}`;
|
|
127
|
+
fs.writeFileSync(filePath, head + merged, "utf-8");
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
fs.writeFileSync(filePath, head + section + rest, "utf-8");
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
function basenameOf(p) {
|
|
135
|
+
const parts = p.split("/");
|
|
136
|
+
return parts[parts.length - 1] || p;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=changelog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog.js","sourceRoot":"","sources":["../../src/sync/changelog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAEjD,MAAM,gBAAgB,GAAG;IACvB,aAAa;IACb,EAAE;IACF,wDAAwD;IACxD,EAAE;CACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,IAAsB,EACtB,EAAQ;IAER,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IACzB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;QAC/D,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAA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MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3D,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAG,MAAM,IAAI,OAAO,WAAW,CAAC,OAAO,EAAE,OAAO,kBAAkB,EAAE,CAAC;QACjF,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;SAAM,CAAC;QACN,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,GAAG,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ArtifactListResponse, ChatMessage, Conversation } from "../models/types.js";
|
|
2
|
+
import type { SyncState } from "./state.js";
|
|
3
|
+
export interface BranchDiff {
|
|
4
|
+
/** Leaf uuid identifying the branch. */
|
|
5
|
+
leafUuid: string;
|
|
6
|
+
/** Short label used for filesystem/git branch names (e.g. "019ddea7"). */
|
|
7
|
+
shortLabel: string;
|
|
8
|
+
/** True if the branch is the current/main branch (matches current_leaf_message_uuid). */
|
|
9
|
+
isMain: boolean;
|
|
10
|
+
/** True if the branch did not exist in the previous sync. */
|
|
11
|
+
isNew: boolean;
|
|
12
|
+
/** True if the branch existed but gained messages since last sync. */
|
|
13
|
+
hasNewMessages: boolean;
|
|
14
|
+
/** Indices of newly added messages on this branch (root->leaf order). */
|
|
15
|
+
newMessageIndices: number[];
|
|
16
|
+
/** Full root->leaf message array for the branch (always populated). */
|
|
17
|
+
messages: ChatMessage[];
|
|
18
|
+
}
|
|
19
|
+
export interface ArtifactDiff {
|
|
20
|
+
added: {
|
|
21
|
+
path: string;
|
|
22
|
+
size: number;
|
|
23
|
+
created_at: string;
|
|
24
|
+
}[];
|
|
25
|
+
changed: {
|
|
26
|
+
path: string;
|
|
27
|
+
size: number;
|
|
28
|
+
created_at: string;
|
|
29
|
+
prev_size: number;
|
|
30
|
+
prev_created_at: string;
|
|
31
|
+
}[];
|
|
32
|
+
removed: {
|
|
33
|
+
path: string;
|
|
34
|
+
size: number;
|
|
35
|
+
created_at: string;
|
|
36
|
+
}[];
|
|
37
|
+
}
|
|
38
|
+
export interface MetadataDiff {
|
|
39
|
+
renamed?: {
|
|
40
|
+
from: string;
|
|
41
|
+
to: string;
|
|
42
|
+
};
|
|
43
|
+
modelChanged?: {
|
|
44
|
+
from: string | null;
|
|
45
|
+
to: string | null;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface ConversationDiff {
|
|
49
|
+
/** True if there is no prior state (first sync of this conversation). */
|
|
50
|
+
isInitial: boolean;
|
|
51
|
+
/** True if state exists and nothing changed (caller may skip/log only). */
|
|
52
|
+
isUnchanged: boolean;
|
|
53
|
+
branches: BranchDiff[];
|
|
54
|
+
artifacts: ArtifactDiff;
|
|
55
|
+
metadata: MetadataDiff;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Diffs a freshly fetched conversation (with full message tree from
|
|
59
|
+
* ?tree=True) and its current artifact list against a previously stored
|
|
60
|
+
* SyncState.
|
|
61
|
+
*
|
|
62
|
+
* If prevState is undefined the result describes an "initial" sync: every
|
|
63
|
+
* branch is new, every artifact is added.
|
|
64
|
+
*/
|
|
65
|
+
export declare function diffConversation(prevState: SyncState | undefined, conversation: Conversation, artifacts: ArtifactListResponse): ConversationDiff;
|
|
66
|
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