dsh-timeback 0.7.7 → 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 +1535 -35
- package/docs/MARKET.md +2 -2
- package/index.js +16 -2
- package/package.json +1 -1
- package/src/notes.js +59 -4
- package/src/service.js +12 -2
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/service.js
CHANGED
|
@@ -739,7 +739,16 @@ export class TimebackService {
|
|
|
739
739
|
forkAtSeq: checkpoint.seq,
|
|
740
740
|
forkCheckpointId: checkpoint.id,
|
|
741
741
|
})
|
|
742
|
-
|
|
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
|
+
}
|
|
743
752
|
const inherited = await this.registry.addCheckpoint(childSessionId, {
|
|
744
753
|
turn: checkpoint.turn,
|
|
745
754
|
phase: 'inherited',
|
|
@@ -963,7 +972,7 @@ export class TimebackService {
|
|
|
963
972
|
const body = typeof input.body === 'string' ? input.body : ''
|
|
964
973
|
if (id) {
|
|
965
974
|
try {
|
|
966
|
-
return { ok: true, ...(await notes.update(id, { title, body })) }
|
|
975
|
+
return { ok: true, ...(await notes.update(id, { title, body, ...(input.kind ? { kind: input.kind } : {}) })) }
|
|
967
976
|
} catch (error) {
|
|
968
977
|
if (error?.code === 'notes/not-found') throw new TimebackError('记录不存在或已删除', 'timeback/note-unknown')
|
|
969
978
|
throw error
|
|
@@ -975,6 +984,7 @@ export class TimebackService {
|
|
|
975
984
|
...(await notes.create({
|
|
976
985
|
title,
|
|
977
986
|
body,
|
|
987
|
+
kind: input.kind === 'doc' ? 'doc' : 'sticky',
|
|
978
988
|
source: source === 'agent' ? 'agent' : 'user',
|
|
979
989
|
sessionId: typeof input.sessionId === 'string' && input.sessionId !== '' ? input.sessionId : null,
|
|
980
990
|
workspace: typeof input.cwd === 'string' && input.cwd !== '' ? input.cwd : null,
|