dsh-timeback 0.7.6 → 0.7.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 +22 -2
- package/client.js +1724 -122
- package/docs/MARKET.md +2 -2
- package/index.js +16 -2
- package/package.json +1 -1
- package/src/notes.js +59 -4
- package/src/registry.js +40 -0
- package/src/service.js +35 -4
package/docs/MARKET.md
CHANGED
|
@@ -78,12 +78,12 @@ dshmarket;要让所有人的 dshmarket 搜到,必须走下一节的公共目
|
|
|
78
78
|
|
|
79
79
|
## 4. npm(已发布 0.6.0)
|
|
80
80
|
|
|
81
|
-
`dsh-timeback@0.7.
|
|
81
|
+
`dsh-timeback@0.7.8` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
|
|
82
82
|
用户可以直接安装/固定版本:
|
|
83
83
|
|
|
84
84
|
```bash
|
|
85
85
|
dsh plugin --profile web add dsh-timeback
|
|
86
|
-
dsh plugin --profile web add dsh-timeback@0.7.
|
|
86
|
+
dsh plugin --profile web add dsh-timeback@0.7.8
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
|
package/index.js
CHANGED
|
@@ -436,6 +436,7 @@ export function apply(ctx, rawConfig) {
|
|
|
436
436
|
id: typeof body.id === 'string' ? body.id : undefined,
|
|
437
437
|
title: typeof body.title === 'string' ? body.title : '',
|
|
438
438
|
body: typeof body.body === 'string' ? body.body : '',
|
|
439
|
+
kind: body.kind === 'doc' ? 'doc' : undefined,
|
|
439
440
|
sessionId: typeof body.sessionId === 'string' ? body.sessionId : undefined,
|
|
440
441
|
cwd: typeof body.cwd === 'string' ? body.cwd : undefined,
|
|
441
442
|
},
|
|
@@ -494,7 +495,17 @@ export function apply(ctx, rawConfig) {
|
|
|
494
495
|
return
|
|
495
496
|
}
|
|
496
497
|
const mode = action === 'restore-files' ? 'files-only' : body.mode === 'branch-only' ? 'branch-only' : 'branch-and-files'
|
|
497
|
-
writeJson(
|
|
498
|
+
writeJson(
|
|
499
|
+
res,
|
|
500
|
+
200,
|
|
501
|
+
await service.rewind({
|
|
502
|
+
sessionId: sessionId || undefined,
|
|
503
|
+
checkpointId,
|
|
504
|
+
mode,
|
|
505
|
+
...(typeof body.name === 'string' && body.name.trim() !== '' ? { name: body.name.trim().slice(0, 120) } : {}),
|
|
506
|
+
}),
|
|
507
|
+
req,
|
|
508
|
+
)
|
|
498
509
|
} catch (error) {
|
|
499
510
|
const status = error instanceof TimebackError ? 400 : 500
|
|
500
511
|
const payload = {
|
|
@@ -558,6 +569,7 @@ export function apply(ctx, rawConfig) {
|
|
|
558
569
|
id: { type: 'string', description: 'update/delete 的记录 id(nt-…)' },
|
|
559
570
|
title: { type: 'string', description: '记录标题(create/update,可选)' },
|
|
560
571
|
body: { type: 'string', description: '记录正文,Markdown 文本' },
|
|
572
|
+
kind: { type: 'string', enum: ['sticky', 'doc'], description: 'create 时可选:sticky 便签(默认)或 doc 完整 Markdown 文档页' },
|
|
561
573
|
sessionId: sessionIdParam,
|
|
562
574
|
},
|
|
563
575
|
['action'],
|
|
@@ -567,7 +579,7 @@ export function apply(ctx, rawConfig) {
|
|
|
567
579
|
return { ok: true, ...(await service.board({ sessionId: toolSessionId })), sessionId: toolSessionId ?? null }
|
|
568
580
|
}
|
|
569
581
|
if (args.action === 'create') {
|
|
570
|
-
return service.saveBoardNote({ title: args.title, body: args.body, sessionId: toolSessionId }, 'agent')
|
|
582
|
+
return service.saveBoardNote({ title: args.title, body: args.body, kind: args.kind === 'doc' ? 'doc' : 'sticky', sessionId: toolSessionId }, 'agent')
|
|
571
583
|
}
|
|
572
584
|
if (args.action === 'update') return service.saveBoardNote({ id: args.id, title: args.title, body: args.body, sessionId: toolSessionId }, 'agent')
|
|
573
585
|
if (args.action === 'delete') return service.deleteBoardNote(String(args.id ?? ''), { sessionId: toolSessionId })
|
|
@@ -588,6 +600,7 @@ export function apply(ctx, rawConfig) {
|
|
|
588
600
|
enum: ['branch-and-files', 'branch-only', 'files-only'],
|
|
589
601
|
description: 'branch-and-files:分支并恢复文件(默认);branch-only:只分支;files-only:只恢复文件、不新建会话',
|
|
590
602
|
},
|
|
603
|
+
name: { type: 'string', description: '分支会话的名称;省略时使用自动生成的名称' },
|
|
591
604
|
sessionId: sessionIdParam,
|
|
592
605
|
},
|
|
593
606
|
['checkpointId'],
|
|
@@ -596,6 +609,7 @@ export function apply(ctx, rawConfig) {
|
|
|
596
609
|
sessionId: resolveSessionId(args, exec),
|
|
597
610
|
checkpointId: String(args.checkpointId),
|
|
598
611
|
mode: args.mode,
|
|
612
|
+
...(typeof args.name === 'string' && args.name.trim() !== '' ? { name: args.name.trim().slice(0, 120) } : {}),
|
|
599
613
|
}),
|
|
600
614
|
),
|
|
601
615
|
),
|
package/package.json
CHANGED
package/src/notes.js
CHANGED
|
@@ -38,6 +38,7 @@ function normalizeEntry(input, now) {
|
|
|
38
38
|
title: clip(input?.title, TITLE_LIMIT).trim() || '未命名记录',
|
|
39
39
|
body: clip(input?.body, BODY_LIMIT),
|
|
40
40
|
source,
|
|
41
|
+
kind: input?.kind === 'doc' ? 'doc' : 'sticky',
|
|
41
42
|
sessionId: typeof input?.sessionId === 'string' && input.sessionId !== '' ? input.sessionId : null,
|
|
42
43
|
checkpointId: typeof input?.checkpointId === 'string' && input.checkpointId !== '' ? input.checkpointId : null,
|
|
43
44
|
workspace: typeof input?.workspace === 'string' && input.workspace !== '' ? input.workspace : null,
|
|
@@ -51,7 +52,7 @@ const BOARD_ANCHORS = new Set(['top', 'right', 'bottom', 'left'])
|
|
|
51
52
|
const MAX_EDGES = 200
|
|
52
53
|
|
|
53
54
|
function emptyCanvas() {
|
|
54
|
-
return { notes: {}, background: [], drawings: {}, edges: [] }
|
|
55
|
+
return { notes: {}, background: [], drawings: {}, edges: [], texts: [], windows: [] }
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
/** Clamp note-to-note connector edges. */
|
|
@@ -113,9 +114,10 @@ function normalizeCanvas(value) {
|
|
|
113
114
|
notes[id] = {
|
|
114
115
|
x: Math.round(Number(layout.x) || 0),
|
|
115
116
|
y: Math.round(Number(layout.y) || 0),
|
|
116
|
-
width: Math.min(640, Math.max(160, Math.round(Number(layout.width) || 232))),
|
|
117
|
-
height: Math.min(560, Math.max(120, Math.round(Number(layout.height) || 176))),
|
|
118
117
|
z: Math.round(Number(layout.z) || 0),
|
|
118
|
+
kind: layout.kind === 'doc' ? 'doc' : 'sticky',
|
|
119
|
+
width: Math.min(1200, Math.max(160, Math.round(Number(layout.width) || 232))),
|
|
120
|
+
height: Math.min(900, Math.max(120, Math.round(Number(layout.height) || 176))),
|
|
119
121
|
color: STROKE_COLORS.test(String(layout.color || '')) ? String(layout.color) : '#f0c36b',
|
|
120
122
|
}
|
|
121
123
|
}
|
|
@@ -127,7 +129,54 @@ function normalizeCanvas(value) {
|
|
|
127
129
|
if (normalized.length > 0) drawings[id] = normalized
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
|
-
|
|
132
|
+
const texts = []
|
|
133
|
+
if (Array.isArray(canvas.texts)) {
|
|
134
|
+
for (const [index, raw] of canvas.texts.slice(0, 200).entries()) {
|
|
135
|
+
if (!raw || typeof raw !== 'object') continue
|
|
136
|
+
const text = clip(raw.text, 4000)
|
|
137
|
+
if (text === '') continue
|
|
138
|
+
texts.push({
|
|
139
|
+
id: typeof raw.id === 'string' && raw.id !== '' ? raw.id : `tx-${index}`,
|
|
140
|
+
text,
|
|
141
|
+
x: Math.round(Number(raw.x) || 0),
|
|
142
|
+
y: Math.round(Number(raw.y) || 0),
|
|
143
|
+
width: Math.min(1200, Math.max(80, Math.round(Number(raw.width) || 320))),
|
|
144
|
+
color: /^#[0-9a-f]{6}$/i.test(String(raw.color || '')) ? String(raw.color).toLowerCase() : '#e6e6e6',
|
|
145
|
+
fontSize: Math.min(96, Math.max(8, Math.round(Number(raw.fontSize) || 18))),
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const windows = []
|
|
150
|
+
if (Array.isArray(canvas.windows)) {
|
|
151
|
+
for (const [index, raw] of canvas.windows.slice(0, 40).entries()) {
|
|
152
|
+
if (!raw || typeof raw !== 'object') continue
|
|
153
|
+
const kind = raw.kind === 'image' ? 'image' : raw.kind === 'table' ? 'table' : ''
|
|
154
|
+
if (kind === '') continue
|
|
155
|
+
const id = typeof raw.id === 'string' && raw.id !== '' ? raw.id : `win-${index}`
|
|
156
|
+
const base = {
|
|
157
|
+
id,
|
|
158
|
+
kind,
|
|
159
|
+
title: clip(raw.title, 200).trim() || (kind === 'table' ? '表格' : '图片'),
|
|
160
|
+
x: Math.round(Number(raw.x) || 0),
|
|
161
|
+
y: Math.round(Number(raw.y) || 0),
|
|
162
|
+
width: Math.min(1600, Math.max(160, Math.round(Number(raw.width) || (kind === 'image' ? 360 : 480)))),
|
|
163
|
+
height: Math.min(1200, Math.max(120, Math.round(Number(raw.height) || (kind === 'image' ? 260 : 260)))),
|
|
164
|
+
}
|
|
165
|
+
if (kind === 'table') {
|
|
166
|
+
const rows = []
|
|
167
|
+
for (const row of Array.isArray(raw.rows) ? raw.rows.slice(0, 50) : []) {
|
|
168
|
+
if (!Array.isArray(row)) continue
|
|
169
|
+
rows.push(row.slice(0, 20).map((cell) => clip(typeof cell === 'string' ? cell : String(cell ?? ''), 500)))
|
|
170
|
+
}
|
|
171
|
+
windows.push({ ...base, rows: rows.length > 0 ? rows : [['']] })
|
|
172
|
+
} else {
|
|
173
|
+
const src = typeof raw.src === 'string' ? raw.src : ''
|
|
174
|
+
if (!/^data:image\//i.test(src) || src.length > 3_000_000) continue
|
|
175
|
+
windows.push({ ...base, src, alt: clip(raw.alt, 300) })
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return { notes, background: normalizeStrokes(canvas.background), drawings, edges: normalizeEdges(canvas.edges), texts, windows }
|
|
131
180
|
}
|
|
132
181
|
|
|
133
182
|
/** Clone one board state without sharing references. */
|
|
@@ -143,6 +192,11 @@ function cloneBoard(board) {
|
|
|
143
192
|
Object.entries(board.canvas?.drawings ?? {}).map(([id, strokes]) => [id, strokes.map((stroke) => ({ ...stroke, points: stroke.points.map((point) => [...point]) }))]),
|
|
144
193
|
),
|
|
145
194
|
edges: (board.canvas?.edges ?? []).map((edge) => ({ ...edge, from: { ...edge.from }, to: { ...edge.to } })),
|
|
195
|
+
texts: (board.canvas?.texts ?? []).map((text) => ({ ...text })),
|
|
196
|
+
windows: (board.canvas?.windows ?? []).map((window) => ({
|
|
197
|
+
...window,
|
|
198
|
+
...(Array.isArray(window.rows) ? { rows: window.rows.map((row) => [...row]) } : {}),
|
|
199
|
+
})),
|
|
146
200
|
},
|
|
147
201
|
}
|
|
148
202
|
}
|
|
@@ -248,6 +302,7 @@ export class NotesStore {
|
|
|
248
302
|
if (!entry) throw new NotesError('记录不存在或已删除', 'notes/not-found')
|
|
249
303
|
if (patch.title !== undefined) entry.title = clip(patch.title, TITLE_LIMIT).trim() || '未命名记录'
|
|
250
304
|
if (patch.body !== undefined) entry.body = clip(patch.body, BODY_LIMIT)
|
|
305
|
+
if (patch.kind !== undefined) entry.kind = patch.kind === 'doc' ? 'doc' : 'sticky'
|
|
251
306
|
entry.updatedAt = this.now()
|
|
252
307
|
return { entry }
|
|
253
308
|
}, '更新记录')
|
package/src/registry.js
CHANGED
|
@@ -217,6 +217,46 @@ export class CheckpointRegistry {
|
|
|
217
217
|
return stored
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Insert historical checkpoints at a specific position (used when a pruned
|
|
222
|
+
* branch inherits the kept part of the original conversation).
|
|
223
|
+
* @param sessionId - target session.
|
|
224
|
+
* @param checkpoints - checkpoint data; ids are regenerated.
|
|
225
|
+
* @param beforeId - insert before this checkpoint id (or append).
|
|
226
|
+
* @returns {Promise<object[]>} stored checkpoints.
|
|
227
|
+
*/
|
|
228
|
+
async insertCheckpoints(sessionId, checkpoints, beforeId = null) {
|
|
229
|
+
await this.open()
|
|
230
|
+
const session = this.state.sessions[sessionId]
|
|
231
|
+
if (!session) throw new RegistryError(`未知会话:${sessionId}`, 'registry/session-unknown')
|
|
232
|
+
const stored = []
|
|
233
|
+
for (const checkpoint of Array.isArray(checkpoints) ? checkpoints : []) {
|
|
234
|
+
stored.push({
|
|
235
|
+
id: checkpoint.id ?? `cp-${this.uuid()}`,
|
|
236
|
+
turn: checkpoint.turn ?? null,
|
|
237
|
+
phase: checkpoint.phase ?? 'manual',
|
|
238
|
+
seq: Number.isSafeInteger(checkpoint.seq) ? checkpoint.seq : null,
|
|
239
|
+
createdAt: checkpoint.createdAt ?? this.now(),
|
|
240
|
+
label: checkpoint.label ?? null,
|
|
241
|
+
prompt: checkpoint.prompt ?? null,
|
|
242
|
+
snapshot: checkpoint.snapshot ?? null,
|
|
243
|
+
files: checkpoint.files ?? null,
|
|
244
|
+
note: normalizeNote(checkpoint.note),
|
|
245
|
+
boardVersion: Number.isSafeInteger(checkpoint.boardVersion) ? checkpoint.boardVersion : null,
|
|
246
|
+
error: checkpoint.error ?? null,
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
if (stored.length === 0) return []
|
|
250
|
+
const index = beforeId ? session.checkpoints.findIndex((checkpoint) => checkpoint.id === beforeId) : -1
|
|
251
|
+
if (index >= 0) session.checkpoints.splice(index, 0, ...stored)
|
|
252
|
+
else session.checkpoints.push(...stored)
|
|
253
|
+
const excess = session.checkpoints.length - this.maxCheckpoints
|
|
254
|
+
if (excess > 0) session.checkpoints.splice(0, excess)
|
|
255
|
+
session.updatedAt = this.now()
|
|
256
|
+
await this.flush()
|
|
257
|
+
return stored
|
|
258
|
+
}
|
|
259
|
+
|
|
220
260
|
/**
|
|
221
261
|
* Save the free-text note shown on one checkpoint card.
|
|
222
262
|
* @returns {Promise<object|undefined>} the updated checkpoint.
|
package/src/service.js
CHANGED
|
@@ -739,8 +739,17 @@ export class TimebackService {
|
|
|
739
739
|
forkAtSeq: checkpoint.seq,
|
|
740
740
|
forkCheckpointId: checkpoint.id,
|
|
741
741
|
})
|
|
742
|
-
|
|
743
|
-
|
|
742
|
+
const customName = typeof input.name === 'string' && input.name.trim() !== '' ? input.name.trim().slice(0, 120) : ''
|
|
743
|
+
if (customName) {
|
|
744
|
+
await this.registry.updateSession(childSessionId, { title: customName })
|
|
745
|
+
const childLive = this.liveSession(childSessionId)
|
|
746
|
+
if (childLive && this.sessionTitle?.rename) {
|
|
747
|
+
await this.sessionTitle.rename(childLive, customName).catch(() => {})
|
|
748
|
+
}
|
|
749
|
+
} else {
|
|
750
|
+
this.nameBranch(childSessionId, sessionId, checkpoint)
|
|
751
|
+
}
|
|
752
|
+
const inherited = await this.registry.addCheckpoint(childSessionId, {
|
|
744
753
|
turn: checkpoint.turn,
|
|
745
754
|
phase: 'inherited',
|
|
746
755
|
seq: checkpoint.seq,
|
|
@@ -750,6 +759,27 @@ export class TimebackService {
|
|
|
750
759
|
files: null,
|
|
751
760
|
boardVersion: checkpoint.boardVersion ?? null,
|
|
752
761
|
})
|
|
762
|
+
// A prune archives the source session; copy the kept part of its history
|
|
763
|
+
// into the replacement branch so "delete after" does not erase earlier
|
|
764
|
+
// turns from the timeback tree.
|
|
765
|
+
if (input.copyHistory === true) {
|
|
766
|
+
const kept = (entry) => {
|
|
767
|
+
if (entry.id === checkpoint.id || entry.phase === 'inherited') return false
|
|
768
|
+
if (Number.isInteger(entry.seq) && Number.isInteger(checkpoint.seq) && entry.seq < checkpoint.seq) return true
|
|
769
|
+
if (Number.isInteger(entry.turn) && Number.isInteger(checkpoint.turn) && entry.turn < checkpoint.turn) return true
|
|
770
|
+
// The first turn's before-checkpoint has a null seq (no boundary yet).
|
|
771
|
+
if (entry.turn === checkpoint.turn && entry.phase === 'before') return true
|
|
772
|
+
return false
|
|
773
|
+
}
|
|
774
|
+
const history = this.registry.checkpoints(sessionId).filter(kept)
|
|
775
|
+
if (history.length > 0) {
|
|
776
|
+
await this.registry.insertCheckpoints(
|
|
777
|
+
childSessionId,
|
|
778
|
+
history.map((entry) => ({ ...entry, id: undefined, lastEndSeq: entry.seq })),
|
|
779
|
+
inherited?.id,
|
|
780
|
+
)
|
|
781
|
+
}
|
|
782
|
+
}
|
|
753
783
|
}
|
|
754
784
|
let safety = null
|
|
755
785
|
let restore = null
|
|
@@ -942,7 +972,7 @@ export class TimebackService {
|
|
|
942
972
|
const body = typeof input.body === 'string' ? input.body : ''
|
|
943
973
|
if (id) {
|
|
944
974
|
try {
|
|
945
|
-
return { ok: true, ...(await notes.update(id, { title, body })) }
|
|
975
|
+
return { ok: true, ...(await notes.update(id, { title, body, ...(input.kind ? { kind: input.kind } : {}) })) }
|
|
946
976
|
} catch (error) {
|
|
947
977
|
if (error?.code === 'notes/not-found') throw new TimebackError('记录不存在或已删除', 'timeback/note-unknown')
|
|
948
978
|
throw error
|
|
@@ -954,6 +984,7 @@ export class TimebackService {
|
|
|
954
984
|
...(await notes.create({
|
|
955
985
|
title,
|
|
956
986
|
body,
|
|
987
|
+
kind: input.kind === 'doc' ? 'doc' : 'sticky',
|
|
957
988
|
source: source === 'agent' ? 'agent' : 'user',
|
|
958
989
|
sessionId: typeof input.sessionId === 'string' && input.sessionId !== '' ? input.sessionId : null,
|
|
959
990
|
workspace: typeof input.cwd === 'string' && input.cwd !== '' ? input.cwd : null,
|
|
@@ -1102,7 +1133,7 @@ export class TimebackService {
|
|
|
1102
1133
|
registeredChild.forkAtSeq === checkpoint.seq
|
|
1103
1134
|
let rewind = null
|
|
1104
1135
|
if (!childUsable) {
|
|
1105
|
-
rewind = await this.rewind({ sessionId, checkpointId: checkpoint.id, mode })
|
|
1136
|
+
rewind = await this.rewind({ sessionId, checkpointId: checkpoint.id, mode, copyHistory: true })
|
|
1106
1137
|
childSessionId = rewind.childSessionId
|
|
1107
1138
|
}
|
|
1108
1139
|
// The truncated branch replaces the old session, so it should look like the
|