@restregular/dsh-memory 0.36.1 → 0.37.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  本项目的版本记录。安装 id 与 npm 版本一一对应。
4
4
 
5
+ ## 0.37.0 — 钩子可读设置数据 + memory_list 完整时间戳 + 去掉冗余 key
6
+
7
+ - **钩子沙箱可读设置(ctx.settings)**:`HookRunInput` 新增可选 `settings`(只读快照:`digestChars` / `impressionChars` / `recallChars`),经 `runHookCode` 序列化进沙箱 `ctx.settings`;`parseForInject` 从实时 `injectSettings()` 取值(摘要 160 字、印象字数面板可改、召回 300 字)传入,`memory_hooks run` 试跑也带默认快照。before-inject 规则代码从此能按"当前摘要字数限制"截断,不写死数字。
8
+ - **新增规则代码**:挂了一条 `before-inject` 钩子「注入摘要只取概括句」——注入摘要时只保留记忆里第一个全角冒号「:」前的内容,没有冒号就用全文,超长按 `ctx.settings` 里的摘要字数上限截断。已试跑验证。
9
+ - **memory_list fields=full_time**:`fields` 参数新增 `full_time`,传了就给每条记录 `fullTime:{createdAt,updatedAt,expiresAt?}`(ISO 8601 精确到秒,无毫秒),渲染文案同步显示「创建/更新/过期」。不传则不带时间字段,保持旧行为。
10
+ - **去掉 save 提示里冗余的作用域 key**:`memory_save` 结果文案此前既在头部 `@ <scope>`、又追加一行「保存到的目标作用域 key:」说同一件事;现在只在头部 `@ <原始 key>` 出现一次,开头格式不变(`memorySaveResultIds` 按 UUID 抽取不受影响)。
11
+ - 回归守卫:`hooks.test.ts` 加 ctx.settings 透传与跟随实时设置两例,`tools.test.ts` 加 full_time 数据与渲染一例,`apply-registration.test.ts` 守卫 key 不再重复。全套 62 个测试文件 0 失败。
12
+
5
13
  ## 0.36.1 — 删除钩子加二次确认
6
14
 
7
15
  - **问题**:用户误点面板「删除」把「记忆内容规范(概括句:正文)」校验钩子删掉了——`memory_hooks delete` 与面板删除都是硬删除(`hooks.json` 直接 filter 后原子覆盖,没有回收站、没有 .bak),一次点击/一次调用代码就没了,且没有任何确认。
