@restregular/dsh-memory 0.14.1 → 0.14.2

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,12 @@
2
2
 
3
3
  本项目的版本记录。安装 id 与 npm 版本一一对应。
4
4
 
5
+ ## 0.14.2 — 修复轨迹 callId 解析,审计页签不再全空;行内有审计图标
6
+
7
+ - **根因**:Trajectory 把 `trajectoryVirtualRecordKey()` 的结果写入 `data-trajectory-row-key`,而该函数会先 `encodeURIComponent`,DOM 上实际是 `tool%00call%00<callId>`。旧解析按原始 `\0call\0` 分隔符找,永远拿不到 callId,详情页签就用空锚点查询,所以无论点哪条记录都没有审计内容;行徽标也因此从不出现。现在先 `decodeURIComponent` 再解析,并剥掉 `\0summary\0<kind>` 后缀;未编码的旧格式也继续兼容。
8
+ - **轨迹行图标**:有记忆审计的调用行左侧显示产品年轮线条图标(12px、`fill:none`、1.3 描边、跟随 currentColor),点击直接打开该调用的记忆审计;没有审计的行不显示。图标用 `shell.overlay` 固定定位,不插轨迹表格 DOM。
9
+ - 回归测试:编码 key / 未编码 key / collapsed summary 后缀;详情页签能拿到 call-1;行标记只命中 call-1、不命中 call-2。
10
+
5
11
  ## 0.14.1 — 移除头部入口,记忆视图内滚,轨迹详情加审计页签
6
12
 
7
13
  - **移除会话头部的「记忆审计」按钮**:入口收敛到会话内的「记忆」视图和轨迹详情页签,不再占用标题行。
package/README.md CHANGED
@@ -375,7 +375,7 @@ GET /memory/api/anchor?session=<id>&turn=<n>&step=<n>&callId=<optional>
375
375
 
376
376
  DSH 自带的 Trajectory 面板是一个**纯投影**:它只声明 `conversation.trajectory.images` 一个子槽,没有行/列扩展点,选中状态也只存在组件内部。因此插件不能直接往轨迹表格里插审计行。当前采用的是一条不碰轨迹 React 树的组合:
377
377
 
378
- - **轨迹 → 记忆审计**:Trajectory 的选中行带有稳定的 `data-trajectory-row-key`(工具行是 `kind\0call\0<callId>`)。一个 `shell.overlay` 徽标只读观察选中行,按 callId 查审计,在行右侧浮出「记忆 N」。点击后打开记忆面板的「审计」页,并按 `op:<callId>` 过滤。
378
+ - **轨迹 → 记忆审计**:Trajectory 的选中行带有 `data-trajectory-row-key`。注意它在 DOM 上经过 `encodeURIComponent`(工具行实际是 `tool%00call%00<callId>`),插件会先解码再取 callId。有审计的调用行左侧会显示产品年轮线条图标;选中行右侧另有「记忆 N」徽标,点击按 `op:<callId>` 打开审计。
379
379
  - **轨迹详情页签**:点击轨迹里的任意记录后,右侧详情面板的页签行会多出一个「记忆审计」页签(用 `shell.overlay` 贴着详情面板,不改轨迹的 React 树)。它展示该记录 callId 对应的审计事件,底部按钮直接打开本会话的记忆审计面板;没有 callId 的记录明确提示无法精确过滤。
380
380
  - **记忆审计 → 轨迹**:审计详情里的「在轨迹中定位」把条目上的 `operationId`(记忆工具调用、触发召回的工具调用)交给 Trajectory 的 `openView('trajectory', callId)`。没有 `operationId` 的按轮/步事件先请求 `/anchor`,由 Host 从会话事件窗口里找该 turn/step 的第一个 `tool/call`;找不到就只切到轨迹页,不伪造定位。
381
381
  - **会话内的「记忆」视图**:与 Chat / 轨迹同一个 view ring,按当前会话展示审计;它直接使用宿主传给每个 view 的 `openView`,因此跳转是官方支持路径。它声明 `data-conversation-composer-overlay` 让壳层压住外层滚动,审计列表在自己的滚动容器里滚动,外层界面不需要跟着滚。主面板不在 view ring 内,通过 `conversation.session` 注册的 per-session store 调同一个 action;拿不到时退化为打开会话/轨迹页。
