@restregular/dsh-memory 0.25.7 → 0.25.9

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,21 @@
2
2
 
3
3
  本项目的版本记录。安装 id 与 npm 版本一一对应。
4
4
 
5
+ ## 0.25.9 — 会话作用域的短 id 改成前 16 位(以前全显示成「会话 session-」)
6
+
7
+ - **问题**:真机会话 id 以 `session-` 开头,那正好是 8 个字符。以前展示会话作用域时取「id 前 8 位」,于是每个会话作用域都渲染成同一个「会话 session-」——用户无法区分是哪个会话,等于没给 id。
8
+ - **口径**:统一改成会话 id 的**前 16 位**,形如 `会话 session-1a2b3c4d`;有会话标题时是 `标题(session-1a2b3c4d)`。规则集中在 `memory-local` 的 `sessionShortId` / `sessionScopeLabel`,服务端与客户端同口径。
9
+ - **覆盖范围**(凡是显示会话作用域名字的地方):`/status` 的 label(面板作用域下拉、记录卡与记忆树)、审计页的会话筛选选项与悬停提示、审计页锁定会话的 pill、以及 `memory_save` / `memory_search` / `memory_list` / `memory_get` / `memory_scopes` 的工具输出。
10
+ - **保持不变**:「记忆权限」浮窗里本会话那一行仍是「当前会话」(0.25.8),标签里的裸 scope 键仍留在 `title`;注入摘要里的 scope 分类标签仍是「会话」(那是分类不是名字)。
11
+ - 测试:新增 `sessionShortId` / `sessionScopeLabel` 的单测(含 `session-` 前缀的真实 id、两个会话必须不同名、异常输入不抛错)、`/status` 真实前缀 id 的回退标签用例、以及客户端 helper 用例;改写三个受口径影响的既有断言。全套 502 tests / 501 pass / 1 skipped。
12
+
13
+ ## 0.25.8 — 记忆权限浮窗不再被「回到底部」按钮盖住;本会话作用域叫「当前会话」
14
+
15
+ - **层级修正(浮窗曾被「回到底部」圆钮压住)**:宿主会话在 active 阶段给输入框所在的 composer seat 上了 `position:sticky + z-index:7`,那是一个独立的层叠上下文;浮窗写在它里面,`position:fixed` 也只在那个上下文里比较层级,永远压不过兄弟层 z-index:8 的「回到底部」按钮。现在浮窗通过 `react-dom` 的 `createPortal` 挂到 `document.body`,直接参与根层叠上下文的排序;`z-index` 从 80 提到 900(会话里的浮动件都在 100 以内,宿主自己的对话框 / 提示层是 1000 起,所以压得过前者、盖不住后者)。拿不到 `react-dom` 的宿主退回原地渲染,功能一致。
16
+ - **点外面关闭仍然正确**:portal 之后浮窗不再长在按钮那棵树里,outside-click 判定补了浮窗自己的 ref,点浮窗内部(搜索框、勾选框、保存)不会被当成「点外面」。
17
+ - **本会话作用域改名「当前会话」**:作用域列表里 `session:<本会话 id>` 那一行不再显示会话标题 + 短 id(或「会话 1a2b3c4d」),统一显示「当前会话」——面板本来就是给这个会话设权限,用户不需要对号入座。**只改本会话那一条**:目录里别的会话的 scope(有记录就会被发现)仍按标题 / 短 id 显示。搜索也走显示名,输入「当前会话」能直接筛到这一行;原始 `session:<id>` 仍留在名称的 `title` 提示里。
18
+ - 测试:新增「浮窗 portal 到 document.body」与「本会话作用域显示为当前会话、别的会话照旧」两个用例,并断言浮窗 `z-index:900`(高于会话浮动件 8 / 100、低于宿主弹窗 1000);改写两个受显示名与排序影响的既有断言。`source/memory-panel/test/*` 53/53 通过,全套 54 个文件里仅 `memory-local/test/multiprocess.test.ts` 因沙箱禁止 spawn 子进程失败(真机全权限可过)。
19
+
5
20
  ## 0.25.7 — 记忆权限里整张作用域卡片都能点选
6
21
 
7
22
  - **卡片整体可点**:「记忆权限」浮窗的作用域列表里,以前只有 16px 的勾选框和名称文字能点,点计数或行内留白没反应。现在整张卡片都能点——点名称、记录数、留白等同点勾选框(选中 / 取消勾选),鼠标移到卡片上就是可点击形态。行内的【绑定】/【可读】/【可写】按钮与勾选框仍各管各的:按钮点击不会再把卡片切换第二次(事件冒泡被拦掉),勾选框也不会被切换两下。
