dsh-timeback 0.7.6 → 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 CHANGED
@@ -106,7 +106,7 @@ desktop app):
106
106
  ```bash
107
107
  # From npm (published: https://www.npmjs.com/package/dsh-timeback)
108
108
  dsh plugin --profile web add dsh-timeback
109
- dsh plugin --profile web add dsh-timeback@0.7.6 # pin a release
109
+ dsh plugin --profile web add dsh-timeback@0.7.7 # pin a release
110
110
 
111
111
  # Straight from GitHub (no npm release needed)
112
112
  dsh plugin --profile web add github:<owner>/dsh-timeback
package/client.js CHANGED
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
23
23
  const REFRESH_MS = 3000
24
24
  const MAX_ROWS = 240
25
25
  /** Bump together with package.json so a stale browser bundle is obvious. */
26
- const BUILD = '0.7.6+sticky'
26
+ const BUILD = '0.7.7+sticky'
27
27
  /** Set by apply(): opens another Session in the main column. */
28
28
  let openSessionBridge = null
29
29
  /** Set by apply(): opens the Timeback tab in the right sidebar. */
@@ -189,8 +189,8 @@ window.__ModuleLoader__.load({
189
189
  'guide.boardTitle': '记录板',
190
190
  'guide.boardDescription': '全局 Markdown 记录板:手动添加或让会话记录,回溯时一起回退。',
191
191
  'panel.recording': '记录设置',
192
- 'panel.recordThis': '记录此工作区并保存文件快照',
193
- 'panel.recordThisHint': '该开关按工作区目录生效(含子目录):父目录开启后子目录默认继承;在子目录取消勾选可单独关闭该子目录,不影响父目录。',
192
+ 'panel.recordThis': '全选',
193
+ 'panel.recordThisHint': '勾选“全选”记录整个工作区;取消下面文件夹/文件即可只记录选中的部分。',
194
194
  'panel.recordOff': '未开启记录',
195
195
  'panel.recordOn': '记录中',
196
196
  'panel.recordAll': '插件配置 capture=all:所有工作区自动记录',
@@ -205,6 +205,9 @@ window.__ModuleLoader__.load({
205
205
  'panel.workspaceDisabled': '已关闭此工作区的自动记录',
206
206
  'panel.workspaceStillOn': '操作已提交,但该目录仍被其它记录设置覆盖;请在上方已开启列表里取消对应路径。',
207
207
  'panel.selectAllHint': '只记录勾选的文件夹和文件',
208
+ 'panel.workspaceSectionTitle': '工作区文件快照',
209
+ 'panel.expandWorkspaceSection': '展开工作区记录设置',
210
+ 'panel.collapseWorkspaceSection': '收起工作区记录设置',
208
211
  'panel.expandFolder': '展开文件夹',
209
212
  'panel.collapseFolder': '收起文件夹',
210
213
  'panel.selectedCount': '已选择 {selected} / {total} 项(文件夹包含其内部文件)',
@@ -454,6 +457,9 @@ window.__ModuleLoader__.load({
454
457
  'panel.workspaceEnabled': 'Recording enabled for this workspace',
455
458
  'panel.workspaceDisabled': 'Recording disabled for this workspace',
456
459
  'panel.selectAllHint': '只记录勾选的文件夹和文件',
460
+ 'panel.workspaceSectionTitle': '工作区文件快照',
461
+ 'panel.expandWorkspaceSection': '展开工作区记录设置',
462
+ 'panel.collapseWorkspaceSection': '收起工作区记录设置',
457
463
  'panel.expandFolder': '展开文件夹',
458
464
  'panel.collapseFolder': '收起文件夹',
459
465
  'panel.selectedCount': '已选择 {selected} / {total} 项(文件夹包含其内部文件)',
@@ -461,6 +467,9 @@ window.__ModuleLoader__.load({
461
467
  'panel.pathsLoading': '正在读取工作区文件…',
462
468
  'panel.pathsFailed': '读取工作区文件失败:{error}',
463
469
  'panel.selectAllHint': 'Only selected folders/files are recorded',
470
+ 'panel.workspaceSectionTitle': 'Workspace file snapshots',
471
+ 'panel.expandWorkspaceSection': 'Expand workspace recording settings',
472
+ 'panel.collapseWorkspaceSection': 'Collapse workspace recording settings',
464
473
  'panel.expandFolder': 'Expand folder',
465
474
  'panel.collapseFolder': 'Collapse folder',
466
475
  'panel.selectedCount': '{selected} / {total} selected (a folder includes its contents)',
@@ -675,6 +684,7 @@ window.__ModuleLoader__.load({
675
684
  .tb-card:active{cursor:grabbing}
676
685
  .tb-card-note{font-size:11px;line-height:1.35;color:var(--dsw-alias-label-primary,#d7dbe2);overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;word-break:break-word;border-left:2px solid color-mix(in srgb, var(--tb-color,#4d7cfe) 65%, transparent);padding-left:6px}
677
686
  .tb-card-prompt.withnote{-webkit-line-clamp:1;font-size:11px}
687
+ .tb-card-rewind{margin-left:auto;appearance:none;border:1px solid color-mix(in srgb, var(--tb-color,#4d7cfe) 55%, transparent);background:color-mix(in srgb, var(--tb-color,#4d7cfe) 14%, transparent);color:var(--tb-color,#4d7cfe);border-radius:4px;padding:0 5px;line-height:15px;font-size:10px;cursor:pointer;white-space:nowrap}
678
688
  .tb-card-editnote{margin-left:auto;appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.05));color:var(--dsw-alias-label-secondary,#9aa0a6);border-radius:4px;padding:0 5px;line-height:15px;font-size:10px;cursor:pointer;white-space:nowrap}
679
689
  .tb-card-editnote:hover{color:var(--dsw-alias-label-primary,#e6e6e6)}
680
690
  .tb-card-editnote.has{color:var(--tb-color,#4d7cfe);border-color:color-mix(in srgb, var(--tb-color,#4d7cfe) 50%, transparent)}
@@ -961,7 +971,7 @@ window.__ModuleLoader__.load({
961
971
  /** Parse inline Markdown (bold/italic/code/link) into React children. */
962
972
  function inlineMarkdown(text, keyPrefix) {
963
973
  const nodes = []
964
- const pattern = /(<span style="color:\s*#[0-9a-f]{3,8}\s*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*\n]+\*|_[^\n_]+_)/g
974
+ const pattern = /(<span style="[^"]*color:\s*(?:#[0-9a-f]{3,8}|rgba?\([^)]*\))[^"]*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|\*[^*\n]+\*|_[^\n_]+_)/gi
965
975
  let last = 0
966
976
  let match
967
977
  let index = 0
@@ -970,8 +980,9 @@ window.__ModuleLoader__.load({
970
980
  const token = match[0]
971
981
  const key = `${keyPrefix}-i${index++}`
972
982
  if (token.startsWith('<span')) {
973
- const match = /^<span style="color:\s*(#[0-9a-f]{3,8})\s*">([\s\S]*?)<\/span>$/i.exec(token)
974
- if (match) nodes.push(h('span', { key, style: { color: match[1] } }, ...inlineMarkdown(match[2], `${keyPrefix}-c${index}`)))
983
+ const match = /^<span style="[^"]*color:\s*([^";]+)[^"]*">([\s\S]*?)<\/span>$/i.exec(token)
984
+ const color = match ? normalizeCssColor(match[1]) : ''
985
+ if (color) nodes.push(h('span', { key, style: { color } }, ...inlineMarkdown(match[2], `${keyPrefix}-c${index}`)))
975
986
  else nodes.push(token)
976
987
  } else if (token.startsWith('`')) nodes.push(h('code', { key }, token.slice(1, -1)))
