dsh-plugin-memory 0.19.4 → 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 CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
4
4
 
5
+ ## [0.20.0] - 2026-11-16
6
+
7
+ ### Added
8
+
9
+ - **记忆面板新增「时间轴」tab**(与图谱切换):单线地铁式横向时间轴,数据全部从 `log.md` 派生(不新增存储);拖动平移、滚轮缩放且**粒度自动联动** 日/周/月/年;节点不拥挤时自动显示事件描述,拥挤时只留圆点;单击弹详情、双击打开对应记忆页面(匹配不到则打开 `log.md`);默认只显示关键事件(可勾选显示全部);深浅主题跟随 DSH 主题变量。
10
+ - 新增只读路由 `GET /api/memory/timeline`(`buildTimeline`:事件→页面路径模糊匹配、空/损坏日志容错)。
11
+ - 新增 `test/timeline.test.mjs` 与 `session-ui` 时间轴用例;全量 **353** 测试通过。
12
+
13
+ ### Changed
14
+
15
+ - `MemorySection` 改为 tab 容器:只挂载当前投影(图谱的轮询在时间轴打开时暂停,反之亦然)。
16
+ - `openInSidebar` 抽出共享的 `openMemoryPath`(图谱与时间轴共用侧栏打开逻辑)。
17
+
18
+ ## [0.19.5] - 2026-11-12
19
+
20
+ ### Fixed
21
+
22
+ - **page-access 记账健壮性**:`agent/inbox/inserted` 监听器整体 try/catch(写盘/渲染异常只 warn,不污染宿主事件分发);`stamped` 集合在 agent 销毁时删除,长期多会话不再累积会话 id。
23
+
24
+ ### Changed
25
+
26
+ - 商店条目更新到 0.19.x(README 与市场描述同步 rc.2 兼容要求:rc.2 用户必须 ≥0.19.2)。
27
+
5
28
  ## [0.19.4] - 2026-11-12
6
29
 
7
30
  ### Fixed
package/README.md CHANGED
@@ -48,6 +48,7 @@ then install **Memory** from the list. (A JSON index in the official format, ser
48
48
  - **A companion** — digest nudge, proactive recall, weekly growth recap, context-sensitive tone; shared speech floor with other proactive plugins.
49
49
  - **Portable** — plain markdown + git, `pack`/`unpack`, optional auto-commit.
50
50
  - **Memory graph** — interactive 3D sphere: rotate / zoom / drag nodes, search-to-focus, hover or click to light up neighbours; select a node → **Reveal in Finder** or **Copy path**; **double-click a node to open its file in the DSH sidebar** (falls back to the OS file manager).
51
+ - **Timeline** — the same store on a time axis: one draggable metro-style line of log events; wheel zoom switches day/week/month/year granularity automatically; event descriptions show on nodes whenever they fit; click for details, double-click to open the page (falls back to `log.md`); follows the light/dark DSH theme.
51
52
  - **Health tools** — dashboard, `checkup`, `lint`, `doctor`, automatic `last_access` stamping.
52
53
  - **Zero build, bilingual panel, hot-editable config.**
53
54
 
package/README.zh.md CHANGED
@@ -48,6 +48,7 @@ https://raw.githubusercontent.com/LittleBlackTong/dsh-plugin-memory/main/docs/ma
48
48
  - **像个搭子** —— digest 提醒、主动追忆、每周成长回顾、按语境调语气;与其它主动插件共享发言权仲裁。
49
49
  - **可迁移** —— 纯 markdown + git,`pack`/`unpack` 搬家,可选自动提交。
50
50
  - **记忆图谱** —— 可交互 3D 球面:旋转/缩放/拖节点整理、搜索定位、悬停或点击点亮邻居;选中节点可 **在 Finder 中显示** 或 **复制路径**;**双击节点直接在 DSH 侧栏打开该文件**(打不开时回退系统文件管理器)。
51
+ - **时间轴** —— 同一份记忆的时间投影:单线地铁式事件轨道,可拖动、滚轮缩放自动切换 日/周/月/年 刻度;节点不拥挤时显示事件描述,单击看详情、双击打开对应页面(匹配不到则打开 `log.md`);深浅主题自适应。
51
52
  - **健康工具** —— 看板、`checkup`、`lint`、`doctor`、自动 `last_access`。
52
53
  - **零构建、面板双语、配置热改。**
53
54
 
@@ -26,8 +26,8 @@
26
26
  },