package/README.md CHANGED
@@ -47,7 +47,7 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
47
47
  | **自动召回** | 每轮按用户问题召回;新会话第一步注入项目 / global 摘要;发布、部署、工具失败等行为按标签触发定向召回 |
48
48
  | **印象形态** | 每轮只给每条记忆的短摘要;模型判断相关但需要细节时再 `memory_get` 取全文,省 token 也不丢信息 |
49
49
  | **硬性规则** | `kind: rule` 进系统提示常驻段;行首带 8 位 id,注入的是摘要,需要全文时用 `memory_get`;旧会话会收到新增 / 编辑提醒;超预算有明确警告,不静默丢弃 |
50
- | **记忆权限** | 输入框旁的「记忆权限」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 / 无限制);每个作用域一行就是一条设置:**勾选**表示本会话可访问,行内**【绑定】/【可读】/【可写】**控制工作区默认可见与读写权限——绑定到当前工作区后新会话默认可见,可读 / 可写独立影响工具读写;Agent 通过 `memory_scopes request` 申请到的范围外授权**也用勾选呈现**(名称右边挂一个「AI」气泡,样式与你自己勾选的行区分开),取消勾选只是草稿,**点「保存」才真正撤销**(0.25.4 起),且按钮数字 / 「已选」都把 AI 授权算进去(0.25.5 起)并**实时轮询**——浮窗关着,Agent 刚拿到的授权也会让按钮数字自己变(0.25.6 起);**整张作用域卡片都能点选**,点名称 / 计数 / 留白等同点勾选框(0.25.7 起);Agent 及其子 Agent 都按它检索、注入与 `memory_get` |
50
+ | **记忆权限** | 输入框旁的「记忆权限」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 / 无限制);每个作用域一行就是一条设置:**勾选**表示本会话可访问,行内**【绑定】/【可读】/【可写】**控制工作区默认可见与读写权限——绑定到当前工作区后新会话默认可见,可读 / 可写独立影响工具读写;Agent 通过 `memory_scopes request` 申请到的范围外授权**也用勾选呈现**(名称右边挂一个「AI」气泡,样式与你自己勾选的行区分开),取消勾选只是草稿,**点「保存」才真正撤销**(0.25.4 起),且按钮数字 / 「已选」都把 AI 授权算进去(0.25.5 起)并**实时轮询**——浮窗关着,Agent 刚拿到的授权也会让按钮数字自己变(0.25.6 起);**整张作用域卡片都能点选**,点名称 / 计数 / 留白等同点勾选框(0.25.7 起),本会话那一行直接叫「**当前会话**」(0.25.8 起);浮窗挂在页面根层,不会被输入框上方的浮动按钮盖住(0.25.8 起);Agent 及其子 Agent 都按它检索、注入与 `memory_get` |
51
51
  | **修正版编辑** | 面板里编辑一条记忆 = 新建一条修正版并通过 `supersedes` 指向旧记录,旧记录不原地修改;记录页「是否被修正」筛选默认隐藏旧版本,可切到全部 / 只看已修正 |
52
52
  | **范围外审批** | 普通限制下,工具命中可见域外的记忆时会在**对应会话的输入框上方**出现审批卡(样式与系统权限审批一致):展示工具、Agent 说明、查询关键词与范围外记忆摘要,支持逐条勾选 / 全选 / 取消全选(「允许选中的 N 条」或整单「允许一次」)或「拒绝」;点记忆 ID 直接跳到面板「记录」页并展开该条 |
53
53
  | **上下文去重** | `memory_search` / `memory_list` 返回过的条目记进会话上下文状态;同一版本再次命中只回记忆 ID(`memory_search` 的裸 ID 与带摘要条目之间空一行),并提示用 `memory_get` 取全文(内容更新后重新给摘要) |
@@ -91,7 +91,10 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
91
91
  输入框工具行右侧有「记忆权限」按钮。**打开会话时就会读取这个会话的设置**,按钮上的数字是当前生效的作用域数量,边框样式表示限制等级(绝对限制 = 橙黄实线 / 普通限制 = 蓝色实线 / 无限制 = 灰色虚线;`title` 里写明「已设置 / 使用默认 / 继承父会话 + 数量 + 等级」)。点开的浮窗使用毛玻璃背景,按当前会话列出可选作用域(当前会话 / 当前项目 / global / 已有自定义作用域):
92
92
 
93
93
  - **默认范围**:没有显式设置时(新会话)按默认设置生效 —— **当前会话 + 当前项目 + global + 已绑定的作用域** + **普通限制**;面板按同一份默认范围预选,不会出现空面板。
