@kabxx/dsh-session-move 0.1.0 → 0.1.2
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 +11 -7
- package/icon.svg +24 -8
- package/package.json +1 -1
- package/src/client.js +317 -15
- package/src/history-process.js +190 -0
- package/src/history-stream.js +483 -0
- package/src/history-worker.js +180 -0
- package/src/history.js +44 -0
- package/src/ledger.js +0 -20
- package/src/move.js +74 -42
- package/src/plan.js +22 -2
- package/src/platform-fs.js +11 -2
- package/src/recovery.js +21 -19
- package/src/sidebar.js +100 -25
- package/src/transaction.js +426 -84
- package/src/zstd-frame.js +87 -51
- package/src/inbox.js +0 -39
package/src/sidebar.js
CHANGED
|
@@ -1,41 +1,116 @@
|
|
|
1
|
+
import { inspectMoveHistory } from './history.js'
|
|
2
|
+
|
|
1
3
|
const original = Symbol.for('cordis.original')
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
function rowsFor({ lastSeq, summary }, cwd, moved) {
|
|
6
|
+
const row = (val) => ({ ver: 1, seq: lastSeq + Number(moved), val })
|
|
7
|
+
return {
|
|
8
|
+
title: row(summary.title),
|
|
9
|
+
workingDirectory: row(moved ? cwd : summary.workingDirectory),
|
|
10
|
+
agentPreset: row(summary.agentPreset ?? null),
|
|
11
|
+
sessionListMetadata: row(summary.sessionListMetadata),
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Snapshot live resident summaries before teardown so failed moves restore them without rescanning. */
|
|
16
|
+
export function captureLiveSummaries(ctx, writers) {
|
|
17
|
+
const captured = new Map()
|
|
18
|
+
const service = ctx.get('sessionController')
|
|
19
|
+
const list = (service?.[original] ?? service)?.listState
|
|
20
|
+
if (typeof list?.summaryFor !== 'function') return captured
|
|
21
|
+
for (const { session } of writers) {
|
|
22
|
+
try {
|
|
23
|
+
const summary = list.summaryFor(session)
|
|
24
|
+
captured.set(session.id, {
|
|
25
|
+
...summary,
|
|
26
|
+
agentAvailable: false,
|
|
27
|
+
running: false,
|
|
28
|
+
...(summary.projections === undefined ? {} : {
|
|
29
|
+
projections: { kind: 'cached', asOfSeq: summary.projections.asOfSeq, values: summary.projections.values },
|
|
30
|
+
}),
|
|
31
|
+
})
|
|
32
|
+
} catch (error) {
|
|
33
|
+
ctx.logger?.warn?.('Session move: could not capture live summary for "%s": %s', session.id, error)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return captured
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Update cold list rows from the write-locked cut without constructing a full Session. */
|
|
40
|
+
export async function refreshSessionSummaries(ctx, members, cuts, { restored, signal, allowScan = true } = {}) {
|
|
5
41
|
const service = ctx.get('sessionController')
|
|
6
42
|
if (!service) return true
|
|
7
|
-
//
|
|
43
|
+
// These methods are internal to the pinned DSH version. Partial checkpoint
|
|
44
|
+
// rows are valid: other projections still fold from the authoritative log.
|
|
8
45
|
const list = (service[original] ?? service).listState
|
|
9
|
-
|
|
10
|
-
const cache =
|
|
46
|
+
const injectedCache = ctx.get('sessionProjectionCache')
|
|
47
|
+
const cache = injectedCache?.[original] ?? injectedCache
|
|
11
48
|
let synced = true
|
|
12
49
|
|
|
13
|
-
for (const { id, cwd } of members) {
|
|
50
|
+
for (const { id, cwd, moved = false } of members) {
|
|
14
51
|
try {
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
52
|
+
const live = ctx.sessions.get(id)
|
|
53
|
+
if (live !== undefined) {
|
|
54
|
+
if (live.header.cwd !== cwd) throw new Error('Session header changed')
|
|
55
|
+
ctx.emit('api-session/added', list.summaryFor(live))
|
|
56
|
+
continue
|
|
57
|
+
}
|
|
58
|
+
const snapshot = await ctx.sessionPersistence.stat(id)
|
|
59
|
+
const header = snapshot?.header
|
|
60
|
+
if (header?.id !== id || header.cwd !== cwd || snapshot.formatStatus !== 'current'
|
|
61
|
+
|| snapshot.location?.kind !== 'jsonl') throw new Error('Session header changed')
|
|
62
|
+
const hasCut = Boolean(cuts?.has(id))
|
|
63
|
+
if (!hasCut && !moved && restored?.has(id)) {
|
|
64
|
+
const appearing = ctx.sessions.get(id)
|
|
65
|
+
if (appearing !== undefined) {
|
|
66
|
+
if (appearing.header.cwd !== cwd) throw new Error('Session header changed')
|
|
67
|
+
ctx.emit('api-session/added', list.summaryFor(appearing))
|
|
68
|
+
continue
|
|
23
69
|
}
|
|
24
|
-
session
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
70
|
+
ctx.emit('api-session/added', restored.get(id))
|
|
71
|
+
continue
|
|
72
|
+
}
|
|
73
|
+
if (!hasCut && !allowScan) {
|
|
74
|
+
if (typeof list?.summarizeCold !== 'function') throw new Error('Unsupported session summary interface')
|
|
75
|
+
const appearing = ctx.sessions.get(id)
|
|
76
|
+
if (appearing !== undefined) {
|
|
77
|
+
if (appearing.header.cwd !== cwd) throw new Error('Session header changed')
|
|
78
|
+
ctx.emit('api-session/added', list.summaryFor(appearing))
|
|
79
|
+
continue
|
|
80
|
+
}
|
|
81
|
+
ctx.emit('api-session/added', list.summarizeCold(snapshot))
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
const cut = hasCut ? cuts.get(id) : await inspectMoveHistory({ path: snapshot.location.path, id, cwd }, signal ? { signal } : undefined)
|
|
85
|
+
const rows = rowsFor(cut, cwd, moved && hasCut)
|
|
86
|
+
const keys = ctx.sessionProjections.summaryKeys()
|
|
87
|
+
const values = ctx.sessionProjections.viewCheckpoint(rows, keys)
|
|
88
|
+
const appearing = ctx.sessions.get(id)
|
|
89
|
+
if (appearing !== undefined) {
|
|
90
|
+
if (appearing.header.cwd !== cwd) throw new Error('Session header changed')
|
|
91
|
+
ctx.emit('api-session/added', list.summaryFor(appearing))
|
|
92
|
+
continue
|
|
28
93
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
94
|
+
if (cache && typeof cache.put === 'function') {
|
|
95
|
+
try {
|
|
96
|
+
await cache.put(id, { formatVersion: header.version, createdAt: header.createdAt, cwd,
|
|
97
|
+
isSeeded: header.isSeeded, inheritedEventCount: cut.inheritedEventCount }, rows)
|
|
98
|
+
} catch (error) {
|
|
33
99
|
ctx.logger?.warn?.('Session move: could not checkpoint "%s": %s', id, error)
|
|
34
100
|
}
|
|
35
101
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
102
|
+
if (typeof list?.summarizeCold !== 'function') throw new Error('Unsupported session summary interface')
|
|
103
|
+
const summary = list.summarizeCold(snapshot)
|
|
104
|
+
// The stock per-record backend may refuse some child IDs. Their live
|
|
105
|
+
// list event can still carry the same valid projection hints.
|
|
106
|
+
ctx.emit('api-session/added', {
|
|
107
|
+
...summary,
|
|
108
|
+
updatedAt: Math.max(header.createdAt, cut.summary.sessionListMetadata.lastPromptAt ?? 0),
|
|
109
|
+
blank: cut.summary.sessionListMetadata.blank,
|
|
110
|
+
...(Object.keys(values).length === 0 ? {} : {
|
|
111
|
+
projections: { kind: 'cached', asOfSeq: rows.title.seq, values },
|
|
112
|
+
}),
|
|
113
|
+
})
|
|
39
114
|
} catch (error) {
|
|
40
115
|
synced = false
|
|
41
116
|
ctx.logger?.warn?.('Session move: could not publish summary for "%s": %s', id, error)
|