@restregular/dsh-memory 0.12.4 → 0.12.6
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 +18 -0
- package/README.md +2 -0
- package/lib/client.js +252 -33
- package/lib/panel.js +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的版本记录。安装 id 与 npm 版本一一对应。
|
|
4
4
|
|
|
5
|
+
## 0.12.6 — 审计详情分类、滚动与关联跳转
|
|
6
|
+
|
|
7
|
+
- **详情完整可滚动**:审计页采用固定视口高度 + `grid-template-rows:minmax(0,1fr)`,详情面板 `height:100%` 独立滚动,长内容可以滚到底部;整页不滚动。
|
|
8
|
+
- **选择与省略分类展示**:详情里按组显示「选中正文 / 本次新增 / 标签索引 / 省略(按原因分组)/ 去重跳过」,每组有数量;候选与可枚举 ID 的关系有说明,不再混成一排。
|
|
9
|
+
- **记忆 ID 浮窗**:hover 显示记录类型、作用域、重要度、标签与原文摘要;点击跳到「记录」页并自动展开该记录(`RecordCard` 新增 focus 展开)。记录不在当前列表时通过 `/records?id=` 精确补查。
|
|
10
|
+
- **会话 ID 浮窗与跳转**:hover 显示会话标题/cwd/更新时间/运行状态;点击通过宿主 `uiWorkspace.openSession` 打开会话(旧宿主退回 hash 路由)。
|
|
11
|
+
- 面板 `/records` 新增 `id`(精确或前缀)过滤,供审计详情按 ID 补查。
|
|
12
|
+
- 测试补充:详情 ID 分组、记忆/会话 ID hover 浮窗与点击回调、记录页自动展开;全量 323 项 322 通过 1 跳过。
|
|
13
|
+
|
|
14
|
+
## 0.12.5 — 审计表头与行严格对齐
|
|
15
|
+
|
|
16
|
+
- 表头移入滚动容器内部并设为 sticky:表头与行共享同一个内容宽度(含滚动条),不再出现标题比内容偏左。
|
|
17
|
+
- 表头与行统一 `box-sizing: border-box`,使用相同的 1px 透明/实线边框与 9px 水平内边距,列起点逐像素一致。
|
|
18
|
+
- 重新分配列宽:通道 140、触发/阶段 `minmax(150px,1.3fr)`、候选 `minmax(110px,.8fr)`、预算 112、
|
|
19
|
+
投递 `minmax(108px,.9fr)`、结果 92;总宽度仍自适应,触发和投递不再被截断。
|
|
20
|
+
- 行内预算改为紧凑条(flex:进度条 + `used/budget`),不再套用详情页的三列预算网格,避免数字被裁切。
|
|
21
|
+
- 测试新增:表头存在、行内预算为紧凑条、表头列名可见。
|
|
22
|
+
|
|
5
23
|
## 0.12.4 — 审计页自动刷新与窗口内布局
|
|
6
24
|
|
|
7
25
|
- **自动刷新**:默认开启,间隔 0.5 秒;可关闭,并可在 0.5 / 1 / 2 / 5 / 10 秒之间切换。
|
package/README.md
CHANGED
|
@@ -415,6 +415,8 @@ npm run verify # 构建到 .verify/,不落 packages/
|
|
|
415
415
|
|
|
416
416
|
## 更新日志
|
|
417
417
|
|
|
418
|
+
- **0.12.6** —— 审计详情分类展示选中/新增/标签/省略/去重 ID;记忆与会话 ID 支持 hover 浮窗和点击跳转;详情独立滚动可到底。
|
|
419
|
+
- **0.12.5** —— 审计表头移入滚动容器并 sticky,与行严格对齐;重分配列宽,行内预算改紧凑条。
|
|
418
420
|
- **0.12.4** —— 审计页默认每 0.5 秒自动刷新(可关/可调间隔);移除顶部标题与气泡,整页固定在窗口内,仅列表滚动;新增表头并优化列宽;复制/导出提示就地显示。
|
|
419
421
|
- **0.12.3** —— 审计页筛选改为两行紧凑布局与自绘时间范围/开关;事件列表放入独立滚动容器。
|
|
420
422
|
- **0.12.2** —— 修复 `CordisMemoryService` 未转发审计方法,导致审计页显示“provider 未提供注入审计接口”;升级后需重启 DSH。
|
package/lib/client.js
CHANGED
|
@@ -361,15 +361,16 @@ 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
|
-
'.memp .audit-table-head{display:grid;grid-template-columns:
|
|
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)}',
|
|
368
|
+
'.memp .audit-table-head span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
368
369
|
'.memp .audit-list{display:flex;flex-direction:column;gap:5px;min-width:0;flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;padding:5px 4px 1px 1px;scrollbar-width:thin;scrollbar-color:color-mix(in srgb,var(--dsw-alias-label-secondary) 30%,transparent) transparent}',
|
|
369
370
|
'.memp .audit-list::-webkit-scrollbar{width:8px}',
|
|
370
371
|
'.memp .audit-list::-webkit-scrollbar-thumb{background:color-mix(in srgb,var(--dsw-alias-label-secondary) 28%,transparent);border-radius:999px;border:2px solid transparent;background-clip:padding-box}',
|
|
371
372
|
'.memp .audit-list::-webkit-scrollbar-track{background:transparent}',
|
|
372
|
-
'.memp .audit-row{display:grid;grid-template-columns:
|
|
373
|
+
'.memp .audit-row{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;box-sizing:border-box;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;background:var(--dsw-alias-bg-layer-1);padding:6px 9px;font-size:11.5px;cursor:pointer;text-align:left;color:inherit;width:100%}',
|
|
373
374
|
'.memp .audit-row:hover{border-color:var(--dsw-alias-brand-primary)}',
|
|
374
375
|
'.memp .audit-row.on{border-color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 6%,var(--dsw-alias-bg-layer-1))}',
|
|
375
376
|
'.memp .audit-row .m{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
@@ -384,7 +385,7 @@ window.__ModuleLoader__.load({
|
|
|
384
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))}',
|
|
385
386
|
'.memp .audit-pill.mute{color:var(--dsw-alias-label-secondary)}',
|
|
386
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}',
|
|
387
|
-
'.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:100%;min-height:0;overflow:auto;scrollbar-width:thin}',
|
|
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;height:100%;max-height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin}',
|
|
388
389
|
'.memp .audit-detail-head{display:flex;gap:7px;align-items:center}',
|
|
389
390
|
'.memp .audit-detail-head b{font-size:12.5px}',
|
|
390
391
|
'.memp .audit-detail-head .spacer{flex:1}',
|
|
@@ -395,6 +396,11 @@ window.__ModuleLoader__.load({
|
|
|
395
396
|
'.memp .audit-sec{border-top:1px solid var(--dsw-alias-border-l1);padding-top:8px;display:flex;flex-direction:column;gap:5px}',
|
|
396
397
|
'.memp .audit-sec-title{font-size:10.5px;letter-spacing:.04em;color:var(--dsw-alias-label-secondary)}',
|
|
397
398
|
'.memp .audit-budget{display:grid;grid-template-columns:64px minmax(0,1fr) 92px;gap:7px;align-items:center;font-size:10.5px;color:var(--dsw-alias-label-secondary)}',
|
|
399
|
+
'.memp .audit-budget-compact{display:flex;align-items:center;gap:5px;min-width:0;font-size:10px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}',
|
|
400
|
+
'.memp .audit-budget-compact .bar{flex:1;min-width:18px;height:4px;border-radius:999px;background:var(--dsw-alias-bg-layer-2);overflow:hidden}',
|
|
401
|
+
'.memp .audit-budget-compact .bar i{display:block;height:100%;border-radius:999px;background:var(--dsw-alias-brand-primary)}',
|
|
402
|
+
'.memp .audit-budget-compact .bar i.over{background:var(--dsw-alias-label-danger, #e05555)}',
|
|
403
|
+
'.memp .audit-budget-compact .num{flex:none;white-space:nowrap}',
|
|
398
404
|
'.memp .audit-budget .bar{height:5px;border-radius:999px;background:var(--dsw-alias-bg-layer-2);overflow:hidden}',
|
|
399
405
|
'.memp .audit-budget .bar i{display:block;height:100%;border-radius:999px;background:var(--dsw-alias-brand-primary)}',
|
|
400
406
|
'.memp .audit-budget .bar i.over{background:var(--dsw-alias-label-danger, #e05555)}',
|
|
@@ -402,7 +408,22 @@ window.__ModuleLoader__.load({
|
|
|
402
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}',
|
|
403
409
|
'.memp .audit-pager{display:flex;gap:6px;align-items:center;justify-content:flex-end;font-size:11px;color:var(--dsw-alias-label-secondary)}',
|
|
404
410
|
'.memp .audit-flat{display:flex;flex-wrap:wrap;gap:4px}',
|
|
405
|
-
'
|
|
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:hidden;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:none;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:170px;overflow:hidden}',
|
|
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)}',
|
|
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}}',
|
|
406
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 - 120px);max-height:calc(100vh - 120px)}}',
|
|
407
428
|
].join('')
|
|
408
429
|
|
|
@@ -704,7 +725,7 @@ window.__ModuleLoader__.load({
|
|
|
704
725
|
})
|
|
705
726
|
}
|
|
706
727
|
|
|
707
|
-
function RecordCard({ rec, vectorOn, labels, onSaved, onDeleted }) {
|
|
728
|
+
function RecordCard({ rec, vectorOn, labels, onSaved, onDeleted, focus = false }) {
|
|
708
729
|
// collapsed by default: the list stays scannable, full text on demand
|
|
709
730
|
const [expanded, setExpanded] = React.useState(false)
|
|
710
731
|
const [editing, setEditing] = React.useState(false)
|
|
@@ -716,6 +737,9 @@ window.__ModuleLoader__.load({
|
|
|
716
737
|
const [error, setError] = React.useState('')
|
|
717
738
|
const [copied, setCopied] = React.useState(false)
|
|
718
739
|
|
|
740
|
+
// 从审计页点 memory ID 跳过来时自动展开目标记录。
|
|
741
|
+
React.useEffect(() => { if (focus) setExpanded(true) }, [focus])
|
|
742
|
+
|
|
719
743
|
const copyId = () => {
|
|
720
744
|
try {
|
|
721
745
|
if (navigator?.clipboard?.writeText) void navigator.clipboard.writeText(rec.id)
|
|
@@ -755,7 +779,7 @@ window.__ModuleLoader__.load({
|
|
|
755
779
|
setTags(rec.tags.join(', ')); setImportance(rec.importance)
|
|
756
780
|
}
|
|
757
781
|
|
|
758
|
-
return h('div', { className: 'rec' },
|
|
782
|
+
return h('div', { className: 'rec' + (focus ? ' focus' : '') },
|
|
759
783
|
h('div', {
|
|
760
784
|
className: 'rec-head',
|
|
761
785
|
role: 'button',
|
|
@@ -2117,7 +2141,12 @@ window.__ModuleLoader__.load({
|
|
|
2117
2141
|
{ value: 'custom', label: '自定义日期…', ms: null },
|
|
2118
2142
|
]
|
|
2119
2143
|
|
|
2120
|
-
|
|
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 }) {
|
|
2121
2150
|
const [entries, setEntries] = React.useState([])
|
|
2122
2151
|
const [stats, setStats] = React.useState(null)
|
|
2123
2152
|
const [total, setTotal] = React.useState(0)
|
|
@@ -2142,6 +2171,8 @@ window.__ModuleLoader__.load({
|
|
|
2142
2171
|
const [until, setUntil] = React.useState('')
|
|
2143
2172
|
const [selectedId, setSelectedId] = React.useState(null)
|
|
2144
2173
|
const [reloadTick, setReloadTick] = React.useState(0)
|
|
2174
|
+
const [tip, setTip] = React.useState(null)
|
|
2175
|
+
const [recordCache, setRecordCache] = React.useState({})
|
|
2145
2176
|
|
|
2146
2177
|
function queryParams(cursorValue) {
|
|
2147
2178
|
const params = new URLSearchParams()
|
|
@@ -2205,6 +2236,73 @@ window.__ModuleLoader__.load({
|
|
|
2205
2236
|
|
|
2206
2237
|
const resetAndReload = () => { setCursor(''); setCursorStack([]); setReloadTick((n) => n + 1) }
|
|
2207
2238
|
const selected = selectedId === null ? null : entries.find((entry) => entry.id === selectedId) || null
|
|
2239
|
+
|
|
2240
|
+
// 记忆 ID / 会话 ID 的悬停浮窗与跳转。
|
|
2241
|
+
const recordMap = {}
|
|
2242
|
+
for (const rec of records) if (rec && rec.id) recordMap[rec.id] = rec
|
|
2243
|
+
for (const [id, rec] of Object.entries(recordCache)) if (!recordMap[id]) recordMap[id] = rec
|
|
2244
|
+
const findRecord = (id) => {
|
|
2245
|
+
if (recordMap[id]) return recordMap[id]
|
|
2246
|
+
return records.find((rec) => rec && rec.id && rec.id.startsWith(id)) || recordCache[id]
|
|
2247
|
+
}
|
|
2248
|
+
const fetchRecord = async (id) => {
|
|
2249
|
+
const known = findRecord(id)
|
|
2250
|
+
if (known) return known
|
|
2251
|
+
try {
|
|
2252
|
+
const value = await api(`records?id=${encodeURIComponent(id)}`)
|
|
2253
|
+
const rec = Array.isArray(value.records) ? value.records[0] : undefined
|
|
2254
|
+
if (rec !== undefined) setRecordCache((prev) => ({ ...prev, [rec.id]: rec, [id]: rec }))
|
|
2255
|
+
return rec
|
|
2256
|
+
} catch {
|
|
2257
|
+
return undefined
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
const tipPosition = (event) => {
|
|
2261
|
+
const width = typeof window !== 'undefined' ? window.innerWidth : 1200
|
|
2262
|
+
const height = typeof window !== 'undefined' ? window.innerHeight : 800
|
|
2263
|
+
return {
|
|
2264
|
+
x: Math.max(8, Math.min(event.clientX + 14, width - 390)),
|
|
2265
|
+
y: Math.max(8, Math.min(event.clientY + 14, height - 320)),
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
const moveTip = (event) => {
|
|
2269
|
+
if (!event || typeof event.clientX !== 'number') return
|
|
2270
|
+
setTip((prev) => prev === null ? prev : { ...prev, ...tipPosition(event) })
|
|
2271
|
+
}
|
|
2272
|
+
const hideTip = () => setTip(null)
|
|
2273
|
+
const showMemoryTip = (id, event) => {
|
|
2274
|
+
const pos = tipPosition(event)
|
|
2275
|
+
const known = findRecord(id)
|
|
2276
|
+
setTip({ type: 'memory', id, record: known, loading: known === undefined, ...pos })
|
|
2277
|
+
if (known === undefined) {
|
|
2278
|
+
fetchRecord(id).then((record) => {
|
|
2279
|
+
if (record !== undefined) setTip((prev) => prev !== null && prev.id === id ? { ...prev, record, loading: false } : prev)
|
|
2280
|
+
})
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
const showSessionTip = (id, event) => {
|
|
2284
|
+
const summary = typeof sessionInfo === 'function' ? (() => { try { return sessionInfo(id) } catch { return undefined } })() : undefined
|
|
2285
|
+
setTip({ type: 'session', id, summary, ...tipPosition(event) })
|
|
2286
|
+
}
|
|
2287
|
+
const openMemoryId = async (id) => {
|
|
2288
|
+
const record = findRecord(id) || await fetchRecord(id)
|
|
2289
|
+
hideTip()
|
|
2290
|
+
if (typeof openRecord === 'function') openRecord(record?.id ?? id, record?.scope)
|
|
2291
|
+
}
|
|
2292
|
+
const openSessionId = (id) => {
|
|
2293
|
+
hideTip()
|
|
2294
|
+
if (typeof openSession === 'function') openSession(id)
|
|
2295
|
+
}
|
|
2296
|
+
const idChip = (id, tone = '', title = undefined) => h('button', {
|
|
2297
|
+
key: `${tone}:${id}`,
|
|
2298
|
+
className: 'audit-id' + (tone ? ` ${tone}` : ''),
|
|
2299
|
+
title: title || id,
|
|
2300
|
+
onMouseEnter: (event) => showMemoryTip(id, event),
|
|
2301
|
+
onMouseMove: moveTip,
|
|
2302
|
+
onMouseLeave: hideTip,
|
|
2303
|
+
onClick: () => openMemoryId(id),
|
|
2304
|
+
}, id.length > 12 ? `${id.slice(0, 8)}…${id.slice(-4)}` : id)
|
|
2305
|
+
|
|
2208
2306
|
const prepared = entries.filter((entry) => entry.delivery && entry.delivery.status === 'unknown' && entry.reasonCode === 'prepared').length
|
|
2209
2307
|
const suppressed = entries.filter((entry) => entry.delivery && (entry.delivery.status === 'suppressed' || entry.delivery.status === 'not_attempted')).length
|
|
2210
2308
|
const failed = entries.filter((entry) => entry.outcome === 'failed').length
|
|
@@ -2352,7 +2450,7 @@ window.__ModuleLoader__.load({
|
|
|
2352
2450
|
`${entry.trigger || '—'}${entry.phase ? ` / ${entry.phase}` : ''}`),
|
|
2353
2451
|
h('span', { className: 'm nums col-nums' }, `${candidates} / ${picked} / ${omitted}`),
|
|
2354
2452
|
h('span', { className: 'm col-budget' }, budget
|
|
2355
|
-
? h('span', { className: 'audit-budget' },
|
|
2453
|
+
? h('span', { className: 'audit-budget-compact' },
|
|
2356
2454
|
h('span', { className: 'bar' }, h('i', { className: budget.over ? 'over' : '', style: { width: `${budget.budget > 0 ? Math.min(100, Math.round((budget.used / budget.budget) * 100)) : 100}%` } })),
|
|
2357
2455
|
h('span', { className: 'num' }, `${budget.used}/${budget.budget}`),
|
|
2358
2456
|
)
|
|
@@ -2374,10 +2472,36 @@ window.__ModuleLoader__.load({
|
|
|
2374
2472
|
})
|
|
2375
2473
|
const selectedIds = selected.selected ? selected.selected.contentIds : (selected.contentIds || [])
|
|
2376
2474
|
const hintIds = selected.selected ? selected.selected.hintIds : (selected.hintIds || [])
|
|
2475
|
+
const newlyAddedIds = selected.selected && Array.isArray(selected.selected.newlyAddedIds) ? selected.selected.newlyAddedIds : []
|
|
2377
2476
|
const omitted = Array.isArray(selected.omitted) ? selected.omitted : []
|
|
2477
|
+
const dedupIds = selected.dedup && Array.isArray(selected.dedup.ids) ? selected.dedup.ids : []
|
|
2478
|
+
const omitGroups = new Map()
|
|
2479
|
+
for (const item of omitted) {
|
|
2480
|
+
const reason = item.reason || 'other'
|
|
2481
|
+
if (!omitGroups.has(reason)) omitGroups.set(reason, [])
|
|
2482
|
+
omitGroups.get(reason).push(item)
|
|
2483
|
+
}
|
|
2484
|
+
const sameIdSet = (a, b) => a.length === b.length && a.every((id) => b.includes(id))
|
|
2485
|
+
const idGroup = (label, ids, tone, empty = '无', titleOf = undefined) => h('div', { className: 'audit-id-group' },
|
|
2486
|
+
h('div', { className: 'audit-id-group-title' }, h('span', null, label), h('b', null, String(ids.length))),
|
|
2487
|
+
ids.length > 0
|
|
2488
|
+
? h('div', { className: 'audit-flat' }, ids.map((id) => idChip(id, tone, titleOf ? titleOf(id) : undefined)))
|
|
2489
|
+
: h('span', { className: 'audit-id-sub' }, empty),
|
|
2490
|
+
)
|
|
2378
2491
|
const kv = (label, value) => (value === undefined || value === null || value === '')
|
|
2379
2492
|
? null
|
|
2380
2493
|
: [h('span', { className: 'k', key: `k-${label}` }, label), h('span', { className: 'v', key: `v-${label}` }, String(value))]
|
|
2494
|
+
const sessionNode = selected.sessionId
|
|
2495
|
+
? [h('span', { className: 'k', key: 'k-session' }, '会话'),
|
|
2496
|
+
h('span', { className: 'v', key: 'v-session' }, h('button', {
|
|
2497
|
+
className: 'audit-id',
|
|
2498
|
+
title: selected.sessionId,
|
|
2499
|
+
onMouseEnter: (event) => showSessionTip(selected.sessionId, event),
|
|
2500
|
+
onMouseMove: moveTip,
|
|
2501
|
+
onMouseLeave: hideTip,
|
|
2502
|
+
onClick: () => openSessionId(selected.sessionId),
|
|
2503
|
+
}, selected.sessionId))]
|
|
2504
|
+
: null
|
|
2381
2505
|
const json = JSON.stringify(selected, null, 2)
|
|
2382
2506
|
return h('div', { className: 'audit-detail' },
|
|
2383
2507
|
h('div', { className: 'audit-detail-head' },
|
|
@@ -2392,7 +2516,7 @@ window.__ModuleLoader__.load({
|
|
|
2392
2516
|
kv('序号', selected.seq),
|
|
2393
2517
|
kv('时间', fmtTime(selected.at)),
|
|
2394
2518
|
kv('schema', selected.schemaVersion || '旧版'),
|
|
2395
|
-
|
|
2519
|
+
sessionNode,
|
|
2396
2520
|
kv('step', selected.step),
|
|
2397
2521
|
kv('通道', `${auditChannelLabel(selected.channel)} / ${selected.kind}`),
|
|
2398
2522
|
kv('阶段', selected.stage),
|
|
@@ -2422,10 +2546,29 @@ window.__ModuleLoader__.load({
|
|
|
2422
2546
|
kv('选中', selectedIds.length),
|
|
2423
2547
|
kv('新增', selected.selected && selected.selected.newlyAddedIds ? selected.selected.newlyAddedIds.length : '—'),
|
|
2424
2548
|
kv('hint', hintIds.length),
|
|
2549
|
+
kv('省略', omitted.length),
|
|
2425
2550
|
kv('去重跳过', selected.dedup ? selected.dedup.skipped : '—'),
|
|
2426
2551
|
),
|
|
2427
|
-
|
|
2428
|
-
|
|
2552
|
+
h('div', { className: 'audit-id-sub' }, '候选中的可枚举 ID = 选中 + 省略;标签过滤 / 退役排除只在上方计数里。'),
|
|
2553
|
+
idGroup(selected.channel === 'rules' ? '选中规则' : '选中正文', selectedIds, '', '没有选中 ID'),
|
|
2554
|
+
newlyAddedIds.length > 0 && !sameIdSet(newlyAddedIds, selectedIds)
|
|
2555
|
+
? idGroup('本次新增到消息', newlyAddedIds, '', '无')
|
|
2556
|
+
: null,
|
|
2557
|
+
hintIds.length > 0 ? idGroup('标签索引(只给 ID,未注入正文)', hintIds, '', '无') : null,
|
|
2558
|
+
...Array.from(omitGroups.entries()).map(([reason, items]) => idGroup(
|
|
2559
|
+
`省略 · ${AUDIT_OMIT_LABEL[reason] || reason}`,
|
|
2560
|
+
items.map((item) => item.id),
|
|
2561
|
+
'omit',
|
|
2562
|
+
'无',
|
|
2563
|
+
(id) => {
|
|
2564
|
+
const item = items.find((entry) => entry.id === id)
|
|
2565
|
+
return `${id}${item && item.tags && item.tags.length > 0 ? ` · ${item.tags.join(', ')}` : ''}`
|
|
2566
|
+
},
|
|
2567
|
+
)),
|
|
2568
|
+
dedupIds.length > 0 ? idGroup('去重跳过', dedupIds, 'dedup', '无') : null,
|
|
2569
|
+
selectedIds.length + hintIds.length + omitted.length + dedupIds.length === 0
|
|
2570
|
+
? h('div', { className: 'audit-id-sub' }, '这条事件没有可枚举的记忆 ID。')
|
|
2571
|
+
: null,
|
|
2429
2572
|
),
|
|
2430
2573
|
budgetRows.length > 0 ? h('div', { className: 'audit-sec' },
|
|
2431
2574
|
h('div', { className: 'audit-sec-title' }, '预算'),
|
|
@@ -2465,6 +2608,15 @@ window.__ModuleLoader__.load({
|
|
|
2465
2608
|
)
|
|
2466
2609
|
})() : null
|
|
2467
2610
|
|
|
2611
|
+
const listHeader = h('div', { className: 'audit-table-head' },
|
|
2612
|
+
h('span', null, '时间'),
|
|
2613
|
+
h('span', null, '通道 / 事件'),
|
|
2614
|
+
h('span', null, '触发 / 阶段'),
|
|
2615
|
+
h('span', null, '候选 / 选中 / 省略'),
|
|
2616
|
+
h('span', null, '预算'),
|
|
2617
|
+
h('span', null, '投递'),
|
|
2618
|
+
h('span', null, '结果'),
|
|
2619
|
+
)
|
|
2468
2620
|
const listBody = loading
|
|
2469
2621
|
? h('div', { className: 'audit-empty' }, '加载审计事件…')
|
|
2470
2622
|
: entries.length === 0
|
|
@@ -2474,21 +2626,45 @@ window.__ModuleLoader__.load({
|
|
|
2474
2626
|
error ? h('div', { className: 'err' }, error) : null,
|
|
2475
2627
|
error ? h('div', null, h('button', { onClick: () => setReloadTick((n) => n + 1) }, '重试')) : null,
|
|
2476
2628
|
)
|
|
2477
|
-
: h('div', { className: 'audit-list' }, entries.map(row))
|
|
2629
|
+
: h('div', { className: 'audit-list' }, listHeader, entries.map(row))
|
|
2630
|
+
const listArea = h('div', { className: 'audit-list-wrap' }, listBody)
|
|
2631
|
+
|
|
2632
|
+
const tipNode = tip === null ? null : (() => {
|
|
2633
|
+
if (tip.type === 'session') {
|
|
2634
|
+
const summary = tip.summary || {}
|
|
2635
|
+
const title = summary.title || summary.name || `会话 ${String(tip.id).slice(0, 8)}`
|
|
2636
|
+
return h('div', { className: 'audit-tip', style: { left: tip.x, top: tip.y } },
|
|
2637
|
+
h('div', { className: 'audit-tip-head' }, h('span', null, '会话'), h('span', { className: 'audit-tip-title' }, title)),
|
|
2638
|
+
h('div', { className: 'audit-tip-meta' },
|
|
2639
|
+
auditPill(String(tip.id).slice(0, 8) + '…', 'mute'),
|
|
2640
|
+
summary.running === true ? auditPill('运行中', 'ok') : null,
|
|
2641
|
+
summary.archived === true ? auditPill('已归档', 'warn') : null,
|
|
2642
|
+
),
|
|
2643
|
+
summary.cwd ? h('div', { className: 'audit-tip-content' }, summary.cwd) : null,
|
|
2644
|
+
summary.updatedAt ? h('div', { className: 'audit-tip-foot' }, `更新于 ${fmtTime(summary.updatedAt)}`) : null,
|
|
2645
|
+
h('div', { className: 'audit-tip-foot' }, '点击打开会话'),
|
|
2646
|
+
)
|
|
2647
|
+
}
|
|
2648
|
+
const record = tip.record
|
|
2649
|
+
return h('div', { className: 'audit-tip', style: { left: tip.x, top: tip.y } },
|
|
2650
|
+
h('div', { className: 'audit-tip-head' }, h('span', null, '记忆'), h('span', { className: 'audit-tip-title' }, record ? record.id : tip.id)),
|
|
2651
|
+
record
|
|
2652
|
+
? h('div', null,
|
|
2653
|
+
h('div', { className: 'audit-tip-meta' },
|
|
2654
|
+
auditPill(record.kind, 'mute'),
|
|
2655
|
+
auditPill(record.scope, 'mute'),
|
|
2656
|
+
auditPill(`重要度 ${Number(record.importance ?? 0).toFixed(2)}`, 'mute'),
|
|
2657
|
+
),
|
|
2658
|
+
record.tags && record.tags.length > 0
|
|
2659
|
+
? h('div', { className: 'audit-flat' }, record.tags.map((tag) => h('span', { className: 'tag', key: tag }, tag)))
|
|
2660
|
+
: null,
|
|
2661
|
+
h('div', { className: 'audit-tip-content' }, `${String(record.content || '').slice(0, 700)}${String(record.content || '').length > 700 ? '…' : ''}`),
|
|
2662
|
+
)
|
|
2663
|
+
: h('div', { className: 'audit-tip-content' }, tip.loading ? '加载记录…' : '记录未找到(可能已删除或不在已加载作用域)'),
|
|
2664
|
+
h('div', { className: 'audit-tip-foot' }, '点击跳转到「记录」页并展开'),
|
|
2665
|
+
)
|
|
2666
|
+
})()
|
|
2478
2667
|
|
|
2479
|
-
const listHeader = h('div', { className: 'audit-table-head' },
|
|
2480
|
-
h('span', null, '时间'),
|
|
2481
|
-
h('span', null, '通道 / 事件'),
|
|
2482
|
-
h('span', null, '触发 / 阶段'),
|
|
2483
|
-
h('span', null, '候选 / 选中 / 省略'),
|
|
2484
|
-
h('span', null, '预算'),
|
|
2485
|
-
h('span', null, '投递'),
|
|
2486
|
-
h('span', null, '结果'),
|
|
2487
|
-
)
|
|
2488
|
-
const listArea = h('div', { className: 'audit-list-wrap' },
|
|
2489
|
-
entries.length > 0 ? listHeader : null,
|
|
2490
|
-
listBody,
|
|
2491
|
-
)
|
|
2492
2668
|
|
|
2493
2669
|
return h('div', { className: 'audit' },
|
|
2494
2670
|
...banner,
|
|
@@ -2519,13 +2695,14 @@ window.__ModuleLoader__.load({
|
|
|
2519
2695
|
load(nextCursor, stack)
|
|
2520
2696
|
} }, '下一页'),
|
|
2521
2697
|
),
|
|
2698
|
+
tipNode,
|
|
2522
2699
|
)
|
|
2523
2700
|
}
|
|
2524
2701
|
|
|
2525
2702
|
/** 待嵌入自动刷新:最多 300 次 × 1.5s(后端挂着时不无限轮询)。 */
|
|
2526
2703
|
const PENDING_POLL_LIMIT = 300
|
|
2527
2704
|
|
|
2528
|
-
function MemoryPanel() {
|
|
2705
|
+
function MemoryPanel({ openSession, sessionInfo } = {}) {
|
|
2529
2706
|
const [records, setRecords] = React.useState([])
|
|
2530
2707
|
const [scopes, setScopes] = React.useState([])
|
|
2531
2708
|
const [embedServer, setEmbedServer] = React.useState(null)
|
|
@@ -2535,6 +2712,7 @@ window.__ModuleLoader__.load({
|
|
|
2535
2712
|
const [dangerAsk, setDangerAsk] = React.useState('')
|
|
2536
2713
|
const [scopeFilter, setScopeFilter] = React.useState('')
|
|
2537
2714
|
const [q, setQ] = React.useState('')
|
|
2715
|
+
const [focusRecord, setFocusRecord] = React.useState(null)
|
|
2538
2716
|
const [loading, setLoading] = React.useState(true)
|
|
2539
2717
|
const [error, setError] = React.useState('')
|
|
2540
2718
|
const [tab, setTab] = React.useState('data')
|
|
@@ -2560,6 +2738,16 @@ window.__ModuleLoader__.load({
|
|
|
2560
2738
|
setLoading(false)
|
|
2561
2739
|
}
|
|
2562
2740
|
React.useEffect(() => { load('', '') }, [])
|
|
2741
|
+
|
|
2742
|
+
/** 审计里的记忆 ID → 切到「记录」页并展开对应记录。 */
|
|
2743
|
+
const openRecord = (id, scope) => {
|
|
2744
|
+
setFocusRecord(id)
|
|
2745
|
+
setTab('data')
|
|
2746
|
+
setQ('')
|
|
2747
|
+
const nextScope = scope || ''
|
|
2748
|
+
setScopeFilter(nextScope)
|
|
2749
|
+
load('', nextScope)
|
|
2750
|
+
}
|
|
2563
2751
|
// 导入完成后从设置页切换回记录页时,列表要能看到新数据(事件由设置页发出)。
|
|
2564
2752
|
React.useEffect(() => {
|
|
2565
2753
|
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
|
|
@@ -2853,7 +3041,7 @@ window.__ModuleLoader__.load({
|
|
|
2853
3041
|
const listBody = !loading && !error && records.length === 0
|
|
2854
3042
|
? h('div', { className: 'empty' }, filtering ? '没有匹配的记忆' : '还没有记忆')
|
|
2855
3043
|
: h('div', { className: 'list' },
|
|
2856
|
-
records.map((rec) => h(RecordCard, { key: rec.id, rec, vectorOn: configured && vectorEnabled, labels: labels, onSaved: () => { setPendingTick(0); load() }, onDeleted: () => { setPendingTick(0); load() } })))
|
|
3044
|
+
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() } })))
|
|
2857
3045
|
|
|
2858
3046
|
// 服务页底部:一句号召 + 两个外链(Star / issue)。放在内容最后,不打扰上面的状态卡。
|
|
2859
3047
|
const footer = h('div', { className: 'footer' },
|
|
@@ -2899,7 +3087,7 @@ window.__ModuleLoader__.load({
|
|
|
2899
3087
|
: tab === 'tree'
|
|
2900
3088
|
? treeBody
|
|
2901
3089
|
: tab === 'audit'
|
|
2902
|
-
? h(AuditTab, { scopes })
|
|
3090
|
+
? h(AuditTab, { scopes, records, openRecord, openSession, sessionInfo })
|
|
2903
3091
|
: overviewBody,
|
|
2904
3092
|
)
|
|
2905
3093
|
}
|
|
@@ -2907,10 +3095,10 @@ window.__ModuleLoader__.load({
|
|
|
2907
3095
|
const inject = ['slots']
|
|
2908
3096
|
|
|
2909
3097
|
/** 侧栏入口打开的主界面页面(整块可滚动,内容就是面板本体)。 */
|
|
2910
|
-
function MemoryPage() {
|
|
3098
|
+
function MemoryPage({ openSession, sessionInfo } = {}) {
|
|
2911
3099
|
return h('div', { className: 'mem-page' },
|
|
2912
3100
|
h('div', { className: 'mem-page-head' }, h('h2', null, '记忆系统')),
|
|
2913
|
-
h(MemoryPanel, {}),
|
|
3101
|
+
h(MemoryPanel, { openSession, sessionInfo }),
|
|
2914
3102
|
)
|
|
2915
3103
|
}
|
|
2916
3104
|
|
|
@@ -2953,9 +3141,40 @@ window.__ModuleLoader__.load({
|
|
|
2953
3141
|
|
|
2954
3142
|
const slots = ctx.get('slots')
|
|
2955
3143
|
if (slots === undefined) return
|
|
3144
|
+
|
|
3145
|
+
/** 宿主 uiWorkspace 服务:打开会话 / 读取会话摘要(旧宿主缺失时静默降级)。 */
|
|
3146
|
+
const workspaceService = () => {
|
|
3147
|
+
try { return ctx.get('uiWorkspace') } catch { return undefined }
|
|
3148
|
+
}
|
|
3149
|
+
const openSession = (id) => {
|
|
3150
|
+
try {
|
|
3151
|
+
const workspace = workspaceService()
|
|
3152
|
+
if (workspace && typeof workspace.openSession === 'function') {
|
|
3153
|
+
workspace.openSession(id)
|
|
3154
|
+
return
|
|
3155
|
+
}
|
|
3156
|
+
// 没有 uiWorkspace(极旧宿主/独立预览)时退回 hash 路由;不保证宿主识别。
|
|
3157
|
+
if (typeof window !== 'undefined') window.location.hash = `#/s/${encodeURIComponent(id)}`
|
|
3158
|
+
} catch (error) {
|
|
3159
|
+
console.warn('[dsh-memory] 打开会话失败:', error?.message)
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
const sessionInfo = (id) => {
|
|
3163
|
+
try {
|
|
3164
|
+
const workspace = workspaceService()
|
|
3165
|
+
const summary = workspace?.sessions?.list?.getSnapshot?.()?.byId?.[id]
|
|
3166
|
+
if (summary !== undefined) return summary
|
|
3167
|
+
const session = ctx.get('sessions')?.get?.(id)
|
|
3168
|
+
if (session === undefined) return undefined
|
|
3169
|
+
return session.summary ?? session
|
|
3170
|
+
} catch {
|
|
3171
|
+
return undefined
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
|
|
2956
3175
|
slots.inject('settings.section', () => slots.register(
|
|
2957
3176
|
{ name: 'settings.section', id: 'memory', order: 24, label: NAV_LABEL },
|
|
2958
|
-
() => React.createElement(MemoryPanel),
|
|
3177
|
+
() => React.createElement(MemoryPanel, { openSession, sessionInfo }),
|
|
2959
3178
|
))
|
|
2960
3179
|
|
|
2961
3180
|
// 侧栏入口(可选):开启后在左侧栏「插件」下方多一个「记忆系统」,点击在主界面打开面板。
|
|
@@ -2974,7 +3193,7 @@ window.__ModuleLoader__.load({
|
|
|
2974
3193
|
}
|
|
2975
3194
|
try {
|
|
2976
3195
|
sidebarDisposers = [
|
|
2977
|
-
slots.inject('main', () => slots.register({ name: 'main', key: 'memory' }, () => React.createElement(MemoryPage))),
|
|
3196
|
+
slots.inject('main', () => slots.register({ name: 'main', key: 'memory' }, () => React.createElement(MemoryPage, { openSession, sessionInfo }))),
|
|
2978
3197
|
slots.inject('sidebar.panellist', () => slots.register(
|
|
2979
3198
|
{ name: 'sidebar.panellist', id: 'memory', order: 20, label: () => NAV_LABEL },
|
|
2980
3199
|
() => 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
|
}
|