@restregular/dsh-memory 0.22.3 → 0.23.1

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.
@@ -59,13 +59,19 @@ import { canonicalWorkspacePath, normalizeScopeInput, resolveScopeRef } from '..
59
59
 
60
60
 
61
61
  /**
62
- * 被可见域挡住、没有返回给模型的原因(absolute 模式不会出现:一律视为不存在)。
63
- * `partial` = 用户只允许了其中几条,其余按拒绝处理。
62
+ * 被可见域挡住、没有返回给模型的原因。
63
+ * - rejected / timeout / unavailable / partial = 普通限制审批的结局;
64
+ * - absolute = 绝对限制下作用域根本不在范围内(0.23 起不再假装"不存在");
65
+ * - read-disabled = 作用域在范围内但「可读」开关被关掉(0.23)。
64
66
  */
65
-
67
+
66
68
 
67
69
 
68
70
 
71
+                        
72
+
73
+               
74
+
69
75
                  
70
76
 
71
77
 
@@ -131,10 +137,14 @@ import { canonicalWorkspacePath, normalizeScopeInput, resolveScopeRef } from '..
131
137
                             
132
138
 
133
139
 
134
-                               
140
+                           
135
141
                 
136
142
 
137
143
 
144
+                
145
+
146
+                  
147
+
138
148
 
139
149
                              
140
150
                                  
@@ -259,11 +269,17 @@ function scopeInPolicy(policy , scope )
259
269
  return policy.scopes.some((rule) => rule.scope === scope)
260
270
  }
261
271
 
262
- /** 这条记录是否在可见域内(scope 与类型都要满足)。 */
272
+ /** 该 scope 的规则;不在策略里时 undefined(等于范围外)。 */
273
+ function policyRule(policy , scope ) {
274
+ if (policy === undefined || policy.level === 'none') return undefined
275
+ return policy.scopes.find((item) => item.scope === scope)
276
+ }
277
+
278
+ /** 这条记录是否在可见域内(scope、read 开关与类型都要满足)。 */
263
279
  function recordAllowed(policy , scope , kind ) {
264
280
  if (policy === undefined || policy.level === 'none') return true
265
- const rule = policy.scopes.find((item) => item.scope === scope)
266
- if (rule === undefined) return false
281
+ const rule = policyRule(policy, scope)
282
+ if (rule === undefined || rule.read === false) return false
267
283
  return rule.kinds === undefined || rule.kinds.length === 0 || rule.kinds.includes(kind)
268
284
  }
269
285
 
@@ -272,6 +288,17 @@ function outsideReason(policy , scope )
272
288
  return scopeInPolicy(policy, scope) ? 'kind' : 'scope'
273
289
  }
274
290
 
291
+ /** 范围被挡住时给模型的原因:绝对限制 / 可读开关 / 普通审批结局。 */
292
+ function withheldReasonFor(
293
+ policy ,
294
+ verdict ,
295
+ hasAbsolute ,
296
+ ) {
297
+ if (verdict !== undefined) return verdict.outcome === 'allowed-once' ? 'partial' : verdict.outcome
298
+ if (policy !== undefined && policy.level === 'absolute' && hasAbsolute) return 'absolute'
299
+ return 'read-disabled'
300
+ }
301
+
275
302
  /** memory_* 的 description 参数说明(模型可见)。 */
276
303
  const DESCRIPTION_PARAM_DESCRIPTION =
277
304
  '本次调用要做什么(一句话,给用户看)。本会话「记忆范围」为普通限制时必填:审批范围外记忆时,弹窗会把它展示给用户。'
@@ -401,14 +428,46 @@ function visibilityError(outcome , action , sc
401
428
  )
402
429
  }
403
430
 
