@artenx/dshb 0.1.41 → 0.1.43

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 (35) hide show
  1. package/lib/client.js +251 -103
  2. package/lib/client.js.map +1 -1
  3. package/lib/core/index.js +343 -7
  4. package/lib/core/index.js.map +1 -1
  5. package/lib/core/routes.d.ts +1 -1
  6. package/lib/core/sync/coordinator.d.ts +5 -5
  7. package/lib/core/sync/coordinator.js +7 -2
  8. package/lib/core/sync/coordinator.js.map +1 -1
  9. package/lib/core/sync/host-key.d.ts +1 -1
  10. package/lib/core/sync/internal-routes.d.ts +3 -3
  11. package/lib/core/sync/model.d.ts +1 -1
  12. package/lib/core/sync/model.js +3 -0
  13. package/lib/core/sync/model.js.map +1 -1
  14. package/lib/core/sync/node-sync.d.ts +1 -1
  15. package/lib/core/sync/offline-archive.d.ts +4 -4
  16. package/lib/core/sync/peer-manager.d.ts +2 -2
  17. package/lib/core/sync/peer-manager.js +1 -0
  18. package/lib/core/sync/peer-manager.js.map +1 -1
  19. package/lib/core/sync/routes.d.ts +1 -1
  20. package/lib/core/sync/session-journal.d.ts +1 -1
  21. package/lib/core/sync/session-journal.js +10 -0
  22. package/lib/core/sync/session-journal.js.map +1 -1
  23. package/lib/core/sync/session-routes.d.ts +1 -1
  24. package/lib/core/sync/session-sync.d.ts +1 -1
  25. package/lib/core/sync/ssh-transport.d.ts +1 -1
  26. package/lib/core/sync/stores.d.ts +1 -1
  27. package/lib/core/workspaces.d.ts +1 -1
  28. package/lib/{host-key-CjO13Ds4.d.ts → host-key-DeHqgO7s.d.ts} +2 -2
  29. package/lib/{model-CX2TlH2E.d.ts → model-qtM3rcyA.d.ts} +3 -1
  30. package/lib/{node-sync-qnJ7u0TU.d.ts → node-sync-CJZl2FCE.d.ts} +3 -3
  31. package/lib/{session-journal-lum5L2ip.d.ts → session-journal-BwrCnkk4.d.ts} +4 -2
  32. package/lib/{session-sync-Be5wuYHJ.d.ts → session-sync-Celc4x_B.d.ts} +5 -5
  33. package/lib/{ssh-transport-Cevwfre9.d.ts → ssh-transport-DLXkPpxT.d.ts} +5 -5
  34. package/lib/{stores-BwQLabuJ.d.ts → stores-NzEbaGQ3.d.ts} +2 -2
  35. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"session-journal.js","names":[],"sources":["../../../src/core/sync/session-journal.ts"],"sourcesContent":["import { createHash, randomBytes } from 'node:crypto'\nimport { chmodSync, closeSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport type { Dirent } from 'node:fs'\nimport type { SyncImportMethod } from './model.js'\n\ninterface JournalBatch {\n peerId: string\n sourceName: string\n bundleDigest: string\n startedAt: string\n recordKeys: string[]\n importedVia?: SyncImportMethod\n allowSameInstance?: boolean\n}\n\ninterface JournalData {\n version: 1\n batches: Record<string, JournalBatch>\n}\n\nfunction sessionHome(home?: string): string {\n return home ?? process.env.DSH_HOME ?? join(homedir(), '.dsh')\n}\n\nfunction validBatch(value: unknown): value is JournalBatch {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return false\n const batch = value as Record<string, unknown>\n return typeof batch.peerId === 'string' && /^p-[a-f0-9]{24}$/.test(batch.peerId) &&\n typeof batch.sourceName === 'string' && batch.sourceName.length <= 128 && !/[\\u0000-\\u001f\\u007f]/.test(batch.sourceName) &&\n typeof batch.bundleDigest === 'string' && /^sha256:[a-f0-9]{64}$/.test(batch.bundleDigest) &&\n typeof batch.startedAt === 'string' && batch.startedAt.length <= 64 &&\n Array.isArray(batch.recordKeys) && batch.recordKeys.every((key) => typeof key === 'string' && key.length <= 8192) &&\n (batch.importedVia === undefined || batch.importedVia === 'peer' || batch.importedVia === 'offline') &&\n (batch.allowSameInstance === undefined || typeof batch.allowSameInstance === 'boolean')\n}\n\nfunction validateJournal(value: unknown): JournalData {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid sync session journal')\n const journal = value as Record<string, unknown>\n if (journal.version !== 1 || journal.batches === null || typeof journal.batches !== 'object' || Array.isArray(journal.batches)) {\n throw new Error('Invalid sync session journal')\n }\n const batches = Object.create(null) as Record<string, JournalBatch>\n for (const [id, batch] of Object.entries(journal.batches)) {\n if (!/^b-[a-f0-9]{32}$/.test(id) || !validBatch(batch)) throw new Error('Invalid sync session journal batch')\n batches[id] = {\n ...batch,\n importedVia: batch.importedVia ?? 'peer',\n allowSameInstance: batch.allowSameInstance ?? false,\n recordKeys: [...batch.recordKeys],\n }\n }\n return { version: 1, batches }\n}\n\nfunction atomicWrite(path: string, value: unknown): void {\n mkdirSync(join(path, '..'), { recursive: true, mode: 0o700 })\n const temporary = `${path}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`\n let descriptor: number | undefined\n try {\n descriptor = openSync(temporary, 'wx', 0o600)\n writeFileSync(descriptor, `${JSON.stringify(value, null, 2)}\\n`, 'utf8')\n fsyncSync(descriptor)\n closeSync(descriptor)\n descriptor = undefined\n renameSync(temporary, path)\n chmodSync(path, 0o600)\n } catch (error) {\n if (descriptor !== undefined) closeSync(descriptor)\n try {\n unlinkSync(temporary)\n } catch (cleanupError) {\n if (!(cleanupError instanceof Error) || !('code' in cleanupError) || cleanupError.code !== 'ENOENT') {\n throw new AggregateError([error, cleanupError], 'session journal write and cleanup failed')\n }\n }\n throw error\n }\n}\n\nexport class SyncSessionJournalStore {\n private readonly home: string\n private readonly filePath: string\n private data: JournalData | undefined\n\n constructor(home?: string) {\n this.home = sessionHome(home)\n this.filePath = join(this.home, 'dshb', 'sync-session-journal.json')\n }\n\n begin(\n peerId: string,\n sourceName: string,\n bundleDigest: string,\n recordKeys: readonly string[],\n startedAt = new Date().toISOString(),\n importedVia: SyncImportMethod = 'peer',\n allowSameInstance = false,\n ): string {\n const batchId = `b-${createHash('sha256').update(JSON.stringify([peerId, bundleDigest])).digest('hex').slice(0, 32)}`\n const data = this.load()\n const existing = data.batches[batchId]\n const batch: JournalBatch = {\n peerId,\n sourceName,\n bundleDigest,\n startedAt: existing?.startedAt ?? startedAt,\n recordKeys: [...new Set([...(existing?.recordKeys ?? []), ...recordKeys])],\n importedVia,\n allowSameInstance,\n }\n data.batches[batchId] = batch\n this.save()\n return batchId\n }\n\n beginWithBundle(\n peerId: string,\n sourceName: string,\n bundleDigest: string,\n recordKeys: readonly string[],\n bundle: unknown,\n startedAt = new Date().toISOString(),\n importedVia: SyncImportMethod = 'peer',\n allowSameInstance = false,\n ): string {\n const batchId = `b-${createHash('sha256').update(JSON.stringify([peerId, bundleDigest])).digest('hex').slice(0, 32)}`\n this.writeBundle(batchId, bundle)\n const registered = this.begin(\n peerId,\n sourceName,\n bundleDigest,\n recordKeys,\n startedAt,\n importedVia,\n allowSameInstance,\n )\n if (registered !== batchId) throw new Error('Session journal batch identity changed')\n return batchId\n }\n\n pendingPeerIds(): string[] {\n return [...new Set(Object.values(this.load().batches).map((batch) => batch.peerId))]\n }\n\n pendingBatches(): Array<{ batchId: string; peerId: string; sourceName: string; bundleDigest: string; importedVia: SyncImportMethod; allowSameInstance: boolean }> {\n return Object.entries(this.load().batches).map(([batchId, batch]) => ({\n batchId,\n peerId: batch.peerId,\n sourceName: batch.sourceName,\n bundleDigest: batch.bundleDigest,\n importedVia: batch.importedVia ?? 'peer',\n allowSameInstance: batch.allowSameInstance ?? false,\n }))\n }\n\n findBatch(peerId: string, bundleDigest: string): {\n batchId: string\n peerId: string\n sourceName: string\n bundleDigest: string\n importedVia: SyncImportMethod\n allowSameInstance: boolean\n } | undefined {\n const match = Object.entries(this.load().batches).find(([, batch]) =>\n batch.peerId === peerId && batch.bundleDigest === bundleDigest,\n )\n if (!match) return undefined\n const [batchId, batch] = match\n return {\n batchId,\n peerId: batch.peerId,\n sourceName: batch.sourceName,\n bundleDigest: batch.bundleDigest,\n importedVia: batch.importedVia ?? 'peer',\n allowSameInstance: batch.allowSameInstance ?? false,\n }\n }\n\n writeBundle(batchId: string, value: unknown): void {\n if (!/^b-[a-f0-9]{32}$/.test(batchId)) throw new Error('Invalid sync session batch ID')\n atomicWrite(this.bundlePath(batchId), value)\n }\n\n readBundle(batchId: string): unknown | undefined {\n try {\n return JSON.parse(readFileSync(this.bundlePath(batchId), 'utf8')) as unknown\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return undefined\n throw error\n }\n }\n\n writePrepared(batchId: string, recordKey: string, value: unknown): void {\n if (!/^b-[a-f0-9]{32}$/.test(batchId)) throw new Error('Invalid sync session batch ID')\n const file = this.preparedPath(batchId, recordKey)\n atomicWrite(file, value)\n }\n\n readPrepared(batchId: string, recordKey: string): unknown | undefined {\n const file = this.preparedPath(batchId, recordKey)\n try {\n return JSON.parse(readFileSync(file, 'utf8')) as unknown\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return undefined\n throw error\n }\n }\n\n complete(batchId: string): void {\n const data = this.load()\n delete data.batches[batchId]\n this.save()\n rmSync(join(this.home, 'dshb', 'sync-session-staging', batchId), { recursive: true, force: true })\n }\n\n /**\n * 丢弃一个未完成批次:删除批次记录与暂存目录。用于手动停止同步——\n * 该批未应用的条目不再落地,重启后也不会被 recoverPending 回放。\n * 已应用完成的条目不受影响(它们是完整会话,不是半文件)。\n */\n discard(batchId: string): void {\n if (!/^b-[a-f0-9]{32}$/.test(batchId)) throw new Error('Invalid sync session batch ID')\n const data = this.load()\n if (data.batches[batchId] === undefined) return\n delete data.batches[batchId]\n this.save()\n rmSync(join(this.home, 'dshb', 'sync-session-staging', batchId), { recursive: true, force: true })\n }\n\n cleanupOrphanedStaging(): void {\n const root = join(this.home, 'dshb', 'sync-session-staging')\n let entries: Dirent[]\n try {\n entries = readdirSync(root, { withFileTypes: true })\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return\n throw error\n }\n const activeBatches = new Set(Object.keys(this.load().batches))\n for (const entry of entries) {\n if (entry.isDirectory() && /^b-[a-f0-9]{32}$/.test(entry.name) && !activeBatches.has(entry.name)) {\n rmSync(join(root, entry.name), { recursive: true, force: true })\n }\n }\n }\n\n private preparedPath(batchId: string, recordKey: string): string {\n const digest = createHash('sha256').update(recordKey).digest('hex')\n return join(this.home, 'dshb', 'sync-session-staging', batchId, `${digest}.json`)\n }\n\n private bundlePath(batchId: string): string {\n return join(this.home, 'dshb', 'sync-session-staging', batchId, 'bundle.json')\n }\n\n private load(): JournalData {\n if (this.data) return this.data\n try {\n this.data = validateJournal(JSON.parse(readFileSync(this.filePath, 'utf8')) as unknown)\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {\n this.data = { version: 1, batches: {} }\n } else {\n throw error\n }\n }\n return this.data\n }\n\n private save(): void {\n atomicWrite(this.filePath, this.load())\n }\n}\n"],"mappings":";;;;;AAsBA,SAAS,YAAY,MAAuB;CAC1C,OAAO,QAAQ,QAAQ,IAAI,YAAY,KAAK,QAAQ,GAAG,MAAM;AAC/D;AAEA,SAAS,WAAW,OAAuC;CACzD,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO;CAChF,MAAM,QAAQ;CACd,OAAO,OAAO,MAAM,WAAW,YAAY,mBAAmB,KAAK,MAAM,MAAM,KAC7E,OAAO,MAAM,eAAe,YAAY,MAAM,WAAW,UAAU,OAAO,CAAC,wBAAwB,KAAK,MAAM,UAAU,KACxH,OAAO,MAAM,iBAAiB,YAAY,wBAAwB,KAAK,MAAM,YAAY,KACzF,OAAO,MAAM,cAAc,YAAY,MAAM,UAAU,UAAU,MACjE,MAAM,QAAQ,MAAM,UAAU,KAAK,MAAM,WAAW,OAAO,QAAQ,OAAO,QAAQ,YAAY,IAAI,UAAU,IAAI,MAC/G,MAAM,gBAAgB,KAAA,KAAa,MAAM,gBAAgB,UAAU,MAAM,gBAAgB,eACzF,MAAM,sBAAsB,KAAA,KAAa,OAAO,MAAM,sBAAsB;AACjF;AAEA,SAAS,g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AAC;CAGrE;CAEA,aAAqB,SAAiB,WAA2B;EAC/D,MAAM,SAAS,WAAW,QAAQ,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,KAAK;EAClE,OAAO,KAAK,KAAK,MAAM,QAAQ,wBAAwB,SAAS,GAAG,OAAO,MAAM;CAClF;CAEA,WAAmB,SAAyB;EAC1C,OAAO,KAAK,KAAK,MAAM,QAAQ,wBAAwB,SAAS,aAAa;CAC/E;CAEA,OAA4B;EAC1B,IAAI,KAAK,MAAM,OAAO,KAAK;EAC3B,IAAI;GACF,KAAK,OAAO,gBAAgB,KAAK,MAAM,aAAa,KAAK,UAAU,MAAM,CAAC,CAAY;EACxF,SAAS,OAAO;GACd,IAAI,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS,UAC9D,KAAK,OAAO;IAAE,SAAS;IAAG,SAAS,CAAC;GAAE;QAEtC,MAAM;EAEV;EACA,OAAO,KAAK;CACd;CAEA,OAAqB;EACnB,YAAY,KAAK,UAAU,KAAK,KAAK,CAAC;CACxC;AACF"}
