claude-mem-lite 6.31.0 → 6.32.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +24 -9
- package/README.zh-CN.md +16 -9
- package/adopt-cli.mjs +156 -4
- package/bash-utils.mjs +6 -2
- package/claudemd.mjs +57 -5
- package/commands/adopt.md +9 -5
- package/install.mjs +3 -2
- package/lib/local-steering.mjs +6 -1
- package/lib/task-imperative.mjs +3 -2
- package/mem-cli.mjs +3 -3
- package/npm-shrinkwrap.json +5 -5
- package/package.json +4 -4
- package/scripts/pre-agent-inject.js +6 -2
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"plugins": [
|
|
10
10
|
{
|
|
11
11
|
"name": "claude-mem-lite",
|
|
12
|
-
"version": "6.
|
|
12
|
+
"version": "6.32.0",
|
|
13
13
|
"source": "./",
|
|
14
14
|
"homepage": "https://github.com/sdsrss/claude-mem-lite",
|
|
15
15
|
"description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark)."
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-mem-lite",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.32.0",
|
|
4
4
|
"description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark).",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "sdsrss"
|
package/README.md
CHANGED
|
@@ -167,9 +167,9 @@ Plugin mode manages its own hooks/runtime. On session start it only **checks and
|
|
|
167
167
|
|
|
168
168
|
> **The plugin install is complete on its own** — hooks, MCP tools, and the bundled slash commands (`/mem`, `/lesson`, `/claude-mem-lite:bug`, `/adopt`) all run from the plugin with no second step. The slash commands invoke the bundled CLI by an absolute path resolved from the plugin directory (`node "${CLAUDE_PLUGIN_ROOT}/cli.mjs" <cmd>`), so they work without anything on your `PATH`. A global `claude-mem-lite` **shell** command (for running queries yourself in a terminal) is **optional** — `npm i -g claude-mem-lite` — and is a *separate* npm install: the plugin's auto-update does **not** refresh it, so re-run `npm i -g claude-mem-lite@latest` if you want that shell command kept in sync. You do **not** need it for the plugin to be fully functional.
|
|
169
169
|
|
|
170
|
-
> **Auto-adopt no longer adds its block to your project's `CLAUDE.md` (next release after 6.19.4).** On every SessionStart the plugin delivers its steering text — the trigger table that boosts Claude's proactive use of `mem_recall` / `mem_save`. In a git repository that does not already carry the block it keeps a managed block in `CLAUDE.local.md` at the repository root (Claude Code loads that file like `CLAUDE.md`, also in subagents that load project instructions; the built-in Explore and Plan agents load none) and adds the file to the repository's `.git/info/exclude` unless your ignore rules already cover it, so git does not list or commit it; you get a **one-time notice** the first time it is written. Claude Code reads instruction files before the plugin's startup hook runs, so the session that creates the file gets the text added to its context instead, once (its subagents do not see it). Where Claude Code reads an `AGENTS.md` as the project's instructions, it stops reading it once a `CLAUDE.md` or `CLAUDE.local.md` exists in the session's directory or above, so there nothing is written and the text is **injected** (subagents do not see it), with a one-time notice that names that `AGENTS.md`. With `CLAUDE_MEM_RULES_STEERING=1` the block goes to `.claude/rules/claude-mem-lite.md` at the repository root instead — excluded from git the same way, loaded by Claude Code as project instructions, also in subagents that load project instructions, and it leaves `AGENTS.md` loading — with its own one-time notice; it is not the default because in a pre-registered A/B it did not beat injection by the bar set in advance (`docs/audits/20261006-d212-ab.md`). Outside git, in a repository rooted at `$HOME`,
|
|
170
|
+
> **Auto-adopt no longer adds its block to your project's `CLAUDE.md` (next release after 6.19.4).** On every SessionStart the plugin delivers its steering text — the trigger table that boosts Claude's proactive use of `mem_recall` / `mem_save`. In a git repository that does not already carry the block it keeps a managed block in `CLAUDE.local.md` at the repository root (Claude Code loads that file like `CLAUDE.md`, also in subagents that load project instructions; the built-in Explore and Plan agents load none) and adds the file to the repository's `.git/info/exclude` unless your ignore rules already cover it, so git does not list or commit it; you get a **one-time notice** the first time it is written. Where Claude Code already loads the current block from a `CLAUDE.md` or `CLAUDE.local.md` above the repository root (outside git, above the session's directory) — a directory you ran `adopt` in, or, in a `claude --worktree` session, the main checkout's `CLAUDE.local.md` — nothing is written or injected and an untracked copy the plugin wrote before is taken out (with `CLAUDE_MEM_NO_TEMPLATE_REFRESH=1` it stays), except while `claudeMdExcludes` is set in your user or project settings. Claude Code reads instruction files before the plugin's startup hook runs, so the session that creates the file gets the text added to its context instead, once (its subagents do not see it). Where Claude Code reads an `AGENTS.md` as the project's instructions, it stops reading it once a `CLAUDE.md` or `CLAUDE.local.md` exists in the session's directory or above, so there nothing is written and the text is **injected** (subagents do not see it), with a one-time notice that names that `AGENTS.md`. With `CLAUDE_MEM_RULES_STEERING=1` the block goes to `.claude/rules/claude-mem-lite.md` at the repository root instead — excluded from git the same way, loaded by Claude Code as project instructions, also in subagents that load project instructions, and it leaves `AGENTS.md` loading — with its own one-time notice; it is not the default because in a pre-registered A/B it did not beat injection by the bar set in advance (`docs/audits/20261006-d212-ab.md`). Outside git, in a repository rooted at `$HOME`, or where the repository root is an npm package that `npm publish` would ship it with (no `"private": true`, no `files` list leaving it out, and without one no `.npmignore` naming it), nothing is written and, unless a current block above already loads (see above), the text is **injected** into each session's context, with a one-time notice suggesting `/adopt` (not at `$HOME`). With the variable set, the same holds where the rules file cannot be written (a symbolic link on its path, a tracked or foreign file of that name, an npm package that would ship it). The notice beside an `AGENTS.md` names it, why there is no file, and the ways to a file that keep it loading, each only where it works: Project instructions = `claude-md-and-agents-md` in `/config`, after which `CLAUDE.local.md` is written (not where `CLAUDE.local.md` is refused too: a package root, or a file you removed), and `/adopt`, whose `CLAUDE.md` imports the `AGENTS.md` beside it (not offered when an `AGENTS.md` above that directory or in a subdirectory would stop loading). The detail file the block points at lives in the plugin's data directory, named with a `~/` path. `.git/info/exclude` is read by git only: docker build contexts, archives and other packagers can pick `CLAUDE.local.md` or the rules file up (a publishable npm package root does not keep `CLAUDE.local.md`: a block written before is taken out at the next session start; in a project whose `AGENTS.md` it would switch off, the block comes out and is injected, or, with `CLAUDE_MEM_RULES_STEERING=1`, moves to the rules file where that can be written). Earlier versions added the block to your project's own `<cwd>/CLAUDE.md` (a file that is normally committed) plus a `<cwd>/.claude/plugin_claude_mem_lite.md` detail file, unasked, in every project you opened; those projects keep the block, and the first session of this version refreshes it because the text changed — to move one to the local file, run `claude-mem-lite unadopt` there and commit the removal. Why not inject everywhere: in our sandbox evaluation (one project, Claude Opus 5.5) the agent made 1.5 proactive memory saves per 8-session run with injected steering against 5.25 with the block in `CLAUDE.local.md` or `CLAUDE.md`, and subagents never saw injected text. It applies regardless of install path (npm, npx, `/plugin`, manual); silence these notices with `MEM_NO_ADOPT_HINT=1`.
|
|
171
171
|
>
|
|
172
|
-
> **Want the block in `CLAUDE.md` instead** (for example to share it with your team)? Run `claude-mem-lite adopt`: it writes the slug-scoped managed block into `<cwd>/CLAUDE.md` plus the detail file, preserving everything outside the block, and removes the auto-written local copy (`CLAUDE.local.md` or the rules file). Claude Code stops reading `AGENTS.md` once a `CLAUDE.md` exists, so a `CLAUDE.md` that adopt creates next to an `AGENTS.md` (or `.claude/AGENTS.md`) starts by importing it (`@AGENTS.md`, behind a marker comment Claude Code does not load), and that file keeps loading; an `AGENTS.md` above the directory or tracked below it cannot be imported that way and is named in adopt's output, with the setting that keeps it (Project instructions = `claude-md-and-agents-md`). Nothing is imported where a `CLAUDE.md` of yours already exists, since `AGENTS.md` was not being read there. `unadopt` deletes a `CLAUDE.md` that holds nothing but those lines and the block.
|
|
172
|
+
> **Want the block in `CLAUDE.md` instead** (for example to share it with your team)? Run `claude-mem-lite adopt`: it writes the slug-scoped managed block into `<cwd>/CLAUDE.md` plus the detail file, preserving everything outside the block, and removes the auto-written local copy (`CLAUDE.local.md` or the rules file). Claude Code stops reading `AGENTS.md` once a `CLAUDE.md` exists, so a `CLAUDE.md` that adopt creates next to an `AGENTS.md` (or `.claude/AGENTS.md`) starts by importing it (`@AGENTS.md`, behind a marker comment Claude Code does not load), and that file keeps loading; an `AGENTS.md` above the directory or tracked below it cannot be imported that way and is named in adopt's output, with the setting that keeps it (Project instructions = `claude-md-and-agents-md`). Nothing is imported where a `CLAUDE.md` of yours already exists, since `AGENTS.md` was not being read there. `unadopt` deletes a `CLAUDE.md` that holds nothing but those lines and the block. While auto-adopt is on, a session started in the directory whose `CLAUDE.md` carries the block refreshes it when the shipped template changes and adds no local or injected copy on top of it. A `CLAUDE.md` holding nothing but the block (what an earlier version's auto-adopt wrote) gets the same `AGENTS.md` import at the next session started in its directory, with a one-time notice. Seen from a session started in a subdirectory, the import points outside the working directory, so Claude Code asks once to approve it. A local block (`CLAUDE.local.md` or the rules file) the plugin created and you deleted (or `claude-mem-lite unadopt` removed) is not written back — the text is injected instead — until `claude-mem-lite adopt --enable` (beside an `AGENTS.md` that `CLAUDE.local.md` would switch off, a file comes back only with `CLAUDE_MEM_RULES_STEERING=1` too). Turn steering off per project with `claude-mem-lite adopt --disable` (it also removes the local block; a `CLAUDE.md` block stays until `unadopt`; `--enable` re-arms) or globally with `export MEM_NO_AUTO_ADOPT=1` (blocks already written stay and keep loading until `unadopt`); freeze the blocks against template refreshes with `CLAUDE_MEM_NO_TEMPLATE_REFRESH=1`. `claude-mem-lite unadopt` removes the `CLAUDE.md` block, the detail file, and the local block (`CLAUDE.local.md` or `.claude/rules/claude-mem-lite.md`) with its exclude entry.
|
|
173
173
|
|
|
174
174
|
### Method 2: npx (one-liner)
|
|
175
175
|
|
|
@@ -239,6 +239,21 @@ rm -rf ~/claude-mem-lite/ # unhidden data dir from before the first release (n
|
|
|
239
239
|
repos/ # Shallow-cloned source repos
|
|
240
240
|
```
|
|
241
241
|
|
|
242
|
+
## Upgrading to 6.32.0
|
|
243
|
+
|
|
244
|
+
**The steering sync looks above the repository before writing its copy; nothing to run, and the
|
|
245
|
+
schema version stays 49.** To go back, pin `claude-mem-lite@6.31.0`; its next session writes the
|
|
246
|
+
local copy back. Both changes below hold unless `claudeMdExcludes` is set in your user or project
|
|
247
|
+
settings.
|
|
248
|
+
|
|
249
|
+
- **No `CLAUDE.local.md` where Claude Code already loads the current block from above the
|
|
250
|
+
repository root**: in a `claude --worktree` session, the main checkout's `CLAUDE.local.md`; below a
|
|
251
|
+
directory you ran `adopt` in, its `CLAUDE.md`. An untracked copy the plugin wrote there before is
|
|
252
|
+
taken out (kept with `CLAUDE_MEM_NO_TEMPLATE_REFRESH=1`), and comes back if that block goes.
|
|
253
|
+
`claude-mem-lite adopt --status` names the file that carries it.
|
|
254
|
+
- **Outside git, nothing is injected below a directory whose `CLAUDE.md` carries the current block.**
|
|
255
|
+
- Details in CHANGELOG.md.
|
|
256
|
+
|
|
242
257
|
## Upgrading to 6.31.0
|
|
243
258
|
|
|
244
259
|
**Recall injects less that does not apply to the step at hand; nothing to run, and the schema
|
|
@@ -768,8 +783,8 @@ Slash commands `/adopt` and `/unadopt` wrap the same CLI.
|
|
|
768
783
|
|
|
769
784
|
**Safety:**
|
|
770
785
|
- Regenerated, not hand-edit-safe: `adopt` rewrites the managed block to the shipped
|
|
771
|
-
template, and so does
|
|
772
|
-
included. Keep your own notes outside the `claude-mem-lite:begin…end` markers, or set
|
|
786
|
+
template, and so does a later session started in that directory (while auto-adopt is on)
|
|
787
|
+
whenever the block differs from it — hand edits included. Keep your own notes outside the `claude-mem-lite:begin…end` markers, or set
|
|
773
788
|
`CLAUDE_MEM_NO_TEMPLATE_REFRESH=1` to freeze the block.
|
|
774
789
|
- Slug-scoped & dedup-guarded: only the `claude-mem-lite:begin…end` region is
|
|
775
790
|
ever rewritten, and duplicate / CRLF-orphaned copies are collapsed to one.
|
|
@@ -778,13 +793,13 @@ Slash commands `/adopt` and `/unadopt` wrap the same CLI.
|
|
|
778
793
|
- **Auto-adopt runs on EVERY SessionStart, for any install path, and no longer adds
|
|
779
794
|
the block to `CLAUDE.md` (next release after 6.19.4).** A git project without the
|
|
780
795
|
block gets it in `CLAUDE.local.md` at the git root (kept out of git via
|
|
781
|
-
`.git/info/exclude
|
|
796
|
+
`.git/info/exclude`; not where the current block already loads from above the root), or in SessionStart context where `CLAUDE.local.md` would stop
|
|
782
797
|
Claude Code reading the project's `AGENTS.md` (in `.claude/rules/claude-mem-lite.md`
|
|
783
|
-
with `CLAUDE_MEM_RULES_STEERING=1`),
|
|
798
|
+
with `CLAUDE_MEM_RULES_STEERING=1`), and where no file can be written; a project that
|
|
784
799
|
carries the `CLAUDE.md` block (explicit `adopt`, or an older version's auto-adopt)
|
|
785
|
-
has it
|
|
786
|
-
`CLAUDE_MEM_NO_TEMPLATE_REFRESH=1`)
|
|
787
|
-
|
|
800
|
+
has it refreshed by a session started in that directory when the shipped template
|
|
801
|
+
changes (freeze with `CLAUDE_MEM_NO_TEMPLATE_REFRESH=1`), and that session adds no
|
|
802
|
+
local or injected copy; a `CLAUDE.md` holding only the block also gets
|
|
788
803
|
adopt's `AGENTS.md` import when an `AGENTS.md` is beside it. A local block (`CLAUDE.local.md` or
|
|
789
804
|
the rules file) the plugin created and you (or `unadopt`) removed is not written back;
|
|
790
805
|
`adopt --enable` re-arms it (beside such an `AGENTS.md`, together with
|
package/README.zh-CN.md
CHANGED
|
@@ -154,9 +154,9 @@ node install.mjs install
|
|
|
154
154
|
1. **安装依赖** -- `npm install --omit=dev`(编译原生 `better-sqlite3`)
|
|
155
155
|
2. **注册 MCP 服务器** -- `mem-lite` 服务器定义 19 个工具(10 个核心 + 9 个隐藏但可调;`mem_search_feedback` 仅在启用搜索遥测时注册)。v2.78 前服务器名为通用的 `mem`,现已改名为 `mem-lite` 避免与用户其它 `.mcp.json` 冲突;工具名(`mem_search`/`mem_recall` 等)保持不变。
|
|
156
156
|
|
|
157
|
-
> **自动 adopt 不再把托管块加进你项目的 `CLAUDE.md`(6.19.4 之后的下一个版本起)。** 每次 SessionStart,插件都会送达引导文本(提升 Claude 主动调用 `mem_recall` / `mem_save` 的触发表)。在还没有托管块的 git 仓库里,它把托管块写进仓库根目录的 `CLAUDE.local.md`(Claude Code 像加载 `CLAUDE.md` 一样加载它,加载项目指令的子代理也能看到;内置的 Explore 和 Plan 子代理不加载这类文件),并把这个文件加进仓库的 `.git/info/exclude`(你的 ignore 规则已覆盖时不加),所以 git 不列出、也不提交它;第一次写入时你会看到一条**一次性提示**。Claude Code 在插件的启动钩子运行之前就读取了指令文件,所以创建这个文件的那个会话改为在上下文里注入一次引导(该会话的子代理看不到)。Claude Code 把某个 `AGENTS.md` 当作项目指令读取时,会话目录或上层只要有 `CLAUDE.md` 或 `CLAUDE.local.md` 它就不再读 `AGENTS.md`,所以在这种仓库里什么都不写,改为**注入**引导(子代理看不到),并给一条点名那个 `AGENTS.md` 的一次性提示。设了 `CLAUDE_MEM_RULES_STEERING=1` 时,托管块改写进仓库根目录的 `.claude/rules/claude-mem-lite.md`:同样经 `.git/info/exclude` 排除在 git 之外,Claude Code 把它当作项目指令加载(加载项目指令的子代理也能看到),而且不会让 `AGENTS.md` 失效;第一次写入时有单独的一次性提示。它不是默认做法,因为在预先登记的 A/B 里它没有达到事先定下的、胜过注入的标准(`docs/audits/20261006-d212-ab.md`)。不在 git 仓库里、仓库根是 `$HOME
|
|
157
|
+
> **自动 adopt 不再把托管块加进你项目的 `CLAUDE.md`(6.19.4 之后的下一个版本起)。** 每次 SessionStart,插件都会送达引导文本(提升 Claude 主动调用 `mem_recall` / `mem_save` 的触发表)。在还没有托管块的 git 仓库里,它把托管块写进仓库根目录的 `CLAUDE.local.md`(Claude Code 像加载 `CLAUDE.md` 一样加载它,加载项目指令的子代理也能看到;内置的 Explore 和 Plan 子代理不加载这类文件),并把这个文件加进仓库的 `.git/info/exclude`(你的 ignore 规则已覆盖时不加),所以 git 不列出、也不提交它;第一次写入时你会看到一条**一次性提示**。Claude Code 已经从仓库根目录之上(不在 git 里时,从会话目录之上)的 `CLAUDE.md` 或 `CLAUDE.local.md` 加载当前版本的托管块时(你运行过 `adopt` 的上级目录;或在 `claude --worktree` 会话里,主检出的 `CLAUDE.local.md`),这里既不写也不注入,插件之前写的、未被 git 跟踪的副本会被移除(设了 `CLAUDE_MEM_NO_TEMPLATE_REFRESH=1` 时保留);用户或项目设置里有 `claudeMdExcludes` 时除外。Claude Code 在插件的启动钩子运行之前就读取了指令文件,所以创建这个文件的那个会话改为在上下文里注入一次引导(该会话的子代理看不到)。Claude Code 把某个 `AGENTS.md` 当作项目指令读取时,会话目录或上层只要有 `CLAUDE.md` 或 `CLAUDE.local.md` 它就不再读 `AGENTS.md`,所以在这种仓库里什么都不写,改为**注入**引导(子代理看不到),并给一条点名那个 `AGENTS.md` 的一次性提示。设了 `CLAUDE_MEM_RULES_STEERING=1` 时,托管块改写进仓库根目录的 `.claude/rules/claude-mem-lite.md`:同样经 `.git/info/exclude` 排除在 git 之外,Claude Code 把它当作项目指令加载(加载项目指令的子代理也能看到),而且不会让 `AGENTS.md` 失效;第一次写入时有单独的一次性提示。它不是默认做法,因为在预先登记的 A/B 里它没有达到事先定下的、胜过注入的标准(`docs/audits/20261006-d212-ab.md`)。不在 git 仓库里、仓库根是 `$HOME`,或者仓库根是一个 `npm publish` 会把它带上的 npm 包(没有 `"private": true`,没有把它排除在外的 `files` 列表,没有 `files` 列表时也没有列出它的 `.npmignore`)时,什么都不写;除非上层已加载当前版本的托管块(见上文),否则每个会话把引导**注入**上下文,并一次性提示可以运行 `/adopt`(在 `$HOME` 下不提示)。设了这个变量但 rules 文件写不了时(路径上有符号链接、同名文件被跟踪或是你自己的文件、npm 包会把它带上)同样改为注入。`AGENTS.md` 旁边的提示会说明是哪个 `AGENTS.md`、为什么没有文件,并只给出在这里行得通的、保留 `AGENTS.md` 又能写文件的做法:在 `/config` 里把 Project instructions 设为 `claude-md-and-agents-md`,之后就会写 `CLAUDE.local.md`(`CLAUDE.local.md` 也会被拒写时不提,比如 npm 包根,或你删过的文件);运行 `/adopt`,它写的 `CLAUDE.md` 会导入同目录的 `AGENTS.md`(上层目录或子目录里的 `AGENTS.md` 会因此失效时不提)。托管块指向的详情文件放在插件自己的数据目录,以 `~/` 路径书写。`.git/info/exclude` 只对 git 生效:docker 构建上下文、归档和其他打包工具都可能把 `CLAUDE.local.md` 打进去(rules 文件同样如此;可发布的 npm 包根目录不会保留 `CLAUDE.local.md`:之前写入的托管块会在下一次会话启动时移除;在这个文件会让 `AGENTS.md` 失效的项目里,托管块会被移除、改为注入;设了 `CLAUDE_MEM_RULES_STEERING=1` 时,在写得了的情况下移到 rules 文件)。旧版本会在你打开的每个项目里,未经询问就向项目自己的 `<cwd>/CLAUDE.md`(通常会进 git)写入托管块,外加 `<cwd>/.claude/plugin_claude_mem_lite.md` 详情文件;这些项目保留托管块,本版本的第一个会话会因为文本变化刷新它——想把某个项目迁到本地文件,在那里运行 `claude-mem-lite unadopt` 并提交这次删除。为什么不全部改成注入:沙箱实测中(一个项目,Claude Opus 5.5),8 个会话里模型主动记录的次数,注入时平均 1.5 次,写在 `CLAUDE.local.md` 或 `CLAUDE.md` 时 5.25 次;而且子代理完全看不到注入的文本。**任何安装路径都生效**(npm、npx、`/plugin`、手动);这些提示都可以用 `MEM_NO_ADOPT_HINT=1` 关闭。
|
|
158
158
|
>
|
|
159
|
-
> **想把托管块改写进 `CLAUDE.md`**(例如与团队共享)?运行 `claude-mem-lite adopt`:它向 `<cwd>/CLAUDE.md` 写入 slug 限定的托管块和详情文件,块以外的内容逐字保留,并删除自动写入的那份本地副本(`CLAUDE.local.md` 或 rules 文件)。`CLAUDE.md` 一存在,Claude Code 就不再读 `AGENTS.md`,所以 adopt 在 `AGENTS.md`(或 `.claude/AGENTS.md`)旁边新建 `CLAUDE.md` 时,会在文件开头导入它(`@AGENTS.md`,前面一行是 Claude Code 不加载的标记注释),`AGENTS.md` 因此继续加载;上层目录里的、或 git 跟踪在子目录里的 `AGENTS.md` 不能这样导入,adopt 会在输出里列出它们,并给出保留它们的设置(Project instructions 设为 `claude-md-and-agents-md`)。已经有你自己的 `CLAUDE.md` 时不导入,因为那里本来就不读 `AGENTS.md`。`unadopt` 会删除只剩这些行和托管块的 `CLAUDE.md
|
|
159
|
+
> **想把托管块改写进 `CLAUDE.md`**(例如与团队共享)?运行 `claude-mem-lite adopt`:它向 `<cwd>/CLAUDE.md` 写入 slug 限定的托管块和详情文件,块以外的内容逐字保留,并删除自动写入的那份本地副本(`CLAUDE.local.md` 或 rules 文件)。`CLAUDE.md` 一存在,Claude Code 就不再读 `AGENTS.md`,所以 adopt 在 `AGENTS.md`(或 `.claude/AGENTS.md`)旁边新建 `CLAUDE.md` 时,会在文件开头导入它(`@AGENTS.md`,前面一行是 Claude Code 不加载的标记注释),`AGENTS.md` 因此继续加载;上层目录里的、或 git 跟踪在子目录里的 `AGENTS.md` 不能这样导入,adopt 会在输出里列出它们,并给出保留它们的设置(Project instructions 设为 `claude-md-and-agents-md`)。已经有你自己的 `CLAUDE.md` 时不导入,因为那里本来就不读 `AGENTS.md`。`unadopt` 会删除只剩这些行和托管块的 `CLAUDE.md`。auto-adopt 开着时,从托管块所在目录启动的会话会在出货模板变化时刷新它,且不会再叠加本地副本或注入。只有托管块的 `CLAUDE.md`(旧版本自动 adopt 写的)会在下一次从它所在目录启动的会话里补上同样的 `AGENTS.md` 导入,并给一次性提示。从子目录启动的会话看来,这个导入指向工作目录之外,Claude Code 会请你批准一次。插件创建过、又被你删掉(或被 `claude-mem-lite unadopt` 删掉)的本地托管块(`CLAUDE.local.md` 或 rules 文件)不会被写回,改为注入,直到运行 `claude-mem-lite adopt --enable`(在 `CLAUDE.local.md` 会让 `AGENTS.md` 失效的仓库里,还要设 `CLAUDE_MEM_RULES_STEERING=1` 才会再写文件)。关闭方式:项目级 `claude-mem-lite adopt --disable`(同时删除本地托管块;`CLAUDE.md` 托管块保留到 `unadopt`;重新启用用 `--enable`);全局 `export MEM_NO_AUTO_ADOPT=1`(已写入的托管块保留并继续加载,直到 `unadopt`);只冻结模板刷新用 `CLAUDE_MEM_NO_TEMPLATE_REFRESH=1`。`claude-mem-lite unadopt` 会移除 `CLAUDE.md` 托管块、详情文件,以及本地托管块(`CLAUDE.local.md` 或 `.claude/rules/claude-mem-lite.md`)和它的 exclude 条目。
|
|
160
160
|
3. **配置钩子** -- 全部七个生命周期事件:`SessionStart`、`PreCompact`、`PreToolUse`、`PostToolUse`、`PostToolUseFailure`、`Stop`、`UserPromptSubmit`
|
|
161
161
|
4. **创建数据目录** -- `~/.claude-mem-lite/`(隐藏目录),存放数据库与运行时文件
|
|
162
162
|
5. **自动迁移** -- `~/.claude-mem/claude-mem.db`(原版 claude-mem)以 `.legacy-backup-<时间>` 文件的形式移入 `~/.claude-mem-lite/`(插件、以及跨文件系统时的 install 改为复制),并新建一个数据库。`~/claude-mem-lite/`(首个发布版 2.0.0 之前的非隐藏目录)里留下的数据库在第一次打开时移入数据目录,前提是数据目录里还没有 claude-mem-lite 的数据库、日志、快照或保留副本;两个目录里的其他文件都不移动、不删除
|
|
@@ -201,6 +201,14 @@ rm -rf ~/claude-mem-lite/ # 首个发布版之前的非隐藏目录(不是
|
|
|
201
201
|
repos/ # 浅克隆的源代码仓库
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
+
## 升级到 6.32.0
|
|
205
|
+
|
|
206
|
+
**写引导副本之前,插件先看仓库之上的文件;不用执行任何操作,schema 版本仍是 49。** 想退回,请固定 `claude-mem-lite@6.31.0`;它的下一个会话会把本地副本写回来。用户或项目设置里有 `claudeMdExcludes` 时,下面两条都不适用。
|
|
207
|
+
|
|
208
|
+
- **Claude Code 已从仓库根目录之上加载当前版本的托管块时,不再写 `CLAUDE.local.md`**:`claude --worktree` 会话里是主检出的 `CLAUDE.local.md`;在你运行过 `adopt` 的目录下面,是那个目录的 `CLAUDE.md`。插件之前在这里写的、未被 git 跟踪的副本会被移除(设了 `CLAUDE_MEM_NO_TEMPLATE_REFRESH=1` 时保留);上层那份没了,副本会再写回来。`claude-mem-lite adopt --status` 会指出是哪个文件带着它。
|
|
209
|
+
- **不在 git 里时,带当前托管块的 `CLAUDE.md` 所在目录之下的会话不再注入引导。**
|
|
210
|
+
- 详见 CHANGELOG.md。
|
|
211
|
+
|
|
204
212
|
## 升级到 6.31.0
|
|
205
213
|
|
|
206
214
|
**召回注入的内容里,和当前这一步无关的更少了;不用执行任何操作,schema 版本仍是 49。** 每项会少注入内容的改动都有开关可以退回;要撤销纯文本的改动,请固定 `claude-mem-lite@6.30.15`。
|
|
@@ -598,19 +606,18 @@ Slash 命令 `/adopt` 和 `/unadopt` 是上述 CLI 的包装。
|
|
|
598
606
|
同理。
|
|
599
607
|
|
|
600
608
|
**安全性:**
|
|
601
|
-
- 托管块会被重新生成,不保留手改:`adopt`
|
|
602
|
-
|
|
609
|
+
- 托管块会被重新生成,不保留手改:`adopt` 会把它改写成出货模板,之后从该目录启动的会话
|
|
610
|
+
(auto-adopt 开着时)只要它和模板不同也会改写——手动编辑的内容一样被覆盖。自己的笔记写在
|
|
603
611
|
`claude-mem-lite:begin…end` 标记之外,或设 `CLAUDE_MEM_NO_TEMPLATE_REFRESH=1` 冻结。
|
|
604
612
|
- 按 slug 限定、去重:只改写 `claude-mem-lite:begin…end` 这一段,重复或 CRLF 残留的
|
|
605
613
|
副本会合并成一份。旧的 `MEMORY.md` 方案才有行数预算,`CLAUDE.md` 没有截断上限。
|
|
606
614
|
- **任何安装路径每次 SessionStart 都自动 adopt,且不再把托管块加进 `CLAUDE.md`(6.19.4
|
|
607
615
|
之后的下一个版本起)。** 没有托管块的 git 项目,引导写进 git 根目录的 `CLAUDE.local.md`
|
|
608
|
-
(经 `.git/info/exclude` 排除在 git
|
|
616
|
+
(经 `.git/info/exclude` 排除在 git 之外;根目录之上已加载当前版本的托管块时不写);这个文件会让 Claude Code 不再读项目的 `AGENTS.md` 时
|
|
609
617
|
注入 SessionStart 上下文(设 `CLAUDE_MEM_RULES_STEERING=1` 时改写进 `.claude/rules/claude-mem-lite.md`),
|
|
610
|
-
|
|
611
|
-
`CLAUDE.md` 托管块的项目(显式 adopt
|
|
612
|
-
`CLAUDE_MEM_NO_TEMPLATE_REFRESH=1`
|
|
613
|
-
也一样;只有托管块的 `CLAUDE.md` 旁边有 `AGENTS.md` 时,还会补上 adopt 的 `AGENTS.md` 导入。插件创建过、又被你(或 `unadopt`)删掉的本地托管块(`CLAUDE.local.md` 或 rules 文件)不会被写回;
|
|
618
|
+
文件写不了时也注入;带
|
|
619
|
+
`CLAUDE.md` 托管块的项目(显式 adopt 或旧版本写入),由从该目录启动的会话在出货模板变化时刷新(用
|
|
620
|
+
`CLAUDE_MEM_NO_TEMPLATE_REFRESH=1` 冻结),且该会话不会再叠加本地副本或注入;只有托管块的 `CLAUDE.md` 旁边有 `AGENTS.md` 时,还会补上 adopt 的 `AGENTS.md` 导入。插件创建过、又被你(或 `unadopt`)删掉的本地托管块(`CLAUDE.local.md` 或 rules 文件)不会被写回;
|
|
614
621
|
`adopt --enable` 可重新启用(在这类 `AGENTS.md` 仓库里还要设 `CLAUDE_MEM_RULES_STEERING=1`)。项目级关闭:`claude-mem-lite adopt --disable`(写
|
|
615
622
|
`<memdir>/.mem-no-auto-adopt` 哨兵,存活于 marker 删除 / 插件重装;在仓库根目录运行时,对从子目录启动的
|
|
616
623
|
会话同样生效;并删除本地托管块)。全局关闭:`export MEM_NO_AUTO_ADOPT=1`(已写入的托管块保留,直到 `unadopt`)。
|
package/adopt-cli.mjs
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
realpathSync,
|
|
27
27
|
} from 'fs';
|
|
28
28
|
import { claudeConfigDir, claudeStatePath } from './lib/data-paths.mjs';
|
|
29
|
-
import { join, isAbsolute, relative, dirname } from 'path';
|
|
29
|
+
import { join, isAbsolute, relative, dirname, resolve, basename } from 'path';
|
|
30
30
|
import {
|
|
31
31
|
memdirPath,
|
|
32
32
|
disableSentinelPath,
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
hasResidue as claudeMdHasResidue,
|
|
46
46
|
needsRefresh,
|
|
47
47
|
readBlock,
|
|
48
|
+
readBlockAt,
|
|
48
49
|
migrateLegacyMemoryDir,
|
|
49
50
|
hasLegacyMemdirSentinel,
|
|
50
51
|
claudeMdPath,
|
|
@@ -78,7 +79,9 @@ import {
|
|
|
78
79
|
samePath,
|
|
79
80
|
localFileLinked,
|
|
80
81
|
userInstructionFiles,
|
|
82
|
+
steeringDetailDocPath,
|
|
81
83
|
} from './lib/local-steering.mjs';
|
|
84
|
+
import { pluginSettingsScopes } from './lib/plugin-key.mjs';
|
|
82
85
|
import { CLI_INVOKE } from './cli-path.mjs';
|
|
83
86
|
|
|
84
87
|
/**
|
|
@@ -272,6 +275,15 @@ function adoptOne(cwd, { force, dryRun }) {
|
|
|
272
275
|
log(`[adopt] ${cwd} → ${r.action}${docNote}${migNote}${localNote}${importNote}`);
|
|
273
276
|
for (const line of elsewhere('stops')) log(line);
|
|
274
277
|
for (const line of sharedNote('stops')) log(line);
|
|
278
|
+
// In a subdirectory the root's local copy stays for the root's sessions, and sessions started
|
|
279
|
+
// here load it as an ancestor too. No layout the plugin could pick loads the block once in every
|
|
280
|
+
// session without moving the root's sessions to injection (D#509(4) spec), so say which one does.
|
|
281
|
+
const top = localSteeringRoot(cwd);
|
|
282
|
+
const rootCopy = top && !samePath(top, cwd) ? readLocalSteering(top, PLUGIN_SLUG) : null;
|
|
283
|
+
if (rootCopy && rootCopy.body !== null)
|
|
284
|
+
log(
|
|
285
|
+
` ⚠ ${rootCopy.path} also carries the block, and sessions started here load both, so they load it twice. For one copy in every session, keep the block in one CLAUDE.md at ${top} (\`${CLI_INVOKE} adopt\` there, \`${CLI_INVOKE} unadopt\` here).`,
|
|
286
|
+
);
|
|
275
287
|
// The copy that could not come out loads beside CLAUDE.md: said, and not a success (R3-4).
|
|
276
288
|
if (local.action === 'failed') {
|
|
277
289
|
if (local.residue) log(` ⚠ ${local.residue}`);
|
|
@@ -409,6 +421,22 @@ export function silentAutoAdopt({ cwd, markerDir, markerKey }) {
|
|
|
409
421
|
// (delta review P2-2; lib/quiet-scope.mjs mirrors it).
|
|
410
422
|
if (isAutoAdoptDisabledFor(root)) return { ok: true, action: 'disabled', reason: 'root-disabled' };
|
|
411
423
|
}
|
|
424
|
+
// The shipped block already loads from above the top-level (an enclosing directory's
|
|
425
|
+
// CLAUDE.md, or in a worktree the main checkout's CLAUDE.local.md): a local copy would be the
|
|
426
|
+
// second (D#509(4)). One the plugin wrote goes and is forgotten, so the file comes back if that
|
|
427
|
+
// block goes or falls behind; one the user removed stays removed. Frozen
|
|
428
|
+
// (CLAUDE_MEM_NO_TEMPLATE_REFRESH=1, how edits inside the markers are kept), it stays: removing
|
|
429
|
+
// it would lose them (v6.32.0 pre-release defects review F2). The detail doc in the data
|
|
430
|
+
// directory, which a CLAUDE.local.md above points at, is kept current as when writing one (F7).
|
|
431
|
+
if (steeringAbove(root, cwd).current) {
|
|
432
|
+
if (
|
|
433
|
+
process.env.CLAUDE_MEM_NO_TEMPLATE_REFRESH !== '1' &&
|
|
434
|
+
removeLocalSteering(root, PLUGIN_SLUG, { keepTracked: true }).action === 'removed'
|
|
435
|
+
)
|
|
436
|
+
forgetLocalSteering(root);
|
|
437
|
+
ensureSteeringDetailDoc();
|
|
438
|
+
return { ok: true, action: 'already-adopted', reason: 'above-root' };
|
|
439
|
+
}
|
|
412
440
|
const localBlock = buildClaudeMdBlock({ detailDocRef: tildePath(ensureSteeringDetailDoc()) });
|
|
413
441
|
const r = writeLocalSteering(root, {
|
|
414
442
|
slug: PLUGIN_SLUG,
|
|
@@ -440,9 +468,13 @@ export function silentAutoAdopt({ cwd, markerDir, markerKey }) {
|
|
|
440
468
|
}
|
|
441
469
|
// managed-only loads no project CLAUDE.md, so the hook does not offer /adopt (v6.30.0 pre-tag
|
|
442
470
|
// claims review P2-5; inside a git work tree the reason is local-managed-only).
|
|
443
|
-
return
|
|
444
|
-
|
|
445
|
-
|
|
471
|
+
if (managedOnly) return { ok: true, action: 'inject', reason: 'managed-only' };
|
|
472
|
+
// Outside git there is no top-level to stop at, and the host loads every CLAUDE.md above the
|
|
473
|
+
// session as an ancestor: the shipped block there already steers it, and injecting was a
|
|
474
|
+
// second copy (D#760). An out-of-date one is not relied on (D#509(4)).
|
|
475
|
+
if (steeringAbove(cwd).current)
|
|
476
|
+
return { ok: true, action: 'already-adopted', reason: 'ancestor-claude-md' };
|
|
477
|
+
return { ok: true, action: 'inject' };
|
|
446
478
|
}
|
|
447
479
|
dropLocalSteering(cwd, { atRootOnly: true, keepTracked: true });
|
|
448
480
|
let action = 'already-adopted';
|
|
@@ -532,6 +564,91 @@ function blockAbove(cwd, root) {
|
|
|
532
564
|
}
|
|
533
565
|
}
|
|
534
566
|
|
|
567
|
+
// The main checkout of the linked worktree at `top` as Claude Code 2.1.322 finds it from `.git` (its
|
|
568
|
+
// canonical-root lookup), or null. `.git` reads `gitdir: <gitdir>`; that directory's `gitdir` file
|
|
569
|
+
// must point back at `<top>/.git` (a worktree moved without `git worktree repair` does not, and is
|
|
570
|
+
// no worktree to the host); its `commondir` names the common directory, whose parent is the checkout
|
|
571
|
+
// when it is named `.git`, and which is itself the checkout otherwise (a bare repository). A
|
|
572
|
+
// submodule's gitdir has no back-pointer, so null. The host's further checks reject layouts git does
|
|
573
|
+
// not make; where they would differ, this skips more and the block loads twice, never not at all.
|
|
574
|
+
function worktreeMainCheckout(top) {
|
|
575
|
+
try {
|
|
576
|
+
const dotGit = readFileSync(join(top, '.git'), 'utf8').trim();
|
|
577
|
+
if (!dotGit.startsWith('gitdir:')) return null;
|
|
578
|
+
const gitdir = resolve(top, dotGit.slice(7).trim());
|
|
579
|
+
const back = resolve(gitdir, readFileSync(join(gitdir, 'gitdir'), 'utf8').trim());
|
|
580
|
+
if (realpathSync(back) !== join(realpathSync(top), '.git')) return null;
|
|
581
|
+
const common = resolve(gitdir, readFileSync(join(gitdir, 'commondir'), 'utf8').trim());
|
|
582
|
+
return basename(common) === '.git' ? dirname(common) : common;
|
|
583
|
+
} catch {
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Whether the user settings or a project's settings files set claudeMdExcludes. An excluded file does
|
|
589
|
+
// not load, and its globs are not evaluated here, so with any set nothing above is relied on. One set
|
|
590
|
+
// where these files do not reach (--settings, managed settings) is not seen (D#781, D#787).
|
|
591
|
+
function claudeMdExcludesSet(dirs) {
|
|
592
|
+
const files = new Set(dirs.flatMap((d) => pluginSettingsScopes(claudeConfigDir(), d)));
|
|
593
|
+
for (const f of files) {
|
|
594
|
+
try {
|
|
595
|
+
const v = JSON.parse(readFileSync(f, 'utf8'))?.claudeMdExcludes;
|
|
596
|
+
if (Array.isArray(v) ? v.length > 0 : v !== undefined && v !== null) return true;
|
|
597
|
+
} catch {
|
|
598
|
+
/* absent or unparseable: sets nothing */
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* The plugin's block in the instruction files Claude Code loads at launch from ABOVE `top` — a git
|
|
606
|
+
* top-level, or outside git the session's directory (D#509(4), D#760). Checked on Claude Code
|
|
607
|
+
* 2.1.322 with InstructionsLoaded and in its source (tasks/specs/d509-steering-above-root.md): the
|
|
608
|
+
* CLAUDE.md and CLAUDE.local.md of every directory above the session load, inside other git
|
|
609
|
+
* repositories too, up to but not including the filesystem root; a worktree session skips the
|
|
610
|
+
* CLAUDE.md (and rules) of every directory from its main checkout down, while still loading their
|
|
611
|
+
* CLAUDE.local.md. Rules files never count here.
|
|
612
|
+
*
|
|
613
|
+
* `current` is the nearest such file whose block is the shipped one — a CLAUDE.md compared as the
|
|
614
|
+
* sync compares it (block and detail doc), a CLAUDE.local.md against the local block — or any block
|
|
615
|
+
* under CLAUDE_MEM_NO_TEMPLATE_REFRESH=1; `stale` the nearest one that is not. Only a current block
|
|
616
|
+
* may stand in for the local copy: an out-of-date one alone would swap the shipped text for an older
|
|
617
|
+
* one (6.19's block lacks the row on checking a memory against the code). Nothing counts under
|
|
618
|
+
* managed-only (no project file loads) or where claudeMdExcludes is set.
|
|
619
|
+
* @returns {{current: string|null, stale: string|null}} file paths
|
|
620
|
+
*/
|
|
621
|
+
function steeringAbove(top, cwd = top) {
|
|
622
|
+
const found = { current: null, stale: null };
|
|
623
|
+
if (userInstructionFiles() === 'managed-only') return found;
|
|
624
|
+
const main = worktreeMainCheckout(top);
|
|
625
|
+
if (claudeMdExcludesSet(main ? [cwd, top, main] : [cwd, top])) return found;
|
|
626
|
+
const frozen = process.env.CLAUDE_MEM_NO_TEMPLATE_REFRESH === '1';
|
|
627
|
+
const version = CURRENT_SENTINEL_VERSION;
|
|
628
|
+
const shipped = { slug: PLUGIN_SLUG, version, block: buildClaudeMdBlock(), doc: getDetailDoc() };
|
|
629
|
+
const localBlock = buildClaudeMdBlock({ detailDocRef: tildePath(steeringDetailDocPath()) });
|
|
630
|
+
const note = (file, current) => {
|
|
631
|
+
if (current) found.current ??= file;
|
|
632
|
+
else found.stale ??= file;
|
|
633
|
+
};
|
|
634
|
+
const dirs = [];
|
|
635
|
+
for (let d = dirname(top); dirname(d) !== d; d = dirname(d)) dirs.push(d);
|
|
636
|
+
const lastSkipped = main ? dirs.findIndex((d) => samePath(d, main)) : -1;
|
|
637
|
+
for (const [i, d] of dirs.entries()) {
|
|
638
|
+
if (i > lastSkipped && blockIn(d)) note(claudeMdPath(d), frozen || !needsRefresh(d, shipped));
|
|
639
|
+
let local = null;
|
|
640
|
+
try {
|
|
641
|
+
local = readBlockAt(join(d, LOCAL_MD), PLUGIN_SLUG);
|
|
642
|
+
} catch {
|
|
643
|
+
/* a directory or an unreadable file: no block of ours */
|
|
644
|
+
}
|
|
645
|
+
if (local && local.body !== null)
|
|
646
|
+
note(join(d, LOCAL_MD), frozen || (local.version === version && local.body === localBlock));
|
|
647
|
+
if (found.current) return found;
|
|
648
|
+
}
|
|
649
|
+
return found;
|
|
650
|
+
}
|
|
651
|
+
|
|
535
652
|
function writeMarker(markerDir, markerKey) {
|
|
536
653
|
if (!existsSync(markerDir)) mkdirSync(markerDir, { recursive: true });
|
|
537
654
|
const path = join(markerDir, `.auto-adopt-${markerKey}`);
|
|
@@ -669,6 +786,41 @@ function localSteeringStatus(cwd) {
|
|
|
669
786
|
return `— none: CLAUDE.md carries the block (the local copy in ${cur.path} is removed at the next session start)`;
|
|
670
787
|
return `⚠ CLAUDE.md carries the block, and ${cur.path} also does${kept ? ` (${kept}; the plugin leaves it as it is)` : ''}: sessions here load it twice`;
|
|
671
788
|
}
|
|
789
|
+
// Then the files above the top-level (outside git, above the session), as the session checks them
|
|
790
|
+
// (D#509(4), D#760).
|
|
791
|
+
const above = steeringAbove(root ?? cwd, cwd);
|
|
792
|
+
if (above.current) {
|
|
793
|
+
const cur = root ? readLocalSteering(root, PLUGIN_SLUG) : null;
|
|
794
|
+
if (cur === null || cur.body === null) return `— none: ${above.current} carries the block`;
|
|
795
|
+
const kept = localFileLinked(root, cur.path)
|
|
796
|
+
? 'behind a symbolic link'
|
|
797
|
+
: trackedByGit(root, relative(root, cur.path))
|
|
798
|
+
? 'tracked by git'
|
|
799
|
+
: null;
|
|
800
|
+
// A session started here takes the copy out, when the sync runs and where it can, unless a damaged
|
|
801
|
+
// sentinel line in CLAUDE.md stops it first or the template is frozen.
|
|
802
|
+
if (
|
|
803
|
+
!kept &&
|
|
804
|
+
runs &&
|
|
805
|
+
removable(cur.path) &&
|
|
806
|
+
straySentinelLines(claudeMdPath(cwd), PLUGIN_SLUG).length === 0 &&
|
|
807
|
+
process.env.CLAUDE_MEM_NO_TEMPLATE_REFRESH !== '1'
|
|
808
|
+
)
|
|
809
|
+
return `— none: ${above.current} carries the block (the local copy in ${cur.path} is removed at the next session start)`;
|
|
810
|
+
return `⚠ ${above.current} carries the block, and ${cur.path} also does${kept ? ` (${kept}; the plugin leaves it as it is)` : ''}: sessions here load it twice`;
|
|
811
|
+
}
|
|
812
|
+
const line = localFileLine(cwd, root, runs);
|
|
813
|
+
if (!above.stale) return line;
|
|
814
|
+
// Out of date, it does not stand in for the local copy, and it loads here all the same. Only a
|
|
815
|
+
// CLAUDE.md has a remedy that holds in every state: what a session does to a CLAUDE.local.md
|
|
816
|
+
// depends on that directory (refreshed, taken out, or left as it is when tracked).
|
|
817
|
+
const how =
|
|
818
|
+
basename(above.stale) === LOCAL_MD ? '' : `; \`${CLI_INVOKE} adopt\` there brings it up to date`;
|
|
819
|
+
return `${line}\n ⚠ ${above.stale} holds an out-of-date copy of the block, which sessions here load as well${how}`;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// The rest of the `local:` line: the local file, or why there is none and what changes it.
|
|
823
|
+
function localFileLine(cwd, root, runs) {
|
|
672
824
|
if (root) {
|
|
673
825
|
const cur = readLocalSteering(root, PLUGIN_SLUG);
|
|
674
826
|
if (cur.body !== null) return currentLocalLine(root, cwd, cur, runs);
|
package/bash-utils.mjs
CHANGED
|
@@ -75,8 +75,12 @@ const GIT_READ_SUBCMDS = new Set([
|
|
|
75
75
|
// intentionally excluded — they appear too often in benign search/log output. Gates
|
|
76
76
|
// the bugfix-shape save-nudge (lib/cite-back-hint.mjs) so `node cli.mjs search "error"`
|
|
77
77
|
// + an edit in the same episode no longer looks like an unsaved fix.
|
|
78
|
+
// D#734: only spaces/tabs between the `\n` and `at` (a frame is indented on its own line). With
|
|
79
|
+
// `\s+` there, every newline of a blank run started a match that ran to the run's end and back:
|
|
80
|
+
// 100k newlines took ~2.8 s per call. Replayed over 44,630 real exit-0 Bash results
|
|
81
|
+
// (2026-11-03), the narrower prefix changed no isHardError verdict.
|
|
78
82
|
const HARD_ERROR_RE =
|
|
79
|
-
/\bERR!|\bpanic\b|traceback|segfault|core dumped|\benoent\b|command not found|assertion\s?error|\n\
|
|
83
|
+
/\bERR!|\bpanic\b|traceback|segfault|core dumped|\benoent\b|command not found|assertion\s?error|\n[ \t]+at\s+\S|(?:type|reference|range|syntax|eval|uri)error:/i;
|
|
80
84
|
|
|
81
85
|
// Commands that only set the shell up for the next one. They neither make a command
|
|
82
86
|
// read-only nor stop it being one: `cd repo && grep …` is a grep. This matters because
|
|
@@ -886,7 +890,7 @@ function collectErrorTerms(cmd, response) {
|
|
|
886
890
|
// `fail`, no `not found` — npm says "no such file") and `panic: assignment to entry
|
|
887
891
|
// in nil map`, while letting `panic: runtime error: …` through purely because that
|
|
888
892
|
// message happens to contain the substring `error`.
|
|
889
|
-
// Note HARD_ERROR_RE's `\n\
|
|
893
|
+
// Note HARD_ERROR_RE's `\n[ \t]+at\s+\S` alternative cannot match a single line (it
|
|
890
894
|
// needs the preceding newline); that is fine — it is a stack-frame anchor, and the
|
|
891
895
|
// frames it guards are accompanied by a line the other alternatives do catch.
|
|
892
896
|
const errLines = String(response || '')
|
package/claudemd.mjs
CHANGED
|
@@ -15,7 +15,20 @@
|
|
|
15
15
|
//
|
|
16
16
|
// See docs/CLAUDE-MD-STEERING-PLAN.md for rationale + migration.
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
readFileSync,
|
|
20
|
+
existsSync,
|
|
21
|
+
unlinkSync,
|
|
22
|
+
mkdirSync,
|
|
23
|
+
rmdirSync,
|
|
24
|
+
readdirSync,
|
|
25
|
+
lstatSync,
|
|
26
|
+
openSync,
|
|
27
|
+
fstatSync,
|
|
28
|
+
closeSync,
|
|
29
|
+
readSync,
|
|
30
|
+
constants as fsConstants,
|
|
31
|
+
} from 'fs';
|
|
19
32
|
import { atomicWriteFileSync as atomicWrite } from './lib/atomic-write.mjs';
|
|
20
33
|
import { join, basename } from 'path';
|
|
21
34
|
import { createHash } from 'crypto';
|
|
@@ -174,7 +187,9 @@ function isOwnImportsOnly(rest, slug) {
|
|
|
174
187
|
export function holdsOnlyOwnLines(p, slug) {
|
|
175
188
|
try {
|
|
176
189
|
if (!existsSync(p)) return false;
|
|
177
|
-
const
|
|
190
|
+
const text = readRegularText(p);
|
|
191
|
+
if (text === null) return false;
|
|
192
|
+
const rest = text.replace(blockRegexG(slug), '');
|
|
178
193
|
return rest.trim() === '' || isOwnImportsOnly(rest, slug);
|
|
179
194
|
} catch {
|
|
180
195
|
return false;
|
|
@@ -199,7 +214,9 @@ const ANY_BLOCK_RE_G =
|
|
|
199
214
|
export function holdsOnlyPluginLines(p, slug) {
|
|
200
215
|
try {
|
|
201
216
|
if (!existsSync(p)) return false;
|
|
202
|
-
const
|
|
217
|
+
const text = readRegularText(p);
|
|
218
|
+
if (text === null) return false;
|
|
219
|
+
const rest = text.replace(blockRegexG(slug), '').replace(ANY_BLOCK_RE_G, '');
|
|
203
220
|
return rest.trim() === '' || isOwnImportsOnly(rest, slug);
|
|
204
221
|
} catch {
|
|
205
222
|
return false;
|
|
@@ -264,6 +281,40 @@ export function readBlock(cwd, slug) {
|
|
|
264
281
|
return readBlockAt(claudeMdPath(cwd), slug);
|
|
265
282
|
}
|
|
266
283
|
|
|
284
|
+
// Claude Code 2.1.322 skips an instruction file that is "not a regular file or exceeds 4194304 byte
|
|
285
|
+
// limit" (its own message).
|
|
286
|
+
const INSTRUCTION_FILE_MAX_BYTES = 4194304;
|
|
287
|
+
|
|
288
|
+
// A regular file's text, or null for one Claude Code would not load: a FIFO or a device, or over its
|
|
289
|
+
// size limit. The session sync reads instruction files in every directory above the project
|
|
290
|
+
// (D#509(4)), /tmp among them, where any local user can put a FIFO (a blocking read stalled
|
|
291
|
+
// SessionStart, v6.32.0 pre-release defects review F1) or a huge file (read whole, it filled memory,
|
|
292
|
+
// delta review R2-1). Opened non-blocking and checked on the descriptor, so a file swapped in after
|
|
293
|
+
// the check is not the one read. The size fstat reports is no bound — a /proc file reports 0 and
|
|
294
|
+
// never ends, and a file can grow — so at most one byte past the limit is read, as Claude Code's own
|
|
295
|
+
// bounded read does (round-3 review F1). A directory still throws EISDIR, as a plain read did.
|
|
296
|
+
function readRegularText(p) {
|
|
297
|
+
const fd = openSync(p, fsConstants.O_RDONLY | (fsConstants.O_NONBLOCK ?? 0));
|
|
298
|
+
try {
|
|
299
|
+
const st = fstatSync(fd);
|
|
300
|
+
if (st.isDirectory()) throw Object.assign(new Error(`${p}: is a directory`), { code: 'EISDIR' });
|
|
301
|
+
if (!st.isFile() || st.size > INSTRUCTION_FILE_MAX_BYTES) return null;
|
|
302
|
+
const chunks = [];
|
|
303
|
+
let total = 0;
|
|
304
|
+
for (;;) {
|
|
305
|
+
const chunk = Buffer.allocUnsafe(65536);
|
|
306
|
+
const n = readSync(fd, chunk, 0, chunk.length, null);
|
|
307
|
+
if (n === 0) break;
|
|
308
|
+
total += n;
|
|
309
|
+
if (total > INSTRUCTION_FILE_MAX_BYTES) return null;
|
|
310
|
+
chunks.push(chunk.subarray(0, n));
|
|
311
|
+
}
|
|
312
|
+
return Buffer.concat(chunks, total).toString('utf8');
|
|
313
|
+
} finally {
|
|
314
|
+
closeSync(fd);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
267
318
|
/**
|
|
268
319
|
* readBlock for any instructions file — CLAUDE.md, or the CLAUDE.local.md that auto-adopt
|
|
269
320
|
* writes (lib/local-steering.mjs). One parser, so both files get the same CRLF, orphan and
|
|
@@ -274,7 +325,8 @@ export function readBlock(cwd, slug) {
|
|
|
274
325
|
*/
|
|
275
326
|
export function readBlockAt(p, slug) {
|
|
276
327
|
if (!existsSync(p)) return { exists: false, version: null, body: null, raw: '' };
|
|
277
|
-
const raw =
|
|
328
|
+
const raw = readRegularText(p);
|
|
329
|
+
if (raw === null) return { exists: true, version: null, body: null, raw: '' };
|
|
278
330
|
const m = raw.match(blockRegex(slug));
|
|
279
331
|
if (!m) return { exists: true, version: null, body: null, raw };
|
|
280
332
|
// Normalize CRLF in the captured body so drift comparison (needsRefresh) is
|
|
@@ -374,7 +426,7 @@ export function needsRefresh(cwd, { slug, version, block, doc }) {
|
|
|
374
426
|
if (!existsSync(dp)) return true;
|
|
375
427
|
let cur;
|
|
376
428
|
try {
|
|
377
|
-
cur =
|
|
429
|
+
cur = readRegularText(dp);
|
|
378
430
|
} catch {
|
|
379
431
|
return true;
|
|
380
432
|
}
|
package/commands/adopt.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: adopt
|
|
3
|
-
description: "Use when: user asks to put the claude-mem-lite steering block into the current project's CLAUDE.md (for example to share it with the team), or to (re)install it there. Writes a sentinel-wrapped managed block into <cwd>/CLAUDE.md plus a <cwd>/.claude/plugin_claude_mem_lite.md detail doc, removes the auto-written local copy (CLAUDE.local.md or .claude/rules/claude-mem-lite.md), and migrates away any legacy memory-dir sentinel. Auto-adopt never adds the block to CLAUDE.md itself; it only keeps an existing one in sync. Run /unadopt to remove."
|
|
3
|
+
description: "Use when: user asks to put the claude-mem-lite steering block into the current project's CLAUDE.md (for example to share it with the team), or to (re)install it there. Writes a sentinel-wrapped managed block into <cwd>/CLAUDE.md plus a <cwd>/.claude/plugin_claude_mem_lite.md detail doc, removes the auto-written local copy (CLAUDE.local.md or .claude/rules/claude-mem-lite.md) when run at the repository root, and migrates away any legacy memory-dir sentinel. Auto-adopt never adds the block to CLAUDE.md itself; it only keeps an existing one in sync. Run /unadopt to remove."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# /adopt
|
|
@@ -12,13 +12,17 @@ in the project's memory-dir `MEMORY.md`: that index belongs to the user's own
|
|
|
12
12
|
memories.
|
|
13
13
|
|
|
14
14
|
Auto-adopt does not add the block to `CLAUDE.md`: in a git repository it keeps the same block
|
|
15
|
-
in `CLAUDE.local.md` at the repository root, excluded from git through `.git/info/exclude`.
|
|
16
|
-
|
|
15
|
+
in `CLAUDE.local.md` at the repository root, excluded from git through `.git/info/exclude`. Where Claude Code already loads the current block from a `CLAUDE.md` or
|
|
16
|
+
`CLAUDE.local.md` above the repository root (outside git, above the session's directory; in a `claude --worktree` session,
|
|
17
|
+
the main checkout's `CLAUDE.local.md`), no local copy is written and nothing is added, unless your user or project settings
|
|
18
|
+
set `claudeMdExcludes`.
|
|
19
|
+
Otherwise, next to an `AGENTS.md` that file would switch off, and where it cannot be written (outside git,
|
|
17
20
|
for example), it adds the text to each session's context instead; with
|
|
18
21
|
`CLAUDE_MEM_RULES_STEERING=1` it keeps the block in `.claude/rules/claude-mem-lite.md` next to
|
|
19
22
|
an `AGENTS.md`, excluded the same way. Run `/adopt` when you want the block in `CLAUDE.md` — a file that is normally committed,
|
|
20
|
-
so your team gets it too.
|
|
21
|
-
`CLAUDE.md`
|
|
23
|
+
so your team gets it too. Run at the repository root, it removes the local copy so the text does not load twice. While auto-adopt is on, a session started
|
|
24
|
+
in the directory whose `CLAUDE.md` carries the block refreshes it when the shipped template changes and, where that file holds
|
|
25
|
+
nothing but the block, adds the `AGENTS.md` import described below.
|
|
22
26
|
|
|
23
27
|
## What it writes
|
|
24
28
|
|
package/install.mjs
CHANGED
|
@@ -1341,8 +1341,9 @@ function configureHooks() {
|
|
|
1341
1341
|
};
|
|
1342
1342
|
|
|
1343
1343
|
// P0 subagent dispatch-time injection (default off — CLAUDE_MEM_SUBAGENT_INJECT).
|
|
1344
|
-
// Fires on the Agent/Task dispatch so a subagent
|
|
1345
|
-
// can receive one relevant lesson via updatedInput
|
|
1344
|
+
// Fires on the Agent/Task dispatch so a subagent, which starts without the SessionStart
|
|
1345
|
+
// context, can receive one relevant lesson via updatedInput before its first tool call.
|
|
1346
|
+
// Parity with hooks/hooks.json.
|
|
1346
1347
|
// Behind the bash prefilter since 2026-08-22 (audit P2-5): the flag is off by
|
|
1347
1348
|
// default, and a disabled feature was starting a Node interpreter on every single
|
|
1348
1349
|
// Agent dispatch (22.6ms → 2.4ms; see scripts/pre-agent-inject.sh). The prefilter
|
package/lib/local-steering.mjs
CHANGED
|
@@ -61,6 +61,11 @@ export const LOCAL_MD = 'CLAUDE.local.md';
|
|
|
61
61
|
/** The rules file used where CLAUDE.local.md would switch AGENTS.md off, relative to the top-level. */
|
|
62
62
|
export const RULES_MD = '.claude/rules/claude-mem-lite.md';
|
|
63
63
|
|
|
64
|
+
/** Where ensureSteeringDetailDoc keeps the detail doc, without writing it (adopt --status reads). */
|
|
65
|
+
export function steeringDetailDocPath() {
|
|
66
|
+
return join(resolveDataDir(process.env.CLAUDE_MEM_DIR), 'plugin_claude_mem_lite.md');
|
|
67
|
+
}
|
|
68
|
+
|
|
64
69
|
/**
|
|
65
70
|
* The detail doc the block points at, kept in the plugin's data dir (never in the project:
|
|
66
71
|
* both the injected and the CLAUDE.local.md block carry its absolute path). Rewritten only
|
|
@@ -69,7 +74,7 @@ export const RULES_MD = '.claude/rules/claude-mem-lite.md';
|
|
|
69
74
|
* @returns {string} absolute path
|
|
70
75
|
*/
|
|
71
76
|
export function ensureSteeringDetailDoc() {
|
|
72
|
-
const p =
|
|
77
|
+
const p = steeringDetailDocPath();
|
|
73
78
|
const doc = getDetailDoc();
|
|
74
79
|
let current = null;
|
|
75
80
|
try {
|
package/lib/task-imperative.mjs
CHANGED
|
@@ -30,8 +30,9 @@ export function formatTaskImperative(lesson, id) {
|
|
|
30
30
|
return `${TASK_IMPERATIVE_PREFIX} You must: ${body}.${tag}`;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
// Subagent-dispatch framing.
|
|
34
|
-
// inside
|
|
33
|
+
// Subagent-dispatch framing. A subagent starts without the SessionStart context (plugin
|
|
34
|
+
// hooks do fire inside it, so recall arrives with its first tool call; #8848 no longer
|
|
35
|
+
// holds); the P0 dispatch hook (scripts/pre-agent-inject.js) APPENDS
|
|
35
36
|
// this block to a spawned subagent's prompt via PreToolUse updatedInput. This is
|
|
36
37
|
// deliberately NOT the "You must:" imperative above: Phase-0b measured live
|
|
37
38
|
// (2026-07-03) that a raw imperative PREPEND trips the subagent's own
|
package/mem-cli.mjs
CHANGED
|
@@ -3020,9 +3020,9 @@ function _reportSidechainCiteRecall({ days, json }) {
|
|
|
3020
3020
|
);
|
|
3021
3021
|
if (sidechain.files > 0 && sidechain.injected === 0) {
|
|
3022
3022
|
out(' → subagent transcripts exist but none carried a detectable memory injection in');
|
|
3023
|
-
out(' this window
|
|
3024
|
-
out(' time surface (pre-agent-inject.js, CLAUDE_MEM_SUBAGENT_INJECT)
|
|
3025
|
-
out(' a lesson
|
|
3023
|
+
out(' this window: neither PreToolUse recall inside the subagents nor the dispatch-');
|
|
3024
|
+
out(' time surface (pre-agent-inject.js, CLAUDE_MEM_SUBAGENT_INJECT, off by default)');
|
|
3025
|
+
out(' put a lesson in front of them.');
|
|
3026
3026
|
} else if (sidechain.files === 0) {
|
|
3027
3027
|
out(' → no subagent transcripts in window.');
|
|
3028
3028
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-mem-lite",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.32.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "claude-mem-lite",
|
|
9
|
-
"version": "6.
|
|
9
|
+
"version": "6.32.0",
|
|
10
10
|
"os": [
|
|
11
11
|
"darwin",
|
|
12
12
|
"linux",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@eslint/js": "^10.0.1",
|
|
25
|
-
"@vitest/coverage-v8": "^5.0
|
|
25
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
26
26
|
"acorn": "8.19.0",
|
|
27
|
-
"eslint": "^10.
|
|
27
|
+
"eslint": "^10.14.0",
|
|
28
28
|
"fast-check": "^4.10.2",
|
|
29
|
-
"knip": "^6.
|
|
29
|
+
"knip": "^6.44.1",
|
|
30
30
|
"picomatch": "^4.0.4",
|
|
31
31
|
"prettier": "3.9.10",
|
|
32
32
|
"vitest": "^5.0.3"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-mem-lite",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.32.0",
|
|
4
4
|
"description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "npm@10.9.2",
|
|
@@ -250,11 +250,11 @@
|
|
|
250
250
|
},
|
|
251
251
|
"devDependencies": {
|
|
252
252
|
"@eslint/js": "^10.0.1",
|
|
253
|
-
"@vitest/coverage-v8": "^5.0
|
|
253
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
254
254
|
"acorn": "8.19.0",
|
|
255
|
-
"eslint": "^10.
|
|
255
|
+
"eslint": "^10.14.0",
|
|
256
256
|
"fast-check": "^4.10.2",
|
|
257
|
-
"knip": "^6.
|
|
257
|
+
"knip": "^6.44.1",
|
|
258
258
|
"picomatch": "^4.0.4",
|
|
259
259
|
"prettier": "3.9.10",
|
|
260
260
|
"vitest": "^5.0.3"
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// claude-mem-lite: PreToolUse:Agent|Task hook — subagent dispatch-time memory injection.
|
|
3
|
-
//
|
|
3
|
+
// Plugin hooks do fire inside subagents now (#8848 no longer holds: subagent transcripts on one
|
|
4
|
+
// machine carry PreToolUse recall, 2026-11-10), but a subagent starts
|
|
5
|
+
// without the SessionStart context, so it sees no memory before its first tool call. This hook
|
|
4
6
|
// injects ONE relevant project lesson into a dispatched subagent's prompt by mutating
|
|
5
7
|
// tool_input.prompt via hookSpecificOutput.updatedInput. Verified live 2026-07-03
|
|
6
8
|
// (Phase 0a: the mutation reaches the subagent's task-prompt position; Phase 0b: an
|
|
7
9
|
// appended, attributed, reference-only block is adopted, whereas a raw imperative
|
|
8
|
-
// prepend trips the subagent's own prompt-injection detector and is refused).
|
|
10
|
+
// prepend trips the subagent's own prompt-injection detector and is refused). It writes no
|
|
11
|
+
// cooldown or injected-id marker for the subagent's thread (its agent_id is not known at
|
|
12
|
+
// dispatch), so the subagent's own PreToolUse recall can show the same lesson again.
|
|
9
13
|
//
|
|
10
14
|
// DEFAULT OFF (CLAUDE_MEM_SUBAGENT_INJECT=on|1). The off path costs one env check and
|
|
11
15
|
// returns — no stdin read, no DB, no heavy imports (schema/better-sqlite3 are dynamic,
|