@xsok/dsh-enhanced 0.0.0-stage → 0.2.2-11

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.
@@ -0,0 +1,202 @@
1
+ /**
2
+ * `session_projcache` title merge for the pure-JS engine.
3
+ *
4
+ * Each session has one shard document under `storages/session_projcache/sessions/`
5
+ * holding `{ version, record: { identity, rows: { title: { val, seq } } } }`.
6
+ * The title is the only field that travels: statistics and targets are per machine.
7
+ * A newer `seq` wins, otherwise the side that has a title wins; a shared mirror is
8
+ * written for every local shard so the other machine can pick it up.
9
+ *
10
+ * The merge is incremental: a shard whose mtime matches the previous snapshot on
11
+ * both sides is skipped without parsing, which is what keeps large caches cheap.
12
+ */
13
+ import { promises as fsp } from 'node:fs';
14
+ import { randomUUID } from 'node:crypto';
15
+ import path from 'node:path';
16
+
17
+ async function readJson(file) {
18
+ try {
19
+ return JSON.parse(await fsp.readFile(file, 'utf8'));
20
+ } catch {
21
+ return undefined;
22
+ }
23
+ }
24
+
25
+ async function writeJson(file, value) {
26
+ await fsp.mkdir(path.dirname(file), { recursive: true });
27
+ const temporary = `${file}.${randomUUID()}.tmp`;
28
+ await fsp.writeFile(temporary, `${JSON.stringify(value)}\n`, 'utf8');
29
+ await fsp.rename(temporary, file);
30
+ }
31
+
32
+ /** Title row of one shard, tolerating both document shapes. */
33
+ export function titleOf(doc) {
34
+ if (doc === null || typeof doc !== 'object') return undefined;
35
+ const record = doc.record !== undefined && doc.record !== null ? doc.record : doc;
36
+ const title = record?.rows?.title;
37
+ return title !== undefined && title !== null && title.val !== undefined ? title : undefined;
38
+ }
39
+
40
+ /** Newer `seq` wins; otherwise the side that has a title wins. */
41
+ export function pickTitle(localTitle, sharedTitle) {
42
+ if (sharedTitle === undefined) return localTitle;
43
+ if (localTitle === undefined) return sharedTitle;
44
+ return Number(localTitle.seq) >= Number(sharedTitle.seq) ? localTitle : sharedTitle;
45
+ }
46
+
47
+ function sameTitle(current, winner) {
48
+ return current !== undefined
49
+ && String(current.val) === String(winner.val)
50
+ && Number(current.seq) === Number(winner.seq);
51
+ }
52
+
53
+ function setTitle(doc, winner) {
54
+ const record = doc.record !== undefined && doc.record !== null ? doc.record : doc;
55
+ record.rows = record.rows ?? {};
56
+ record.rows.title = winner;
57
+ }
58
+
59
+ /** Whether one shard still claims its session was never used. */
60
+ function isBlank(doc) {
61
+ if (doc === null || typeof doc !== 'object') return false;
62
+ const record = doc.record !== undefined && doc.record !== null ? doc.record : doc;
63
+ return record?.rows?.sessionListMetadata?.val?.blank === true;
64
+ }
65
+
66
+ /** Map of session id -> { file, mtime } for one shard directory. */
67
+ async function indexShards(dir) {
68
+ const map = new Map();
69
+ let entries;
70
+ try {
71
+ entries = await fsp.readdir(dir, { withFileTypes: true });
72
+ } catch {
73
+ return map;
74
+ }
75
+ for (const entry of entries) {
76
+ if (!entry.isFile() || !entry.name.startsWith('session-') || !entry.name.endsWith('.json')) continue;
77
+ const file = path.join(dir, entry.name);
78
+ try {
79
+ const stat = await fsp.stat(file);
80
+ map.set(entry.name.slice(0, -5), { file, mtime: stat.mtimeMs });
81
+ } catch {
82
+ // A shard that vanished mid-scan is simply absent.
83
+ }
84
+ }
85
+ return map;
86
+ }
87
+
88
+ /**
89
+ * Merge titles between the local cache and its shared mirror.
90
+ * @returns counters for the run summary.
91
+ */
92
+ export async function mergeProjcacheTitles(deps) {
93
+ const {
94
+ localDir,
95
+ sharedDir,
96
+ stateDir,
97
+ machineId,
98
+ force = false,
99
+ apply = true,
100
+ // Sessions the blank-session guard keeps out of the share this run: their
101
+ // shard must not be mirrored either, or the empty state would still travel.
102
+ skipIds = new Set(),
103
+ } = deps;
104
+ const localIndex = await indexShards(localDir);
105
+ const sharedIndex = await indexShards(sharedDir);
106
+ if (localIndex.size === 0 && sharedIndex.size === 0) {
107
+ return { parsed: 0, updated: 0, mirrored: 0, untouched: 0 };
108
+ }
109
+
110
+ const stateFile = path.join(stateDir, `projcache-state-${machineId}.json`);
111
+ const previous = force ? {} : ((await readJson(stateFile)) ?? {});
112
+ const previousLocal = previous.local ?? {};
113
+ const previousShared = previous.shared ?? {};
114
+
115
+ let parsed = 0;
116
+ let updated = 0;
117
+ let mirrored = 0;
118
+ let untouched = 0;
119
+
120
+ for (const id of new Set([...localIndex.keys(), ...sharedIndex.keys()])) {
121
+ if (skipIds.has(id)) {
122
+ untouched += 1;
123
+ continue;
124
+ }
125
+ const localEntry = localIndex.get(id);
126
+ const sharedEntry = sharedIndex.get(id);
127
+ const currentLocal = localEntry === undefined ? -1 : localEntry.mtime;
128
+ const currentShared = sharedEntry === undefined ? -1 : sharedEntry.mtime;
129
+ if (!force && currentLocal === previousLocal[id] && currentShared === previousShared[id]) {
130
+ untouched += 1;
131
+ continue;
132
+ }
133
+
134
+ const localDoc = localEntry === undefined ? undefined : await readJson(localEntry.file);
135
+ if (localEntry !== undefined) parsed += 1;
136
+ const sharedDoc = sharedEntry === undefined ? undefined : await readJson(sharedEntry.file);
137
+ if (sharedEntry !== undefined) parsed += 1;
138
+
139
+ const localTitle = titleOf(localDoc);
140
+ const sharedTitle = titleOf(sharedDoc);
141
+ const winner = pickTitle(localTitle, sharedTitle);
142
+
143
+ if (winner !== undefined && localEntry !== undefined && localDoc !== undefined && !sameTitle(localTitle, winner)) {
144
+ setTitle(localDoc, winner);
145
+ if (apply) await writeJson(localEntry.file, localDoc);
146
+ updated += 1;
147
+ }
148
+ if (winner !== undefined && sharedEntry !== undefined && sharedDoc !== undefined && !sameTitle(sharedTitle, winner)) {
149
+ setTitle(sharedDoc, winner);
150
+ if (apply) await writeJson(sharedEntry.file, sharedDoc);
151
+ updated += 1;
152
+ }
153
+ if (sharedEntry === undefined && localEntry !== undefined) {
154
+ // No mirror yet: copy the whole shard so the share knows the session.
155
+ await fsp.mkdir(sharedDir, { recursive: true });
156
+ const target = path.join(sharedDir, `${id}.json`);
157
+ if (apply) {
158
+ try {
159
+ await fsp.copyFile(localEntry.file, target);
160
+ await fsp.utimes(target, new Date(localEntry.mtime), new Date(localEntry.mtime)).catch(() => {});
161
+ mirrored += 1;
162
+ } catch {
163
+ // A shard that cannot be mirrored is retried next round; never abort.
164
+ }
165
+ } else {
166
+ mirrored += 1;
167
+ }
168
+ } else if (localEntry !== undefined && sharedEntry !== undefined
169
+ && isBlank(sharedDoc) && !isBlank(localDoc)) {
170
+ // The local shard says the session has a conversation while the share still
171
+ // says it is empty: overwrite the share, or every other machine that pulls
172
+ // it keeps hiding the conversation.
173
+ if (apply) {
174
+ try {
175
+ await fsp.copyFile(localEntry.file, sharedEntry.file);
176
+ await fsp.utimes(sharedEntry.file, new Date(localEntry.mtime), new Date(localEntry.mtime)).catch(() => {});
177
+ mirrored += 1;
178
+ } catch {
179
+ // Retried next round.
180
+ }
181
+ } else {
182
+ mirrored += 1;
183
+ }
184
+ }
185
+ }
186
+
187
+ if (apply && !force) {
188
+ const nextLocal = {};
189
+ for (const [id, entry] of await indexShards(localDir)) nextLocal[id] = entry.mtime;
190
+ const nextShared = {};
191
+ for (const [id, entry] of await indexShards(sharedDir)) nextShared[id] = entry.mtime;
192
+ await writeJson(stateFile, {
193
+ version: 1,
194
+ machine: machineId,
195
+ updatedAt: new Date().toISOString(),
196
+ local: nextLocal,
197
+ shared: nextShared,
198
+ }).catch(() => {});
199
+ }
200
+
201
+ return { parsed, updated, mirrored, untouched };
202
+ }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Old-generation cleanup for the pure-JS engine.
3
+ *
4
+ * The desktop app only reads the highest `session.v<N>` of a session, so older
5
+ * artifacts are dead weight. Removing them is destructive, so every rule below
6
+ * must hold before a file is touched:
7
+ *
8
+ * 1. the highest generation decodes cleanly (a corrupt newest copy means keep everything);
9
+ * 2. that generation is not newer than the app understands;
10
+ * 3. no older file is *newer* than the highest (an older app may have written it);
11
+ * 4. every candidate is older than the grace window.
12
+ *
13
+ * Local files go to `<dshHome>/.sync-quarantine/<stamp>/…` (or straight away with
14
+ * `hard`); shared copies are backed up the same way and then deleted. Runs are
15
+ * throttled to once per 24 hours.
16
+ */
17
+ import { promises as fsp } from 'node:fs';
18
+ import { randomUUID } from 'node:crypto';
19
+ import path from 'node:path';
20
+ import { scanSessionGroups } from './scan.js';
21
+ import { decodeBuffer, scanFrames } from './zstd.js';
22
+
23
+ async function readJson(file, fallback) {
24
+ try {
25
+ return JSON.parse(await fsp.readFile(file, 'utf8'));
26
+ } catch {
27
+ return fallback;
28
+ }
29
+ }
30
+
31
+ async function writeJson(file, value) {
32
+ await fsp.mkdir(path.dirname(file), { recursive: true });
33
+ const temporary = `${file}.${randomUUID()}.tmp`;
34
+ await fsp.writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
35
+ await fsp.rename(temporary, file);
36
+ }
37
+
38
+ /** Structural check: frames parse and every frame decompresses. */
39
+ export async function isHealthy(file) {
40
+ try {
41
+ const buffer = await fsp.readFile(file);
42
+ const frames = scanFrames(buffer);
43
+ if (frames.length === 0) return false;
44
+ decodeBuffer(buffer);
45
+ return true;
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+
51
+ function stamp(date) {
52
+ const pad = (value) => String(value).padStart(2, '0');
53
+ return `${String(date.getFullYear())}${pad(date.getMonth() + 1)}${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
54
+ }
55
+
56
+ /** Decide what to do with one session group; never mutates anything. */
57
+ export async function planGroup(group, options) {
58
+ const { appGen, graceDays = 0, now = Date.now(), healthy } = options;
59
+ const sorted = [...group.files].sort((a, b) => b.generation - a.generation || b.mtime - a.mtime);
60
+ const high = sorted[0];
61
+ const lows = sorted.filter((file) => file.generation < high.generation);
62
+ if (lows.length === 0) return { action: 'skip', reason: 'single-generation' };
63
+
64
+ const ok = healthy === undefined ? await isHealthy(high.path) : await healthy(high.path);
65
+ if (!ok) return { action: 'keep', reason: 'highest generation failed verification', high, lows };
66
+ if (appGen !== undefined && high.generation > appGen) {
67
+ return { action: 'keep', reason: `app only supports v${String(appGen)}`, high, lows };
68
+ }
69
+ if (lows.some((file) => file.mtime > high.mtime)) {
70
+ return { action: 'keep', reason: 'an older artifact is newer than the highest', high, lows };
71
+ }
72
+ if (graceDays > 0 && lows.some((file) => now - file.mtime < graceDays * 86_400_000)) {
73
+ return { action: 'keep', reason: 'within the grace window', high, lows };
74
+ }
75
+ return { action: 'prune', high, lows };
76
+ }
77
+
78
+ /** Move one file into the quarantine tree, keeping side/project/session layout. */
79
+ async function quarantine(file, quarantineRoot, group, stampText, side) {
80
+ const target = path.join(quarantineRoot, stampText, side, group.projectKey, group.id, path.basename(file.path));
81
+ await fsp.mkdir(path.dirname(target), { recursive: true });
82
+ await fsp.copyFile(file.path, target).catch(async () => {
83
+ await fsp.copyFile(file.path, `${target}.retry`);
84
+ await fsp.rename(`${target}.retry`, target);
85
+ });
86
+ await fsp.rm(file.path, { force: true });
87
+ return target;
88
+ }
89
+
90
+ /** Remove quarantine snapshots older than the retention window. */
91
+ export async function purgeQuarantine(quarantineRoot, days, apply = true) {
92
+ if (!(days > 0)) return 0;
93
+ let entries;
94
+ try {
95
+ entries = await fsp.readdir(quarantineRoot, { withFileTypes: true });
96
+ } catch {
97
+ return 0;
98
+ }
99
+ const cutoff = Date.now() - days * 86_400_000;
100
+ let removed = 0;
101
+ for (const entry of entries) {
102
+ if (!entry.isDirectory()) continue;
103
+ const dir = path.join(quarantineRoot, entry.name);
104
+ const stat = await fsp.stat(dir).catch(() => undefined);
105
+ if (stat === undefined || stat.mtimeMs >= cutoff) continue;
106
+ removed += 1;
107
+ if (apply) await fsp.rm(dir, { recursive: true, force: true }).catch(() => {});
108
+ }
109
+ return removed;
110
+ }
111
+
112
+ /**
113
+ * Run the pruning pass.
114
+ * @returns counters matching the PowerShell summary (`quarantined`, `hardDeleted`,
115
+ * `sharedDeleted`, `kept`, `throttled`, `quarantinePurged`) plus per-file reasons.
116
+ */
117
+ export async function pruneOldGenerations(deps) {
118
+ const {
119
+ localRoot,
120
+ sharedRoot,
121
+ dshHome,
122
+ stateDir,
123
+ machineId,
124
+ appGen,
125
+ throttleHours = 24,
126
+ graceDays = 7,
127
+ quarantineDays = 15,
128
+ hard = false,
129
+ pruneNow = false,
130
+ apply = true,
131
+ now = Date.now(),
132
+ } = deps;
133
+
134
+ const stats = { quarantined: 0, hardDeleted: 0, sharedDeleted: 0, kept: 0, throttled: 0, quarantinePurged: 0, details: [] };
135
+ const stateFile = path.join(stateDir, `prune-${machineId}.json`);
136
+
137
+ if (!pruneNow && throttleHours > 0) {
138
+ const last = await readJson(stateFile, undefined);
139
+ const lastAt = typeof last?.at === 'string' ? Date.parse(last.at) : Number.NaN;
140
+ if (Number.isFinite(lastAt) && (now - lastAt) < throttleHours * 3_600_000) {
141
+ stats.throttled = 1;
142
+ return stats;
143
+ }
144
+ }
145
+
146
+ const local = await scanSessionGroups(localRoot);
147
+ const shared = await scanSessionGroups(sharedRoot);
148
+ const quarantineRoot = path.join(dshHome, '.sync-quarantine');
149
+ const stampText = stamp(new Date(now));
150
+
151
+ for (const [side, groups] of [['local', local], ['shared', shared]]) {
152
+ for (const group of groups.values()) {
153
+ const plan = await planGroup(group, { appGen, graceDays, now });
154
+ if (plan.action === 'skip') continue;
155
+ if (plan.action === 'keep') {
156
+ stats.kept += 1;
157
+ stats.details.push({ side, id: group.id, action: 'keep', reason: plan.reason });
158
+ continue;
159
+ }
160
+ for (const file of plan.lows) {
161
+ if (!apply) {
162
+ stats.details.push({ side, id: group.id, action: 'dry-run', file: file.name });
163
+ if (side === 'local') stats.quarantined += 1;
164
+ else stats.sharedDeleted += 1;
165
+ continue;
166
+ }
167
+ if (hard) {
168
+ await fsp.rm(file.path, { force: true }).catch(() => {});
169
+ if (side === 'local') stats.hardDeleted += 1;
170
+ else stats.sharedDeleted += 1;
171
+ stats.details.push({ side, id: group.id, action: 'hard-deleted', file: file.name });
172
+ continue;
173
+ }
174
+ await quarantine(file, quarantineRoot, group, stampText, side).catch(() => {});
175
+ if (side === 'local') stats.quarantined += 1;
176
+ else stats.sharedDeleted += 1;
177
+ stats.details.push({ side, id: group.id, action: 'quarantined', file: file.name });
178
+ }
179
+ }
180
+ }
181
+
182
+ if (apply) {
183
+ stats.quarantinePurged = await purgeQuarantine(quarantineRoot, quarantineDays, apply);
184
+ await writeJson(stateFile, { version: 1, machine: machineId, at: new Date(now).toISOString() }).catch(() => {});
185
+ }
186
+ return stats;
187
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Read-only scan primitives for the pure-JS sync engine.
3
+ *
4
+ * This is the first parity step: it must reproduce what `dsh-session-sync.ps1`
5
+ * counts in `-Status`, without writing anything.
6
+ */
7
+ import { promises as fsp } from 'node:fs';
8
+ import path from 'node:path';
9
+
10
+ /** Encode a cwd the same way the persistence layer names project folders. */
11
+ export function projectKey(cwd) {
12
+ if (typeof cwd !== 'string' || cwd === '') return '_no-cwd';
13
+ let readable = '';
14
+ let separatorRun = false;
15
+ for (const ch of cwd) {
16
+ if (ch === '/' || ch === '\\' || ch === ':') {
17
+ if (!separatorRun) readable += '-';
18
+ separatorRun = true;
19
+ } else if (ch !== '~' && /^[A-Za-z0-9._-]$/u.test(ch)) {
20
+ readable += ch;
21
+ separatorRun = false;
22
+ } else {
23
+ readable += `~${ch.codePointAt(0).toString(16).toUpperCase().padStart(4, '0')}`;
24
+ separatorRun = false;
25
+ }
26
+ }
27
+ readable = readable.replace(/^-+/u, '');
28
+ if (readable === '') readable = 'root';
29
+ if (readable.length > 251) readable = readable.slice(0, 251);
30
+ return `--${readable}--`;
31
+ }
32
+
33
+ /** Generation number of one artifact name; -1 when it is not a session log. */
34
+ export function artifactGeneration(name) {
35
+ const versioned = /^session\.v(\d+)\.jsonl\.zstd$/u.exec(name);
36
+ if (versioned !== null) return Number(versioned[1]);
37
+ if (name === 'session.jsonl.zstd') return 0;
38
+ return -1;
39
+ }
40
+
41
+ async function readDirSafe(dir) {
42
+ try {
43
+ return await fsp.readdir(dir, { withFileTypes: true });
44
+ } catch {
45
+ return [];
46
+ }
47
+ }
48
+
49
+ /** Scan one sessions root; keeps the newest generation per session id. */
50
+ export async function scanSessions(root) {
51
+ const sessions = new Map();
52
+ for (const project of await readDirSafe(root)) {
53
+ if (!project.isDirectory()) continue;
54
+ const projectDir = path.join(root, project.name);
55
+ for (const entry of await readDirSafe(projectDir)) {
56
+ if (!entry.isDirectory()) continue;
57
+ const id = entry.name;
58
+ const dir = path.join(projectDir, id);
59
+ let best = null;
60
+ for (const file of await readDirSafe(dir)) {
61
+ if (!file.isFile()) continue;
62
+ const generation = artifactGeneration(file.name);
63
+ if (generation < 0) continue;
64
+ const full = path.join(dir, file.name);
65
+ let stat;
66
+ try { stat = await fsp.stat(full); } catch { continue; }
67
+ if (best === null || generation > best.generation
68
+ || (generation === best.generation && stat.mtimeMs > best.mtime)) {
69
+ best = { id, dir, file: full, name: file.name, generation, mtime: stat.mtimeMs, size: stat.size, projectKey: project.name };
70
+ }
71
+ }
72
+ if (best !== null) sessions.set(id, best);
73
+ }
74
+ }
75
+ return sessions;
76
+ }
77
+
78
+ /** Every session directory with all of its generations, for pruning. */
79
+ export async function scanSessionGroups(root) {
80
+ const groups = new Map();
81
+ for (const project of await readDirSafe(root)) {
82
+ if (!project.isDirectory()) continue;
83
+ const projectDir = path.join(root, project.name);
84
+ for (const entry of await readDirSafe(projectDir)) {
85
+ if (!entry.isDirectory()) continue;
86
+ const dir = path.join(projectDir, entry.name);
87
+ const files = [];
88
+ for (const file of await readDirSafe(dir)) {
89
+ if (!file.isFile()) continue;
90
+ const generation = artifactGeneration(file.name);
91
+ if (generation < 0) continue;
92
+ const full = path.join(dir, file.name);
93
+ const stat = await fsp.stat(full).catch(() => undefined);
94
+ if (stat === undefined) continue;
95
+ files.push({ name: file.name, path: full, generation, mtime: stat.mtimeMs, size: stat.size });
96
+ }
97
+ if (files.length > 0) groups.set(entry.name, { id: entry.name, dir, projectKey: project.name, files });
98
+ }
99
+ }
100
+ return groups;
101
+ }
102
+
103
+ const CONFIG_ITEMS = (profile) => [ `profiles/${profile}/cordis.patch.yml`,
104
+ 'skills',
105
+ 'AGENTS.md',
106
+ '.credentials.yaml',
107
+ ];
108
+
109
+ /** List one config item as relative file paths. */
110
+ export async function scanConfigItem(baseDir, relPath) {
111
+ const root = path.join(baseDir, ...relPath.split('/'));
112
+ const files = [];
113
+ async function walk(dir, prefix) {
114
+ for (const entry of await readDirSafe(dir)) {
115
+ const rel = prefix === '' ? entry.name : `${prefix}/${entry.name}`;
116
+ const full = path.join(dir, entry.name);
117
+ if (entry.isDirectory()) await walk(full, rel);
118
+ else files.push(`${relPath}/${rel}`);
119
+ }
120
+ }
121
+ try {
122
+ const stat = await fsp.stat(root);
123
+ if (stat.isFile()) return [relPath];
124
+ } catch {
125
+ return [];
126
+ }
127
+ await walk(root, '');
128
+ return files;
129
+ }
130
+
131
+ /** All configuration files the engine is allowed to sync. */
132
+ export async function scanConfig(baseDir, profile = 'desktop') {
133
+ const files = [];
134
+ for (const item of CONFIG_ITEMS(profile)) {
135
+ files.push(...await scanConfigItem(baseDir, item));
136
+ }
137
+ return files;
138
+ }
139
+
140
+ /** Count attachment objects by the three synced trees. */
141
+ export async function scanAttachments(root) {
142
+ const result = { objects: 0, fileObjects: 0, files: 0 };
143
+ for (const [key, name] of [['objects', 'objects'], ['fileObjects', 'file-objects'], ['files', 'files']]) {
144
+ const dir = path.join(root, name);
145
+ for (const bucket of await readDirSafe(dir)) {
146
+ if (!bucket.isDirectory()) continue;
147
+ const bucketDir = path.join(dir, bucket.name);
148
+ for (const entry of await readDirSafe(bucketDir)) {
149
+ if (entry.isDirectory()) {
150
+ if (key === 'files') {
151
+ for (const inner of await readDirSafe(path.join(bucketDir, entry.name))) {
152
+ if (inner.isFile()) result[key] += 1;
153
+ }
154
+ }
155
+ continue;
156
+ }
157
+ result[key] += 1;
158
+ }
159
+ }
160
+ }
161
+ return result;
162
+ }
163
+
164
+ /** The same numbers `-Status` prints, for parity comparison. */
165
+ export async function statusReport({ dshHome, syncDir, profile = 'desktop' }) {
166
+ const local = await scanSessions(path.join(dshHome, 'sessions'));
167
+ const shared = await scanSessions(path.join(syncDir, 'sessions'));
168
+ const localConfig = await scanConfig(path.join(dshHome), profile);
169
+ const sharedConfig = await scanConfig(path.join(syncDir, 'config'), profile);
170
+ const localAtt = await scanAttachments(path.join(dshHome, 'attachments', 'v1'));
171
+ const sharedAtt = await scanAttachments(path.join(syncDir, 'attachments', 'v1'));
172
+ return {
173
+ sessions: { local: local.size, shared: shared.size },
174
+ config: { local: localConfig.length, shared: sharedConfig.length },
175
+ attachments: { local: localAtt, shared: sharedAtt },
176
+ };
177
+ }