open-memex 0.9.0-alpha.1 → 0.9.0-alpha.3
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/AGENTS.md +5 -2
- package/CHANGELOG.md +8 -0
- package/README.md +22 -4
- package/README.zh-CN.md +6 -3
- package/dist/.build-stamp +1 -1
- package/dist/cli.js +66 -4
- package/dist/doctor.js +2 -1
- package/dist/init.js +11 -4
- package/dist/mcp.js +18 -5
- package/dist/opencode-v2.js +1 -1
- package/dist/retrieve/inject.js +6 -0
- package/dist/retrieve/search.js +13 -2
- package/dist/reuse-report.js +64 -0
- package/dist/review.js +14 -0
- package/dist/store/db.js +19 -0
- package/dist/store/lifecycle.js +8 -0
- package/dist/store/usage.js +266 -0
- package/dist/tools/memory.js +12 -2
- package/dist/tools/ops.js +58 -3
- package/docs/V2-DESIGN.md +3 -1
- package/docs/design/decisions.md +1 -1
- package/package.json +1 -1
- package/scripts/smoke-mcp.ts +49 -4
- package/scripts/smoke-pure.ts +64 -0
- package/scripts/test-full.ts +194 -0
- package/skills/open-memex/SKILL.md +13 -0
- package/src/cli.ts +71 -4
- package/src/doctor.ts +2 -1
- package/src/init.ts +11 -4
- package/src/mcp.ts +24 -4
- package/src/opencode-v2.ts +2 -2
- package/src/retrieve/inject.ts +7 -0
- package/src/retrieve/search.ts +19 -3
- package/src/reuse-report.ts +119 -0
- package/src/review.ts +12 -0
- package/src/store/db.ts +20 -0
- package/src/store/lifecycle.ts +9 -0
- package/src/store/usage.ts +319 -0
- package/src/tools/memory.ts +14 -1
- package/src/tools/ops.ts +75 -3
package/AGENTS.md
CHANGED
|
@@ -12,7 +12,7 @@ via `prepublishOnly` — Node refuses `--experimental-strip-types` for files und
|
|
|
12
12
|
|
|
13
13
|
- **opencode host** loads `src/index.ts` under embedded **Bun**. SQLite here is `bun:sqlite` (built-in).
|
|
14
14
|
- **CLI** (`src/cli.ts`) and smoke tests run under **Node 22+** with `--experimental-strip-types`. SQLite here is `better-sqlite3` (native module).
|
|
15
|
-
- **MCP server** (`src/mcp.ts`, stdio) runs under **Node 22+** with `--experimental-strip-types`. It exposes the same
|
|
15
|
+
- **MCP server** (`src/mcp.ts`, stdio) runs under **Node 22+** with `--experimental-strip-types`. It exposes the same thirteen memory tools to any MCP client (VS Code Copilot, Cursor, Claude Code). **stdout is the protocol channel — never log to stdout in `mcp.ts`; diagnostics go to stderr.**
|
|
16
16
|
|
|
17
17
|
`src/store/db.ts` picks the backend at runtime by sniffing `globalThis.Bun`. Both backends share the same surface (`new Database(path)`, `.exec`, `.prepare().run/all/get`, `.close`). Any DB code you write must stay on that common subset — do not import `better-sqlite3` or `bun:sqlite` directly outside `db.ts`. The Node driver is pinned to the `better-sqlite3` 13 N-API line (D72): the pre-13 `node::ObjectWrap` build aborts intermittently on Node 24.19+ when a prepared statement is finalized by GC.
|
|
18
18
|
|
|
@@ -33,8 +33,9 @@ Consequences:
|
|
|
33
33
|
npm install # once
|
|
34
34
|
npm run typecheck # tsc --noEmit — the only lint/type gate
|
|
35
35
|
npm run cli -- where | list | search "q" | add ... | forget <id> | reindex
|
|
36
|
+
npm run cli -- useful <id...> # D77-L2: explicit useful signal + cumulative counters
|
|
36
37
|
npm run cli -- <command> --help # per-command help (AI assistants discover flags this way)
|
|
37
|
-
npm run cli -- sync-status # last sync time/kind + outbox drafts + repo review states + uncommitted files
|
|
38
|
+
npm run cli -- sync-status # last sync time/kind + outbox drafts + repo review states + uncommitted files + D77 reuse report
|
|
38
39
|
npm run cli -- inventory [--format text|json|html] [--scope both] # what is remembered, in the open (D68); personal-bearing output refused inside a git worktree without --allow-personal
|
|
39
40
|
npm run cli -- audit [--scope project|personal|both] # memory health: near-dup pairs, stale actives, broken chains, personal-in-repo, expired working-state notes (read-only)
|
|
40
41
|
npm run cli -- wstate [--clear] # show/clear the session working-state note (D89 §3.6; the file it prints is editable directly)
|
|
@@ -125,6 +126,8 @@ Layout: `memories/<scope_key>/<id>.md` (YAML frontmatter + body) + `index.db` (S
|
|
|
125
126
|
|
|
126
127
|
**Markdown files are the source of truth; `index.db` is rebuildable.** `syncScope()` (in `src/store/sync.ts`) reconciles the two by mtime on plugin load and before every CLI read. When adding new frontmatter fields, update `Frontmatter` in `src/store/markdown.ts`, the `memories` table in `src/store/db.ts`, and `upsertFromFile` in `src/store/sync.ts` together, and bump the reindex path.
|
|
127
128
|
|
|
129
|
+
D77-L2 counters are the one deliberate exception: `memory_usage` (in `index.db`, owned by `src/store/usage.ts`) holds `retrieved_count` / `useful_self` / `useful_team` keyed by memory id, is created with `CREATE TABLE IF NOT EXISTS` outside the versioned schema, and is NOT dropped by `rebuildIndexSchema` — accumulated telemetry has no Markdown source to rebuild from. They never go into frontmatter and never leave the machine. Only `memory_useful` (explicit), a human approve at review, and a supersede raise the useful side; passive retrieval (search/list/injection, opt-in via `record: true`) raises only `retrieved_count` — never "fix" this by counting exposure as useful. D77-L3's report (`loadReuseReport` in usage.ts, pure rendering in `src/reuse-report.ts`) rides `memory_status` / `cli sync-status`: per-scope rates with the useful split shown separately (self vs team, per D77), top reused, zombies (retrieved, never useful; retracted/archived excluded from both lists), and a lifecycle tag on superseded/deprecated entries so historical reuse never reads as current guidance.
|
|
130
|
+
|
|
128
131
|
## Scope keys
|
|
129
132
|
|
|
130
133
|
- `personal` scope key is literal `"personal"` (v1 called this `user`; renamed in v2, design §19).
|
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,14 @@ the `@alpha` tag are development snapshots and are not listed individually.
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [0.9.0-alpha.3] - 2026-11-04
|
|
13
|
+
|
|
14
|
+
- D77-L3: the reuse report — D77's third and final layer. `memory_status` (MCP) and `open-memex sync-status` now end with a **Reuse (D77)** block built from the `memory_usage` counters: per-scope `retrieved` / `useful` rates (personal + this project) with the **useful split shown separately** (`self` vs `team`, as D77 requires — the combined total drives the rate), the **top reused** memories, and **zombies** — retrieved at least once, never confirmed useful, i.e. the decay/prune candidates. Superseded/deprecated entries stay in the lists (their reuse was real) but carry a lifecycle tag like `[superseded]`, so historical data never reads to the agent as current guidance (a supersede itself ticks the old memory). The agent-facing tool result caps each list (cut disclosed, pointing at the CLI); the CLI prints them uncapped. Retracted/archived memories are excluded from both lists but still count toward the scope totals; an empty store gets an honest "no data yet" line instead of a silent section. Rendering is pure (`src/reuse-report.ts`, smoke-tested without SQLite); collection is one join query in `loadReuseReport`. The counters themselves stay local-only SQLite telemetry (D77).
|
|
15
|
+
|
|
16
|
+
## [0.9.0-alpha.2] - 2026-11-03
|
|
17
|
+
|
|
18
|
+
- D77-L2: measure usefulness by reuse (the D77 counters, layer 2). Each memory now carries local counters in a `memory_usage` table beside the rebuildable index (D77: counters live in SQLite, never in frontmatter, never off the machine): `retrieved_count` — incremented when a memory is actually returned by `memory_search`, `memory_list`, the CLI `search`/`list`, or the session-start injection — and the useful split, `useful_self` (personal memories and unpublished project drafts) vs `useful_team` (approved/published project memories). Only explicit signals raise the useful side: the new **`memory_useful`** tool (thirteenth MCP tool, seventh on the opencode plugin; also `open-memex useful <id...>`), a human approve at review (`promote` to approved, or the `--local-approve` propose shortcut), and a supersede (recorded even when the index row is momentarily missing — the Markdown file is the source of truth). Passive exposure never counts as useful — the tool description, MCP handshake, READMEs, skill, and AGENTS.md all state the restraint so an agent that reads only one still behaves. `memory_usage` is created with `CREATE TABLE IF NOT EXISTS` outside the versioned schema and survives `rebuildIndexSchema` (ids come from the files); hard forget prunes the row, branch-switch removals do not. `memory_useful` returns counts plus `reuse_rate` (useful / retrieved, `n/a` when never retrieved). The D77-L3 reuse report (top reused, zero-reuse zombies, per-scope rates) remains open.
|
|
19
|
+
|
|
12
20
|
## [0.9.0-alpha.1] - 2026-11-03
|
|
13
21
|
|
|
14
22
|
- Session working-state note (D89 → D90, new minor line): one ephemeral per-project Markdown note for resuming an interrupted task — task summary, open files, last commands, where the work stands, next step. The agent writes it at wrap-up via the new **`memory_workingstate`** tool (now the **twelve** tools on both the opencode plugin and the MCP server), it surfaces once at session start next to the first-turn injection (framed as scratch, never knowledge), it never enters `memories/` or the retrieval index or the review ladder, and anything in it worth keeping goes through the normal propose-first flow. TTL defaults to 7 days (`workingStateTtlDays`; `workingStateEnabled` gates the whole feature — both flat keys, settable via `config set`). Expired notes stay silent at session start and are reported by `open-memex audit`; `open-memex wstate` (`--clear`) is the human surface. The write passes through `redact()` and `atomicWriteTextSync` like every path. One correction to D89's wording, recorded as D90: the opencode plugin API has no Stop hook, so the opencode write path is the instruction + tool branch (the agent refreshes the note when the user signals wrap-up); Claude Code's Stop hook waits for the Phase 2C native plugin.
|
package/README.md
CHANGED
|
@@ -444,8 +444,8 @@ If a secret slips through anyway, `open-memex forget <id>` deletes the memory.
|
|
|
444
444
|
|
|
445
445
|
## Tools the agent gets
|
|
446
446
|
|
|
447
|
-
The MCP server exposes
|
|
448
|
-
|
|
447
|
+
The MCP server exposes thirteen tools; the opencode native plugin exposes the
|
|
448
|
+
seven core ones (marked ●). The other six are the team-review workflow tools —
|
|
449
449
|
they only matter once you share memories through Git.
|
|
450
450
|
|
|
451
451
|
| Tool | What it does |
|
|
@@ -456,7 +456,8 @@ they only matter once you share memories through Git.
|
|
|
456
456
|
| ● `memory_supersede` | Replace a memory with a newer version (keeps a supersede chain) |
|
|
457
457
|
| ● `memory_forget` | Delete a memory by id (`soft=true` hides it instead — retracted, one-way) |
|
|
458
458
|
| ● `memory_workingstate` | Read/write/clear the per-project working-state note (§3.6, D89) — resumes an interrupted task; scratch state, never a memory |
|
|
459
|
-
| `
|
|
459
|
+
| ● `memory_useful` | Mark a memory as useful (D77) — explicit confirmation only; exposure is counted separately as `retrieved_count` |
|
|
460
|
+
| `memory_status` | Show the sync queue (outbox drafts, repo review states, uncommitted files) plus the D77 reuse report |
|
|
460
461
|
| `memory_submit` | Move named drafts into the repo memory dir (local branch + commit) |
|
|
461
462
|
| `memory_propose` | Copy personal memories into the project scope as review candidates |
|
|
462
463
|
| `memory_promote` | Advance `proposed → approved → published` (or reject / resubmit) |
|
|
@@ -467,6 +468,23 @@ So an MCP-connected editor always has the full set; opencode's plugin covers
|
|
|
467
468
|
capture and recall, and anything workflow-shaped goes through the CLI or an
|
|
468
469
|
MCP-connected editor.
|
|
469
470
|
|
|
471
|
+
**Usefulness is measured by reuse, not storage (D77).** Every memory carries
|
|
472
|
+
local counters: `retrieved_count` — how often it was actually handed to the
|
|
473
|
+
agent (search results, lists, the session-start injection) — and useful
|
|
474
|
+
counts, split into `useful_self` (personal memories, unpublished project
|
|
475
|
+
drafts) and `useful_team` (approved/published project memories). Only
|
|
476
|
+
explicit signals raise the useful side: `memory_useful` when a person
|
|
477
|
+
confirms it paid off, a human approval at review, or a supersede. Passive
|
|
478
|
+
exposure never counts as useful — a memory that merely showed up in results
|
|
479
|
+
has shown nothing yet. Same-side CLI surface: `open-memex useful <id...>`.
|
|
480
|
+
Counters live in the local SQLite index only (never in the Markdown files,
|
|
481
|
+
never off this machine). The report rides `memory_status` (and
|
|
482
|
+
`open-memex sync-status`): per-scope retrieved/useful rates with the self/team
|
|
483
|
+
split shown separately, the most-reused memories, and the "zombies" —
|
|
484
|
+
retrieved but never confirmed useful, i.e. the decay/prune candidates
|
|
485
|
+
(D77-L3). Superseded/deprecated entries stay visible as reuse history but
|
|
486
|
+
carry a lifecycle tag, never presented as current guidance.
|
|
487
|
+
|
|
470
488
|
## Memory types
|
|
471
489
|
|
|
472
490
|
Every memory has a `type` (what it is) and `tags` (what it's about). Eleven
|
|
@@ -950,7 +968,7 @@ config: if it has comments, add the `"plugin"` line manually.
|
|
|
950
968
|
Checks the Node version, config source, scope resolution for the current
|
|
951
969
|
directory, and storage writability; verifies VS Code hasn't disabled MCP;
|
|
952
970
|
then boots a real MCP server and runs `initialize` + `tools/list` against
|
|
953
|
-
it — all
|
|
971
|
+
it — all thirteen tools must show up. It also reports pre-rename `my-o-memory`
|
|
954
972
|
leftovers if any editor config still references the old package name.
|
|
955
973
|
|
|
956
974
|
## FAQ
|
package/README.zh-CN.md
CHANGED
|
@@ -286,7 +286,7 @@ open-memex capture --dry-run "…"
|
|
|
286
286
|
|
|
287
287
|
## 助手拿到的工具
|
|
288
288
|
|
|
289
|
-
MCP
|
|
289
|
+
MCP 服务器暴露十三个工具;opencode 原生插件暴露其中七个核心的(标 ●)。另外六个是团队评审工作流工具——只有当你通过 Git 共享记忆时才用得上。
|
|
290
290
|
|
|
291
291
|
| 工具 | 做什么 |
|
|
292
292
|
|---|---|
|
|
@@ -296,7 +296,8 @@ MCP 服务器暴露十二个工具;opencode 原生插件暴露其中六个核
|
|
|
296
296
|
| ● `memory_supersede` | 用新版本替换一条记忆(保留 supersede 链) |
|
|
297
297
|
| ● `memory_forget` | 按 id 删除一条记忆(`soft=true` 改为隐藏——retracted,单向) |
|
|
298
298
|
| ● `memory_workingstate` | 读/写/清除每项目的工作状态笔记(§3.6,D89)——让被中断的任务得以续接;只是草稿状态,永远不会成为记忆 |
|
|
299
|
-
| `
|
|
299
|
+
| ● `memory_useful` | 确认一条记忆有用(D77)——只认显式确认;被动的搜索/列表出现只计入 `retrieved_count`,绝不算有用 |
|
|
300
|
+
| `memory_status` | 显示同步队列(outbox 草稿、仓库评审状态、未提交文件),并附带 D77 复用报告 |
|
|
300
301
|
| `memory_submit` | 把指定的草稿移进仓库记忆目录(本地分支 + 提交) |
|
|
301
302
|
| `memory_propose` | 把个人记忆复制到项目作用域,作为评审候选 |
|
|
302
303
|
| `memory_promote` | 推进 `proposed → approved → published`(或拒绝 / 重新提交) |
|
|
@@ -305,6 +306,8 @@ MCP 服务器暴露十二个工具;opencode 原生插件暴露其中六个核
|
|
|
305
306
|
|
|
306
307
|
所以 MCP 接入的编辑器永远是全套;opencode 插件主攻捕获与回想,工作流类的事走 CLI 或 MCP 接入的编辑器。
|
|
307
308
|
|
|
309
|
+
**有用性靠复用来衡量,不靠存储量(D77)。** 每条记忆带本地计数器:`retrieved_count`——它真正被递交给助手的次数(搜索结果、清单、会话开始注入);有用计数则拆成 `useful_self`(个人记忆、未评审的项目草稿)和 `useful_team`(approved/published 的项目记忆)。只有显式信号会抬升有用侧:`memory_useful`(人确认它帮上忙时)、评审中的人为 approve、或一次 supersede。被动曝光永远不算有用——记忆只是出现在结果里,还不能说明任何事。同侧的人用入口:`open-memex useful <id...>`。计数器只存在本地 SQLite 索引里(不进 Markdown 文件、不出这台机器)。复用报告挂在 `memory_status`(以及 `open-memex sync-status`)上:各作用域的 retrieved/useful 比率(self/team 分开显示)、复用最多的记忆,以及"僵尸"——被检索过却从未被确认有用、即衰减/清理候选项(D77-L3)。superseded/deprecated 的记忆仍作为复用历史出现,但带生命周期标记,不会被当成当前指引。
|
|
310
|
+
|
|
308
311
|
## 记忆类型
|
|
309
312
|
|
|
310
313
|
每条记忆有一个 `type`(它是什么)和 `tags`(它关于什么)。内置十一种类型:
|
|
@@ -618,7 +621,7 @@ Windows 上已加载的 DLL 是锁定的:如果 open-memex 的 MCP 服务器
|
|
|
618
621
|
你的编辑器配置里有注释(JSONC)或 JSON 不合法,open-memex 永不重写它无法安全解析的文件。`init` 已经把要加的确切片段打印出来了——手动粘贴进去就好。opencode 配置同理:有注释时,手动把 `"plugin"` 那一行加上。
|
|
619
622
|
|
|
620
623
|
**感觉有问题——跑 `open-memex doctor`。**
|
|
621
|
-
它检查 Node 版本、配置来源、当前目录的作用域解析、存储可写性,并确认 VS Code 没有把 MCP 禁用;然后启动一个真实 MCP 服务器,对它跑 `initialize` + `tools/list
|
|
624
|
+
它检查 Node 版本、配置来源、当前目录的作用域解析、存储可写性,并确认 VS Code 没有把 MCP 禁用;然后启动一个真实 MCP 服务器,对它跑 `initialize` + `tools/list`——十三个工具必须全部出现。它还会报告改名之前遗留的 `my-o-memory` 引用(如果某编辑器配置里还留着旧包名的话)。
|
|
622
625
|
|
|
623
626
|
## 常见问题
|
|
624
627
|
|
package/dist/.build-stamp
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
507da63044e3c491b1ec5b7f077ccfbc492c986775ce97b77f172e5395fccca3
|
package/dist/cli.js
CHANGED
|
@@ -10,6 +10,8 @@ import { proposeMemories, promoteMemory, listConflicts, resolveConflict, formatR
|
|
|
10
10
|
import { getSyncStatus, formatSyncStatus, submitMemories } from "./submit.js";
|
|
11
11
|
import { getPrStatus, formatPrStatus, applyPrStatus } from "./github.js";
|
|
12
12
|
import { search, list, countList, hitStateLabel } from "./retrieve/search.js";
|
|
13
|
+
import { recordUseful, getUsage, reuseRate, usefulCount, usefulKindFor, deleteUsage, loadReuseReport } from "./store/usage.js";
|
|
14
|
+
import { formatReuseReport } from "./reuse-report.js";
|
|
13
15
|
import { DEFAULT_EXPANSIONS_WEIGHT } from "./retrieve/weights.js";
|
|
14
16
|
import { formatInventoryLine, truncationNote } from "./retrieve/display.js";
|
|
15
17
|
import { writeMemoryFile, readMemoryFile, ulid, msToRfc3339, normalizeAliases, } from "./store/markdown.js";
|
|
@@ -144,6 +146,17 @@ Retraction is one-way: a retracted memory cannot be set back to active
|
|
|
144
146
|
|
|
145
147
|
Example:
|
|
146
148
|
open-memex status 01ABC deprecated`,
|
|
149
|
+
useful: `Mark a memory as useful (D77): record that it demonstrably paid
|
|
150
|
+
off. Useful is split automatically — useful_self for personal memories and
|
|
151
|
+
unpublished project drafts, useful_team for approved/published project
|
|
152
|
+
memories. Only explicit confirmation counts; passive retrieval (search/
|
|
153
|
+
list/injection) is counted separately as retrieved_count, never as useful.
|
|
154
|
+
A supersede or a human approval also records a useful signal on its own.
|
|
155
|
+
|
|
156
|
+
Usage: open-memex useful <id...>
|
|
157
|
+
|
|
158
|
+
Example:
|
|
159
|
+
open-memex useful 01ABC`,
|
|
147
160
|
forget: `Delete a memory by id. With --soft, hide it instead: the memory
|
|
148
161
|
is retracted (out of lists and search, file kept). Retraction is one-way —
|
|
149
162
|
save the content as a new memory to bring it back. If the memory lives in
|
|
@@ -194,7 +207,9 @@ Examples:
|
|
|
194
207
|
open-memex resolve 01ABC`,
|
|
195
208
|
"sync-status": `Show the project memory sync pipeline: when the index last synced
|
|
196
209
|
and what triggered it, drafts waiting in the outbox (appdata), memories in the
|
|
197
|
-
repo awaiting review or published, and repo files not yet committed.
|
|
210
|
+
repo awaiting review or published, and repo files not yet committed. The
|
|
211
|
+
D77 reuse report follows: per-scope retrieved/useful rates, most-reused
|
|
212
|
+
memories, and "zombies" (retrieved but never confirmed useful).
|
|
198
213
|
|
|
199
214
|
Usage: open-memex sync-status
|
|
200
215
|
|
|
@@ -388,7 +403,7 @@ Example:
|
|
|
388
403
|
doctor: `Environment health check: Node version, config source, scope resolution,
|
|
389
404
|
storage writability, VS Code MCP enablement (settings.json + system policy),
|
|
390
405
|
then boots a real MCP server and runs initialize + tools/list against it —
|
|
391
|
-
all
|
|
406
|
+
all thirteen tools must show up.
|
|
392
407
|
|
|
393
408
|
Usage: open-memex doctor
|
|
394
409
|
|
|
@@ -429,6 +444,7 @@ Usage:
|
|
|
429
444
|
open-memex add "content" [--scope project|personal] [--type T] [--tag t1,t2]
|
|
430
445
|
open-memex supersede <id> "new content" [--type T] [--tag t1,t2]
|
|
431
446
|
open-memex status <id> active|deprecated|retracted|archived
|
|
447
|
+
open-memex useful <id...>
|
|
432
448
|
open-memex forget <id> [--soft]
|
|
433
449
|
open-memex propose <id...> --to project [--local-approve]
|
|
434
450
|
open-memex promote <id> [--reject] [--resubmit] [--note "..."] [--by NAME]
|
|
@@ -477,8 +493,8 @@ first-turn injection); \`--yes\` accepts all defaults, and non-terminal runs nev
|
|
|
477
493
|
\`open-memex config set <key> <value>\` changes those settings after install.
|
|
478
494
|
|
|
479
495
|
Once installed globally (\`npm i -g open-memex\`) the \`open-memex\` command is
|
|
480
|
-
available directly: \`open-memex mcp\` starts the stdio MCP server (
|
|
481
|
-
the opencode plugin's
|
|
496
|
+
available directly: \`open-memex mcp\` starts the stdio MCP server (13 tools, a superset of
|
|
497
|
+
the opencode plugin's seven memory_* tools); \`open-memex mcp --print-config <client>\`
|
|
482
498
|
prints a copy-paste MCP client config snippet.
|
|
483
499
|
|
|
484
500
|
Scope defaults to \`project\` (derived from cwd's git remote or path).
|
|
@@ -917,6 +933,7 @@ async function main() {
|
|
|
917
933
|
type: flags.type,
|
|
918
934
|
limit: flags.limit ? Number(flags.limit) : undefined,
|
|
919
935
|
include,
|
|
936
|
+
record: true,
|
|
920
937
|
});
|
|
921
938
|
const total = countList(s.key, { type: flags.type, include });
|
|
922
939
|
if (scopes.length > 1) {
|
|
@@ -960,6 +977,7 @@ async function main() {
|
|
|
960
977
|
limit: flags.limit ? Number(flags.limit) : undefined,
|
|
961
978
|
type: flags.type,
|
|
962
979
|
stats,
|
|
980
|
+
record: true,
|
|
963
981
|
});
|
|
964
982
|
if (explain && stats) {
|
|
965
983
|
console.log(`fts: ${stats.ftsQuery || "(empty query)"}`);
|
|
@@ -1168,9 +1186,43 @@ async function main() {
|
|
|
1168
1186
|
}
|
|
1169
1187
|
}
|
|
1170
1188
|
deleteFromIndex(id);
|
|
1189
|
+
// D77-L2: hard forget prunes the usage row with the memory (the tool
|
|
1190
|
+
// path does the same); branch-switch removals go through syncScope and
|
|
1191
|
+
// keep counters for that reason.
|
|
1192
|
+
deleteUsage(id);
|
|
1171
1193
|
console.log(`deleted ${id}`);
|
|
1172
1194
|
return;
|
|
1173
1195
|
}
|
|
1196
|
+
if (cmd === "useful") {
|
|
1197
|
+
// D77-L2: the explicit confirmation route for humans. Auto-split like
|
|
1198
|
+
// the memory_useful tool; unknown ids fail that id without touching
|
|
1199
|
+
// the rest of the batch.
|
|
1200
|
+
const ids = rest;
|
|
1201
|
+
if (ids.length === 0)
|
|
1202
|
+
usage();
|
|
1203
|
+
syncScope(project.key, "cli");
|
|
1204
|
+
syncScope(PERSONAL_SCOPE.key, "cli");
|
|
1205
|
+
let notFound = 0;
|
|
1206
|
+
for (const id of ids) {
|
|
1207
|
+
const row = db()
|
|
1208
|
+
.prepare(`SELECT scope, review_state FROM memories WHERE id = ?`)
|
|
1209
|
+
.get(id);
|
|
1210
|
+
if (!row) {
|
|
1211
|
+
console.error(`not found: ${id}`);
|
|
1212
|
+
notFound++;
|
|
1213
|
+
continue;
|
|
1214
|
+
}
|
|
1215
|
+
const kind = usefulKindFor(row.scope, row.review_state);
|
|
1216
|
+
recordUseful(id, kind, "tool");
|
|
1217
|
+
const u = getUsage(id);
|
|
1218
|
+
const rate = reuseRate(u);
|
|
1219
|
+
const useful = usefulCount(u);
|
|
1220
|
+
console.log(`useful (${kind}) ${id} — retrieved: ${u.retrieved_count}, useful_self: ${u.useful_self}, useful_team: ${u.useful_team}, reuse_rate: ${rate === null ? "n/a" : rate.toFixed(2)} (useful ${useful}/${u.retrieved_count})`);
|
|
1221
|
+
}
|
|
1222
|
+
if (notFound > 0)
|
|
1223
|
+
process.exit(1);
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1174
1226
|
/** Positional args with flags (and their values) skipped. */
|
|
1175
1227
|
function positionalArgs(argv) {
|
|
1176
1228
|
const out = [];
|
|
@@ -1351,6 +1403,16 @@ async function main() {
|
|
|
1351
1403
|
syncScope(PERSONAL_SCOPE.key, "cli");
|
|
1352
1404
|
try {
|
|
1353
1405
|
console.log(formatSyncStatus(getSyncStatus(), { cap: Number.POSITIVE_INFINITY }));
|
|
1406
|
+
// D77-L3: same reuse block as the memory_status tool, uncapped (a
|
|
1407
|
+
// human asked; the CLI is where the full list lives).
|
|
1408
|
+
const reuse = loadReuseReport([
|
|
1409
|
+
{ scopeKey: project.key, label: "this project" },
|
|
1410
|
+
{ scopeKey: PERSONAL_SCOPE.key, label: "personal" },
|
|
1411
|
+
], { topLimit: Number.POSITIVE_INFINITY, zombieLimit: Number.POSITIVE_INFINITY });
|
|
1412
|
+
console.log("");
|
|
1413
|
+
for (const line of formatReuseReport(reuse, { entryCap: Number.POSITIVE_INFINITY })) {
|
|
1414
|
+
console.log(line);
|
|
1415
|
+
}
|
|
1354
1416
|
}
|
|
1355
1417
|
catch (e) {
|
|
1356
1418
|
console.error(`sync-status failed: ${e.message}`);
|
package/dist/doctor.js
CHANGED
|
@@ -13,7 +13,7 @@ import { resolveCwdScope } from "./scope.js";
|
|
|
13
13
|
import { MIN_NODE_VERSION, nativeDriverFloorMessage, nodeSupportsNativeDriver, } from "./runtime-floor.js";
|
|
14
14
|
import { db, backendName } from "./store/db.js";
|
|
15
15
|
import { LEGACY_PACKAGE_NAME, opencodeGlobalConfigPath, userMcpConfigPath } from "./init.js";
|
|
16
|
-
// D64: the MCP server exposes
|
|
16
|
+
// D64: the MCP server exposes thirteen tools; checking only the seven the
|
|
17
17
|
// opencode plugin carries let a half-registered server pass as healthy.
|
|
18
18
|
const EXPECTED_TOOLS = [
|
|
19
19
|
"memory_add",
|
|
@@ -21,6 +21,7 @@ const EXPECTED_TOOLS = [
|
|
|
21
21
|
"memory_list",
|
|
22
22
|
"memory_supersede",
|
|
23
23
|
"memory_forget",
|
|
24
|
+
"memory_useful",
|
|
24
25
|
"memory_workingstate",
|
|
25
26
|
"memory_status",
|
|
26
27
|
"memory_submit",
|
package/dist/init.js
CHANGED
|
@@ -51,9 +51,9 @@ const INSTRUCTIONS = `${MARKER}
|
|
|
51
51
|
|
|
52
52
|
You have a local memory MCP server (\`open-memex\`). Its tools are
|
|
53
53
|
\`memory_add\`, \`memory_search\`, \`memory_list\`, \`memory_supersede\`,
|
|
54
|
-
\`memory_forget\`, \`
|
|
55
|
-
\`memory_propose\`, \`memory_promote\`, \`memory_resolve\`,
|
|
56
|
-
always call them by these full names.
|
|
54
|
+
\`memory_forget\`, \`memory_useful\`, \`memory_workingstate\`, \`memory_status\`,
|
|
55
|
+
\`memory_submit\`, \`memory_propose\`, \`memory_promote\`, \`memory_resolve\`,
|
|
56
|
+
\`memory_pr_status\` — always call them by these full names.
|
|
57
57
|
|
|
58
58
|
- The server tells you when project outbox drafts are waiting for review — in
|
|
59
59
|
tool results. When it does (or when the user asks), call \`memory_status\`
|
|
@@ -90,6 +90,11 @@ always call them by these full names.
|
|
|
90
90
|
note — task summary, open files, last commands, where the work stands, next
|
|
91
91
|
step — so an interrupted task can resume in a fresh session. It is scratch
|
|
92
92
|
state, not durable knowledge: never save it as a memory.
|
|
93
|
+
- When a person confirms a memory was useful, or accepts work that clearly
|
|
94
|
+
relied on one, call \`memory_useful\` on it. NEVER call it just because a
|
|
95
|
+
memory appeared in search results or the session-start block: passive
|
|
96
|
+
exposure is counted separately and never counts as useful. Superseding a
|
|
97
|
+
memory or approving it at review already records its useful signal.
|
|
93
98
|
|
|
94
99
|
## Syncing project memories for review (D26)
|
|
95
100
|
|
|
@@ -102,7 +107,9 @@ yet. Syncing them into the repo for review is an explicit, user-approved step:
|
|
|
102
107
|
- When the user says "sync memory" (or "同步记忆"), run the sync
|
|
103
108
|
flow above: call \`memory_status\`, summarize the outbox drafts, and ask which
|
|
104
109
|
ones to sync. ALWAYS use the \`memory_status\` tool for this — never browse
|
|
105
|
-
the memory data directory directly.
|
|
110
|
+
the memory data directory directly. That tool also carries the D77 reuse
|
|
111
|
+
report (per-scope rates, most-reused memories, and "zombies"): surface it
|
|
112
|
+
when the user asks what memory is actually being reused.
|
|
106
113
|
- When the user approves, call \`memory_submit\` with the approved ids. It
|
|
107
114
|
copies the drafts into the current project's \`.ai/open-memex/\` directory as
|
|
108
115
|
\`proposed\` and commits locally on the CURRENT branch. It NEVER creates a
|
package/dist/mcp.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Exposes the memory tools as the opencode plugin
|
|
5
5
|
* (memory_add / memory_search / memory_list / memory_supersede /
|
|
6
|
-
* memory_forget, plus memory_workingstate + memory_status /
|
|
7
|
-
* memory_propose / memory_promote / memory_resolve /
|
|
6
|
+
* memory_forget, plus memory_useful + memory_workingstate + memory_status /
|
|
7
|
+
* memory_submit / memory_propose / memory_promote / memory_resolve /
|
|
8
|
+
* memory_pr_status)
|
|
8
9
|
* over the Model Context Protocol, so any MCP client —
|
|
9
10
|
* VS Code Copilot Chat, Cursor, Claude Code, etc. — can use open-memex
|
|
10
11
|
* without a host-specific plugin.
|
|
@@ -29,7 +30,7 @@ import { loadConfig } from "./config.js";
|
|
|
29
30
|
import { resolveProjectScope, PERSONAL_SCOPE } from "./scope.js";
|
|
30
31
|
import { db } from "./store/db.js";
|
|
31
32
|
import { syncScope } from "./store/sync.js";
|
|
32
|
-
import { addMemory, searchMemories, listMemories, supersedeMemory, forgetMemory, statusMemories, submitMemoriesOp, proposeMemoriesOp, promoteMemoryOp, resolveMemoryOp, prStatusOp, workingStateMemory, memoryAddArgs, memorySearchArgs, memoryListArgs, memorySupersedeArgs, memoryForgetArgs, memoryStatusArgs, memorySubmitArgs, memoryProposeArgs, memoryPromoteArgs, memoryResolveArgs, memoryPrStatusArgs, memoryWorkingStateArgs, TOOL_DESCRIPTIONS, withOutboxNote, } from "./tools/ops.js";
|
|
33
|
+
import { addMemory, searchMemories, listMemories, supersedeMemory, forgetMemory, markMemoryUseful, statusMemories, submitMemoriesOp, proposeMemoriesOp, promoteMemoryOp, resolveMemoryOp, prStatusOp, workingStateMemory, memoryAddArgs, memorySearchArgs, memoryListArgs, memorySupersedeArgs, memoryForgetArgs, memoryStatusArgs, memorySubmitArgs, memoryProposeArgs, memoryPromoteArgs, memoryResolveArgs, memoryPrStatusArgs, memoryWorkingStateArgs, memoryUsefulArgs, TOOL_DESCRIPTIONS, withOutboxNote, } from "./tools/ops.js";
|
|
33
34
|
import { outboxDraftCount } from "./submit.js";
|
|
34
35
|
// Server version tracks package.json — never hardcode it here again.
|
|
35
36
|
// package.json sits two levels above this file in both layouts
|
|
@@ -53,7 +54,7 @@ const SERVER_VERSION = (() => {
|
|
|
53
54
|
*/
|
|
54
55
|
const SERVER_INSTRUCTIONS = `You are connected to an open-memex local memory MCP server.
|
|
55
56
|
Its tools are memory_add, memory_search, memory_list, memory_supersede,
|
|
56
|
-
memory_forget, memory_workingstate, memory_status, memory_submit,
|
|
57
|
+
memory_forget, memory_useful, memory_workingstate, memory_status, memory_submit,
|
|
57
58
|
memory_propose, memory_promote, memory_resolve, memory_pr_status — always call
|
|
58
59
|
them by these full names.
|
|
59
60
|
|
|
@@ -66,7 +67,9 @@ them by these full names.
|
|
|
66
67
|
- When the user says "sync memory" (or "同步记忆"), call memory_status,
|
|
67
68
|
summarize the outbox drafts (one line each), and ask which ones to sync.
|
|
68
69
|
ALWAYS use the memory_status tool for this — never browse the memory data
|
|
69
|
-
directory directly.
|
|
70
|
+
directory directly. memory_status also carries the D77 reuse report
|
|
71
|
+
(per-scope rates, most-reused, and never-used-but-retrieved "zombies") —
|
|
72
|
+
surface it when the user asks what memory is actually being reused.
|
|
70
73
|
- After memory_submit, ask ONE follow-up: "want me to create a branch + push +
|
|
71
74
|
open the PR, or will you handle it yourself?" NEVER create branches, push, or
|
|
72
75
|
open PRs without the user's explicit approval. A "yes, you do it" covers the
|
|
@@ -109,6 +112,11 @@ them by these full names.
|
|
|
109
112
|
files, last commands, where the work stands, next step — so an interrupted
|
|
110
113
|
task can resume. It is scratch state, not knowledge: do not save it as a
|
|
111
114
|
memory; durable conclusions still follow the propose-first flow above.
|
|
115
|
+
- When a person confirms a memory was useful, or accepted work that clearly
|
|
116
|
+
relied on one, call memory_useful on it. NEVER call memory_useful just
|
|
117
|
+
because a memory appeared in results or the session-start block — passive
|
|
118
|
+
exposure never counts as useful. (Superseding or approving a memory also
|
|
119
|
+
auto-records its useful signal; no need to duplicate those.)
|
|
112
120
|
`;
|
|
113
121
|
/** Adapt a framework-agnostic op result to an MCP tool response. */
|
|
114
122
|
function toMcp(p) {
|
|
@@ -193,6 +201,11 @@ export async function runMcpServer() {
|
|
|
193
201
|
inputSchema: z.object(memoryForgetArgs),
|
|
194
202
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false },
|
|
195
203
|
}, withSync((args) => toMcp(withOutboxNote(getScope().key, forgetMemory(args), "call memory_status to review"))));
|
|
204
|
+
server.registerTool("memory_useful", {
|
|
205
|
+
description: TOOL_DESCRIPTIONS.memory_useful,
|
|
206
|
+
inputSchema: z.object(memoryUsefulArgs),
|
|
207
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false },
|
|
208
|
+
}, withSync((args) => toMcp(markMemoryUseful(args))));
|
|
196
209
|
server.registerTool("memory_status", {
|
|
197
210
|
description: TOOL_DESCRIPTIONS.memory_status,
|
|
198
211
|
inputSchema: z.object(memoryStatusArgs),
|
package/dist/opencode-v2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { PLUGIN_ID, bootstrapPlugin, captureFromText, captureHandoff, injectOnce, surfaceWorkingStateOnce, } from "./plugin-core.js";
|
|
3
3
|
import { makeTools } from "./tools/memory.js";
|
|
4
|
-
/** Register the
|
|
4
|
+
/** Register the seven memory tools on a v2 host. */
|
|
5
5
|
async function registerTools(ctx, state) {
|
|
6
6
|
const tools = makeTools(() => state.scope, state.cfg);
|
|
7
7
|
await ctx.tool.transform((editor) => {
|
package/dist/retrieve/inject.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { list, hitStateLabel } from "./search.js";
|
|
2
|
+
import { recordRetrieved } from "../store/usage.js";
|
|
2
3
|
import { PERSONAL_SCOPE } from "../scope.js";
|
|
3
4
|
function oneLine(s, max = 240) {
|
|
4
5
|
const trimmed = s.replace(/\s+/g, " ").trim();
|
|
@@ -9,6 +10,11 @@ export function buildContextBlock(scope, cfg) {
|
|
|
9
10
|
const user = list(PERSONAL_SCOPE.key, { limit: cfg.maxProfileItems });
|
|
10
11
|
if (project.length === 0 && user.length === 0)
|
|
11
12
|
return null;
|
|
13
|
+
// D77-L2: the injection is a retrieval surface — the memories it puts in
|
|
14
|
+
// front of the agent were "returned", so they count as exposure. It must
|
|
15
|
+
// NOT touch the useful counters: passive surfacing never refreshes
|
|
16
|
+
// usefulness (D77).
|
|
17
|
+
recordRetrieved([...project.map((m) => m.id), ...user.map((m) => m.id)]);
|
|
12
18
|
const lines = ["[OPEN-MEMEX]"];
|
|
13
19
|
if (user.length > 0) {
|
|
14
20
|
lines.push("", "User profile / preferences:");
|
package/dist/retrieve/search.js
CHANGED
|
@@ -2,6 +2,7 @@ import { db } from "../store/db.js";
|
|
|
2
2
|
import { toFtsQuery } from "./query.js";
|
|
3
3
|
import { BM25_WEIGHTS } from "./weights.js";
|
|
4
4
|
import { loadAliasEntries, planAliasExpansions, mergeRounds, } from "./alias-memory.js";
|
|
5
|
+
import { recordRetrieved } from "../store/usage.js";
|
|
5
6
|
function toHit(r) {
|
|
6
7
|
const aliases = r.aliases ? r.aliases.split(",").map((a) => a.trim()).filter(Boolean) : [];
|
|
7
8
|
let snippet = r.snippet ?? "";
|
|
@@ -232,7 +233,12 @@ export function search(query, opts = {}) {
|
|
|
232
233
|
// without a user alias the query side stays a single FTS round.
|
|
233
234
|
if (opts.stats)
|
|
234
235
|
opts.stats.candidates = merged.length;
|
|
235
|
-
|
|
236
|
+
const hits = resolveVisible(merged, limit, opts.stats);
|
|
237
|
+
// D77-L2: record only the ids actually returned — the candidate pool is
|
|
238
|
+
// not an exposure, and #53 guarantees the cut below is the final result.
|
|
239
|
+
if (opts.record && hits.length > 0)
|
|
240
|
+
recordRetrieved(hits.map((h) => h.id));
|
|
241
|
+
return hits;
|
|
236
242
|
}
|
|
237
243
|
export function list(scopeKey, opts = {}) {
|
|
238
244
|
const limit = Math.max(1, Math.min(opts.limit ?? 20, 100));
|
|
@@ -257,9 +263,14 @@ export function list(scopeKey, opts = {}) {
|
|
|
257
263
|
if (opts.include === "all") {
|
|
258
264
|
// D68: the audit view — every row as stored (superseded versions,
|
|
259
265
|
// retracted, archived), no chain collapsing, capped at limit.
|
|
266
|
+
// NOT an exposure (D77-L2): the audit view is inspection for pruning
|
|
267
|
+
// decisions; counting it would inflate memories the user never saw.
|
|
260
268
|
return raw.slice(0, limit).map(toHit);
|
|
261
269
|
}
|
|
262
|
-
|
|
270
|
+
const hits = resolveVisible(raw, limit);
|
|
271
|
+
if (opts.record && hits.length > 0)
|
|
272
|
+
recordRetrieved(hits.map((h) => h.id));
|
|
273
|
+
return hits;
|
|
263
274
|
}
|
|
264
275
|
/**
|
|
265
276
|
* True totals for the inventory's truncation disclosure (D68). Under
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* D77-L3: the reuse report — pure types + rendering, no SQLite import (the
|
|
3
|
+
* data comes from `loadReuseReport` in store/usage.ts). Split like
|
|
4
|
+
* weights.ts so smoke-pure can test the formatting without a database.
|
|
5
|
+
*
|
|
6
|
+
* Report rules (D77):
|
|
7
|
+
* - per-scope reuse rate = useful / retrieved over tracked memories
|
|
8
|
+
* (counters exist per memory; scopes are personal vs the current project);
|
|
9
|
+
* - the useful side is shown split into self vs team — D77 requires reporting
|
|
10
|
+
* them separately so the team-knowledge claim stays honest (the combined
|
|
11
|
+
* total still drives ranking and the rate);
|
|
12
|
+
* - "top reused" = highest useful, then highest exposure;
|
|
13
|
+
* - "zombies" = retrieved at least once, never confirmed useful — the
|
|
14
|
+
* decay/prune candidates the D77 text calls out;
|
|
15
|
+
* - retracted/archived memories are excluded from the two lists (their
|
|
16
|
+
* counters still count toward the scope totals — history is history);
|
|
17
|
+
* - superseded/deprecated entries stay in the lists (their reuse is real)
|
|
18
|
+
* but carry a lifecycle tag, so historical data never reads as current
|
|
19
|
+
* guidance — supersede itself ticks the OLD memory's useful counter;
|
|
20
|
+
* - lists are capped and the cut is disclosed (D68 honesty rule).
|
|
21
|
+
*/
|
|
22
|
+
function rateText(rate) {
|
|
23
|
+
return rate === null ? "n/a" : `${Math.round(rate * 100)}%`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Render the report as plain lines. Always emits the "Reuse (D77" header, so
|
|
27
|
+
* the section exists (with an honest empty-state line) even before any
|
|
28
|
+
* retrieval has been recorded — discoverability over silence.
|
|
29
|
+
*/
|
|
30
|
+
export function formatReuseReport(report, opts = {}) {
|
|
31
|
+
const cap = opts.entryCap ?? 5;
|
|
32
|
+
const lines = ["Reuse (D77 — local counters, never leave this machine):"];
|
|
33
|
+
if (report.tracked === 0) {
|
|
34
|
+
lines.push(" no data yet — search/list/session-start injection record exposure; memory_useful records usefulness.");
|
|
35
|
+
return lines;
|
|
36
|
+
}
|
|
37
|
+
for (const s of report.scopes) {
|
|
38
|
+
if (s.tracked === 0)
|
|
39
|
+
continue;
|
|
40
|
+
lines.push(` ${s.label}: retrieved ${s.retrieved}, useful ${s.useful} (self ${s.usefulSelf}, team ${s.usefulTeam}) — ${rateText(s.rate)} over ${s.tracked} memor${s.tracked === 1 ? "y" : "ies"}`);
|
|
41
|
+
}
|
|
42
|
+
// Only disambiguate each entry's scope when both scopes have data — the
|
|
43
|
+
// single-scope case would just repeat the same tag on every line.
|
|
44
|
+
const multi = report.scopes.filter((s) => s.tracked > 0).length > 1;
|
|
45
|
+
const tag = (e) => (multi ? `[${e.scopeLabel}/${e.type}]` : `[${e.type}]`);
|
|
46
|
+
// Lifecycle tag: superseded/deprecated entries are historical reuse, not
|
|
47
|
+
// current guidance (a supersede ticks the old memory, so it can rank high).
|
|
48
|
+
const life = (e) => (e.status && e.status !== "active" ? ` [${e.status}]` : "");
|
|
49
|
+
lines.push(` top reused: ${report.topTotal}`);
|
|
50
|
+
for (const e of report.top.slice(0, cap)) {
|
|
51
|
+
lines.push(` · ${e.id} ${tag(e)}${life(e)} retrieved=${e.retrieved} useful=${e.useful} (self ${e.usefulSelf}, team ${e.usefulTeam}) — ${e.snippet}`);
|
|
52
|
+
}
|
|
53
|
+
if (report.topTotal > cap) {
|
|
54
|
+
lines.push(` … and ${report.topTotal - cap} more (full list: open-memex sync-status)`);
|
|
55
|
+
}
|
|
56
|
+
lines.push(` zombies (retrieved, never confirmed useful): ${report.zombieTotal}`);
|
|
57
|
+
for (const e of report.zombies.slice(0, cap)) {
|
|
58
|
+
lines.push(` · ${e.id} ${tag(e)}${life(e)} retrieved=${e.retrieved} — ${e.snippet}`);
|
|
59
|
+
}
|
|
60
|
+
if (report.zombieTotal > cap) {
|
|
61
|
+
lines.push(` … and ${report.zombieTotal - cap} more (full list: open-memex sync-status)`);
|
|
62
|
+
}
|
|
63
|
+
return lines;
|
|
64
|
+
}
|
package/dist/review.js
CHANGED
|
@@ -26,6 +26,7 @@ import { resolveProjectScope } from "./scope.js";
|
|
|
26
26
|
import { parse as parseMemory, serialize, atomicWriteTextSync, ulid, writeMemoryFile, } from "./store/markdown.js";
|
|
27
27
|
import { findMemoryFile } from "./store/lifecycle.js";
|
|
28
28
|
import { upsertFromFile } from "./store/sync.js";
|
|
29
|
+
import { recordUseful } from "./store/usage.js";
|
|
29
30
|
/** Best-effort author identity: git user.name, else the OS user. */
|
|
30
31
|
export function currentAuthor() {
|
|
31
32
|
try {
|
|
@@ -108,6 +109,13 @@ function copyPersonalToProject(sourceId, srcFm, srcBody, opts = {}) {
|
|
|
108
109
|
};
|
|
109
110
|
const { filePath } = writeMemoryFile(fm, srcBody);
|
|
110
111
|
upsertFromFile({ fm, body: srcBody, filePath, mtimeMs: Date.now() });
|
|
112
|
+
// D77-L2: a local approval is still a human approval at review, so it must
|
|
113
|
+
// record the same useful_team tick the promote path records. It bypasses
|
|
114
|
+
// promoteMemory by design (solo-dev shortcut) and submit preserves the
|
|
115
|
+
// approved state, so no later step would otherwise count it — and the
|
|
116
|
+
// later `approved → published` promote stays non-counting for both paths.
|
|
117
|
+
if (targetState === "approved")
|
|
118
|
+
recordUseful(fm.id, "team", "promote");
|
|
111
119
|
return { id: fm.id, filePath, reviewState: fm.review_state };
|
|
112
120
|
}
|
|
113
121
|
/**
|
|
@@ -202,6 +210,12 @@ export function promoteMemory(id, opts = {}) {
|
|
|
202
210
|
};
|
|
203
211
|
atomicWriteTextSync(mf.filePath, serialize(fm, mf.body));
|
|
204
212
|
upsertFromFile({ fm, body: mf.body, filePath: mf.filePath, mtimeMs: Date.now() });
|
|
213
|
+
// D77-L2: a human approve at review is exactly the "explicit confirmation"
|
|
214
|
+
// the D77 useful definition names. One tick per approve step — the later
|
|
215
|
+
// published transition passes through approved and does not re-count.
|
|
216
|
+
// Always useful_team: promoteMemory is project-only by contract above.
|
|
217
|
+
if (to === "approved")
|
|
218
|
+
recordUseful(id, "team", "promote");
|
|
205
219
|
return { id, from, to, history: fm.review_history };
|
|
206
220
|
}
|
|
207
221
|
/** Render a memory's audit trail as compact human-readable lines (D29). */
|
package/dist/store/db.js
CHANGED
|
@@ -111,6 +111,24 @@ END;
|
|
|
111
111
|
`;
|
|
112
112
|
/** Current index schema version. Bump when TABLE_SCHEMA/FTS_SCHEMA change. */
|
|
113
113
|
const SCHEMA_VERSION = 9;
|
|
114
|
+
// D77-L2: reuse counters live in their own table, keyed by memory id. It is
|
|
115
|
+
// created on every open (CREATE IF NOT EXISTS) and deliberately NOT part of
|
|
116
|
+
// the rebuildable index: `rebuildIndexSchema` drops memories/memories_fts
|
|
117
|
+
// and re-derives them from the Markdown files, but the counters are
|
|
118
|
+
// accumulated telemetry with no source-of-truth file to rebuild from — so
|
|
119
|
+
// they must survive a rebuild (ids are stable: the files carry them).
|
|
120
|
+
// No SCHEMA_VERSION bump: the table is additive with IF NOT EXISTS.
|
|
121
|
+
const USAGE_SCHEMA = `
|
|
122
|
+
CREATE TABLE IF NOT EXISTS memory_usage (
|
|
123
|
+
id TEXT PRIMARY KEY,
|
|
124
|
+
retrieved_count INTEGER NOT NULL DEFAULT 0,
|
|
125
|
+
useful_self INTEGER NOT NULL DEFAULT 0,
|
|
126
|
+
useful_team INTEGER NOT NULL DEFAULT 0,
|
|
127
|
+
last_retrieved_at TEXT NOT NULL DEFAULT '',
|
|
128
|
+
last_useful_at TEXT,
|
|
129
|
+
updated_at TEXT NOT NULL DEFAULT ''
|
|
130
|
+
);
|
|
131
|
+
`;
|
|
114
132
|
function userVersion(d) {
|
|
115
133
|
const row = d.prepare("PRAGMA user_version").get();
|
|
116
134
|
return row.user_version;
|
|
@@ -165,6 +183,7 @@ export function db() {
|
|
|
165
183
|
rebuildIndexSchema(d);
|
|
166
184
|
d.exec(TABLE_SCHEMA);
|
|
167
185
|
d.exec(FTS_SCHEMA);
|
|
186
|
+
d.exec(USAGE_SCHEMA);
|
|
168
187
|
if (userVersion(d) < SCHEMA_VERSION)
|
|
169
188
|
rebuildIndexSchema(d);
|
|
170
189
|
_db = d;
|