@restregular/dsh-memory 0.25.9 → 0.25.11

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.
@@ -72,12 +72,18 @@ const HINT_FOOTER = '这些条目的正文尚未加载;遇到相关任务时
72
72
 
73
73
 
74
74
 
75
- /** scope 的中文标签:global/项目/会话/自定义。 */
75
+ /**
76
+ * scope 的紧凑分类标签:global/项目/会话/自定义。
77
+ *
78
+ * 前三种是**分类词**(摘要按预算只给类型,不给完整名字);自定义作用域没有分类可归,
79
+ * 所以给 `custom:<名字>` —— 0.25.11 起补上前缀,否则摘要里它是个裸名字,和全局/项目/
80
+ * 会话这些分类词混在一起看不出是什么。
81
+ */
76
82
  export function digestScopeLabel(scope ) {
77
83
  if (scope === 'global') return '全局'
78
84
  if (scope === 'project' || scope.startsWith('project:')) return '项目'
79
85
  if (scope === 'session' || scope.startsWith('session:')) return '会话'
80
- return scope
86
+ return `custom:${scope}`
81
87
  }
82
88
 
83
89
  /**
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, sessionScopeLabel, sessionShortId } from './provider/scope.js'
30
+ import { normalizeScopeInput, resolveCurrentScopes, scopeDisplayName, sessionShortId } from './provider/scope.js'
31
31
 
32
32
 
33
33
  function writeJson(res, body, status = 200) {
@@ -141,39 +141,39 @@ async function readJsonBody(req) {
141
141
  }
142
142
 
143
143
  /**
144
- * scope 键 → **不需要查宿主服务**的展示标签。
145
- * global → 「全局」
146
- * project:<cwd> → cwd
147
- * session:<id> → 「会话 <id 前 16 位>」(如 `会话 session-1a2b3c4d`)
148
- * 其他 → 原名(自定义 scope)
144
+ * scope 键 → **不需要查宿主服务**的展示名(带类型前缀)。
145
+ * global → `global:全局`
146
+ * project:<cwd> → `project:<cwd>`
147
+ * session:<id> → `session:session-1a2b3c4d`(会话 id 前 16 位)
148
+ * 自定义 → `custom:<名字>`(自定义 scope 的键本身没有前缀,靠类型补)
149
149
  *
150
- * 16 位而不是 8 位:会话 id 以 `session-` 开头(正好 8 个字符),取 8 位会让所有会话
151
- * 作用域都显示成「会话 session-」。规则集中在 provider 的 sessionScopeLabel。
150
+ * 细节都有两处坑:①会话 id 以 `session-` 开头(正好 8 个字符),取 8 位会让所有会话
151
+ * 作用域都显示成同一个名字,所以取 16 位;②自定义作用域与 global 的键天然不带前缀,
152
+ * 必须按类型补 —— 规则集中在 provider 的 scopeDisplayName。
152
153
  */
153
154
  function fallbackScopeLabel(scope) {
154
- if (scope === 'global') return '全局'
155
- if (scope.startsWith('project:')) return scope.slice('project:'.length)
156
- if (scope.startsWith('session:')) return sessionScopeLabel(scope)
157
- return scope
155
+ return scopeDisplayName(scope)
158
156
  }
159
157
 
160
158
  /**
161
- * scope 键 → 展示标签。在 fallback 之上多一步:会话 scope 尽力取会话标题
159
+ * scope 键 → 展示名。在 fallback 之上多一步:会话 scope 尽力取会话标题
162
160
  * (宿主 `sessionTitle` 服务的 `get(session)` → `{ title }`,见 @deepseek-ai/dsh-session-title)。
163
161
  * 所有宿主服务访问都在 try/catch 里:面板绝不能因为拿不到标题而失败。
162
+ *
163
+ * 带标题时形如 `session:修层级(1a2b3c4d)` —— 类型前缀仍在最前面,名字部分换成标题。
164
164
  */
165
165
  function scopeLabel(ctx, scope) {
166
- if (!scope.startsWith('session:')) return fallbackScopeLabel(scope)
166
+ if (!scope.startsWith('session:')) return scopeDisplayName(scope)
167
167
  const id = scope.slice('session:'.length)
168
168
  const short = sessionShortId(id)
169
169
  try {
170
170
  const session = ctx?.get?.('sessions')?.get?.(id)
171
171
  if (session !== undefined) {
172
172
  const title = ctx.get('sessionTitle')?.get?.(session)?.title
173
- if (typeof title === 'string' && title.length > 0) return `${title}(${short})`
173
+ if (typeof title === 'string' && title.length > 0) return scopeDisplayName(scope, `${title}(${short})`)
174
174
  }
175
175
  } catch { /* 标题是尽力而为 */ }
176
- return sessionScopeLabel(scope)
176
+ return scopeDisplayName(scope)
177
177
  }
