dsh-synapse 0.5.7 → 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.
- package/README.md +45 -0
- package/app.js +915 -244
- package/browser-cache.js +286 -0
- package/client.js +5 -2
- package/docs/architecture.md +12 -2
- package/docs/en/README.md +16 -1
- package/docs/zh-CN/README.md +15 -0
- package/index.js +310 -264
- package/package.json +4 -2
- package/session-bodies.js +497 -0
- package/styles.css +82 -43
package/browser-cache.js
ADDED
|
@@ -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="
|
|
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('
|
|
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
|
}
|
package/docs/architecture.md
CHANGED
|
@@ -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`)
|
|
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
|
-
|
|
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
|
@@ -105,10 +105,19 @@ The canvas supports:
|
|
|
105
105
|
- Panning and zooming up to 4×.
|
|
106
106
|
- Dragging cards with persisted positions.
|
|
107
107
|
- Expanding or collapsing descendant conversation subtrees.
|
|
108
|
-
-
|
|
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.
|
|
109
110
|
- Smooth card scrolling and Markdown table rendering.
|
|
110
111
|
- Folding tool calls and results into the related assistant answer by `callId`.
|
|
111
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
|
+
|
|
112
121
|
The **Dialogue / Session Map** switch can be moved too:
|
|
113
122
|
|
|
114
123
|
- Drag it by the six-dot grip on its left edge; the position is remembered per browser.
|
|
@@ -118,6 +127,12 @@ The **Dialogue / Session Map** switch can be moved too:
|
|
|
118
127
|
|
|
119
128
|
## Recent changes
|
|
120
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
|
+
|
|
121
136
|
**0.5.6**
|
|
122
137
|
|
|
123
138
|
- The top switch is draggable, remembers where you left it, and resets on a double-click (new).
|
package/docs/zh-CN/README.md
CHANGED
|
@@ -105,10 +105,19 @@ dsh web --port 0
|
|
|
105
105
|
- 拖动画布和缩放视图(最高 4×)。
|
|
106
106
|
- 拖动卡片并自动保存位置。
|
|
107
107
|
- 展开或折叠后续对话子树。
|
|
108
|
+
- 切换「全工作区 / 聚焦会话」,只显示选中会话及其派生分支,保持当前视角与缩放。
|
|
108
109
|
- 一键定位当前会话。
|
|
109
110
|
- 卡片内部平滑滚动和 Markdown 表格渲染。
|
|
110
111
|
- 将工具调用和结果按 `callId` 折叠到对应助手回答中。
|
|
111
112
|
|
|
113
|
+
### 聚焦会话与折叠
|
|
114
|
+
|
|
115
|
+
地图默认显示「全工作区」。在侧栏选中会话后点击「聚焦会话」,只显示该会话的全部轮次和递归派生分支。侧栏仍列出所有会话;在聚焦模式中选择另一会话,会切换聚焦对象。选择子会话时,范围包含该子会话及其后代,不包含父会话和兄弟会话。
|
|
116
|
+
|
|
117
|
+
点击地图中的分支卡片会同步 DSH 当前会话并打开详情,保留原来的聚焦范围。「全工作区 / 聚焦会话」只切换卡片和连线的显隐,不移动镜头、不调整缩放、不改变卡片坐标;在聚焦模式下拖动画布或缩放后,退出也保持当前视角。需要把当前会话居中时,单独点击「定位」。
|
|
118
|
+
|
|
119
|
+
点击卡片右侧的 **−**,收起全部子卡片及后代,保留当前卡片;即使子卡片自己已经折叠,也会一起隐藏。点击 **+** 再展开,子卡片原有的折叠状态和手动位置保留。
|
|
120
|
+
|
|
112
121
|
顶部「对话 / 会话地图」开关也可以挪位置:
|
|
113
122
|
|
|
114
123
|
- 按住开关左侧的**六点手柄**拖动,鬆手即记忆(存在浏览器本地,按浏览器各自独立);
|
|
@@ -118,6 +127,12 @@ dsh web --port 0
|
|
|
118
127
|
|
|
119
128
|
## 最近更新
|
|
120
129
|
|
|
130
|
+
**0.5.8 · 2026-11-22**
|
|
131
|
+
|
|
132
|
+
- 新增聚焦会话视图,支持完整轮次及递归派生分支,侧栏保留全工作区会话。
|
|
133
|
+
- 全工作区与聚焦会话切换只改变显隐,保持当前镜头、缩放和卡片位置。
|
|
134
|
+
- 修复父卡片折叠后,已折叠的子卡片仍留在画布上的问题;再次展开父卡片时保留子卡片的折叠状态。
|
|
135
|
+
|
|
121
136
|
**0.5.6**
|
|
122
137
|
|
|
123
138
|
- 顶部开关可以拖动、记忆位置、双击复位(本次新增)。
|