1
+ {"version":3,"file":"session-journal.js","names":[],"sources":["../../../src/core/sync/session-journal.ts"],"sourcesContent":["import { createHash, randomBytes } from 'node:crypto'\nimport { chmodSync, closeSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport type { Dirent } from 'node:fs'\nimport type { SyncImportMethod } from './model.js'\n\ninterface JournalBatch {\n peerId: string\n sourceName: string\n bundleDigest: string\n startedAt: string\n recordKeys: string[]\n importedVia?: SyncImportMethod\n allowSameInstance?: boolean\n}\n\ninterface JournalData {\n version: 1\n batches: Record<string, JournalBatch>\n}\n\nfunction sessionHome(home?: string): string {\n return home ?? process.env.DSH_HOME ?? join(homedir(), '.dsh')\n}\n\nfunction validBatch(value: unknown): value is JournalBatch {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return false\n const batch = value as Record<string, unknown>\n return typeof batch.peerId === 'string' && /^p-[a-f0-9]{24}$/.test(batch.peerId) &&\n typeof batch.sourceName === 'string' && batch.sourceName.length <= 128 && !/[\\u0000-\\u001f\\u007f]/.test(batch.sourceName) &&\n typeof batch.bundleDigest === 'string' && /^sha256:[a-f0-9]{64}$/.test(batch.bundleDigest) &&\n typeof batch.startedAt === 'string' && batch.startedAt.length <= 64 &&\n Array.isArray(batch.recordKeys) && batch.recordKeys.every((key) => typeof key === 'string' && key.length <= 8192) &&\n (batch.importedVia === undefined || batch.importedVia === 'peer' || batch.importedVia === 'offline') &&\n (batch.allowSameInstance === undefined || typeof batch.allowSameInstance === 'boolean')\n}\n\nfunction validateJournal(value: unknown): JournalData {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid sync session journal')\n const journal = value as Record<string, unknown>\n if (journal.version !== 1 || journal.batches === null || typeof journal.batches !== 'object' || Array.isArray(journal.batches)) {\n throw new Error('Invalid sync session journal')\n }\n const batches = Object.create(null) as Record<string, JournalBatch>\n for (const [id, batch] of Object.entries(journal.batches)) {\n if (!/^b-[a-f0-9]{32}$/.test(id) || !validBatch(batch)) throw new Error('Invalid sync session journal batch')\n batches[id] = {\n ...batch,\n importedVia: batch.importedVia ?? 'peer',\n allowSameInstance: batch.allowSameInstance ?? false,\n recordKeys: [...batch.recordKeys],\n }\n }\n return { version: 1, batches }\n}\n\nfunction atomicWrite(path: string, value: unknown): void {\n mkdirSync(join(path, '..'), { recursive: true, mode: 0o700 })\n const temporary = `${path}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`\n let descriptor: number | undefined\n try {\n descriptor = openSync(temporary, 'wx', 0o600)\n writeFileSync(descriptor, `${JSON.stringify(value, null, 2)}\\n`, 'utf8')\n fsyncSync(descriptor)\n closeSync(descriptor)\n descriptor = undefined\n renameSync(temporary, path)\n chmodSync(path, 0o600)\n } catch (error) {\n if (descriptor !== undefined) closeSync(descriptor)\n try {\n unlinkSync(temporary)\n } catch (cleanupError) {\n if (!(cleanupError instanceof Error) || !('code' in cleanupError) || cleanupError.code !== 'ENOENT') {\n throw new AggregateError([error, cleanupError], 'session journal write and cleanup failed')\n }\n }\n throw error\n }\n}\n\nexport class SyncSessionJournalStore {\n private readonly home: string\n private readonly filePath: string\n private data: JournalData | undefined\n\n constructor(home?: string) {\n this.home = sessionHome(home)\n this.filePath = join(this.home, 'dshb', 'sync-session-journal.json')\n }\n\n begin(\n peerId: string,\n sourceName: string,\n bundleDigest: string,\n recordKeys: readonly string[],\n startedAt = new Date().toISOString(),\n importedVia: SyncImportMethod = 'peer',\n allowSameInstance = false,\n ): string {\n const batchId = `b-${createHash('sha256').update(JSON.stringify([peerId, bundleDigest])).digest('hex').slice(0, 32)}`\n const data = this.load()\n const existing = data.batches[batchId]\n const batch: JournalBatch = {\n peerId,\n sourceName,\n bundleDigest,\n startedAt: existing?.startedAt ?? startedAt,\n recordKeys: [...new Set([...(existing?.recordKeys ?? []), ...recordKeys])],\n importedVia,\n allowSameInstance,\n }\n data.batches[batchId] = batch\n this.save()\n return batchId\n }\n\n beginWithBundle(\n peerId: string,\n sourceName: string,\n bundleDigest: string,\n recordKeys: readonly string[],\n bundle: unknown,\n startedAt = new Date().toISOString(),\n importedVia: SyncImportMethod = 'peer',\n allowSameInstance = false,\n ): string {\n const batchId = `b-${createHash('sha256').update(JSON.stringify([peerId, bundleDigest])).digest('hex').slice(0, 32)}`\n this.writeBundle(batchId, bundle)\n const registered = this.begin(\n peerId,\n sourceName,\n bundleDigest,\n recordKeys,\n startedAt,\n importedVia,\n allowSameInstance,\n )\n if (registered !== batchId) throw new Error('Session journal batch identity changed')\n return batchId\n }\n\n pendingPeerIds(): string[] {\n return [...new Set(Object.values(this.load().batches).map((batch) => batch.peerId))]\n }\n\n /** 返回包含该同步记录键的最近一次导入批次;用于把本地会话映射回来源 peer。 */\n peerIdForRecordKey(recordKey: string): string | undefined {\n if (typeof recordKey !== 'string' || recordKey.length === 0 || recordKey.length > 8192) return undefined\n let hit: JournalBatch | undefined\n for (const batch of Object.values(this.load().batches)) {\n if (!batch.recordKeys.includes(recordKey)) continue\n if (!hit || batch.startedAt > hit.startedAt) hit = batch\n }\n return hit?.peerId\n }\n\n pendingBatches(): Array<{ batchId: string; peerId: string; sourceName: string; bundleDigest: string; importedVia: SyncImportMethod; allowSameInstance: boolean }> {\n return Object.entries(this.load().batches).map(([batchId, batch]) => ({\n batchId,\n peerId: batch.peerId,\n sourceName: batch.sourceName,\n bundleDigest: batch.bundleDigest,\n importedVia: batch.importedVia ?? 'peer',\n allowSameInstance: batch.allowSameInstance ?? false,\n }))\n }\n\n findBatch(peerId: string, bundleDigest: string): {\n batchId: string\n peerId: string\n sourceName: string\n bundleDigest: string\n importedVia: SyncImportMethod\n allowSameInstance: boolean\n } | undefined {\n const match = Object.entries(this.load().batches).find(([, batch]) =>\n batch.peerId === peerId && batch.bundleDigest === bundleDigest,\n )\n if (!match) return undefined\n const [batchId, batch] = match\n return {\n batchId,\n peerId: batch.peerId,\n sourceName: batch.sourceName,\n bundleDigest: batch.bundleDigest,\n importedVia: batch.importedVia ?? 'peer',\n allowSameInstance: batch.allowSameInstance ?? false,\n }\n }\n\n writeBundle(batchId: string, value: unknown): void {\n if (!/^b-[a-f0-9]{32}$/.test(batchId)) throw new Error('Invalid sync session batch ID')\n atomicWrite(this.bundlePath(batchId), value)\n }\n\n readBundle(batchId: string): unknown | undefined {\n try {\n return JSON.parse(readFileSync(this.bundlePath(batchId), 'utf8')) as unknown\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return undefined\n throw error\n }\n }\n\n writePrepared(batchId: string, recordKey: string, value: unknown): void {\n if (!/^b-[a-f0-9]{32}$/.test(batchId)) throw new Error('Invalid sync session batch ID')\n const file = this.preparedPath(batchId, recordKey)\n atomicWrite(file, value)\n }\n\n readPrepared(batchId: string, recordKey: string): unknown | undefined {\n const file = this.preparedPath(batchId, recordKey)\n try {\n return JSON.parse(readFileSync(file, 'utf8')) as unknown\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return undefined\n throw error\n }\n }\n\n complete(batchId: string): void {\n const data = this.load()\n delete data.batches[batchId]\n this.save()\n rmSync(join(this.home, 'dshb', 'sync-session-staging', batchId), { recursive: true, force: true })\n }\n\n /**\n * 丢弃一个未完成批次:删除批次记录与暂存目录。用于手动停止同步——\n * 该批未应用的条目不再落地,重启后也不会被 recoverPending 回放。\n * 已应用完成的条目不受影响(它们是完整会话,不是半文件)。\n */\n discard(batchId: string): void {\n if (!/^b-[a-f0-9]{32}$/.test(batchId)) throw new Error('Invalid sync session batch ID')\n const data = this.load()\n if (data.batches[batchId] === undefined) return\n delete data.batches[batchId]\n this.save()\n rmSync(join(this.home, 'dshb', 'sync-session-staging', batchId), { recursive: true, force: true })\n }\n\n cleanupOrphanedStaging(): void {\n const root = join(this.home, 'dshb', 'sync-session-staging')\n let entries: Dirent[]\n try {\n entries = readdirSync(root, { withFileTypes: true })\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return\n throw error\n }\n const activeBatches = new Set(Object.keys(this.load().batches))\n for (const entry of entries) {\n if (entry.isDirectory() && /^b-[a-f0-9]{32}$/.test(entry.name) && !activeBatches.has(entry.name)) {\n rmSync(join(root, entry.name), { recursive: true, force: true })\n }\n }\n }\n\n private preparedPath(batchId: string, recordKey: string): string {\n const digest = createHash('sha256').update(recordKey).digest('hex')\n return join(this.home, 'dshb', 'sync-session-staging', batchId, `${digest}.json`)\n }\n\n private bundlePath(batchId: string): string {\n return join(this.home, 'dshb', 'sync-session-staging', batchId, 'bundle.json')\n }\n\n private load(): JournalData {\n if (this.data) return this.data\n try {\n this.data = validateJournal(JSON.parse(readFileSync(this.filePath, 'utf8')) as unknown)\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {\n this.data = { version: 1, batches: {} }\n } else {\n throw error\n }\n }\n return this.data\n }\n\n private save(): void {\n atomicWrite(this.filePath, this.load())\n }\n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O,MAAM;CAClF;CAEA,WAAmB,SAAyB;EAC1C,OAAO,KAAK,KAAK,MAAM,QAAQ,wBAAwB,SAAS,aAAa;CAC/E;CAEA,OAA4B;EAC1B,IAAI,KAAK,MAAM,OAAO,KAAK;EAC3B,IAAI;GACF,KAAK,OAAO,gBAAgB,KAAK,MAAM,aAAa,KAAK,UAAU,MAAM,CAAC,CAAY;EACxF,SAAS,OAAO;GACd,IAAI,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS,UAC9D,KAAK,OAAO;IAAE,SAAS;IAAG,SAAS,CAAC;GAAE;QAEtC,MAAM;EAEV;EACA,OAAO,KAAK;CACd;CAEA,OAAqB;EACnB,YAAY,KAAK,UAAU,KAAK,KAAK,CAAC;CACxC;AACF"}
@@ -1,4 +1,4 @@
1
- import { h as SyncSessionService } from "../../session-sync-Be5wuYHJ.js";
1
+ import { h as SyncSessionService } from "../../session-sync-Celc4x_B.js";
2
2
  import { Context } from "@deepseek-ai/cordis";
3
3
  //#region src/core/sync/session-routes.d.ts
4
4
  declare function registerSyncSessionRoutes(ctx: Context, sessions: SyncSessionService): void;
@@ -1,2 +1,2 @@
1
- import { C as sessionEventListDigest, D as validateSyncSessionManifest, E as validateSyncSessionBundle, S as planSessionTransfers, T as validateObjectPayload, _ as SyncSessionWorkspace, a as SyncSessionBundle, b as makeSyncSessionBundle, c as SyncSessionEventDelta, d as SyncSessionManifest, f as SyncSessionManifestEntry, g as SyncSessionTransferPlan, h as SyncSessionService, i as SyncSessionApplyResult, l as SyncSessionEventPrefix, m as SyncSessionObjectInbox, n as SyncObjectInboxWriter, o as SyncSessionEntry, p as SyncSessionObject, r as SyncSessionApplyOptions, s as SyncSessionError, t as ExportObjectCache, u as SyncSessionInstructionSnapshot, v as WorkspaceRegistryLike, w as syncSessionEntryKey, x as makeSyncSessionManifest, y as estimateJsonBytes } from "../../session-sync-Be5wuYHJ.js";
1
+ import { C as sessionEventListDigest, D as validateSyncSessionManifest, E as validateSyncSessionBundle, S as planSessionTransfers, T as validateObjectPayload, _ as SyncSessionWorkspace, a as SyncSessionBundle, b as makeSyncSessionBundle, c as SyncSessionEventDelta, d as SyncSessionManifest, f as SyncSessionManifestEntry, g as SyncSessionTransferPlan, h as SyncSessionService, i as SyncSessionApplyResult, l as SyncSessionEventPrefix, m as SyncSessionObjectInbox, n as SyncObjectInboxWriter, o as SyncSessionEntry, p as SyncSessionObject, r as SyncSessionApplyOptions, s as SyncSessionError, t as ExportObjectCache, u as SyncSessionInstructionSnapshot, v as WorkspaceRegistryLike, w as syncSessionEntryKey, x as makeSyncSessionManifest, y as estimateJsonBytes } from "../../session-sync-Celc4x_B.js";
2
2
  export { ExportObjectCache, SyncObjectInboxWriter, SyncSessionApplyOptions, SyncSessionApplyResult, SyncSessionBundle, SyncSessionEntry, SyncSessionError, SyncSessionEventDelta, SyncSessionEventPrefix, SyncSessionInstructionSnapshot, SyncSessionManifest, SyncSessionManifestEntry, SyncSessionObject, SyncSessionObjectInbox, SyncSessionService, SyncSessionTransferPlan, SyncSessionWorkspace, WorkspaceRegistryLike, estimateJsonBytes, makeSyncSessionBundle, makeSyncSessionManifest, planSessionTransfers, sessionEventListDigest, syncSessionEntryKey, validateObjectPayload, validateSyncSessionBundle, validateSyncSessionManifest };
@@ -1,2 +1,2 @@
1
- import { _ as parseRemoteProbeOutput, a as SyncRemoteProbe, c as SyncRemoteProbeProfile, d as SyncSshErrorCategory, f as SyncSshProbeError, g as buildSyncSshConnectConfig, h as buildRemoteProbeScript, i as SyncRemoteNodeManifest, l as SyncRemoteProbeResult, m as SyncSshTransport, n as REMOTE_PROBE_END_MARKER, o as SyncRemoteProbeDraft, p as SyncSshSession, r as SyncRemoteHandshake, s as SyncRemoteProbeHandshake, t as REMOTE_PROBE_BEGIN_MARKER, u as SyncSessionDeltaPrefixError } from "../../ssh-transport-Cevwfre9.js";
1
+ import { _ as parseRemoteProbeOutput, a as SyncRemoteProbe, c as SyncRemoteProbeProfile, d as SyncSshErrorCategory, f as SyncSshProbeError, g as buildSyncSshConnectConfig, h as buildRemoteProbeScript, i as SyncRemoteNodeManifest, l as SyncRemoteProbeResult, m as SyncSshTransport, n as REMOTE_PROBE_END_MARKER, o as SyncRemoteProbeDraft, p as SyncSshSession, r as SyncRemoteHandshake, s as SyncRemoteProbeHandshake, t as REMOTE_PROBE_BEGIN_MARKER, u as SyncSessionDeltaPrefixError } from "../../ssh-transport-DLXkPpxT.js";
2
2
  export { REMOTE_PROBE_BEGIN_MARKER, REMOTE_PROBE_END_MARKER, SyncRemoteHandshake, SyncRemoteNodeManifest, SyncRemoteProbe, SyncRemoteProbeDraft, SyncRemoteProbeHandshake, SyncRemoteProbeProfile, SyncRemoteProbeResult, SyncSessionDeltaPrefixError, SyncSshErrorCategory, SyncSshProbeError, SyncSshSession, SyncSshTransport, buildRemoteProbeScript, buildSyncSshConnectConfig, parseRemoteProbeOutput };
@@ -1,3 +1,3 @@
1
1
  import { t as HlcSnapshot } from "../../revision-C9sOlDZ6.js";
2
- import { n as SyncStateStore, r as getOrCreateSyncInstanceId, t as SyncPeerStore } from "../../stores-BwQLabuJ.js";
2
+ import { n as SyncStateStore, r as getOrCreateSyncInstanceId, t as SyncPeerStore } from "../../stores-NzEbaGQ3.js";
3
3
  export { type HlcSnapshot, SyncPeerStore, SyncStateStore, getOrCreateSyncInstanceId };
@@ -1,6 +1,6 @@
1
1
  import { o as NodeRegistry } from "../node-registry-BTnnM5-k.js";
2
2
  import { r as WorkspaceBindingsStore } from "../workspace-bindings-CsB0TIJB.js";
3
- import { s as SyncNodeService } from "../node-sync-qnJ7u0TU.js";
3
+ import { s as SyncNodeService } from "../node-sync-CJZl2FCE.js";
4
4
  import { Context } from "@deepseek-ai/cordis";
5
5
  //#region src/core/workspaces.d.ts
6
6
  declare function registerWorkspaceRoutes(ctx: Context, registry: NodeRegistry, bindings: WorkspaceBindingsStore, syncNodes?: SyncNodeService): void;
@@ -1,4 +1,4 @@
1
- import { u as SyncPeer } from "./model-CX2TlH2E.js";
1
+ import { u as SyncPeer } from "./model-qtM3rcyA.js";
2
2
  //#region src/core/sync/host-key.d.ts
3
3
  type SyncHostKeyDecision = 'trusted' | 'untrusted' | 'changed';
4
4
  declare class SyncHostKeyChallengeError extends Error {
@@ -27,4 +27,4 @@ declare class SyncHostKeyChallenges {
27
27
  }
28
28
  //#endregion
29
29
  export { inspectSyncHostKey as a, SyncHostKeyDecision as i, SyncHostKeyChallengeExpiredError as n, isOpenSshFingerprint as o, SyncHostKeyChallenges as r, opensshFingerprintFromSha256Hex as s, SyncHostKeyChallengeError as t };
30
- //# sourceMappingURL=host-key-CjO13Ds4.d.ts.map
30
+ //# sourceMappingURL=host-key-DeHqgO7s.d.ts.map
@@ -23,6 +23,8 @@ interface SyncPeer {
23
23
  direction: SyncDirection;
24
24
  schedule: SyncSchedule;
25
25
  mode: SyncMode;
26
+ /** 同步工作节点配置;仅元数据同步可关闭(全量会话同步依赖节点配置)。缺省 true。 */
27
+ syncNodes?: boolean;
26
28
  syncSessions: boolean;
27
29
  selection?: SyncSelection;
28
30
  enabled: boolean;
@@ -165,4 +167,4 @@ declare function isRecord(value: unknown): value is Record<string, unknown>;
165
167
  declare function isNonNegativeSafeInteger(value: unknown): value is number;
166
168
  //#endregion
167
169
  export { parseSyncPeer as C, syncWorkspaceKey as D, syncRecordKey as E, isRecord as S, parseSyncSelection as T, SyncSessionArchive as _, SyncDirection as a, SyncWorkspaceOrigin as b, SyncMode as c, SyncPeerDraft as d, SyncPeerProgress as f, SyncSelection as g, SyncSchedule as h, SyncCatalogWorkspace as i, SyncOrigin as l, SyncRecordMetadata as m, SyncCatalogNode as n, SyncEntityKind as o, SyncProvenance as p, SyncCatalogSession as r, SyncImportMethod as s, SyncCatalog as t, SyncPeer as u, SyncState as v, parseSyncPeerDraft as w, isNonNegativeSafeInteger as x, SyncWorkspaceMapping as y };
168
- //# sourceMappingURL=model-CX2TlH2E.d.ts.map
170
+ //# sourceMappingURL=model-qtM3rcyA.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { c as NodeSsh, o as NodeRegistry, r as NodeDocker, s as NodeSecrets } from "./node-registry-BTnnM5-k.js";
2
2
  import { r as WorkspaceBindingsStore } from "./workspace-bindings-CsB0TIJB.js";
3
- import { m as SyncRecordMetadata, s as SyncImportMethod } from "./model-CX2TlH2E.js";
4
- import { n as SyncStateStore } from "./stores-BwQLabuJ.js";
3
+ import { m as SyncRecordMetadata, s as SyncImportMethod } from "./model-qtM3rcyA.js";
4
+ import { n as SyncStateStore } from "./stores-NzEbaGQ3.js";
5
5
  //#region src/core/sync/node-sync.d.ts
6
6
  interface SyncNodeProfile {
7
7
  name: string;
@@ -86,4 +86,4 @@ declare class SyncNodeService {
86
86
  }
87
87
  //#endregion
88
88
  export { SyncNodeManifestError as a, SyncNodeView as c, SyncNodeManifest as i, SyncNodeEntry as n, SyncNodeProfile as o, SyncNodeInUseError as r, SyncNodeService as s, SyncNodeApplyResult as t };
89
- //# sourceMappingURL=node-sync-qnJ7u0TU.d.ts.map
89
+ //# sourceMappingURL=node-sync-CJZl2FCE.d.ts.map
@@ -1,4 +1,4 @@
1
- import { s as SyncImportMethod } from "./model-CX2TlH2E.js";
1
+ import { s as SyncImportMethod } from "./model-qtM3rcyA.js";
2
2
  //#region src/core/sync/session-journal.d.ts
3
3
  declare class SyncSessionJournalStore {
4
4
  private readonly home;
@@ -8,6 +8,8 @@ declare class SyncSessionJournalStore {
8
8
  begin(peerId: string, sourceName: string, bundleDigest: string, recordKeys: readonly string[], startedAt?: string, importedVia?: SyncImportMethod, allowSameInstance?: boolean): string;
9
9
  beginWithBundle(peerId: string, sourceName: string, bundleDigest: string, recordKeys: readonly string[], bundle: unknown, startedAt?: string, importedVia?: SyncImportMethod, allowSameInstance?: boolean): string;
10
10
  pendingPeerIds(): string[];
11
+ /** 返回包含该同步记录键的最近一次导入批次;用于把本地会话映射回来源 peer。 */
12
+ peerIdForRecordKey(recordKey: string): string | undefined;
11
13
  pendingBatches(): Array<{
12
14
  batchId: string;
13
15
  peerId: string;
@@ -43,4 +45,4 @@ declare class SyncSessionJournalStore {
43
45
  }
44
46
  //#endregion
45
47
  export { SyncSessionJournalStore as t };
46
- //# sourceMappingURL=session-journal-lum5L2ip.d.ts.map
48
+ //# sourceMappingURL=session-journal-BwrCnkk4.d.ts.map
@@ -1,12 +1,12 @@
1
1
  import { o as NodeRegistry } from "./node-registry-BTnnM5-k.js";
2
2
  import { r as WorkspaceBindingsStore } from "./workspace-bindings-CsB0TIJB.js";
3
3
  import { r as SyncRevision } from "./revision-C9sOlDZ6.js";
4
- import { _ as SyncSessionArchive, i as SyncCatalogWorkspace, l as SyncOrigin, m as SyncRecordMetadata, r as SyncCatalogSession, s as SyncImportMethod } from "./model-CX2TlH2E.js";
5
- import { n as SyncStateStore } from "./stores-BwQLabuJ.js";
6
- import { s as SyncNodeService } from "./node-sync-qnJ7u0TU.js";
4
+ import { _ as SyncSessionArchive, i as SyncCatalogWorkspace, l as SyncOrigin, m as SyncRecordMetadata, r as SyncCatalogSession, s as SyncImportMethod } from "./model-qtM3rcyA.js";
5
+ import { n as SyncStateStore } from "./stores-NzEbaGQ3.js";
6
+ import { s as SyncNodeService } from "./node-sync-CJZl2FCE.js";
7
7
  import { S as BrandedNumber, _ as FileAttachmentRef, a as SystemPromptUpdate, b as TypertResource, c as ToolSchema, d as Message, f as SystemMessage, g as ToolCallId, i as LlmFailure, l as AssistantMessage, m as UserMessage, n as LlmCallConfig, o as TokenUsage, p as ToolResultMessage, r as LlmCallConfigAdapterDefaults, s as ToolHistory, t as AssistantStreamRecord, u as DeveloperMessage, v as ImageAttachmentRef, x as Branded, y as TypertLookup } from "./index-VF8bcBeX.js";
8
8
  import { a as SessionInstructionSnapshotStore, s as WorkspaceInstructionStore } from "./workspace-instructions-C_ViytzA.js";
9
- import { t as SyncSessionJournalStore } from "./session-journal-lum5L2ip.js";
9
+ import { t as SyncSessionJournalStore } from "./session-journal-BwrCnkk4.js";
10
10
  import { Context, Service } from "@deepseek-ai/cordis";
11
11
  //#region ../../node_modules/@deepseek-ai/dsh-scope/lib/types/index.d.ts
12
12
  declare const ScopedBrand: unique symbol;
@@ -1377,4 +1377,4 @@ declare class SyncSessionService {
1377
1377
  }
1378
1378
  //#endregion
1379
1379
  export { sessionEventListDigest as C, validateSyncSessionManifest as D, validateSyncSessionBundle as E, planSessionTransfers as S, validateObjectPayload as T, SyncSessionWorkspace as _, SyncSessionBundle as a, makeSyncSessionBundle as b, SyncSessionEventDelta as c, SyncSessionManifest as d, SyncSessionManifestEntry as f, SyncSessionTransferPlan as g, SyncSessionService as h, SyncSessionApplyResult as i, SyncSessionEventPrefix as l, SyncSessionObjectInbox as m, SyncObjectInboxWriter as n, SyncSessionEntry as o, SyncSessionObject as p, SyncSessionApplyOptions as r, SyncSessionError as s, ExportObjectCache as t, SyncSessionInstructionSnapshot as u, WorkspaceRegistryLike as v, syncSessionEntryKey as w, makeSyncSessionManifest as x, estimateJsonBytes as y };
1380
- //# sourceMappingURL=session-sync-Be5wuYHJ.d.ts.map
1380
+ //# sourceMappingURL=session-sync-Celc4x_B.d.ts.map
@@ -1,9 +1,9 @@
1
- import { t as SyncCatalog, u as SyncPeer } from "./model-CX2TlH2E.js";
2
- import { i as SyncNodeManifest, t as SyncNodeApplyResult } from "./node-sync-qnJ7u0TU.js";
1
+ import { t as SyncCatalog, u as SyncPeer } from "./model-qtM3rcyA.js";
2
+ import { i as SyncNodeManifest, t as SyncNodeApplyResult } from "./node-sync-CJZl2FCE.js";
3
3
  import { SyncPeerManager, SyncPeerSecrets } from "./core/sync/peer-manager.js";
4
- import { r as SyncHostKeyChallenges, t as SyncHostKeyChallengeError } from "./host-key-CjO13Ds4.js";
4
+ import { r as SyncHostKeyChallenges, t as SyncHostKeyChallengeError } from "./host-key-DeHqgO7s.js";
5
5
  import { f as SyncFrame } from "./protocol-DyPDIJWa.js";
6
- import { a as SyncSessionBundle, d as SyncSessionManifest, i as SyncSessionApplyResult, l as SyncSessionEventPrefix, p as SyncSessionObject } from "./session-sync-Be5wuYHJ.js";
6
+ import { a as SyncSessionBundle, d as SyncSessionManifest, i as SyncSessionApplyResult, l as SyncSessionEventPrefix, p as SyncSessionObject } from "./session-sync-Celc4x_B.js";
7
7
  import { Client, ClientChannel, ConnectConfig } from "ssh2";
8
8
  //#region src/core/sync/ssh-transport.d.ts
9
9
  type SyncSshErrorCategory = 'auth' | 'network' | 'hostkey' | 'timeout' | 'helper' | 'protocol';
@@ -138,4 +138,4 @@ declare class SyncRemoteProbe {
138
138
  }
139
139
  //#endregion
140
140
  export { parseRemoteProbeOutput as _, SyncRemoteProbe as a, SyncRemoteProbeProfile as c, SyncSshErrorCategory as d, SyncSshProbeError as f, buildSyncSshConnectConfig as g, buildRemoteProbeScript as h, SyncRemoteNodeManifest as i, SyncRemoteProbeResult as l, SyncSshTransport as m, REMOTE_PROBE_END_MARKER as n, SyncRemoteProbeDraft as o, SyncSshSession as p, SyncRemoteHandshake as r, SyncRemoteProbeHandshake as s, REMOTE_PROBE_BEGIN_MARKER as t, SyncSessionDeltaPrefixError as u };
141
- //# sourceMappingURL=ssh-transport-Cevwfre9.d.ts.map
141
+ //# sourceMappingURL=ssh-transport-DLXkPpxT.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { r as SyncRevision } from "./revision-C9sOlDZ6.js";
2
- import { d as SyncPeerDraft, u as SyncPeer, v as SyncState } from "./model-CX2TlH2E.js";
2
+ import { d as SyncPeerDraft, u as SyncPeer, v as SyncState } from "./model-qtM3rcyA.js";
3
3
  //#region src/core/sync/stores.d.ts
4
4
  declare function getOrCreateSyncInstanceId(home?: string): string;
5
5
  declare class SyncPeerStore {
@@ -28,4 +28,4 @@ declare class SyncStateStore {
28
28
  }
29
29
  //#endregion
30
30
  export { SyncStateStore as n, getOrCreateSyncInstanceId as r, SyncPeerStore as t };
31
- //# sourceMappingURL=stores-BwQLabuJ.d.ts.map
31
+ //# sourceMappingURL=stores-NzEbaGQ3.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artenx/dshb",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "description": "让 DSH 变成随时可用的多设备 Agent 工作台,支持将远程节点添加到本地 DSH,并像操作本地内容一样访问远程节点,包括会话环境、文件目录、终端等。支持在安装了本插件的多个 DSH 实例间同步数据。若部署在云服务器,Web 端访问支持登录认证。真正实现远程节点本地化操作。最新版本已支持 DSH 桌面端。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",