@restregular/dsh-memory 0.12.5 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +2 -0
- package/lib/client.js +258 -17
- package/lib/panel.js +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的版本记录。安装 id 与 npm 版本一一对应。
|
|
4
4
|
|
|
5
|
+
## 0.12.7 — 审计详情滚动与锚定浮窗
|
|
6
|
+
|
|
7
|
+
- **详情底部不再被裁切**:审计页高度收紧到 `100vh - 210px`;详情面板改为 `height:auto` +
|
|
8
|
+
`max-height:calc(100vh - 340px)` + `overflow-y:auto`,并加 20px 底部内边距;「原始结构化事件」
|
|
9
|
+
等底部内容可以完整滚入视口。
|
|
10
|
+
- **浮窗不再跟随鼠标**:浮窗改为根据 ID 气泡的 `getBoundingClientRect()` 固定定位(下方优先,
|
|
11
|
+
空间不足自动翻到上方),不再随 mousemove 移动。
|
|
12
|
+
- **hover 延迟 + 可移入浮窗**:进入 ID 气泡后等待 350ms 才显示;显示后鼠标移到浮窗内不会隐藏,
|
|
13
|
+
离开气泡/浮窗 220ms 后隐藏;不再需要重新 hover 才能看到完整 ID(浮窗标题/内容已含完整 ID)。
|
|
14
|
+
- 浮窗改为 `pointer-events:auto` 且可滚动,长正文可以直接在浮窗内查看/滚动。
|
|
15
|
+
- **点击直接跳转**:点击 ID 气泡或浮窗本身都直接执行跳转(记忆 → 记录页并展开,会话 → 打开会话)。
|
|
16
|
+
- 测试更新:hover 延迟后显示完整 ID、记忆原文/会话标题,点击回调仍正确。
|
|
17
|
+
|
|
18
|
+
## 0.12.6 — 审计详情分类、滚动与关联跳转
|
|
19
|
+
|
|
20
|
+
- **详情完整可滚动**:审计页采用固定视口高度 + `grid-template-rows:minmax(0,1fr)`,详情面板 `height:100%` 独立滚动,长内容可以滚到底部;整页不滚动。
|
|
21
|
+
- **选择与省略分类展示**:详情里按组显示「选中正文 / 本次新增 / 标签索引 / 省略(按原因分组)/ 去重跳过」,每组有数量;候选与可枚举 ID 的关系有说明,不再混成一排。
|
|
22
|
+
- **记忆 ID 浮窗**:hover 显示记录类型、作用域、重要度、标签与原文摘要;点击跳到「记录」页并自动展开该记录(`RecordCard` 新增 focus 展开)。记录不在当前列表时通过 `/records?id=` 精确补查。
|
|
23
|
+
- **会话 ID 浮窗与跳转**:hover 显示会话标题/cwd/更新时间/运行状态;点击通过宿主 `uiWorkspace.openSession` 打开会话(旧宿主退回 hash 路由)。
|
|
24
|
+
- 面板 `/records` 新增 `id`(精确或前缀)过滤,供审计详情按 ID 补查。
|
|
25
|
+
- 测试补充:详情 ID 分组、记忆/会话 ID hover 浮窗与点击回调、记录页自动展开;全量 323 项 322 通过 1 跳过。
|
|
26
|
+
|
|
5
27
|
## 0.12.5 — 审计表头与行严格对齐
|
|
6
28
|
|
|
7
29
|
- 表头移入滚动容器内部并设为 sticky:表头与行共享同一个内容宽度(含滚动条),不再出现标题比内容偏左。
|
package/README.md
CHANGED
|
@@ -415,6 +415,8 @@ npm run verify # 构建到 .verify/,不落 packages/
|
|
|
415
415
|
|
|
416
416
|
## 更新日志
|
|
417
417
|
|
|
418
|
+
- **0.12.7** —— 审计详情可完整滚到底;ID 浮窗改为按气泡位置固定显示,延迟 hover 显示、可移入浮窗,点击气泡或浮窗都直接跳转。
|
|
419
|
+
- **0.12.6** —— 审计详情分类展示选中/新增/标签/省略/去重 ID;记忆与会话 ID 支持 hover 浮窗和点击跳转;详情独立滚动可到底。
|
|
418
420
|
- **0.12.5** —— 审计表头移入滚动容器并 sticky,与行严格对齐;重分配列宽,行内预算改紧凑条。
|
|
419
421
|
- **0.12.4** —— 审计页默认每 0.5 秒自动刷新(可关/可调间隔);移除顶部标题与气泡,整页固定在窗口内,仅列表滚动;新增表头并优化列宽;复制/导出提示就地显示。
|
|
420
422
|
- **0.12.3** —— 审计页筛选改为两行紧凑布局与自绘时间范围/开关;事件列表放入独立滚动容器。
|
package/lib/client.js
CHANGED
|
@@ -335,7 +335,7 @@ window.__ModuleLoader__.load({
|
|
|
335
335
|
'.memp .td-rel-text{color:var(--dsw-alias-label-secondary);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;word-break:break-word}',
|
|
336
336
|
'@media (max-width:620px){.memp .tree-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.memp .tree-toolbar input[type=text]{max-width:none}}',
|
|
337
337
|
// ===== 审计 =====
|
|
338
|
-
'.memp .audit{display:flex;flex-direction:column;gap:10px;min-height:0;height:calc(100vh -
|
|
338
|
+
'.memp .audit{display:flex;flex-direction:column;gap:10px;min-height:0;height:calc(100vh - 210px);max-height:calc(100vh - 210px);overflow:hidden}',
|
|
339
339
|
'.memp .audit-head{display:flex;align-items:flex-start;gap:12px;flex-wrap:wrap}',
|
|
340
340
|
'.memp .audit-title{font-size:16px;font-weight:650;line-height:1.35}',
|
|
341
341
|
'.memp .audit-sub{font-size:11.5px;color:var(--dsw-alias-label-secondary);line-height:1.55;margin-top:2px}',
|
|
@@ -361,7 +361,7 @@ window.__ModuleLoader__.load({
|
|
|
361
361
|
'.memp .audit-switch .switch.on .knob{left:16px}',
|
|
362
362
|
'.memp .audit-filter-sub{padding-top:1px}',
|
|
363
363
|
'.memp .audit-range-sep{color:var(--dsw-alias-label-secondary);font-size:11px;flex:none}',
|
|
364
|
-
'.memp .audit-split{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;min-height:0;flex:1;overflow:hidden;align-items:stretch}',
|
|
364
|
+
'.memp .audit-split{display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:10px;min-height:0;flex:1;overflow:hidden;align-items:stretch}',
|
|
365
365
|
'.memp .audit-split.has-detail{grid-template-columns:minmax(0,1fr) minmax(300px,360px)}',
|
|
366
366
|
'.memp .audit-list-wrap{display:flex;flex-direction:column;min-height:0;min-width:0;overflow:hidden}',
|
|
367
367
|
'.memp .audit-table-head{display:grid;grid-template-columns:62px 140px minmax(150px,1.3fr) minmax(110px,0.8fr) 112px minmax(108px,0.9fr) 92px;gap:8px;align-items:center;position:sticky;top:0;z-index:2;box-sizing:border-box;padding:6px 9px;margin-bottom:2px;font-size:10px;letter-spacing:.03em;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-1);border:1px solid transparent;border-bottom-color:var(--dsw-alias-border-l1)}',
|
|
@@ -385,7 +385,7 @@ window.__ModuleLoader__.load({
|
|
|
385
385
|
'.memp .audit-pill.bad{color:var(--dsw-alias-label-danger, #e05555);border-color:color-mix(in srgb,var(--dsw-alias-label-danger, #e05555) 42%,var(--dsw-alias-border-l1))}',
|
|
386
386
|
'.memp .audit-pill.mute{color:var(--dsw-alias-label-secondary)}',
|
|
387
387
|
'.memp .audit-empty{border:1px dashed var(--dsw-alias-border-l1);border-radius:10px;padding:26px 16px;text-align:center;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.65}',
|
|
388
|
-
'.memp .audit-detail{border:1px solid var(--dsw-alias-border-l1);border-radius:11px;background:var(--dsw-alias-bg-layer-1);padding:10px 11px;display:flex;flex-direction:column;gap:9px;max-height:
|
|
388
|
+
'.memp .audit-detail{border:1px solid var(--dsw-alias-border-l1);border-radius:11px;background:var(--dsw-alias-bg-layer-1);padding:10px 11px 20px;box-sizing:border-box;display:flex;flex-direction:column;gap:9px;height:auto;max-height:calc(100vh - 340px);min-height:0;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin}',
|
|
389
389
|
'.memp .audit-detail-head{display:flex;gap:7px;align-items:center}',
|
|
390
390
|
'.memp .audit-detail-head b{font-size:12.5px}',
|
|
391
391
|
'.memp .audit-detail-head .spacer{flex:1}',
|
|
@@ -408,8 +408,23 @@ window.__ModuleLoader__.load({
|
|
|
408
408
|
'.memp .audit-json{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:10px;line-height:1.45;white-space:pre-wrap;word-break:break-word;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:7px;max-height:220px;overflow:auto}',
|
|
409
409
|
'.memp .audit-pager{display:flex;gap:6px;align-items:center;justify-content:flex-end;font-size:11px;color:var(--dsw-alias-label-secondary)}',
|
|
410
410
|
'.memp .audit-flat{display:flex;flex-wrap:wrap;gap:4px}',
|
|
411
|
+
'.memp .audit-id{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:10px;line-height:1.65;padding:1px 6px;border-radius:6px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);cursor:pointer;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
412
|
+
'.memp .audit-id:hover{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}',
|
|
413
|
+
'.memp .audit-id.omit{color:color-mix(in srgb,#D9A441 78%,var(--dsw-alias-label-primary));border-color:color-mix(in srgb,#D9A441 32%,var(--dsw-alias-border-l1))}',
|
|
414
|
+
'.memp .audit-id.dedup{opacity:.75}',
|
|
415
|
+
'.memp .audit-id-group{display:flex;flex-direction:column;gap:5px;padding:7px 8px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-2) 55%,transparent)}',
|
|
416
|
+
'.memp .audit-id-group-title{display:flex;align-items:center;gap:6px;font-size:10.5px;color:var(--dsw-alias-label-secondary);letter-spacing:.02em}',
|
|
417
|
+
'.memp .audit-id-group-title b{font-weight:600;color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}',
|
|
418
|
+
'.memp .audit-id-sub{font-size:9.5px;color:var(--dsw-alias-label-secondary);opacity:.85}',
|
|
419
|
+
'.memp .audit-tip{position:fixed;z-index:120;max-width:min(380px,calc(100vw - 24px));max-height:min(300px,60vh);overflow:auto;padding:9px 10px;border:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-l1));border-radius:10px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 97%,black 3%);box-shadow:0 14px 36px rgba(0,0,0,.28);pointer-events:auto;cursor:pointer;color:var(--dsw-alias-label-primary)}',
|
|
420
|
+
'.memp .audit-tip-head{display:flex;align-items:center;gap:6px;margin-bottom:5px;font-size:11px;color:var(--dsw-alias-label-secondary)}',
|
|
421
|
+
'.memp .audit-tip-title{font-weight:600;color:var(--dsw-alias-label-primary);font-size:11.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}',
|
|
422
|
+
'.memp .audit-tip-meta{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:5px}',
|
|
423
|
+
'.memp .audit-tip-content{font-size:11px;line-height:1.55;white-space:pre-wrap;word-break:break-word;color:var(--dsw-alias-label-primary);max-height:none;overflow:visible}',
|
|
424
|
+
'.memp .audit-tip-foot{margin-top:6px;font-size:9.5px;color:var(--dsw-alias-label-secondary)}',
|
|
425
|
+
'.memp .rec.focus{border-color:var(--dsw-alias-brand-primary);box-shadow:0 0 0 1px color-mix(in srgb,var(--dsw-alias-brand-primary) 25%,transparent)}',
|
|
411
426
|
'@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}}',
|
|
412
|
-
'@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 -
|
|
427
|
+
'@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)}}',
|
|
413
428
|
].join('')
|
|
414
429
|
|
|
415
430
|
async function api(method, body) {
|
|
@@ -710,7 +725,7 @@ window.__ModuleLoader__.load({
|
|
|
710
725
|
})
|
|
711
726
|
}
|
|
712
727
|
|
|
713
|
-
function RecordCard({ rec, vectorOn, labels, onSaved, onDeleted }) {
|
|
728
|
+
function RecordCard({ rec, vectorOn, labels, onSaved, onDeleted, focus = false }) {
|
|
714
729
|
// collapsed by default: the list stays scannable, full text on demand
|
|
715
730
|
const [expanded, setExpanded] = React.useState(false)
|
|
716
731
|
const [editing, setEditing] = React.useState(false)
|
|
@@ -722,6 +737,9 @@ window.__ModuleLoader__.load({
|
|
|
722
737
|
const [error, setError] = React.useState('')
|
|
723
738
|
const [copied, setCopied] = React.useState(false)
|
|
724
739
|
|
|
740
|
+
// 从审计页点 memory ID 跳过来时自动展开目标记录。
|
|
741
|
+
React.useEffect(() => { if (focus) setExpanded(true) }, [focus])
|
|
742
|
+
|
|
725
743
|
const copyId = () => {
|
|
726
744
|
try {
|
|
727
745
|
if (navigator?.clipboard?.writeText) void navigator.clipboard.writeText(rec.id)
|
|
@@ -761,7 +779,7 @@ window.__ModuleLoader__.load({
|
|
|
761
779
|
setTags(rec.tags.join(', ')); setImportance(rec.importance)
|
|
762
780
|
}
|
|
763
781
|
|
|
764
|
-
return h('div', { className: 'rec' },
|
|
782
|
+
return h('div', { className: 'rec' + (focus ? ' focus' : '') },
|
|
765
783
|
h('div', {
|
|
766
784
|
className: 'rec-head',
|
|
767
785
|
role: 'button',
|
|
@@ -2123,7 +2141,12 @@ window.__ModuleLoader__.load({
|
|
|
2123
2141
|
{ value: 'custom', label: '自定义日期…', ms: null },
|
|
2124
2142
|
]
|
|
2125
2143
|
|
|
2126
|
-
|
|
2144
|
+
const AUDIT_OMIT_LABEL = {
|
|
2145
|
+
top_k: '条数上限', budget: '预算', superseded: '已退役', expired: '已过期',
|
|
2146
|
+
tag_mismatch: '标签不匹配', dedup: '去重', excluded: '被排除', skipped: '跳过',
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
function AuditTab({ scopes, records = [], openRecord, openSession, sessionInfo }) {
|
|
2127
2150
|
const [entries, setEntries] = React.useState([])
|
|
2128
2151
|
const [stats, setStats] = React.useState(null)
|
|
2129
2152
|
const [total, setTotal] = React.useState(0)
|
|
@@ -2148,6 +2171,10 @@ window.__ModuleLoader__.load({
|
|
|
2148
2171
|
const [until, setUntil] = React.useState('')
|
|
2149
2172
|
const [selectedId, setSelectedId] = React.useState(null)
|
|
2150
2173
|
const [reloadTick, setReloadTick] = React.useState(0)
|
|
2174
|
+
const [tip, setTip] = React.useState(null)
|
|
2175
|
+
const [recordCache, setRecordCache] = React.useState({})
|
|
2176
|
+
const tipTimer = React.useRef(null)
|
|
2177
|
+
const hideTimer = React.useRef(null)
|
|
2151
2178
|
|
|
2152
2179
|
function queryParams(cursorValue) {
|
|
2153
2180
|
const params = new URLSearchParams()
|
|
@@ -2211,6 +2238,95 @@ window.__ModuleLoader__.load({
|
|
|
2211
2238
|
|
|
2212
2239
|
const resetAndReload = () => { setCursor(''); setCursorStack([]); setReloadTick((n) => n + 1) }
|
|
2213
2240
|
const selected = selectedId === null ? null : entries.find((entry) => entry.id === selectedId) || null
|
|
2241
|
+
|
|
2242
|
+
// 记忆 ID / 会话 ID 的悬停浮窗与跳转。
|
|
2243
|
+
const recordMap = {}
|
|
2244
|
+
for (const rec of records) if (rec && rec.id) recordMap[rec.id] = rec
|
|
2245
|
+
for (const [id, rec] of Object.entries(recordCache)) if (!recordMap[id]) recordMap[id] = rec
|
|
2246
|
+
const findRecord = (id) => {
|
|
2247
|
+
if (recordMap[id]) return recordMap[id]
|
|
2248
|
+
return records.find((rec) => rec && rec.id && rec.id.startsWith(id)) || recordCache[id]
|
|
2249
|
+
}
|
|
2250
|
+
const fetchRecord = async (id) => {
|
|
2251
|
+
const known = findRecord(id)
|
|
2252
|
+
if (known) return known
|
|
2253
|
+
try {
|
|
2254
|
+
const value = await api(`records?id=${encodeURIComponent(id)}`)
|
|
2255
|
+
const rec = Array.isArray(value.records) ? value.records[0] : undefined
|
|
2256
|
+
if (rec !== undefined) setRecordCache((prev) => ({ ...prev, [rec.id]: rec, [id]: rec }))
|
|
2257
|
+
return rec
|
|
2258
|
+
} catch {
|
|
2259
|
+
return undefined
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
const clearTipTimers = () => {
|
|
2263
|
+
if (tipTimer.current !== null) { clearTimeout(tipTimer.current); tipTimer.current = null }
|
|
2264
|
+
if (hideTimer.current !== null) { clearTimeout(hideTimer.current); hideTimer.current = null }
|
|
2265
|
+
}
|
|
2266
|
+
React.useEffect(() => () => clearTipTimers(), [])
|
|
2267
|
+
const positionForAnchor = (element) => {
|
|
2268
|
+
const width = typeof window !== 'undefined' ? window.innerWidth : 1200
|
|
2269
|
+
const height = typeof window !== 'undefined' ? window.innerHeight : 800
|
|
2270
|
+
const rect = element && typeof element.getBoundingClientRect === 'function' ? element.getBoundingClientRect() : null
|
|
2271
|
+
if (rect === null) return { x: 12, y: 12 }
|
|
2272
|
+
const tipWidth = Math.min(380, width - 24)
|
|
2273
|
+
const tipHeight = 240
|
|
2274
|
+
const x = Math.max(12, Math.min(rect.left, width - tipWidth - 12))
|
|
2275
|
+
let y = rect.bottom + 8
|
|
2276
|
+
if (y + tipHeight > height - 12) y = Math.max(12, rect.top - tipHeight - 8)
|
|
2277
|
+
return { x, y }
|
|
2278
|
+
}
|
|
2279
|
+
const scheduleTip = (build, element) => {
|
|
2280
|
+
clearTipTimers()
|
|
2281
|
+
if (tip !== null && tip.id !== build().id) setTip(null)
|
|
2282
|
+
tipTimer.current = setTimeout(() => {
|
|
2283
|
+
tipTimer.current = null
|
|
2284
|
+
setTip({ ...build(), ...positionForAnchor(element) })
|
|
2285
|
+
}, 350)
|
|
2286
|
+
}
|
|
2287
|
+
const cancelHideTip = () => {
|
|
2288
|
+
if (hideTimer.current !== null) { clearTimeout(hideTimer.current); hideTimer.current = null }
|
|
2289
|
+
}
|
|
2290
|
+
const scheduleHideTip = () => {
|
|
2291
|
+
if (tipTimer.current !== null) { clearTimeout(tipTimer.current); tipTimer.current = null }
|
|
2292
|
+
cancelHideTip()
|
|
2293
|
+
hideTimer.current = setTimeout(() => { hideTimer.current = null; setTip(null) }, 220)
|
|
2294
|
+
}
|
|
2295
|
+
const hideTip = () => { clearTipTimers(); setTip(null) }
|
|
2296
|
+
const showMemoryTip = (id, element) => {
|
|
2297
|
+
const known = findRecord(id)
|
|
2298
|
+
const box = { record: known }
|
|
2299
|
+
scheduleTip(() => ({ type: 'memory', id, record: box.record, loading: box.record === undefined }), element)
|
|
2300
|
+
if (known === undefined) {
|
|
2301
|
+
fetchRecord(id).then((record) => {
|
|
2302
|
+
if (record === undefined) return
|
|
2303
|
+
box.record = record
|
|
2304
|
+
setTip((prev) => prev !== null && prev.id === id ? { ...prev, record, loading: false } : prev)
|
|
2305
|
+
})
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
const showSessionTip = (id, element) => {
|
|
2309
|
+
const summary = typeof sessionInfo === 'function' ? (() => { try { return sessionInfo(id) } catch { return undefined } })() : undefined
|
|
2310
|
+
scheduleTip(() => ({ type: 'session', id, summary }), element)
|
|
2311
|
+
}
|
|
2312
|
+
const openMemoryId = async (id) => {
|
|
2313
|
+
const record = findRecord(id) || await fetchRecord(id)
|
|
2314
|
+
hideTip()
|
|
2315
|
+
if (typeof openRecord === 'function') openRecord(record?.id ?? id, record?.scope)
|
|
2316
|
+
}
|
|
2317
|
+
const openSessionId = (id) => {
|
|
2318
|
+
hideTip()
|
|
2319
|
+
if (typeof openSession === 'function') openSession(id)
|
|
2320
|
+
}
|
|
2321
|
+
const idChip = (id, tone = '', title = undefined) => h('button', {
|
|
2322
|
+
key: `${tone}:${id}`,
|
|
2323
|
+
className: 'audit-id' + (tone ? ` ${tone}` : ''),
|
|
2324
|
+
'aria-label': title || id,
|
|
2325
|
+
onMouseEnter: (event) => showMemoryTip(id, event.currentTarget),
|
|
2326
|
+
onMouseLeave: scheduleHideTip,
|
|
2327
|
+
onClick: () => openMemoryId(id),
|
|
2328
|
+
}, id.length > 12 ? `${id.slice(0, 8)}…${id.slice(-4)}` : id)
|
|
2329
|
+
|
|
2214
2330
|
const prepared = entries.filter((entry) => entry.delivery && entry.delivery.status === 'unknown' && entry.reasonCode === 'prepared').length
|
|
2215
2331
|
const suppressed = entries.filter((entry) => entry.delivery && (entry.delivery.status === 'suppressed' || entry.delivery.status === 'not_attempted')).length
|
|
2216
2332
|
const failed = entries.filter((entry) => entry.outcome === 'failed').length
|
|
@@ -2380,10 +2496,35 @@ window.__ModuleLoader__.load({
|
|
|
2380
2496
|
})
|
|
2381
2497
|
const selectedIds = selected.selected ? selected.selected.contentIds : (selected.contentIds || [])
|
|
2382
2498
|
const hintIds = selected.selected ? selected.selected.hintIds : (selected.hintIds || [])
|
|
2499
|
+
const newlyAddedIds = selected.selected && Array.isArray(selected.selected.newlyAddedIds) ? selected.selected.newlyAddedIds : []
|
|
2383
2500
|
const omitted = Array.isArray(selected.omitted) ? selected.omitted : []
|
|
2501
|
+
const dedupIds = selected.dedup && Array.isArray(selected.dedup.ids) ? selected.dedup.ids : []
|
|
2502
|
+
const omitGroups = new Map()
|
|
2503
|
+
for (const item of omitted) {
|
|
2504
|
+
const reason = item.reason || 'other'
|
|
2505
|
+
if (!omitGroups.has(reason)) omitGroups.set(reason, [])
|
|
2506
|
+
omitGroups.get(reason).push(item)
|
|
2507
|
+
}
|
|
2508
|
+
const sameIdSet = (a, b) => a.length === b.length && a.every((id) => b.includes(id))
|
|
2509
|
+
const idGroup = (label, ids, tone, empty = '无', titleOf = undefined) => h('div', { className: 'audit-id-group' },
|
|
2510
|
+
h('div', { className: 'audit-id-group-title' }, h('span', null, label), h('b', null, String(ids.length))),
|
|
2511
|
+
ids.length > 0
|
|
2512
|
+
? h('div', { className: 'audit-flat' }, ids.map((id) => idChip(id, tone, titleOf ? titleOf(id) : undefined)))
|
|
2513
|
+
: h('span', { className: 'audit-id-sub' }, empty),
|
|
2514
|
+
)
|
|
2384
2515
|
const kv = (label, value) => (value === undefined || value === null || value === '')
|
|
2385
2516
|
? null
|
|
2386
2517
|
: [h('span', { className: 'k', key: `k-${label}` }, label), h('span', { className: 'v', key: `v-${label}` }, String(value))]
|
|
2518
|
+
const sessionNode = selected.sessionId
|
|
2519
|
+
? [h('span', { className: 'k', key: 'k-session' }, '会话'),
|
|
2520
|
+
h('span', { className: 'v', key: 'v-session' }, h('button', {
|
|
2521
|
+
className: 'audit-id',
|
|
2522
|
+
'aria-label': selected.sessionId,
|
|
2523
|
+
onMouseEnter: (event) => showSessionTip(selected.sessionId, event.currentTarget),
|
|
2524
|
+
onMouseLeave: scheduleHideTip,
|
|
2525
|
+
onClick: () => openSessionId(selected.sessionId),
|
|
2526
|
+
}, selected.sessionId))]
|
|
2527
|
+
: null
|
|
2387
2528
|
const json = JSON.stringify(selected, null, 2)
|
|
2388
2529
|
return h('div', { className: 'audit-detail' },
|
|
2389
2530
|
h('div', { className: 'audit-detail-head' },
|
|
@@ -2398,7 +2539,7 @@ window.__ModuleLoader__.load({
|
|
|
2398
2539
|
kv('序号', selected.seq),
|
|
2399
2540
|
kv('时间', fmtTime(selected.at)),
|
|
2400
2541
|
kv('schema', selected.schemaVersion || '旧版'),
|
|
2401
|
-
|
|
2542
|
+
sessionNode,
|
|
2402
2543
|
kv('step', selected.step),
|
|
2403
2544
|
kv('通道', `${auditChannelLabel(selected.channel)} / ${selected.kind}`),
|
|
2404
2545
|
kv('阶段', selected.stage),
|
|
@@ -2428,10 +2569,29 @@ window.__ModuleLoader__.load({
|
|
|
2428
2569
|
kv('选中', selectedIds.length),
|
|
2429
2570
|
kv('新增', selected.selected && selected.selected.newlyAddedIds ? selected.selected.newlyAddedIds.length : '—'),
|
|
2430
2571
|
kv('hint', hintIds.length),
|
|
2572
|
+
kv('省略', omitted.length),
|
|
2431
2573
|
kv('去重跳过', selected.dedup ? selected.dedup.skipped : '—'),
|
|
2432
2574
|
),
|
|
2433
|
-
|
|
2434
|
-
|
|
2575
|
+
h('div', { className: 'audit-id-sub' }, '候选中的可枚举 ID = 选中 + 省略;标签过滤 / 退役排除只在上方计数里。'),
|
|
2576
|
+
idGroup(selected.channel === 'rules' ? '选中规则' : '选中正文', selectedIds, '', '没有选中 ID'),
|
|
2577
|
+
newlyAddedIds.length > 0 && !sameIdSet(newlyAddedIds, selectedIds)
|
|
2578
|
+
? idGroup('本次新增到消息', newlyAddedIds, '', '无')
|
|
2579
|
+
: null,
|
|
2580
|
+
hintIds.length > 0 ? idGroup('标签索引(只给 ID,未注入正文)', hintIds, '', '无') : null,
|
|
2581
|
+
...Array.from(omitGroups.entries()).map(([reason, items]) => idGroup(
|
|
2582
|
+
`省略 · ${AUDIT_OMIT_LABEL[reason] || reason}`,
|
|
2583
|
+
items.map((item) => item.id),
|
|
2584
|
+
'omit',
|
|
2585
|
+
'无',
|
|
2586
|
+
(id) => {
|
|
2587
|
+
const item = items.find((entry) => entry.id === id)
|
|
2588
|
+
return `${id}${item && item.tags && item.tags.length > 0 ? ` · ${item.tags.join(', ')}` : ''}`
|
|
2589
|
+
},
|
|
2590
|
+
)),
|
|
2591
|
+
dedupIds.length > 0 ? idGroup('去重跳过', dedupIds, 'dedup', '无') : null,
|
|
2592
|
+
selectedIds.length + hintIds.length + omitted.length + dedupIds.length === 0
|
|
2593
|
+
? h('div', { className: 'audit-id-sub' }, '这条事件没有可枚举的记忆 ID。')
|
|
2594
|
+
: null,
|
|
2435
2595
|
),
|
|
2436
2596
|
budgetRows.length > 0 ? h('div', { className: 'audit-sec' },
|
|
2437
2597
|
h('div', { className: 'audit-sec-title' }, '预算'),
|
|
@@ -2492,6 +2652,44 @@ window.__ModuleLoader__.load({
|
|
|
2492
2652
|
: h('div', { className: 'audit-list' }, listHeader, entries.map(row))
|
|
2493
2653
|
const listArea = h('div', { className: 'audit-list-wrap' }, listBody)
|
|
2494
2654
|
|
|
2655
|
+
const tipNode = tip === null ? null : (() => {
|
|
2656
|
+
if (tip.type === 'session') {
|
|
2657
|
+
const summary = tip.summary || {}
|
|
2658
|
+
const title = summary.title || summary.name || `会话 ${String(tip.id).slice(0, 8)}`
|
|
2659
|
+
return h('div', { className: 'audit-tip', style: { left: tip.x, top: tip.y }, onMouseEnter: cancelHideTip, onMouseLeave: hideTip, onClick: () => openSessionId(tip.id) },
|
|
2660
|
+
h('div', { className: 'audit-tip-head' }, h('span', null, '会话'), h('span', { className: 'audit-tip-title' }, title)),
|
|
2661
|
+
h('div', { className: 'audit-tip-meta' },
|
|
2662
|
+
auditPill(String(tip.id).slice(0, 8) + '…', 'mute'),
|
|
2663
|
+
summary.running === true ? auditPill('运行中', 'ok') : null,
|
|
2664
|
+
summary.archived === true ? auditPill('已归档', 'warn') : null,
|
|
2665
|
+
),
|
|
2666
|
+
summary.cwd ? h('div', { className: 'audit-tip-content' }, summary.cwd) : null,
|
|
2667
|
+
h('div', { className: 'audit-tip-content' }, `ID ${tip.id}`),
|
|
2668
|
+
summary.updatedAt ? h('div', { className: 'audit-tip-foot' }, `更新于 ${fmtTime(summary.updatedAt)}`) : null,
|
|
2669
|
+
h('div', { className: 'audit-tip-foot' }, '点击打开会话'),
|
|
2670
|
+
)
|
|
2671
|
+
}
|
|
2672
|
+
const record = tip.record
|
|
2673
|
+
return h('div', { className: 'audit-tip', style: { left: tip.x, top: tip.y }, onMouseEnter: cancelHideTip, onMouseLeave: hideTip, onClick: () => openMemoryId(tip.id) },
|
|
2674
|
+
h('div', { className: 'audit-tip-head' }, h('span', null, '记忆'), h('span', { className: 'audit-tip-title' }, record ? record.id : tip.id)),
|
|
2675
|
+
record
|
|
2676
|
+
? h('div', null,
|
|
2677
|
+
h('div', { className: 'audit-tip-meta' },
|
|
2678
|
+
auditPill(record.kind, 'mute'),
|
|
2679
|
+
auditPill(record.scope, 'mute'),
|
|
2680
|
+
auditPill(`重要度 ${Number(record.importance ?? 0).toFixed(2)}`, 'mute'),
|
|
2681
|
+
),
|
|
2682
|
+
record.tags && record.tags.length > 0
|
|
2683
|
+
? h('div', { className: 'audit-flat' }, record.tags.map((tag) => h('span', { className: 'tag', key: tag }, tag)))
|
|
2684
|
+
: null,
|
|
2685
|
+
h('div', { className: 'audit-tip-content' }, String(record.content || '')),
|
|
2686
|
+
)
|
|
2687
|
+
: h('div', { className: 'audit-tip-content' }, tip.loading ? '加载记录…' : '记录未找到(可能已删除或不在已加载作用域)'),
|
|
2688
|
+
h('div', { className: 'audit-tip-foot' }, '点击跳转到「记录」页并展开'),
|
|
2689
|
+
)
|
|
2690
|
+
})()
|
|
2691
|
+
|
|
2692
|
+
|
|
2495
2693
|
return h('div', { className: 'audit' },
|
|
2496
2694
|
...banner,
|
|
2497
2695
|
h('div', { className: 'audit-stats' },
|
|
@@ -2521,13 +2719,14 @@ window.__ModuleLoader__.load({
|
|
|
2521
2719
|
load(nextCursor, stack)
|
|
2522
2720
|
} }, '下一页'),
|
|
2523
2721
|
),
|
|
2722
|
+
tipNode,
|
|
2524
2723
|
)
|
|
2525
2724
|
}
|
|
2526
2725
|
|
|
2527
2726
|
/** 待嵌入自动刷新:最多 300 次 × 1.5s(后端挂着时不无限轮询)。 */
|
|
2528
2727
|
const PENDING_POLL_LIMIT = 300
|
|
2529
2728
|
|
|
2530
|
-
function MemoryPanel() {
|
|
2729
|
+
function MemoryPanel({ openSession, sessionInfo } = {}) {
|
|
2531
2730
|
const [records, setRecords] = React.useState([])
|
|
2532
2731
|
const [scopes, setScopes] = React.useState([])
|
|
2533
2732
|
const [embedServer, setEmbedServer] = React.useState(null)
|
|
@@ -2537,6 +2736,7 @@ window.__ModuleLoader__.load({
|
|
|
2537
2736
|
const [dangerAsk, setDangerAsk] = React.useState('')
|
|
2538
2737
|
const [scopeFilter, setScopeFilter] = React.useState('')
|
|
2539
2738
|
const [q, setQ] = React.useState('')
|
|
2739
|
+
const [focusRecord, setFocusRecord] = React.useState(null)
|
|
2540
2740
|
const [loading, setLoading] = React.useState(true)
|
|
2541
2741
|
const [error, setError] = React.useState('')
|
|
2542
2742
|
const [tab, setTab] = React.useState('data')
|
|
@@ -2562,6 +2762,16 @@ window.__ModuleLoader__.load({
|
|
|
2562
2762
|
setLoading(false)
|
|
2563
2763
|
}
|
|
2564
2764
|
React.useEffect(() => { load('', '') }, [])
|
|
2765
|
+
|
|
2766
|
+
/** 审计里的记忆 ID → 切到「记录」页并展开对应记录。 */
|
|
2767
|
+
const openRecord = (id, scope) => {
|
|
2768
|
+
setFocusRecord(id)
|
|
2769
|
+
setTab('data')
|
|
2770
|
+
setQ('')
|
|
2771
|
+
const nextScope = scope || ''
|
|
2772
|
+
setScopeFilter(nextScope)
|
|
2773
|
+
load('', nextScope)
|
|
2774
|
+
}
|
|
2565
2775
|
// 导入完成后从设置页切换回记录页时,列表要能看到新数据(事件由设置页发出)。
|
|
2566
2776
|
React.useEffect(() => {
|
|
2567
2777
|
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
|
|
@@ -2855,7 +3065,7 @@ window.__ModuleLoader__.load({
|
|
|
2855
3065
|
const listBody = !loading && !error && records.length === 0
|
|
2856
3066
|
? h('div', { className: 'empty' }, filtering ? '没有匹配的记忆' : '还没有记忆')
|
|
2857
3067
|
: h('div', { className: 'list' },
|
|
2858
|
-
records.map((rec) => h(RecordCard, { key: rec.id, rec, vectorOn: configured && vectorEnabled, labels: labels, onSaved: () => { setPendingTick(0); load() }, onDeleted: () => { setPendingTick(0); load() } })))
|
|
3068
|
+
records.map((rec) => h(RecordCard, { key: rec.id, rec, focus: focusRecord === rec.id, vectorOn: configured && vectorEnabled, labels: labels, onSaved: () => { setPendingTick(0); load() }, onDeleted: () => { setPendingTick(0); load() } })))
|
|
2859
3069
|
|
|
2860
3070
|
// 服务页底部:一句号召 + 两个外链(Star / issue)。放在内容最后,不打扰上面的状态卡。
|
|
2861
3071
|
const footer = h('div', { className: 'footer' },
|
|
@@ -2901,7 +3111,7 @@ window.__ModuleLoader__.load({
|
|
|
2901
3111
|
: tab === 'tree'
|
|
2902
3112
|
? treeBody
|
|
2903
3113
|
: tab === 'audit'
|
|
2904
|
-
? h(AuditTab, { scopes })
|
|
3114
|
+
? h(AuditTab, { scopes, records, openRecord, openSession, sessionInfo })
|
|
2905
3115
|
: overviewBody,
|
|
2906
3116
|
)
|
|
2907
3117
|
}
|
|
@@ -2909,10 +3119,10 @@ window.__ModuleLoader__.load({
|
|
|
2909
3119
|
const inject = ['slots']
|
|
2910
3120
|
|
|
2911
3121
|
/** 侧栏入口打开的主界面页面(整块可滚动,内容就是面板本体)。 */
|
|
2912
|
-
function MemoryPage() {
|
|
3122
|
+
function MemoryPage({ openSession, sessionInfo } = {}) {
|
|
2913
3123
|
return h('div', { className: 'mem-page' },
|
|
2914
3124
|
h('div', { className: 'mem-page-head' }, h('h2', null, '记忆系统')),
|
|
2915
|
-
h(MemoryPanel, {}),
|
|
3125
|
+
h(MemoryPanel, { openSession, sessionInfo }),
|
|
2916
3126
|
)
|
|
2917
3127
|
}
|
|
2918
3128
|
|
|
@@ -2955,9 +3165,40 @@ window.__ModuleLoader__.load({
|
|
|
2955
3165
|
|
|
2956
3166
|
const slots = ctx.get('slots')
|
|
2957
3167
|
if (slots === undefined) return
|
|
3168
|
+
|
|
3169
|
+
/** 宿主 uiWorkspace 服务:打开会话 / 读取会话摘要(旧宿主缺失时静默降级)。 */
|
|
3170
|
+
const workspaceService = () => {
|
|
3171
|
+
try { return ctx.get('uiWorkspace') } catch { return undefined }
|
|
3172
|
+
}
|
|
3173
|
+
const openSession = (id) => {
|
|
3174
|
+
try {
|
|
3175
|
+
const workspace = workspaceService()
|
|
3176
|
+
if (workspace && typeof workspace.openSession === 'function') {
|
|
3177
|
+
workspace.openSession(id)
|
|
3178
|
+
return
|
|
3179
|
+
}
|
|
3180
|
+
// 没有 uiWorkspace(极旧宿主/独立预览)时退回 hash 路由;不保证宿主识别。
|
|
3181
|
+
if (typeof window !== 'undefined') window.location.hash = `#/s/${encodeURIComponent(id)}`
|
|
3182
|
+
} catch (error) {
|
|
3183
|
+
console.warn('[dsh-memory] 打开会话失败:', error?.message)
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
const sessionInfo = (id) => {
|
|
3187
|
+
try {
|
|
3188
|
+
const workspace = workspaceService()
|
|
3189
|
+
const summary = workspace?.sessions?.list?.getSnapshot?.()?.byId?.[id]
|
|
3190
|
+
if (summary !== undefined) return summary
|
|
3191
|
+
const session = ctx.get('sessions')?.get?.(id)
|
|
3192
|
+
if (session === undefined) return undefined
|
|
3193
|
+
return session.summary ?? session
|
|
3194
|
+
} catch {
|
|
3195
|
+
return undefined
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
|
|
2958
3199
|
slots.inject('settings.section', () => slots.register(
|
|
2959
3200
|
{ name: 'settings.section', id: 'memory', order: 24, label: NAV_LABEL },
|
|
2960
|
-
() => React.createElement(MemoryPanel),
|
|
3201
|
+
() => React.createElement(MemoryPanel, { openSession, sessionInfo }),
|
|
2961
3202
|
))
|
|
2962
3203
|
|
|
2963
3204
|
// 侧栏入口(可选):开启后在左侧栏「插件」下方多一个「记忆系统」,点击在主界面打开面板。
|
|
@@ -2976,7 +3217,7 @@ window.__ModuleLoader__.load({
|
|
|
2976
3217
|
}
|
|
2977
3218
|
try {
|
|
2978
3219
|
sidebarDisposers = [
|
|
2979
|
-
slots.inject('main', () => slots.register({ name: 'main', key: 'memory' }, () => React.createElement(MemoryPage))),
|
|
3220
|
+
slots.inject('main', () => slots.register({ name: 'main', key: 'memory' }, () => React.createElement(MemoryPage, { openSession, sessionInfo }))),
|
|
2980
3221
|
slots.inject('sidebar.panellist', () => slots.register(
|
|
2981
3222
|
{ name: 'sidebar.panellist', id: 'memory', order: 20, label: () => NAV_LABEL },
|
|
2982
3223
|
() => React.createElement(NavLineIcon),
|
package/lib/panel.js
CHANGED
|
@@ -592,6 +592,7 @@ async function handle(ctx, routePath, req, res) {
|
|
|
592
592
|
if (method === 'GET' && path === '/records') {
|
|
593
593
|
const rawScope = url.searchParams.get('scope')
|
|
594
594
|
const query = (url.searchParams.get('q') ?? '').trim().toLowerCase()
|
|
595
|
+
const idQuery = (url.searchParams.get('id') ?? '').trim()
|
|
595
596
|
// scope 先过同一套规范化:非法 → 400(而不是当成一个陌生 scope 去建文件);
|
|
596
597
|
// 合法但不存在的 scope → 空列表。`peek`/`peekScope`,**绝不通过 store.scope() 创建**。
|
|
597
598
|
let scope = null
|
|
@@ -624,6 +625,9 @@ async function handle(ctx, routePath, req, res) {
|
|
|
624
625
|
|| r.kind.toLowerCase().includes(query)
|
|
625
626
|
|| r.tags.some((t) => t.toLowerCase().includes(query)))
|
|
626
627
|
}
|
|
628
|
+
if (idQuery) {
|
|
629
|
+
records = records.filter((r) => r.id === idQuery || r.id.startsWith(idQuery))
|
|
630
|
+
}
|
|
627
631
|
writeJson(res, { ok: true, value: { records } })
|
|
628
632
|
return
|
|
629
633
|
}
|