dsh-timeback 0.7.5 → 0.7.7
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 -5
- package/client.js +246 -103
- package/docs/MARKET.md +2 -2
- package/docs/PUBLISHING.md +7 -1
- package/index.js +39 -11
- package/package.json +1 -1
- package/src/registry.js +40 -0
- package/src/service.js +125 -23
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.7` 已发布到官方 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.7
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
|
package/docs/PUBLISHING.md
CHANGED
|
@@ -207,7 +207,7 @@ git tag v0.6.2 && git push origin v0.6.2
|
|
|
207
207
|
|
|
208
208
|
## 6. 发布前检查清单
|
|
209
209
|
|
|
210
|
-
- [ ] `node --test test/*.test.js` 全绿(当前
|
|
210
|
+
- [ ] `node --test test/*.test.js` 全绿(当前 65 个)
|
|
211
211
|
- [ ] `package.json` 的 `version` 与 `client.js` 里的 `BUILD` 一致
|
|
212
212
|
- [ ] `npm pack --dry-run` 里包含 `index.js`、`client.js`、`src/`、`locale/`、`icon.svg`、`cordis.patch.yml`
|
|
213
213
|
- [ ] `LICENSE`、`ACKNOWLEDGEMENTS.md`、`README.md` 是当前行为(记录按工作区开关、删除=截断分支+归档)
|
|
@@ -221,4 +221,10 @@ git tag v0.6.2 && git push origin v0.6.2
|
|
|
221
221
|
- **安装后插件没有 Host 行**:检查仓库根是否还有 `package.json` 的 `dsh.bundle.patch` 和 `cordis.patch.yml`;
|
|
222
222
|
- **`engines.dsh` 不匹配**:DSH 安装时会拒绝;用 `>=0.2.2-rc.1 <0.3.0-0` 覆盖当前 rc 系列,升级 DSH 大版本时同步调整;
|
|
223
223
|
- **工作区默认不记录**:这是设计(隐私);用户需在面板/工作区菜单/新会话行勾选;
|
|
224
|
+
- **发布后市场要等 24 小时才显示可更新**:这是 pnpm 11/12 的供应链保护 `minimumReleaseAge`,默认 1440 分钟(24h);dshmarket 会把过新的版本先标记为“等待”。管理员可在 profile 的 `pnpm-workspace.yaml` 放宽,例如 `minimumReleaseAge: 0`,或只豁免本插件:
|
|
225
|
+
```yaml
|
|
226
|
+
minimumReleaseAgeExclude:
|
|
227
|
+
- dsh-timeback
|
|
228
|
+
```
|
|
229
|
+
Desktop 版可能通过环境变量 `pnpm_config_minimum_release_age` 强制该窗口,需在 Desktop 设置/环境里调整。
|
|
224
230
|
- **“删除后续”不是物理删除**:DSH 会话日志 append-only,本插件用“创建截断分支 + 归档旧会话”实现,旧会话可在 DSH 侧栏归档列表恢复。
|
package/index.js
CHANGED
|
@@ -315,7 +315,9 @@ export function apply(ctx, rawConfig) {
|
|
|
315
315
|
return
|
|
316
316
|
}
|
|
317
317
|
if (pathname === `${config.routePath}/api/notes`) {
|
|
318
|
-
|
|
318
|
+
const sessionId = url.searchParams.get('session') ?? undefined
|
|
319
|
+
const cwd = url.searchParams.get('cwd') ?? undefined
|
|
320
|
+
writeJson(res, 200, { ok: true, board: await service.board({ sessionId, cwd }) }, req)
|
|
319
321
|
return
|
|
320
322
|
}
|
|
321
323
|
if (pathname === `${config.routePath}/api/tree`) {
|
|
@@ -399,11 +401,30 @@ export function apply(ctx, rawConfig) {
|
|
|
399
401
|
return
|
|
400
402
|
}
|
|
401
403
|
if (action === 'board-canvas') {
|
|
402
|
-
writeJson(
|
|
404
|
+
writeJson(
|
|
405
|
+
res,
|
|
406
|
+
200,
|
|
407
|
+
await service.saveBoardCanvas(body.canvas ?? {}, {
|
|
408
|
+
sessionId: typeof body.sessionId === 'string' && body.sessionId !== '' ? body.sessionId : undefined,
|
|
409
|
+
cwd: typeof body.cwd === 'string' && body.cwd !== '' ? body.cwd : undefined,
|
|
410
|
+
}),
|
|
411
|
+
req,
|
|
412
|
+
)
|
|
403
413
|
return
|
|
404
414
|
}
|
|
405
415
|
if (action === 'notes-list') {
|
|
406
|
-
writeJson(
|
|
416
|
+
writeJson(
|
|
417
|
+
res,
|
|
418
|
+
200,
|
|
419
|
+
{
|
|
420
|
+
ok: true,
|
|
421
|
+
board: await service.board({
|
|
422
|
+
sessionId: typeof body.sessionId === 'string' && body.sessionId !== '' ? body.sessionId : undefined,
|
|
423
|
+
cwd: typeof body.cwd === 'string' && body.cwd !== '' ? body.cwd : undefined,
|
|
424
|
+
}),
|
|
425
|
+
},
|
|
426
|
+
req,
|
|
427
|
+
)
|
|
407
428
|
return
|
|
408
429
|
}
|
|
409
430
|
if (action === 'note-save') {
|
|
@@ -425,7 +446,15 @@ export function apply(ctx, rawConfig) {
|
|
|
425
446
|
return
|
|
426
447
|
}
|
|
427
448
|
if (action === 'note-delete') {
|
|
428
|
-
writeJson(
|
|
449
|
+
writeJson(
|
|
450
|
+
res,
|
|
451
|
+
200,
|
|
452
|
+
await service.deleteBoardNote(typeof body.id === 'string' ? body.id : '', {
|
|
453
|
+
sessionId: typeof body.sessionId === 'string' && body.sessionId !== '' ? body.sessionId : undefined,
|
|
454
|
+
cwd: typeof body.cwd === 'string' && body.cwd !== '' ? body.cwd : undefined,
|
|
455
|
+
}),
|
|
456
|
+
req,
|
|
457
|
+
)
|
|
429
458
|
return
|
|
430
459
|
}
|
|
431
460
|
if (action === 'card-note') {
|
|
@@ -523,7 +552,7 @@ export function apply(ctx, rawConfig) {
|
|
|
523
552
|
ctx.tools.register(
|
|
524
553
|
tool(
|
|
525
554
|
'timeback_note',
|
|
526
|
-
'
|
|
555
|
+
'在时间回溯的 Markdown 记录板上读写记录。记录板按工作区隔离:不同工作区/目录各有自己的记录板,同一工作区的所有会话共享;回溯到某个检查点时,记录板也会一起恢复到该检查点时的状态。action=list 查看;create 新建(title/body,body 为 Markdown);update 修改(id/title/body);delete 删除(id)。用户让你记录笔记、决策、进展或结论时使用它。',
|
|
527
556
|
{
|
|
528
557
|
action: { type: 'string', enum: ['list', 'create', 'update', 'delete'], description: 'list/create/update/delete' },
|
|
529
558
|
id: { type: 'string', description: 'update/delete 的记录 id(nt-…)' },
|
|
@@ -533,16 +562,15 @@ export function apply(ctx, rawConfig) {
|
|
|
533
562
|
},
|
|
534
563
|
['action'],
|
|
535
564
|
async (args, exec) => {
|
|
565
|
+
const toolSessionId = typeof args.sessionId === 'string' && args.sessionId !== '' ? args.sessionId : exec?.agent?.session?.id
|
|
536
566
|
if (args.action === 'list') {
|
|
537
|
-
|
|
538
|
-
return { ok: true, ...(await service.board()), sessionId: sessionId ?? null }
|
|
567
|
+
return { ok: true, ...(await service.board({ sessionId: toolSessionId })), sessionId: toolSessionId ?? null }
|
|
539
568
|
}
|
|
540
569
|
if (args.action === 'create') {
|
|
541
|
-
|
|
542
|
-
return service.saveBoardNote({ title: args.title, body: args.body, sessionId }, 'agent')
|
|
570
|
+
return service.saveBoardNote({ title: args.title, body: args.body, sessionId: toolSessionId }, 'agent')
|
|
543
571
|
}
|
|
544
|
-
if (args.action === 'update') return service.saveBoardNote({ id: args.id, title: args.title, body: args.body }, 'agent')
|
|
545
|
-
if (args.action === 'delete') return service.deleteBoardNote(String(args.id ?? ''))
|
|
572
|
+
if (args.action === 'update') return service.saveBoardNote({ id: args.id, title: args.title, body: args.body, sessionId: toolSessionId }, 'agent')
|
|
573
|
+
if (args.action === 'delete') return service.deleteBoardNote(String(args.id ?? ''), { sessionId: toolSessionId })
|
|
546
574
|
throw new TimebackError(`未知操作:${String(args.action)}`, 'timeback/action-unknown')
|
|
547
575
|
},
|
|
548
576
|
),
|
package/package.json
CHANGED
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
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
* event sequence numbers; nothing here appends Session events.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { randomUUID } from 'node:crypto'
|
|
11
|
+
import { createHash, randomUUID } from 'node:crypto'
|
|
12
12
|
import { promises as fs } from 'node:fs'
|
|
13
13
|
import path from 'node:path'
|
|
14
|
+
import { NotesStore } from './notes.js'
|
|
14
15
|
import { workspaceContains, workspaceKey } from './registry.js'
|
|
15
16
|
|
|
16
17
|
/** A user-facing operation failure. */
|
|
@@ -73,6 +74,76 @@ export class TimebackService {
|
|
|
73
74
|
this.sessionTitle = options.sessionTitle ?? null
|
|
74
75
|
this.workspaceRegistry = options.workspaceRegistry ?? null
|
|
75
76
|
this.notes = options.notes ?? null
|
|
77
|
+
this.scopedNotes = new Map()
|
|
78
|
+
this.notesInit = Promise.resolve()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Notes board for one workspace directory (each workspace gets its own board).
|
|
83
|
+
* The legacy global board is migrated into the first workspace that asks for
|
|
84
|
+
* a board; every other workspace starts empty.
|
|
85
|
+
* @param cwd - canonical workspace directory, or null for the legacy global board.
|
|
86
|
+
* @returns {Promise<NotesStore|null>}
|
|
87
|
+
*/
|
|
88
|
+
async notesFor(cwd) {
|
|
89
|
+
if (!this.notes) return null
|
|
90
|
+
if (!cwd) return this.openNotes(this.notes)
|
|
91
|
+
const canonical = await this.canonicalDir(cwd)
|
|
92
|
+
const id = createHash('sha1').update(canonical).digest('hex').slice(0, 16)
|
|
93
|
+
const cached = this.scopedNotes.get(id)
|
|
94
|
+
if (cached) return this.openNotes(cached)
|
|
95
|
+
const dir = path.join(this.config.dataDir, 'boards', id)
|
|
96
|
+
this.notesInit = this.notesInit.then(async () => {
|
|
97
|
+
try {
|
|
98
|
+
await fs.access(path.join(dir, 'notes.json'))
|
|
99
|
+
return
|
|
100
|
+
} catch {
|
|
101
|
+
// First access to this workspace's board.
|
|
102
|
+
}
|
|
103
|
+
await fs.mkdir(dir, { recursive: true, mode: 0o700 })
|
|
104
|
+
const marker = path.join(this.config.dataDir, 'boards', '.legacy-copied')
|
|
105
|
+
let copied = false
|
|
106
|
+
try {
|
|
107
|
+
await fs.access(marker)
|
|
108
|
+
copied = true
|
|
109
|
+
} catch {
|
|
110
|
+
copied = false
|
|
111
|
+
}
|
|
112
|
+
if (!copied) {
|
|
113
|
+
try {
|
|
114
|
+
await fs.copyFile(this.notes.file, path.join(dir, 'notes.json'))
|
|
115
|
+
await fs.cp(this.notes.historyDir, path.join(dir, 'notes-history'), { recursive: true }).catch(() => {})
|
|
116
|
+
} catch {
|
|
117
|
+
// No legacy board, or it could not be copied: start empty.
|
|
118
|
+
}
|
|
119
|
+
await fs.writeFile(marker, new Date().toISOString(), 'utf8').catch(() => {})
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
await this.notesInit
|
|
123
|
+
const raced = this.scopedNotes.get(id)
|
|
124
|
+
if (raced) return this.openNotes(raced)
|
|
125
|
+
const store = new NotesStore({ dataDir: dir, logger: this.logger })
|
|
126
|
+
await store.open()
|
|
127
|
+
this.scopedNotes.set(id, store)
|
|
128
|
+
return store
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async openNotes(store) {
|
|
132
|
+
await store.open()
|
|
133
|
+
return store
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Notes board selected by an explicit session/cwd (legacy board when absent). */
|
|
137
|
+
async notesForInput(input = {}) {
|
|
138
|
+
if (!input || (!input.cwd && !input.sessionId)) return this.notesFor(null)
|
|
139
|
+
const cwd = await this.resolveWorkspace(input)
|
|
140
|
+
return this.notesFor(cwd)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Current board version of the workspace a session/cwd belongs to. */
|
|
144
|
+
async notesVersionFor(cwd) {
|
|
145
|
+
const notes = await this.notesFor(cwd)
|
|
146
|
+
return notes?.version ?? null
|
|
76
147
|
}
|
|
77
148
|
|
|
78
149
|
/** Prepare persistent state and probe git availability. */
|
|
@@ -374,7 +445,7 @@ export class TimebackService {
|
|
|
374
445
|
prompt: record.prompt,
|
|
375
446
|
snapshot: after.snapshot,
|
|
376
447
|
files: after.files,
|
|
377
|
-
boardVersion:
|
|
448
|
+
boardVersion: after.boardVersion ?? null,
|
|
378
449
|
lastEndSeq: seq,
|
|
379
450
|
})
|
|
380
451
|
record.lastTree = checkpoint?.snapshot?.tree ?? record.lastTree
|
|
@@ -397,7 +468,6 @@ export class TimebackService {
|
|
|
397
468
|
}
|
|
398
469
|
}
|
|
399
470
|
if (!record.recording) return null
|
|
400
|
-
await this.notes?.open?.()
|
|
401
471
|
if (record.afterSnapshot) return record.afterSnapshot
|
|
402
472
|
if (record.afterPromise) return record.afterPromise
|
|
403
473
|
record.afterPromise = (async () => {
|
|
@@ -420,6 +490,7 @@ export class TimebackService {
|
|
|
420
490
|
checkpointId,
|
|
421
491
|
snapshot: { tree: snapshot.tree, cwd: snapshot.cwd, repoId: snapshot.repoId, excludePaths: selection.excludePaths },
|
|
422
492
|
files: snapshot.files,
|
|
493
|
+
boardVersion: await this.notesVersionFor(cwd),
|
|
423
494
|
}
|
|
424
495
|
record.afterSnapshot = result
|
|
425
496
|
return result
|
|
@@ -435,7 +506,6 @@ export class TimebackService {
|
|
|
435
506
|
* @returns {Promise<object>} the stored checkpoint.
|
|
436
507
|
*/
|
|
437
508
|
async capture(input) {
|
|
438
|
-
await this.notes?.open?.()
|
|
439
509
|
const sessionId = String(input.session.id)
|
|
440
510
|
await this.registry.ensureSession({ sessionId, cwd: input.cwd })
|
|
441
511
|
const checkpointId = `cp-${randomUUID()}`
|
|
@@ -462,7 +532,7 @@ export class TimebackService {
|
|
|
462
532
|
prompt: input.prompt,
|
|
463
533
|
snapshot: { tree: snapshot.tree, cwd: snapshot.cwd, repoId: snapshot.repoId, excludePaths: selection.excludePaths },
|
|
464
534
|
files: snapshot.files,
|
|
465
|
-
boardVersion: this.
|
|
535
|
+
boardVersion: await this.notesVersionFor(input.cwd),
|
|
466
536
|
})
|
|
467
537
|
return checkpoint
|
|
468
538
|
}
|
|
@@ -611,7 +681,7 @@ export class TimebackService {
|
|
|
611
681
|
dataDir: this.config.dataDir,
|
|
612
682
|
currentSessionId,
|
|
613
683
|
rootSessionId: root.id,
|
|
614
|
-
boardVersion: this.
|
|
684
|
+
boardVersion: await this.notesVersionFor(currentCwd),
|
|
615
685
|
workspace,
|
|
616
686
|
sessions,
|
|
617
687
|
limits: {
|
|
@@ -670,7 +740,7 @@ export class TimebackService {
|
|
|
670
740
|
forkCheckpointId: checkpoint.id,
|
|
671
741
|
})
|
|
672
742
|
this.nameBranch(childSessionId, sessionId, checkpoint)
|
|
673
|
-
await this.registry.addCheckpoint(childSessionId, {
|
|
743
|
+
const inherited = await this.registry.addCheckpoint(childSessionId, {
|
|
674
744
|
turn: checkpoint.turn,
|
|
675
745
|
phase: 'inherited',
|
|
676
746
|
seq: checkpoint.seq,
|
|
@@ -680,6 +750,27 @@ export class TimebackService {
|
|
|
680
750
|
files: null,
|
|
681
751
|
boardVersion: checkpoint.boardVersion ?? null,
|
|
682
752
|
})
|
|
753
|
+
// A prune archives the source session; copy the kept part of its history
|
|
754
|
+
// into the replacement branch so "delete after" does not erase earlier
|
|
755
|
+
// turns from the timeback tree.
|
|
756
|
+
if (input.copyHistory === true) {
|
|
757
|
+
const kept = (entry) => {
|
|
758
|
+
if (entry.id === checkpoint.id || entry.phase === 'inherited') return false
|
|
759
|
+
if (Number.isInteger(entry.seq) && Number.isInteger(checkpoint.seq) && entry.seq < checkpoint.seq) return true
|
|
760
|
+
if (Number.isInteger(entry.turn) && Number.isInteger(checkpoint.turn) && entry.turn < checkpoint.turn) return true
|
|
761
|
+
// The first turn's before-checkpoint has a null seq (no boundary yet).
|
|
762
|
+
if (entry.turn === checkpoint.turn && entry.phase === 'before') return true
|
|
763
|
+
return false
|
|
764
|
+
}
|
|
765
|
+
const history = this.registry.checkpoints(sessionId).filter(kept)
|
|
766
|
+
if (history.length > 0) {
|
|
767
|
+
await this.registry.insertCheckpoints(
|
|
768
|
+
childSessionId,
|
|
769
|
+
history.map((entry) => ({ ...entry, id: undefined, lastEndSeq: entry.seq })),
|
|
770
|
+
inherited?.id,
|
|
771
|
+
)
|
|
772
|
+
}
|
|
773
|
+
}
|
|
683
774
|
}
|
|
684
775
|
let safety = null
|
|
685
776
|
let restore = null
|
|
@@ -721,9 +812,11 @@ export class TimebackService {
|
|
|
721
812
|
// The notes board travels with the rewind: a checkpoint stores the board
|
|
722
813
|
// version it saw, so rewinding restores that Markdown state too.
|
|
723
814
|
let board = null
|
|
724
|
-
|
|
815
|
+
const boardCwd = checkpoint.snapshot?.cwd ?? session.cwd ?? null
|
|
816
|
+
const boardNotes = await this.notesFor(boardCwd)
|
|
817
|
+
if (boardNotes && Number.isSafeInteger(checkpoint.boardVersion)) {
|
|
725
818
|
try {
|
|
726
|
-
board = await
|
|
819
|
+
board = await boardNotes.restore(checkpoint.boardVersion)
|
|
727
820
|
} catch (error) {
|
|
728
821
|
this.logger?.warn?.(`timeback: board restore failed: ${error?.message ?? error}`)
|
|
729
822
|
board = { restoredFrom: checkpoint.boardVersion, error: error?.message ? String(error.message) : String(error) }
|
|
@@ -736,7 +829,8 @@ export class TimebackService {
|
|
|
736
829
|
if (Number.isSafeInteger(candidate.boardVersion)) referenced.add(candidate.boardVersion)
|
|
737
830
|
}
|
|
738
831
|
}
|
|
739
|
-
this.notes.
|
|
832
|
+
const stores = [this.notes, ...this.scopedNotes.values()]
|
|
833
|
+
for (const store of stores) store.pruneHistory(referenced).catch(() => {})
|
|
740
834
|
}
|
|
741
835
|
return {
|
|
742
836
|
ok: true,
|
|
@@ -846,10 +940,12 @@ export class TimebackService {
|
|
|
846
940
|
/* ---------------------------------------------------------------- */
|
|
847
941
|
|
|
848
942
|
/** @returns {Promise<{version:number,updatedAt:number,entries:object[]}>} the Markdown board. */
|
|
849
|
-
async board() {
|
|
943
|
+
async board(input = {}) {
|
|
850
944
|
await this.start()
|
|
851
|
-
|
|
852
|
-
|
|
945
|
+
const notes = await this.notesForInput(input)
|
|
946
|
+
if (!notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
|
|
947
|
+
await notes.open()
|
|
948
|
+
return notes.board()
|
|
853
949
|
}
|
|
854
950
|
|
|
855
951
|
/**
|
|
@@ -859,13 +955,15 @@ export class TimebackService {
|
|
|
859
955
|
*/
|
|
860
956
|
async saveBoardNote(input, source = 'user') {
|
|
861
957
|
await this.start()
|
|
862
|
-
|
|
958
|
+
const notes = await this.notesForInput(input)
|
|
959
|
+
if (!notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
|
|
960
|
+
await notes.open()
|
|
863
961
|
const id = typeof input.id === 'string' && input.id !== '' ? input.id : ''
|
|
864
962
|
const title = typeof input.title === 'string' ? input.title : ''
|
|
865
963
|
const body = typeof input.body === 'string' ? input.body : ''
|
|
866
964
|
if (id) {
|
|
867
965
|
try {
|
|
868
|
-
return { ok: true, ...(await
|
|
966
|
+
return { ok: true, ...(await notes.update(id, { title, body })) }
|
|
869
967
|
} catch (error) {
|
|
870
968
|
if (error?.code === 'notes/not-found') throw new TimebackError('记录不存在或已删除', 'timeback/note-unknown')
|
|
871
969
|
throw error
|
|
@@ -874,7 +972,7 @@ export class TimebackService {
|
|
|
874
972
|
if (body.trim() === '' && title.trim() === '') throw new TimebackError('记录内容不能为空', 'timeback/note-empty')
|
|
875
973
|
return {
|
|
876
974
|
ok: true,
|
|
877
|
-
...(await
|
|
975
|
+
...(await notes.create({
|
|
878
976
|
title,
|
|
879
977
|
body,
|
|
880
978
|
source: source === 'agent' ? 'agent' : 'user',
|
|
@@ -885,19 +983,23 @@ export class TimebackService {
|
|
|
885
983
|
}
|
|
886
984
|
|
|
887
985
|
/** Persist the sticky-note canvas (layout, background strokes, per-note strokes). */
|
|
888
|
-
async saveBoardCanvas(canvas) {
|
|
986
|
+
async saveBoardCanvas(canvas, input = {}) {
|
|
889
987
|
await this.start()
|
|
890
|
-
|
|
891
|
-
|
|
988
|
+
const notes = await this.notesForInput(input)
|
|
989
|
+
if (!notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
|
|
990
|
+
await notes.open()
|
|
991
|
+
return { ok: true, ...(await notes.updateCanvas(canvas ?? {})) }
|
|
892
992
|
}
|
|
893
993
|
|
|
894
994
|
/** Delete one board note. */
|
|
895
|
-
async deleteBoardNote(id) {
|
|
995
|
+
async deleteBoardNote(id, input = {}) {
|
|
896
996
|
await this.start()
|
|
897
|
-
|
|
997
|
+
const notes = await this.notesForInput(input)
|
|
998
|
+
if (!notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
|
|
999
|
+
await notes.open()
|
|
898
1000
|
if (typeof id !== 'string' || id === '') throw new TimebackError('缺少记录 id', 'timeback/note-id-required')
|
|
899
1001
|
try {
|
|
900
|
-
return { ok: true, ...(await
|
|
1002
|
+
return { ok: true, ...(await notes.remove(id)) }
|
|
901
1003
|
} catch (error) {
|
|
902
1004
|
if (error?.code === 'notes/not-found') throw new TimebackError('记录不存在或已删除', 'timeback/note-unknown')
|
|
903
1005
|
throw error
|
|
@@ -1021,7 +1123,7 @@ export class TimebackService {
|
|
|
1021
1123
|
registeredChild.forkAtSeq === checkpoint.seq
|
|
1022
1124
|
let rewind = null
|
|
1023
1125
|
if (!childUsable) {
|
|
1024
|
-
rewind = await this.rewind({ sessionId, checkpointId: checkpoint.id, mode })
|
|
1126
|
+
rewind = await this.rewind({ sessionId, checkpointId: checkpoint.id, mode, copyHistory: true })
|
|
1025
1127
|
childSessionId = rewind.childSessionId
|
|
1026
1128
|
}
|
|
1027
1129
|
// The truncated branch replaces the old session, so it should look like the
|