27
27
  "versions": [
28
28
  {
29
- "version": "0.19.3",
30
- "publishTimestamp": 1794411755,
29
+ "version": "0.19.5",
30
+ "publishTimestamp": 1794412856,
31
31
  "source": {
32
32
  "type": "npm"
33
33
  },
@@ -0,0 +1,358 @@
1
+ # 记忆时间轴视图 Implementation Plan
2
+
3
+ > **For agentic workers:** REQUIRED SUB-SKILL: Use subagent-driven-development (recommended) or executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+ **Goal:** 在 dsh-plugin-memory 的记忆面板里新增「时间轴」tab:单线地铁式横向时间轴,从 `log.md` 派生事件,缩放自动联动日/周/月/年刻度,节点不拥挤时显示描述,深浅主题自适应,单击详情、双击打开文件。
6
+
7
+ **Architecture:** Host 增加一个只读解析模块 `lib/timeline.js`(log.md → events + stats,含事件→页面路径的模糊匹配)并注册 `GET /api/memory/timeline`;Client 把 `MemorySection` 改为 tab 容器,现有 `GraphCard` 原样保留,新增 `TimelineCard` 与一组纯函数(缩放→粒度、刻度、布局/标签碰撞、初始视口)以便 vm 单测。
8
+
9
+ **Tech Stack:** Node 18+ ESM(host 半,无构建)、`window.__ModuleLoader__` 零构建 CJS 客户端半、`node:test`、React(仅平台种子,client 半不 require 其它 Harness 包)。
10
+
11
+ **Spec:** `docs/superpowers/specs/2026-11-16-memory-timeline-design.md`
12
+
13
+ ## Global Constraints
14
+
15
+ - 不新增依赖;不 require 任何 `@deepseek-ai/dsh-client-*` 客户端包(只 `react` 平台种子)。
16
+ - host 路由只读、失败返回空 payload + 200,绝不抛错、绝不改动记忆文件。
17
+ - 日期按 `YYYY-MM-DD` 解析为 UTC 日(`Date.UTC`),展示用该字符串;不做时区换算。
18
+ - 站点标题必须 `escapeHtml` 后再进 DOM(纯文本)。
19
+ - 主色/文本/边框一律用 DSH 主题变量 + fallback(`var(--dsw-alias-*, 兜底色)`),跟随深/浅主题。
20
+ - 默认只显示关键事件(排除 `NOISE_KINDS`);「显示全部事件」开关可看全量。
21
+ - 初始视口:最近一周(最新事件在右端)。
22
+ - 现有 341 个测试 + `npm test` self-test 必须保持全绿。
23
+ - 双击打开文件:复用现有 `openInSidebar`(工作区外回退系统文件管理器);事件无 `path` 时打开 `log.md` 并给出提示文案。
24
+
25
+ ---
26
+
27
+ ## File Structure
28
+
29
+ | File | 职责 |
30
+ |---|---|
31
+ | `lib/timeline.js`(新) | 解析 `log.md`、页面索引、事件→路径匹配、group 映射、关键/噪声分类、stats |
32
+ | `lib/index.js`(改) | 注册 `GET /api/memory/timeline`、导出 `buildTimeline`/`TIMELINE_ROUTE_PATH` |
33
+ | `lib/types/index.d.ts`(改) | `TimelineEvent` / `TimelinePayload` 类型 |
34
+ | `lib/client.js`(改) | tab 容器、`TimelineCard`、纯函数(scaleFor/layoutTimeline)、样式、中英文案、双击打开 |
35
+ | `test/timeline.test.mjs`(新) | host 解析与路由测试 |
36
+ | `test/session-ui.test.mjs`(改) | 时间轴纯函数与渲染测试(vm + React stub) |
37
+ | `README.md` / `README.zh.md`(改) | 功能说明加「时间轴视图」 |
38
+ | `CHANGELOG.md`(改) | 0.20.0 记录 |
39
+
40
+ ---
41
+
42
+ ### Task 1: Host timeline 解析与只读路由
43
+
44
+ **Files:**
45
+ - Create: `lib/timeline.js`
46
+ - Modify: `lib/index.js`(import、路由常量、webServer 路由、导出)
47
+ - Modify: `lib/types/index.d.ts`
48
+ - Test: `test/timeline.test.mjs`
49
+
50
+ **Interfaces:**
51
+ - Produces:
52
+ - `buildTimeline(memoryDir: string, options?: { }): { events: TimelineEvent[]; stats: { events: number; first?: string; last?: string; pages: number } }`
53
+ - `TimelineEvent = { date: string; kind: string; group: 'fix'|'feat'|'publish'|'decision'|'other'; title: string; path?: string }`
54
+ - `groupOf(kind: string): string`,`isNoiseKind(kind: string): boolean`
55
+ - `TIMELINE_ROUTE_PATH = '/api/memory/timeline'`
56
+
57
+ - [ ] **Step 1: 写 host 测试(先红)**
58
+
59
+ `test/timeline.test.mjs` 关键用例(fixture 用 `mkdtempSync`,写 `log.md` 与页面):
60
+
61
+ ```js
62
+ import { buildTimeline, groupOf, isNoiseKind, NOISE_KINDS } from '../lib/timeline.js'
63
+
64
+ // fixture log.md:
65
+ // # Memory Log
66
+ // ## [2026-11-10] fix | dsh-plugin-memory 0.19.4(双向兼容)
67
+ // ## [2026-11-12] publish | 商店分支重建
68
+ // ## [2026-11-12] note | 无新增的普通日志
69
+ // ## [bad-date] fix | 非法日期应被跳过
70
+
71
+ test('buildTimeline parses log headings into events', () => {
72
+ const { events, stats } = buildTimeline(dir)
73
+ assert.deepEqual(events.map((e) => [e.date, e.kind, e.group]), [
74
+ ['2026-11-10', 'fix', 'fix'],
75
+ ['2026-11-12', 'publish', 'publish'],
76
+ ['2026-11-12', 'note', 'other'],
77
+ ])
78
+ assert.equal(stats.events, 3)
79
+ assert.equal(stats.first, '2026-11-10')
80
+ assert.equal(stats.last, '2026-11-12')
81
+ })
82
+
83
+ test('buildTimeline matches events to page paths by title and file name', () => {
84
+ // 页面 projects/active/dsh-plugin-memory.md frontmatter title: dsh-plugin-memory 插件本体
85
+ // 事件标题 "dsh-plugin-memory 0.19.4(双向兼容)" → path: 'projects/active/dsh-plugin-memory.md'
86
+ // 无匹配事件省略 path
87
+ })
88
+
89
+ test('buildTimeline tolerates missing/corrupt log and invalid dates', () => {
90
+ assert.deepEqual(buildTimeline(emptyDir), { events: [], stats: { events: 0, pages: 0 } })
91
+ // 无 log.md → 空;坏 JSON 无关;日期非 YYYY-MM-DD → 跳过
92
+ })
93
+
94
+ test('group mapping and noise classification', () => {
95
+ assert.equal(groupOf('bugfix'), 'fix')
96
+ assert.equal(groupOf('release'), 'publish')
97
+ assert.equal(groupOf('design'), 'decision')
98
+ assert.equal(groupOf('task'), 'other')
99
+ assert.equal(isNoiseKind('note'), true)
100
+ assert.equal(isNoiseKind('fix'), false)
101
+ assert.equal(NOISE_KINDS.has('digest'), true)
102
+ })
103
+ ```
104
+
105
+ - [ ] **Step 2: 运行确认失败**
106
+
107
+ Run: `node --test test/timeline.test.mjs`
108
+ Expected: FAIL(`buildTimeline` 未定义)。
109
+
110
+ - [ ] **Step 3: 实现 `lib/timeline.js`**
111
+
112
+ ```js
113
+ import { existsSync, readFileSync, readdirSync } from 'node:fs'
114
+ import { join, relative, sep } from 'node:path'
115
+
116
+ export const GROUP_OF = {
117
+ fix: 'fix', bugfix: 'fix', repair: 'fix',
118
+ feat: 'feat', feature: 'feat', implement: 'feat', impl: 'feat',
119
+ publish: 'publish', release: 'publish', deliverable: 'publish',
120
+ decision: 'decision', design: 'decision',
121
+ }
122
+ export const NOISE_KINDS = new Set(['note','digest','install','uninstall','setup','bootstrap','task','probe','recall','consolidate','ops','schedule','export'])
123
+ export const groupOf = (kind) => GROUP_OF[kind] ?? 'other'
124
+ export const isNoiseKind = (kind) => NOISE_KINDS.has(kind)
125
+
126
+ const LOG_LINE = /^## \[(\d{4}-\d{2}-\d{2})\] (\w+) \| (.+)$/
127
+ const PAGE_SKIP = new Set(['SOUL.md','MEMORY.md','index.md','log.md','BOOTSTRAP.md'])
128
+
129
+ function readPageIndex(memoryDir) {
130
+ const pages = []
131
+ const walk = (dir) => {
132
+ let entries
133
+ try { entries = readdirSync(dir, { withFileTypes: true }) } catch { return }
134
+ for (const ent of entries) {
135
+ const p = join(dir, ent.name)
136
+ if (ent.isDirectory()) { if (ent.name !== 'raw') walk(p); continue }
137
+ if (!ent.name.endsWith('.md') || PAGE_SKIP.has(ent.name)) continue
138
+ try {
139
+ const text = readFileSync(p, 'utf8')
140
+ const title = /^title:\s*(.+)$/m.exec(text)?.[1]?.trim().replace(/^["']|["']$/g, '')
141
+ pages.push({ path: relative(memoryDir, p).split(sep).join('/'), title, name: ent.name.replace(/\.md$/, '') })
142
+ } catch { /* skip unreadable page */ }
143
+ }
144
+ }
145
+ walk(memoryDir)
146
+ return pages
147
+ }
148
+
149
+ function matchPath(title, pages) {
150
+ let best
151
+ for (const page of pages) {
152
+ for (const needle of [page.title, page.name]) {
153
+ if (typeof needle !== 'string' || needle.length === 0) continue
154
+ if (title.includes(needle) && (best === undefined || needle.length > best.len)) best = { path: page.path, len: needle.length }
155
+ }
156
+ }
157
+ return best?.path
158
+ }
159
+
160
+ export function buildTimeline(memoryDir) {
161
+ const logPath = join(memoryDir, 'log.md')
162
+ const pages = existsSync(memoryDir) ? readPageIndex(memoryDir) : []
163
+ const events = []
164
+ let text = ''
165
+ try { text = existsSync(logPath) ? readFileSync(logPath, 'utf8') : '' } catch { text = '' }
166
+ for (const line of text.split(/\r?\n/)) {
167
+ const m = LOG_LINE.exec(line)
168
+ if (!m) continue
169
+ const [, date, kind, title] = m
170
+ const event = { date, kind, group: groupOf(kind), title: title.trim() }
171
+ const path = matchPath(event.title, pages)
172
+ if (path !== undefined) event.path = path
173
+ events.push(event)
174
+ }
175
+ events.sort((a, b) => a.date < b.date ? -1 : a.date > b.date ? 1 : 0)
176
+ const stats = { events: events.length, pages: pages.length }
177
+ if (events.length > 0) { stats.first = events[0].date; stats.last = events[events.length - 1].date }
178
+ return { events, stats }
179
+ }
180
+ ```
181
+
182
+ - [ ] **Step 4: 运行确认通过**
183
+
184
+ Run: `node --test test/timeline.test.mjs`
185
+ Expected: PASS(4 个用例)。
186
+
187
+ - [ ] **Step 5: 注册 host 路由 + 类型 + 导出**
188
+
189
+ `lib/index.js`:
190
+ - import:`import { buildTimeline } from './timeline.js'`
191
+ - 常量:`export const TIMELINE_ROUTE_PATH = '/api/memory/timeline'`
192
+ - 在 graph 路由同一个 `ctx.inject(['webServer'], ...)` 或新增 effect 中注册:
193
+ ```js
194
+ ctx.inject(['webServer'], (webCtx) => {
195
+ const disposeTimeline = webCtx.webServer.register({
196
+ kind: 'exact',
197
+ path: TIMELINE_ROUTE_PATH,
198
+ handler: (req, res) => {
199
+ try {
200
+ const payload = buildTimeline(currentMemoryDir)
201
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' })
202
+ res.end(JSON.stringify(payload))
203
+ } catch (error) {
204
+ ctx.logger?.warn?.(`memory: timeline failed: ${error instanceof Error ? error.message : String(error)}`)
205
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' })
206
+ res.end(JSON.stringify({ events: [], stats: { events: 0, pages: 0 } }))
207
+ }
208
+ },
209
+ })
210
+ webCtx.effect(() => () => disposeTimeline, 'memory.timeline-route()')
211
+ })
212
+ ```
213
+ - 底部导出:`export { buildTimeline } from './timeline.js'`
214
+ - `lib/types/index.d.ts` 增加 `TimelineEvent` / `TimelinePayload` / `buildTimeline` 声明。
215
+
216
+ - [ ] **Step 6: 全量测试 + commit**
217
+
218
+ Run: `node --test` → 全绿;`npm test` → self-test PASS。
219
+ ```bash
220
+ git add lib/timeline.js lib/index.js lib/types/index.d.ts test/timeline.test.mjs
221
+ git commit -m "feat: timeline host parser and /api/memory/timeline route"
222
+ ```
223
+
224
+ ---
225
+
226
+ ### Task 2: Client 时间轴视图(tab + TimelineCard)
227
+
228
+ **Files:**
229
+ - Modify: `lib/client.js`(DICTS、常量、纯函数、样式、TimelineCard、MemorySection tab 容器、__test 导出)
230
+ - Test: `test/session-ui.test.mjs`(扩)
231
+
232
+ **Interfaces:**
233
+ - Consumes(Task 1):`GET /api/memory/timeline` 返回 `{ events: [{date,kind,group,title,path?}], stats }`。
234
+ - Produces(导出到 `__test`):
235
+ - `scaleFor(pxPerDay: number): 'day'|'week'|'month'|'year'`
236
+ - `computeTimelineLayout({ events, width, offset, pxPerDay, showAll }): { axis: {left,width}, ticks: [{x,label}], stations: [{x,y,size,group,date,title,index}], labels: [{x,y,text}] }`
237
+ - `initialTimelineOffset({ events, width, pxPerDay }): number`(最近一周)
238
+ - `TimelineCard({ t })`(React 组件)
239
+
240
+ - [ ] **Step 1: 写 client 测试(先红)**(`test/session-ui.test.mjs`,`loadClient()` 已存在)
241
+
242
+ ```js
243
+ test('scaleFor maps zoom density to day/week/month/year', () => {
244
+ const seam = loadClient()
245
+ assert.equal(seam.scaleFor(54), 'day')
246
+ assert.equal(seam.scaleFor(20), 'week')
247
+ assert.equal(seam.scaleFor(3), 'month')
248
+ assert.equal(seam.scaleFor(1), 'year')
249
+ })
250
+
251
+ test('computeTimelineLayout drops overlapping labels but keeps stations', () => {
252
+ const seam = loadClient()
253
+ const events = [
254
+ { date: '2026-11-10', kind: 'fix', group: 'fix', title: '修复 A' },
255
+ { date: '2026-11-10', kind: 'fix', group: 'fix', title: '修复 B' }, // 同日,拥挤
256
+ ]
257
+ const layout = seam.computeTimelineLayout({ events, width: 600, offset: 0, pxPerDay: 54, showAll: false })
258
+ assert.equal(layout.stations.length, 2)
259
+ assert.equal(layout.labels.length, 1, 'overlapping labels collapse to one')
260
+ })
261
+
262
+ test('initialTimelineOffset keeps the last week visible', () => {
263
+ const seam = loadClient()
264
+ const events = [{ date: '2026-11-12', kind: 'fix', group: 'fix', title: 'x' }]
265
+ const offset = seam.initialTimelineOffset({ events, width: 600, pxPerDay: 54 })
266
+ assert.ok(Number.isFinite(offset))
267
+ assert.ok(offset < 0, 'the newest event sits at the right edge')
268
+ })
269
+
270
+ test('TimelineCard renders stats, stations and detail card', () => {
271
+ const seam = loadClient()
272
+ const node = seam.TimelineCard({ t: (k) => seam.DICTS.zh[k] })
273
+ assert.ok(node !== null)
274
+ // 含统计行与「显示全部事件」开关
275
+ })
276
+ ```
277
+
278
+ - [ ] **Step 2: 运行确认失败**
279
+
280
+ Run: `node --test test/session-ui.test.mjs`
281
+ Expected: FAIL(`scaleFor`/`computeTimelineLayout` 未定义)。
282
+
283
+ - [ ] **Step 3: 实现纯函数**
284
+
285
+ 在 `lib/client.js`(`GraphView` 附近)新增:
286
+
287
+ ```js
288
+ const DAY_MS = 86400000
289
+ const TIMELINE_URL = '/api/memory/timeline'
290
+ const TIMELINE_NOISE = new Set(['note','digest','install','uninstall','setup','bootstrap','task','probe','recall','consolidate','ops','schedule','export'])
291
+ const TIMELINE_GROUPS = { fix:'修复', feat:'功能', publish:'发布', decision:'决策', other:'其他' } // 用 DICTS 文案
292
+ const timelineGroupOf = (kind) => ({ fix:'fix',bugfix:'fix',feat:'feat',feature:'feat',implement:'feat',impl:'feat',publish:'publish',release:'publish',deliverable:'publish',decision:'decision',design:'decision' })[kind] ?? 'other'
293
+ function scaleFor(pxPerDay) { return pxPerDay >= 30 ? 'day' : pxPerDay >= 7 ? 'week' : pxPerDay >= 1.6 ? 'month' : 'year' }
294
+ function visibleTimelineEvents(events, showAll) { return (events || []).filter((e) => showAll || !TIMELINE_NOISE.has(e.kind)) }
295
+ function initialTimelineOffset({ events, width, pxPerDay }) {
296
+ const list = visibleTimelineEvents(events, false)
297
+ if (list.length === 0) return 0
298
+ const last = Date.parse(list[list.length - 1].date + 'T00:00:00Z')
299
+ const first = Date.parse(list[0].date + 'T00:00:00Z')
300
+ const weekAgo = last - 7 * DAY_MS
301
+ const anchor = weekAgo > first ? weekAgo : first
302
+ return width - 40 - (last - anchor) / DAY_MS * pxPerDay
303
+ }
304
+ function computeTimelineLayout({ events, width, offset, pxPerDay, showAll }) {
305
+ // 线性时间轴;刻度按 scaleFor(pxPerDay) 生成;同日站点 ±9px / 上下交错;
306
+ // 标签按 x 排序做碰撞检测(左缘 - 上一右缘 < 8px 则跳过),22 字截断。
307
+ // 返回 { axis, ticks, stations, labels };所有坐标是 px。
308
+ }
309
+ ```
310
+
311
+ - [ ] **Step 4: 实现 TimelineCard + tab 容器 + 样式 + 文案**
312
+
313
+ - `ensureTimelineStyles()`:注入 `<style id="dsh-memory-timeline-style">`,类名 `dsh-mem-tl-*`;颜色用 `var(--dsw-alias-*, 兜底)`,站点色用 5 组 CSS 变量(深浅主题各一组,参考 `ensureGraphStyles` 现有做法)。
314
+ - `TimelineCard`:state(payload/status/offset/pxPerDay/showAll/selected/fetchedAt),`fetch(TIMELINE_URL)` + `setInterval(15000)`,失败静默保留旧数据;拖拽(pointer events)、wheel 缩放(`offset = mx - (mx - offset) * (next/px)`)、「回到今天」、`showAll` 开关、双击站点 → `openTimelineEvent(event)`。
315
+ - `openTimelineEvent`:`event.path` 存在 → 复用 `openInSidebar(path)` 的底层(从现有 `openInSidebar(id)` 抽出 `openMemoryFile(relPath)`,图谱节点路径走同一函数);无 path → 打开 `log.md` 并显示 `timelineNoPage` 文案。
316
+ - `MemorySection` 改为:tab 栏(图谱/时间轴)+ 条件渲染 `GraphCard` / `TimelineCard`(默认图谱;切 tab 才挂载该卡片)。`__test` 追加导出:`scaleFor`、`computeTimelineLayout`、`initialTimelineOffset`、`TimelineCard`、`openTimelineEvent`。
317
+
318
+ - [ ] **Step 5: 运行 client 测试 + 全量**
319
+
320
+ Run: `node --test test/session-ui.test.mjs` → PASS;`node --test` → 全绿;`npm test` → PASS。
321
+
322
+ - [ ] **Step 6: commit**
323
+
324
+ ```bash
325
+ git add lib/client.js test/session-ui.test.mjs
326
+ git commit -m "feat: memory panel timeline tab (single-line metro layout, zoom-linked scale, adaptive labels)"
327
+ ```
328
+
329
+ ---
330
+
331
+ ### Task 3: 文档、CHANGELOG 与发布前校验
332
+
333
+ **Files:**
334
+ - Modify: `README.md`、`README.zh.md`、`CHANGELOG.md`
335
+ - Modify: `package.json`(版本 0.20.0)
336
+ - 测试:全量
337
+
338
+ - [ ] **Step 1: README 功能段**:在 Features / 功能列表加「时间轴视图」条目(中英):记忆面板新增「时间轴」tab——单线地铁式横向滚动、拖动/滚轮缩放、缩放自动联动日/周/月/年、节点不拥挤时显示描述、单击看详情、双击打开文件、深浅主题跟随、默认只显示关键事件。
339
+ - [ ] **Step 2: CHANGELOG 0.20.0**:`### Added` 记录上述功能 + `GET /api/memory/timeline`。
340
+ - [ ] **Step 3: 版本**:`package.json` → `0.20.0`。
341
+ - [ ] **Step 4: 全量校验**:`node --test`、`npm test`、`npm pack --dry-run`(确认 files 含 lib/timeline.js)。
342
+
343
+ ---
344
+
345
+ ## Self-Review(spec 覆盖)
346
+
347
+ | Spec 要求 | 对应 Task |
348
+ |---|---|
349
+ | 面板 tab(图谱/时间轴) | Task 2 Step 4 |
350
+ | 单线 + 多色站点 | Task 2 computeTimelineLayout/TimelineCard |
351
+ | 拖动 + 滚轮缩放 + 自动粒度 | Task 2 Step 3/4 |
352
+ | 节点不拥挤显示描述 | Task 2 Step 3(标签碰撞) |
353
+ | 深浅主题跟随 | Task 2 Step 4(DSH 变量) |
354
+ | 默认关键事件 + 显示全部开关 | Task 2 Step 3(visibleTimelineEvents) |
355
+ | 单击详情 / 双击打开文件 | Task 2 Step 4 |
356
+ | 初始视口最近一周 | Task 2 Step 3(initialTimelineOffset) |
357
+ | `GET /api/memory/timeline` + 解析/匹配/容错 | Task 1 |
358
+ | README/CHANGELOG/版本 | Task 3 |
@@ -0,0 +1,153 @@
1
+ # 记忆面板 · 时间轴视图设计
2
+
3
+ > Status: draft(待阿周 review)
4
+ > 日期:2026-11-16
5
+ > 关联:dsh-plugin-memory(当前 0.19.5)、图谱面板(GraphCard/GraphView)
6
+ > 原型:`/tmp/memory-timeline-mockup/index.html`(v3:单线、缩放联动、双主题、标签自适应;不在仓库内)
7
+
8
+ ## 1. 目标
9
+
10
+ 在记忆面板(设置 → 记忆)里新增 **时间轴** 视图,与现有 **图谱** 视图通过 tab 切换。时间轴把 `log.md` 的事件按时间轴展示成「地铁线路」:单条主线、多色站点、可拖动/滚轮缩放、缩放自动联动 日/周/月/年 刻度、节点不拥挤时显示事件描述、深浅色主题自适应。
11
+
12
+ **已确认的交互**(阿周 2026-11-16):
13
+ 1. 单线(一条主线 + 多色站点),不做多车道。
14
+ 2. 缩放自动联动粒度(不手动切换日/周/月/年)。
15
+ 3. 默认只显示关键事件;勾选「显示全部事件」再显示笔记/过程类。
16
+ 4. 单击站点弹详情卡;**双击站点打开对应记忆文件**(复用图谱节点的侧栏打开逻辑)。
17
+ 5. 初始视口停在**最近一周**(最新事件在右端)。
18
+ 6. 深色/浅色两套主题(跟随 DSH 主题)。
19
+
20
+ ## 2. 非目标(YAGNI)
21
+
22
+ - 不做多车道(按类型分线)。
23
+ - 不做虚拟化/分页(首版 300 条量级直接渲染;超过 ~1000 条再评估)。
24
+ - 不新增记忆存储格式:时间轴数据全部从现有 `log.md` 与页面 frontmatter 派生。
25
+ - 不承诺每条事件都能打开页面:log 标题是自由文本,匹配不到时双击打开 `log.md`(见 §4.3)。
26
+
27
+ ## 3. 数据层(Host)
28
+
29
+ ### 3.1 新只读路由
30
+
31
+ `GET /api/memory/timeline`(与 `/api/memory/graph` 同风格,`webServer` 注册、`ctx.inject(['webServer'])`):
32
+
33
+ ```json
34
+ {
35
+ "events": [
36
+ { "date": "2026-11-12", "kind": "fix", "group": "fix", "title": "dsh-plugin-memory 0.19.5(健壮性加固…)", "path": "projects/active/dsh-plugin-memory.md" }
37
+ ],
38
+ "stats": { "events": 295, "first": "2026-08-18", "last": "2026-11-12", "pages": 56 }
39
+ }
40
+ ```
41
+
42
+ - `date`:`log.md` 中 `## [YYYY-MM-DD]` 的日期。
43
+ - `kind`:条目里的 kind(fix/feat/publish/decision/note/task/…,全量保留)。
44
+ - `title`:`|` 之后的标题文本。
45
+ - `group`:客户端使用的 5 类映射(fix/feat/publish/decision/other),host 侧提供以保证两端一致。
46
+ - `path`:可选;见 §4.3 的匹配规则;匹配不到省略该字段。
47
+ - `stats`:统计(事件数、起止日期、页面数),供面板顶部展示。
48
+
49
+ ### 3.2 解析规则
50
+
51
+ - 只解析 `log.md` 的 `## [date] kind | title` 行(当前 295 条;忽略其他行)。
52
+ - 过滤无效日期(非法日期跳过,不报错)。
53
+ - **不缓存**:每次请求重读 `log.md`(文件小、与图谱同样轻量);后续若日志增长再考虑 mtime 缓存。
54
+ - 解析失败(文件缺失/不可读)→ 返回空数组 + 200(只读、不抛错)。
55
+
56
+ ### 3.3 事件 → 页面匹配(双击打开用)
57
+
58
+ 按优先级匹配,匹配不到就 `path` 缺失:
59
+ 1. 标题包含某页面标题(frontmatter `title`)或文件名(不含 `.md`)→ 该页面路径。
60
+ 2. 标题包含 `projects/active/<name>`、`user/<name>` 之类的相对路径片段 → 直接对应。
61
+ 3. 都不中:不提供 `path`。
62
+
63
+ 双击行为(客户端):
64
+ - 有 `path`:走现有 `openInSidebar`/`openNode` 同一套逻辑(`dsh-resource://file/session/<sid>/<rel>`;工作区外回退系统文件管理器)。
65
+ - 无 `path`:在侧栏打开 `log.md`(整个文件),并提示「该事件没有对应页面,已打开 log.md」。
66
+
67
+ ## 4. 客户端视图
68
+
69
+ ### 4.1 结构(复用 GraphCard 的数据流)
70
+
71
+ ```
72
+ MemorySection
73
+ └─ MemoryPanelCard(新,包 GraphCard 与 TimelineCard)
74
+ ├─ tab 栏:图谱 | 时间轴
75
+ ├─ GraphCard(现有,原样保留;切到图谱时才轮询 graph)
76
+ └─ TimelineCard(新)
77
+ ├─ 顶部统计行(事件数 / 跨度 / 当前粒度)
78
+ ├─ toolbar(缩放联动提示、缩放按钮、回到今天、显示全部开关、图例)
79
+ ├─ stage(时间轴轨道:轴线、刻度、站点、标签)
80
+ └─ 详情卡(单击站点显示日期 + 类型 + 标题)
81
+ ```
82
+
83
+ - tab 状态只在内存中(默认「时间轴」还是「图谱」?——建议**保持图谱为默认**,与现状一致;时间轴是增强)。
84
+ - 切到图 tab 时才加载 graph;时间轴 tab 打开时拉 `/api/memory/timeline` 并按固定间隔(如 15s)轮询刷新。
85
+ - `TimelineCard` 复用 `GraphCard` 的刷新失败静默策略(保留上一次数据)。
86
+
87
+ ### 4.2 时间轴渲染(纯函数拆分,便于单测)
88
+
89
+ **坐标模型**:线性时间轴。`x = (t - minT) / DAY * pxPerDay + offset`。
90
+
91
+ - `pxPerDay`:连续缩放值(初始 54,范围 1.4–240)。
92
+ - `scaleFor(pxPerDay)`:`>=30 日`、`>=7 周`、`>=1.6 月`、否则 `年`。
93
+ - 刻度:日视图每 ≥7 天、周视图每 2 周(周一起)、月视图每月 1 日、年视图每年 1 月 1 日。
94
+ - 站点:按事件日期定位;同日多事件水平 ±9px、上下交错(`j % 2`)。
95
+ - 站点尺寸/颜色按 group(fix/feat/publish 13px、decision 14px、other 10px)。
96
+ - **标签自适应**:按 x 排序后顺序放置,若标签左边缘与上一个标签右边缘间距 < 8px 则跳过该标签(只留圆点);标签最多 22 字截断,max-width 200px。
97
+ - **初始视口**:最近一周——把 `[maxT - 7d, maxT]` 放进视口右侧:`offset = W - 40 - (maxT - minT)/DAY*pxPerDay` 的基础上,偏移到让 maxT 在右侧 40px 内、且最近 7 天可见(即视口宽度不足 7 天时以 maxT 为准)。
98
+ - 「回到今天」:重置到上述初始视口。
99
+ - 交互:`pointerdown/move/up` 拖动平移(clamp 到数据范围两端);`wheel` 缩放(围绕鼠标位置:`offset = mx - (mx - offset) * (newPx/oldPx)`);缩放后自动重算 scale/刻度/标签。
100
+
101
+ ### 4.3 过滤
102
+
103
+ - 默认只显示「关键事件」:`group !== 'other'` 或 group === 'other' 但 kind 属于关键集合?——简化:**默认排除过程的 kind**(note/digest/install/uninstall/setup/bootstrap/task/probe/recall/consolidate/ops/schedule/export),其余显示(与原型 v3 一致,约 250 条)。
104
+ - 勾选「显示全部事件」→ 全量。
105
+ - 过滤在客户端(host 返回全量),统计行显示 `显示 X / 全部 Y`。
106
+
107
+ ### 4.4 主题
108
+
109
+ - **跟随 DSH 主题**:所有颜色用 DSH 变量 + fallback,例如
110
+ - 文本:`var(--dsw-alias-label-primary, #...)`
111
+ - 次级:`var(--dsw-alias-label-secondary, ...)`
112
+ - 边框:`var(--dsw-alias-border-l2, ...)`
113
+ - 背景:`var(--dsw-alias-bg-layer-1/2, ...)`
114
+ - 站点颜色在两套主题下的对比度用 CSS 变量组(亮/暗各一组),参考图谱现有做法。
115
+ - 不新增独立主题切换按钮(跟随宿主);原型里的 ◐ 只用于演示。
116
+
117
+ ### 4.5 打开文件
118
+
119
+ - 双击站点 → 与图谱节点一致:host 的 `/api/memory/session` / 客户端 `openInSidebar`;失败提示文案复用 `graphSidebarFailed`/`graphSidebarOutside`,新增 `timelineNoPage`("该事件没有对应页面,已打开 log.md")。
120
+
121
+ ## 5. 改动清单
122
+
123
+ | 文件 | 改动 |
124
+ |---|---|
125
+ | `lib/timeline.js`(新) | 解析 `log.md` → events + stats(纯函数,可单测) |
126
+ | `lib/index.js` | 注册 `GET /api/memory/timeline`;导出 `buildTimeline` |
127
+ | `lib/client.js` | 新增 `TimelineCard`、tab 容器、标签/刻度/缩放纯函数;复用 `openInSidebar`;新增文案(中英) |
128
+ | `lib/types/index.d.ts` | 新 API 类型(TimelineEvent/TimelinePayload) |
129
+ | `test/timeline.test.mjs`(新) | host 解析(含异常/空/非法日期)、group 映射、path 匹配 |
130
+ | `test/session-ui.test.mjs`(扩) | TimelineCard 渲染(vm + React stub:站点数量、标签自适应阈值、缩放联动 scaleFor、初始视口最近一周) |
131
+ | `README.md` / `README.zh.md` | 功能描述加「时间轴视图」 |
132
+ | `docs/CONFIGURATION.md` | 无需新增配置项(纯只读视图) |
133
+
134
+ ## 6. 测试计划
135
+
136
+ - host:解析真实 log 片段(fixture)、空文件、损坏文件、无 `##`、未知 kind、匹配到/匹配不到页面。
137
+ - client 纯函数:`scaleFor` 边界(30/7/1.6)、`layout` 刻度生成、标签碰撞(拥挤/不拥挤)、初始视口计算(最近一周)。
138
+ - client 渲染:TimelineCard 在 fake React 下渲染(统计行、站点 DOM、详情卡点击);tab 切换(图谱 ↔ 时间轴)。
139
+ - 回归:现有 341 测试全绿 + self-test。
140
+
141
+ ## 7. 风险与边界
142
+
143
+ 1. **log 事件↔页面匹配不保证**:只做标题/路径模糊匹配,匹配不到时双击打开 log.md;文档与 UI 文案明确。
144
+ 2. **纯文本标题的 XSS**:所有标题经 `escapeHtml`(沿用现有工具),不注入 HTML。
145
+ 3. **性能**:300–1000 站点直接 DOM 渲染可接受;标签计算 O(n log n)。超 1000 条再考虑 canvas/虚拟化。
146
+ 4. **时区**:日期按 `YYYY-MM-DD` 解析为 UTC 日(避免本地时区跨日漂移),展示用本地日期字符串(log 本身是本地记录)。
147
+ 5. **主题变量缺失**(老版本宿主):全部变量带 fallback,退化到当前深浅色。
148
+ 6. **rc.2 兼容**:纯增量(新路由 + 新视图),复用已有 `webServer`/`slots`/`openInSidebar` 路径;不触碰 `agents.roots` 等敏感面。
149
+
150
+ ## 8. 待定(review 时确认)
151
+
152
+ - tab 默认落在「图谱」还是「时间轴」?(建议图谱,保持现状)
153
+ - 「显示全部事件」开关默认关(关键事件),确认。