94
+ - **本会话那一行的名字**(0.25.8):本会话 `session:<id>` 那一行固定显示「**当前会话**」(原始 scope 键在 `title` 里),别的会话的 scope 仍按标题 / 短 id 显示;搜索也按显示名匹配,输入「当前会话」即可筛到这一行。
95
+ - **会话作用域的短 id**(0.25.9):凡是显示会话作用域名字的地方(面板作用域下拉、记录卡与记忆树、审计页的会话筛选与提示、`memory_*` 工具输出、`/status` 的 label)都取会话 id 的**前 16 位**,形如 `会话 session-1a2b3c4d`。以前取前 8 位,而真机会话 id 恰好以 `session-` 开头(正好 8 个字符),结果所有会话作用域都显示成同一个「会话 session-」——等于没给 id。有会话标题时形如 `标题(session-1a2b3c4d)`。
94
96
  - **搜索与批量**:顶部可搜索作用域,支持「全选 / 取消全选」;列表最大高度受限,作用域多时在浮窗内滚动。**整张作用域卡片都能点**(0.25.7 起)——点名称、记录数或行内留白等同点勾选框,只有行内的按钮(勾选框 / 绑定 / 可读 / 可写)各管各的,点它们不会再多切换一次。
97
+ - **浮窗层级**(0.25.8):浮窗 portal 到 `document.body` 渲染,`z-index:900`,不会再被会话里的「回到底部」圆钮(z-index:8)之类浮动件盖住;同时仍低于宿主自己的对话框 / 提示层(1000 起)。
95
98
  - **状态按钮(0.23.0 / 0.23.1)**:作用域列表每行有【绑定】、【可读】|【可写】。**默认范围自带的会话 + 项目 + global 显示为已绑定且不可取消**;**绑定**按钮用于把其它作用域额外并入当前工作区的默认范围(没有显式覆盖的新会话可见);**可读 / 可写**是会话级,独立控制该作用域的读取与写入(关掉可读 → 搜索 / 读取跳过并说明原因;关掉可写 → 保存 / 删除被拒绝并说明原因)。
96
99
  - **限制等级**:
97
100
  - **绝对限制**:可见域外的读取 / 写入 / 删除一律不执行;命中被挡住时会明确告诉 Agent 是「绝对限制」以及怎么调整(不再假装记忆不存在)。