404
- /** 写入/删除前判断一个 scope 是否可操作(可见范围 = 可操作范围)。 */
405
- function scopeOperable(service , agent , policy , scope ) {
431
+ /** 写入/删除被「可写」开关或绝对限制挡住时给模型的真实原因。 */
432
+ function scopeWriteBlockedError(policy , scope , action ) {
433
+ const verb = action === 'write' ? '写入' : '删除'
434
+ const rule = policyRule(policy, scope)
435
+ if (rule !== undefined && rule.write === false) {
436
+ return new MemoryToolError(
437
+ 'SCOPE_READ_ONLY',
438
+ `作用域 ${scope} 在本会话记忆范围里被标记为「不可写」(可读/可写按钮),本次${verb}没有执行。如需${verb},请让用户打开该作用域的「可写」状态。`,
439
+ )
440
+ }
441
+ return new MemoryToolError(
442
+ 'VISIBILITY_ABSOLUTE',
443
+ `作用域 ${scope} 不在本会话可见范围内(限制等级:绝对限制),本次${verb}没有执行。如需${verb},请让用户调整「记忆范围」后重试。`,
444
+ )
445
+ }
446
+
447
+ /** 按 id 删除时,记录存在但被可见域挡住的原因(绝对限制 / 不可写)。 */
448
+ function blockedRecordError(policy , scope , id ) {
449
+ const rule = policyRule(policy, scope)
450
+ if (rule !== undefined && rule.write === false) {
451
+ return new MemoryToolError(
452
+ 'SCOPE_READ_ONLY',
453
+ `记忆 ${id} 所在作用域 ${scope} 在本会话记忆范围里被标记为「不可写」,本次删除没有执行。如需删除,请让用户打开该作用域的「可写」状态。`,
454
+ )
455
+ }
456
+ return new MemoryToolError(
457
+ 'VISIBILITY_ABSOLUTE',
458
+ `记忆 ${id} 不在本会话可见范围内(限制等级:绝对限制),本次删除没有执行。如需删除,请让用户调整「记忆范围」后重试。`,
459
+ )
460
+ }
461
+
462
+ /** 写入/删除前判断一个 scope 是否可写(0.23 起独立于 read 开关)。 */
463
+ function scopeWritable(service , agent , policy , scope ) {
406
464
  if (policy === undefined || policy.level === 'none') return true
407
465
  try {
408
- const verdict = service.isScopeOperable?.(agent, scope)
466
+ const verdict = service.isScopeWritable?.(agent, scope) ?? service.isScopeOperable?.(agent, scope)
409
467
  if (typeof verdict === 'boolean') return verdict
410
468
  } catch { /* 退回本地判断 */ }
411
- return scopeInPolicy(policy, scope)
469
+ const rule = policyRule(policy, scope)
470
+ return rule !== undefined && rule.write !== false
412
471
  }
413
472
 
414
473
  /** 规范里所有已知 scope(用来在普通限制下把范围外也搜一遍,看看有没有可审批的命中)。 */
@@ -563,18 +622,20 @@ export function memorySaveTool(opts )
563
622
  explicit = resolved
564
623
  }
565
624
 
566
- // 写入护栏(0.20.0):可见范围 = 可操作范围。范围外写入:
567
- // - absolute → 按"作用域不存在/不可写"处理,不暴露可见域配置;
568
- // - normal → 先向用户审批一次,拒绝/超时把真实原因抛给模型;
569
- // - none → 不限制。
625
+ // 写入护栏(0.20.0 / 0.23.0):write 开关与范围等级分开判断。
626
+ // - 作用域在范围内但「可写」关掉 → 直接拒绝并说明开关;
627
+ // - absolute 且作用域不在范围内 → 直接拒绝并说明绝对限制;
628
+ // - normal 且作用域不在范围内 → 先向用户审批一次,拒绝/超时讲真实原因;
629
+ // - none → 不限制。
570
630
  // 拿不到会话(老宿主 / 无 exec)时不判断:没有会话就没有"本会话的可见域"。
571
631
  const policy = agent === undefined ? undefined : visibilityPolicy(service, agent)
572
632
  const level = policy?.level ?? 'none'
573
633
  const target = explicit ?? (typeof service.resolveWriteScope === 'function' ? service.resolveWriteScope(agent) : undefined)
574
634
  let approved = false
