dsh-synapse 0.5.6 → 0.5.8

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,286 @@
1
+ // Browser-only helpers, with no dependency on DSH or a DOM. Byte accounting
2
+ // uses UTF-16 string storage plus object/key allowances, not exact heap size.
3
+ const SynapseCache = (() => {
4
+ const LIMITS = Object.freeze({
5
+ bodyBytes: 16 * 1024 * 1024, bodyEntries: 512,
6
+ markdownBytes: 4 * 1024 * 1024, markdownEntries: 256,
7
+ markdownEntryBytes: 512 * 1024, requests: 2, batch: 20, wanted: 256,
8
+ })
9
+ const textBytes = value => typeof value === 'string' ? value.length * 2 : 0
10
+ const messageKey = (threadId, seq) => `${threadId}:${seq}`
11
+
12
+ // A world-space grid keeps camera moves proportional to nearby regions,
13
+ // rather than to the number of cards in the entire conversation history.
14
+ class RegionIndex {
15
+ constructor(cellSize = 1024, width = 310, height = 276) {
16
+ this.cellSize = cellSize
17
+ this.width = width
18
+ this.height = height
19
+ this.cells = new Map()
20
+ this.keysById = new Map()
21
+ this.items = new Map()
22
+ }
23
+ cellKeys(bounds) {
24
+ const keys = []
25
+ const left = Math.floor(bounds.left / this.cellSize)
26
+ const right = Math.floor(bounds.right / this.cellSize)
27
+ const top = Math.floor(bounds.top / this.cellSize)
28
+ const bottom = Math.floor(bounds.bottom / this.cellSize)
29
+ if (![left, right, top, bottom].every(Number.isSafeInteger) || (right - left + 1) * (bottom - top + 1) > 65536) return keys
30
+ for (let x = left; x <= right; x++) {
31
+ for (let y = top; y <= bottom; y++) keys.push(`${x},${y}`)
32
+ }
33
+ return keys
34
+ }
35
+ set(item) {
36
+ this.delete(item.id)
37
+ const { x, y } = item.position
38
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return
39
+ const keys = this.cellKeys({ left: x, right: x + this.width, top: y, bottom: y + this.height })
40
+ for (const key of keys) {
41
+ if (!this.cells.has(key)) this.cells.set(key, new Set())
42
+ this.cells.get(key).add(item.id)
43
+ }
44
+ this.keysById.set(item.id, keys)
45
+ this.items.set(item.id, item)
46
+ }
47
+ delete(id) {
48
+ for (const key of this.keysById.get(id) ?? []) {
49
+ const cell = this.cells.get(key)
50
+ cell.delete(id)
51
+ if (cell.size === 0) this.cells.delete(key)
52
+ }
53
+ this.keysById.delete(id)
54
+ this.items.delete(id)
55
+ }
56
+ query(bounds) {
57
+ const ids = new Set()
58
+ const found = []
59
+ for (const key of this.cellKeys(bounds)) {
60
+ for (const id of this.cells.get(key) ?? []) {
61
+ if (ids.has(id)) continue
62
+ ids.add(id)
63
+ const item = this.items.get(id)
64
+ const { x, y } = item.position
65
+ if (x + this.width < bounds.left || x > bounds.right || y + this.height < bounds.top || y > bounds.bottom) continue
66
+ found.push(item)
67
+ }
68
+ }
69
+ return found
70
+ }
71
+ }
72
+
73
+ class ByteLru {
74
+ constructor(maxBytes, maxEntries) {
75
+ this.maxBytes = maxBytes
76
+ this.maxEntries = maxEntries
77
+ this.bytes = 0
78
+ this.entries = new Map()
79
+ }
80
+ get size() { return this.entries.size }
81
+ has(key) { return this.entries.has(key) }
82
+ peek(key) { return this.entries.get(key)?.value }
83
+ get(key) {
84
+ const entry = this.entries.get(key)
85
+ if (!entry) return undefined
86
+ this.entries.delete(key)
87
+ this.entries.set(key, entry)
88
+ return entry.value
89
+ }
90
+ set(key, value, size, owner) {
91
+ this.delete(key)
92
+ const bytes = size + textBytes(key) + 128
93
+ if (!Number.isFinite(bytes) || bytes > this.maxBytes || this.maxEntries <= 0) return false
94
+ while (this.entries.size >= this.maxEntries || this.bytes + bytes > this.maxBytes) this.delete(this.entries.keys().next().value)
95
+ this.entries.set(key, { value, bytes, owner })
96
+ this.bytes += bytes
97
+ return true
98
+ }
99
+ delete(key) {
100
+ const entry = this.entries.get(key)
101
+ if (entry) this.bytes -= entry.bytes
102
+ return this.entries.delete(key)
103
+ }
104
+ retainOwners(owners) {
105
+ for (const [key, entry] of this.entries) if (!owners.has(entry.owner)) this.delete(key)
106
+ }
107
+ clear() { this.entries.clear(); this.bytes = 0 }
108
+ }
109
+
110
+ function bodyBytes(payload) {
111
+ let bytes = 256
112
+ for (const field of ['text', 'reason']) bytes += textBytes(payload[field])
113
+ for (const entry of payload.process ?? []) {
114
+ bytes += 192
115
+ for (const field of ['callId', 'name', 'status', 'arguments', 'result', 'error']) bytes += textBytes(entry[field])
116
+ }
117
+ return bytes
118
+ }
119
+
120
+ class BodyCache {
121
+ constructor(maxBytes = LIMITS.bodyBytes, maxEntries = LIMITS.bodyEntries) {
122
+ this.lru = new ByteLru(maxBytes, maxEntries)
123
+ }
124
+ get bytes() { return this.lru.bytes }
125
+ get size() { return this.lru.size }
126
+ get(threadId, seq, revision) {
127
+ const key = messageKey(threadId, seq)
128
+ const entry = this.lru.peek(key)
129
+ if (entry && entry.revision !== revision) { this.lru.delete(key); return undefined }
130
+ return this.lru.get(key)?.payload
131
+ }
132
+ set(threadId, seq, revision, payload) {
133
+ return this.lru.set(messageKey(threadId, seq), { revision, payload }, bodyBytes(payload) + textBytes(revision), threadId)
134
+ }
135
+ retainThreads(ids) { this.lru.retainOwners(ids) }
136
+ clear() { this.lru.clear() }
137
+ }
138
+
139
+ /** Keep wanted/attempt/failure metadata bounded to the current screen.
140
+ * Failed or evicted wanted entries get one attempt per visit. This prevents
141
+ * an oversized viewport from fetching and evicting itself forever.
142
+ */
143
+ class BodyLoader {
144
+ constructor({ cache, request, onUpdate = () => {}, concurrency = LIMITS.requests, batch = LIMITS.batch, maxWanted = LIMITS.wanted }) {
145
+ this.cache = cache
146
+ this.request = request
147
+ this.onUpdate = onUpdate
148
+ this.concurrency = concurrency
149
+ this.batch = batch
150
+ this.maxWanted = maxWanted
151
+ this.wanted = new Map()
152
+ this.attempted = new Set()
153
+ this.failures = new Set()
154
+ this.jobs = new Set()
155
+ this.waiters = []
156
+ this.viewKey = null
157
+ }
158
+ sync(messages, viewKey = this.viewKey) {
159
+ if (viewKey !== this.viewKey) {
160
+ this.attempted.clear()
161
+ this.failures.clear()
162
+ this.viewKey = viewKey
163
+ }
164
+ const next = new Map()
165
+ for (const message of messages) {
166
+ if (next.size >= this.maxWanted) break
167
+ const key = messageKey(message.threadId, message.seq)
168
+ if (next.has(key)) continue
169
+ const previous = this.wanted.get(key)
170
+ const entry = previous?.revision === message.revision ? previous : { ...message, key }
171
+ entry.priority = message.priority
172
+ next.set(key, entry)
173
+ }
174
+ for (const [key, previous] of this.wanted) {
175
+ if (next.get(key) !== previous) { this.attempted.delete(key); this.failures.delete(key) }
176
+ }
177
+ this.wanted = next
178
+ for (const job of [...this.jobs]) if (job.entries.some(entry => !this.current(entry))) this.cancel(job)
179
+ // Opening the inspector may interrupt speculative nearby requests.
180
+ // Reserve a request slot for its missing body instead of waiting behind
181
+ // two background batches.
182
+ const urgent = [...next.values()].some(entry => entry.priority === 0 && this.cache.get(entry.threadId, entry.seq, entry.revision) === undefined
183
+ && !this.attempted.has(entry.key) && ![...this.jobs].some(job => job.entries.includes(entry)))
184
+ if (urgent && this.jobs.size >= this.concurrency) {
185
+ const background = [...this.jobs].find(job => job.entries.every(entry => entry.priority !== 0))
186
+ if (background) this.cancel(background)
187
+ }
188
+ for (const job of this.jobs) for (const entry of job.entries) this.attempted.add(entry.key)
189
+ this.pump()
190
+ }
191
+ current(entry) { return this.wanted.get(entry.key) === entry }
192
+ cancel(job) {
193
+ this.jobs.delete(job)
194
+ job.controller.abort()
195
+ for (const entry of job.entries) {
196
+ if (this.current(entry) && this.cache.get(entry.threadId, entry.seq, entry.revision) === undefined) this.attempted.delete(entry.key)
197
+ }
198
+ }
199
+ pause({ clearCache = false } = {}) {
200
+ this.wanted.clear()
201
+ this.attempted.clear()
202
+ this.failures.clear()
203
+ this.viewKey = null
204
+ for (const job of [...this.jobs]) this.cancel(job)
205
+ if (clearCache) this.cache.clear()
206
+ this.settleIdle()
207
+ }
208
+ retainThreads(ids) {
209
+ this.cache.retainThreads(ids)
210
+ this.sync([...this.wanted.values()].filter(entry => ids.has(entry.threadId)))
211
+ }
212
+ unavailable(threadId, seq, revision) {
213
+ const key = messageKey(threadId, seq)
214
+ return this.failures.has(key) || (this.attempted.has(key) && this.cache.get(threadId, seq, revision) === undefined && ![...this.jobs].some(job => job.entries.some(entry => entry.key === key)))
215
+ }
216
+ retry() {
217
+ for (const entry of this.wanted.values()) {
218
+ if (this.cache.get(entry.threadId, entry.seq, entry.revision) !== undefined) continue
219
+ if ([...this.jobs].some(job => job.entries.includes(entry))) continue
220
+ this.attempted.delete(entry.key)
221
+ this.failures.delete(entry.key)
222
+ }
223
+ this.pump()
224
+ }
225
+ pump() {
226
+ while (this.jobs.size < this.concurrency) {
227
+ const entries = []
228
+ for (const entry of this.wanted.values()) {
229
+ if (this.attempted.has(entry.key) || this.cache.get(entry.threadId, entry.seq, entry.revision) !== undefined) continue
230
+ if (entries.length > 0 && entries[0].threadId !== entry.threadId) continue
231
+ entries.push(entry)
232
+ if (entries.length === this.batch) break
233
+ }
234
+ if (entries.length === 0) break
235
+ const job = { entries, controller: new AbortController() }
236
+ for (const entry of entries) this.attempted.add(entry.key)
237
+ this.jobs.add(job)
238
+ void this.run(job)
239
+ }
240
+ this.settleIdle()
241
+ }
242
+ async run(job) {
243
+ let changed = false
244
+ try {
245
+ let cursor = 0
246
+ while (this.jobs.has(job) && !job.controller.signal.aborted) {
247
+ const threadId = job.entries[0].threadId
248
+ const seqs = job.entries.map(entry => entry.seq)
249
+ const response = await this.request(`/synapse/api/threads/${threadId}/full?seqs=${seqs.join(',')}&cursor=${cursor}&limit=${this.batch}`, job.controller.signal)
250
+ if (!this.jobs.has(job) || job.controller.signal.aborted) return
251
+ for (const [seq, payload] of Object.entries(response.messages ?? {})) {
252
+ const entry = job.entries.find(item => item.seq === Number(seq))
253
+ if (!entry || !this.current(entry) || payload === null || typeof payload !== 'object') continue
254
+ this.cache.set(threadId, entry.seq, entry.revision, payload)
255
+ changed = true
256
+ }
257
+ if (response.nextCursor === null || response.nextCursor === undefined) break
258
+ if (!Number.isSafeInteger(response.nextCursor) || response.nextCursor <= cursor || response.nextCursor >= seqs.length) throw new Error('正文分页游标无效')
259
+ cursor = response.nextCursor
260
+ }
261
+ for (const entry of job.entries) {
262
+ if (this.current(entry) && this.cache.get(entry.threadId, entry.seq, entry.revision) === undefined) { this.failures.add(entry.key); changed = true }
263
+ }
264
+ } catch {
265
+ if (this.jobs.has(job) && !job.controller.signal.aborted) {
266
+ for (const entry of job.entries) {
267
+ if (this.current(entry) && this.cache.get(entry.threadId, entry.seq, entry.revision) === undefined) { this.failures.add(entry.key); changed = true }
268
+ }
269
+ }
270
+ } finally {
271
+ const currentJob = this.jobs.delete(job)
272
+ this.pump()
273
+ if (currentJob && changed) this.onUpdate(job.entries)
274
+ }
275
+ }
276
+ idle() {
277
+ if (this.jobs.size === 0) return Promise.resolve()
278
+ return new Promise(resolve => this.waiters.push(resolve))
279
+ }
280
+ settleIdle() {
281
+ if (this.jobs.size === 0) for (const resolve of this.waiters.splice(0)) resolve()
282
+ }
283
+ }
284
+
285
+ return { LIMITS, RegionIndex, ByteLru, BodyCache, BodyLoader, textBytes }
286
+ })()
package/client.js CHANGED
@@ -117,7 +117,7 @@ window.__ModuleLoader__.load({
117
117
  document.head.append(style)
118
118
  const host = document.createElement('div')
119
119
  host.className = 'dsh-synapse-host'
120
- host.innerHTML = '<div class="dsh-synapse-switch" role="group" aria-label="视图切换"><span class="dsh-synapse-grip" role="button" tabindex="0" aria-label="拖动位置" title="拖动位置(双击复位,方向键微调)"><svg aria-hidden="true" viewBox="0 0 8 14"><circle cx="2" cy="2" r="1.3"/><circle cx="6" cy="2" r="1.3"/><circle cx="2" cy="7" r="1.3"/><circle cx="6" cy="7" r="1.3"/><circle cx="2" cy="12" r="1.3"/><circle cx="6" cy="12" r="1.3"/></svg></span><button type="button" data-view="dialog" class="active" aria-pressed="true">对话</button><button type="button" data-view="map" aria-pressed="false">会话地图</button></div><section class="dsh-synapse-overlay" hidden><iframe title="会话地图" src="/synapse/"></iframe></section>'
120
+ host.innerHTML = '<div class="dsh-synapse-switch" role="group" aria-label="视图切换"><span class="dsh-synapse-grip" role="button" tabindex="0" aria-label="拖动位置" title="拖动位置(双击复位,方向键微调)"><svg aria-hidden="true" viewBox="0 0 8 14"><circle cx="2" cy="2" r="1.3"/><circle cx="6" cy="2" r="1.3"/><circle cx="2" cy="7" r="1.3"/><circle cx="6" cy="7" r="1.3"/><circle cx="2" cy="12" r="1.3"/><circle cx="6" cy="12" r="1.3"/></svg></span><button type="button" data-view="dialog" class="active" aria-pressed="true">对话</button><button type="button" data-view="map" aria-pressed="false">会话地图</button></div><section class="dsh-synapse-overlay" hidden><iframe title="会话地图" src="synapse/"></iframe></section>'
121
121
  document.body.append(host)
122
122
  const switchEl = host.querySelector('.dsh-synapse-switch')
123
123
  // Two live instances (a bundle loaded twice, or a sibling that outlived a
@@ -228,6 +228,7 @@ window.__ModuleLoader__.load({
228
228
  overlay.classList.remove('is-opening')
229
229
  overlay.hidden = true
230
230
  setView('dialog')
231
+ send('synapse:map-closed')
231
232
  }
232
233
  const send = (type, payload) => { frame.contentWindow?.postMessage({ source: 'dsh-synapse', type, ...payload }, location.origin) }
233
234
  let syncQueued = false
@@ -326,7 +327,7 @@ window.__ModuleLoader__.load({
326
327
  const sessionIds = new Set(sessions.map(session => session.id))
327
328
  const removedSessionIds = [...knownSessionIds].filter(id => !sessionIds.has(id))
328
329
  knownSessionIds = sessionIds
329
- void fetch('/synapse/api/sessions/sync', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ sessions, removedSessionIds }) }).catch(() => {})
330
+ void fetch('synapse/api/sessions/sync', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ sessions, removedSessionIds }) }).catch(() => {})
330
331
  })
