@artenx/dshb 0.1.54 → 0.1.56

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 (62) hide show
  1. package/README.md +22 -7
  2. package/lib/auth/index.js +1 -1
  3. package/lib/auth/index.js.map +1 -1
  4. package/lib/{catalog-BPkswHoz.js → catalog-B6Qvy7bH.js} +8 -4
  5. package/lib/catalog-B6Qvy7bH.js.map +1 -0
  6. package/lib/client.js +421 -29
  7. package/lib/client.js.map +1 -1
  8. package/lib/core/index.js +138 -5
  9. package/lib/core/index.js.map +1 -1
  10. package/lib/core/routes.d.ts +1 -1
  11. package/lib/core/sync/coordinator.d.ts +5 -5
  12. package/lib/core/sync/coordinator.js +54 -26
  13. package/lib/core/sync/coordinator.js.map +1 -1
  14. package/lib/core/sync/host-key.d.ts +1 -1
  15. package/lib/core/sync/internal-routes.d.ts +3 -3
  16. package/lib/core/sync/internal-routes.js +83 -2
  17. package/lib/core/sync/internal-routes.js.map +1 -1
  18. package/lib/core/sync/model.d.ts +1 -1
  19. package/lib/core/sync/model.js.map +1 -1
  20. package/lib/core/sync/node-sync.d.ts +1 -1
  21. package/lib/core/sync/node-sync.js +2 -4
  22. package/lib/core/sync/node-sync.js.map +1 -1
  23. package/lib/core/sync/offline-archive.d.ts +4 -4
  24. package/lib/core/sync/offline-archive.js +2 -2
  25. package/lib/core/sync/offline-routes.js +1 -1
  26. package/lib/core/sync/peer-manager.d.ts +2 -2
  27. package/lib/core/sync/remote-helper.js +6 -4
  28. package/lib/core/sync/remote-helper.js.map +1 -1
  29. package/lib/core/sync/routes.d.ts +9 -4
  30. package/lib/core/sync/routes.js +31 -4
  31. package/lib/core/sync/routes.js.map +1 -1
  32. package/lib/core/sync/session-journal.d.ts +1 -1
  33. package/lib/core/sync/session-open-routes.d.ts +32 -0
  34. package/lib/core/sync/session-open-routes.js +239 -0
  35. package/lib/core/sync/session-open-routes.js.map +1 -0
  36. package/lib/core/sync/session-routes.d.ts +1 -1
  37. package/lib/core/sync/session-routes.js +1 -1
  38. package/lib/core/sync/session-sync.d.ts +1 -1
  39. package/lib/core/sync/session-sync.js +1 -1
  40. package/lib/core/sync/ssh-transport.d.ts +1 -1
  41. package/lib/core/sync/ssh-transport.js +44 -1
  42. package/lib/core/sync/ssh-transport.js.map +1 -1
  43. package/lib/core/sync/stores.d.ts +1 -1
  44. package/lib/core/workspace-bindings.js +62 -24
  45. package/lib/core/workspace-bindings.js.map +1 -1
  46. package/lib/core/workspace-instruction-context.d.ts +1 -1
  47. package/lib/core/workspace-instructions.js +9 -1
  48. package/lib/core/workspace-instructions.js.map +1 -1
  49. package/lib/core/workspaces.d.ts +1 -1
  50. package/lib/{host-key-hIj6EY1x.d.ts → host-key-kbG50cnS.d.ts} +2 -2
  51. package/lib/{index-VF8bcBeX.d.ts → index-D6KDknUV.d.ts} +3 -309
  52. package/lib/{model-ByASrkzO.d.ts → model-zRfOihS3.d.ts} +4 -1
  53. package/lib/{node-sync-Cv1Amudy.d.ts → node-sync-Ba4yARei.d.ts} +3 -3
  54. package/lib/{session-journal-BnpGWLo2.d.ts → session-journal-BKjaO_1l.d.ts} +2 -2
  55. package/lib/{session-sync-Bn5ZXU8H.d.ts → session-sync-B5MCI0TW.d.ts} +31 -8
  56. package/lib/{session-sync-Dwz4dp4U.js → session-sync-DrilvkP1.js} +171 -98
  57. package/lib/session-sync-DrilvkP1.js.map +1 -0
  58. package/lib/{ssh-transport-CcGpOVy5.d.ts → ssh-transport-Uii7j8la.d.ts} +14 -5
  59. package/lib/{stores-BfruQqD-.d.ts → stores-DnyrIi4h.d.ts} +2 -2
  60. package/package.json +6 -2
  61. package/lib/catalog-BPkswHoz.js.map +0 -1
  62. package/lib/session-sync-Dwz4dp4U.js.map +0 -1