575
- if (level !== 'none' && target !== undefined && !scopeOperable(service, agent, policy, target)) {
576
- if (level === 'absolute') {
577
- throw new MemoryToolError('SCOPE_NOT_WRITABLE', `作用域 ${target} 不存在或不可写`)
635
+ if (level !== 'none' && target !== undefined && !scopeWritable(service, agent, policy, target)) {
636
+ const rule = policyRule(policy, target)
637
+ if (rule !== undefined || level === 'absolute') {
638
+ throw scopeWriteBlockedError(policy, target, 'write')
578
639
  }
579
640
  const draft = {
580
641
  id: 'new-record',
@@ -698,7 +759,7 @@ function applySummaryDedupe(opts , exec , records
698
759
 
699
760
 
700
761
                                    
701
-                         
762
+                               
702
763
 
703
764
 
704
765
 
@@ -727,15 +788,17 @@ export function memorySearchTool(opts )
727
788
  const level = policy?.level ?? 'none'
728
789
  // level=none 时策略里的 scopes 只是偏好,不参与限制(等价于没有可见域)。
729
790
  const visible = policy !== undefined && policy.level !== 'none' ? policy.scopes.map((rule) => rule.scope) : undefined
730
- // 只有"用户显式设过"的普通限制才把磁盘上其它 scope 也搜一遍(才有范围外命中
731
- // 可以审批)。默认策略下普通检索就只搜默认的三路集合,避免每次都弹审批。
732
- const expand = level === 'normal' && explicitPolicy(policy)
791
+ // 用户显式设过的策略(absolute / normal)才把磁盘上其它 scope 也搜一遍:
792
+ // 既为普通限制找"可审批的命中",也让绝对限制能告诉 Agent「有几条被挡住」。
793
+ // 默认策略不主动外扩,避免普通检索每次都扫全盘/弹审批。
794
+ const expand = explicitPolicy(policy) && level !== 'none'
733
795
  let scopes
734
796
  if (resolved.all) {
735
797
  if (visible !== undefined) {
736
798
  // 'all' 在有可见范围限制时只等于"所有可见范围",不是磁盘上的全部 scope。
737
- // 普通限制额外把磁盘上其它 scope 也搜一遍,才有"范围外命中"可审批。
738
- scopes = level === 'normal' ? [...new Set([...visible, ...allKnownScopes(service)])] : visible
799
+ // 但显式 'all' 本身就表达"跨作用域",所以仍把磁盘上其它 scope 搜一遍:
800
+ // 普通限制据此发起审批,绝对限制据此告诉 Agent 被挡住了几条。
801
+ scopes = [...new Set([...visible, ...allKnownScopes(service)])]
739
802
  } else {
740
803
  scopes = allKnownScopes(service)
741
804
  }
@@ -757,29 +820,30 @@ export function memorySearchTool(opts )
757
820
  })
758
821
  const inside = hits.filter((hit) => recordAllowed(policy, hit.record.scope, hit.record.kind))
759
822
  const outside = hits.filter((hit) => !recordAllowed(policy, hit.record.scope, hit.record.kind))
760
- // undefined = 没有范围外命中 / 绝对限制(不审批);只有普通限制会真的问一次。
823
+ // 只有"作用域不在范围里"才可能审批;read:false 的作用域显式不可读,审批也不该放行。
824
+ const needsApproval = outside.filter((hit) => policyRule(policy, hit.record.scope) === undefined || policyRule(policy, hit.record.scope)?.read !== false)
761
825
  let verdict
762
- if (outside.length > 0 && level === 'normal') {
826
+ if (needsApproval.length > 0 && level === 'normal') {
763
827
  verdict = await askOutOfScope(
764
828
  service,
765
829
  agent,
766
830
  policy,
767
831
  'memory_search',
768
832
  args.query,
769
- outside.map((hit) => hit.record),
833
+ needsApproval.map((hit) => hit.record),
770
834
  'read',
771
835
  (exec )?.signal,
772
836
  descriptionOf(args.description),
773
837
  )
774
838
  }
775
- // verdict 为空 = 没有发起审批(绝对限制 / 没有范围外命中):范围外一律不放行。
839
+ // verdict 为空 = 没有发起审批(绝对限制 / read:false / 没有范围外命中):范围外不放行。
776
840
  const approvedOutside = verdict === undefined
777
841
  ? []
778
842
  : verdict.outcome !== 'allowed-once'
779
843
  ? []
780
844
  : verdict.allowedIds === undefined
781
- ? outside
782
- : outside.filter((hit) => verdict .allowedIds .has(hit.record.id))
845
+ ? needsApproval
846
+ : needsApproval.filter((hit) => verdict .allowedIds .has(hit.record.id))
783
847
  const insideIds = new Set(inside.map((hit) => hit.record.id))
784
848
  const approvedOutsideIds = new Set(approvedOutside.map((hit) => hit.record.id))
785
849
  const selected = hits.filter((hit) => insideIds.has(hit.record.id) || approvedOutsideIds.has(hit.record.id))
@@ -794,10 +858,11 @@ export function memorySearchTool(opts )
794
858
  summary: summarize(h.record.content, chars),
795
859
  })),
796
860
  }
797
- // absolute:范围外视为不存在,连"被挡住"都不告诉模型。
798
- if (verdict !== undefined) {
799
- const denied = outside.length - approvedOutside.length
800
- if (denied > 0) result.withheld = { count: denied, reason: verdict.outcome === 'allowed-once' ? 'partial' : verdict.outcome }
861
+ // 0.23:被挡住时告诉模型真实原因(绝对限制 / 不可读 / 审批拒绝…),不再假装不存在。
862
+ const denied = outside.length - approvedOutside.length
863
+ if (denied > 0) {
864
+ const reason = withheldReasonFor(policy, verdict, outside.length > 0)
865
+ if (reason !== undefined) result.withheld = { count: denied, reason }
801
866
  }
802
867
  if (wantedTopK !== undefined) result.records = result.records.slice(0, wantedTopK)
803
868
  // 上下文去重:同一条记忆同版本已经出现过 → 只回 id,摘要让 memory_get 按需取。
@@ -843,15 +908,15 @@ export function memoryForgetTool(opts )
843
908
  const policy = agent === undefined ? undefined : visibilityPolicy(service, agent)
844
909
  const level = policy?.level ?? 'none'
845
910
  const signal = (exec )?.signal
846
- // ---- 按 id 删除:先查出这条记录在哪个 scope,再按可操作范围判断 ----
911
+ // ---- 按 id 删除:先查出这条记录在哪个 scope,再按可写范围判断 ----
847
912
  if (args.id) {
848
913
  const matches = (service.getByIds?.([args.id]) ?? []).filter((record) => record.id === args.id)
849
- const blocked = matches.filter((record) => !recordAllowed(policy, record.scope, record.kind))
914
+ const blocked = matches.filter((record) => !scopeWritable(service, agent, policy, record.scope))
850
915
  let approved = false
851
916
  if (blocked.length > 0) {
852
- if (level === 'absolute') {
853
- // 绝对限制:范围外的记录"视为不存在",与真的没有这条 id 完全一样。
854
- throw new MemoryToolError('RECORD_NOT_FOUND', `id ${args.id} not found`)
917
+ // 作用域在范围内但「可写」关掉,或绝对限制下根本不在范围内:直接说明原因。
918
+ if (level === 'absolute' || policyRule(policy, blocked[0] .scope) !== undefined) {
919
+ throw blockedRecordError(policy, blocked[0] .scope, args.id)
855
920
  }
856
921
  if (level === 'normal') {
857
922
  const verdict = await askOutOfScope(
@@ -881,17 +946,17 @@ export function memoryForgetTool(opts )
881
946
  throw toolError(error)
882
947
  }
883
948
  }
884
- // ---- 按 query 删除:目标 scope 必须在可操作范围内 ----
949
+ // ---- 按 query 删除:目标 scope 必须可写 ----
885
950
  const resolved = resolveScope(opts, service, exec, args.scope, 'read')
886
951
  if (resolved.all) {
887
952
  throw new MemoryToolError('SCOPE_NOT_WRITABLE', "scope 'all' cannot be combined with query; name the scope you mean")
888
953
  }
889
954
  const scope = resolved.scope ?? readScopes(opts, service, agent)[0]
890
955
  let approved = false
891
- if (level !== 'none' && scope !== undefined && !scopeOperable(service, agent, policy, scope)) {
892
- if (level === 'absolute') {
893
- // 绝对限制:这个作用域"不存在",按一条都没匹配处理(不删、也不泄露原因)。
894
- return { removed: 0, ids: [] }
956
+ if (level !== 'none' && scope !== undefined && !scopeWritable(service, agent, policy, scope)) {
957
+ // 绝对限制 / 「可写」关掉:直接说明原因,不再静默返回"删了 0 条"。
958
+ if (policyRule(policy, scope) !== undefined || level === 'absolute') {
959
+ throw scopeWriteBlockedError(policy, scope, 'delete')
895
960
  }
896
961
  const verdict = await askOutOfScope(
897
962
  service,
@@ -945,7 +1010,7 @@ export function memoryForgetTool(opts )
945
1010
 
946
1011
 
947
1012
                               
948
-                   
1013
+                      
949
1014
 
950
1015
 
951
1016
 
@@ -969,10 +1034,14 @@ export function memoryListTool(opts )
969
1034
  const level = policy?.level ?? 'none'
970
1035
  // level=none 时策略里的 scopes 只是偏好,不参与限制(等价于没有可见域)。
971
1036
  const visible = policy !== undefined && policy.level !== 'none' ? policy.scopes.map((rule) => rule.scope) : undefined
1037
+ const readable = policy !== undefined && policy.level !== 'none'
1038
+ ? policy.scopes.filter((rule) => rule.read !== false).map((rule) => rule.scope)
1039
+ : undefined
1040
+ const expand = explicitPolicy(policy) && level !== 'none'
972
1041
  let scopes
973
1042
  if (resolved.all) {
974
1043
  if (visible !== undefined) {
975
- scopes = level === 'normal' ? [...new Set([...visible, ...allKnownScopes(service)])] : visible
1044
+ scopes = [...new Set([...visible, ...allKnownScopes(service)])]
976
1045
  } else {
977
1046
  scopes = allKnownScopes(service)
978
1047
  }
@@ -994,16 +1063,16 @@ export function memoryListTool(opts )
994
1063
  })
995
1064
  const inside = raw.filter((record) => recordAllowed(policy, record.scope, record.kind))
996
1065
  const outside = raw.filter((record) => !recordAllowed(policy, record.scope, record.kind))
997
- // undefined = 没有范围外命中 / 绝对限制(不审批);只有普通限制会真的问一次。
1066
+ const needsApproval = outside.filter((record) => policyRule(policy, record.scope) === undefined || policyRule(policy, record.scope)?.read !== false)
998
1067
  let verdict
999
- if (outside.length > 0 && level === 'normal') {
1068
+ if (needsApproval.length > 0 && level === 'normal') {
1000
1069
  verdict = await askOutOfScope(
1001
1070
  service,
1002
1071
  agent,
1003
1072
  policy,
1004
1073
  'memory_list',
1005
1074
  resolved.scope ?? args.scope ?? 'all',
1006
- outside,
1075
+ needsApproval,
1007
1076
  'read',
1008
1077
  (exec )?.signal,
1009
1078
  descriptionOf(args.description),
@@ -1014,8 +1083,8 @@ export function memoryListTool(opts )
1014
1083
  : verdict.outcome !== 'allowed-once'
1015
1084
  ? []
1016
1085
  : verdict.allowedIds === undefined
1017
- ? outside
1018
- : outside.filter((record) => verdict .allowedIds .has(record.id))
1086
+ ? needsApproval
1087
+ : needsApproval.filter((record) => verdict .allowedIds .has(record.id))
1019
1088
  const insideIds = new Set(inside.map((record) => record.id))
1020
1089
  const approvedOutsideIds = new Set(approvedOutside.map((record) => record.id))
1021
1090
  const selected = raw
@@ -1028,9 +1097,10 @@ export function memoryListTool(opts )
1028
1097
  updatedAt: r.updatedAt,
1029
1098
  content: r.content,
1030
1099
  }))
1031
- if (verdict !== undefined) {
1032
- const denied = outside.length - approvedOutside.length
1033
- if (denied > 0) withheld = { count: denied, reason: verdict.outcome === 'allowed-once' ? 'partial' : verdict.outcome }
1100
+ const denied = outside.length - approvedOutside.length
1101
+ if (denied > 0) {
1102
+ const reason = withheldReasonFor(policy, verdict, outside.length > 0)
1103
+ if (reason !== undefined) withheld = { count: denied, reason }
1034
1104
  }
1035
1105
  // 上下文去重:同版本已经出现过 → 只回 id,正文让 memory_get 按需取。
1036
1106
  const dedup = opts.contextDedup?.(exec)
@@ -1051,8 +1121,8 @@ export function memoryListTool(opts )
1051
1121
  throw toolError(error)
1052
1122
  }
1053
1123
  const statsAll = service.scopeStats?.()
1054
- const stats = statsAll !== undefined && visible !== undefined
1055
- ? statsAll.filter((s) => visible.includes(s.scope))
1124
+ const stats = statsAll !== undefined && readable !== undefined
1125
+ ? statsAll.filter((s) => readable.includes(s.scope))
1056
1126
  : statsAll
1057
1127
  return {
1058
1128
  records,
@@ -1102,7 +1172,7 @@ export const DEFAULT_GET_FIELDS = ['content', 'scope', 'kind', 'tags
1102
1172
 
1103
1173
 
1104
1174
                                 
1105
-                   
1175
+                                
1106
1176
 
1107
1177
 
1108
1178
 
@@ -1195,39 +1265,42 @@ export function memoryGetTool(opts )
1195
1265
  const level = policy?.level ?? 'none'
1196
1266
  const inside = all.filter((record) => recordAllowed(policy, record.scope, record.kind))
1197
1267
  const outside = all.filter((record) => !recordAllowed(policy, record.scope, record.kind))
1198
- // undefined = 没有范围外命中 / 绝对限制(不审批);只有普通限制会真的问一次。
1268
+ // read:false 是用户显式关掉的可读状态,审批也不放行;只有"作用域不在范围里"才审批。
1269
+ const needsApproval = outside.filter((record) => policyRule(policy, record.scope) === undefined || policyRule(policy, record.scope)?.read !== false)
1199
1270
  let verdict
1200
- if (outside.length > 0 && level === 'normal') {
1271
+ if (needsApproval.length > 0 && level === 'normal') {
1201
1272
  verdict = await askOutOfScope(
1202
1273
  service,
1203
1274
  agent,
1204
1275
  policy,
1205
1276
  'memory_get',
1206
1277
  ids.join(' '),
1207
- outside,
1278
+ needsApproval,
1208
1279
  'read',
1209
1280
  (exec )?.signal,
1210
1281
  descriptionOf(args.description),
1211
1282
  )
1212
1283
  }
1213
- // verdict 为空 = 没有发起审批(绝对限制):范围外一律按不存在处理。
1284
+ // verdict 为空 = 没有发起审批(绝对限制 / read:false):范围外不放行。
1214
1285
  const approvedOutside = verdict === undefined
1215
1286
  ? []
1216
1287
  : verdict.outcome !== 'allowed-once'
1217
1288
  ? []
1218
1289
  : verdict.allowedIds === undefined
1219
- ? outside
1220
- : outside.filter((record) => verdict .allowedIds .has(record.id))
1290
+ ? needsApproval
1291
+ : needsApproval.filter((record) => verdict .allowedIds .has(record.id))
1221
1292
  const insideIds = new Set(inside.map((record) => record.id))
1222
1293
  const approvedIds = new Set(approvedOutside.map((record) => record.id))
1223
1294
  const found = all.filter((record) => insideIds.has(record.id) || approvedIds.has(record.id))
1224
1295
  const denied = outside.length - approvedOutside.length
1296
+ const reason = denied > 0 ? withheldReasonFor(policy, verdict, outside.length > 0) : undefined
1225
1297
  return {
1226
1298
  records: found.map((r) => pickGetFields(r, fields, chars)),
1227
1299
  fields,
1228
- missing: ids.filter((token) => !found.some((r) => r.id === token || r.id.startsWith(token))),
1229
- ...(verdict !== undefined && denied > 0
1230
- ? { withheld: { count: denied, reason: verdict.outcome === 'allowed-once' ? 'partial' : verdict.outcome } }
1300
+ // 被可见域挡住的 id 不是"不存在":它们进 withheld 说明原因,不进 missing。
1301
+ missing: ids.filter((token) => !all.some((r) => r.id === token || r.id.startsWith(token))),
1302
+ ...(reason !== undefined
1303
+ ? { withheld: { count: denied, reason } }
1231
1304
  : {}),
1232
1305
  }
1233
1306
  } catch (error) {
@@ -6,15 +6,15 @@
6
6
  * 正文走 memory_get;memory_get 的 fields 决定渲染哪些元数据。
7
7
  *
8
8
  * 0.20.0:范围外命中被挡住时,把**真实原因**(用户拒绝 / 审批超时 / 无法审批)
9
- * 写进渲染文本。绝对限制下工具根本不会带 withheld(视为不存在),所以这里
10
- * 不需要也不应该提"被挡住"。
9
+ * 写进渲染文本。
10
+ * 0.23.0:绝对限制与「不可读」开关也会被说明(不再假装"不存在"),并提示怎么调整。
11
11
  */
12
12
 
13
13
 
14
14
  /** 把 scope 键渲染成展示文案(宿主能查到会话标题时用它,否则用短 id)。 */
15
15
 
16
16
 
17
- /** 有内容没返回时的原因(absolute 模式不会走到这里)。 */
17
+ /** 有内容没返回时的原因。 */
18
18
 
19
19
 
20
20
  /**
@@ -33,7 +33,7 @@ const joinList = (value ) =>
33
33
 
34
34
  /**
35
35
  * 范围外内容为什么没返回——给模型看的真实原因。
36
- * 空字符串 = 没有需要说明的(没有 withheld,或 absolute 模式下不告知)。
36
+ * 空字符串 = 没有需要说明的(没有 withheld)。
37
37
  */
38
38
  export function renderWithheldNote(withheld ) {
39
39
  if (withheld === undefined || withheld.count <= 0) return ''
@@ -47,6 +47,10 @@ export function renderWithheldNote(withheld ) {
47
47
  return `另有 ${count} 条记忆在本会话的可见域外,当前环境无法发起审批,未返回。`
48
48
  case 'partial':
49
49
  return `另有 ${count} 条记忆在本会话的可见域外,用户在本次审批中只允许了其余条目(限制等级:普通限制),未返回。如确实需要,请让用户调整「记忆范围」后重试。`
50
+ case 'absolute':
51
+ return `另有 ${count} 条记忆在本会话的可见域外,当前限制等级为「绝对限制」,不会发起审批,未返回。如确实是本次任务需要的内容,请让用户调整「记忆范围」后重试。`
52
+ case 'read-disabled':
53
+ return `另有 ${count} 条记忆所在的作用域在本会话记忆范围里被标记为「不可读」(可读/可写按钮),未返回。如确实需要,请让用户打开该作用域的「可读」状态后重试。`
50
54
  default:
51
55
  return ''
52
56
  }
@@ -144,8 +148,7 @@ export function renderGetResult(value , label ) {
144
148
  return text === '' ? head : `${head}\n${text}`
145
149
  }).join('\n\n')
146
150
  const missing = value.missing.length > 0 ? `未找到:${value.missing.join(', ')}` : ''
147
- // 被可见域挡住的那几条:absolute 模式下 provider 不会给 withheld(视为不存在),
148
- // 其余情况把真实原因(拒绝 / 超时 / 无法审批)告诉模型。
151
+ // 被可见域挡住的那几条:把真实原因(拒绝 / 超时 / 绝对限制 / 不可读)告诉模型。
149
152
  const note = renderWithheldNote(value.withheld)
150
153
  const tail = [missing, note].filter((part) => part !== '').join('\n\n')
151
154
  if (body === '') return tail === '' ? '没有找到记忆。' : tail
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.22.3",
3
+ "version": "0.23.1",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",