331
332
  }
332
333
  const syncTheme = () => {
@@ -375,6 +376,8 @@ window.__ModuleLoader__.load({
375
376
  if (event.data.type === 'synapse:close') return close()
376
377
  if (event.data.type === 'synapse:map-ready') return showMapOverlay()
377
378
  if (event.data.type === 'synapse:request-current') {
379
+ send(overlay.hidden ? 'synapse:map-closed' : 'synapse:map-visible')
380
+ publishLiveSessions()
378
381
  send('synapse:workspaces', { workspaces: workspaceSnapshot(ctx), archivedSessionIds: archivedSessionIds(ctx) })
379
382
  return send('synapse:current-session', { session: currentSession(ctx) })
380
383
  }
@@ -78,9 +78,19 @@ Each user question becomes a conversation card. The following assistant messages
78
78
 
79
79
  Only a turn a person typed becomes a card. The harness also writes its own `user/message` rows — the runtime-context snapshot, the skill catalogue `<system-reminder>` — and those carry a structured `data.source.kind`; injected kinds (`skill-catalog`, plus the runtime snapshot's text marker) are not projected, so they neither occupy a card nor steal the answer from the real question. Existing projections are pruned the same way when the store loads.
80
80
 
81
- Projected messages keep only a preview (280 characters), not the body. The body already lives in the DSH session log, and a workspace file full of copies is what made one workspace reach several megabytes and stall the canvas (issue #42). The canvas asks the Host for the bodies of the cards it actually mounts (`GET /synapse/api/threads/:id/full`), and the detail view asks for a whole thread at once; when a session is archived or gone from DSH the previews stay and the card is marked unavailable instead of rendering blank.
81
+ Projected messages keep only a preview (280 characters), not the body. The body already lives in the DSH session log, and a workspace file full of copies is what made one workspace reach several megabytes and stall the canvas (issue #42). The canvas asks the Host for the bodies of the cards it actually mounts (`GET /synapse/api/threads/:id/full`). The detail view renders at most 40 messages, initially on the latest page; opening a card selects the page containing its source sequence.
82
82
 
83
- Bodies returned by the detail fetch are capped at 200 000 characters (`MAX_BODY_CHARS`), while the preview stays at 280; a truncated body carries a marker so the card can say the rest lives in DSH.
83
+ `session-bodies.js` enforces body and log budgets (issue #54). The body API accepts up to 40 integer `seqs`, a non-negative `cursor`, and `limit=1..20` (default 20). With no selectors it pages the stored thread order; with selectors the cursor indexes matching messages in that order. Responses include `cursor`, `nextCursor` (null at completion), and `total`. The client requests batches of 20 and follows the response cursor, which can advance by fewer than 20 when the response budget is reached. Successful partial pages never mark an entire thread loaded.
84
+
85
+ Actual serialized UTF-8 JSON is capped at 512 KiB per response, 128 KiB per message, 64 KiB for text, and 8 KiB per tool field. Each message returns up to 12 process entries within a 64 KiB process budget, with truncation and omitted-entry indicators. Only requested sequences and their selected tool call IDs have bodies extracted. Nested tool content has depth and block-count guards. Missing or over-budget logs retain previews and display a notice with the existing DSH opening action.
86
+
87
+ Closed logs are read from a size-pinned file snapshot of at most 8 MiB compressed. Zstd frame boundaries are parsed structurally, including skippable frames and incomplete append tails; production decompression is asynchronous, capped at 8 MiB per frame and 32 MiB overall, with a 2 MiB JSONL line limit. Only bounded selected events are retained, and text is copied into independent backing allocations so short V8 slices cannot retain large JSON lines. The LRU cache has at most four entries and an 8 MiB conservative accounting budget (serialized size × 3 plus key and object allowance); this is an accounting limit, not an exact V8 heap measurement. Identical reads share a promise, with at most two readers active and sixteen distinct reads pending. Unrelated raw history is scanned under these limits but not cached. Workspace projection paging remains a later step.
88
+
89
+ `browser-cache.js` owns the frontend cache and request lifecycle. The body LRU has a 16 MiB accounting budget and at most 512 messages, including text, process payloads, revision strings and key/object allowances. The Markdown LRU has a 4 MiB budget and at most 256 entries; input keys and rendered HTML both count, entries larger than 512 KiB are not cached, and streaming partial replies bypass this cache. Browser accounting uses two bytes per UTF-16 code unit plus object allowances; these numbers are not an exact browser heap or DOM limit.
90
+
91
+ Retained canvas graph cards hold only previews. Hydrated cards are temporary rendering objects, so evicted bodies are not kept alive by the graph. Up to 256 currently wanted messages are tracked, with two concurrent requests and batches of 20. The loader follows byte-limited response cursors. Departing messages abort their requests; response acceptance and final cleanup check request identity as well as current wanted-message revision. Tool metadata changes invalidate earlier bodies. A canceled request neither becomes a failure nor interferes with a replacement request for the same sequence.
92
+
93
+ Workspace changes clear body/Markdown caches and graph references. Removed or archived threads lose their entries and outstanding requests; transient scroll, expansion, page and live-reply state is pruned. The bridge sends `synapse:map-closed` even though a hidden iframe does not receive a page visibility change. Closing the map, hiding the browser tab or unloading it aborts body requests and releases rendered body DOM; reopening keeps camera state and hydrates the current view. Already cached messages remain reusable across detail/canvas changes. Failures or visible entries evicted under memory pressure are attempted once per visit, so a large viewport cannot create a fetch/eviction loop; entering another detail/page can retry. Total workspace projection data and the currently rendered DOM are outside the cache budgets.
84
94
 
85
95
  Projection writes are coalesced during event bursts, and live updates reuse cached Markdown and patch the active card instead of rebuilding the complete canvas. Card coordinates remain visual metadata only and never determine conversation lineage.
86
96
 
package/docs/en/README.md CHANGED
@@ -17,23 +17,28 @@ DSH installs plugins per profile. Each profile keeps its own plugin list and `no
17
17
  | How you run DSH | Profile to use |
18
18
  |---|---|
19
19
  | Desktop app (DeepSeek Harness client) | `desktop` |
20
- | `dsh web` on the command line | `web` |
21
- | Both | Install once per profile |
20
+ | `dsh web` on the command line (if you keep that profile) | `web` |
22
21
 
23
22
  - Installing from the app's plugin page already targets the profile the app uses, so you do not pick one there.
24
- - **Quick self-check: if the "会话地图 / Session map" switch never appears, the plugin went into the other profile** — run the other command and install again.
23
+ - **Quick self-check: if the "会话地图 / Session map" switch never appears, the plugin went into the other profile** — install again with the other `--profile`.
25
24
  - A desktop install takes effect after **restarting the app**; a command-line install takes effect after restarting `dsh web` and refreshing the page.
26
25
 
27
26
  ## Installation
28
27
 
28
+ `dsh` is the launcher that ships with the DSH runtime, at `resources\runtime\cli\bin\dsh.cmd` inside the app directory. Check that it responds first:
29
+
30
+ ```powershell
31
+ dsh --version
32
+ ```
33
+
29
34
  ### Install from npm
30
35
 
31
36
  ```powershell
32
37
  # Desktop app
33
- corepack pnpm dsh plugin --profile desktop add dsh-synapse
38
+ dsh plugin --profile desktop add dsh-synapse
34
39
 
35
- # Command line (dsh web)
36
- corepack pnpm dsh plugin --profile web add dsh-synapse
40
+ # Command line (only if you keep a web profile)
41
+ dsh plugin --profile web add dsh-synapse
37
42
  ```
38
43
 
39
44
  The npm package ships prebuilt code, so no build-script permission is needed — the simplest install. GitHub and local-checkout routes below are alternatives.
@@ -41,7 +46,7 @@ The npm package ships prebuilt code, so no build-script permission is needed —
41
46
  ### Install from GitHub
42
47
 
43
48
  ```powershell
44
- corepack pnpm dsh plugin --profile web add github:liangmianya/dsh-synapse
49
+ dsh plugin --profile desktop add github:liangmianya/dsh-synapse
45
50
  ```
46
51
 
47
52
  GitHub installs run the package `prepare` script, which validates JavaScript syntax with `node --check`.
@@ -60,7 +65,7 @@ Use the complete key containing the tarball URL and commit, not the bare package
60
65
  ### Install a local checkout
61
66
 
62
67
  ```powershell
63
- corepack pnpm dsh plugin --profile web add link:E:\path\to\dsh-synapse
68
+ dsh plugin --profile desktop add link:E:\path\to\dsh-synapse
64
69
  ```
65
70
 
66
71
  The `link:` form references the local checkout directly and is recommended for development. In a normal run, restart the host (the desktop app or `dsh web`) and refresh the page after editing the plugin.
@@ -68,7 +73,7 @@ The `link:` form references the local checkout directly and is recommended for d
68
73
  ## Start DSH Web
69
74
 
70
75
  ```powershell
71
- corepack pnpm dsh web
76
+ dsh web
72
77
  ```
73
78
 
74
79
  Default address:
@@ -80,7 +85,7 @@ http://127.0.0.1:3080/
80
85
  Let DSH choose a free port when 3080 is occupied:
81
86
 
82
87
  ```powershell
83
- corepack pnpm dsh web --port 0
88
+ dsh web --port 0
84
89
  ```
85
90
 
86
91
  Open the top **Session Map** switch after startup. Do not run two `dsh web` processes that share the same profile.
@@ -100,10 +105,19 @@ The canvas supports:
100
105
  - Panning and zooming up to 4×.
101
106
  - Dragging cards with persisted positions.
102
107
  - Expanding or collapsing descendant conversation subtrees.
103
- - One-click focus on the current session.
108
+ - Showing only the selected session and its derived branches while keeping the current camera and zoom.
109
+ - One-click centering on the current session.
104
110
  - Smooth card scrolling and Markdown table rendering.
105
111
  - Folding tool calls and results into the related assistant answer by `callId`.
106
112
 
113
+ ### Session focus and subtree folding
114
+
115
+ The map starts in **全工作区 (Entire workspace)** mode. Select a session in the sidebar and click **聚焦会话 (Focus session)** to show every turn of that session and its recursively derived branches. The sidebar still lists all sessions. Selecting another sidebar session changes the focus root; selecting a child session includes that child and its descendants, excluding its parent and siblings.
116
+
117
+ Clicking a branch card activates its DSH session and opens its details while keeping the existing focus scope. Switching between Entire workspace and Focus session only changes card and connector visibility. It keeps the current camera, zoom and card coordinates, including any pan or zoom changes made while focused. Use **定位 (Locate)** separately when you want to center the current session.
118
+
119
+ A card's **−** button hides every descendant, including children that are already folded, while keeping the card itself visible. Its **+** button expands the subtree again, preserving each child's own fold state and manually dragged position.
120
+
107
121
  The **Dialogue / Session Map** switch can be moved too:
108
122
 
109
123
  - Drag it by the six-dot grip on its left edge; the position is remembered per browser.
@@ -113,6 +127,12 @@ The **Dialogue / Session Map** switch can be moved too:
113
127
 
114
128
  ## Recent changes
115
129
 
130
+ **0.5.8 · 2026-11-22**
131
+
132
+ - Added session focus with all turns and recursively derived branches, while keeping the entire workspace's session list in the sidebar.
133
+ - Switching the display scope only changes visibility and preserves the current camera, zoom and card positions.
134
+ - Fixed nested folding: folded children no longer remain visible when their parent is collapsed, and their own fold state is retained when the parent expands.
135
+
116
136
  **0.5.6**
117
137
 
118
138
  - The top switch is draggable, remembers where you left it, and resets on a double-click (new).
@@ -151,7 +171,7 @@ Add the actual host to `trustedHosts` when exposing DSH on a LAN.
151
171
  Remove the plugin:
152
172
 
153
173
  ```powershell
154
- corepack pnpm dsh plugin --profile web remove dsh-synapse
174
+ dsh plugin --profile web remove dsh-synapse
155
175
  ```
156
176
 
157
177
  `remove` deletes the dependency and profile activation layer but keeps canvas data. Reinstalling reuses and migrates the old data when necessary.
@@ -17,23 +17,28 @@ DSH 按 profile 分套安装插件:每套 profile 有自己的插件清单和
17
17
  | 你平时怎么用 DSH | 要装的 profile |
18
18
  |---|---|
19
19
  | 桌面 App(DeepSeek Harness 客户端) | `desktop` |
20
- | 命令行 `dsh web` / 浏览器访问 | `web` |
21
- | 两种都用 | 两套各装一次 |
20
+ | 命令行 `dsh web` / 浏览器访问(如果你自己也维护了这套) | `web` |
22
21
 
23
22
  - 从 App 内的插件页面安装时,App 会自动装进它自己用的那套,无需关心 profile。
24
- - **自检口诀:装完顶部看不到「会话地图」开关,就是装到另一套去了**,换成另一条命令再装一次即可。
23
+ - **自检口诀:装完顶部看不到「会话地图」开关,就是装到另一套去了**,把 `--profile` 换成另一套的名字再装一次即可。
25
24
  - 桌面 App 装完需要**重启 App**;命令行装的,重启 `dsh web` 并刷新页面。
26
25
 
27
26
  ## 安装
28
27
 
28
+ `dsh` 是 DSH 运行时自带的 launcher,位于 App 安装目录的 `resources\runtime\cli\bin\dsh.cmd`。先确认它能调用:
29
+
30
+ ```powershell
31
+ dsh --version
32
+ ```
33
+
29
34
  ### 从 npm 安装
30
35
 
31
36
  ```powershell
32
37
  # 桌面 App
33
- corepack pnpm dsh plugin --profile desktop add dsh-synapse
38
+ dsh plugin --profile desktop add dsh-synapse
34
39
 
35
- # 命令行 dsh web
36
- corepack pnpm dsh plugin --profile web add dsh-synapse
40
+ # 命令行形态(仅当你有对应的 web profile)
41
+ dsh plugin --profile web add dsh-synapse
37
42
  ```
38
43
 
39
44
  npm 包分发的是预构建产物,无需任何构建授权——最简单的安装方式。下方 GitHub 与本地 checkout 为备选。
@@ -41,7 +46,7 @@ npm 包分发的是预构建产物,无需任何构建授权——最简单的
41
46
  ### 从 GitHub 安装
42
47
 
43
48
  ```powershell
44
- corepack pnpm dsh plugin --profile web add github:liangmianya/dsh-synapse
49
+ dsh plugin --profile desktop add github:liangmianya/dsh-synapse
45
50
  ```
46
51
 
47
52
  GitHub 安装会运行本包的 `prepare` 脚本,通过 `node --check` 验证 JavaScript 语法。
@@ -60,7 +65,7 @@ allowBuilds:
60
65
  ### 本地开发安装
61
66
 
62
67
  ```powershell
63
- corepack pnpm dsh plugin --profile web add link:E:\path\to\dsh-synapse
68
+ dsh plugin --profile desktop add link:E:\path\to\dsh-synapse
64
69
  ```
65
70
 
66
71
  `link:` 会直接引用本地 checkout,适合开发和调试。普通运行模式下修改代码后,建议重启宿主(桌面 App 或 `dsh web`)并刷新页面。
@@ -68,7 +73,7 @@ corepack pnpm dsh plugin --profile web add link:E:\path\to\dsh-synapse
68
73
  ## 启动
69
74
 
70
75
  ```powershell
71
- corepack pnpm dsh web
76
+ dsh web
72
77
  ```
73
78
 
74
79
  默认地址:
@@ -80,7 +85,7 @@ http://127.0.0.1:3080/
80
85
  如果 3080 被占用,可以让 DSH 自动选择端口:
81
86
 
82
87
  ```powershell
83
- corepack pnpm dsh web --port 0
88
+ dsh web --port 0
84
89
  ```
85
90
 
86
91
  启动后点击顶部“会话地图”进入 Synapse。不要同时运行两个共享同一 profile 的 `dsh web` 实例。
@@ -100,10 +105,19 @@ corepack pnpm dsh web --port 0
100
105
  - 拖动画布和缩放视图(最高 4×)。
101
106
  - 拖动卡片并自动保存位置。
102
107
  - 展开或折叠后续对话子树。
108
+ - 切换「全工作区 / 聚焦会话」,只显示选中会话及其派生分支,保持当前视角与缩放。
103
109
  - 一键定位当前会话。
104
110
  - 卡片内部平滑滚动和 Markdown 表格渲染。
105
111
  - 将工具调用和结果按 `callId` 折叠到对应助手回答中。
106
112
 
113
+ ### 聚焦会话与折叠
114
+
115
+ 地图默认显示「全工作区」。在侧栏选中会话后点击「聚焦会话」,只显示该会话的全部轮次和递归派生分支。侧栏仍列出所有会话;在聚焦模式中选择另一会话,会切换聚焦对象。选择子会话时,范围包含该子会话及其后代,不包含父会话和兄弟会话。
116
+
117
+ 点击地图中的分支卡片会同步 DSH 当前会话并打开详情,保留原来的聚焦范围。「全工作区 / 聚焦会话」只切换卡片和连线的显隐,不移动镜头、不调整缩放、不改变卡片坐标;在聚焦模式下拖动画布或缩放后,退出也保持当前视角。需要把当前会话居中时,单独点击「定位」。
118
+
119
+ 点击卡片右侧的 **−**,收起全部子卡片及后代,保留当前卡片;即使子卡片自己已经折叠,也会一起隐藏。点击 **+** 再展开,子卡片原有的折叠状态和手动位置保留。
120
+
107
121
  顶部「对话 / 会话地图」开关也可以挪位置:
108
122
 
109
123
  - 按住开关左侧的**六点手柄**拖动,鬆手即记忆(存在浏览器本地,按浏览器各自独立);
@@ -113,6 +127,12 @@ corepack pnpm dsh web --port 0
113
127
 
114
128
  ## 最近更新
115
129
 
130
+ **0.5.8 · 2026-11-22**
131
+
132
+ - 新增聚焦会话视图,支持完整轮次及递归派生分支,侧栏保留全工作区会话。
133
+ - 全工作区与聚焦会话切换只改变显隐,保持当前镜头、缩放和卡片位置。
134
+ - 修复父卡片折叠后,已折叠的子卡片仍留在画布上的问题;再次展开父卡片时保留子卡片的折叠状态。
135
+
116
136
  **0.5.6**
117
137
 
118
138
  - 顶部开关可以拖动、记忆位置、双击复位(本次新增)。
@@ -151,7 +171,7 @@ corepack pnpm dsh web --port 0
151
171
  卸载插件:
152
172
 
153
173
  ```powershell
154
- corepack pnpm dsh plugin --profile web remove dsh-synapse
174
+ dsh plugin --profile web remove dsh-synapse
155
175
  ```
156
176
 
157
177
  `remove` 只移除插件依赖和 profile 激活层,不会删除画布数据。重新安装后,旧数据会继续使用并按需迁移。