178
178
 
179
179
  /** 会话 scope 查标题的上限:标题要读会话事件日志,scope 多了它就成了 /status 的大头。 */
@@ -569,7 +569,10 @@ function visibilityPayload(ctx, memory, sessionId) {
569
569
  const rule = rules.get(item.scope)
570
570
  return {
571
571
  ...item,
572
- label: item.name ?? scopeLabel(ctx, item.scope),
572
+ // 别名也带类型前缀:项目别名 → `project:<别名>`,自定义 → `custom:<别名>`。
573
+ label: typeof item.name === 'string' && item.name !== ''
574
+ ? scopeDisplayName(item.scope, item.name)
575
+ : scopeLabel(ctx, item.scope),
573
576
  read: rule === undefined ? true : rule.read !== false,
574
577
  write: rule === undefined ? true : rule.write !== false,
575
578
  // bound = 显式绑定或默认范围自带;defaultBound 告诉客户端这一项不能取消。
@@ -841,7 +844,10 @@ async function handle(ctx, routePath, req, res) {
841
844
  // 其余直接用「会话 <id 前 16 位>」。列表本身**始终**完整(不受这个上限影响)。
842
845
  const scopes = stats.map((s, index) => ({
843
846
  ...s,
844
- label: s.name ?? (index < TITLE_LOOKUP_LIMIT ? scopeLabel(ctx, s.scope) : fallbackScopeLabel(s.scope)),
847
+ // 别名(项目 / 自定义作用域)也要带类型前缀;没有别名时退回按类型算的展示名。
848
+ label: typeof s.name === 'string' && s.name !== ''
849
+ ? scopeDisplayName(s.scope, s.name)
850
+ : (index < TITLE_LOOKUP_LIMIT ? scopeLabel(ctx, s.scope) : fallbackScopeLabel(s.scope)),
845
851
  }))
846
852
  let embedServer = null
847
853
  // older providers have no lifecycle API — the panel simply omits the card
@@ -197,9 +197,41 @@ export function sessionShortId(sessionId ) {
197
197
  return String(sessionId ?? '').slice(0, SESSION_SHORT_ID_CHARS)
198
198
  }
199
199
 
200
- /** 会话 scope 键(`session:<id>`)→ 「会话 + 前 16 位 id」的展示名。 */
201
- export function sessionScopeLabel(scope ) {
202
- return `会话 ${sessionShortId(scope.slice('session:'.length))}`
200
+ /**
201
+ * scope 键 → 展示用的**类型前缀**。
202
+ *
203
+ * global → `global:`
204
+ * project:* → `project:`
205
+ * session:* → `session:`
206
+ * 其余(自定义) → `custom:` —— 自定义 scope 的键**本身没有前缀**(就是一个名字),
207
+ * 所以这个前缀只能在这里补上;别拿 `scopeKind` 之外的规则去猜。
208
+ */
209
+ export function scopeTypePrefix(scope ) {
210
+ if (scope === 'global') return 'global:'
211
+ if (scope.startsWith('project:')) return 'project:'
212
+ if (scope.startsWith('session:')) return 'session:'
213
+ return 'custom:'
214
+ }
215
+
216
+ /** 没有别名 / 标题时,各类型自己的名字(前缀之后那一段)。 */
217
+ export function scopeDefaultName(scope ) {
218
+ if (scope === 'global') return '全局'
219
+ if (scope.startsWith('project:')) return scope.slice('project:'.length)
220
+ if (scope.startsWith('session:')) return sessionShortId(scope.slice('session:'.length))
221
+ return String(scope)
222
+ }
223
+
224
+ /**
225
+ * scope 键 → 展示名,形如 `global:全局` / `project:<cwd>` / `session:session-1a2b3c4d` /
226
+ * `custom:<名字>`。`humanName` 是服务端能拿到的人类可读名(会话标题、项目别名、自定义
227
+ * 作用域的用途名),省略或空串时用类型默认名。
228
+ *
229
+ * 前缀必须由**类型**决定而不是由名字猜:自定义作用域的键天生没有前缀,老代码直接吐
230
+ * 裸名字,在列表里会和 global / project 混在一起分不清种类。
231
+ */
232
+ export function scopeDisplayName(scope , humanName ) {
233
+ const name = typeof humanName === 'string' && humanName.length > 0 ? humanName : scopeDefaultName(scope)
234
+ return `${scopeTypePrefix(scope)}${name}`
203
235
  }
204
236
 
205
237
  /** 写路径遇到只读 scope 时的错误码('all' 不能写)。 */
@@ -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, sessionScopeLabel, sessionShortId, } from '../provider/scope.js'
24
+ import { resolveCurrentScopes, scopeDisplayName, sessionShortId, } from '../provider/scope.js'
25
25
 
26
26
  export const name = 'dsh-tool-memory'
27
27
  export const inject = ['tools', 'memory']
@@ -89,32 +89,30 @@ export function apply(ctx , config = {}) {
89
89
  const tools = memoryTools(opts)
90
90
 
91
91
  /**
92
- * scope 键 → 展示标签。会话标题只有宿主服务能给:`ctx.get('sessionTitle')` 的 `get(session)`
93
- * 返回 `{ title }`(见 @deepseek-ai/dsh-session-title)。整套访问都在 try/catch 里 ——
94
- * 旧宿主没有这个服务、会话已经不在内存里,都不能影响工具结果,回退成"会话 <id 前 16 位>"。
92
+ * scope 键 → 展示名(带类型前缀:`global:全局` / `project:<cwd>` / `session:xxx` /
93
+ * `custom:<名字>`)。会话标题只有宿主服务能给:`ctx.get('sessionTitle')` 的
94
+ * `get(session)` 返回 `{ title }`(见 @deepseek-ai/dsh-session-title);整套访问都在
95
+ * try/catch 里 —— 旧宿主没有这个服务、会话已经不在内存里,都不能影响工具结果,
96
+ * 回退成「会话 id 前 16 位」。
95
97
  */
96
98
  const labelFor = (scope , agent ) => {
97
- if (scope === 'global') return '全局'
98
- if (scope.startsWith('project:')) return scope.slice('project:'.length)
99
- if (scope.startsWith('session:')) {
100
- const id = scope.slice('session:'.length)
101
- const short = sessionShortId(id)
102
- try {
103
- const session = (agent )?.session
104
- if (session?.id === id) {
105
- const titles = ctx.get?.('sessionTitle')
106
- const snapshot = titles?.get?.(session)
107
- const title = snapshot?.title
108
- if (typeof title === 'string' && title.length > 0) return `${title}(${short})`
109
- }
110
- } catch { /* 拿不到标题就用短 id */ }
111
- return sessionScopeLabel(scope)
112
- }
113
- return scope
99
+ if (!scope.startsWith('session:')) return scopeDisplayName(scope)
100
+ const id = scope.slice('session:'.length)
101
+ const short = sessionShortId(id)
102
+ try {
103
+ const session = (agent )?.session
104
+ if (session?.id === id) {
105
+ const titles = ctx.get?.('sessionTitle')
106
+ const snapshot = titles?.get?.(session)
107
+ const title = snapshot?.title
108
+ if (typeof title === 'string' && title.length > 0) return scopeDisplayName(scope, `${title}(${short})`)
109
+ }
110
+ } catch { /* 拿不到标题就用短 id */ }
111
+ return scopeDisplayName(scope)
114
112
  }
115
113
 
116
- const renderScope = (scope , agent ) =>
117
- scopeKind(scope) === 'custom' ? `自定义「${scope}」` : labelFor(scope, agent)
114
+ // 自定义作用域也一样:`custom:<名字>`(它的键本来没有前缀,由类型补上)。
115
+ const renderScope = (scope , agent ) => labelFor(scope, agent)
118
116
 
119
117
  /** 作用域清单文案(名字 + 条数);最多 20 个,其余写"…另有 N 个"。 */
120
118
  const scopeSummary = (value , agent ) => {
@@ -10,6 +10,7 @@
10
10
  * 0.23.0:绝对限制与「不可读」开关也会被说明(不再假装"不存在"),并提示怎么调整。
11
11
  */
12
12
 
13
+ import { scopeDisplayName } from '../provider/scope.js'
13
14
 
14
15
  /** 把 scope 键渲染成展示文案(宿主能查到会话标题时用它,否则用短 id)。 */
15
16
 
@@ -140,7 +141,9 @@ export function renderScopesResult(value , label )
140
141
  }
141
142
  if (value.scopes.length === 0) return '当前没有可列出的作用域。'
142
143
  const body = value.scopes.map((item) => {
143
- const name = item.name !== undefined && item.name !== '' ? item.name : label(item.scope)
144
+ // 别名(项目 / 自定义作用域)也带类型前缀:自定义作用域的键本身没有前缀,
145
+ // 直接吐裸名字会和 global / project 混在一起分不清种类。
146
+ const name = item.name !== undefined && item.name !== '' ? scopeDisplayName(item.scope, item.name) : label(item.scope)
144
147
  const description = item.description !== undefined && item.description.trim() !== ''
145
148
  ? item.description.trim()
146
149
  : '(未填写用途)'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.25.9",
3
+ "version": "0.25.11",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",