977
988
  else if (token.startsWith('**') || token.startsWith('__')) nodes.push(h('strong', { key }, token.slice(2, -2)))
@@ -1290,6 +1301,14 @@ window.__ModuleLoader__.load({
1290
1301
  return next.length === folders.length && next.every((folder, index) => folder === folders[index]) ? folders : next
1291
1302
  }
1292
1303
 
1304
+ /** A stable lane colour for one Session (order-independent). */
1305
+ function stableSessionColor(sessionId) {
1306
+ const value = String(sessionId ?? '')
1307
+ let hash = 0
1308
+ for (let index = 0; index < value.length; index += 1) hash = (hash * 31 + value.charCodeAt(index)) >>> 0
1309
+ return LANE_COLORS[hash % LANE_COLORS.length]
1310
+ }
1311
+
1293
1312
  /**
1294
1313
  * Lay out branch cards left-to-right (turn chain) with one horizontal lane
1295
1314
  * per branch Session, fork edges from the parent turn card to the child's
@@ -1329,7 +1348,7 @@ window.__ModuleLoader__.load({
1329
1348
  }
1330
1349
  for (const session of sessions) {
1331
1350
  const lane = laneOf.get(session.sessionId) ?? 0
1332
- const color = LANE_COLORS[lane % LANE_COLORS.length]
1351
+ const color = stableSessionColor(session.sessionId)
1333
1352
  const y = CANVAS_PAD + lane * (CARD_HEIGHT + CARD_GAP_Y)
1334
1353
  const onPath = currentPath.has(session.sessionId)
1335
1354
  const parent = session.parentSessionId ? byId.get(session.parentSessionId) : null
@@ -1467,10 +1486,13 @@ window.__ModuleLoader__.load({
1467
1486
  })
1468
1487
  for (const ordered of orderedCards) {
1469
1488
  const card = ordered.card
1470
- card.x = x
1489
+ const naturalX = x
1490
+ card.x = naturalX
1471
1491
  card.y = y
1472
1492
  pushCard(card)
1473
- x += CARD_WIDTH + CARD_GAP_X
1493
+ // If the user dragged the previous card, keep the next new card after
1494
+ // where it actually is instead of the old automatic slot.
1495
+ x = Math.max(naturalX + CARD_WIDTH + CARD_GAP_X, card.x + CARD_WIDTH + CARD_GAP_X)
1474
1496
  }
1475
1497
  // Folders collapse member cards into one compact card until unpacked.
1476
1498
  if (Array.isArray(folders) && folders.length > 0 && sessionCards.length > 0) {
@@ -1599,7 +1621,7 @@ window.__ModuleLoader__.load({
1599
1621
  }
1600
1622
 
1601
1623
  /** One card of the conversation canvas. */
1602
- function CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding }) {
1624
+ function CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding, onRewind }) {
1603
1625
  const files = (card.checkpoints ?? []).reduce(
1604
1626
  (total, checkpoint) => ({
1605
1627
  added: total.added + (checkpoint.files?.added ?? 0),
@@ -1679,6 +1701,22 @@ window.__ModuleLoader__.load({
1679
1701
  '📝',
1680
1702
  )
1681
1703
  : null,
1704
+ branchTarget && branchTarget.hasSnapshot === true && typeof onRewind === 'function'
1705
+ ? h(
1706
+ 'button',
1707
+ {
1708
+ type: 'button',
1709
+ className: 'tb-card-rewind',
1710
+ title: t('panel.rewind'),
1711
+ 'aria-label': t('panel.rewind'),
1712
+ onClick: (event) => {
1713
+ event.stopPropagation()
1714
+ onRewind(card, branchTarget)
1715
+ },
1716
+ },
1717
+ '⏪',
1718
+ )
1719
+ : null,
1682
1720
  card.createdAt ? h('span', { className: 'tb-card-time' }, clock(card.createdAt)) : null,
1683
1721
  card.isCurrentPosition ? h('span', { className: 'tb-card-dot', title: t('panel.current') }) : null,
1684
1722
  ),
@@ -1845,6 +1883,7 @@ window.__ModuleLoader__.load({
1845
1883
  onUnpackFolder,
1846
1884
  dropTargetKey,
1847
1885
  folding,
1886
+ onRewind,
1848
1887
  expandedFolderId,
1849
1888
  onToggleFolder,
1850
1889
  onMemberDragStart,
@@ -1954,7 +1993,7 @@ window.__ModuleLoader__.load({
1954
1993
  onMemberDragStart,
1955
1994
  suppressClickRef,
1956
1995
  })
1957
- : CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding }),
1996
+ : CanvasCard({ card, t, selectedKey, onSelect, onOpen, onBranch, onPrune, onNote, onDragStart, suppressClickRef, dropTargetKey, folding, onRewind }),
1958
1997
  ),
1959
1998
  ),
1960
1999
  )
@@ -2121,6 +2160,7 @@ window.__ModuleLoader__.load({
2121
2160
  return () => window.clearTimeout(timer)
2122
2161
  }, [feedback])
2123
2162
  const [view, setView] = React.useState('tree')
2163
+ const [workspaceOpen, setWorkspaceOpen] = React.useState(false)
2124
2164
  const [selectedKey, setSelectedKey] = React.useState(null)
2125
2165
  const [zoom, setZoom] = React.useState(1)
2126
2166
  const [canvasExpanded, setCanvasExpanded] = React.useState(false)
@@ -2308,7 +2348,7 @@ window.__ModuleLoader__.load({
2308
2348
  pruneCandidate,
2309
2349
  })
2310
2350
  if (action === 'prune' && result.childSessionId) openChild(result.childSessionId)
2311
- if (action === 'rewind') {
2351
+ if (action === 'rewind' || action === 'prune') {
2312
2352
  try {
2313
2353
  window.dispatchEvent(new CustomEvent('dsh-timeback:board-changed'))
2314
2354
  } catch {
@@ -2481,8 +2521,13 @@ window.__ModuleLoader__.load({
2481
2521
  const clientVersion = BUILD.split('+')[0]
2482
2522
  const serverVersion = typeof data?.serverVersion === 'string' ? data.serverVersion : null
2483
2523
  const staleBundle = Boolean(serverVersion && clientVersion !== serverVersion)
2484
- const fallbackNode =
2485
- layout?.cards.filter((card) => card.sessionId === data?.currentSessionId).slice(-1)[0] ?? layout?.cards.slice(-1)[0] ?? null
2524
+ const fallbackCard = (() => {
2525
+ const candidates = layout?.cards.filter((card) => card.sessionId === data?.currentSessionId) ?? []
2526
+ const latest = candidates[candidates.length - 1]
2527
+ if (latest?.kind === 'folder') return latest.members?.[latest.members.length - 1] ?? candidates.filter((card) => card.kind !== 'folder').slice(-1)[0] ?? latest
2528
+ return latest ?? candidates[candidates.length - 1] ?? layout?.cards.slice(-1)[0] ?? null
2529
+ })()
2530
+ const fallbackNode = fallbackCard && fallbackCard.kind !== 'folder' ? fallbackCard : null
2486
2531
  const selectedNode = (selectedKey ? layout?.cards.find((card) => card.key === selectedKey) : null) ?? fallbackNode
2487
2532
  const effectiveSelectedKey = selectedNode?.key ?? null
2488
2533
 
@@ -2989,7 +3034,17 @@ window.__ModuleLoader__.load({
2989
3034
  ),
2990
3035
  )
2991
3036
  : null,
2992
- renderWorkspaceSection({ workspace: data?.workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged: () => setTick((value) => value + 1) }),
3037
+ renderWorkspaceSection({
3038
+ workspace: data?.workspace,
3039
+ gitOff,
3040
+ busy,
3041
+ t,
3042
+ toggleWorkspace,
3043
+ sessionId,
3044
+ onWorkspaceChanged: () => setTick((value) => value + 1),
3045
+ open: workspaceOpen,
3046
+ onToggle: () => setWorkspaceOpen((value) => !value),
3047
+ }),
2993
3048
  gitOff ? h('p', { className: 'tb-note' }, t('panel.noGit')) : h('p', { className: 'tb-note' }, t('panel.warning')),
2994
3049
  state.error ? h('div', { className: 'tb-feedback err', role: 'alert' }, `${t('panel.error')}: ${state.error}`) : null,
2995
3050
  state.loading && !data ? h('div', { className: 'tb-empty' }, t('panel.loading')) : null,
@@ -3025,6 +3080,7 @@ window.__ModuleLoader__.load({
3025
3080
  ? h(
3026
3081
  'div',
3027
3082
  { className: 'tb-tree-section' },
3083
+ renderCheckpointDetail({ node: selectedNode, layout, t, act, busy, gitOff, currentSessionId: data.currentSessionId, onNote: openCardNote }),
3028
3084
  TreeCanvas({
3029
3085
  layout,
3030
3086
  t,
@@ -3033,6 +3089,7 @@ window.__ModuleLoader__.load({
3033
3089
  onOpen: openSessionByCard,
3034
3090
  onBranch: branchFromCard,
3035
3091
  onPrune: pruneFromCard,
3092
+ onRewind: (card, checkpoint) => act('rewind', checkpoint, null, card.sessionId),
3036
3093
  onNote: openCardNote,
3037
3094
  expanded: canvasExpanded,
3038
3095
  onToggleExpand: () => setCanvasExpanded((value) => !value),
@@ -3060,7 +3117,6 @@ window.__ModuleLoader__.load({
3060
3117
  h('div', { className: 'tb-canvas-hint' }, t('tree.panHint')),
3061
3118
  h('div', { className: 'tb-canvas-hint' }, t('tree.dragHint')),
3062
3119
  layout.truncated ? h('div', { className: 'tb-ws-hint' }, format(t('tree.truncated'), { count: MAX_TREE_TURNS })) : null,
3063
- renderCheckpointDetail({ node: selectedNode, layout, t, act, busy, gitOff, currentSessionId: data.currentSessionId, onNote: openCardNote }),
3064
3120
  )
3065
3121
  : h(
3066
3122
  'div',
@@ -3319,11 +3375,10 @@ window.__ModuleLoader__.load({
3319
3375
  }
3320
3376
 
3321
3377
  /** Draw the per-workspace recording switch and the enabled-workspace list. */
3322
- function renderWorkspaceSection({ workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged }) {
3378
+ function renderWorkspaceSection({ workspace, gitOff, busy, t, toggleWorkspace, sessionId, onWorkspaceChanged, open, onToggle }) {
3323
3379
  if (!workspace) return null
3324
3380
  const cwd = workspace.cwd
3325
3381
  const mode = workspace.mode
3326
- const canToggle = mode === 'workspace' && !gitOff && Boolean(cwd) && workspace.exists !== false && busy === ''
3327
3382
  const checked = mode === 'all' || workspace.enabled === true
3328
3383
  const reason = gitOff
3329
3384
  ? t('panel.recordDisabledNoGit')
@@ -3334,37 +3389,16 @@ window.__ModuleLoader__.load({
3334
3389
  : mode === 'off'
3335
3390
  ? t('panel.recordFixedOff')
3336
3391
  : t('panel.recordThisHint')
3337
- return h(
3338
- 'div',
3339
- { className: 'tb-ws' },
3340
- h(
3341
- 'div',
3342
- { className: 'tb-ws-row', title: reason },
3343
- h(
3344
- 'span',
3345
- { className: 'tb-ws-text' },
3346
- h('span', { className: 'tb-ws-title' }, t('panel.recordThis')),
3347
- cwd ? h('span', { className: 'tb-ws-path', title: cwd }, cwd) : null,
3348
- h('span', { className: 'tb-ws-hint' }, reason),
3349
- ),
3350
- ),
3351
- mode === 'workspace' && cwd
3352
- ? h(WorkspacePathSelector, {
3353
- sessionId,
3354
- workspace,
3355
- t,
3356
- onChanged: typeof onWorkspaceChanged === 'function' ? onWorkspaceChanged : undefined,
3357
- })
3358
- : null,
3359
- mode === 'workspace' && workspace.enabledWorkspaces?.length > 0
3392
+ const list = (items, kind) =>
3393
+ Array.isArray(items) && items.length > 0
3360
3394
  ? h(
3361
3395
  'div',
3362
3396
  { className: 'tb-ws-list' },
3363
- h('span', { className: 'tb-ws-hint' }, t('panel.enabledWorkspaces')),
3364
- ...workspace.enabledWorkspaces.map((entry) =>
3397
+ h('span', { className: 'tb-ws-hint' }, kind === 'enabled' ? t('panel.enabledWorkspaces') : t('panel.excludedWorkspaces')),
3398
+ ...items.map((entry) =>
3365
3399
  h(
3366
3400
  'div',
3367
- { key: entry.path, className: 'tb-ws-item' },
3401
+ { key: kind + entry.path, className: 'tb-ws-item' },
3368
3402
  h('span', { className: 'tb-ws-path', title: entry.path }, entry.path),
3369
3403
  h(
3370
3404
  'button',
@@ -3372,36 +3406,46 @@ window.__ModuleLoader__.load({
3372
3406
  type: 'button',
3373
3407
  className: 'tb-btn',
3374
3408
  disabled: busy !== '',
3375
- onClick: () => toggleWorkspace(false, entry.path),
3409
+ onClick: () => toggleWorkspace(kind === 'excluded', entry.path),
3376
3410
  },
3377
- t('panel.disableThis'),
3411
+ kind === 'enabled' ? t('panel.disableThis') : t('panel.restoreThis'),
3378
3412
  ),
3379
3413
  ),
3380
3414
  ),
3381
3415
  )
3382
- : null,
3383
- mode === 'workspace' && workspace.excludedWorkspaces?.length > 0
3416
+ : null
3417
+ return h(
3418
+ 'div',
3419
+ { className: 'tb-ws' },
3420
+ h(
3421
+ 'button',
3422
+ {
3423
+ type: 'button',
3424
+ className: 'tb-ws-summary',
3425
+ title: `${t('panel.workspaceSectionTitle')} · ${reason}`,
3426
+ 'aria-expanded': open === true,
3427
+ onClick: typeof onToggle === 'function' ? onToggle : undefined,
3428
+ },
3429
+ h('span', { className: 'tb-ws-caret' }, open ? '▾' : '▸'),
3430
+ h('span', { className: 'tb-ws-title' }, t('panel.workspaceSectionTitle')),
3431
+ cwd ? h('span', { className: 'tb-ws-path', title: cwd }, cwd) : null,
3432
+ h('span', { className: `tb-chip ${checked ? 'ok' : 'warn'}` }, checked ? t('panel.recordOn') : t('panel.recordOff')),
3433
+ ),
3434
+ open
3384
3435
  ? h(
3385
3436
  'div',
3386
- { className: 'tb-ws-list' },
3387
- h('span', { className: 'tb-ws-hint' }, t('panel.excludedWorkspaces')),
3388
- ...workspace.excludedWorkspaces.map((entry) =>
3389
- h(
3390
- 'div',
3391
- { key: `x:${entry.path}`, className: 'tb-ws-item' },
3392
- h('span', { className: 'tb-ws-path', title: entry.path }, entry.path),
3393
- h(
3394
- 'button',
3395
- {
3396
- type: 'button',
3397
- className: 'tb-btn',
3398
- disabled: busy !== '',
3399
- onClick: () => toggleWorkspace(true, entry.path),
3400
- },
3401
- t('panel.restoreThis'),
3402
- ),
3403
- ),
3404
- ),
3437
+ { className: 'tb-ws-body' },
3438
+ h('div', { className: 'tb-ws-row' }, h('span', { className: 'tb-ws-text' }, h('span', { className: 'tb-ws-hint' }, reason))),
3439
+ mode === 'workspace' && cwd
3440
+ ? h(WorkspacePathSelector, {
3441
+ sessionId,
3442
+ workspace,
3443
+ t,
3444
+ onChanged: typeof onWorkspaceChanged === 'function' ? onWorkspaceChanged : undefined,
3445
+ })
3446
+ : null,
3447
+ list(workspace.enabledWorkspaces, 'enabled'),
3448
+ list(workspace.excludedWorkspaces, 'excluded'),
3405
3449
  )
3406
3450
  : null,
3407
3451
  )
@@ -3738,6 +3782,22 @@ window.__ModuleLoader__.load({
3738
3782
  return `#${rgb.map((value) => Math.min(255, Math.max(0, Math.round(Number(value) || 0))).toString(16).padStart(2, '0')).join('')}`
3739
3783
  }
3740
3784
 
3785
+ /** Normalize any CSS color string (#rgb, #rrggbbaa, rgb()/rgba()) to #rrggbb. */
3786
+ function normalizeCssColor(value) {
3787
+ const raw = String(value || '').trim().toLowerCase()
3788
+ if (raw === '') return ''
3789
+ const short = /^#([0-9a-f]{3})$/.exec(raw)
3790
+ if (short) return `#${[...short[1]].map((char) => char + char).join('')}`
3791
+ const hex = /^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/.exec(raw)
3792
+ if (hex) return `#${hex[1]}`
3793
+ const rgb = /^rgba?\(\s*([0-9.]+%?)[\s,]+([0-9.]+%?)[\s,]+([0-9.]+%?)/.exec(raw)
3794
+ if (rgb) {
3795
+ const channel = (part) => (part.endsWith('%') ? Math.round((parseFloat(part) * 255) / 100) : Math.round(parseFloat(part)))
3796
+ return rgbToHex([channel(rgb[1]), channel(rgb[2]), channel(rgb[3])])
3797
+ }
3798
+ return ''
3799
+ }
3800
+
3741
3801
  const BOARD_ANCHORS = ['top', 'right', 'bottom', 'left']
3742
3802
 
3743
3803
  function emptyBoardCanvas() {
@@ -3927,7 +3987,7 @@ window.__ModuleLoader__.load({
3927
3987
 
3928
3988
  /** Inline Markdown -> HTML for the rich editor. */
3929
3989
  function inlineMarkdownToHtml(text) {
3930
- const pattern = /(<span style="color:\s*#[0-9a-f]{3,8}\s*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|~~[^~]+~~|\*[^*\n]+\*|_[^_\n]+_)/g
3990
+ const pattern = /(<span style="[^"]*color:\s*(?:#[0-9a-f]{3,8}|rgba?\([^)]*\))[^"]*">[\s\S]*?<\/span>|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|~~[^~]+~~|\*[^*\n]+\*|_[^_\n]+_)/gi
3931
3991
  let html = ''
3932
3992
  let last = 0
3933
3993
  let match
@@ -3935,9 +3995,10 @@ window.__ModuleLoader__.load({
3935
3995
  html += escapeHtmlText(text.slice(last, match.index))
3936
3996
  const token = match[0]
3937
3997
  if (token.startsWith('<span')) {
3938
- const span = /^<span style="color:\s*(#[0-9a-f]{3,8})\s*">([\s\S]*?)<\/span>$/i.exec(token)
3939
- html += span
3940
- ? `<span style="color:${span[1].toLowerCase()}">${inlineMarkdownToHtml(span[2])}</span>`
3998
+ const span = /^<span style="[^"]*color:\s*([^";]+)[^"]*">([\s\S]*?)<\/span>$/i.exec(token)
3999
+ const color = span ? normalizeCssColor(span[1]) : ''
4000
+ html += color
4001
+ ? `<span style="color:${color}">${inlineMarkdownToHtml(span[2])}</span>`
3941
4002
  : escapeHtmlText(token)
3942
4003
  } else if (token.startsWith('**') || token.startsWith('__')) {
3943
4004
  html += `<strong>${inlineMarkdownToHtml(token.slice(2, -2))}</strong>`
@@ -4035,14 +4096,15 @@ window.__ModuleLoader__.load({
4035
4096
  const style = node.style
4036
4097
  if (style) {
4037
4098
  if (typeof style === 'string') {
4038
- const match = /color:\s*(#[0-9a-f]{3,8})/i.exec(style)
4039
- if (match) return match[1].toLowerCase()
4099
+ const match = /color:\s*([^;]+)/i.exec(style)
4100
+ if (match && normalizeCssColor(match[1])) return normalizeCssColor(match[1])
4040
4101
  } else if (typeof style.color === 'string') {
4041
- return /^#[0-9a-f]{3,8}$/i.test(style.color) ? style.color.toLowerCase() : ''
4102
+ const normalized = normalizeCssColor(style.color)
4103
+ if (normalized) return normalized
4042
4104
  }
4043
4105
  }
4044
4106
  const attr = node.getAttribute ? node.getAttribute('color') : ''
4045
- return /^#[0-9a-f]{3,8}$/i.test(String(attr || '')) ? String(attr).toLowerCase() : ''
4107
+ return normalizeCssColor(attr)
4046
4108
  }
4047
4109
  const inline = (node) => {
4048
4110
  if (!node) return ''
@@ -4115,6 +4177,7 @@ window.__ModuleLoader__.load({
4115
4177
  const [mode, setMode] = React.useState('rich')
4116
4178
  const sourceRef = React.useRef(null)
4117
4179
  const richRef = React.useRef(null)
4180
+ const richRangeRef = React.useRef(null)
4118
4181
  const lastMarkdownRef = React.useRef(null)
4119
4182
  const valueRef = React.useRef(value)
4120
4183
  valueRef.current = value
@@ -4129,7 +4192,21 @@ window.__ModuleLoader__.load({
4129
4192
  lastMarkdownRef.current = valueRef.current
4130
4193
  }, [])
4131
4194
 
4195
+ const rememberRichSelection = () => {
4196
+ const element = richRef.current
4197
+ if (!element) return
4198
+ try {
4199
+ const selection = window.getSelection()
4200
+ if (!selection || selection.rangeCount === 0) return
4201
+ const range = selection.getRangeAt(0)
4202
+ if (element.contains(range.commonAncestorContainer)) richRangeRef.current = range.cloneRange()
4203
+ } catch {
4204
+ // Selection APIs can be unavailable in tests.
4205
+ }
4206
+ }
4207
+
4132
4208
  const syncRich = () => {
4209
+ rememberRichSelection()
4133
4210
  if (composingRef.current) return
4134
4211
  const element = richRef.current
4135
4212
  if (!element) return
@@ -4148,11 +4225,18 @@ window.__ModuleLoader__.load({
4148
4225
  const element = richRef.current
4149
4226
  if (!element) return
4150
4227
  try {
4151
- element.focus()
4228
+ element.focus({ preventScroll: true })
4229
+ const range = richRangeRef.current
4230
+ if (range) {
4231
+ const selection = window.getSelection()
4232
+ selection.removeAllRanges()
4233
+ selection.addRange(range)
4234
+ }
4152
4235
  document.execCommand(command, false, argument)
4153
4236
  } catch {
4154
4237
  // execCommand can be unavailable; the source tab still works.
4155
4238
  }
4239
+ rememberRichSelection()
4156
4240
  syncRich()
4157
4241
  }
4158
4242
 
@@ -4263,7 +4347,19 @@ window.__ModuleLoader__.load({
4263
4347
  'div',
4264
4348
  { className: 'tb-md-tools' },
4265
4349
  ...tools.map((tool) =>
4266
- h('button', { key: tool.key, type: 'button', className: 'tb-md-tool', title: tool.title, disabled, onClick: tool.run }, tool.label),
4350
+ h(
4351
+ 'button',
4352
+ {
4353
+ key: tool.key,
4354
+ type: 'button',
4355
+ className: 'tb-md-tool',
4356
+ title: tool.title,
4357
+ disabled,
4358
+ onMouseDown: (event) => event.preventDefault(),
4359
+ onClick: tool.run,
4360
+ },
4361
+ tool.label,
4362
+ ),
4267
4363
  ),
4268
4364
  ),
4269
4365
  h(
@@ -4290,6 +4386,7 @@ window.__ModuleLoader__.load({
4290
4386
  title: color,
4291
4387
  style: { background: color },
4292
4388
  disabled,
4389
+ onMouseDown: (event) => event.preventDefault(),
4293
4390
  onClick: () => applyColor(color),
4294
4391
  }),
4295
4392
  ),
@@ -4321,8 +4418,12 @@ window.__ModuleLoader__.load({
4321
4418
  'aria-multiline': 'true',
4322
4419
  'data-placeholder': props?.placeholder || '',
4323
4420
  onInput: syncRich,
4421
+ onMouseUp: rememberRichSelection,
4324
4422
  onBlur: syncRich,
4325
- onKeyUp: syncRich,
4423
+ onKeyUp: () => {
4424
+ rememberRichSelection()
4425
+ syncRich()
4426
+ },
4326
4427
  onCompositionStart: () => {
4327
4428
  composingRef.current = true
4328
4429
  },
@@ -4477,7 +4578,7 @@ window.__ModuleLoader__.load({
4477
4578
  } catch (error) {
4478
4579
  setState((previous) => ({ ...previous, loading: false, error: error?.message || String(error) }))
4479
4580
  }
4480
- }, [])
4581
+ }, [boardSessionId])
4481
4582
 
4482
4583
  React.useEffect(() => {
4483
4584
  refresh()
@@ -5873,6 +5974,7 @@ window.__ModuleLoader__.load({
5873
5974
  window.__TIMEBACK_TEST__.domToMarkdown = domToMarkdown
5874
5975
  window.__TIMEBACK_TEST__.turnRows = turnRows
5875
5976
  window.__TIMEBACK_TEST__.mergeCardFolder = mergeCardFolder
5977
+ window.__TIMEBACK_TEST__.stableSessionColor = stableSessionColor
5876
5978
  window.__TIMEBACK_TEST__.removeFolderMember = removeFolderMember
5877
5979
  window.__TIMEBACK_TEST__.layoutTree = layoutTree
5878
5980
  window.__TIMEBACK_TEST__.CanvasFolderCard = CanvasFolderCard
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.6` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
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.6
86
+ dsh plugin --profile web add dsh-timeback@0.7.7
87
87
  ```
88
88
 
89
89
  awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-timeback",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
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/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
@@ -740,7 +740,7 @@ export class TimebackService {
740
740
  forkCheckpointId: checkpoint.id,
741
741
  })
742
742
  this.nameBranch(childSessionId, sessionId, checkpoint)
743
- await this.registry.addCheckpoint(childSessionId, {
743
+ const inherited = await this.registry.addCheckpoint(childSessionId, {
744
744
  turn: checkpoint.turn,
745
745
  phase: 'inherited',
746
746
  seq: checkpoint.seq,
@@ -750,6 +750,27 @@ export class TimebackService {
750
750
  files: null,
751
751
  boardVersion: checkpoint.boardVersion ?? null,
752
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
+ }
753
774
  }
754
775
  let safety = null
755
776
  let restore = null
@@ -1102,7 +1123,7 @@ export class TimebackService {
1102
1123
  registeredChild.forkAtSeq === checkpoint.seq
1103
1124
  let rewind = null
1104
1125
  if (!childUsable) {
1105
- rewind = await this.rewind({ sessionId, checkpointId: checkpoint.id, mode })
1126
+ rewind = await this.rewind({ sessionId, checkpointId: checkpoint.id, mode, copyHistory: true })
1106
1127
  childSessionId = rewind.childSessionId
1107
1128
  }
1108
1129
  // The truncated branch replaces the old session, so it should look like the