dsh-session-sync 0.2.10 → 0.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.
- package/ARCHITECTURE.md +1 -1
- package/CHANGELOG.md +6 -0
- package/index.mjs +17 -6
- package/lib/paths.mjs +52 -0
- package/package.json +1 -1
package/ARCHITECTURE.md
CHANGED
|
@@ -52,7 +52,7 @@ The three-way merge compares `base` (merge base), `ours` (local), and `theirs` (
|
|
|
52
52
|
| `append-both` | both appended past base | keep ours + fork file for theirs |
|
|
53
53
|
| `diverged` | neither is a superset | keep ours + fork file for theirs |
|
|
54
54
|
|
|
55
|
-
Fork files are named `<basename>.remote-fork-<UTC timestamp>-<device8>`; mirror and cleanup **never delete or overwrite** files matching that pattern, so both lineages always survive. When a conflicting session is live and has no open turn, the plugin also forks the session at the harness level and injects a persistent `user/message` notice into the child.
|
|
55
|
+
Fork files are named `<basename>.remote-fork-<UTC timestamp>-<device8>`; mirror and cleanup **never delete or overwrite** files matching that pattern, so both lineages always survive. When a conflicting session is live and has no open turn, the plugin also forks the session at the harness level and injects a persistent `user/message` notice into the child. The session-level mapping follows the host's real session-store layout `$DSH_HOME/sessions/<projectKey>/<sessionId>/<file>` — `projectKey` is derived from the session `cwd` (`_no-cwd` when absent) and `sessionId` is the host's `encodeSegment` form, which `lib/paths.mjs` decodes back (`~XXXX` escapes). Fork paths that do not fit that shape (or the legacy flat `<mirrorDir>/<sessionId>/<file>` form) are reported with a warning and never silently dropped; the fork files themselves are always preserved.
|
|
56
56
|
|
|
57
57
|
## Confirmation gate
|
|
58
58
|
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.11] - 2026-09-09
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Map fork files to sessions with the host's real session-store layout `$DSH_HOME/sessions/<projectKey>/<sessionId>/<file>`: the session-level fork lookup treated the project key as a session id, so on harness `dsh-v0.1.5-alpha.1` (session format V3, zstd by default) every session-level fork and its `sync/conflict` event was silently skipped while the fork files were still kept. `lib/paths.mjs` now exposes `sessionIdOfForkPath` and `decodeSegment` (the inverse of the host's `~XXXX` segment escaping), `handleForks` uses them and warns instead of staying silent when a fork path cannot be mapped, and the legacy flat `<mirrorDir>/<sessionId>/<file>` layout still maps when the last segment looks like a file. The byte-level mirror, merge, and encryption path is unchanged; no new dependencies.
|
|
13
|
+
|
|
8
14
|
## [0.2.10] - 2026-09-09
|
|
9
15
|
|
|
10
16
|
### Fixed
|
package/index.mjs
CHANGED
|
@@ -42,7 +42,12 @@ import {
|
|
|
42
42
|
messageOf,
|
|
43
43
|
registryUnavailable,
|
|
44
44
|
} from './lib/errors.mjs'
|
|
45
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
assertNestingSafe,
|
|
47
|
+
resolveRepoDir,
|
|
48
|
+
resolveSessionRoot,
|
|
49
|
+
sessionIdOfForkPath,
|
|
50
|
+
} from './lib/paths.mjs'
|
|
46
51
|
import { GitBackend } from './lib/git.mjs'
|
|
47
52
|
import { SyncEngine } from './lib/engine.mjs'
|
|
48
53
|
import { EncryptedBackend, encryptTree, decryptTree, mergeTrees } from './lib/encrypted.mjs'
|
|
@@ -660,13 +665,19 @@ export function apply(ctx, config = {}) {
|
|
|
660
665
|
/** fork 文件产生回调:尝试把冲突会话在会话层面 fork(安全时)。 */
|
|
661
666
|
function handleForks(forkPaths) {
|
|
662
667
|
const bySession = new Map()
|
|
668
|
+
let unmapped = 0
|
|
663
669
|
for (const forkPath of forkPaths) {
|
|
664
|
-
const
|
|
665
|
-
if (
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
bySession.set(parts[1], list)
|
|
670
|
+
const sessionId = sessionIdOfForkPath(forkPath)
|
|
671
|
+
if (sessionId === undefined) {
|
|
672
|
+
unmapped += 1
|
|
673
|
+
continue
|
|
669
674
|
}
|
|
675
|
+
const list = bySession.get(sessionId) ?? []
|
|
676
|
+
list.push(forkPath)
|
|
677
|
+
bySession.set(sessionId, list)
|
|
678
|
+
}
|
|
679
|
+
if (unmapped > 0) {
|
|
680
|
+
logger.warn(`sync: ${unmapped} fork path(s) outside the project/session layout were not mapped to a session-level fork (files preserved)`)
|
|
670
681
|
}
|
|
671
682
|
for (const [sessionId, paths] of bySession) {
|
|
672
683
|
const session = ctx.sessions.get(sessionId)
|
package/lib/paths.mjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// 或 containment 检查(路径越界 = PATH_UNSAFE 响亮失败,绝不静默)。
|
|
6
6
|
|
|
7
7
|
import path from 'node:path'
|
|
8
|
+
import { MIRROR_DIR } from './constants.mjs'
|
|
8
9
|
import { badConfig, pathUnsafe } from './errors.mjs'
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -81,6 +82,57 @@ export function assertRelPath(rel) {
|
|
|
81
82
|
return rel
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
/**
|
|
86
|
+
* 段是否形如文件名(含扩展名;排除空段与 `.`/`..`)。
|
|
87
|
+
* 用于区分旧扁平布局的 `<id>/<file>` 与新布局的 `<projectKey>/<sessionId>`。
|
|
88
|
+
* @param {string} segment - 单个路径段。
|
|
89
|
+
* @returns {boolean} 形如文件名为 true。
|
|
90
|
+
*/
|
|
91
|
+
function looksLikeFileSegment(segment) {
|
|
92
|
+
return segment.length > 0 && segment !== '.' && segment !== '..' && segment.includes('.')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 解码宿主 `encodeSegment` 的 `~XXXX` 转义(逆运算;宿主
|
|
97
|
+
* session-persistence-jsonl/src/format.ts:198-213)。无转义时原样返回;
|
|
98
|
+
* 宿主把 `~` 本身也转义成 `~007E`,故单遍替换即无损可逆。
|
|
99
|
+
* @param {string} segment - 已编码的单个路径段。
|
|
100
|
+
* @returns {string} 解码后的段。
|
|
101
|
+
*/
|
|
102
|
+
export function decodeSegment(segment) {
|
|
103
|
+
return segment.replace(/~([0-9A-Fa-f]{4})/gu, (_match, hex) => String.fromCharCode(parseInt(hex, 16)))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* fork 相对路径 → 会话 id。
|
|
108
|
+
*
|
|
109
|
+
* 宿主权威布局(0.1.5-alpha.1):<mirrorDir>/<projectKey>/<sessionId>/<file>,
|
|
110
|
+
* 其中 projectKey 由会话 cwd 计算(缺省 `_no-cwd`),sessionId 经宿主
|
|
111
|
+
* encodeSegment 转义成单个路径段(session-persistence-jsonl/src/format.ts:224-268)。
|
|
112
|
+
* 旧扁平布局 <mirrorDir>/<sessionId>/<file> 保留宽松回退(仅当末段形如文件名,
|
|
113
|
+
* 以不误吃新布局的 <projectKey>/<sessionId> 目录);其余形态(根级文件、目录、
|
|
114
|
+
* 空段/`..`、非镜像前缀)→ undefined。
|
|
115
|
+
* @param {string} forkPath - 镜像相对路径(POSIX 分隔)。
|
|
116
|
+
* @param {string} [mirrorDir] - 镜像目录名(默认 MIRROR_DIR)。
|
|
117
|
+
* @returns {string|undefined} 解码后的会话 id;无法映射时 undefined。
|
|
118
|
+
*/
|
|
119
|
+
export function sessionIdOfForkPath(forkPath, mirrorDir = MIRROR_DIR) {
|
|
120
|
+
if (typeof forkPath !== 'string' || forkPath.length === 0) return undefined
|
|
121
|
+
const parts = forkPath.split('/')
|
|
122
|
+
if (parts[0] !== mirrorDir) return undefined
|
|
123
|
+
if (parts.length >= 4) {
|
|
124
|
+
for (let index = 1; index < parts.length; index += 1) {
|
|
125
|
+
const segment = parts[index]
|
|
126
|
+
if (segment.length === 0 || segment === '.' || segment === '..') return undefined
|
|
127
|
+
}
|
|
128
|
+
return decodeSegment(parts[2])
|
|
129
|
+
}
|
|
130
|
+
if (parts.length === 3 && parts[1].length > 0 && looksLikeFileSegment(parts[2])) {
|
|
131
|
+
return decodeSegment(parts[1])
|
|
132
|
+
}
|
|
133
|
+
return undefined
|
|
134
|
+
}
|
|
135
|
+
|
|
84
136
|
/**
|
|
85
137
|
* 相对路径 → 工作树镜像路径(<repoDir>/sessions/<rel>)。
|
|
86
138
|
* @param {string} repoDir - 同步仓库根。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-sync",
|
|
3
3
|
"description": "Cross-device sync for DeepSeek Harness sessions: a dedicated git mirror of the session store, append-only three-way merge with keep-both + fork conflict resolution, /sync command, sync_pull/sync_push/sync_status tools, and configurable auto push/pull",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.11",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/PerryLink/dsh-session-sync.git"
|