dsh-retrace 0.4.151 → 0.4.153

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/lib/client.js CHANGED
@@ -3570,6 +3570,129 @@ export function buildRestoreArchive(payload) {
3570
3570
  }
3571
3571
 
3572
3572
  /** Browser-only download helper for binary archives; absent DOM ⇒ explicit no-op. */
3573
+ /**
3574
+ * 读档点搜索/类型过滤(纯函数):按轮次(数字)或关键词(类型名/原文/版本号)过滤;
3575
+ * `kind === 'all'` 不过滤类型。返回保持原顺序的新数组。
3576
+ */
3577
+ export function filterRestoreEntries(entries, { query = '', kind = 'all', t = null } = {}) {
3578
+ const list = Array.isArray(entries) ? entries : []
3579
+ const text = String(query ?? '').trim()
3580
+ const kindFilter = String(kind ?? 'all')
3581
+ const tr = typeof t === 'function' ? t : (key) => key
3582
+ return list.filter((entry) => {
3583
+ const entryKind = entry?.kind ?? ''
3584
+ if (kindFilter !== 'all' && entryKind !== kindFilter) return false
3585
+ if (text === '') return true
3586
+ const turn = Number.isSafeInteger(entry?.turn) ? String(entry.turn) : ''
3587
+ if (/^\d+$/.test(text)) return turn !== '' && turn === text
3588
+ const haystack = `${turn}\n${entry?.markerText ?? ''}\n${entry?.versionId ?? ''}\n${kindLabel(entryKind, tr)}\n${entry?.preimage === true ? 'preimage' : ''}`.toLowerCase()
3589
+ return haystack.includes(text.toLowerCase())
3590
+ })
3591
+ }
3592
+
3593
+ /**
3594
+ * 读档点「骨架」:把扁平行按**轮次**分组(同轮编辑/撤回/恢复等嵌套在一条轮次行下),
3595
+ * 默认展开一层(`closed` 只记显式收起的轮次);轮次缺失的行保持原位。
3596
+ * 行的 `level` 统一 +1(分支缩进由调用方传入的 `row.branchLevel` 决定配色)。
3597
+ */
3598
+ export function groupRestoreRowsByTurn(rows, { closed = new Set(), t = null } = {}) {
3599
+ const list = Array.isArray(rows) ? rows : []
3600
+ const groups = new Map()
3601
+ const order = []
3602
+ for (const row of list) {
3603
+ const turn = roundOf(row?.record?.turn) ?? roundOf(row?.turn)
3604
+ if (turn === null) continue
3605
+ if (!groups.has(turn)) { groups.set(turn, []); order.push(turn) }
3606
+ groups.get(turn).push(row)
3607
+ }
3608
+ const out = []
3609
+ const emitted = new Set()
3610
+ for (const row of list) {
3611
+ const turn = roundOf(row?.record?.turn) ?? roundOf(row?.turn)
3612
+ if (turn === null) { out.push(row); continue }
3613
+ if (emitted.has(turn)) continue
3614
+ emitted.add(turn)
3615
+ const members = groups.get(turn) ?? []
3616
+ const open = !(closed instanceof Set) || !closed.has(turn)
3617
+ out.push({
3618
+ kind: 'turn-group',
3619
+ turn,
3620
+ count: members.length,
3621
+ open,
3622
+ level: 0,
3623
+ height: 28,
3624
+ jumpSeq: members[0]?.record?.boundarySeq ?? members[0]?.seq ?? null,
3625
+ group: true,
3626
+ })
3627
+ if (!open) continue
3628
+ for (const member of members) out.push({ ...member, level: (Number.isInteger(member.level) ? member.level : 0) + 1 })
3629
+ }
3630
+ return out
3631
+ }
3632
+
3633
+ /**
3634
+ * 多选导出(纯函数,只读):把多条 `restoreExport` 载荷打成一个 zip。
3635
+ * - `manifest.json`:format/mode/exportFormat/count/entries(不含内部生成机制);
3636
+ * - 每条:`entries/<n>-<versionId>/original.md` 或 `data.json`(按 format),
3637
+ * 以及该条的文件字节(base64 解码后原样放入同目录)。
3638
+ * 不做任何回档调用。格式 json ⇒ data.json(结构化原文+文件清单);md ⇒ original.md。
3639
+ */
3640
+ export function buildRestoreArchiveMulti(items, { format = 'json', filename = '' } = {}) {
3641
+ const list = Array.isArray(items) ? items.filter((item) => item && typeof item === 'object') : []
3642
+ const exportFormat = format === 'md' ? 'md' : 'json'
3643
+ const zipEntries = []
3644
+ const manifestEntries = []
3645
+ const encoder = new TextEncoder()
3646
+ list.forEach((item, index) => {
3647
+ const payload = item.payload ?? item
3648
+ const manifest = payload?.manifest ?? {}
3649
+ const versionId = String(item.versionId ?? manifest.versionId ?? `entry-${index + 1}`)
3650
+ const dir = `entries/${String(index + 1).padStart(3, '0')}-${versionId}`
3651
+ const originalText = typeof payload?.originalText === 'string' ? payload.originalText : ''
3652
+ const filePaths = []
3653
+ const files = Array.isArray(payload?.files) ? payload.files : []
3654
+ for (const file of files) {
3655
+ if (!file || file.deleted === true || typeof file.path !== 'string' || typeof file.base64 !== 'string') continue
3656
+ const rel = file.path.replace(/^\/+/, '')
3657
+ if (rel === '') continue
3658
+ zipEntries.push({ path: `${dir}/files/${rel}`, bytes: base64ToBytes(file.base64) })
3659
+ filePaths.push(rel)
3660
+ }
3661
+ if (exportFormat === 'md') {
3662
+ if (originalText !== '') zipEntries.push({ path: `${dir}/original.md`, bytes: encoder.encode(originalText) })
3663
+ } else {
3664
+ const data = {
3665
+ format: 'dsh-retrace/restore-export-entry@1',
3666
+ versionId,
3667
+ kind: manifest.kind ?? item.kind ?? null,
3668
+ turn: Number.isSafeInteger(manifest.turn) ? manifest.turn : null,
3669
+ createdAt: manifest.createdAt ?? null,
3670
+ originalText,
3671
+ files: filePaths,
3672
+ }
3673
+ zipEntries.push({ path: `${dir}/data.json`, bytes: encoder.encode(`${JSON.stringify(data, null, 2)}\n`) })
3674
+ }
3675
+ manifestEntries.push({ versionId, files: filePaths, dir })
3676
+ })
3677
+ const manifest = {
3678
+ format: 'dsh-retrace/restore-export@2',
3679
+ mode: 'multi',
3680
+ exportFormat,
3681
+ count: manifestEntries.length,
3682
+ entries: manifestEntries,
3683
+ }
3684
+ const entries = [
3685
+ { path: 'manifest.json', bytes: encoder.encode(`${JSON.stringify(manifest, null, 2)}\n`) },
3686
+ ...zipEntries,
3687
+ ]
3688
+ return {
3689
+ filename: typeof filename === 'string' && filename !== '' ? filename : `retrace-export-${manifestEntries.length}-${exportFormat}.zip`,
3690
+ bytes: buildZip(entries),
3691
+ entries: entries.map((entry) => entry.path),
3692
+ manifest,
3693
+ }
3694
+ }
3695
+
3573
3696
  function downloadBytesFile(filename, bytes) {
3574
3697
  try {
3575
3698
  if (typeof Blob === 'undefined' || typeof document === 'undefined' || typeof URL === 'undefined'
@@ -3630,6 +3753,12 @@ function RetraceView({ sessionId, useChat, useProjection, t, actions, store }) {
3630
3753
  const [detailOpen, setDetailOpen] = useState(null)
3631
3754
  // 统一恢复列表(读档点 + 检查点前像):server 合并排序(轮次/时间)+ 分页。
3632
3755
  const [restorePage, setRestorePage] = useState({ loading: true, error: null, entries: null, total: 0, hasMore: false, limit: 20, unavailable: false })
3756
+ // 读档点骨架/搜索/多选导出:轮次分组默认展开一层;搜索只影响已加载页。
3757
+ const [restoreQuery, setRestoreQuery] = useState('')
3758
+ const [restoreKind, setRestoreKind] = useState('all')
3759
+ const [closedTurns, setClosedTurns] = useState(() => new Set())
3760
+ const [selectedIds, setSelectedIds] = useState(() => new Set())
3761
+ const [exportFormat, setExportFormat] = useState('json')
3633
3762
 
3634
3763
  // Live push-frame path (projection standard kit) — falls back to HTTP.
3635
3764
  const projected = typeof useProjection === 'function' ? useProjection('retrace/versions') : undefined
@@ -3803,6 +3932,33 @@ function RetraceView({ sessionId, useChat, useProjection, t, actions, store }) {
3803
3932
  }).catch(() => download(fallback))
3804
3933
  }
3805
3934
 
3935
+ /** 多选导出(只读):逐条取 export 载荷 → 合并成一个 zip(manifest+原文/文件字节)。 */
3936
+ const exportSelected = () => {
3937
+ if (selectedEntries.length === 0) return
3938
+ const fallbackFor = (record) => ({
3939
+ manifest: {
3940
+ format: 'dsh-retrace/restore-export@1',
3941
+ source: record.preimage === true ? 'checkpoint' : 'readpoint',
3942
+ versionId: record.versionId,
3943
+ kind: record.kind,
3944
+ turn: Number.isSafeInteger(record.turn) ? record.turn : null,
3945
+ createdAt: record.createdAt ?? null,
3946
+ files: [],
3947
+ note: 'host export unavailable; manifest only',
3948
+ },
3949
+ files: [],
3950
+ originalText: record.markerText ?? '',
3951
+ })
3952
+ Promise.all(selectedEntries.map((record) => callOp('restoreExport', { sessionId, versionId: record.versionId })
3953
+ .then((envelope) => (envelope?.ok === true && envelope.value ? envelope.value : fallbackFor(record)))
3954
+ .catch(() => fallbackFor(record)))).then((payloads) => {
3955
+ const archive = buildRestoreArchiveMulti(payloads.map((payload, index) => ({ payload, versionId: selectedEntries[index]?.versionId })), { format: exportFormat })
3956
+ downloadBytesFile(archive.filename, archive.bytes)
3957
+ }).catch((cause) => {
3958
+ reportBadgeFailure('restoreExport', `多选导出失败: ${cause?.message ?? cause}`)
3959
+ })
3960
+ }
3961
+
3806
3962
  // Jump: switch to the chat tab (tab-bar click — `actions?.setView?.()` is a
3807
3963
  // silent no-op for store-less third-party views), page up via the session
3808
3964
  // store's official `loadThrough(seq)` until the anchor seq is loaded, then
@@ -3958,16 +4114,44 @@ function RetraceView({ sessionId, useChat, useProjection, t, actions, store }) {
3958
4114
  // 行数 = 已加载条数 = 顶部「已显示」;层级只在完整历史的大纲(versions 全量)上保留。
3959
4115
  const restoreMode = Array.isArray(restorePage.entries)
3960
4116
  const outlineTree = restoreMode ? null : tree
4117
+ // 搜索/类型过滤:只作用于读档点列表(已加载页),时间线大纲保持全量。
4118
+ const displayList = restoreMode
4119
+ ? filterRestoreEntries(list, { query: restoreQuery, kind: restoreKind, t })
4120
+ : list
3961
4121
  // 读档点列表:不套森林 + 不折叠静默档 ⇒ 每一条已加载的读档点都占一行(可回),
3962
4122
  // 与顶部「已显示」严格一致;时间线(全量大纲)保持原行为。
3963
- const rows = buildDisplayRows({
3964
- versions: list, digests, tree: outlineTree, expanded, detailOpen, t, collapseQuiet: !restoreMode,
4123
+ const flatRows = buildDisplayRows({
4124
+ versions: displayList, digests, tree: outlineTree, expanded, detailOpen, t, collapseQuiet: !restoreMode,
3965
4125
  })
4126
+ // 骨架:读档点按轮次分组(默认展开一层,`closedTurns` 记显式收起的轮次)。
4127
+ const rows = restoreMode ? groupRestoreRowsByTurn(flatRows, { closed: closedTurns, t }) : flatRows
3966
4128
  // 0.4.148: 顶部总数用 host 的 total(不是当前页长度);「已显示」才是本页行数。
3967
4129
  const totalCount = Array.isArray(restorePage.entries)
3968
4130
  ? (Number.isSafeInteger(restorePage.total) ? restorePage.total : list.length)
3969
4131
  : list.length
3970
- const shownCount = list.length
4132
+ const shownCount = displayList.length
4133
+ // 分支缩进配色:父边界已加载时取它在树上的层深(读档点扁平模式树为空 ⇒ 全部为 0)。
4134
+ const branchLevelOf = (record) => {
4135
+ if (!(tree instanceof Map) || !record) return 0
4136
+ let level = 0
4137
+ let cursor = Number.isSafeInteger(record.boundarySeq) ? tree.get(record.boundarySeq) : null
4138
+ while (cursor && cursor.parent !== null && level < 3) { level += 1; cursor = tree.get(cursor.parent) ?? null }
4139
+ return level
4140
+ }
4141
+ const toggleTurnGroup = (turn) => setClosedTurns((prev) => {
4142
+ const next = new Set(prev)
4143
+ if (next.has(turn)) next.delete(turn); else next.add(turn)
4144
+ return next
4145
+ })
4146
+ const toggleSelect = (versionId) => setSelectedIds((prev) => {
4147
+ const next = new Set(prev)
4148
+ if (typeof versionId !== 'string' || versionId === '') return next
4149
+ if (next.has(versionId)) next.delete(versionId); else next.add(versionId)
4150
+ return next
4151
+ })
4152
+ const selectedEntries = Array.isArray(restorePage.entries)
4153
+ ? restorePage.entries.filter((entry) => selectedIds instanceof Set && selectedIds.has(entry?.versionId))
4154
+ : []
3971
4155
  // 渲染卡死修复:带起始索引切片,渲染用索引算 top(原 `list.indexOf`
3972
4156
  // 是 O(N²))。行高不再恒定(展开明细的行更高)⇒ top 与前缀和挂钩,
3973
4157
  // 仍然只渲染可见行。
@@ -3988,7 +4172,7 @@ function RetraceView({ sessionId, useChat, useProjection, t, actions, store }) {
3988
4172
  const visibleEnd = Math.max(visibleStart, clampIndex(visibleTo(rows, offsets, scrollTop + 640), rows.length))
3989
4173
  const visible = rows.slice(visibleStart, visibleEnd)
3990
4174
  const collapseHint = collapseHintOf({ rows, offsets, scrollTop, viewportHeight: LIST_VIEWPORT_H })
3991
- const rowKey = (row) => row.record?.versionId ?? `${row.kind}:${row.seq}`
4175
+ const rowKey = (row) => row.record?.versionId ?? (row.kind === 'turn-group' ? `turn:${row.turn}` : `${row.kind}:${row.seq}`)
3992
4176
  // Scroll anchoring: capture where the toggled row sits BEFORE the height change
3993
4177
  // and compensate afterwards (only when that row is above the viewport).
3994
4178
  const listRef = useRef(null)
@@ -4094,6 +4278,60 @@ function RetraceView({ sessionId, useChat, useProjection, t, actions, store }) {
4094
4278
  t(Array.isArray(restorePage.entries) ? 'restore.orderHint' : 'timeline.orderHint')),
4095
4279
  ]),
4096
4280
 
4281
+ // 读档点工具条:搜索(轮次/关键词)+ 类型过滤 + 多选导出(只读)。
4282
+ restoreMode && createElement('div', { key: 'restore-tools', className: 'dsh-rt-restore-tools' }, [
4283
+ createElement('input', {
4284
+ key: 'search',
4285
+ type: 'search',
4286
+ className: 'dsh-rt-search',
4287
+ value: restoreQuery,
4288
+ placeholder: t('restore.searchPlaceholder'),
4289
+ 'aria-label': t('restore.searchPlaceholder'),
4290
+ onChange: (event) => setRestoreQuery(event.target.value),
4291
+ }),
4292
+ createElement('select', {
4293
+ key: 'kind',
4294
+ className: 'dsh-rt-filter',
4295
+ value: restoreKind,
4296
+ 'aria-label': t('restore.kindAll'),
4297
+ onChange: (event) => setRestoreKind(event.target.value),
4298
+ }, [
4299
+ createElement('option', { key: 'all', value: 'all' }, t('restore.kindAll')),
4300
+ ...['edit', 'recall', 'regenerate', 'restore', 'compaction'].map((kind) => createElement('option', { key: kind, value: kind }, kindLabel(kind, t))),
4301
+
4302
+ ].filter(Boolean)),
4303
+ createElement('span', { key: 'count', className: 'dsh-rt-filter-count' }, `${displayList.length}/${list.length}`),
4304
+ createElement('button', {
4305
+ key: 'select-all',
4306
+ type: 'button',
4307
+ className: 'dsh-rt-chip',
4308
+ onClick: () => setSelectedIds((prev) => {
4309
+ const next = new Set(prev)
4310
+ const visibleIds = displayList.map((entry) => entry?.versionId).filter((id) => typeof id === 'string')
4311
+ const allSelected = visibleIds.length > 0 && visibleIds.every((id) => next.has(id))
4312
+ for (const id of visibleIds) { if (allSelected) next.delete(id); else next.add(id) }
4313
+ return next
4314
+ }),
4315
+ }, t('restore.selectAll')),
4316
+ createElement('select', {
4317
+ key: 'format',
4318
+ className: 'dsh-rt-filter',
4319
+ value: exportFormat,
4320
+ 'aria-label': t('restore.export'),
4321
+ onChange: (event) => setExportFormat(event.target.value === 'md' ? 'md' : 'json'),
4322
+ }, [
4323
+ createElement('option', { key: 'json', value: 'json' }, 'JSON'),
4324
+ createElement('option', { key: 'md', value: 'md' }, 'Markdown'),
4325
+ ]),
4326
+ createElement('button', {
4327
+ key: 'export-selected',
4328
+ type: 'button',
4329
+ className: 'dsh-rt-chip dsh-rt-chip-danger',
4330
+ disabled: selectedEntries.length === 0,
4331
+ onClick: exportSelected,
4332
+ }, t('restore.exportSelected', { count: selectedEntries.length })),
4333
+ ]),
4334
+
4097
4335
  // issue #7:标题旧前缀清理(一次性维护动作)。入口放读档点页顶部,结果/失败都在原地可见。
4098
4336
  createElement('div', { key: 'title-clean', className: 'dsh-rt-title-clean' }, [
4099
4337
  createElement('button', {
@@ -4147,6 +4385,8 @@ function RetraceView({ sessionId, useChat, useProjection, t, actions, store }) {
4147
4385
  error !== null && createElement('div', { key: 'error', className: 'dsh-rt-error' }, error),
4148
4386
  loading && createElement('div', { key: 'loading', className: 'dsh-rt-timeline-empty' }, t('timeline.loading')),
4149
4387
  !loading && list.length === 0 && createElement('div', { key: 'empty', className: 'dsh-rt-timeline-empty' }, t('timeline.empty')),
4388
+ // 搜索空态(读档点模式且已加载但过滤后为空)。
4389
+ !loading && restoreMode && list.length > 0 && displayList.length === 0 && createElement('div', { key: 'empty-filtered', className: 'dsh-rt-timeline-empty dsh-rt-empty-filtered' }, t('restore.emptyFiltered')),
4150
4390
 
4151
4391
  rows.length > 0 && createElement('div', {
4152
4392
  key: 'list',
@@ -4177,6 +4417,11 @@ function RetraceView({ sessionId, useChat, useProjection, t, actions, store }) {
4177
4417
  ? () => {}
4178
4418
  : () => (row.record.preimage === true ? jump(row.record.jumpSeq) : jumpRow(row)),
4179
4419
  onExport: row.record === undefined ? () => {} : () => exportRestoreEntry(row.record),
4420
+ onToggleGroup: toggleTurnGroup,
4421
+ selectable: restoreMode && row.record !== undefined,
4422
+ selected: row.record !== undefined && selectedIds instanceof Set && selectedIds.has(row.record.versionId),
4423
+ onSelect: toggleSelect,
4424
+ branchLevel: branchLevelOf(row.record),
4180
4425
  })),
4181
4426
  ]),
4182
4427
  ]),
@@ -4255,12 +4500,32 @@ function jumpTargetOf(row) {
4255
4500
  return Number.isSafeInteger(nowSeq) ? nowSeq : row?.record?.boundarySeq
4256
4501
  }
4257
4502
 
4258
- function CheckpointRow({ row, t, top, onToggle, onToggleDepth, onToggleDetail, onPreview, onJump, onExport }) {
4503
+ function CheckpointRow({ row, t, top, onToggle, onToggleDepth, onToggleDetail, onPreview, onJump, onExport, onToggleGroup = () => {}, selectable = false, selected = false, onSelect = () => {} }) {
4259
4504
  const level = Number.isInteger(row.level) ? row.level : 0
4260
4505
  const levelClass = levelClassOf(level)
4261
4506
  const currentClass = row.current ? ' dsh-rt-current' : ''
4262
- const style = { top: `${top}px`, paddingLeft: indentOf(level) }
4507
+ const branchDepth = Number.isInteger(row.branchLevel) && row.branchLevel > 0 ? Math.min(row.branchLevel, 3) : 0
4508
+ const branchClass = branchDepth > 0 ? ` dsh-rt-branch dsh-rt-branch-${branchDepth}` : ''
4509
+ const style = { top: `${top}px`, paddingLeft: indentOf(level + branchDepth) }
4263
4510
  const guide = guideSpans(level)
4511
+ if (row.kind === 'turn-group') {
4512
+ // 轮次骨架:同轮的多条改动嵌套在一条轮次行下(默认展开一层,点标题收起)。
4513
+ return createElement('div', { className: 'dsh-rt-turn-group', style: { top: `${top}px` } }, [
4514
+ createElement('button', {
4515
+ key: 'toggle',
4516
+ type: 'button',
4517
+ className: 'dsh-rt-turn-head',
4518
+ 'aria-expanded': row.open === true,
4519
+ onClick: () => onToggleGroup(row.turn),
4520
+ }, `${row.open === true ? '\u25be' : '\u25b8'} ${t('restore.groupTurn', { turn: row.turn, count: row.count })}`),
4521
+ row.jumpSeq !== null && row.jumpSeq !== undefined && createElement('button', {
4522
+ key: 'jump',
4523
+ type: 'button',
4524
+ className: 'dsh-rt-chip dsh-rt-turn-jump',
4525
+ onClick: () => onJump(row.jumpSeq),
4526
+ }, t('restore.jump')),
4527
+ ])
4528
+ }
4264
4529
  if (row.kind === 'collapsed') {
4265
4530
  return createElement('div', { className: `dsh-rt-tree-toggle${levelClass}${currentClass}`, style }, [
4266
4531
  ...guide,
@@ -4293,7 +4558,7 @@ function CheckpointRow({ row, t, top, onToggle, onToggleDepth, onToggleDetail, o
4293
4558
  // reach here — they have no main-timeline row at all (R20).
4294
4559
  const plainTurn = roundOf(row.record?.turn)
4295
4560
  const plainFiles = row.record?.hasFilePreimage === true || (row.record?.preimage === true && (row.record?.fileCount ?? 0) > 0)
4296
- return createElement('div', { className: `dsh-rt-version dsh-rt-plain${levelClass}${currentClass}`, style }, [
4561
+ return createElement('div', { className: `dsh-rt-version dsh-rt-plain${levelClass}${currentClass}${branchClass}`, style }, [
4297
4562
  ...guide,
4298
4563
  createElement('span', { className: `dsh-rt-version-kind dsh-rt-version-kind-${row.record.kind}`, title: kindLabel(row.record.kind, t) }, KIND_ICONS[row.record.kind] ?? '\u2022'),
4299
4564
  createElement('div', { key: 'body', className: 'dsh-rt-version-body' }, [
@@ -4316,6 +4581,15 @@ function CheckpointRow({ row, t, top, onToggle, onToggleDepth, onToggleDetail, o
4316
4581
  ]),
4317
4582
  ]),
4318
4583
  createElement('span', { key: 'actions', className: 'dsh-rt-version-actions' }, [
4584
+ selectable ? createElement('input', {
4585
+ key: 'select',
4586
+ type: 'checkbox',
4587
+ className: 'dsh-rt-select-box',
4588
+ title: t('restore.export'),
4589
+ 'aria-label': t('restore.export'),
4590
+ checked: selected === true,
4591
+ onChange: () => onSelect(row.record?.versionId),
4592
+ }) : null,
4319
4593
  // 0.4.146:兜底/压缩行同样是固定三动作(回到会话 → 回档 → 导出),回档入口不隐藏。
4320
4594
  createElement('button', { key: 'jump', type: 'button', className: 'dsh-rt-chip', onClick: onJump }, t('restore.jump')),
4321
4595
  createElement('button', { key: 'restore', type: 'button', className: 'dsh-rt-chip dsh-rt-chip-danger', onClick: onPreview }, t('restore.rollback')),
@@ -4330,6 +4604,10 @@ function CheckpointRow({ row, t, top, onToggle, onToggleDepth, onToggleDetail, o
4330
4604
  level,
4331
4605
  current: row.current === true,
4332
4606
  nested: level > 0,
4607
+ branchLevel: row.branchLevel ?? 0,
4608
+ selectable,
4609
+ selected,
4610
+ onSelect,
4333
4611
  what: row.digest?.what ?? null,
4334
4612
  summary: row.digest?.summary,
4335
4613
  summaryCalled: row.digest?.called === true,
@@ -4505,7 +4783,7 @@ function CurrentPathBlock({ t, rounds, open, onToggle, onJump, messages, start }
4505
4783
  *
4506
4784
  * `what` may be absent (old boundary): the row still shows two lines, never blank.
4507
4785
  */
4508
- function VersionRow({ record, top, t, level = 0, current = false, nested = false, what, summary, summaryCalled, discardedCount, turn = null, now = null, detailOpen = false, onToggleDetail, onPreview, onJump, onExport = () => {} }) {
4786
+ function VersionRow({ record, top, t, level = 0, current = false, nested = false, branchLevel = 0, selectable = false, selected = false, onSelect = () => {}, what, summary, summaryCalled, discardedCount, turn = null, now = null, detailOpen = false, onToggleDetail, onPreview, onJump, onExport = () => {} }) {
4509
4787
  const summaryText = summaryCalled === true && typeof summary === 'string' && summary.trim() !== '' ? summary : null
4510
4788
  const artifacts = artifactsLabel(what?.artifacts, t)
4511
4789
  const hasWhat = what !== null && what !== undefined
@@ -4561,7 +4839,9 @@ function VersionRow({ record, top, t, level = 0, current = false, nested = false
4561
4839
  detailCount: detailLines.length,
4562
4840
  contentCount: contentLines.length,
4563
4841
  })
4564
- return createElement('div', { className: `dsh-rt-version${levelClass}${currentClass}`, style: { top: `${top}px`, height: `${rowHeight}px`, paddingLeft: indentOf(level) } }, [
4842
+ const branchDepth = Number.isInteger(branchLevel) && branchLevel > 0 ? Math.min(branchLevel, 3) : 0
4843
+ const branchClass = branchDepth > 0 ? ` dsh-rt-branch dsh-rt-branch-${branchDepth}` : ''
4844
+ return createElement('div', { className: `dsh-rt-version${levelClass}${currentClass}${branchClass}`, style: { top: `${top}px`, height: `${rowHeight}px`, paddingLeft: indentOf(level + branchDepth) } }, [
4565
4845
  // 逐级引导线:每一级一枚 `│ `(CSS 画成该级配色的细色条)——层级不靠量像素,
4566
4846
  // 复制成纯文本也仍然是 `│ │ │ …`。
4567
4847
  ...guideSpans(level),
@@ -4619,6 +4899,15 @@ function VersionRow({ record, top, t, level = 0, current = false, nested = false
4619
4899
  // → 导出(只读)。⛔ 任何行都不隐藏「回档」;缺文件快照只让弹窗里的
4620
4900
  // 「仅产物/两者」置灰并说明,入口始终存在。
4621
4901
  createElement('span', { key: 'actions', className: 'dsh-rt-version-actions' }, [
4902
+ selectable ? createElement('input', {
4903
+ key: 'select',
4904
+ type: 'checkbox',
4905
+ className: 'dsh-rt-select-box',
4906
+ title: t('restore.export'),
4907
+ 'aria-label': t('restore.export'),
4908
+ checked: selected === true,
4909
+ onChange: () => onSelect(record.versionId),
4910
+ }) : null,
4622
4911
  createElement('button', { key: 'jump', type: 'button', className: 'dsh-rt-chip', onClick: onJump }, t('restore.jump')),
4623
4912
  createElement('button', { key: 'restore', type: 'button', className: 'dsh-rt-chip dsh-rt-chip-danger', onClick: onPreview }, t('restore.rollback')),
4624
4913
  createElement('button', { key: 'export', type: 'button', className: 'dsh-rt-chip', onClick: onExport }, t('restore.export')),