@@ -8,6 +8,8 @@ export const POLICY_TEXT = `## 记忆系统
8
8
 
9
9
  memory_search 只返回印象(ID、作用域、类型、标签和少量摘要);判断相关后再用 memory_get(ids, fields) 取正文。fields 省略 = content + scope + kind + tags;只要摘要用 ["summary"],只要正文用 ["content"],需要重要度 / 时间 / 触发词等再显式加上对应字段。
10
10
 
11
+ memory_list 默认不返回时间戳;要完整时间(精确到秒)就传 fields:["full_time"],每条会给 createdAt / updatedAt / expiresAt 的 ISO 时间戳并显示在列表文案里。
12
+
11
13
  搜索命中作用域外记忆时默认**不弹审批**:结果里的 outOfScope 字段只列出命中的作用域——各几条、以及这些作用域的**用途描述**,不含任何记忆内容(也就没有摘要可引用)。确认某个作用域的用途确实与本次任务相关时,再用 memory_search 带 requestApproval=true 重新发起同一次搜索(这时才弹审批),或用 memory_scopes(action="request") 申请该作用域的本会话权限。
12
14
 
13
15
  需要知道有哪些作用域、各自用来做什么、当前能不能读/写时,用 memory_scopes(action="list")。它只返回目录元信息(名字 / 用途 / 访问状态)与初始化记录正文,不返回普通记忆正文;范围外作用域在绝对限制下仍可发现,但正文(含初始化记录)永不可读、不可申请。
@@ -107,6 +107,22 @@ const PHASE_ENTRY = {
107
107
 
108
108
 
109
109
 
110
+ /**
111
+ * 钩子脚本能读到的注入设置(只读快照,随 ctx 进沙箱)。
112
+ *
113
+ * 只暴露"和摘要字数相关"的几项,不把整个 settings.json 倒进沙箱:
114
+ * 脚本用它决定"冒号前的内容如果太长,按哪个上限截断"。
115
+ * 各项与 inject-settings.ts 里的默认值一致,调用方(parseForInject)用实时设置覆盖。
116
+ */
117
+
118
+                          
119
+
120
+                      
121
+
122
+                    
123
+
124
+
125
+
110
126
  /** 一次运行的输入。 */
111
127
 
112
128
 
@@ -114,6 +130,8 @@ const PHASE_ENTRY = {
114
130
 
115
131
 
116
132
 
133
+                             
134
+
117
135
 
118
136
 
119
137
  /** 单个钩子的运行结果。 */
@@ -300,6 +318,8 @@ export function runHookCode(
300
318
  ...(input.tool !== undefined ? { tool: input.tool } : {}),
301
319
  ...(input.sessionId !== undefined ? { sessionId: input.sessionId } : {}),
302
320
  ...(input.description !== undefined ? { description: input.description } : {}),
321
+ // 0.37.0:只读设置快照进沙箱 ctx.settings —— 脚本能按当前摘要字数限制截断。
322
+ ...(input.settings !== undefined ? { settings: input.settings } : {}),
303
323
  now: Date.now(),
304
324
  })
305
325
  const driver = new vm.Script(
@@ -1100,6 +1100,13 @@ export class LocalMemoryService {
1100
1100
  {
1101
1101
  const settings = this.hookSettings()
1102
1102
  if (!settings.enabled || records.length === 0) return { records: [...records], changed: [], warnings: [] }
1103
+ // 0.37.0:设置快照只读一次,传给每条记录的 before-inject 钩子(ctx.settings)。
1104
+ const injectCfg = this.injectSettings()
1105
+ const settingsView = {
1106
+ digestChars: 160,
1107
+ impressionChars: injectCfg.impression.chars,
1108
+ recallChars: 300,
1109
+ }
1103
1110
  const out = []
1104
1111
  const changed = []
1105
1112
  const warnings = []
@@ -1122,6 +1129,7 @@ export class LocalMemoryService {
1122
1129
  },
1123
1130
  tool: 'inject',
1124
1131
  ...(sessionId !== undefined ? { sessionId } : {}),
1132
+ settings: settingsView,
1125
1133
  })
1126
1134
  const outcome = outcomes.find((item) => item.hook.id === hook.id)
1127
1135
  if (outcome === undefined) continue
@@ -137,18 +137,17 @@ export function apply(ctx , config = {}) {
137
137
  }
138
138
 
139
139
  register(tools.memory_save, (value, _args, exec) => {
140
- const agent = (exec )?.agent
140
+ // 0.37.0:作用域 key 只在头部出现一次 —— head 直接写原始 key(value.scope),
141
+ // 去掉了原先额外追加的那行 key 文案(它和 @ <scope> 说同一件事,重复)。
142
+ // 文案仍以「已保存记忆 <uuid> @ <key>」开头,signals.ts 按 UUID 抽取不受影响。
141
143
  const head = value.deduped
142
- ? `已更新既有记忆(内容相同,去重):${value.id} @ ${renderScope(value.scope, agent)}`
143
- : `已保存记忆 ${value.id} @ ${renderScope(value.scope, agent)}`
144
- // 0.36.0:所有 memory_save 返回统一带上保存到的目标作用域 key;用 supersedes
145
- // 修正旧记忆时额外说明修正关系(旧记录所在作用域可不同)。文案仍以
146
- // 「已保存记忆 <uuid> @ <scope>」开头,signals.ts 按 UUID 抽取不受影响。
147
- const scopeKeyLine = `保存到的目标作用域 key:${value.scope}`
144
+ ? `已更新既有记忆(内容相同,去重):${value.id} @ ${value.scope}`
145
+ : `已保存记忆 ${value.id} @ ${value.scope}`
146
+ // supersedes 场景补一条修正关系(旧记录所在作用域可不同)。
148
147
  const correctionLine = value.supersedes === undefined
149
148
  ? ''
150
149
  : `\n已用本条修正旧记忆 ${value.supersedes.id}${value.supersedes.scope !== undefined ? `(旧记录在 ${value.supersedes.scope})` : ''}`
151
- const tail = `\n${scopeKeyLine}${correctionLine}`
150
+ const tail = correctionLine
152
151
  const hook = value.hook
153
152
  if (hook === undefined) return `${head}${tail}`
154
153
  const approvalText = {
@@ -218,7 +218,7 @@ import { canonicalWorkspacePath, defaultScopeDescription, normalizeScopeInput, r
218
218
 
219
219
 
220
220
 
221
-
221
+
222
222
                  
223
223
 
224
224
                          
@@ -1633,16 +1633,41 @@ export function memoryForgetTool(opts )
1633
1633
  }
1634
1634
  }
1635
1635
 
1636
+ /** 毫秒时间戳 → ISO 8601 精确到秒(去掉毫秒)。非法值返回 undefined。 */
1637
+ function isoSecond(value ) {
1638
+ if (typeof value !== 'number' || !Number.isFinite(value)) return undefined
1639
+ return new Date(value).toISOString().slice(0, 19) + 'Z'
1640
+ }
1641
+
1642
+ /** memory_list 的 fields 解析:目前只认 full_time。 */
1643
+ function listWantsFullTime(fields ) {
1644
+ return Array.isArray(fields) && fields.some((field) => String(field).trim() === 'full_time')
1645
+ }
1646
+
1636
1647
 
1637
1648
 
1638
1649
 
1639
1650
 
1651
+
1652
+                         
1653
+                   
1654
+
1655
+
1640
1656
                              
1641
1657
 
1642
1658
 
1643
1659
 
1644
1660
 
1645
-
1661
+
1662
+
1663
+
1664
+
1665
+
1666
+
1667
+
1668
+                      
1669
+
1670
+
1646
1671
                                 
1647
1672
 
1648
1673
 
@@ -1661,6 +1686,11 @@ export function memoryListTool(opts )
1661
1686
  kind: { type: 'string' },
1662
1687
  limit: { type: 'number', description: '1~200' },
1663
1688
  description: { type: 'string', description: DESCRIPTION_PARAM_DESCRIPTION },
1689
+ fields: {
1690
+ type: 'array',
1691
+ items: { type: 'string' },
1692
+ description: '可选字段。`full_time` = 每条记忆给出精确到秒的完整时间戳(createdAt / updatedAt / expiresAt);不传则不带。',
1693
+ },
1664
1694
  },
1665
1695
  async execute(args , exec ) {
1666
1696
  const service = svc(opts)
@@ -1728,12 +1758,24 @@ export function memoryListTool(opts )
1728
1758
  const selected = raw
1729
1759
  .filter((record) => insideIds.has(record.id) || approvedOutsideIds.has(record.id))
1730
1760
  .slice(0, limit)
1761
+ const wantFullTime = listWantsFullTime(args.fields)
1731
1762
  records = selected.map((r) => ({
1732
1763
  id: r.id,
1733
1764
  scope: r.scope,
1734
1765
  kind: r.kind,
1735
1766
  updatedAt: r.updatedAt,
1736
1767
  content: r.content,
1768
+ ...(wantFullTime
1769
+ ? {
1770
+ fullTime: {
1771
+ createdAt: isoSecond(r.createdAt) ?? isoSecond(r.updatedAt) ?? '',
1772
+ updatedAt: isoSecond(r.updatedAt) ?? '',
1773
+ ...(r.expiresAt !== undefined && Number.isFinite(r.expiresAt)
1774
+ ? { expiresAt: isoSecond(r.expiresAt) }
1775
+ : {}),
1776
+ },
1777
+ }
1778
+ : {}),
1737
1779
  }))
1738
1780
  const denied = outside.length - approvedOutside.length
1739
1781
  if (denied > 0) {
@@ -2609,6 +2651,8 @@ export function memoryHooksTool(opts )
2609
2651
  importance: 0.8,
2610
2652
  },
2611
2653
  tool: 'memory_hooks',
2654
+ // 0.37.0:试跑也带设置快照,脚本里读 ctx.settings.* 不会是 undefined。
2655
+ settings: { digestChars: 160, impressionChars: 120, recallChars: 300 },
2612
2656
  }
2613
2657
  const mine = service.runHookTrial(hook.id, input)
2614
2658
  const verdict = mine[0]
@@ -142,7 +142,11 @@ export function renderListResult(value , label ) {
142
142
  omitted += 1
143
143
  return shortId(record.id)
144
144
  }
145
- return `(${label(record.scope)}/${record.kind}) ${record.content}`
145
+ const full = record.fullTime
146
+ const timeLine = full === undefined
147
+ ? ''
148
+ : ` [创建 ${full.createdAt} · 更新 ${full.updatedAt}${full.expiresAt !== undefined ? ` · 过期 ${full.expiresAt}` : ''}]`
149
+ return `(${label(record.scope)}/${record.kind})${timeLine} ${record.content}`
146
150
  }).join('\n')
147
151
  const note = renderWithheldNote(value.withheld)
148
152
  const tail = [omitted > 0 ? DEDUPE_NOTE : '', note].filter((part) => part !== '').join('\n\n')
@@ -412,7 +416,7 @@ export function renderHooksResult(value , label )
412
416
  const note = value.note !== undefined ? `${value.note}\n` : ''
413
417
  const settings = settingsLine()
414
418
  return `${body}${settings !== '' ? `\n\n${settings}` : ''}${note !== '' ? `\n${note}` : ''}`
415
- }
419
+ }
416
420
 
417
421
 
418
422
  //# sourceURL=source/tool-memory/src/render.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.36.1",
3
+ "version": "0.37.0",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
@@ -76,7 +76,17 @@ function verify(memory) {
76
76
  `ctx` 描述这次调用:
77
77
 
78
78
  ```js
79
- { phase, tool, sessionId, description, now }
79
+ { phase, tool, sessionId, description, now, settings }
80
+ ```
81
+
82
+ `settings` 是**只读设置快照**(0.37.0 起),脚本能读到当前注入设置里的摘要字数限制,按它截断而不写死数字:
83
+
84
+ ```js
85
+ {
86
+ digestChars: 160, // 会话第一步摘要里每条正文的字数上限
87
+ impressionChars: 120, // 自动召回"印象"模式每条摘要的字数上限(面板可改)
88
+ recallChars: 300, // 自动召回完整模式每条正文的字数上限
89
+ }
80
90
  ```
81
91
 
82
92
  `tool` 是触发者(`'memory_save'` / `'memory_hooks'` / `'inject'`),可以据此分支: