memory: fix extraction trigger, dedupe, and add runtime diagnostics

Four defects found by end-to-end testing, not by reading the code.

1. Extraction never ran, silently. Collecting every event type that
   ctx.event.subscribe actually delivers shows `session.idle` is NOT among
   them — it is defined in the protocol but never emitted on this stream.
   The subscription filtered on it alone, so auto-extraction was a permanent
   no-op with no error. Now debounced off events that do arrive
   (session.step.started / session.tool.called / session.inbox.delivered)
   after `settleMs` of quiet, which is what "idle" meant anyway. Verified:
   the trigger now fires and reports "轮数不足" for a 1-turn session.

2. Dedupe silently stopped rejecting duplicates. It compared against a fixed
   retrieval score, but that score carries idf and scope priors that drift as
   the corpus grows, so an obvious restatement of an existing memory scored
   0.48 against a 0.9 threshold and was written as a rival entry. Now uses
   term coverage of the candidate, which answers "is this already said?" and
   does not move with corpus size. Verified: a 100%-duplicate is rejected, a
   novel pitfall is kept.

3. Harness-injected user turns became the retrieval query. "<system-reminder>"
   and "The server restarted while you were working" are user-role messages,
   so the hook retrieved on them and injected memories chosen by noise. Both
   are filtered out now.

4. The `pinned` flag was absent from the remember tool's input schema, so the
   schema stripped it and pinning was unreachable from the tool surface.
   `kind` also ignored the rules/ category when a stale value was stored.

memory_inspect now reports runtime health for the two paths with no other
observable effect: last injection size and query, and last extraction outcome
with its reason. Without it, "working" and "silently dead" look identical —
which is exactly how defects 1 and 2 survived the first round of testing.
This commit is contained in:
2026-10-09 10:28:34 +08:00
parent a64ea2acb3
commit 92c612b94c
5 changed files with 242 additions and 39 deletions
+1 -1
View File
@@ -4,5 +4,5 @@
| 文件 | 概述 | 重点 |
|---|---|---|
| plugin-push-on-change.md | 改动这两个目录后立即 commit 并 push,不询问。 | ~/.config/opencode 本身就是 git 仓库,.gitignore 只放行 skills/ 和 plugins/ |
| plugin-push-on-change.md | 改动这三棵目录后立即 commit 并 push,不询问;改插件代码后必须重启服务。 | 本目录是 git 仓库;.gitignore 只放行 skills/ plugins/ memory/ 三棵树 |
<!-- auto:end
+7 -5
View File
@@ -1,17 +1,19 @@
---
id: rules/plugin-push-on-change.md
kind: rule
summary: 改动这两个目录后立即 commit 并 push,不询问。
highlight: ~/.config/opencode 本身就是 git 仓库,.gitignore 只放行 skills/ 和 plugins/
summary: 改动这三棵目录后立即 commit 并 push,不询问;改插件代码后必须重启服务。
highlight: 本目录是 git 仓库;.gitignore 只放行 skills/ plugins/ memory/ 三棵树
created: 1791512032262
updated: 1791512246723
updated: 1791512893909
pinned: true
---
`~/.config/opencode` 自身是 git 仓库,`.gitignore` 只放行 `skills/` 和 `plugins/`(外加 .gitignore、pwsh.cmd、package.json)。
`~/.config/opencode` 自身是 git 仓库,`.gitignore` 只放行三棵树:`skills/`、`plugins/`、`memory/`(外加 .gitignore、pwsh.cmd、package.json)。
在这两个目录下创建、修改、删除任何文件后,**提交并推送后再回复用户**,不要问是否要 push。
在这三棵树下创建、修改、删除任何文件后,**提交并推送后再回复用户**,不要问是否要 push。
推送用 SSH(origin 已是 SSH 地址)。HTTPS 推送会提示密码且无 TTY,必然失败。
推送失败就报错并停下,不要静默重试,也不要 `git reset`。提交信息要写清楚改了什么、为什么改。
**改完插件代码必须 `opencode service restart`**:热重载会应用新工具名,但已缓存的模块改动不一定生效。踩过两次「改了没生效」的坑。