package/lib/client.js CHANGED
@@ -26,6 +26,25 @@ window.__ModuleLoader__.load({
26
26
  const React = require('react')
27
27
  const h = React.createElement
28
28
 
29
+ /**
30
+ * 0.25.8:把「记忆权限」浮窗挂到 document.body 用的 portal。
31
+ *
32
+ * 按钮注册在 conversation.input.right,整个输入框在宿主会话的 active 阶段是
33
+ * `.composerSeat{position:sticky; z-index:7}` —— 一个独立的层叠上下文。浮窗哪怕写
34
+ * `position:fixed` 也只能在这个上下文里排层级,永远压不过兄弟层的「回到底部」圆钮
35
+ * (`.toBottomSlot{z-index:8}`),表现为圆钮盖在浮窗上面。portal 到 body 之后浮窗直接
36
+ * 在根层叠上下文里参与排序,才真正高于 8。
37
+ *
38
+ * react-dom 由宿主的 ModuleLoader 以 seed word 提供(宿主自己与 dshmarket / rewind
39
+ * 等插件的 client bundle 都 require 它)。拿不到就退回原地渲染:层级受限,但不报错。
40
+ */
41
+ const createPortal = (() => {
42
+ try {
43
+ const dom = require('react-dom')
44
+ return dom && typeof dom.createPortal === 'function' ? dom.createPortal : null
45
+ } catch { return null }
46
+ })()
47
+
29
48
  const API = '/memory/api'
30
49
 
31
50
  const CSS = [
@@ -496,7 +515,10 @@ window.__ModuleLoader__.load({
496
515
  '.mem-scope-btn.is-absolute:hover,.mem-scope-btn.is-normal:hover,.mem-scope-btn.is-none:hover{background:var(--dsw-alias-interactive-bg-hover)}',
497
516
  '.mem-scope-btn svg{flex:none}',
498
517
  // 毛玻璃浮窗:半透明 + backdrop blur;不支持 backdrop-filter 时退回实心底。
499
- '.mem-scope-pop{position:fixed;z-index:80;width:340px;max-height:min(520px,72vh);display:flex;flex-direction:column;gap:8px;padding:12px;border:1px solid color-mix(in srgb,var(--dsw-alias-border-l2,var(--dsw-alias-border-l1)) 60%,transparent);border-radius:14px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 78%,transparent);-webkit-backdrop-filter:blur(20px) saturate(1.35);backdrop-filter:blur(20px) saturate(1.35);box-shadow:0 10px 28px rgba(0,0,0,.18);color:var(--dsw-alias-label-primary);font-size:13px;overflow:hidden}',
518
+ // 0.25.8:z-index 80 → 900。浮窗 portal 到 body 后与宿主各层在根层叠上下文里比较:
519
+ // 会话层的「回到底部」按钮是 z-index:8、宿主的下拉/菜单层是 100,而宿主自己的
520
+ // 对话框 / 提示层是 1000 起 —— 取 900 保证压过会话里的所有浮动件,又不会盖住宿主弹窗。
521
+ '.mem-scope-pop{position:fixed;z-index:900;width:340px;max-height:min(520px,72vh);display:flex;flex-direction:column;gap:8px;padding:12px;border:1px solid color-mix(in srgb,var(--dsw-alias-border-l2,var(--dsw-alias-border-l1)) 60%,transparent);border-radius:14px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 78%,transparent);-webkit-backdrop-filter:blur(20px) saturate(1.35);backdrop-filter:blur(20px) saturate(1.35);box-shadow:0 10px 28px rgba(0,0,0,.18);color:var(--dsw-alias-label-primary);font-size:13px;overflow:hidden}',
500
522
  '@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){.mem-scope-pop{background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-1))}}',
501
523
  '.mem-scope-head{display:flex;align-items:center;gap:8px}',
502
524
  '.mem-scope-head h4{margin:0;font-size:13px;font-weight:600;line-height:1.4}',
@@ -652,6 +674,22 @@ window.__ModuleLoader__.load({
652
674
  return rec && rec.expiredAt !== null && rec.expiredAt !== undefined && Number(rec.expiredAt) < Date.now()
653
675
  }
654
676
 
677
+ /**
678
+ * 会话 id → 展示用的短 id(前 16 位,如 `session-1a2b3c4d`)。
679
+ *
680
+ * 为什么是 16 而不是 8:DSH 的会话 id 以 `session-` 开头 —— 正好 8 个字符。
681
+ * 取前 8 位会让所有会话作用域都显示成「会话 session-」,等于没给 id。
682
+ * 服务端 memory-local 的 sessionShortId / sessionScopeLabel 是同一口径。
683
+ */
684
+ const SESSION_SHORT_ID_CHARS = 16
685
+ function sessionShortId(sessionId) {
686
+ return String(sessionId === null || sessionId === undefined ? '' : sessionId).slice(0, SESSION_SHORT_ID_CHARS)
687
+ }
688
+ /** 会话 scope 键(`session:<id>`)→「会话 + 前 16 位 id」。 */
689
+ function sessionScopeLabel(scope) {
690
+ return `会话 ${sessionShortId(String(scope).slice('session:'.length))}`
691
+ }
692
+
655
693
  /**
656
694
  * scope 键 → 展示标签。优先用 /status 返回的 `label`(服务端能查会话标题、能解析
657
695
  * project 的 cwd);服务端没给(旧 provider / 还没加载到)时用本地回退。
@@ -661,7 +699,7 @@ window.__ModuleLoader__.load({
661
699
  if (typeof mapped === 'string' && mapped.length > 0) return mapped
662
700
  if (scope === 'global') return '全局'
663
701
  if (scope.startsWith('project:')) return scope.slice(8)
664
- if (scope.startsWith('session:')) return `会话 ${scope.slice(8, 16)}`
702
+ if (scope.startsWith('session:')) return sessionScopeLabel(scope)
665
703
  return scope
666
704
  }
667
705
 
@@ -3003,11 +3041,11 @@ window.__ModuleLoader__.load({
3003
3041
  const writeErrors = stats && typeof stats.writeErrors === 'number' ? stats.writeErrors : 0
3004
3042
  const sessionOptions = [{ value: '', label: '全部会话(显式)' }]
3005
3043
  .concat((scopes || []).filter((scope) => scope.scope?.startsWith('session:')).map((scope) => ({
3006
- value: scope.scope.slice(8),
3007
- label: scope.label || `会话 ${scope.scope.slice(8, 16)}`,
3044
+ value: scope.scope.slice('session:'.length),
3045
+ label: scope.label || sessionScopeLabel(scope.scope),
3008
3046
  })))
3009
3047
  if (effectiveSession && !sessionOptions.some((item) => item.value === effectiveSession)) {
3010
- sessionOptions.push({ value: effectiveSession, label: `会话 ${effectiveSession.slice(0, 8)}` })
3048
+ sessionOptions.push({ value: effectiveSession, label: sessionScopeLabel(`session:${effectiveSession}`) })
3011
3049
  }
3012
3050
  const channelOptions = [{ value: '', label: '全部通道' }].concat(Object.keys(AUDIT_CHANNEL_META).map((key) => ({ value: key, label: AUDIT_CHANNEL_META[key] })))
3013
3051
  const outcomeOptions = [{ value: '', label: '全部结果' }].concat(Object.keys(AUDIT_OUTCOME_META).map((key) => ({ value: key, label: AUDIT_OUTCOME_META[key].label })))
@@ -3048,7 +3086,7 @@ window.__ModuleLoader__.load({
3048
3086
  const toolbar = h('div', { className: 'audit-toolbar' },
3049
3087
  h('div', { className: 'audit-filter-row' },
3050
3088
  lockSession
3051
- ? h('span', { className: 'audit-pill mute', title: lockSession }, `会话 ${String(lockSession).slice(0, 10)}`)
3089
+ ? h('span', { className: 'audit-pill mute', title: lockSession }, sessionScopeLabel(`session:${lockSession}`))
3052
3090
  : h(Dropdown, {
3053
3091
  items: sessionOptions, value: session, disabled: loading,
3054
3092
  onChange: (next) => { setSession(next); writeAuditSession(next); resetAndReload() },
@@ -3361,11 +3399,11 @@ window.__ModuleLoader__.load({
3361
3399
  const tipNode = tip === null ? null : (() => {
3362
3400
  if (tip.type === 'session') {
3363
3401
  const summary = tip.summary || {}
3364
- const title = summary.title || summary.name || `会话 ${String(tip.id).slice(0, 8)}`
3402
+ const title = summary.title || summary.name || sessionScopeLabel(`session:${tip.id}`)
3365
3403
  return h('div', { className: 'audit-tip', style: { left: tip.x, top: tip.y }, onMouseEnter: cancelHideTip, onMouseLeave: hideTip, onClick: () => openSessionId(tip.id) },
3366
3404
  h('div', { className: 'audit-tip-head' }, h('span', null, '会话'), h('span', { className: 'audit-tip-title' }, title)),
3367
3405
  h('div', { className: 'audit-tip-meta' },
3368
- auditPill(String(tip.id).slice(0, 8) + '…', 'mute'),
3406
+ auditPill(`${sessionShortId(tip.id)}…`, 'mute'),
3369
3407
  summary.running === true ? auditPill('运行中', 'ok') : null,
3370
3408
  summary.archived === true ? auditPill('已归档', 'warn') : null,
3371
3409
  ),
@@ -4593,14 +4631,18 @@ window.__ModuleLoader__.load({
4593
4631
  const [grantBusy, setGrantBusy] = React.useState('')
4594
4632
  const [grantError, setGrantError] = React.useState('')
4595
4633
  const wrapRef = React.useRef(null)
4634
+ // 0.25.8:浮窗 portal 到 body 后不再长在 wrapRef 这棵树里,点它自己不能算「点外面」。
4635
+ const popRef = React.useRef(null)
4596
4636
 
4597
4637
  React.useEffect(() => {
4598
4638
  if (!open) return undefined
4599
4639
  if (typeof document === 'undefined' || typeof document.addEventListener !== 'function') return undefined
4640
+ const inside = (node, target) => Boolean(node && typeof node.contains === 'function' && node.contains(target))
4600
4641
  const onDown = (event) => {
4601
4642
  try {
4602
- const node = wrapRef.current
4603
- if (node && typeof node.contains === 'function' && !node.contains(event.target)) setOpen(false)
4643
+ const target = event ? event.target : null
4644
+ if (inside(wrapRef.current, target) || inside(popRef.current, target)) return
4645
+ setOpen(false)
4604
4646
  } catch { /* 关闭失败不影响页面 */ }
4605
4647
  }
4606
4648
  const onKey = (event) => { if (event && event.key === 'Escape') setOpen(false) }
@@ -4924,8 +4966,20 @@ window.__ModuleLoader__.load({
4924
4966
  || (grantsByScope.has(scope) && !pendingRevoke[scope])
4925
4967
  /** 已保存状态的勾选(排序只看它,草稿改动不立刻重排)。 */
4926
4968
  const savedChecked = (scope) => Boolean(savedEntries[scope]) || grantsByScope.has(scope)
4969
+ /**
4970
+ * 0.25.8:本会话自己的 session scope 在列表里叫「当前会话」。
4971
+ *
4972
+ * 面板是「这个会话」的权限面板,那一行就是用户正在用的会话 —— 显示
4973
+ * `session:<uuid>` 或「会话 1a2b3c4d」都只有实现细节,用户无从对号。
4974
+ * **只**改本会话那一条:目录里可能还有别的会话的 scope(它们带记录就会被发现),
4975
+ * 那些仍按标题 / 短 id 显示,不能跟着叫「当前会话」。
4976
+ */
4977
+ const currentSessionScope = (typeof sessionId === 'string' && sessionId !== '') ? `session:${sessionId}` : ''
4978
+ const displayName = (scope, label) => (currentSessionScope !== '' && scope === currentSessionScope)
4979
+ ? '当前会话'
4980
+ : String(label || scope)
4927
4981
  const matches = (label, scope) => !needle
4928
- || String(label || scope).toLowerCase().includes(needle) || String(scope).toLowerCase().includes(needle)
4982
+ || displayName(scope, label).toLowerCase().includes(needle) || String(scope).toLowerCase().includes(needle)
4929
4983
  const visibleScopes = catalog.filter((item) => matches(item.label || item.scope, item.scope))
4930
4984
  // 目录里已经看不到的作用域(记录删光 / 元数据没了)仍占一行,方便取消勾选撤销授权。
4931
4985
  const catalogScopes = new Set(catalog.map((item) => item.scope))
@@ -4933,8 +4987,8 @@ window.__ModuleLoader__.load({
4933
4987
  && !catalogScopes.has(grant.scope) && matches(grant.label || grant.scope, grant.scope))
4934
4988
  // 已勾选的排上面、未勾选的排下面,组内按名称字母排序;顺序以保存过的状态为准。
4935
4989
  const rows = [
4936
- ...visibleScopes.map((item) => ({ scope: item.scope, name: String(item.label || item.scope), item })),
4937
- ...orphanGrants.map((grant) => ({ scope: grant.scope, name: String(grant.label || grant.scope), grant })),
4990
+ ...visibleScopes.map((item) => ({ scope: item.scope, name: displayName(item.scope, item.label), item })),
4991
+ ...orphanGrants.map((grant) => ({ scope: grant.scope, name: displayName(grant.scope, grant.label), grant })),
4938
4992
  ]
4939
4993
  rows.sort((a, b) => (Number(savedChecked(b.scope)) - Number(savedChecked(a.scope)))
4940
4994
  || a.name.localeCompare(b.name, 'zh-Hans-CN', { sensitivity: 'base', numeric: true })
@@ -4992,20 +5046,10 @@ window.__ModuleLoader__.load({
4992
5046
  && grant.scope !== '' && !catalogScopes.has(grant.scope) && !pendingRevoke[grant.scope]).length
4993
5047
  const checkedCount = catalog.filter((item) => isChecked(item.scope)).length + orphanChecked
4994
5048
  const scopeCountText = `${accessibleCount} 个作用域`
4995
- return h('span', { className: 'mem-scope-wrap', ref: wrapRef },
4996
- h('button', {
4997
- type: 'button',
4998
- className: `mem-scope-btn is-${buttonLevel}`,
4999
- title: `${sourceText}记忆权限:${scopeCountText} · ${buttonLevelLabel}`,
5000
- 'aria-label': `${sourceText}记忆权限,${scopeCountText},${buttonLevelLabel}`,
5001
- 'aria-expanded': open,
5002
- onMouseDown: (event) => { try { event.preventDefault() } catch { /* keepFocus */ } },
5003
- onClick: toggle,
5004
- },
5005
- h(NavLineIcon, { size: 14 }),
5006
- data === null ? null : h('span', null, String(accessibleCount)),
5007
- ),
5008
- open ? h('div', { className: 'mem-scope-pop', style: popStyle, role: 'dialog', 'aria-label': '记忆权限' },
5049
+ const portalTarget = typeof document !== 'undefined' && document !== null && document.body ? document.body : null
5050
+ // 0.25.8:浮窗 portal 到 body(原因见文件头 createPortal 的注释)。拿不到 react-dom
5051
+ // 或没有 document.body 时退回原地渲染 —— 层级受限,但功能完全一致。
5052
+ const popover = open ? h('div', { className: 'mem-scope-pop', ref: popRef, style: popStyle, role: 'dialog', 'aria-label': '记忆权限' },
5009
5053
  h('div', { className: 'mem-scope-head' },
5010
5054
  h('h4', null, '记忆权限'),
5011
5055
  h('span', { className: 'spacer' }),
@@ -5082,7 +5126,7 @@ window.__ModuleLoader__.load({
5082
5126
  className: 'mem-scope-label',
5083
5127
  title: item ? row.scope : `${row.scope}(目录中已不可见)`,
5084
5128
  onClick: () => toggleScope(row.scope),
5085
- }, item ? (item.label || item.scope) : (row.grant.label || row.grant.scope)),
5129
+ }, displayName(row.scope, item ? item.label : row.grant.label)),
5086
5130
  grant ? grantTag(grant, row.scope) : null,
5087
5131
  h('span', { className: 'cnt' }, item ? `${item.records ?? 0}` : '目录中已不可见'),
5088
5132
  ),
@@ -5143,7 +5187,23 @@ window.__ModuleLoader__.load({
5143
5187
  onClick: saveDraft,
5144
5188
  }, busy ? '保存中…' : '保存'),
5145
5189
  ),
5146
- ) : null,
5190
+ ) : null
5191
+ return h('span', { className: 'mem-scope-wrap', ref: wrapRef },
5192
+ h('button', {
5193
+ type: 'button',
5194
+ className: `mem-scope-btn is-${buttonLevel}`,
5195
+ title: `${sourceText}记忆权限:${scopeCountText} · ${buttonLevelLabel}`,
5196
+ 'aria-label': `${sourceText}记忆权限,${scopeCountText},${buttonLevelLabel}`,
5197
+ 'aria-expanded': open,
5198
+ onMouseDown: (event) => { try { event.preventDefault() } catch { /* keepFocus */ } },
5199
+ onClick: toggle,
5200
+ },
5201
+ h(NavLineIcon, { size: 14 }),
5202
+ data === null ? null : h('span', null, String(accessibleCount)),
5203
+ ),
5204
+ popover === null
5205
+ ? null
5206
+ : (createPortal !== null && portalTarget !== null ? createPortal(popover, portalTarget) : popover),
5147
5207
  )
5148
5208
  }
5149
5209
  /**
@@ -5724,6 +5784,10 @@ window.__ModuleLoader__.load({
5724
5784
  requestRecordFocus: requestRecordFocus,
5725
5785
  takeRecordFocus: takeRecordFocus,
5726
5786
  buildMemoryTree: buildMemoryTree,
5787
+ // 会话作用域展示名:取会话 id 前 16 位(前 8 位恒为 `session-`)
5788
+ sessionShortId: sessionShortId,
5789
+ sessionScopeLabel: sessionScopeLabel,
5790
+ scopeLabel: scopeLabel,
5727
5791
  KIND_META: KIND_META,
5728
5792
  CSS: CSS,
5729
5793
  shouldPollInstall: shouldPollInstall,
package/lib/panel.js CHANGED
@@ -27,7 +27,7 @@
27
27
  // scope 规范化与 provider 共用同一份实现。路径按**源码树位置**写:构建脚本的改写表
28
28
  // 会把它落成产物里的 `../provider/scope.js`(`lib/panel.js` → `lib/provider/scope.js`),
29
29
  // 在源码树里同一路径直接命中 source/memory-local/src —— 测试与真实加载都能解析。
30
- import { normalizeScopeInput, resolveCurrentScopes } from './provider/scope.js'
30
+ import { normalizeScopeInput, resolveCurrentScopes, sessionScopeLabel, sessionShortId } from './provider/scope.js'
31
31
 
32
32
 
33
33
  function writeJson(res, body, status = 200) {
@@ -144,13 +144,16 @@ async function readJsonBody(req) {
144
144
  * scope 键 → **不需要查宿主服务**的展示标签。
145
145
  * global → 「全局」
146
146
  * project:<cwd> → cwd
147
- * session:<id> → 「会话 <id 前 8 位>」
147
+ * session:<id> → 「会话 <id 前 16 位>」(如 `会话 session-1a2b3c4d`)
148
148
  * 其他 → 原名(自定义 scope)
149
+ *
150
+ * 16 位而不是 8 位:会话 id 以 `session-` 开头(正好 8 个字符),取 8 位会让所有会话
151
+ * 作用域都显示成「会话 session-」。规则集中在 provider 的 sessionScopeLabel。
149
152
  */
150
153
  function fallbackScopeLabel(scope) {
151
154
  if (scope === 'global') return '全局'
152
155
  if (scope.startsWith('project:')) return scope.slice('project:'.length)
153
- if (scope.startsWith('session:')) return `会话 ${scope.slice('session:'.length, 'session:'.length + 8)}`
156
+ if (scope.startsWith('session:')) return sessionScopeLabel(scope)
154
157
  return scope
155
158
  }
156
159
 
@@ -162,7 +165,7 @@ function fallbackScopeLabel(scope) {
162
165
  function scopeLabel(ctx, scope) {
163
166
  if (!scope.startsWith('session:')) return fallbackScopeLabel(scope)
164
167
  const id = scope.slice('session:'.length)
165
- const short = id.slice(0, 8)
168
+ const short = sessionShortId(id)
166
169
  try {
167
170
  const session = ctx?.get?.('sessions')?.get?.(id)
168
171
  if (session !== undefined) {
@@ -170,7 +173,7 @@ function scopeLabel(ctx, scope) {
170
173
  if (typeof title === 'string' && title.length > 0) return `${title}(${short})`
171
174
  }
172
175
  } catch { /* 标题是尽力而为 */ }
173
- return `会话 ${short}`
176
+ return sessionScopeLabel(scope)
174
177
  }
175
178
 
176
179
  /** 会话 scope 查标题的上限:标题要读会话事件日志,scope 多了它就成了 /status 的大头。 */
@@ -835,7 +838,7 @@ async function handle(ctx, routePath, req, res) {
835
838
  ? memory.scopeStats()
836
839
  : store.allScopes().map((s) => ({ scope: s.scope, records: s.records.size, pendingEmbeds: s.embedPending.size }))
837
840
  // 会话标题是尽力而为的增强,而且要读会话事件日志:只给最近活跃的前 N 个查,
838
- // 其余直接用「会话 <id 前 8 位>」。列表本身**始终**完整(不受这个上限影响)。
841
+ // 其余直接用「会话 <id 前 16 位>」。列表本身**始终**完整(不受这个上限影响)。
839
842
  const scopes = stats.map((s, index) => ({
840
843
  ...s,
841
844
  label: s.name ?? (index < TITLE_LOOKUP_LIMIT ? scopeLabel(ctx, s.scope) : fallbackScopeLabel(s.scope)),
@@ -183,6 +183,25 @@ export function scopeTier(scope ) {
183
183
  }
184
184
  }
185
185
 
186
+ /** 会话 id 的展示长度。 */
187
+ export const SESSION_SHORT_ID_CHARS = 16
188
+
189
+ /**
190
+ * 会话 id → 展示用的短 id(前 16 位,如 `session-1a2b3c4d`)。
191
+ *
192
+ * 为什么是 16 而不是 8:DSH 的会话 id 以 `session-` 开头 —— 那正好是 8 个字符。
193
+ * 取前 8 位会让**所有**会话作用域显示成同一个「会话 session-」,等于没给 id。
194
+ * 16 位 = `session-` + 8 位 uuid,既短又能区分。
195
+ */
196
+ export function sessionShortId(sessionId ) {
197
+ return String(sessionId ?? '').slice(0, SESSION_SHORT_ID_CHARS)
198
+ }
199
+
200
+ /** 会话 scope 键(`session:<id>`)→ 「会话 + 前 16 位 id」的展示名。 */
201
+ export function sessionScopeLabel(scope ) {
202
+ return `会话 ${sessionShortId(scope.slice('session:'.length))}`
203
+ }
204
+
186
205
  /** 写路径遇到只读 scope 时的错误码('all' 不能写)。 */
187
206
  export const SCOPE_NOT_WRITABLE = 'SCOPE_NOT_WRITABLE'
188
207
 
@@ -21,7 +21,7 @@ import {
21
21
 
22
22
  } from './index.js'
23
23
  import { renderGetResult, renderListResult, renderScopesResult, renderSearchResult } from './render.js'
24
- import { resolveCurrentScopes, scopeKind, } from '../provider/scope.js'
24
+ import { resolveCurrentScopes, scopeKind, sessionScopeLabel, sessionShortId, } from '../provider/scope.js'
25
25
 
26
26
  export const name = 'dsh-tool-memory'
27
27
  export const inject = ['tools', 'memory']
@@ -91,14 +91,14 @@ export function apply(ctx , config = {}) {
91
91
  /**
92
92
  * scope 键 → 展示标签。会话标题只有宿主服务能给:`ctx.get('sessionTitle')` 的 `get(session)`
93
93
  * 返回 `{ title }`(见 @deepseek-ai/dsh-session-title)。整套访问都在 try/catch 里 ——
94
- * 旧宿主没有这个服务、会话已经不在内存里,都不能影响工具结果,回退成"会话 <id 前 8 位>"。
94
+ * 旧宿主没有这个服务、会话已经不在内存里,都不能影响工具结果,回退成"会话 <id 前 16 位>"。
95
95
  */
96
96
  const labelFor = (scope , agent ) => {
97
97
  if (scope === 'global') return '全局'
98
98
  if (scope.startsWith('project:')) return scope.slice('project:'.length)
99
99
  if (scope.startsWith('session:')) {
100
100
  const id = scope.slice('session:'.length)
101
- const short = id.slice(0, 8)
101
+ const short = sessionShortId(id)
102
102
  try {
103
103
  const session = (agent )?.session
104
104
  if (session?.id === id) {
@@ -108,7 +108,7 @@ export function apply(ctx , config = {}) {
108
108
  if (typeof title === 'string' && title.length > 0) return `${title}(${short})`
109
109
  }
110
110
  } catch { /* 拿不到标题就用短 id */ }
111
- return `会话 ${short}`
111
+ return sessionScopeLabel(scope)
112
112
  }
113
113
  return scope
114
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.25.7",
3
+ "version": "0.25.9",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",