package/lib/client.js CHANGED
@@ -477,6 +477,10 @@ window.__ModuleLoader__.load({
477
477
  '.mem-traj-chip{position:fixed;z-index:70;display:inline-flex;align-items:center;gap:4px;height:20px;padding:0 7px;border:1px solid color-mix(in srgb,var(--dsw-alias-brand-primary) 42%,var(--dsw-alias-border-l1));border-radius:999px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-brand-primary);font-size:10px;line-height:1;cursor:pointer;box-shadow:0 2px 8px rgba(0,0,0,.18);white-space:nowrap}',
478
478
  '.mem-traj-chip:hover{background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,var(--dsw-alias-bg-layer-1))}',
479
479
  '.mem-traj-chip .dot{width:5px;height:5px;border-radius:50%;background:currentColor}',
480
+ // 轨迹行左侧的线条图标标记(年轮)。只做指示,点击直接打开该调用的审计。
481
+ '.mem-traj-mark{position:fixed;z-index:69;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;padding:0;border:0;border-radius:4px;background:transparent;color:color-mix(in srgb,var(--dsw-alias-brand-primary) 74%,var(--dsw-alias-label-secondary));cursor:pointer;pointer-events:auto;opacity:.9}',
482
+ '.mem-traj-mark:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-brand-primary);opacity:1}',
483
+ '.mem-traj-mark:focus-visible{outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
480
484
  '@media (max-width:900px){.memp .audit-split.has-detail{grid-template-columns:minmax(0,1fr)}.memp .audit-row{grid-template-columns:54px 120px 120px minmax(100px,1fr) 96px 100px 80px}.memp .audit-table-head{grid-template-columns:54px 120px 120px minmax(100px,1fr) 96px 100px 80px}}',
481
485
  '@media (max-width:620px){.memp .audit-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.memp .audit-table-head{display:none}.memp .audit-row{display:flex;flex-wrap:wrap;gap:4px 8px}.memp .audit-row .col-trigger,.memp .audit-row .col-budget{display:none}.memp .audit-row .col-nums{margin-left:auto}.memp .audit-row .col-time{order:1}.memp .audit-row .col-channel{order:2}.memp .audit-row .col-delivery{order:3}.memp .audit-row .col-outcome{order:4;margin-left:auto}.memp .audit-filter-row input[type=text],.memp .audit-filter-row input[type=search]{max-width:none;flex:1}.memp .audit{height:calc(100vh - 150px);max-height:calc(100vh - 150px)}.memp .audit-detail{max-height:calc(100vh - 280px)}}',
482
486
  ].join('')
@@ -2157,14 +2161,24 @@ window.__ModuleLoader__.load({
2157
2161
  return signalCall !== '' ? signalCall : undefined
2158
2162
  }
2159
2163
 
2160
- /** Trajectory 的行 key 形如 `tool\0call\0<callId>`;解析失败返回 undefined。 */
2164
+ /**
2165
+ * Trajectory 的行 key 形如 `tool\0call\0<callId>`,但 DOM 上看到的是
2166
+ * `trajectoryVirtualRecordKey()` 返回的 **URI 编码**(`tool%00call%00callId`)。
2167
+ * 必须 decode 一次再解析;collapsed summary 还会追加 `\0summary\0<kind>`。
2168
+ */
2161
2169
  function trajectoryRowCallId(row) {
2162
2170
  try {
2163
- const key = row && typeof row.getAttribute === 'function' ? row.getAttribute('data-trajectory-row-key') : ''
2164
- if (typeof key !== 'string') return undefined
2171
+ const raw = row && typeof row.getAttribute === 'function' ? row.getAttribute('data-trajectory-row-key') : ''
2172
+ if (typeof raw !== 'string' || raw === '') return undefined
2173
+ let key = raw
2174
+ try { key = decodeURIComponent(raw) } catch { /* 不是合法编码时按原文解析 */ }
2165
2175
  const sep = '\u0000call\u0000'
2166
2176
  const at = key.indexOf(sep)
2167
- return at >= 0 ? key.slice(at + sep.length) : undefined
2177
+ if (at < 0) return undefined
2178
+ const rest = key.slice(at + sep.length)
2179
+ const cut = rest.indexOf('\u0000')
2180
+ const callId = cut < 0 ? rest : rest.slice(0, cut)
2181
+ return callId === '' ? undefined : callId
2168
2182
  } catch {
2169
2183
  return undefined
2170
2184
  }
@@ -3715,6 +3729,121 @@ window.__ModuleLoader__.load({
3715
3729
  }, h('span', { className: 'dot' }), `记忆 ${badge.entries.length}`)
3716
3730
  }
3717
3731
 
3732
+ /** 轨迹行左侧的「产品线条图标」标记:有记忆审计的调用才显示。 */
3733
+ function TrajectoryMemoryMarks() {
3734
+ const [marks, setMarks] = React.useState([])
3735
+ const cacheRef = React.useRef(new Map())
3736
+ React.useEffect(() => {
3737
+ let disposed = false
3738
+ let raf = 0
3739
+ const rafFn = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : ((fn) => setTimeout(fn, 16))
3740
+ const cancelFn = typeof cancelAnimationFrame === 'function' ? cancelAnimationFrame : ((id) => clearTimeout(id))
3741
+ const same = (a, b) => a.length === b.length && a.every((mark, index) => {
3742
+ const other = b[index]
3743
+ return other !== undefined
3744
+ && mark.callId === other.callId
3745
+ && Math.abs(mark.top - other.top) < 1
3746
+ && Math.abs(mark.left - other.left) < 1
3747
+ && mark.count === other.count
3748
+ })
3749
+ const tick = () => {
3750
+ try {
3751
+ if (disposed || typeof document === 'undefined' || typeof window === 'undefined') return
3752
+ const sessionId = currentSessionId()
3753
+ if (sessionId === undefined) { setMarks([]); return }
3754
+ const rows = [...document.querySelectorAll('tr[data-trajectory-row-key]')]
3755
+ if (rows.length === 0) { setMarks([]); return }
3756
+ const visible = new Map()
3757
+ for (const row of rows) {
3758
+ const callId = trajectoryRowCallId(row)
3759
+ if (callId === undefined) continue
3760
+ const rect = row.getBoundingClientRect()
3761
+ if (rect.bottom < 0 || rect.top > window.innerHeight || rect.height <= 0) continue
3762
+ visible.set(callId, rect)
3763
+ }
3764
+ if (visible.size === 0) { setMarks([]); return }
3765
+ const cached = cacheRef.current.get(sessionId)
3766
+ const now = Date.now()
3767
+ if (cached && cached.pending === true) return
3768
+ if (!cached || now - cached.at > 3000) {
3769
+ cacheRef.current.set(sessionId, { at: now, pending: true, byOp: new Map() })
3770
+ api(`audit?session=${encodeURIComponent(sessionId)}&limit=200`)
3771
+ .then((value) => {
3772
+ const byOp = new Map()
3773
+ const entries = value && Array.isArray(value.entries) ? value.entries : []
3774
+ for (const entry of entries) {
3775
+ const callId = auditEntryCallId(entry)
3776
+ if (callId !== undefined) byOp.set(callId, (byOp.get(callId) ?? 0) + 1)
3777
+ }
3778
+ cacheRef.current.set(sessionId, { at: Date.now(), pending: false, byOp })
3779
+ if (!disposed) schedule()
3780
+ })
3781
+ .catch(() => {
3782
+ cacheRef.current.set(sessionId, { at: Date.now(), pending: false, byOp: new Map() })
3783
+ })
3784
+ if (!cached) return
3785
+ }
3786
+ const byOp = cached && cached.byOp instanceof Map ? cached.byOp : null
3787
+ if (byOp === null) return
3788
+ const next = []
3789
+ for (const [callId, rect] of visible) {
3790
+ const count = byOp.get(callId)
3791
+ if (count === undefined) continue
3792
+ next.push({
3793
+ callId,
3794
+ count,
3795
+ top: Math.max(2, rect.top + (rect.height - 16) / 2),
3796
+ left: Math.max(2, rect.left + 22),
3797
+ sessionId,
3798
+ })
3799
+ }
3800
+ setMarks((prev) => same(prev, next) ? prev : next)
3801
+ } catch { /* 观察失败:保持现状 */ }
3802
+ }
3803
+ const schedule = () => {
3804
+ if (disposed || raf !== 0) return
3805
+ raf = rafFn(() => { raf = 0; tick() })
3806
+ }
3807
+ let observer = null
3808
+ try {
3809
+ observer = new MutationObserver(schedule)
3810
+ observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['data-selected'] })
3811
+ } catch { observer = null }
3812
+ const onScroll = () => schedule()
3813
+ let timer = null
3814
+ try {
3815
+ window.addEventListener('scroll', onScroll, true)
3816
+ window.addEventListener('resize', onScroll)
3817
+ timer = setInterval(tick, 800)
3818
+ } catch { /* 非浏览器环境 */ }
3819
+ schedule()
3820
+ return () => {
3821
+ disposed = true
3822
+ if (raf !== 0) cancelFn(raf)
3823
+ if (timer !== null) clearInterval(timer)
3824
+ try { observer?.disconnect() } catch { /* 已断开 */ }
3825
+ try {
3826
+ window.removeEventListener('scroll', onScroll, true)
3827
+ window.removeEventListener('resize', onScroll)
3828
+ } catch { /* 非浏览器环境 */ }
3829
+ }
3830
+ }, [])
3831
+ if (marks.length === 0) return null
3832
+ return h(React.Fragment, null, marks.map((mark) => h('button', {
3833
+ key: `${mark.sessionId}:${mark.callId}`,
3834
+ className: 'mem-traj-mark',
3835
+ style: { top: mark.top, left: mark.left },
3836
+ title: `这次调用有 ${mark.count} 条记忆审计;点击在记忆面板里查看`,
3837
+ onClick: (event) => {
3838
+ try { event.stopPropagation() } catch { /* 忽略 */ }
3839
+ openMemoryAuditPanel({ sessionId: mark.sessionId, callId: mark.callId })
3840
+ },
3841
+ }, h('svg', { width: 12, height: 12, viewBox: NAV_VIEW_BOX, fill: 'none', 'aria-hidden': 'true' },
3842
+ h('rect', { ...NAV_FRAME, fill: 'none', stroke: 'currentColor', strokeWidth: 1.3 }),
3843
+ h('path', { d: NAV_RING, fill: 'none', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round', strokeLinejoin: 'round' }),
3844
+ ))))
3845
+ }
3846
+
3718
3847
  /**
3719
3848
  * 轨迹详情面板里的「记忆审计」页签。
3720
3849
  *
@@ -4109,6 +4238,15 @@ window.__ModuleLoader__.load({
4109
4238
  } catch (error) {
4110
4239
  console.warn('[dsh-memory] 记忆审计视图注册失败:', error?.message)
4111
4240
  }
4241
+ try {
4242
+ slots.inject('shell.overlay', () => slots.register({
4243
+ name: 'shell.overlay',
4244
+ id: 'memory-audit-marks',
4245
+ order: 59,
4246
+ }, () => React.createElement(TrajectoryMemoryMarks)))
4247
+ } catch (error) {
4248
+ console.warn('[dsh-memory] 轨迹行记忆标记注册失败:', error?.message)
4249
+ }
4112
4250
  try {
4113
4251
  slots.inject('shell.overlay', () => slots.register({
4114
4252
  name: 'shell.overlay',
@@ -4255,6 +4393,7 @@ window.__ModuleLoader__.load({
4255
4393
  // 审计 ↔ 轨迹桥(测试只覆盖纯解析/焦点总线,不碰宿主 slot 实例)
4256
4394
  MemoryAuditView: MemoryAuditView,
4257
4395
  TrajectoryMemoryBadge: TrajectoryMemoryBadge,
4396
+ TrajectoryMemoryMarks: TrajectoryMemoryMarks,
4258
4397
  TrajectoryDetailAudit: TrajectoryDetailAudit,
4259
4398
  auditEntryCallId: auditEntryCallId,
4260
4399
  trajectoryRowCallId: trajectoryRowCallId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",