dsh-plugin-memory 0.19.5 → 0.20.0
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/CHANGELOG.md +13 -0
- package/README.md +1 -0
- package/README.zh.md +1 -0
- package/docs/market/index.json +2 -2
- package/docs/superpowers/plans/2026-11-16-memory-timeline.md +358 -0
- package/docs/superpowers/specs/2026-11-16-memory-timeline-design.md +153 -0
- package/lib/client.js +550 -33
- package/lib/index.js +30 -0
- package/lib/timeline.js +164 -0
- package/lib/types/index.d.ts +23 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -179,6 +179,26 @@ window.__ModuleLoader__.load({
|
|
|
179
179
|
graphRevealFallback: '打开失败,已复制路径;在 Finder 里按 ⌘⇧G 粘贴路径即可跳转',
|
|
180
180
|
graphSidebarFailed: '侧栏打开失败:',
|
|
181
181
|
graphSidebarOutside: '该文件不在当前会话的工作区内,侧栏无法预览;已用系统文件管理器打开',
|
|
182
|
+
memoryViewGraph: '图谱',
|
|
183
|
+
memoryViewTimeline: '时间轴',
|
|
184
|
+
timelineLoading: '正在读取记忆时间轴…',
|
|
185
|
+
timelineEmpty: '还没有可展示的记忆事件',
|
|
186
|
+
timelineShowAll: '显示全部事件(含笔记/过程)',
|
|
187
|
+
timelineToday: '回到今天',
|
|
188
|
+
timelineScale: '缩放联动',
|
|
189
|
+
timelineHint: '拖动查看历史 · 滚轮缩放(粒度自动联动)· 单击看详情 · 双击打开文件',
|
|
190
|
+
timelineNoPage: '该事件没有对应页面,已打开 log.md',
|
|
191
|
+
timelineOpenFailed: '打开失败:',
|
|
192
|
+
timelineStats: '共 {events} 条事件 · {first} → {last}',
|
|
193
|
+
timelineScaleDay: '日',
|
|
194
|
+
timelineLegendFix: '修复',
|
|
195
|
+
timelineLegendFeat: '功能',
|
|
196
|
+
timelineLegendPublish: '发布',
|
|
197
|
+
timelineLegendDecision: '决策',
|
|
198
|
+
timelineLegendOther: '其他',
|
|
199
|
+
timelineScaleWeek: '周',
|
|
200
|
+
timelineScaleMonth: '月',
|
|
201
|
+
timelineScaleYear: '年',
|
|
182
202
|
graphStats: '{pages} 页 · {links} 条页间互链 · {tagEdges} 条共享 tag',
|
|
183
203
|
graphIndexRoutes: '{count} 条索引路由(虚线)',
|
|
184
204
|
graphIsolated: '{count} 页暂时孤立',
|
|
@@ -338,6 +358,26 @@ window.__ModuleLoader__.load({
|
|
|
338
358
|
graphRevealFallback: 'Reveal failed; the path was copied — paste it in your file manager to jump there',
|
|
339
359
|
graphSidebarFailed: 'Sidebar open failed: ',
|
|
340
360
|
graphSidebarOutside: 'This file is outside the current session workspace, so the sidebar cannot preview it; opened it in the OS file manager instead',
|
|
361
|
+
memoryViewGraph: 'Graph',
|
|
362
|
+
memoryViewTimeline: 'Timeline',
|
|
363
|
+
timelineLoading: 'Loading the memory timeline…',
|
|
364
|
+
timelineEmpty: 'No memory events to show yet',
|
|
365
|
+
timelineShowAll: 'Show all events (including notes/process)',
|
|
366
|
+
timelineToday: 'Back to today',
|
|
367
|
+
timelineScale: 'Zoom',
|
|
368
|
+
timelineHint: 'Drag to travel through history · wheel to zoom (granularity follows automatically) · click for details · double-click to open the file',
|
|
369
|
+
timelineNoPage: 'This event has no linked page, so log.md was opened instead',
|
|
370
|
+
timelineOpenFailed: 'Open failed: ',
|
|
371
|
+
timelineStats: '{events} events · {first} → {last}',
|
|
372
|
+
timelineScaleDay: 'day',
|
|
373
|
+
timelineLegendFix: 'fix',
|
|
374
|
+
timelineLegendFeat: 'feature',
|
|
375
|
+
timelineLegendPublish: 'release',
|
|
376
|
+
timelineLegendDecision: 'decision',
|
|
377
|
+
timelineLegendOther: 'other',
|
|
378
|
+
timelineScaleWeek: 'week',
|
|
379
|
+
timelineScaleMonth: 'month',
|
|
380
|
+
timelineScaleYear: 'year',
|
|
341
381
|
graphStats: '{pages} pages · {links} page links · {tagEdges} shared tags',
|
|
342
382
|
graphIndexRoutes: '{count} index routes (dashed)',
|
|
343
383
|
graphIsolated: '{count} pages isolated',
|
|
@@ -555,17 +595,51 @@ window.__ModuleLoader__.load({
|
|
|
555
595
|
// `gen` bumps after every successful config write so the read-only health
|
|
556
596
|
// card re-mounts and re-reads the store (e.g. after a memoryDir switch).
|
|
557
597
|
const [gen, setGen] = React.useState(0)
|
|
598
|
+
// Two projections of the same store: the relationship graph and the
|
|
599
|
+
// timeline. Only the active one is mounted, so the graph's polling stops
|
|
600
|
+
// while the timeline is open (and vice versa).
|
|
601
|
+
const [view, setView] = React.useState('graph')
|
|
558
602
|
const t = useT(props)
|
|
603
|
+
const tabStyle = (active) => ({
|
|
604
|
+
appearance: 'none',
|
|
605
|
+
border: '1px solid var(--dsw-alias-border-l2, #3a3c42)',
|
|
606
|
+
background: active ? 'var(--dsw-alias-bg-layer-2, #34363d)' : 'transparent',
|
|
607
|
+
color: active ? 'var(--dsw-alias-label-primary, #fff)' : 'var(--dsw-alias-label-secondary, #9aa0aa)',
|
|
608
|
+
borderRadius: '6px',
|
|
609
|
+
padding: '4px 12px',
|
|
610
|
+
fontSize: '12px',
|
|
611
|
+
cursor: 'pointer',
|
|
612
|
+
})
|
|
559
613
|
return React.createElement(LocaleContext.Provider, { value: t },
|
|
560
614
|
React.createElement('div', { 'data-dsh-memory-panel': '', style: { padding: '8px 0' } },
|
|
561
615
|
React.createElement(SectionBoundary, null,
|
|
562
616
|
React.createElement(SoulCard),
|
|
563
617
|
),
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
618
|
+
React.createElement('div', { role: 'tablist', style: { display: 'flex', gap: '6px', padding: '2px 2px 8px' } },
|
|
619
|
+
React.createElement('button', {
|
|
620
|
+
type: 'button',
|
|
621
|
+
role: 'tab',
|
|
622
|
+
'aria-selected': view === 'graph',
|
|
623
|
+
onClick: () => setView('graph'),
|
|
624
|
+
style: tabStyle(view === 'graph'),
|
|
625
|
+
}, t('memoryViewGraph')),
|
|
626
|
+
React.createElement('button', {
|
|
627
|
+
type: 'button',
|
|
628
|
+
role: 'tab',
|
|
629
|
+
'aria-selected': view === 'timeline',
|
|
630
|
+
onClick: () => setView('timeline'),
|
|
631
|
+
style: tabStyle(view === 'timeline'),
|
|
632
|
+
}, t('memoryViewTimeline')),
|
|
568
633
|
),
|
|
634
|
+
// The active projection follows the soul card: the thing people open
|
|
635
|
+
// the panel for should be visible without scrolling.
|
|
636
|
+
view === 'graph'
|
|
637
|
+
? React.createElement(SectionBoundary, { key: `graph-${gen}` },
|
|
638
|
+
React.createElement(GraphCard),
|
|
639
|
+
)
|
|
640
|
+
: React.createElement(SectionBoundary, { key: `timeline-${gen}` },
|
|
641
|
+
React.createElement(TimelineCard),
|
|
642
|
+
),
|
|
569
643
|
React.createElement(SectionBoundary, null,
|
|
570
644
|
React.createElement(MemoryForm, { onSaved: () => setGen((value) => value + 1) }),
|
|
571
645
|
),
|
|
@@ -2047,8 +2121,6 @@ window.__ModuleLoader__.load({
|
|
|
2047
2121
|
|
|
2048
2122
|
/** 双击节点:优先在 DSH 右侧栏打开该 md 文件;不可用时回退系统文件管理器。 */
|
|
2049
2123
|
const openInSidebar = async (id) => {
|
|
2050
|
-
const sidebar = resolveSidebarRight()
|
|
2051
|
-
if (!sidebar || typeof sidebar.openResource !== 'function') return { ok: false, reason: 'sidebar-unavailable' }
|
|
2052
2124
|
let pathInfo
|
|
2053
2125
|
try {
|
|
2054
2126
|
pathInfo = await fetch(`${GRAPH_PATH_URL}?id=${encodeURIComponent(id)}`).then((response) => response.json())
|
|
@@ -2056,33 +2128,9 @@ window.__ModuleLoader__.load({
|
|
|
2056
2128
|
return { ok: false, reason: 'path-fetch-failed' }
|
|
2057
2129
|
}
|
|
2058
2130
|
if (!pathInfo || pathInfo.ok !== true || typeof pathInfo.path !== 'string') return { ok: false, reason: 'path-unresolved' }
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
session = await fetch(SESSION_URL).then((response) => response.json())
|
|
2063
|
-
} catch {
|
|
2064
|
-
return { ok: false, reason: 'session-fetch-failed' }
|
|
2065
|
-
}
|
|
2066
|
-
if (!session || session.ok !== true || typeof session.sessionId !== 'string') return { ok: false, reason: 'no-session' }
|
|
2067
|
-
const root = typeof session.cwd === 'string' && session.cwd.length > 0
|
|
2068
|
-
? session.cwd.replace(/\\/g, '/').replace(/\/+$/, '')
|
|
2069
|
-
: undefined
|
|
2070
|
-
const encodePath = (path) => path.split('/')
|
|
2071
|
-
.map((segment, index) => (index === 0 && /^[A-Za-z]:$/.test(segment) ? segment : encodeURIComponent(segment)))
|
|
2072
|
-
.join('/')
|
|
2073
|
-
// The sidebar only opens `session/<id>/<relative>` addresses; an
|
|
2074
|
-
// absolute address has no authorized session and cannot be claimed.
|
|
2075
|
-
if (root === undefined || (absolute !== root && !absolute.startsWith(`${root}/`))) {
|
|
2076
|
-
return { ok: false, reason: 'outside-workspace' }
|
|
2077
|
-
}
|
|
2078
|
-
const relative = absolute.slice(root.length).replace(/^\/+/, '')
|
|
2079
|
-
const address = `dsh-resource://file/session/${encodeURIComponent(session.sessionId)}/${encodePath(relative)}`
|
|
2080
|
-
try {
|
|
2081
|
-
await sidebar.openResource(address)
|
|
2082
|
-
} catch (error) {
|
|
2083
|
-
return { ok: false, reason: error instanceof Error ? error.message : String(error) }
|
|
2084
|
-
}
|
|
2085
|
-
return { ok: true }
|
|
2131
|
+
// Shared with the timeline: resolve the sidebar service, then open the
|
|
2132
|
+
// session-relative address (absolute addresses cannot be claimed).
|
|
2133
|
+
return openMemoryPath(pathInfo.path)
|
|
2086
2134
|
}
|
|
2087
2135
|
const openNode = (id) => {
|
|
2088
2136
|
const message = (result) => result.reason === 'outside-workspace'
|
|
@@ -2443,6 +2491,466 @@ window.__ModuleLoader__.load({
|
|
|
2443
2491
|
})
|
|
2444
2492
|
|
|
2445
2493
|
/** 记忆图谱卡片:负责取数(含轮询)与生命周期,渲染交给 GraphView。 */
|
|
2494
|
+
|
|
2495
|
+
// ---------------- 记忆时间轴(v0.20) ----------------
|
|
2496
|
+
//
|
|
2497
|
+
// A second projection of the same store as the graph: one horizontal
|
|
2498
|
+
// "metro line" of log events. All geometry lives in pure functions so the
|
|
2499
|
+
// vm tests can exercise zoom granularity, label crowding and the initial
|
|
2500
|
+
// viewport without a DOM; the card only wires state and pointer events.
|
|
2501
|
+
const TIMELINE_URL = '/api/memory/timeline'
|
|
2502
|
+
const TIMELINE_REFRESH_MS = 20000
|
|
2503
|
+
const TIMELINE_HEIGHT = 340
|
|
2504
|
+
const TIMELINE_DAY_MS = 86400000
|
|
2505
|
+
/** Process-noise kinds hidden unless "show all events" is on. */
|
|
2506
|
+
const TIMELINE_NOISE = new Set(['note','digest','install','uninstall','setup','bootstrap','task','probe','recall','consolidate','ops','schedule','export'])
|
|
2507
|
+
const TIMELINE_GROUPS = {
|
|
2508
|
+
fix: 'fix', bugfix: 'fix', repair: 'fix',
|
|
2509
|
+
feat: 'feat', feature: 'feat', implement: 'feat', impl: 'feat',
|
|
2510
|
+
publish: 'publish', release: 'publish', deliverable: 'publish',
|
|
2511
|
+
decision: 'decision', design: 'decision',
|
|
2512
|
+
}
|
|
2513
|
+
const TIMELINE_GROUP_COLORS = { fix: '#e5484d', feat: '#30a46c', publish: '#0091ff', decision: '#8e4ec6', other: '#d97706' }
|
|
2514
|
+
const timelineGroupOf = (kind) => TIMELINE_GROUPS[kind] ?? 'other'
|
|
2515
|
+
const timelineDateMs = (date) => Date.parse(`${date}T00:00:00Z`)
|
|
2516
|
+
const isTimelineNoise = (kind) => TIMELINE_NOISE.has(kind)
|
|
2517
|
+
const pad2 = (value) => String(value).padStart(2, '0')
|
|
2518
|
+
|
|
2519
|
+
/** Zoom density → calendar granularity (day/week/month/year). */
|
|
2520
|
+
function scaleFor(pxPerDay) {
|
|
2521
|
+
if (!Number.isFinite(pxPerDay) || pxPerDay >= 30) return 'day'
|
|
2522
|
+
if (pxPerDay >= 7) return 'week'
|
|
2523
|
+
if (pxPerDay >= 1.6) return 'month'
|
|
2524
|
+
return 'year'
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
function visibleTimelineEvents(events, showAll) {
|
|
2528
|
+
const list = Array.isArray(events)
|
|
2529
|
+
? events.filter((event) => event !== null && typeof event === 'object'
|
|
2530
|
+
&& typeof event.date === 'string' && typeof event.title === 'string')
|
|
2531
|
+
: []
|
|
2532
|
+
return showAll ? list : list.filter((event) => !TIMELINE_NOISE.has(event.kind))
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
function timelineDateLabel(ms, mode) {
|
|
2536
|
+
const date = new Date(ms)
|
|
2537
|
+
const year = date.getUTCFullYear()
|
|
2538
|
+
const month = pad2(date.getUTCMonth() + 1)
|
|
2539
|
+
return mode === 'ym' ? `${year}-${month}` : `${year}-${month}-${pad2(date.getUTCDate())}`
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
/**
|
|
2543
|
+
* Initial viewport: the newest event sits at the right edge and the last
|
|
2544
|
+
* week stays visible whenever the data spans a week (spec §4.2).
|
|
2545
|
+
*/
|
|
2546
|
+
function initialTimelineOffset({ events, width, pxPerDay }) {
|
|
2547
|
+
const list = visibleTimelineEvents(events, false)
|
|
2548
|
+
if (list.length === 0) return 0
|
|
2549
|
+
const last = timelineDateMs(list[list.length - 1].date)
|
|
2550
|
+
const first = timelineDateMs(list[0].date)
|
|
2551
|
+
if (!Number.isFinite(last) || !Number.isFinite(first)) return 0
|
|
2552
|
+
const px = Number.isFinite(pxPerDay) && pxPerDay > 0 ? pxPerDay : 54
|
|
2553
|
+
const w = Number.isFinite(width) && width > 0 ? width : 720
|
|
2554
|
+
// Anchor the newest event at (right edge - 40px); the span to the first
|
|
2555
|
+
// event sets how much history sits left of the viewport.
|
|
2556
|
+
return w - 40 - ((last - first) / TIMELINE_DAY_MS) * px
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
/**
|
|
2560
|
+
* Pure geometry for the timeline card.
|
|
2561
|
+
*
|
|
2562
|
+
* @returns {{ axis: { left: number, width: number }, ticks: object[], stations: object[], labels: object[], first?: string, last?: string }}
|
|
2563
|
+
*/
|
|
2564
|
+
function computeTimelineLayout({ events, width, offset, pxPerDay, showAll }) {
|
|
2565
|
+
const list = visibleTimelineEvents(events, showAll)
|
|
2566
|
+
const px = Number.isFinite(pxPerDay) && pxPerDay > 0 ? pxPerDay : 54
|
|
2567
|
+
const w = Number.isFinite(width) && width > 0 ? width : 720
|
|
2568
|
+
const dx = Number.isFinite(offset) ? offset : 0
|
|
2569
|
+
const empty = { axis: { left: 0, width: 0 }, ticks: [], stations: [], labels: [], first: undefined, last: undefined }
|
|
2570
|
+
if (list.length === 0) return empty
|
|
2571
|
+
const minT = timelineDateMs(list[0].date)
|
|
2572
|
+
const maxT = timelineDateMs(list[list.length - 1].date)
|
|
2573
|
+
if (!Number.isFinite(minT) || !Number.isFinite(maxT)) return empty
|
|
2574
|
+
const xFor = (t) => ((t - minT) / TIMELINE_DAY_MS) * px + dx
|
|
2575
|
+
const scale = scaleFor(px)
|
|
2576
|
+
const ticks = []
|
|
2577
|
+
const pushTick = (t, label) => {
|
|
2578
|
+
const x = xFor(t)
|
|
2579
|
+
if (x >= -80 && x <= w + 80) ticks.push({ x, label })
|
|
2580
|
+
}
|
|
2581
|
+
if (scale === 'day') {
|
|
2582
|
+
const step = Math.max(7, Math.ceil(70 / px / 7) * 7)
|
|
2583
|
+
for (let t = minT; t <= maxT; t += step * TIMELINE_DAY_MS) pushTick(t, timelineDateLabel(t))
|
|
2584
|
+
} else if (scale === 'week') {
|
|
2585
|
+
let t = minT - ((new Date(minT).getUTCDay() + 6) % 7) * TIMELINE_DAY_MS
|
|
2586
|
+
for (; t <= maxT; t += 14 * TIMELINE_DAY_MS) pushTick(t, timelineDateLabel(t))
|
|
2587
|
+
} else if (scale === 'month') {
|
|
2588
|
+
const firstYear = new Date(minT).getUTCFullYear()
|
|
2589
|
+
const lastYear = new Date(maxT).getUTCFullYear()
|
|
2590
|
+
for (let year = firstYear; year <= lastYear; year += 1) {
|
|
2591
|
+
for (let month = 0; month < 12; month += 1) {
|
|
2592
|
+
const t = Date.UTC(year, month, 1)
|
|
2593
|
+
if (t < minT - 31 * TIMELINE_DAY_MS || t > maxT + 31 * TIMELINE_DAY_MS) continue
|
|
2594
|
+
pushTick(t, timelineDateLabel(t, 'ym'))
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
} else {
|
|
2598
|
+
const lastYear = new Date(maxT).getUTCFullYear()
|
|
2599
|
+
for (let year = new Date(minT).getUTCFullYear() - 1; year <= lastYear + 1; year += 1) {
|
|
2600
|
+
const t = Date.UTC(year, 0, 1)
|
|
2601
|
+
if (t < minT - 60 * TIMELINE_DAY_MS || t > maxT + 60 * TIMELINE_DAY_MS) continue
|
|
2602
|
+
pushTick(t, String(year))
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
// Stations: same-day events fan out horizontally and zigzag vertically.
|
|
2606
|
+
const byDay = new Map()
|
|
2607
|
+
list.forEach((event, index) => {
|
|
2608
|
+
const dayKey = Math.floor((timelineDateMs(event.date) - minT) / TIMELINE_DAY_MS)
|
|
2609
|
+
if (!byDay.has(dayKey)) byDay.set(dayKey, [])
|
|
2610
|
+
byDay.get(dayKey).push({ event, index })
|
|
2611
|
+
})
|
|
2612
|
+
const stations = []
|
|
2613
|
+
for (const dayEvents of byDay.values()) {
|
|
2614
|
+
dayEvents.forEach(({ event, index }, slot) => {
|
|
2615
|
+
const group = typeof event.group === 'string' ? event.group : timelineGroupOf(event.kind)
|
|
2616
|
+
stations.push({
|
|
2617
|
+
x: xFor(timelineDateMs(event.date)) + (slot - (dayEvents.length - 1) / 2) * 9,
|
|
2618
|
+
y: TIMELINE_HEIGHT / 2 + (slot % 2 === 0 ? -38 : 38),
|
|
2619
|
+
size: group === 'decision' ? 14 : group === 'fix' || group === 'feat' || group === 'publish' ? 13 : 10,
|
|
2620
|
+
group,
|
|
2621
|
+
kind: event.kind,
|
|
2622
|
+
date: event.date,
|
|
2623
|
+
title: event.title,
|
|
2624
|
+
path: event.path,
|
|
2625
|
+
index,
|
|
2626
|
+
})
|
|
2627
|
+
})
|
|
2628
|
+
}
|
|
2629
|
+
// Labels: keep only the ones that do not collide with the left neighbour.
|
|
2630
|
+
const labels = []
|
|
2631
|
+
let lastRight = -Infinity
|
|
2632
|
+
for (const station of [...stations].sort((a, b) => a.x - b.x)) {
|
|
2633
|
+
const text = station.title.length > 22 ? `${station.title.slice(0, 21)}…` : station.title
|
|
2634
|
+
const labelWidth = Math.min(200, text.length * 11 + 14)
|
|
2635
|
+
if (station.x - labelWidth / 2 - lastRight < 8) continue
|
|
2636
|
+
labels.push({ x: station.x, y: station.y > TIMELINE_HEIGHT / 2 ? station.y + 22 : station.y - 22, text, width: labelWidth })
|
|
2637
|
+
lastRight = station.x + labelWidth / 2
|
|
2638
|
+
}
|
|
2639
|
+
const axisLeft = xFor(minT) - 40
|
|
2640
|
+
return {
|
|
2641
|
+
axis: { left: axisLeft, width: Math.max(0, xFor(maxT) + 40 - axisLeft) },
|
|
2642
|
+
ticks,
|
|
2643
|
+
stations,
|
|
2644
|
+
labels,
|
|
2645
|
+
first: list[0].date,
|
|
2646
|
+
last: list[list.length - 1].date,
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
/** Inject the timeline stylesheet once; colours follow the DSH theme tokens. */
|
|
2651
|
+
function ensureTimelineStyles() {
|
|
2652
|
+
if (typeof document === 'undefined' || document.getElementById('dsh-memory-timeline-style') !== null) return
|
|
2653
|
+
const style = document.createElement('style')
|
|
2654
|
+
style.id = 'dsh-memory-timeline-style'
|
|
2655
|
+
style.textContent = [
|
|
2656
|
+
'.dsh-mem-tl-stage{position:relative;height:' + TIMELINE_HEIGHT + 'px;overflow:hidden;cursor:grab;user-select:none;border:1px solid var(--dsw-alias-border-l2,#3a3c42);border-radius:8px;background:var(--dsw-alias-bg-layer-2,#1d1e22)}',
|
|
2657
|
+
'.dsh-mem-tl-stage.dsh-mem-tl-drag{cursor:grabbing}',
|
|
2658
|
+
'.dsh-mem-tl-axis{position:absolute;top:50%;height:2px;background:var(--dsw-alias-border-l2,#4b4d55);border-radius:2px}',
|
|
2659
|
+
'.dsh-mem-tl-tick{position:absolute;top:calc(50% + 52px);transform:translateX(-50%);font-size:10.5px;color:var(--dsw-alias-label-secondary,#9aa0aa);white-space:nowrap;font-variant-numeric:tabular-nums}',
|
|
2660
|
+
'.dsh-mem-tl-tick::before{content:"";position:absolute;left:50%;top:-9px;width:1px;height:9px;background:var(--dsw-alias-border-l2,#3a3c42)}',
|
|
2661
|
+
'.dsh-mem-tl-station{position:absolute;transform:translate(-50%,-50%);border-radius:50%;cursor:pointer;border:2px solid var(--dsw-alias-bg-layer-1,#1b1c1f);box-shadow:0 0 0 3px rgba(0,0,0,.12)}',
|
|
2662
|
+
'.dsh-mem-tl-station:hover{box-shadow:0 0 0 3px rgba(120,140,180,.25)}',
|
|
2663
|
+
'.dsh-mem-tl-station.dsh-mem-tl-sel{box-shadow:0 0 0 3px rgba(120,140,180,.55)}',
|
|
2664
|
+
'.dsh-mem-tl-label{position:absolute;transform:translate(-50%,-50%);font-size:11px;line-height:1;color:var(--dsw-alias-label-secondary,#9aa0aa);background:var(--dsw-alias-bg-layer-1,rgba(20,21,24,.72));padding:3px 5px;border-radius:4px;white-space:nowrap;pointer-events:none;border:1px solid var(--dsw-alias-border-l2,#2b2d33);overflow:hidden;text-overflow:ellipsis}',
|
|
2665
|
+
'.dsh-mem-tl-detail{display:flex;gap:10px;align-items:baseline;font-size:12px;color:var(--dsw-alias-label-secondary,#9aa0aa);min-height:20px;margin-top:8px}',
|
|
2666
|
+
'.dsh-mem-tl-detail .dsh-mem-tl-dot{flex:none;width:9px;height:9px;border-radius:50%;transform:translateY(1px)}',
|
|
2667
|
+
'.dsh-mem-tl-detail .dsh-mem-tl-date{flex:none;color:var(--dsw-alias-label-secondary,#8b929e);font-variant-numeric:tabular-nums}',
|
|
2668
|
+
'.dsh-mem-tl-detail .dsh-mem-tl-kind{flex:none;padding:1px 6px;border-radius:4px;background:var(--dsw-alias-bg-layer-2,#2f3137);color:var(--dsw-alias-label-secondary,#c9cdd4);font-size:11px}',
|
|
2669
|
+
'.dsh-mem-tl-detail .dsh-mem-tl-text{color:var(--dsw-alias-label-primary,#e6e7ea)}',
|
|
2670
|
+
'.dsh-mem-tl-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:8px;font-size:12px;color:var(--dsw-alias-label-secondary,#9aa0aa)}',
|
|
2671
|
+
'.dsh-mem-tl-toolbar button{appearance:none;border:1px solid var(--dsw-alias-border-l2,#3a3c42);background:var(--dsw-alias-bg-layer-2,#2a2b30);color:var(--dsw-alias-label-secondary,#9aa0aa);border-radius:6px;padding:3px 8px;font-size:12px;cursor:pointer}',
|
|
2672
|
+
'.dsh-mem-tl-toolbar button:hover{color:var(--dsw-alias-label-primary,#fff)}',
|
|
2673
|
+
'.dsh-mem-tl-toolbar label{display:flex;align-items:center;gap:6px;cursor:pointer;user-select:none}',
|
|
2674
|
+
'.dsh-mem-tl-legend{display:flex;gap:10px;margin-left:auto;flex-wrap:wrap;font-size:11px}',
|
|
2675
|
+
'.dsh-mem-tl-legend i{display:inline-block;width:7px;height:7px;border-radius:50%;margin-right:4px;vertical-align:middle}',
|
|
2676
|
+
'.dsh-mem-tl-notice{font-size:12px;color:var(--dsw-alias-label-secondary,#9aa0aa);margin-top:6px}',
|
|
2677
|
+
].join('\n')
|
|
2678
|
+
if (document.head && typeof document.head.appendChild === 'function') document.head.appendChild(style)
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
/**
|
|
2682
|
+
* Open an absolute memory-library path in the right sidebar (shared by the
|
|
2683
|
+
* graph node reveal and the timeline event open).
|
|
2684
|
+
* @returns {Promise<{ ok: true } | { ok: false, reason: string }>}
|
|
2685
|
+
*/
|
|
2686
|
+
async function openMemoryPath(absolutePath) {
|
|
2687
|
+
const sidebar = resolveSidebarRight()
|
|
2688
|
+
if (!sidebar || typeof sidebar.openResource !== 'function') return { ok: false, reason: 'sidebar-unavailable' }
|
|
2689
|
+
const absolute = String(absolutePath).replace(/\\/g, '/')
|
|
2690
|
+
let session
|
|
2691
|
+
try {
|
|
2692
|
+
session = await fetch(SESSION_URL).then((response) => response.json())
|
|
2693
|
+
} catch {
|
|
2694
|
+
return { ok: false, reason: 'session-fetch-failed' }
|
|
2695
|
+
}
|
|
2696
|
+
if (!session || session.ok !== true || typeof session.sessionId !== 'string') return { ok: false, reason: 'no-session' }
|
|
2697
|
+
const root = typeof session.cwd === 'string' && session.cwd.length > 0
|
|
2698
|
+
? session.cwd.replace(/\\/g, '/').replace(/\/+$/, '')
|
|
2699
|
+
: undefined
|
|
2700
|
+
const encodePath = (path) => path.split('/')
|
|
2701
|
+
.map((segment, index) => (index === 0 && /^[A-Za-z]:$/.test(segment) ? segment : encodeURIComponent(segment)))
|
|
2702
|
+
.join('/')
|
|
2703
|
+
// The sidebar only opens `session/<id>/<relative>` addresses; an absolute
|
|
2704
|
+
// address has no authorized session and cannot be claimed.
|
|
2705
|
+
if (root === undefined || (absolute !== root && !absolute.startsWith(`${root}/`))) {
|
|
2706
|
+
return { ok: false, reason: 'outside-workspace' }
|
|
2707
|
+
}
|
|
2708
|
+
const relative = absolute.slice(root.length).replace(/^\/+/, '')
|
|
2709
|
+
const address = `dsh-resource://file/session/${encodeURIComponent(session.sessionId)}/${encodePath(relative)}`
|
|
2710
|
+
try {
|
|
2711
|
+
await sidebar.openResource(address)
|
|
2712
|
+
} catch (error) {
|
|
2713
|
+
return { ok: false, reason: error instanceof Error ? error.message : String(error) }
|
|
2714
|
+
}
|
|
2715
|
+
return { ok: true }
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
/** Open the page a timeline event points at (falls back to log.md). */
|
|
2719
|
+
async function openTimelineEvent(event, options = {}) {
|
|
2720
|
+
const setNotice = typeof options.setNotice === 'function' ? options.setNotice : () => {}
|
|
2721
|
+
const t = typeof options.t === 'function' ? options.t : fallbackT
|
|
2722
|
+
let config
|
|
2723
|
+
try {
|
|
2724
|
+
config = await fetch(CONFIG_URL).then((response) => (response.ok ? response.json() : undefined))
|
|
2725
|
+
} catch {
|
|
2726
|
+
config = undefined
|
|
2727
|
+
}
|
|
2728
|
+
const memoryDir = typeof config?.memoryDir === 'string' && config.memoryDir.length > 0
|
|
2729
|
+
? config.memoryDir.replace(/\\/g, '/').replace(/\/+$/, '')
|
|
2730
|
+
: undefined
|
|
2731
|
+
if (memoryDir === undefined) {
|
|
2732
|
+
setNotice(`${t('timelineOpenFailed')}no-memory-dir`)
|
|
2733
|
+
return { ok: false, reason: 'no-memory-dir' }
|
|
2734
|
+
}
|
|
2735
|
+
const relative = typeof event?.path === 'string' && event.path.length > 0 ? event.path : 'log.md'
|
|
2736
|
+
const result = await openMemoryPath(`${memoryDir}/${relative}`)
|
|
2737
|
+
if (result.ok === true) {
|
|
2738
|
+
if (typeof event?.path !== 'string' || event.path.length === 0) setNotice(t('timelineNoPage'))
|
|
2739
|
+
return result
|
|
2740
|
+
}
|
|
2741
|
+
setNotice(result.reason === 'outside-workspace'
|
|
2742
|
+
? t('graphSidebarOutside')
|
|
2743
|
+
: `${t('timelineOpenFailed')}${result.reason}`)
|
|
2744
|
+
return result
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2747
|
+
function TimelineCard(props) {
|
|
2748
|
+
const t = useT(props)
|
|
2749
|
+
ensureTimelineStyles()
|
|
2750
|
+
const [payload, setPayload] = React.useState(undefined)
|
|
2751
|
+
const [status, setStatus] = React.useState('loading')
|
|
2752
|
+
const [pxPerDay, setPxPerDay] = React.useState(54)
|
|
2753
|
+
const [offset, setOffset] = React.useState(null)
|
|
2754
|
+
const [showAll, setShowAll] = React.useState(false)
|
|
2755
|
+
const [selected, setSelected] = React.useState(undefined)
|
|
2756
|
+
const [notice, setNotice] = React.useState(undefined)
|
|
2757
|
+
const [width, setWidth] = React.useState(0)
|
|
2758
|
+
const stageRef = React.useRef(null)
|
|
2759
|
+
const dragRef = React.useRef(undefined)
|
|
2760
|
+
|
|
2761
|
+
React.useEffect(() => {
|
|
2762
|
+
let alive = true
|
|
2763
|
+
const load = () => {
|
|
2764
|
+
fetch(TIMELINE_URL)
|
|
2765
|
+
.then(async (response) => {
|
|
2766
|
+
if (!response.ok) throw new Error(`GET ${response.status}`)
|
|
2767
|
+
return response.json()
|
|
2768
|
+
})
|
|
2769
|
+
.then((value) => {
|
|
2770
|
+
if (!alive) return
|
|
2771
|
+
setPayload(value)
|
|
2772
|
+
setStatus('ready')
|
|
2773
|
+
})
|
|
2774
|
+
.catch(() => {
|
|
2775
|
+
if (alive) setStatus((current) => (current === 'ready' ? 'ready' : 'failed'))
|
|
2776
|
+
})
|
|
2777
|
+
}
|
|
2778
|
+
load()
|
|
2779
|
+
const timer = typeof setInterval === 'function' ? setInterval(load, TIMELINE_REFRESH_MS) : undefined
|
|
2780
|
+
return () => {
|
|
2781
|
+
alive = false
|
|
2782
|
+
if (timer !== undefined) clearInterval(timer)
|
|
2783
|
+
}
|
|
2784
|
+
}, [])
|
|
2785
|
+
|
|
2786
|
+
React.useEffect(() => {
|
|
2787
|
+
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
|
|
2788
|
+
const measure = () => {
|
|
2789
|
+
const node = stageRef.current
|
|
2790
|
+
if (node && typeof node.clientWidth === 'number' && node.clientWidth > 0) setWidth(node.clientWidth)
|
|
2791
|
+
}
|
|
2792
|
+
measure()
|
|
2793
|
+
window.addEventListener('resize', measure)
|
|
2794
|
+
return () => window.removeEventListener('resize', measure)
|
|
2795
|
+
}, [])
|
|
2796
|
+
|
|
2797
|
+
const events = payload && Array.isArray(payload.events) ? payload.events : []
|
|
2798
|
+
const stats = payload && payload.stats ? payload.stats : {}
|
|
2799
|
+
const layoutWidth = width > 0 ? width : 720
|
|
2800
|
+
const resolvedOffset = offset === null ? initialTimelineOffset({ events, width: layoutWidth, pxPerDay }) : offset
|
|
2801
|
+
const layout = React.useMemo(
|
|
2802
|
+
() => computeTimelineLayout({ events, width: layoutWidth, offset: resolvedOffset, pxPerDay, showAll }),
|
|
2803
|
+
[events, layoutWidth, resolvedOffset, pxPerDay, showAll],
|
|
2804
|
+
)
|
|
2805
|
+
const clampOffset = (value) => {
|
|
2806
|
+
if (layout.first === undefined || layout.last === undefined) return 0
|
|
2807
|
+
const span = (timelineDateMs(layout.last) - timelineDateMs(layout.first)) / TIMELINE_DAY_MS * pxPerDay
|
|
2808
|
+
return Math.min(60, Math.max(layoutWidth - 40 - span, value))
|
|
2809
|
+
}
|
|
2810
|
+
const scaleKey = scaleFor(pxPerDay)
|
|
2811
|
+
const scaleLabel = scaleKey === 'day'
|
|
2812
|
+
? t('timelineScaleDay')
|
|
2813
|
+
: scaleKey === 'week'
|
|
2814
|
+
? t('timelineScaleWeek')
|
|
2815
|
+
: scaleKey === 'month'
|
|
2816
|
+
? t('timelineScaleMonth')
|
|
2817
|
+
: t('timelineScaleYear')
|
|
2818
|
+
|
|
2819
|
+
const onPointerDown = (event) => {
|
|
2820
|
+
dragRef.current = { x: event.clientX, startOffset: resolvedOffset }
|
|
2821
|
+
if (event.currentTarget && event.currentTarget.classList) event.currentTarget.classList.add('dsh-mem-tl-drag')
|
|
2822
|
+
}
|
|
2823
|
+
const onPointerMove = (event) => {
|
|
2824
|
+
const drag = dragRef.current
|
|
2825
|
+
if (drag === undefined) return
|
|
2826
|
+
setOffset(clampOffset(drag.startOffset + (event.clientX - drag.x)))
|
|
2827
|
+
}
|
|
2828
|
+
const stopDrag = (event) => {
|
|
2829
|
+
dragRef.current = undefined
|
|
2830
|
+
if (event && event.currentTarget && event.currentTarget.classList) event.currentTarget.classList.remove('dsh-mem-tl-drag')
|
|
2831
|
+
}
|
|
2832
|
+
const backToToday = () => {
|
|
2833
|
+
setOffset(null)
|
|
2834
|
+
setPxPerDay(54)
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
// Wheel zooms the track, never the settings panel: React's onWheel is a
|
|
2838
|
+
// passive listener (preventDefault is ignored), so the stage gets a
|
|
2839
|
+
// native non-passive listener once it exists. stopPropagation keeps the
|
|
2840
|
+
// surrounding scroll container from moving as well.
|
|
2841
|
+
const wheelStateRef = React.useRef({ pxPerDay: 54, offset: 0 })
|
|
2842
|
+
wheelStateRef.current = { pxPerDay, offset: resolvedOffset }
|
|
2843
|
+
React.useEffect(() => {
|
|
2844
|
+
const node = stageRef.current
|
|
2845
|
+
if (!node || typeof node.addEventListener !== 'function') return undefined
|
|
2846
|
+
const onTimelineWheel = (event) => {
|
|
2847
|
+
event.preventDefault()
|
|
2848
|
+
event.stopPropagation()
|
|
2849
|
+
const rect = typeof node.getBoundingClientRect === 'function' ? node.getBoundingClientRect() : { left: 0 }
|
|
2850
|
+
const mouseX = event.clientX - rect.left
|
|
2851
|
+
const current = wheelStateRef.current
|
|
2852
|
+
const ratio = event.deltaY < 0 ? 1.18 : 1 / 1.18
|
|
2853
|
+
const next = Math.min(240, Math.max(1.4, current.pxPerDay * ratio))
|
|
2854
|
+
setOffset(mouseX - (mouseX - current.offset) * (next / current.pxPerDay))
|
|
2855
|
+
setPxPerDay(next)
|
|
2856
|
+
}
|
|
2857
|
+
node.addEventListener('wheel', onTimelineWheel, { passive: false })
|
|
2858
|
+
return () => {
|
|
2859
|
+
if (typeof node.removeEventListener === 'function') node.removeEventListener('wheel', onTimelineWheel)
|
|
2860
|
+
}
|
|
2861
|
+
}, [status, events.length])
|
|
2862
|
+
|
|
2863
|
+
if (status === 'loading') {
|
|
2864
|
+
return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, t('timelineLoading'))
|
|
2865
|
+
}
|
|
2866
|
+
if (status === 'failed' && payload === undefined) return null
|
|
2867
|
+
|
|
2868
|
+
const toolbar = React.createElement('div', { className: 'dsh-mem-tl-toolbar' },
|
|
2869
|
+
React.createElement('span', null, `${t('timelineScale')}:${scaleLabel}`),
|
|
2870
|
+
React.createElement('span', { style: { display: 'inline-flex', gap: '4px' } },
|
|
2871
|
+
React.createElement('button', { type: 'button', onClick: () => setPxPerDay((value) => Math.max(1.4, value / 1.3)) }, '−'),
|
|
2872
|
+
React.createElement('button', { type: 'button', onClick: () => setPxPerDay((value) => Math.min(240, value * 1.3)) }, '+'),
|
|
2873
|
+
),
|
|
2874
|
+
React.createElement('button', { type: 'button', onClick: backToToday }, t('timelineToday')),
|
|
2875
|
+
React.createElement('label', null,
|
|
2876
|
+
React.createElement('input', { type: 'checkbox', checked: showAll, onChange: (event) => setShowAll(event.target.checked === true) }),
|
|
2877
|
+
t('timelineShowAll'),
|
|
2878
|
+
),
|
|
2879
|
+
React.createElement('span', { className: 'dsh-mem-tl-legend' },
|
|
2880
|
+
['fix', 'feat', 'publish', 'decision', 'other'].map((group) =>
|
|
2881
|
+
React.createElement('span', { key: group },
|
|
2882
|
+
React.createElement('i', { style: { background: TIMELINE_GROUP_COLORS[group] } }),
|
|
2883
|
+
group === 'fix'
|
|
2884
|
+
? t('timelineLegendFix')
|
|
2885
|
+
: group === 'feat'
|
|
2886
|
+
? t('timelineLegendFeat')
|
|
2887
|
+
: group === 'publish'
|
|
2888
|
+
? t('timelineLegendPublish')
|
|
2889
|
+
: group === 'decision'
|
|
2890
|
+
? t('timelineLegendDecision')
|
|
2891
|
+
: t('timelineLegendOther'),
|
|
2892
|
+
),
|
|
2893
|
+
),
|
|
2894
|
+
),
|
|
2895
|
+
)
|
|
2896
|
+
|
|
2897
|
+
const stage = React.createElement('div', {
|
|
2898
|
+
ref: stageRef,
|
|
2899
|
+
className: 'dsh-mem-tl-stage',
|
|
2900
|
+
style: { height: TIMELINE_HEIGHT },
|
|
2901
|
+
onPointerDown,
|
|
2902
|
+
onPointerMove,
|
|
2903
|
+
onPointerUp: stopDrag,
|
|
2904
|
+
onPointerCancel: stopDrag,
|
|
2905
|
+
},
|
|
2906
|
+
React.createElement('div', { className: 'dsh-mem-tl-axis', style: { left: layout.axis.left, width: layout.axis.width } }),
|
|
2907
|
+
layout.ticks.map((tick, index) =>
|
|
2908
|
+
React.createElement('div', { key: `tick-${index}`, className: 'dsh-mem-tl-tick', style: { left: tick.x } }, tick.label),
|
|
2909
|
+
),
|
|
2910
|
+
layout.stations.map((station, index) =>
|
|
2911
|
+
React.createElement('div', {
|
|
2912
|
+
key: `station-${index}`,
|
|
2913
|
+
className: `dsh-mem-tl-station${selected !== undefined && selected.index === station.index ? ' dsh-mem-tl-sel' : ''}`,
|
|
2914
|
+
style: {
|
|
2915
|
+
left: station.x,
|
|
2916
|
+
top: station.y,
|
|
2917
|
+
width: station.size,
|
|
2918
|
+
height: station.size,
|
|
2919
|
+
background: TIMELINE_GROUP_COLORS[station.group] ?? TIMELINE_GROUP_COLORS.other,
|
|
2920
|
+
},
|
|
2921
|
+
title: `${station.date} · ${station.kind}\n${station.title}`,
|
|
2922
|
+
onClick: () => setSelected(station),
|
|
2923
|
+
onDoubleClick: () => { openTimelineEvent(station, { t, setNotice }) },
|
|
2924
|
+
}),
|
|
2925
|
+
),
|
|
2926
|
+
layout.labels.map((label, index) =>
|
|
2927
|
+
React.createElement('div', { key: `label-${index}`, className: 'dsh-mem-tl-label', style: { left: label.x, top: label.y, maxWidth: label.width } }, label.text),
|
|
2928
|
+
),
|
|
2929
|
+
)
|
|
2930
|
+
|
|
2931
|
+
const detail = selected === undefined
|
|
2932
|
+
? React.createElement('div', { className: 'dsh-mem-tl-detail' })
|
|
2933
|
+
: React.createElement('div', { className: 'dsh-mem-tl-detail' },
|
|
2934
|
+
React.createElement('span', { className: 'dsh-mem-tl-dot', style: { background: TIMELINE_GROUP_COLORS[selected.group] ?? TIMELINE_GROUP_COLORS.other } }),
|
|
2935
|
+
React.createElement('span', { className: 'dsh-mem-tl-date' }, selected.date),
|
|
2936
|
+
React.createElement('span', { className: 'dsh-mem-tl-kind' }, `${selected.kind}`),
|
|
2937
|
+
React.createElement('span', { className: 'dsh-mem-tl-text' }, selected.title),
|
|
2938
|
+
)
|
|
2939
|
+
|
|
2940
|
+
return React.createElement('div', { style: cardStyle },
|
|
2941
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'baseline', gap: '10px', flexWrap: 'wrap', marginBottom: '8px' } },
|
|
2942
|
+
React.createElement('span', { style: { fontSize: '13px', fontWeight: 600 } }, t('memoryViewTimeline')),
|
|
2943
|
+
React.createElement('span', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #9aa0aa)' } },
|
|
2944
|
+
fill(t('timelineStats'), { events: String(events.length), first: String(stats.first ?? ''), last: String(stats.last ?? '') })),
|
|
2945
|
+
),
|
|
2946
|
+
toolbar,
|
|
2947
|
+
events.length === 0 ? React.createElement('div', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, t('timelineEmpty')) : stage,
|
|
2948
|
+
detail,
|
|
2949
|
+
notice !== undefined ? React.createElement('div', { className: 'dsh-mem-tl-notice' }, notice) : null,
|
|
2950
|
+
React.createElement('div', { className: 'dsh-mem-tl-notice' }, t('timelineHint')),
|
|
2951
|
+
)
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2446
2954
|
function GraphCard(props) {
|
|
2447
2955
|
const t = useT(props)
|
|
2448
2956
|
const [graph, setGraph] = React.useState(undefined)
|
|
@@ -2651,6 +3159,15 @@ window.__ModuleLoader__.load({
|
|
|
2651
3159
|
InsightsCard,
|
|
2652
3160
|
GraphCard,
|
|
2653
3161
|
GraphView,
|
|
3162
|
+
TimelineCard,
|
|
3163
|
+
scaleFor,
|
|
3164
|
+
computeTimelineLayout,
|
|
3165
|
+
initialTimelineOffset,
|
|
3166
|
+
visibleTimelineEvents,
|
|
3167
|
+
timelineGroupOf,
|
|
3168
|
+
openTimelineEvent,
|
|
3169
|
+
openMemoryPath,
|
|
3170
|
+
TIMELINE_URL,
|
|
2654
3171
|
DICTS,
|
|
2655
3172
|
LOCALE_NS,
|
|
2656
3173
|
fallbackT,
|