@yolk_vat-y/dsh-project-memory 0.6.1 → 0.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolk_vat-y/dsh-project-memory",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Persistent project memory for dsh agents: index docs (PDF/Markdown/text) and code symbols into a searchable per-workspace store, recall them with cited sources, and keep experience entries (problems -> solutions) searchable on demand.",
5
5
  "author": "00080000 <3388065969@qq.com>",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "url": "https://github.com/00080000/dsh-project-memory.git"
20
20
  },
21
21
  "scripts": {
22
- "test": "node test/run-test.mjs && node test/taskbridge.test.mjs && node test/insight-store.test.mjs && node test/reflection-pipeline.test.mjs && node test/auto-inject.test.mjs && node test/insight-actions.test.mjs && node test/host-contract.test.mjs && node test/llm-route.test.mjs && node test/doc-index.test.mjs && node test/chunker.test.mjs && node test/client-hints.test.mjs && node test/recall.test.mjs && node test/recall-vector-fusion.test.mjs && node test/vector-index.test.mjs && node test/readiness.test.mjs && node test/insight-derive.test.mjs && node test/readiness-eval.test.mjs && node test/ops.test.mjs && node test/injection-audit.test.mjs && node test/injection-budget.test.mjs && node test/injection-scenarios.test.mjs && node test/bugfix-0.5.7.test.mjs && node test/client-icons.test.mjs && node test/client-slash.test.mjs && node test/client-toolview.test.mjs && node test/workflow-command.test.mjs && node test/client-session-id.test.mjs && node test/client-degraded.test.mjs && node test/watch-idle.test.mjs && node test/citation-paths.test.mjs && node test/task-view.test.mjs && node test/root-guards.test.mjs && node test/store-gitignore.test.mjs && node test/atomic-write.test.mjs && node test/store-cache.test.mjs && node test/enhancer.test.mjs",
22
+ "test": "node test/run-test.mjs && node test/taskbridge.test.mjs && node test/insight-store.test.mjs && node test/reflection-pipeline.test.mjs && node test/auto-inject.test.mjs && node test/insight-actions.test.mjs && node test/insight-paging.test.mjs && node test/config-schema.test.mjs && node test/host-contract.test.mjs && node test/session-dir.test.mjs && node test/llm-route.test.mjs && node test/doc-index.test.mjs && node test/chunker.test.mjs && node test/client-hints.test.mjs && node test/client-paging.test.mjs && node test/client-task-sync.test.mjs && node test/recall.test.mjs && node test/recall-vector-fusion.test.mjs && node test/vector-index.test.mjs && node test/readiness.test.mjs && node test/insight-derive.test.mjs && node test/readiness-eval.test.mjs && node test/ops.test.mjs && node test/injection-audit.test.mjs && node test/injection-budget.test.mjs && node test/injection-scenarios.test.mjs && node test/bugfix-0.5.7.test.mjs && node test/client-icons.test.mjs && node test/client-slash.test.mjs && node test/client-toolview.test.mjs && node test/workflow-command.test.mjs && node test/client-session-id.test.mjs && node test/client-degraded.test.mjs && node test/watch-idle.test.mjs && node test/citation-paths.test.mjs && node test/task-view.test.mjs && node test/root-guards.test.mjs && node test/store-gitignore.test.mjs && node test/atomic-write.test.mjs && node test/store-cache.test.mjs && node test/enhancer.test.mjs",
23
23
  "eval:injection": "node test/injection-scenarios.test.mjs",
24
24
  "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.client.json",
25
25
  "selfcheck:triggers": "node test/injection-scenarios.test.mjs --selfcheck",
@@ -52,12 +52,12 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@deepseek-ai/cordis": "^4.0.4",
55
- "@deepseek-ai/dsh-client-locale": "0.2.0-rc.2",
56
- "@deepseek-ai/dsh-client-store": "0.2.0-rc.2",
57
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.0-rc.2",
58
- "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.2",
59
- "@deepseek-ai/dsh-llm": "0.2.0-rc.2",
60
- "@deepseek-ai/dsh-tools": "0.2.0-rc.2",
55
+ "@deepseek-ai/dsh-client-locale": "0.2.1-rc.2",
56
+ "@deepseek-ai/dsh-client-store": "0.2.1-rc.2",
57
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.2",
58
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.2",
59
+ "@deepseek-ai/dsh-llm": "0.2.1-rc.2",
60
+ "@deepseek-ai/dsh-tools": "0.2.1-rc.2",
61
61
  "@deepseek-ai/schemastery": "^3.18.2",
62
62
  "@tsdown/css": "0.22.14",
63
63
  "@types/react": "^18.3.31",
@@ -91,6 +91,9 @@
91
91
  }
