dsh-timeback 0.7.4 → 0.7.6

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/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.4` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
81
+ `dsh-timeback@0.7.6` 已发布到官方 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.4
86
+ dsh plugin --profile web add dsh-timeback@0.7.6
87
87
  ```
88
88
 
89
89
  awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
@@ -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` 全绿(当前 40 个)
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
- writeJson(res, 200, { ok: true, board: await service.board() }, req)
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(res, 200, await service.saveBoardCanvas(body.canvas ?? {}), req)
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(res, 200, { ok: true, board: await service.board() }, req)
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(res, 200, await service.deleteBoardNote(typeof body.id === 'string' ? body.id : ''), req)
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
- '在时间回溯的全局 Markdown 记录板上读写记录。记录板与工作区无关、所有会话共享;回溯到某个检查点时,记录板也会一起恢复到该检查点时的状态。action=list 查看;create 新建(title/body,body 为 Markdown);update 修改(id/title/body);delete 删除(id)。用户让你记录笔记、决策、进展或结论时使用它。',
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
- const sessionId = typeof args.sessionId === 'string' && args.sessionId !== '' ? args.sessionId : exec?.agent?.session?.id
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
- const sessionId = typeof args.sessionId === 'string' && args.sessionId !== '' ? args.sessionId : exec?.agent?.session?.id
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-timeback",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "Conversation tree with per-turn workspace snapshots for DeepSeek Harness: branch at any checkpoint and restore the files that turn had.",
5
5
  "type": "module",
6
6
  "license": "MIT",
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: this.notes?.version ?? null,
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.notes?.version ?? null,
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.notes?.version ?? null,
684
+ boardVersion: await this.notesVersionFor(currentCwd),
615
685
  workspace,
616
686
  sessions,
617
687
  limits: {
@@ -721,9 +791,11 @@ export class TimebackService {
721
791
  // The notes board travels with the rewind: a checkpoint stores the board
722
792
  // version it saw, so rewinding restores that Markdown state too.
723
793
  let board = null
724
- if (this.notes && Number.isSafeInteger(checkpoint.boardVersion)) {
794
+ const boardCwd = checkpoint.snapshot?.cwd ?? session.cwd ?? null
795
+ const boardNotes = await this.notesFor(boardCwd)
796
+ if (boardNotes && Number.isSafeInteger(checkpoint.boardVersion)) {
725
797
  try {
726
- board = await this.notes.restore(checkpoint.boardVersion)
798
+ board = await boardNotes.restore(checkpoint.boardVersion)
727
799
  } catch (error) {
728
800
  this.logger?.warn?.(`timeback: board restore failed: ${error?.message ?? error}`)
729
801
  board = { restoredFrom: checkpoint.boardVersion, error: error?.message ? String(error.message) : String(error) }
@@ -736,7 +808,8 @@ export class TimebackService {
736
808
  if (Number.isSafeInteger(candidate.boardVersion)) referenced.add(candidate.boardVersion)
737
809
  }
738
810
  }
739
- this.notes.pruneHistory(referenced).catch(() => {})
811
+ const stores = [this.notes, ...this.scopedNotes.values()]
812
+ for (const store of stores) store.pruneHistory(referenced).catch(() => {})
740
813
  }
741
814
  return {
742
815
  ok: true,
@@ -846,10 +919,12 @@ export class TimebackService {
846
919
  /* ---------------------------------------------------------------- */
847
920
 
848
921
  /** @returns {Promise<{version:number,updatedAt:number,entries:object[]}>} the Markdown board. */
849
- async board() {
922
+ async board(input = {}) {
850
923
  await this.start()
851
- if (!this.notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
852
- return this.notes.board()
924
+ const notes = await this.notesForInput(input)
925
+ if (!notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
926
+ await notes.open()
927
+ return notes.board()
853
928
  }
854
929
 
855
930
  /**
@@ -859,13 +934,15 @@ export class TimebackService {
859
934
  */
860
935
  async saveBoardNote(input, source = 'user') {
861
936
  await this.start()
862
- if (!this.notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
937
+ const notes = await this.notesForInput(input)
938
+ if (!notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
939
+ await notes.open()
863
940
  const id = typeof input.id === 'string' && input.id !== '' ? input.id : ''
864
941
  const title = typeof input.title === 'string' ? input.title : ''
865
942
  const body = typeof input.body === 'string' ? input.body : ''
866
943
  if (id) {
867
944
  try {
868
- return { ok: true, ...(await this.notes.update(id, { title, body })) }
945
+ return { ok: true, ...(await notes.update(id, { title, body })) }
869
946
  } catch (error) {
870
947
  if (error?.code === 'notes/not-found') throw new TimebackError('记录不存在或已删除', 'timeback/note-unknown')
871
948
  throw error
@@ -874,7 +951,7 @@ export class TimebackService {
874
951
  if (body.trim() === '' && title.trim() === '') throw new TimebackError('记录内容不能为空', 'timeback/note-empty')
875
952
  return {
876
953
  ok: true,
877
- ...(await this.notes.create({
954
+ ...(await notes.create({
878
955
  title,
879
956
  body,
880
957
  source: source === 'agent' ? 'agent' : 'user',
@@ -885,19 +962,23 @@ export class TimebackService {
885
962
  }
886
963
 
887
964
  /** Persist the sticky-note canvas (layout, background strokes, per-note strokes). */
888
- async saveBoardCanvas(canvas) {
965
+ async saveBoardCanvas(canvas, input = {}) {
889
966
  await this.start()
890
- if (!this.notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
891
- return { ok: true, ...(await this.notes.updateCanvas(canvas ?? {})) }
967
+ const notes = await this.notesForInput(input)
968
+ if (!notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
969
+ await notes.open()
970
+ return { ok: true, ...(await notes.updateCanvas(canvas ?? {})) }
892
971
  }
893
972
 
894
973
  /** Delete one board note. */
895
- async deleteBoardNote(id) {
974
+ async deleteBoardNote(id, input = {}) {
896
975
  await this.start()
897
- if (!this.notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
976
+ const notes = await this.notesForInput(input)
977
+ if (!notes) throw new TimebackError('记录板存储不可用', 'timeback/notes-unavailable')
978
+ await notes.open()
898
979
  if (typeof id !== 'string' || id === '') throw new TimebackError('缺少记录 id', 'timeback/note-id-required')
899
980
  try {
900
- return { ok: true, ...(await this.notes.remove(id)) }
981
+ return { ok: true, ...(await notes.remove(id)) }
901
982
  } catch (error) {
902
983
  if (error?.code === 'notes/not-found') throw new TimebackError('记录不存在或已删除', 'timeback/note-unknown')
903
984
  throw error