@restregular/dsh-memory 0.36.0 → 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 +16 -0
- package/lib/client.js +3 -0
- package/lib/inject/policy.js +2 -0
- package/lib/provider/hooks.js +20 -0
- package/lib/provider/index.js +8 -0
- package/lib/tools/apply.js +7 -8
- package/lib/tools/index.js +71 -3
- package/lib/tools/render.js +6 -2
- package/package.json +1 -1
- package/skills/memory-hook-scripts/SKILL.md +25 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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
|
+
|
|
13
|
+
## 0.36.1 — 删除钩子加二次确认
|
|
14
|
+
|
|
15
|
+
- **问题**:用户误点面板「删除」把「记忆内容规范(概括句:正文)」校验钩子删掉了——`memory_hooks delete` 与面板删除都是硬删除(`hooks.json` 直接 filter 后原子覆盖,没有回收站、没有 .bak),一次点击/一次调用代码就没了,且没有任何确认。
|
|
16
|
+
- **工具层**:`memory_hooks({action:'delete'})` 改成两步——第一次不带 `confirm` 只返回 `requiresConfirmation:true` + 待删预览(`removed:0`,钩子仍在),模型要把目标钩子的 `name` 或完整 `id` 回填到 `confirm` 再调一次才真删;`confirm` 写错或省略只会再拿一次预览,不会误删别的钩子。工具 description 与返回 `note` 都写明"不可逆、没有回收站"。
|
|
17
|
+
- **面板**:删除按钮加 `window.confirm()`,弹窗点名钩子名、说明不可逆,并提示"只是想让它停下请改用停用"。
|
|
18
|
+
- **文档**:随包技能 `memory-hook-scripts` 补「删除钩子要二次确认」一节;`bundled-skills.test.ts` 与 `hooks-tool.test.ts` 加守卫。全套 62 个测试文件 0 失败。
|
|
19
|
+
- **附注**:本次被删的钩子已从会话日志里找回(多帧 zstd 要先用 zstd.exe 全解,Node 内置 zstd 只解首帧),已重新挂回并试跑验证;恢复后是新 id、需用户重新批准一次才生效。
|
|
20
|
+
|
|
5
21
|
## 0.36.0 — supersedes 支持跨作用域修正,且必须显式带 scope
|
|
6
22
|
|
|
7
23
|
- **跨作用域修正**:此前 `memory_save.supersedes` 的旧记录按 id 精确查找时**只查新记录写入的那一个 scope**,旧记录在别的作用域一律报 `SUPERSEDES_UNKNOWN`(且文案与"id 不存在"完全一样)。现在改成跨全部作用域按完整 id 查找(`findById`):新记录可以落在任意作用域去修正另一作用域里的旧记录(project / global / session / 自定义均可)。配套把"已修正/退役"标记也改成全局收集 —— `search` / `listSync` / 自动召回的 `excludedIds` 不再只看当前搜索的 scopes,否则 global 里的修正版挡不住 project 里的旧记录。
|
package/lib/client.js
CHANGED
|
@@ -2967,6 +2967,9 @@ window.__ModuleLoader__.load({
|
|
|
2967
2967
|
}
|
|
2968
2968
|
|
|
2969
2969
|
const remove = async (hook) => {
|
|
2970
|
+
// 0.36.1:删除钩子不可逆(hooks.json 直接覆盖、无回收站),面板也加一道二次确认,
|
|
2971
|
+
// 与工具层的 confirm 参数对齐 —— 用户误点不再瞬间丢掉写好的规则代码。
|
|
2972
|
+
if (!window.confirm(`确定删除钩子「${hook.name || hook.id}」吗?\n\n这一步不可逆:规则代码会从 hooks.json 直接移除,没有回收站。若只是想让它停下,请改用「停用」。`)) return
|
|
2970
2973
|
setBusy(true)
|
|
2971
2974
|
setError('')
|
|
2972
2975
|
try {
|
package/lib/inject/policy.js
CHANGED
|
@@ -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")。它只返回目录元信息(名字 / 用途 / 访问状态)与初始化记录正文,不返回普通记忆正文;范围外作用域在绝对限制下仍可发现,但正文(含初始化记录)永不可读、不可申请。
|
package/lib/provider/hooks.js
CHANGED
|
@@ -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(
|
package/lib/provider/index.js
CHANGED
|
@@ -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
|
package/lib/tools/apply.js
CHANGED
|
@@ -137,18 +137,17 @@ export function apply(ctx , config = {}) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
register(tools.memory_save, (value, _args, exec) => {
|
|
140
|
-
|
|
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} @ ${
|
|
143
|
-
: `已保存记忆 ${value.id} @ ${
|
|
144
|
-
//
|
|
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 =
|
|
150
|
+
const tail = correctionLine
|
|
152
151
|
const hook = value.hook
|
|
153
152
|
if (hook === undefined) return `${head}${tail}`
|
|
154
153
|
const approvalText = {
|
package/lib/tools/index.js
CHANGED
|
@@ -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) {
|
|
@@ -2360,6 +2402,12 @@ export function memoryBlockTool(opts )
|
|
|
2360
2402
|
|
|
2361
2403
|
|
|
2362
2404
|
|
|
2405
|
+
|
|
2406
|
+
|
|
2407
|
+
|
|
2408
|
+
|
|
2409
|
+
|
|
2410
|
+
|
|
2363
2411
|
|
|
2364
2412
|
|
|
2365
2413
|
|
|
@@ -2372,6 +2420,8 @@ export function memoryBlockTool(opts )
|
|
|
2372
2420
|
|
|
2373
2421
|
|
|
2374
2422
|
|
|
2423
|
+
|
|
2424
|
+
|
|
2375
2425
|
|
|
2376
2426
|
|
|
2377
2427
|
|
|
@@ -2395,6 +2445,7 @@ const HOOKS_TOOL_DESCRIPTION =
|
|
|
2395
2445
|
'Manage executable memory hooks: scripts attached to rule memories that the plugin runs at a fixed phase. '
|
|
2396
2446
|
+ 'before-save validates a memory and can REJECT the save; after-save only observes; before-inject parses text before it enters context. '
|
|
2397
2447
|
+ 'Hook code lives in hooks.json and is NEVER part of memory search/list/digest. '
|
|
2448
|
+
+ 'Deleting a hook is IRREVERSIBLE — action="delete" requires a two-step confirmation: first call without confirm to get a preview, then repeat with confirm="<hook name or id>". '
|
|
2398
2449
|
+ 'Load the `memory-hook-scripts` skill (via the `skill` tool) before writing code — it documents the entry-function names, the sandbox API, the return contract and ready-made examples.'
|
|
2399
2450
|
|
|
2400
2451
|
export function memoryHooksTool(opts ) {
|
|
@@ -2406,10 +2457,11 @@ export function memoryHooksTool(opts )
|
|
|
2406
2457
|
type: 'string',
|
|
2407
2458
|
enum: ['list', 'get', 'save', 'delete', 'approve', 'enable', 'disable', 'run'],
|
|
2408
2459
|
required: true,
|
|
2409
|
-
description: 'list=列全部(不含代码);get=读代码;save=新建/更新;delete
|
|
2460
|
+
description: 'list=列全部(不含代码);get=读代码;save=新建/更新;delete=删除(不可逆,**必须二次确认**:先不带 confirm 调用拿预览,再带 confirm="<钩子的 name 或 id>" 重复调用才真删);approve=请用户批准代码(首次或改代码后);'
|
|
2410
2461
|
+ 'enable/disable=开关;run=拿一段正文试跑(不写记忆)。',
|
|
2411
2462
|
},
|
|
2412
2463
|
id: { type: 'string', description: '钩子 id(或唯一前缀 / 名字);get/delete/approve/enable/disable/run 必填' },
|
|
2464
|
+
confirm: { type: 'string', description: 'delete 专用二次确认:值必须等于目标钩子的 name 或完整 id。删除不可逆(hooks.json 直接覆盖、无回收站),不带或写错只返回待删预览、不会删除。' },
|
|
2413
2465
|
code: { type: 'string', description: '脚本源码(save 必填)。入口函数名与返回约定见技能 memory-hook-scripts。' },
|
|
2414
2466
|
phase: {
|
|
2415
2467
|
type: 'string',
|
|
@@ -2509,6 +2561,20 @@ export function memoryHooksTool(opts )
|
|
|
2509
2561
|
if (typeof service.deleteHook !== 'function') {
|
|
2510
2562
|
throw new MemoryToolError('HOOKS_UNSUPPORTED', '当前 memory provider 不支持记忆钩子')
|
|
2511
2563
|
}
|
|
2564
|
+
// 0.36.1:删除不可逆(hooks.json 硬覆盖、无回收站),必须二次确认。
|
|
2565
|
+
// 第一次调用不带 confirm → 只给"待删除"预览,不删;模型要把 name/id 回填到
|
|
2566
|
+
// confirm 再调一次才真删。确认值必须精确等于目标的 name 或 id,杜绝误删别的钩子。
|
|
2567
|
+
const confirmation = typeof args.confirm === 'string' ? args.confirm.trim() : ''
|
|
2568
|
+
const matches = confirmation !== '' && (confirmation === hook.name || confirmation === hook.id)
|
|
2569
|
+
if (!matches) {
|
|
2570
|
+
return {
|
|
2571
|
+
action,
|
|
2572
|
+
hooks: [withApproval(hook)],
|
|
2573
|
+
requiresConfirmation: true,
|
|
2574
|
+
removed: 0,
|
|
2575
|
+
note: `删除钩子「${hook.name}」是不可逆的(直接从 hooks.json 移除,没有回收站)。这是第一次确认:如确要删除,请用同样的 id 再调用一次并带上 confirm="${hook.name}"(或 confirm="${hook.id}");confirm 不符则不会删除。`,
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2512
2578
|
const deleted = service.deleteHook(hook.id)
|
|
2513
2579
|
return {
|
|
2514
2580
|
action,
|
|
@@ -2585,6 +2651,8 @@ export function memoryHooksTool(opts )
|
|
|
2585
2651
|
importance: 0.8,
|
|
2586
2652
|
},
|
|
2587
2653
|
tool: 'memory_hooks',
|
|
2654
|
+
// 0.37.0:试跑也带设置快照,脚本里读 ctx.settings.* 不会是 undefined。
|
|
2655
|
+
settings: { digestChars: 160, impressionChars: 120, recallChars: 300 },
|
|
2588
2656
|
}
|
|
2589
2657
|
const mine = service.runHookTrial(hook.id, input)
|
|
2590
2658
|
const verdict = mine[0]
|
package/lib/tools/render.js
CHANGED
|
@@ -142,7 +142,11 @@ export function renderListResult(value , label ) {
|
|
|
142
142
|
omitted += 1
|
|
143
143
|
return shortId(record.id)
|
|
144
144
|
}
|
|
145
|
-
|
|
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
|
@@ -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'`),可以据此分支:
|
|
@@ -137,6 +147,20 @@ function verify(memory, ctx) {
|
|
|
137
147
|
|
|
138
148
|
改代码之后要重新批准:审批记的是**代码指纹**,改一个字符就会重新变回待批准。
|
|
139
149
|
|
|
150
|
+
## 删除钩子要二次确认(不可逆)
|
|
151
|
+
|
|
152
|
+
`memory_hooks({ action: 'delete', id })` **不会一次删掉**——删除是从 `hooks.json` 直接移除、没有回收站,写好的代码找不回来(只能从会话日志里翻)。所以它分两步:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
1. memory_hooks({ action: 'delete', id: '<id>', description: '...' })
|
|
156
|
+
→ 返回 requiresConfirmation:true + 待删预览,此时**什么都没删**
|
|
157
|
+
2. 确认要删后,再调一次并带上 confirm:
|
|
158
|
+
memory_hooks({ action: 'delete', id: '<id>', confirm: '<钩子的 name 或完整 id>', description: '...' })
|
|
159
|
+
→ 才真正删除
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`confirm` 必须精确等于该钩子的 `name` 或完整 `id`,写错或省略只会再拿到一次预览,不会误删别的钩子。面板里的「删除」按钮同样有确认弹窗;**只是想让它停下就点「停用」**(代码保留、随时可再启用),别用删除。
|
|
163
|
+
|
|
140
164
|
## 常见错误
|
|
141
165
|
|
|
142
166
|
| 现象 | 原因 |
|