@@ -10,6 +10,7 @@ import { basename, dirname, join, normalize, posix, resolve } from "node:path";
10
10
  import { createHash, randomBytes } from "node:crypto";
11
11
  import "@deepseek-ai/cordis";
12
12
  import { access, lstat, mkdir, open, readdir, realpath, rename, stat, unlink } from "node:fs/promises";
13
+ import { assertContiguous, validateStoredEvents } from "@deepseek-ai/dsh-session-persistence";
13
14
  //#region ../../node_modules/@deepseek-ai/dsh-session/lib/index.js
14
15
  /**
15
16
  * Brand a string as a {@link SessionId}.
@@ -310,88 +311,6 @@ function hasProviderModel(value) {
310
311
  return typeof pair["provider"] === "string" && pair["provider"].length > 0 && typeof pair["model"] === "string" && pair["model"].length > 0;
311
312
  }
312
313
  //#endregion
313
- //#region ../../node_modules/@deepseek-ai/dsh-session-persistence/lib/index.js
314
- /** Durable session contents failed validation after a successful backend read. */
315
- var SessionPersistenceCorruptionError = class extends Error {
316
- /**
317
- * @param message - stable corruption context.
318
- * @param options - original validation failure.
319
- */
320
- constructor(message, options) {
321
- super(message, options);
322
- this.name = "SessionPersistenceCorruptionError";
323
- }
324
- };
325
- /**
326
- * The stored log is intact but this runtime cannot faithfully interpret it:
327
- * the header carries an unsupported format version, or an event's type is
328
- * unknown to this build. Distinct from {@link SessionPersistenceCorruptionError}
329
- * — nothing is damaged; the raw log remains readable at {@link location} when
330
- * the backend keeps one artifact per session.
331
- */
332
- var SessionFormatUnsupportedError = class extends Error {
333
- location;
334
- /**
335
- * @param message - stable reason the log cannot be interpreted, already
336
- * including the raw-log path when one exists.
337
- * @param location - the backend's artifact location, when one exists.
338
- */
339
- constructor(message, location) {
340
- super(message);
341
- this.location = location;
342
- this.name = "SessionFormatUnsupportedError";
343
- }
344
- };
345
- /**
346
- * Backend-shared storage validation: the version gate, the fail-closed event
347
- * vocabulary, append-batch materialization, and contiguity — one place so
348
- * every backend refuses the same inputs identically.
349
- * @module @deepseek-ai/dsh-session-persistence/storage-contract
350
- */
351
- /** Build a format refusal that points at the raw artifact when the backend has one. */
352
- function unsupported(reason, location) {
353
- return new SessionFormatUnsupportedError(location === void 0 ? reason : `${reason} (raw log: ${location.path})`, location);
354
- }
355
- /**
356
- * Validate one exclusively owned stored event array in place: adopt each
357
- * record (validating and freezing it) and refuse any event type this build
358
- * does not know, unless its writer marked it `ignorable: true` — silently
359
- * skipping an unknown required event could reconstruct a wrong session (the
360
- * envelope contract on `SessionEvent.ignorable`). Unknown required types and
361
- * retired pre-release shapes refuse here; this validator performs no migration.
362
- * @param meta - the stored header the events belong to.
363
- * @param events - exclusively owned decoded events; validated in place.
364
- * @param location - the backend's artifact location for refusals, when one exists.
365
- * @returns the same array, validated and frozen.
366
- * @throws {SessionFormatUnsupportedError} for unknown event types.
367
- * @throws {SessionPersistenceCorruptionError} for records that fail validation.
368
- */
369
- function validateStoredEvents(meta, events, location) {
370
- for (const event of events) {
371
- if (!KNOWN_SESSION_EVENT_TYPES.has(event.type) && event.ignorable !== true) throw unsupported(`session "${meta.id}" contains event type "${event.type}" (seq ${event.seq}) unknown to this harness and not marked ignorable; refusing to interpret the log — it was likely written by a newer harness`, location);
372
- if (event.type === "request/header") {
373
- const data = event.data;
374
- if (typeof data === "object" && data !== null && data["reason"] === "fallback") throw unsupported(`session "${meta.id}" contains a request/header event (seq ${event.seq}) with the unsupported legacy reason "fallback"; refusing to interpret the log — it was written by a retired pre-release harness`, location);
375
- }
376
- }
377
- try {
378
- for (const [index, event] of events.entries()) events[index] = adoptSessionEvent(event);
379
- } catch (error) {
380
- if (error instanceof SessionFormatUnsupportedError) throw error;
381
- throw new SessionPersistenceCorruptionError(`stored session "${meta.id}" failed validation: ${String(error)}`, { cause: error });
382
- }
383
- return events;
384
- }
385
- /**
386
- * Refuse a batch that does not contiguously continue the stored log.
387
- * @param id - the session the batch belongs to.
388
- * @param events - the batch, in seq order.
389
- * @param cursor - the stored next-seq.
390
- */
391
- function assertContiguous(id, events, cursor) {
392
- for (const [index, event] of events.entries()) if (event.seq !== cursor + index) throw new Error(`append seq mismatch for "${id}": expected ${cursor + index} at index ${index}, got ${event.seq}`);
393
- }
394
- //#endregion
395
314
  //#region src/core/sync/export-cache.ts
