@restregular/dsh-memory 0.28.0 → 0.30.0

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.
@@ -135,8 +135,10 @@ import { canonicalWorkspacePath, defaultScopeDescription, normalizeScopeInput, r
135
135
 
136
136
 
137
137
 
138
-
138
+
139
139
 
140
+                              
141
+
140
142
                 
141
143
 
142
144
 
@@ -187,10 +189,19 @@ import { canonicalWorkspacePath, defaultScopeDescription, normalizeScopeInput, r
187
189
                  
188
190
 
189
191
                          
190
-
192
+
191
193
                                
192
194
 
193
195
 
196
+                                 
197
+
198
+
199
+
200
+                               
201
+          
202
+
203
+
204
+
194
205
                    
195
206
                                
196
207
 
@@ -290,6 +301,20 @@ function agentOf(exec ) {
290
301
  return (exec )?.agent
291
302
  }
292
303
 
304
+ /**
305
+ * agent → 会话 id(只给需要"这是谁改的"的元数据写入用,如作用域用途的 createdBy)。
306
+ * 与 provider 的 rawSessionIdOf 同口径:header.id 优先,其次 session.id。
307
+ */
308
+ function sessionIdOf(agent ) {
309
+ try {
310
+ const session = (agent )?.session
311
+ const id = session?.header?.id ?? session?.id
312
+ return typeof id === 'string' && id !== '' ? id : undefined
313
+ } catch {
314
+ return undefined
315
+ }
316
+ }
317
+
293
318
  /**
294
319
  * 当前项目 key。优先级:**服务端解析的会话 cwd** → 显式配置 → process.cwd()。
295
320
  *
@@ -1355,7 +1380,7 @@ export function memoryForgetTool(opts )
1355
1380
 
1356
1381
 
1357
1382
                                 
1358
-
1383
+
1359
1384
 
1360
1385
                               
1361
1386
                       
@@ -1485,7 +1510,7 @@ export function memoryListTool(opts )
1485
1510
  }
1486
1511
 
1487
1512
 
1488
-
1513
+
1489
1514
                     
1490
1515
 
1491
1516
 
@@ -1499,6 +1524,15 @@ export function memoryListTool(opts )
1499
1524
 
1500
1525
                  
1501
1526
 
1527
+                          
1528
+
1529
+
1530
+                              
1531
+                    
1532
+
1533
+
1534
+                     
1535
+
1502
1536
                       
1503
1537
 
1504
1538
 
@@ -1511,7 +1545,17 @@ export function memoryListTool(opts )
1511
1545
 
1512
1546
 
1513
1547
 
1514
-
1548
+ /**
1549
+ * action='edit' 的结果(0.29.0):只回「改成了什么」,不回记忆内容。
1550
+ * 字段缺省 = 这次没动它;空串 = 已清空(用途)或已移除(别名)。
1551
+ */
1552
+
1553
+
1554
+
1555
+
1556
+
1557
+
1558
+
1515
1559
 
1516
1560
  /**
1517
1561
  * 作用域目录 / 权限申请工具(0.24.0)。
@@ -1525,9 +1569,9 @@ export function memoryListTool(opts )
1525
1569
  export function memoryScopesTool(opts ) {
1526
1570
  return {
1527
1571
  name: 'memory_scopes',
1528
- description: 'List memory scopes with their purpose and access status (metadata only, no content), or request session access to out-of-scope scopes. action="request" defaults to read-only and requires a reason; absolute restriction never grants access.',
1572
+ description: 'List memory scopes with their purpose and access status (metadata only, no content), request session access to out-of-scope scopes, or edit a scope\'s purpose and alias. action="edit" updates the scope description (empty = clear, falls back to the type default) and/or alias (empty = remove); the scope must be writable in this session. action="request" defaults to read-only and requires a reason; absolute restriction never grants access.',
1529
1573
  parameters: {
1530
- action: { type: 'string', enum: ['list', 'request'], description: 'list = 目录;request = 申请范围外作用域的会话权限(默认只读)' },
1574
+ action: { type: 'string', enum: ['list', 'request', 'edit'], description: 'list = 目录;request = 申请范围外作用域的会话权限(默认只读);edit = 编辑某个作用域的描述 / 别名(需要该作用域可写)' },
1531
1575
  includeOutOfScope: { type: 'boolean', description: 'list:默认 true;false 时只列当前可见域内的作用域。' },
1532
1576
  limit: { type: 'number', description: 'list:1~200,默认 50' },
1533
1577
  scopes: {
@@ -1541,6 +1585,9 @@ export function memoryScopesTool(opts )
1541
1585
  description: 'request:申请哪些权限,省略 = 只读;写权限必须显式加 "write"',
1542
1586
  },
1543
1587
  reason: { type: 'string', description: 'request:一句话申请理由,展示在审批卡上' },
1588
+ scope: { type: 'string', description: 'edit:要编辑的作用域键(目录里显示的那个,如 handbook / project:<路径>)。当前会话范围外时先用 action="request" 申请写权限' },
1589
+ scopeDescription: { type: 'string', description: 'edit:新的用途(一句话,最多 500 字)。空串 = 清空并回退到按类型的默认描述;与本参数一起省略 scopeName 则报错。' },
1590
+ scopeName: { type: 'string', description: 'edit:新的别名(只影响显示与引用,不改作用域键;项目 / 自定义作用域支持)。空串 = 移除别名;省略 = 这次不改别名。' },
1544
1591
  description: { type: 'string', description: DESCRIPTION_PARAM_DESCRIPTION },
1545
1592
  },
1546
1593
  async execute(args , exec ) {
@@ -1548,6 +1595,66 @@ export function memoryScopesTool(opts )
1548
1595
  const agent = agentOf(exec)
1549
1596
  requireDescription(service, agent, args.description)
1550
1597
 
1598
+ // ---- action='edit':编辑作用域描述 / 别名(0.29.0)----
1599
+ // 只改**目录元数据**,不碰任何记忆记录;需要该作用域可写(范围外先用
1600
+ // action='request' 拿写权限,不走隐式审批 —— 审批卡里没有"一条记忆"可展示)。
1601
+ if (args.action === 'edit') {
1602
+ const rawScope = typeof args.scope === 'string' ? args.scope.trim() : ''
1603
+ if (rawScope === '') throw new MemoryToolError('SCOPE_REQUIRED', 'action="edit" 需要 scope(要编辑的作用域键,目录里显示的那个)')
1604
+ const wantDescription = typeof args.scopeDescription === 'string'
1605
+ const wantName = typeof args.scopeName === 'string'
1606
+ if (!wantDescription && !wantName) {
1607
+ throw new MemoryToolError('EDIT_NOTHING_TO_UPDATE', 'action="edit" 至少要给 scopeDescription 或 scopeName 之一(想清空用途传空串,想移除别名传空串)')
1608
+ }
1609
+ if (typeof service.describeScope !== 'function' && wantDescription) {
1610
+ throw new MemoryToolError('SCOPES_UNAVAILABLE', '当前 provider 不支持编辑作用域用途(请升级 @restregular/dsh-memory)')
1611
+ }
1612
+ if (typeof service.renameScope !== 'function' && wantName) {
1613
+ throw new MemoryToolError('SCOPES_UNAVAILABLE', '当前 provider 不支持编辑作用域别名(请升级 @restregular/dsh-memory)')
1614
+ }
1615
+ const resolved = resolveScope(opts, service, exec, rawScope, 'write')
1616
+ if (resolved.all === true) {
1617
+ throw new MemoryToolError('SCOPE_NOT_WRITABLE', "scope 'all' cannot be edited; name one scope")
1618
+ }
1619
+ const scope = resolved.scope ?? currentSessionScope(service, exec)
1620
+ if (scope === undefined) {
1621
+ throw new MemoryToolError('SCOPE_INVALID', `scope "${rawScope}" could not be resolved; use the concrete scope key shown by action="list"`)
1622
+ }
1623
+ // 可写护栏:与写入记忆同一把锁(write 开关 / absolute / 范围外)。
1624
+ const policy = visibilityPolicy(service, agent)
1625
+ const decide = decisionMaker(service, agent)
1626
+ const level = policy?.level ?? 'none'
1627
+ if (level !== 'none' && !scopeWritableBy(decide, service, agent, policy, scope)) {
1628
+ const decision = decide('write', scope)
1629
+ if (decision !== undefined) {
1630
+ if (!decision.requestable) throw writeDecisionError(decision, scope, 'write')
1631
+ throw new MemoryToolError(
1632
+ 'SCOPE_NOT_WRITABLE',
1633
+ `作用域 ${scope} 不在本会话的可写范围内;编辑作用域信息需要写权限,先用 memory_scopes({ action: "request", scopes: ["${scope}"], permissions: ["write"] }) 申请,批准后重试。`,
1634
+ )
1635
+ }
1636
+ if (policy?.level === 'normal') {
1637
+ // 老 provider 没有统一判定:普通限制下范围外就是"可申请",别报成绝对限制。
1638
+ throw new MemoryToolError(
1639
+ 'SCOPE_NOT_WRITABLE',
1640
+ `作用域 ${scope} 不在本会话的可写范围内;编辑作用域信息需要写权限,先用 memory_scopes({ action: "request", scopes: ["${scope}"], permissions: ["write"] }) 申请,批准后重试。`,
1641
+ )
1642
+ }
1643
+ throw scopeWriteBlockedError(policy, scope, 'write')
1644
+ }
1645
+ const description = wantDescription ? String(args.scopeDescription) : undefined
1646
+ const name = wantName ? String(args.scopeName) : undefined
1647
+ const by = sessionIdOf(agent) ?? 'agent'
1648
+ try {
1649
+ const edited = { scope }
1650
+ if (description !== undefined) edited.description = service.describeScope (scope, description, by).description
1651
+ if (name !== undefined) edited.name = service.renameScope (scope, name).name ?? ''
1652
+ return edited
1653
+ } catch (error) {
1654
+ throw toolError(error)
1655
+ }
1656
+ }
1657
+
1551
1658
  if (args.action === 'request') {
1552
1659
  if (typeof service.requestScopeGrants !== 'function') {
1553
1660
  throw new MemoryToolError('SCOPES_UNAVAILABLE', '当前 provider 不支持作用域权限申请(请升级 @restregular/dsh-memory)')
@@ -149,7 +149,8 @@ export function renderListResult(value , label ) {
149
149
 
150
150
  /**
151
151
  * memory_scopes 的渲染:list 只讲“有什么、干什么、能不能碰”;request 讲每个
152
- * scope + 权限的申请结局。两者共用同一个工具入口,但文案完全分开。
152
+ * scope + 权限的申请结局;edit(0.29.0)讲这次改了描述 / 别名的什么。
153
+ * 三者共用同一个工具入口,但文案完全分开。
153
154
  */
154
155
  export function renderScopesResult(value , label ) {
155
156
  if ('results' in value) {
@@ -181,6 +182,20 @@ export function renderScopesResult(value , label )
181
182
  ).join('\n')
182
183
  return `作用域权限申请结果:\n${body}`
183
184
  }
185
+ // edit(0.29.0):只回「改成了什么」。没动过的字段不出现,空串表示清空 / 移除。
186
+ if ('scope' in value) {
187
+ const name = value.name !== undefined && value.name !== '' ? scopeDisplayName(value.scope, value.name) : label(value.scope)
188
+ const lines = [`作用域已更新:${name}(${value.scope})`]
189
+ if (value.description !== undefined) {
190
+ lines.push(value.description === ''
191
+ ? '- 用途:已清空(回退到按类型的默认描述)'
192
+ : `- 用途:${value.description}`)
193
+ }
194
+ if (value.name !== undefined) {
195
+ lines.push(value.name === '' ? '- 别名:已移除(显示名回退到作用域键)' : `- 别名:${value.name}`)
196
+ }
197
+ return lines.join('\n')
198
+ }
184
199
  if (value.scopes.length === 0) return '当前没有可列出的作用域。'
185
200
  const body = value.scopes.map((item) => {
186
201
  // 别名(项目 / 自定义作用域)也带类型前缀:自定义作用域的键本身没有前缀,
@@ -191,7 +206,10 @@ export function renderScopesResult(value , label )
191
206
  : '(未填写用途)'
192
207
  const meta = []
193
208
  if (item.records !== undefined) meta.push(`${item.records} 条`)
194
- if (item.inScope) {
209
+ if (item.archived === true) {
210
+ // 0.30.0:归档不是权限拒绝,而是会话生命周期 —— 数据仍在,恢复会话即复原。
211
+ meta.push('已归档 · 恢复会话后自动恢复读写')
212
+ } else if (item.inScope) {
195
213
  meta.push(item.accessStatus === 'default'
196
214
  ? '范围内'
197
215
  : item.accessStatus === 'read-only'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.28.0",
3
+ "version": "0.30.0",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
@@ -47,11 +47,6 @@
47
47
  "optional": true
48
48
  }
49
49
  },
50
- "repository": {
51
- "type": "git",
52
- "url": "git+https://github.com/RestRegular/dsh-memory",
53
- "directory": "packages/dsh-memory"
54
- },
55
50
  "publishConfig": {
56
51
  "access": "public"
57
52
  },