92
92
  },
93
93
  "dsh": {
94
+ "engines": {
95
+ "dsh": ">=0.0.1-rc.1 <0.1.0 || >=0.1.0-rc.1 <0.3.0-0"
96
+ },
94
97
  "bundle": {
95
98
  "patch": "./cordis.patch.yml"
96
99
  },
@@ -14,6 +14,7 @@ import { stepContent } from './util/task-view.js'
14
14
  import { insightMatchText, normalizedTokenOverlap } from './similarity.js'
15
15
  import { createVectorRerank, vectorItemsFrom } from './vector-index.js'
16
16
  import { BoundedMap, SessionCache } from './util/session-cache.js'
17
+ import { sessionWorkingDir } from './util/session-dir.js'
17
18
  import { cfgInsight, GlobalStore, defaultGlobalFile, recordHit } from './insight-store.js'
18
19
  import { projectTags } from './project-profile.js'
19
20
  import { rankEntriesMergedScored } from './util/search.js'
@@ -136,6 +137,27 @@ export function cfgEngine(config) {
136
137
  }
137
138
  }
138
139
 
140
+ /**
141
+ * 给写入路径(`save_lesson` / `remember`)用的向量打分器:**没装/没配就是 null**。
142
+ *
143
+ * 与注入路径共用一个解析入口(`cfgEngine` + `createVectorRerank`),所以"装了 leanvec 就用、
144
+ * 没装就纯词法"这条规则只有一处实现、一处配置。返回的函数是同步的,供 `saveInsight` 在
145
+ * 写事务里直接调用;任何异常都降级成 null,绝不因为可选的向量层挡住写入。
146
+ * @param {object} config - 插件配置
147
+ * @param {{storeDir: string|null, items: object[]}} o - 持久化位置与候选池(见 vectorItemsFrom)
148
+ * @returns {Promise<((text: string, items: object[]) => Map<string, number>)|null>}
149
+ */
150
+ export async function createWriteCosine(config, { storeDir = null, items = [] } = {}) {
151
+ const engine = cfgEngine(config)
152
+ try {
153
+ const rerank = await createVectorRerank({ storeDir, items, vectorDir: engine.vectorDir, alpha: engine.vectorAlpha })
154
+ if (!rerank || typeof rerank.score !== 'function') return null
155
+ return (text, cands) => rerank.score(text, cands)
156
+ } catch {
157
+ return null
158
+ }
159
+ }
160
+
139
161
  export function lastUserText(messages) {
140
162
  if (!Array.isArray(messages)) return ''
141
163
  let fallback = ''
@@ -681,7 +703,9 @@ function warnUnsafeSessionRoot(root) {
681
703
  */
682
704
  async function injectForStep({ payload, decision, config, cfg, audit, shadow, sessions }) {
683
705
  const session = payload && payload.agent && payload.agent.session
684
- const cwd = session && session.header && session.header.cwd
706
+ // 与工具侧同一口径的「当前工作目录」:0.2.1+ 走 workingDirectory 投影(cd 后会变),
707
+ // 老宿主回退 header.cwd。少了这一步,cd 之后审计与懒索引会落在两个不同的 store 里。
708
+ const cwd = sessionWorkingDir(session, { agent: payload?.agent })
685
709
  const sessionId = session && session.id
686
710
  if (!cwd || !sessionId) return null
687
711
  // 会话 cwd 是家目录/系统目录时整条链路停在这里:不读 store(历史遗留的超大 store
@@ -2,10 +2,14 @@
2
2
  * Memory View — 记忆三作用域列表(Task 草稿 / Project / Global)
3
3
  * 数据通道与任务面板一致:remote.commands.execute 执行 /insight 命令,取 JSON 载荷。
4
4
  * 动作:confirm(草稿审核) / promote(向上提升) / demote(向下降级,需绑定任务) / archive / restore / delete
5
+ *
6
+ * 列表是**增量加载**的:首屏只取 PAGE_SIZE 条,滚到底前 600px 预取下一页追加。
7
+ * 分页的决策逻辑在 ./paging.js(纯函数,可单测),本组件只把它接到渲染上。
5
8
  */
6
9
  import { useEffect, useCallback, useRef, useState } from 'react'
7
10
  import { Button } from '@deepseek-ai/dsh-client-ui-primitives'
8
11
  import { service } from './services.ts'
12
+ import { PAGE_SIZE, PREFETCH_MARGIN, SPINNER_DELAY_MS, appendUnique, createRequestGate, insightListLine, normalizeWindow, progressCounts, reloadWindowRequest } from './paging.js'
9
13
  import css from './TaskPanel.module.css'
10
14
 
11
15
  export type InsightScope = 'task' | 'project' | 'global'
@@ -39,6 +43,9 @@ export interface InsightRow {
39
43
  interface ListPayload {
40
44
  scope: InsightScope
41
45
  count: number
46
+ total: number
47
+ offset: number
48
+ nextOffset: number | null
42
49
  items: InsightRow[]
43
50
  }
44
51
 
@@ -55,7 +62,10 @@ export function parseInsightPayloadText(text?: string | null): ListPayload | nul
55
62
  try {
56
63
  const data = JSON.parse(jsonBlock)
57
64
  if (!Array.isArray(data.items)) return null
58
- return { scope: data.scope ?? 'project', count: data.count ?? data.items.length, items: data.items }
65
+ // 分页字段走 paging.js 归一:老宿主没有 total/nextOffset 时按"一次给全"降级,
66
+ // 新宿主则给出真实的下一页游标。
67
+ const w = normalizeWindow(data, 0)
68
+ return { scope: data.scope ?? 'project', count: w.total, total: w.total, offset: w.offset, nextOffset: w.nextOffset, items: w.items }
59
69
  } catch {
60
70
  return null
61
71
  }
@@ -86,14 +96,23 @@ export function MemoryView({
86
96
  showHints: boolean
87
97
  t: any
88
98
  }) {
89
- const [payload, setPayload] = useState<ListPayload | null>(null)
99
+ const [rows, setRows] = useState<InsightRow[]>([])
100
+ const [total, setTotal] = useState(0)
101
+ const [nextOffset, setNextOffset] = useState<number | null>(null)
90
102
  const [error, setError] = useState<string | null>(null)
91
103
  const [loading, setLoading] = useState(false)
104
+ const [loadingMore, setLoadingMore] = useState(false)
105
+ // 加载指示延迟显示:本地数据几十毫秒就回来,立刻显示只会"闪一下"(见 paging.js)。
106
+ const [showSpinner, setShowSpinner] = useState(false)
92
107
  const [busy, setBusy] = useState(false)
93
108
  const [showNew, setShowNew] = useState(false)
94
109
  const [editingId, setEditingId] = useState<string | null>(null)
95
110
  const [form, setForm] = useState({ title: '', kind: 'lesson', body: '', steps: '', trigger: '' })
96
111
  const [savedTip, setSavedTip] = useState<string | null>(null)
112
+ // 滚动容器(IntersectionObserver 的 root):哨兵是否"可见"必须相对这个容器判定,
113
+ // 用视口当 root 会让面板自身的 480px 上限失效。
114
+ const scrollRef = useRef<HTMLDivElement | null>(null)
115
+ const sentinelRef = useRef<HTMLDivElement | null>(null)
97
116
 
98
117
  const runLine = useCallback(
99
118
  async (line: string): Promise<{ ok: boolean; text: string }> => {
@@ -116,46 +135,113 @@ export function MemoryView({
116
135
  [ctx, sessionId],
117
136
  )
118
137
 
119
- // 用 ref 做并发/频控守卫:loading 状态不能进 refresh 的依赖数组,
120
- // 否则 loading 每次翻转都会重建 refresh → effect 重跑 → 无限循环刷 /insight 命令。
121
- const inflightRef = useRef(false)
122
- const lastRunRef = useRef(0)
138
+ // 并发控制走 paging.js 的 createRequestGate():过期响应丢弃、新请求照发。
139
+ // (早期用"有在途请求就 return"的布尔守卫时,切 scope 的新请求会被直接丢掉,
140
+ // 新列表于是一直空着——见 createRequestGate 的注释。)
141
+ const gateRef = useRef<ReturnType<typeof createRequestGate> | null>(null)
142
+ if (gateRef.current === null) gateRef.current = createRequestGate()
143
+ // 作用域变了之后到达的过期响应必须丢弃,否则会把上一个 scope 的条目追加进来。
144
+ const scopeRef = useRef(scope)
145
+ useEffect(() => {
146
+ scopeRef.current = scope
147
+ }, [scope])
123
148
 
124
- const refresh = useCallback(async (force = false): Promise<void> => {
125
- // 没有活跃会话时不发命令、也不报错:面板顶部已经显示「还没有会话」,
126
- // 再报一次"同步失败"会让人以为记忆库坏了(0.1.7 上会话快照结构变化时就是这个表象)。
127
- if (!sessionId) {
128
- setPayload(null)
129
- setError(null)
130
- setLoading(false)
131
- return
132
- }
133
- if (inflightRef.current) return
134
- const now = Date.now()
135
- if (!force && now - lastRunRef.current < 800) return
136
- inflightRef.current = true
137
- lastRunRef.current = now
138
- setLoading(true)
139
- setError(null)
140
- try {
141
- const res = await runLine(`/tasks insight list ${scope}`)
142
- if (!res.ok) {
143
- setError(res.text)
144
- setPayload(null)
149
+ /**
150
+ * 取一页并落到状态里。
151
+ * @param offset 起始下标。
152
+ * @param limit 本页条数。
153
+ * @param append true=追加到已渲染列表;false=替换成这一页(首屏或前缀重放)。
154
+ */
155
+ const load = useCallback(
156
+ async (offset: number, limit: number, append: boolean): Promise<void> => {
157
+ // 没有活跃会话时不发命令、也不报错:面板顶部已经显示「还没有会话」,
158
+ // 再报一次"同步失败"会让人以为记忆库坏了(0.1.7 上会话快照结构变化时就是这个表象)。
159
+ if (!sessionId) {
160
+ setRows([])
161
+ setTotal(0)
162
+ setNextOffset(null)
163
+ setError(null)
164
+ setLoading(false)
145
165
  return
146
166
  }
147
- const parsed = parseInsightPayloadText(res.text)
148
- setPayload(parsed)
149
- if (!parsed) setError('unparsable payload')
150
- } finally {
151
- inflightRef.current = false
152
- setLoading(false)
153
- }
154
- }, [runLine, scope])
167
+ const requestedScope = scopeRef.current
168
+ const key = `${requestedScope}|${offset}|${limit}|${append}`
169
+ const ticket = gateRef.current!.begin(key)
170
+ if (ticket === false) return
171
+ if (!append) setLoading(true)
172
+ setLoadingMore(append)
173
+ setError(null)
174
+ const spinner = window.setTimeout(() => setShowSpinner(true), SPINNER_DELAY_MS)
175
+ try {
176
+ const res = await runLine(insightListLine(requestedScope, offset, limit))
177
+ // 已被更新的请求取代,或切了作用域:这份响应属于上一个列表,整份丢弃。
178
+ if (gateRef.current!.isStale(ticket, requestedScope, scopeRef.current)) return
179
+ if (!res.ok) {
180
+ setError(res.text)
181
+ return
182
+ }
183
+ const parsed = parseInsightPayloadText(res.text)
184
+ if (!parsed) {
185
+ setError('unparsable payload')
186
+ return
187
+ }
188
+ setRows((prev) => (append ? appendUnique(prev, parsed.items) : parsed.items))
189
+ setTotal(parsed.total)
190
+ setNextOffset(parsed.nextOffset)
191
+ } finally {
192
+ window.clearTimeout(spinner)
193
+ // 加载标志只由最后一次请求回落:过期请求提前清掉会让界面"看起来加载完了"。
194
+ if (gateRef.current!.end(key, ticket)) {
195
+ setShowSpinner(false)
196
+ setLoading(false)
197
+ setLoadingMore(false)
198
+ }
199
+ }
200
+ },
201
+ [runLine, sessionId],
202
+ )
203
+
204
+ // load 的身份随 runLine 变(ctx/sessionId 变化);用 ref 持有它,让下面的 effect
205
+ // 只依赖 scope/sessionId 这两个**原始值**——把函数身份拉进依赖会重跑 effect 并
206
+ // 无限刷 /insight 命令(旧实现用 800ms 频控绕开,这里从根上避免)。
207
+ const loadRef = useRef(load)
208
+ useEffect(() => {
209
+ loadRef.current = load
210
+ }, [load])
155
211
 
156
212
  useEffect(() => {
157
- void refresh()
158
- }, [refresh])
213
+ // 换 scope / 换会话 = 换了一个列表:清空并从头取第一页。
214
+ setRows([])
215
+ setTotal(0)
216
+ setNextOffset(null)
217
+ setError(null)
218
+ if (!sessionId) return
219
+ void loadRef.current(0, PAGE_SIZE, false)
220
+ }, [scope, sessionId])
221
+
222
+ // 滚到底之前就取下一页(rootMargin 600px)。哨兵消失(nextOffset=null)即停止。
223
+ useEffect(() => {
224
+ if (nextOffset === null || typeof IntersectionObserver === 'undefined') return
225
+ const sentinel = sentinelRef.current
226
+ if (!sentinel) return
227
+ const observer = new IntersectionObserver(
228
+ (entries) => {
229
+ if (entries.some((e) => e.isIntersecting)) void loadRef.current(nextOffset, PAGE_SIZE, true)
230
+ },
231
+ // root 用面板自己的滚动容器;取不到时退回视口(仍比"不加载"好)。
232
+ { root: scrollRef.current ?? null, rootMargin: PREFETCH_MARGIN },
233
+ )
234
+ observer.observe(sentinel)
235
+ return () => observer.disconnect()
236
+ }, [nextOffset, rows.length])
237
+
238
+ /**
239
+ * 重载**已加载的整个前缀**(不是重置成第一页):动作之后用户的位置不该跳回顶部。
240
+ */
241
+ const reloadWindow = useCallback(async (): Promise<void> => {
242
+ const { offset, limit } = reloadWindowRequest(rows.length)
243
+ await loadRef.current(offset, limit, false)
244
+ }, [rows.length])
159
245
 
160
246
  const act = async (action: string, id: string): Promise<void> => {
161
247
  if (busy) return
@@ -165,7 +251,7 @@ export function MemoryView({
165
251
  const line = `/tasks insight ${action} ${scope} ${id}${action === 'demote' && scope === 'project' && boundTaskId ? ` ${boundTaskId}` : ''}`
166
252
  const res = await runLine(line)
167
253
  if (!res.ok) setError(res.text)
168
- else void refresh(true)
254
+ else await reloadWindow()
169
255
  } finally {
170
256
  setBusy(false)
171
257
  }
@@ -249,28 +335,29 @@ export function MemoryView({
249
335
  setSavedTip(t('mem.saved'))
250
336
  closeForm()
251
337
  window.setTimeout(() => setSavedTip(null), 2500)
252
- void refresh(true)
338
+ await reloadWindow()
253
339
  }
254
340
  } finally {
255
341
  setBusy(false)
256
342
  }
257
343
  }
258
344
 
259
- const items = payload?.items ?? []
345
+ const items = rows
346
+ const progress = progressCounts(items.length, total)
260
347
 
261
348
  return (
262
- <div className={css.memoryPane}>
349
+ <div className={css.memoryPane} ref={scrollRef}>
263
350
  <div className={css.memToolbar}>
264
351
  <span className={css.memCount}>
265
352
  {scope === 'task' ? t('mem.scope.task') : scope === 'global' ? t('mem.scope.global') : t('mem.scope.project')}
266
- {payload ? ` · ${payload.count}` : ''}
353
+ {total > 0 ? ` · ${total}` : ''}
267
354
  </span>
268
355
  <span className={css.memToolbarActs}>
269
356
  {savedTip && <span className={css.badge}>{savedTip}</span>}
270
357
  {scope !== 'task' && !showNew && (
271
358
  <Button variant="outline" size="sm" disabled={busy} onClick={() => { setShowNew(true); setEditingId(null); setError(null) }}>{t('mem.new')}</Button>
272
359
  )}
273
- <Button variant="outline" size="sm" onClick={() => void refresh(true)} disabled={loading} title={showHints ? t('panel.refresh') : undefined} aria-label={t('panel.refresh')}>
360
+ <Button variant="outline" size="sm" onClick={() => void reloadWindow()} disabled={loading} title={showHints ? t('panel.refresh') : undefined} aria-label={t('panel.refresh')}>
274
361
  ↻
275
362
  </Button>
276
363
  </span>
@@ -307,7 +394,14 @@ export function MemoryView({
307
394
  </div>
308
395
  </div>
309
396
  )}
310
- {error && <div className={css.notice}>{t('mem.error')}: {error}</div>}
397
+ {error && (
398
+ <div className={css.notice}>
399
+ {t('mem.error')}: {error}
400
+ {/* 失败必须给出口:增量加载里"卡住不动"和"已经加载完"外观一样,没有重试按钮
401
+ 用户只能靠开关面板碰运气。 */}
402
+ <Button variant="outline" size="sm" disabled={loading || loadingMore} onClick={() => void reloadWindow()}>{t('mem.retry')}</Button>
403
+ </div>
404
+ )}
311
405
  {loading && !items.length && <div className={css.muted}>{t('mem.loading')}</div>}
312
406
  {!loading && !error && items.length === 0 && <div className={css.muted}>{t('mem.empty')}</div>}
313
407
  <div className={css.memList}>
@@ -355,6 +449,25 @@ export function MemoryView({
355
449
  </div>
356
450
  )
357
451
  })}
452
+ {/* 增量加载哨兵 + 页脚。预取由上面的 IntersectionObserver 驱动(滚到底前 600px),
453
+ 这里只负责:① 放哨兵;② 把"已显示 N / 总数"讲清楚,让无限滚动可预期;
454
+ ③ 环境没有 IntersectionObserver 时退化成手动按钮,绝不静默停住。 */}
455
+ {items.length > 0 && (
456
+ <div className={css.memFooter}>
457
+ {nextOffset !== null && <div ref={sentinelRef} className={css.memSentinel} aria-hidden="true" />}
458
+ {nextOffset !== null && typeof IntersectionObserver === 'undefined' && (
459
+ <Button variant="outline" size="sm" disabled={loadingMore} onClick={() => void loadRef.current(nextOffset, PAGE_SIZE, true)}>
460
+ {t('mem.loadMore')}
461
+ </Button>
462
+ )}
463
+ <span className={css.muted}>
464
+ {progress.loaded < progress.total
465
+ ? t('mem.progress', { loaded: progress.loaded, total: progress.total })
466
+ : t('mem.allLoaded', { total: progress.total })}
467
+ {showSpinner && loadingMore ? ` · ${t('mem.loadingMore')}` : ''}
468
+ </span>
469
+ </div>
470
+ )}
358
471
  </div>
359
472
  </div>
360
473
  )
@@ -33,6 +33,7 @@ export function TaskCommandNode({ node }: { node?: any }) {
33
33
  tasks: parsedTasks.tasks,
34
34
  boundTaskId: parsedTasks.boundId,
35
35
  archivedCount: parsedTasks.archived,
36
+ root: parsedTasks.root,
36
37
  })
37
38
  if (isList) taskUIStore.actions.open()
38
39
  }, [text])
@@ -163,6 +163,10 @@
163
163
  background: var(--dsw-alias-bg-base, transparent);
164
164
  overflow: hidden;
165
165
  transition: border-color 0.15s ease;
166
+ /* 与 .memRow 同款的窗口化:任务多/卡片展开后离屏卡片不再参与 layout/paint。
167
+ 用 `auto` 记住实测高度,折叠/展开切换不会算错。 */
168
+ content-visibility: auto;
169
+ contain-intrinsic-size: auto 140px;
166
170
  }
167
171
  .cardBound {
168
172
  border-color: var(--dsw-alias-border-l3, rgba(127, 127, 127, 0.35));
@@ -686,6 +690,20 @@
686
690
  flex-direction: column;
687
691
  gap: 6px;
688
692
  }
693
+ /* 增量加载哨兵:0 高、不可见,只作为 IntersectionObserver 的观察目标。 */
694
+ .memSentinel {
695
+ height: 1px;
696
+ flex: none;
697
+ }
698
+ /* 页脚状态行:"已显示 N / 总数" + 加载中/已全部加载。让无限滚动可预期,也便于排查。 */
699
+ .memFooter {
700
+ display: flex;
701
+ flex-direction: column;
702
+ align-items: center;
703
+ gap: 4px;
704
+ padding: 6px 0 2px;
705
+ font-size: 12px;
706
+ }
689
707
  .memRow {
690
708
  border: 1px solid var(--dsw-border-weak, rgba(128, 128, 128, 0.25));
691
709
  border-radius: 6px;
@@ -694,6 +712,11 @@
694
712
  flex-direction: column;
695
713
  gap: 4px;
696
714
  background: color-mix(in srgb, var(--dsw-bg-secondary, #f5f5f5) 45%, transparent);
715
+ /* 窗口化:离屏行跳过 layout/paint,但 DOM 仍在 —— 保留 find-in-page 与无障碍,
716
+ 且不必手写虚拟列表(可变行高的 JS 虚拟化是坑)。`auto` 让浏览器记住每行实测高度,
717
+ 所以可变行高也准。不支持的宿主自动退化为普通渲染,零风险。 */
718
+ content-visibility: auto;
719
+ contain-intrinsic-size: auto 76px;
697
720
  }
698
721
  .memRowArchived {
699
722
  opacity: 0.55;
@@ -14,7 +14,7 @@ import {
14
14
  } from './icons.ts'
15
15
  import { createTranslate, zh, en } from './locales.ts'
16
16
  import { missingServices, service } from './services.ts'
17
- import { useTaskData, useTaskDataActions, taskDataStore, parseTaskPayloadText, type TaskStep } from './task-data-store.ts'
17
+ import { useTaskData, useTaskDataActions, parseTaskPayloadText, type TaskStep } from './task-data-store.ts'
18
18
  import { useTaskUI, useTaskUIActions, PANEL_VIEWS } from './task-ui-store.ts'
19
19
  import { MiniBar, TaskCard } from './TaskComponents.tsx'
20
20
  import { MemoryView, type InsightScope } from './MemoryView.tsx'
@@ -102,7 +102,7 @@ function TaskPanelView({ ctx }: { ctx: any }) {
102
102
  const applyPayload = (text?: string): boolean => {
103
103
  const parsed = parseTaskPayloadText(text)
104
104
  if (!parsed) return false
105
- dataActions.setTasks({ tasks: parsed.tasks, boundTaskId: parsed.boundId, archivedCount: parsed.archived })
105
+ dataActions.setTasks({ tasks: parsed.tasks, boundTaskId: parsed.boundId, archivedCount: parsed.archived, root: parsed.root })
106
106
  setSyncedAt(Date.now())
107
107
  setSyncError(null)
108
108
  return true
@@ -133,16 +133,22 @@ function TaskPanelView({ ctx }: { ctx: any }) {
133
133
  return applyPayload(result?.text)
134
134
  }
135
135
 
136
+ /**
137
+ * 只取数据,**不**顺手 switch。
138
+ *
139
+ * 旧实现在这里补一次 `/tasks switch <boundId>`(条件是"新 boundId 与内存里的不同"),
140
+ * 意图是刷新后让宿主 todo 跟随绑定任务。但那是多余的:宿主的 todo 清单是
141
+ * `sessionProjections` 里的 `todos` 单元(由 `todo/write` 事件折叠而来),重启/换标签页
142
+ * 都会从会话日志重建,不需要谁再推一次;而 switch 会 `session.append('todo/write')`,
143
+ * 于是"打开面板/切一次会话"就写一次会话历史(还顺手刷新任务的 lastActiveAt)。
144
+ * 真正的绑定动作都有明确入口:`select_task`、`/tasks switch`、面板卡片的切换按钮,
145
+ * 它们各自会推宿主清单(adoptStepsToSession),不需要巡检式补写。
146
+ */
136
147
  const refresh = async (): Promise<void> => {
137
148
  if (syncing) return
138
149
  setSyncing(true)
139
150
  try {
140
- const prevBoundId = data.boundTaskId
141
151
  await runLine('/tasks')
142
- const newBoundId = taskDataStore.getSnapshot().boundTaskId
143
- if (newBoundId && newBoundId !== prevBoundId) {
144
- await runLine(`/tasks switch ${newBoundId}`)
145
- }
146
152
  } finally {
147
153
  setSyncing(false)
148
154
  }
@@ -59,6 +59,11 @@ export const zh = {
59
59
  'mem.draft': '草稿',
60
60
  'mem.archived': '已归档',
61
61
  'mem.loading': '加载中…',
62
+ 'mem.loadingMore': '加载中…',
63
+ 'mem.loadMore': '加载更多',
64
+ 'mem.progress': '已显示 {loaded} / {total}',
65
+ 'mem.allLoaded': '已全部加载({total} 条)',
66
+ 'mem.retry': '重试',
62
67
  'mem.error': '同步失败',
63
68
  'mem.kind.lesson': '坑',
64
69
  'mem.kind.decision': '权衡',
@@ -143,6 +148,11 @@ export const en = {
143
148
  'mem.draft': 'draft',
144
149
  'mem.archived': 'archived',
145
150
  'mem.loading': 'Loading…',
151
+ 'mem.loadingMore': 'Loading…',
152
+ 'mem.loadMore': 'Load more',
153
+ 'mem.progress': 'Showing {loaded} of {total}',
154
+ 'mem.allLoaded': 'All {total} loaded',
155
+ 'mem.retry': 'Retry',
146
156
  'mem.error': 'Sync failed',
147
157
  'mem.kind.lesson': 'lesson',
148
158
  'mem.kind.decision': 'decision',