396
315
  const MAX_EXPORT_CACHE_FILE_BYTES = 8388608;
397
316
  function cacheHome(home) {
@@ -1738,7 +1657,7 @@ var SyncSessionService = class SyncSessionService {
1738
1657
  instructions;
1739
1658
  journal;
1740
1659
  now;
1741
- getSessionTitle;
1660
+ getSessionProjection;
1742
1661
  operationTail = Promise.resolve();
1743
1662
  exportCache = /* @__PURE__ */ new Map();
1744
1663
  exportCacheStore;
@@ -1748,7 +1667,7 @@ var SyncSessionService = class SyncSessionService {
1748
1667
  objectInbox;
1749
1668
  /** 工作区级指令存储:导入采纳写入,驱动该工作区新会话的指令注入。 */
1750
1669
  workspaceInstructions;
1751
- constructor(state, nodes, registry, bindings, getWorkspaces, getPersistence, getAttachments, getSpills, instructions, journal = new SyncSessionJournalStore(), now = Date.now, home, workspaceInstructions, getSessionTitle) {
1670
+ constructor(state, nodes, registry, bindings, getWorkspaces, getPersistence, getAttachments, getSpills, instructions, journal = new SyncSessionJournalStore(), now = Date.now, home, workspaceInstructions, getSessionProjection) {
1752
1671
  this.state = state;
1753
1672
  this.nodes = nodes;
1754
1673
  this.registry = registry;
@@ -1760,7 +1679,7 @@ var SyncSessionService = class SyncSessionService {
1760
1679
  this.instructions = instructions;
1761
1680
  this.journal = journal;
1762
1681
  this.now = now;
1763
- this.getSessionTitle = getSessionTitle;
1682
+ this.getSessionProjection = getSessionProjection;
1764
1683
  this.exportCacheStore = new SyncSessionExportCacheStore(home);
1765
1684
  this.objectInbox = new SyncSessionObjectInbox(home);
1766
1685
  this.workspaceInstructions = workspaceInstructions ?? sharedWorkspaceInstructionStore();
@@ -1882,6 +1801,58 @@ var SyncSessionService = class SyncSessionService {
1882
1801
  }
1883
1802
  return discarded;
1884
1803
  }
1804
+ /**
1805
+ * 超限会话整文件迁移后的收尾:把已落盘的本地会话挂到工作区并写 membership。
1806
+ * 只做 membership(不重放事件);供 open-session 的 file 迁移路径调用。
1807
+ */
1808
+ async adoptMigratedSession(metadata, localSessionId, workspaceId, sourceName) {
1809
+ const registry = this.getWorkspaces();
1810
+ if (!registry) {
1811
+ this.pendingMigratedAdoptions.push({
1812
+ metadata,
1813
+ localSessionId,
1814
+ workspaceId,
1815
+ sourceName
1816
+ });
1817
+ return false;
1818
+ }
1819
+ const mapping = Object.values(this.state.read().workspaces).find((item) => item.localWorkspaceId === workspaceId);
1820
+ let workspace = registry.get(workspaceId);
1821
+ if (!workspace && mapping) workspace = registry.list().find((item) => normalize(item.path) === normalize(mapping.localPath));
1822
+ if (!workspace) return false;
1823
+ const sessionId = SessionId(localSessionId);
1824
+ if (!await this.requirePersistence().stat(sessionId)) throw new SyncSessionError("session-format", "迁移后的会话文件不可读");
1825
+ const entry = {
1826
+ metadata,
1827
+ workspace: {
1828
+ originInstanceId: metadata.workspaceOrigin?.originInstanceId ?? "",
1829
+ originWorkspaceId: metadata.workspaceOrigin?.originEntityId ?? "",
1830
+ remotePath: workspace.path,
1831
+ title: workspace.title,
1832
+ nodeOrigin: {
1833
+ originInstanceId: metadata.originInstanceId,
1834
+ originEntityId: ""
1835
+ },
1836
+ contentDigest: "sha256:" + "0".repeat(64)
1837
+ },
1838
+ workspacePosition: 0,
1839
+ archived: registry.archivedSessionIds.includes(sessionId),
1840
+ pinned: false,
1841
+ events: [],
1842
+ objects: []
1843
+ };
1844
+ await this.applyMembershipOnly(entry, metadata, sourceName, workspace, "peer");
1845
+ return true;
1846
+ }
1847
+ /** registry 注入后补挂迁移会话(由 index.ts 的 inject 回调调用)。 */
1848
+ pendingMigratedAdoptions = [];
1849
+ async flushPendingMigratedAdoptions() {
1850
+ const pending = this.pendingMigratedAdoptions;
1851
+ this.pendingMigratedAdoptions = [];
1852
+ for (const item of pending) try {
1853
+ await this.adoptMigratedSession(item.metadata, item.localSessionId, item.workspaceId, item.sourceName);
1854
+ } catch {}
1855
+ }
1885
1856
  async recoverPending() {
1886
1857
  const failures = [];
1887
1858
  for (const batch of this.journal.pendingBatches()) try {
@@ -1933,6 +1904,62 @@ var SyncSessionService = class SyncSessionService {
1933
1904
  };
1934
1905
  });
1935
1906
  }
1907
+ /**
1908
+ * Detach metadata-mode imports when their peer is removed. DSH persistence is append-only,
1909
+ * so imported sessions are archived (hidden from active workspaces and still recoverable)
1910
+ * rather than physically erased. Full-sync peers deliberately do not call this method.
1911
+ */
1912
+ removeMetadataPeerImports(peerInstanceId, trackedLocalSessionIds = [], fallbackSourceName) {
1913
+ return this.serializeMutation(async () => {
1914
+ const registry = this.getWorkspaces();
1915
+ if (!registry) throw new SyncSessionError("workspace-unavailable", "工作区注册表不可用");
1916
+ const snapshot = this.state.read();
1917
+ const trackedIds = new Set(trackedLocalSessionIds);
1918
+ const directlyOwnedRecords = Object.entries(snapshot.records).filter(([, metadata]) => metadata.kind === "session" && metadata.importedVia === "peer" && !metadata.deleted && (trackedIds.has(metadata.localEntityId) || peerInstanceId !== void 0 && metadata.originInstanceId === peerInstanceId || fallbackSourceName !== void 0 && metadata.sourceName === fallbackSourceName));
1919
+ const workspaceOriginKeys = /* @__PURE__ */ new Set();
1920
+ for (const [, metadata] of directlyOwnedRecords) if (metadata.workspaceOrigin) workspaceOriginKeys.add(JSON.stringify([metadata.workspaceOrigin.originInstanceId, metadata.workspaceOrigin.originEntityId]));
1921
+ const peerWorkspaceEntries = Object.entries(snapshot.workspaces).filter(([, mapping]) => peerInstanceId !== void 0 && mapping.originInstanceId === peerInstanceId || workspaceOriginKeys.has(JSON.stringify([mapping.originInstanceId, mapping.originWorkspaceId])));
1922
+ for (const [, mapping] of peerWorkspaceEntries) workspaceOriginKeys.add(JSON.stringify([mapping.originInstanceId, mapping.originWorkspaceId]));
1923
+ const peerWorkspaceKeys = new Set(peerWorkspaceEntries.map(([key]) => key));
1924
+ const peerRecords = directlyOwnedRecords;
1925
+ const localSessionIds = new Set(peerRecords.map(([, metadata]) => metadata.localEntityId));
1926
+ const alreadyArchived = new Set(registry.archivedSessionIds.map(String));
1927
+ let sessionsArchived = 0;
1928
+ for (const localId of localSessionIds) {
1929
+ if (alreadyArchived.has(localId)) continue;
1930
+ await registry.archiveSession(SessionId(localId), { stopActivity: true });
1931
+ await registry.unpinSession?.(SessionId(localId));
1932
+ sessionsArchived += 1;
1933
+ }
1934
+ let workspacesRemoved = 0;
1935
+ let workspacesDetached = 0;
1936
+ const checkedWorkspaceIds = /* @__PURE__ */ new Set();
1937
+ for (const [, mapping] of peerWorkspaceEntries) {
1938
+ if (checkedWorkspaceIds.has(mapping.localWorkspaceId)) continue;
1939
+ checkedWorkspaceIds.add(mapping.localWorkspaceId);
1940
+ const workspace = registry.get(mapping.localWorkspaceId);
1941
+ if (!workspace) continue;
1942
+ if (workspace.sessionIds.every((id) => localSessionIds.has(String(id))) && typeof registry.delete === "function" && await registry.delete(workspace.id)) {
1943
+ this.bindings.remove(workspace.path);
1944
+ workspacesRemoved += 1;
1945
+ } else workspacesDetached += 1;
1946
+ }
1947
+ const removedRecordKeys = new Set(peerRecords.map(([key]) => key));
1948
+ this.state.update((draft) => {
1949
+ for (const key of removedRecordKeys) delete draft.records[key];
1950
+ for (const key of peerWorkspaceKeys) delete draft.workspaces[key];
1951
+ for (const [branchId, archive] of Object.entries(draft.archives)) {
1952
+ const workspaceMatches = archive.workspaceOrigin && workspaceOriginKeys.has(JSON.stringify([archive.workspaceOrigin.originInstanceId, archive.workspaceOrigin.originEntityId]));
1953
+ if (archive.originInstanceId === peerInstanceId || workspaceMatches) delete draft.archives[branchId];
1954
+ }
1955
+ });
1956
+ return {
1957
+ sessionsArchived,
1958
+ workspacesRemoved,
1959
+ workspacesDetached
1960
+ };
1961
+ });
1962
+ }
1936
1963
  restoreArchive(branchId) {
1937
1964
  return this.serializeMutation(() => this.restoreArchiveNow(branchId));
1938
1965
  }
@@ -1990,6 +2017,11 @@ var SyncSessionService = class SyncSessionService {
1990
2017
  const preservedLocalIds = /* @__PURE__ */ new Set();
1991
2018
  const workspaceById = /* @__PURE__ */ new Map();
1992
2019
  const archivedBranchSessionIds = new Set(Object.values(stateIndex.state.archives).map((archive) => archive.localSessionId));
2020
+ const archivedOriginKeys = new Set(Object.values(stateIndex.state.archives).filter((archive) => String(archive.localSessionId) !== archive.originSessionId).map((archive) => syncRecordKey("session", {
2021
+ originInstanceId: archive.originInstanceId,
2022
+ originEntityId: archive.originSessionId
2023
+ })));
2024
+ const isArchivedForCatalog = (localId, metadata) => archivedIds.has(localId) || archivedOriginKeys.has(sessionOriginKey(metadata));
1993
2025
  const objectCache = new ExportObjectCache();
1994
2026
  const descriptorCache = /* @__PURE__ */ new Map();
1995
2027
  const getWorkspaceDescriptor = (workspace, binding, nodeOrigin, preferredOrigin) => {
@@ -2045,9 +2077,11 @@ var SyncSessionService = class SyncSessionService {
2045
2077
  } : metadata.workspaceOrigin ? { workspaceOrigin: metadata.workspaceOrigin } : {},
2046
2078
  sessionId,
2047
2079
  ...extra.title ? { title: extra.title } : {},
2080
+ ...extra.blank ? { blank: true } : {},
2048
2081
  ...isNonNegativeSafeInteger(sizeBytes) ? { sizeBytes } : {},
2049
2082
  ...extra.branchId ? { branchId: extra.branchId } : {},
2050
- ...extra.deleted ? { deleted: true } : {}
2083
+ ...extra.deleted ? { deleted: true } : {},
2084
+ ...extra.archived ? { archived: true } : {}
2051
2085
  });
2052
2086
  };
2053
2087
  for (const workspace of workspaces) {
@@ -2072,21 +2106,32 @@ var SyncSessionService = class SyncSessionService {
2072
2106
  const descriptor = getWorkspaceDescriptor(workspace, binding, nodeOrigin, currentSession?.workspaceOrigin);
2073
2107
  const catalogWorkspace = collectWorkspace(descriptor);
2074
2108
  const snapshot = await persistence.stat(SessionId(sessionId));
2075
- if (!snapshot) continue;
2109
+ if (!snapshot) {
2110
+ preservedLocalIds.add(sessionId);
2111
+ skipped.push({
2112
+ sessionId,
2113
+ reason: "session-file-unreadable"
2114
+ });
2115
+ continue;
2116
+ }
2076
2117
  if (snapshot.formatStatus === "migration-required") throw new SyncSessionError("session-format", "会话格式需要由当前 DSH 版本迁移");
2077
2118
  if (manifestOnly) {
2078
2119
  const cached = await this.reuseCachedManifestEntry(persistence, workspace, descriptor, position, SessionId(sessionId), snapshot, pinnedIds.has(sessionId), currentSession, stateIndex);
2079
2120
  if (cached) {
2080
2121
  entries.push(cached);
2081
- const title = this.getSessionTitle?.(snapshot.header);
2082
- collectSession(cached.metadata, catalogWorkspace, sessionId, snapshot.sizeBytes, { ...title ? { title } : {} });
2122
+ const projection = this.getSessionProjection?.(snapshot.header);
2123
+ collectSession(cached.metadata, catalogWorkspace, sessionId, snapshot.sizeBytes, {
2124
+ ...projection?.title ? { title: projection.title } : {},
2125
+ ...projection?.blank ? { blank: true } : {},
2126
+ ...isArchivedForCatalog(sessionId, cached.metadata) ? { archived: true } : {}
2127
+ });
2083
2128
  eligibleLocalIds.add(sessionId);
2084
2129
  continue;
2085
2130
  }
2086
2131
  }
2087
2132
  let exported;
2088
2133
  try {
2089
- exported = await this.exportSessionEntry(persistence, workspace, descriptor, position, SessionId(sessionId), snapshot, archivedIds.has(sessionId), pinnedIds.has(sessionId), void 0, stateIndex, objectCache, options.deferredObjects === true);
2134
+ exported = await this.exportSessionEntry(persistence, workspace, descriptor, position, SessionId(sessionId), snapshot, archivedIds.has(sessionId), pinnedIds.has(sessionId), void 0, stateIndex, objectCache, options.deferredObjects === true, manifestOnly);
2090
2135
  } catch (error) {
2091
2136
  if (!(error instanceof SyncSessionError && error.code === "session-too-large")) throw error;
2092
2137
  skipped.push({
@@ -2094,12 +2139,32 @@ var SyncSessionService = class SyncSessionService {
2094
2139
  reason: "session-payload-too-large"
2095
2140
  });
2096
2141
  preservedLocalIds.add(sessionId);
2142
+ if (options.catalog || manifestOnly) {
2143
+ const projection = this.getSessionProjection?.(snapshot.header);
2144
+ const archivedForCatalog = archivedIds.has(sessionId) || currentSession !== void 0 && archivedOriginKeys.has(sessionOriginKey(currentSession));
2145
+ if (manifestOnly) entries.push({ metadata: currentSession ?? {
2146
+ originInstanceId: instanceId,
2147
+ originEntityId: sessionId
2148
+ } });
2149
+ if (options.catalog) collectSession(currentSession ?? {
2150
+ originInstanceId: instanceId,
2151
+ originEntityId: sessionId
2152
+ }, catalogWorkspace, sessionId, snapshot.sizeBytes, {
2153
+ ...projection?.title ? { title: projection.title } : {},
2154
+ ...projection?.blank ? { blank: true } : {},
2155
+ ...archivedForCatalog ? { archived: true } : {}
2156
+ });
2157
+ }
2097
2158
  continue;
2098
2159
  }
2099
2160
  if (exported) {
2100
2161
  const { entry } = exported;
2101
- const title = this.getSessionTitle?.(snapshot.header);
2102
- collectSession(entry.metadata, catalogWorkspace, sessionId, snapshot.sizeBytes, { ...title ? { title } : {} });
2162
+ const projection = this.getSessionProjection?.(snapshot.header);
2163
+ collectSession(entry.metadata, catalogWorkspace, sessionId, snapshot.sizeBytes, {
2164
+ ...projection?.title ? { title: projection.title } : {},
2165
+ ...projection?.blank ? { blank: true } : {},
2166
+ ...isArchivedForCatalog(sessionId, entry.metadata) ? { archived: true } : {}
2167
+ });
2103
2168
  if (manifestOnly && options.payloadCache) {
2104
2169
  const key = syncSessionEntryKey(entry);
2105
2170
  const size = estimateJsonBytes(entry, MAX_MANIFEST_PAYLOAD_CACHE_BYTES - options.payloadCache.bytes);
@@ -2164,7 +2229,13 @@ var SyncSessionService = class SyncSessionService {
2164
2229
  const descriptor = getWorkspaceDescriptor(workspace, binding, nodeOrigin, stateIndex.archivesByLocalSessionId.get(archive.localSessionId)?.workspaceOrigin);
2165
2230
  const catalogWorkspace = collectWorkspace(descriptor);
2166
2231
  const snapshot = await persistence.stat(SessionId(archive.localSessionId));
2167
- if (!snapshot) continue;
2232
+ if (!snapshot) {
2233
+ skipped.push({
2234
+ sessionId: archive.localSessionId,
2235
+ reason: "session-file-unreadable"
2236
+ });
2237
+ continue;
2238
+ }
2168
2239
  let exported;
2169
2240
  try {
2170
2241
  exported = await this.exportSessionEntry(persistence, workspace, descriptor, archive.workspacePosition, SessionId(archive.localSessionId), snapshot, true, false, archive, stateIndex, objectCache, options.deferredObjects === true);
@@ -2179,10 +2250,11 @@ var SyncSessionService = class SyncSessionService {
2179
2250
  }
2180
2251
  if (exported) {
2181
2252
  const { entry } = exported;
2182
- const title = this.getSessionTitle?.(snapshot.header);
2253
+ const projection = this.getSessionProjection?.(snapshot.header);
2183
2254
  collectSession(entry.metadata, catalogWorkspace, archive.localSessionId, snapshot.sizeBytes, {
2184
2255
  branchId: archive.branchId,
2185
- ...title ? { title } : {}
2256
+ archived: true,
2257
+ ...projection?.title ? { title: projection.title } : {}
2186
2258
  });
2187
2259
  if (manifestOnly && options.payloadCache) {
2188
2260
  const key = syncSessionEntryKey(entry);
@@ -2433,7 +2505,8 @@ var SyncSessionService = class SyncSessionService {
2433
2505
  }
2434
2506
  }
2435
2507
  const objectMap = await this.importObjects(entry.objects, sessionId, attachmentImportCache, inboxConsumed);
2436
- const validatedEvents = validateStoredEvents(header, this.rewriteEvents(entry.events, entry.objects, objectMap, sessionId, String(entry.header.id)));
2508
+ const events = this.rewriteEvents(entry.events, entry.objects, objectMap, sessionId, String(entry.header.id));
2509
+ const validatedEvents = validateStoredEvents(header, events);
2437
2510
  assertContiguous(sessionId, validatedEvents, 0);
2438
2511
  const instructionWorkspaceId = entry.instructionSnapshot?.workspaceOrigin ? this.localWorkspaceIdForOrigin(entry.instructionSnapshot.workspaceOrigin, entry.instructionSnapshot.workspaceRemotePath) : void 0;
2439
2512
  const instructionSnapshot = entry.instructionSnapshot ? {
@@ -3043,7 +3116,7 @@ var SyncSessionService = class SyncSessionService {
3043
3116
  contentDigest: digest
3044
3117
  };
3045
3118
  }
3046
- async exportSessionEntry(persistence, workspace, descriptor, workspacePosition, sessionId, firstSnapshot, archived, pinned, archive, stateIndex, objectCache, deferredObjects = false) {
3119
+ async exportSessionEntry(persistence, workspace, descriptor, workspacePosition, sessionId, firstSnapshot, archived, pinned, archive, stateIndex, objectCache, deferredObjects = false, manifestOnly = false) {
3047
3120
  const { header, inheritedEventCount, events, revision: sourceRevision } = await this.readStableSession(persistence, sessionId, firstSnapshot);
3048
3121
  const localSessionId = String(sessionId);
3049
3122
  const cacheKey = sessionExportCacheKey(localSessionId);
@@ -3496,4 +3569,4 @@ var SyncSessionService = class SyncSessionService {
3496
3569
  //#endregion
3497
3570
  export { estimateJsonBytes as a, planSessionTransfers as c, sessionStateDigest as d, syncSessionEntryKey as f, workspaceDigest as g, validateSyncSessionManifest as h, SyncSessionService as i, sessionEventDigest as l, validateSyncSessionBundle as m, SyncSessionError as n, makeSyncSessionBundle as o, validateObjectPayload as p, SyncSessionObjectInbox as r, makeSyncSessionManifest as s, ExportObjectCache as t, sessionEventListDigest as u };
3498
3571
 
3499
- //# sourceMappingURL=session-sync-Dwz4dp4U.js.map
3572
+ //# sourceMappingURL=session-sync-DrilvkP1.js.map