memfresh 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ First release.
6
+
7
+ - `memfresh check`: missing-path, missing-script, stale-reference, stale-age, contradiction, duplicate, budget, secret-like, broken-import and agents-not-loaded checks across CLAUDE.md, AGENTS.md, GEMINI.md, Cursor rules, Copilot/Windsurf/Cline files, Claude Code auto-memory and Codex files.
8
+ - `memfresh list`, `memfresh snapshot`, `memfresh diff`, `memfresh init --ci`.
9
+ - `--json` output (schemaVersion 1), `--ci` / `--fail-on`, `--limit`, `.memfresh.json` config, inline `<!-- memfresh-ignore -->` comments.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bosco Foulsham
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,265 @@
1
- # Temporary Holding Version
1
+ # memfresh
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Check your coding agents' memory and instruction files (CLAUDE.md, AGENTS.md, Claude Code auto-memory, Cursor rules and friends) for stale facts, contradictions, duplicates and silent truncation, in one command.
4
+
5
+ ## Why
6
+
7
+ I run Claude Code and Codex on the same long-lived repo, and kept finding that one of them was following a convention we dropped months ago, or that the end of a memory file was never being loaded at all. Nobody can see either problem: the agent just behaves oddly. Other people have hit the same wall:
8
+
9
+ - [anthropics/claude-code#82056](https://github.com/anthropics/claude-code/issues/82056): "A session cannot determine whether its auto-memory index loaded whole, truncated, or not at all".
10
+ - [openai/codex#13386](https://github.com/openai/codex/issues/13386): "AGENTS.md is silently truncated and instructions near the end ignored".
11
+ - Hacker News, ["Writing a good Claude.md"](https://news.ycombinator.com/item?id=46098838) (748 points when I checked).
12
+
13
+ memfresh reads the files the same way the tools do, checks them against your repo and its git history, and tells you what is wrong and where. It does not call any model, send anything anywhere, or change your files.
14
+
15
+ ## Real output
16
+
17
+ This is the output of `memfresh` on the demo project built by `examples/make-demo.sh` (invented data, fixed git history, so it is reproducible; a test checks that this block matches a real run):
18
+
19
+ ```text
20
+ $ memfresh --root /tmp/memfresh-demo/repo --claude-memory-dir /tmp/memfresh-demo/memory --no-user
21
+ memfresh: checked 6 files (4 project, 2 user scope)
22
+
23
+ .cursor/rules/style.mdc
24
+ 5 warn contradiction conflicting indentation: spaces:2 (.cursor/rules/style.mdc:5) vs spaces:4 (AGENTS.md:5)
25
+ fix: Decide which is right, then update every file to say the same thing (ideally keep it in one file and import it).
26
+ 6 warn contradiction always/never rule conflict: "never use semicolons" (.cursor/rules/style.mdc:6) vs "always use semicolons" (CLAUDE.md:17)
27
+ fix: Keep one of the two rules and delete or reword the other.
28
+ AGENTS.md
29
+ 1 info agents-not-loaded Claude Code reads CLAUDE.md instead of AGENTS.md when a CLAUDE.md exists in the working directory or above it, and none of them imports this file, so these instructions are not loaded by Claude Code
30
+ fix: Add `@AGENTS.md` to a CLAUDE.md in the same directory (or one above), or set Claude Code's project-instructions mode to claude-md-and-agents-md.
31
+ 4 warn contradiction conflicting package manager: pnpm (AGENTS.md:4) vs npm (CLAUDE.md:6) (pnpm-lock.yaml is present, which is pnpm's lockfile)
32
+ fix: Decide which is right, then update every file to say the same thing (ideally keep it in one file and import it).
33
+ 6 info duplicate "- Keep functions small and name them after what they do." also appears in CLAUDE.md:18
34
+ fix: Keep it in one file and import or link it from the others (for example `@AGENTS.md` from CLAUDE.md).
35
+ CLAUDE.md
36
+ 1 info stale-age last changed 2025-02-03 (git); 12 commits have touched the 2 paths it references since
37
+ fix: Re-read it against the code and update anything that has drifted.
38
+ 7 error missing-script `npm run lint:fix` refers to a script that is not in package.json
39
+ fix: package.json has: lint. Use one of those or remove the line.
40
+ 11 warn stale-reference `src/legacy/auth.ts` was renamed to `src/auth/login.ts` in f49c6ea (2025-04-02)
41
+ fix: Replace the reference with `src/auth/login.ts`.
42
+ 21 warn contradiction conflicting Node version: node 18 (CLAUDE.md:21) (engines.node >=20 in package.json)
43
+ fix: Decide which is right, then update every file to say the same thing (ideally keep it in one file and import it).
44
+ claude-memory:MEMORY.md [user scope]
45
+ 201 error budget MEMORY.md has 230 lines / 17.3 KiB; Claude Code loads only the first 200 lines or 25.0 KiB, whichever comes first, so lines 201-230 are never loaded (cut by the 200-line limit)
46
+ fix: Move detail into topic files and keep MEMORY.md to one line per entry (https://code.claude.com/docs/en/memory#how-it-works).
47
+ services/billing/AGENTS.md
48
+ 1 info agents-not-loaded Claude Code reads CLAUDE.md instead of AGENTS.md when a CLAUDE.md exists in the working directory or above it, and none of them imports this file, so these instructions are not loaded by Claude Code
49
+ fix: Add `@AGENTS.md` to a CLAUDE.md in the same directory (or one above), or set Claude Code's project-instructions mode to claude-md-and-agents-md.
50
+ 316 warn budget 34.6 KiB file exceeds Codex's 32.0 KiB project AGENTS.md limit (documented default) for sessions started in services/billing: Codex truncates it at 31.8 KiB, about line 316, so everything after that is never loaded
51
+ fix: Shorten it, split instructions across nested directories, or raise project_doc_max_bytes in ~/.codex/config.toml.
52
+
53
+ 12 findings: 2 errors, 6 warnings, 4 info
54
+ ```
55
+
56
+ A demo with consistent files produces nothing (build it first with `bash examples/make-demo.sh /tmp/memfresh-demo-clean clean`):
57
+
58
+ ```text
59
+ $ memfresh --root /tmp/memfresh-demo-clean/repo --no-user --ci
60
+ memfresh: checked 3 files (3 project, 0 user scope)
61
+
62
+ No findings.
63
+
64
+ 0 findings: 0 errors, 0 warnings, 0 info
65
+ ```
66
+
67
+ ## Quickstart
68
+
69
+ ```sh
70
+ npm install -g memfresh
71
+ cd your-project
72
+ memfresh
73
+ ```
74
+
75
+ To see it work on the demo first (about two seconds):
76
+
77
+ ```sh
78
+ bash "$(npm root -g)/memfresh/examples/make-demo.sh" /tmp/memfresh-demo
79
+ memfresh --root /tmp/memfresh-demo/repo --claude-memory-dir /tmp/memfresh-demo/memory --no-user
80
+ ```
81
+
82
+ **Try it before it's published.** memfresh is not on npm yet. From a checkout of this repo:
83
+
84
+ ```sh
85
+ npm pack # writes memfresh-0.1.0.tgz
86
+ npm install -g ./memfresh-0.1.0.tgz
87
+ memfresh --help
88
+ ```
89
+
90
+ Needs Node 22 or later. git is optional but two checks (stale-reference, stale-age) and `diff` history need it. No other dependencies.
91
+
92
+ ## Usage
93
+
94
+ ```text
95
+ memfresh [check] [options] check files and report findings (default)
96
+ memfresh list [options] table of every memory/instruction file found
97
+ memfresh snapshot [options] copy the files into .memfresh/snapshots/<timestamp>/
98
+ memfresh diff [options] what changed in memory (git history or snapshots)
99
+ memfresh init --ci write a GitHub Actions workflow
100
+ ```
101
+
102
+ Every command takes `--help` and `--version`.
103
+
104
+ | Option | Applies to | Meaning |
105
+ | --- | --- | --- |
106
+ | `--root <dir>` | all | Project to check (default: the git top-level of the current directory, or the directory itself outside git). |
107
+ | `--user` / `--no-user` | check, list, snapshot, diff | Include or skip user scope. By default whatever exists is included and labelled `[user scope]`. |
108
+ | `--claude-memory-dir <dir>` | check, list, snapshot, diff | Claude Code auto-memory directory, overriding the derived path. An explicit directory is read even with `--no-user` (and reported as user scope). Also the escape hatch if the derivation is wrong on your machine (see Limits). |
109
+ | `--json` | check, list, snapshot, diff | Machine-readable output. `check --json` has `schemaVersion: 1` with `files`, `findings` (`id`, `severity`, `file`, `line`, `message`, `fix`, `related`), `summary` and `notes`. |
110
+ | `--ci` | check | Exit 1 if there are findings at or above `--fail-on` (default: errors only). |
111
+ | `--fail-on warn\|error` | check | Threshold for `--ci` (default `error`; giving it implies `--ci`). `warn` is the strict mode. Info findings never fail a build. |
112
+ | `--limit key=N\|off` | check, list | Override a load limit (see Configuration). Repeatable. |
113
+ | `--max-import-depth <n>` | all discovery | `@import` depth, default 4. |
114
+ | `--config <file>` | all discovery | JSON config; default `<root>/.memfresh.json` if present. |
115
+ | `--since <date\|snapshot>` | diff | `2026-11-01`, `"2 weeks ago"`, a snapshot name (or prefix including the time), or `latest`. Default: 30 days ago. |
116
+ | `--dry-run` | snapshot, init | Say what would be written and write nothing. |
117
+ | `--force` | init | Replace an existing workflow file. Without it memfresh refuses to overwrite. |
118
+
119
+ **Exit codes:** `0` fine (or findings without `--ci`); `1` findings at or above the threshold with `--ci`; `2` usage or runtime error (one-line message on stderr, no stack trace unless `MEMFRESH_DEBUG=1`).
120
+
121
+ Colour is used only when stdout is a terminal; `NO_COLOR` turns it off, `FORCE_COLOR` forces it. JSON is never coloured.
122
+
123
+ ### What gets read
124
+
125
+ | File | Read by | Status |
126
+ | --- | --- | --- |
127
+ | `CLAUDE.md`, `.claude/CLAUDE.md`, `CLAUDE.local.md` (root and nested), `~/.claude/CLAUDE.md`, `.claude/rules/**/*.md`, `~/.claude/rules/` | Claude Code | Verified against the [Claude Code memory docs](https://code.claude.com/docs/en/memory) (fetched 3 Dec 2026). |
128
+ | `@path` imports inside the above and inside AGENTS.md | Claude Code | Verified (same page): relative to the importing file, code spans and fences skipped, four hops deep. The task spec said five; the docs say four, so four is the default and `--max-import-depth` changes it. |
129
+ | Auto-memory: `~/.claude/projects/<project>/memory/MEMORY.md` plus topic files | Claude Code | Location, index and load limit verified (same page). The `<project>` name is derived as the git root path with every non-alphanumeric character turned into `-` (the [sessions docs](https://code.claude.com/docs/en/sessions) give that rule for transcript directories). **Not checked against a real `~/.claude/projects` here: there is none on the build machine.** Also honoured: `autoMemoryDirectory` in settings, `CLAUDE_CONFIG_DIR`, `CLAUDE_CODE_PROJECT_DIR_NAME`. |
130
+ | `AGENTS.md` (root and nested) | Codex (and Claude Code when no CLAUDE.md exists) | Verified against the [Codex AGENTS.md guide](https://developers.openai.com/codex/guides/agents-md) (fetched 3 Dec 2026; it redirects to learn.chatgpt.com) and the Claude Code memory docs. |
131
+ | `~/.codex/AGENTS.md` | Codex only | Codex's global file. Claude Code reads AGENTS.md only in the working directory and the directories above it, so it does not read this one. `CODEX_HOME` is honoured. |
132
+ | `AGENTS.override.md` (root and nested) | Codex only | Codex prefers it over AGENTS.md in the same directory. Claude Code's memory docs list it as not read. An empty override still wins, so it hides AGENTS.md. |
133
+ | `.claude/AGENTS.md` | Claude Code (when no CLAUDE.md exists) | Not part of the Codex chain or budget: Codex reads AGENTS files from the project root down to the directory it starts in, and nobody starts it in `.claude/`. |
134
+ | `~/.codex/memories/*.md` and `*.txt` | Codex memories | The format is not covered by the page I could read, so these are listed and scanned for secrets only. Database files there are ignored. |
135
+ | `.cursor/rules/**/*.mdc` (`description`, `globs`, `alwaysApply`), `.cursorrules` | Cursor | **Unverified against Cursor's own docs** (see Limits). |
136
+ | `GEMINI.md`, `.github/copilot-instructions.md`, `.windsurfrules`, `.clinerules` (file or directory) | Gemini CLI, Copilot, Windsurf, Cline | File names taken from the project spec, **not re-checked against each vendor's docs**. Only the checks that need no tool-specific knowledge apply. |
137
+
138
+ ### Checks
139
+
140
+ | id | severity | what it finds |
141
+ | --- | --- | --- |
142
+ | `missing-path` | warn | A backticked or obvious relative path (or link target) that does not exist. Also `globs`/`paths` frontmatter that matches no file. |
143
+ | `stale-reference` | warn (info for history notes) | A missing path that git history shows was deleted or renamed, with the commit and the new path when it was renamed (files and directories, followed through repeated renames). |
144
+ | `missing-script` | error / warn / info | `npm run X` / `pnpm run X` / `bun run X` where X is not in package.json (nearest package.json, root, `cd dir &&`, and workspace packages), `make X` with no such target in a Makefile memfresh can read completely (pattern and catch-all rules and includes are honoured), `just X` with no such recipe: error. Script names are taken whole, so `pnpm test:unit` and `pnpm test-ci` are looked up as `test:unit` and `test-ci`, not as `test`. `make X` with no Makefile at all, or `just X` with no justfile: warn. Bare `pnpm X` / `yarn X` / `yarn run X` that could be a dependency binary (a name with a colon is treated as a script name, not a binary, so `pnpm test:integration` is an error), or a script that exists only in another package.json: info. |
145
+ | `contradiction` | warn (info across user and project scope) | Package manager (also against the lockfile and `packageManager`), test runner, indentation (also against Prettier `useTabs`, Biome `indentStyle` and `indent_style` in the `[*]` section of `.editorconfig`, for rules that name no language or file kind), quote style, formatter (also against what is configured), Node and Python versions (also against `.nvmrc`, `engines`, `.tool-versions`, `pyproject.toml`), and `always X` against `never X`. Both locations are reported. |
146
+ | `duplicate` | info | The same instruction (normalised, similarity 0.9 or more) in different files. |
147
+ | `budget` | error / warn / info | Parts of files the owning tool will not load. See below. |
148
+ | `secret-like` | error / warn | Provider-prefixed API keys and tokens and private key blocks are errors. Looser shapes (JWTs, URL passwords, `password = ...` assignments) are warnings, and local development hosts (`localhost`, `db`, `*.local` and similar) and `user:user@` URLs are skipped. Always masked in output. |
149
+ | `broken-import` | error / warn / info | `@path` that does not resolve (error when written as an explicit path or at the start of a line, warn when it could be prose such as `@types/node`), deeper than the limit (warn), or loops (info). Imports that resolve outside the project are not read (info). |
150
+ | `agents-not-loaded` | info (warn for override) | AGENTS.md beside a CLAUDE.md that does not import it (Claude Code reads CLAUDE.md instead, per its docs), or AGENTS.md shadowed by AGENTS.override.md (Codex reads one file per directory). |
151
+ | `internal-error` | info | A check threw on this file (a memfresh bug). The rest of the report is unaffected; `--debug` shows the stack. |
152
+ | `stale-age` | info | A memory file untouched for 90+ days while 10+ commits have changed the files it references. Uses the git commit date for tracked files and the file's mtime for untracked ones. |
153
+
154
+ **Budget limits, each with its source.** Defaults appear only where I could cite them:
155
+
156
+ | key | default | source |
157
+ | --- | --- | --- |
158
+ | `claude.memory.lines` | 200 | MEMORY.md: "the first 200 lines or 25KB ... whichever comes first" ([docs](https://code.claude.com/docs/en/memory#how-it-works)) |
159
+ | `claude.memory.bytes` | 25 KiB | same sentence; the page says "25KB" without defining it, so I use the larger reading (25,600 bytes) rather than claim truncation that might not happen |
160
+ | `claude.file.bytes` | 4 MiB | "Claude Code skips a file over 4 MiB and loads none of it" (same page) |
161
+ | `claude.file.recommended-lines` | 200 | "target under 200 lines per CLAUDE.md file". A recommendation, reported as info only |
162
+ | `claude.ondemand.chars` | 40,000 | on-demand files (subdirectory CLAUDE.md, path-scoped rules) are cut to the start; 40,000 characters in 200K-context sessions, more on 1M-context models. Info only |
163
+ | `codex.agents.bytes` | 32 KiB | `project_doc_max_bytes` default, combined size of the project AGENTS.md files from the root down ([guide](https://developers.openai.com/codex/guides/agents-md)); the global `~/.codex/AGENTS.md` is not part of this budget. `project_doc_max_bytes` in `~/.codex/config.toml` is read and overrides it |
164
+ | `cursor.rule.lines`, `file.lines`, `file.bytes` | none | unverified or generic; opt in with `--limit` |
165
+
166
+ For MEMORY.md the finding gives the first line that is never loaded. For Codex, following its open-source loader rather than the guide, files are read in order until the budget is spent: the file that crosses the limit is truncated at the remaining bytes (a warning, with the line), and any later file gets nothing (an error). Separators between files are not counted.
167
+
168
+ ### Other commands
169
+
170
+ - `memfresh list` prints every file found, who reads it, scope, bytes, lines, last modified (git commit date when tracked, else mtime) and whether it is over a known limit.
171
+ - `memfresh snapshot` copies every discovered file, user scope and auto-memory included, into `.memfresh/snapshots/<timestamp>/files/` with a `manifest.json` (sha256, sizes, mtimes). `.memfresh/` carries its own `.gitignore` containing `*`. A snapshot never touches an earlier one. `--dry-run` lists what it would write.
172
+ - `memfresh diff` shows unified diffs grouped by file. Tracked files use git history since `--since` (each commit listed; commits that look agent-authored, by author name, email or a `Co-Authored-By` / "Generated with" trailer, are marked and their added lines counted) plus uncommitted changes. Untracked files, such as auto-memory, are compared with a snapshot, so run `memfresh snapshot` now to have a baseline for later.
173
+ - `memfresh init --ci` writes `.github/workflows/memfresh.yml` running `npx --yes memfresh@<version> check --ci --no-user --fail-on error` with full git history, so it fails only on near-certain problems (see Severity policy). The version is pinned to the one you ran; memfresh is not published to npm yet, so until it is, edit the step to install from wherever you host it. It refuses to overwrite an existing file unless you pass `--force`; `--dry-run` prints it.
174
+
175
+ ## Configuration
176
+
177
+ Everything has a default. Optionally put a `.memfresh.json` in the project root (or pass `--config`):
178
+
179
+ ```json
180
+ {
181
+ "staleDays": 90,
182
+ "staleCommits": 10,
183
+ "duplicateThreshold": 0.9,
184
+ "ignore": ["missing-path:legacy-notes/", "duplicate"],
185
+ "limits": { "codex.agents.bytes": 65536, "file.lines": 400 }
186
+ }
187
+ ```
188
+
189
+ - `ignore` entries are a check id, or `id:path` where `path` is a substring of the file path or a path glob (anything with `*`, `?`, `[` or `{`; a pattern without a slash matches at any depth), for example `"missing-path:docs/**"` or `"contradiction:**/CLAUDE.md"`. `*` as the id matches every check. A path rule applies to either location of a two-location finding. An unknown check id in `ignore` is an error that lists the valid ids; an unknown id in a comment directive is reported as a note (directives inside code fences are examples and are ignored).
190
+ - `limits` take the same keys as `--limit` (`off` disables one). Unknown keys are an error rather than silently ignored.
191
+ - Silence one line in a file with `<!-- memfresh-ignore -->` on it. A comment that stands alone on its line also covers the line below it, and `<!-- memfresh-ignore-next-line -->` always does. Add check ids to limit it (`<!-- memfresh-ignore missing-path, duplicate -->`).
192
+ - Silence a whole file with `<!-- memfresh-ignore-file -->`, or `<!-- memfresh-ignore-file contradiction -->` for chosen checks.
193
+ - A comment on either side of a two-location finding (a contradiction, a duplicate) silences it.
194
+
195
+ ### Severity policy
196
+
197
+ `error` is reserved for near-certain problems: a missing `npm run` script, a missing `make` target in a Makefile memfresh could parse completely, a missing `just` recipe, an `@import` written as an explicit path (or at the start of a line) that does not exist, a MEMORY.md that Claude Code truncates (or a file over its 4 MiB limit), a later Codex AGENTS.md that gets no budget, and provider-prefixed secrets and private keys. Everything that depends on reading English is `warn` or `info`: contradictions, path mentions in prose (including a path that git history shows was deleted or renamed, because the line may be a note about that very rename: `stale-reference` is a warning), duplicates and scoping. `--ci` fails on errors only; use `--fail-on warn` if you want warnings to fail too.
198
+
199
+ A line that already names the rename target ("renamed from `x`") is skipped entirely: there is nothing to report. A line that otherwise reads as history (moved, renamed, migrated, formerly, previously, used to, was, were, split, merged, old, older, legacy, dropped, retired, gone, deleted, became, superseded, "in favour of", or a year after in, until, before, during, by, as of or up to) is downgraded to `info` for a stale or missing path rather than reported as a live reference. An "exists in N other packages" match (a monorepo conversion) is checked first and also gives `info`.
200
+
201
+ ## Measured false-positive rate and recall
202
+
203
+ Six corpora of realistic, correct projects, all invented. They were written by me (two sets) and by four independent reviewers; the reviewers' files were used to find and fix false positives, so these numbers are a measure of the fixes, not of unseen repositories. Run with `memfresh --no-user` through the real CLI:
204
+
205
+ | corpus | projects | errors | warnings | info |
206
+ | --- | --- | --- | --- | --- |
207
+ | mine, round 1 (pnpm, Sphinx, Rust, Go, Rails, Next.js, Django, Gradle, Bun, Laravel, Docusaurus, multi-tool, Phoenix, .NET, SvelteKit) | 15 | 0 | 0 | 1 |
208
+ | mine, round 3 (Nx, Bazel, Unity C#, Flutter/Dart, Swift package, Haskell stack, Julia, R package, Ruby gem, Zig), written before running the tool and not adjusted | 10 | 0 | 0 | 0 |
209
+ | reviewer 2 | 18 | 0 | 0 | 3 |
210
+ | reviewer 3 | 16 | 0 | 0 | 3 |
211
+ | reviewer 4 (Nuxt, Angular, NestJS, Hugo, Bevy, Home Assistant, VS Code extension and others) | 20 | 0 | 0 | 6 |
212
+ | reviewer 5 (Hono, tRPC, Zed, Airflow, dbt, Helm, Bazel and others, with auto-memory) | 18 | 0 | 0 | 13 |
213
+ | **all** | **97** | **0** | **0** | **26** |
214
+
215
+ Recall on planted problems: **23 of 23** in the round-3 reviewer's set, **20 of 20** in the round-4 reviewer's set and **20 of 20** in the round-5 reviewer's set, all at warn or error. In round 4 the first run of that set, before the round-4 fixes, found 16 of 20: the misses were number words ("Two-space indentation"), a Karma/Jasmine versus Jest clash, a backticked path wrongly scoping a version line, and an always/never rule with a trailing "for screens"; a fifth, the verb "go" in a heading being read as the Go language, surfaced while fixing them. All five are fixed, so the 20 of 20 is again a measure of the fixes, not of unseen repositories. The round-5 set first scored 14 of 20 (70%). One miss was a real bug (`pnpm test:unit` read as `pnpm test`, so a missing `test:integration` was never reported); the rest were wording: "Prettier: tabs, single quotes", "gofmt (tabs)", "Unit tests use Vitest" against "Tests use Jest", the verb "touch", and "Always use Gson for JSON parsing" against "Never use Gson". All are fixed, so again the 20 of 20 measures the fixes. Expect lower recall on problems phrased in ways nobody has planted yet: the contradiction detectors only see wording they know. Two of the planted-set extras in round 3 are real: warnings for topic files linked from an over-long MEMORY.md that do not exist.
216
+
217
+ The test suite re-runs all six corpora and the planted sets on every `npm test` (`test/corpus*.test.js`).
218
+
219
+ ## How it works
220
+
221
+ memfresh finds the files (table above), parses each into lines with fenced code and frontmatter marked, and follows `@imports`. Each check works on those lines. Reference checks only trust what is strongly path-like or command-like and skip lines that talk about examples, creation, output, negation or "never". Contradiction detectors extract claims ("use pnpm", "2 spaces", "Node 18") and only compare claims that share a directory group, rule scope (`globs`/`paths`) and qualifier (language, "frontend", a path in backticks). Git history is read with a few `git log` calls; nothing is written except by `snapshot` and `init`, and no network access is ever made.
222
+
223
+ ## Limits
224
+
225
+ I would rather you knew these than found them out.
226
+
227
+ - **Cursor's format is unverified.** `cursor.com/docs/rules` redirected, from this machine, to another product's documentation page, so I could not confirm Cursor's rule format. `.cursor/rules/**/*.mdc` with `description`/`globs`/`alwaysApply` comes from the task spec. I do not apply any Cursor size limit by default.
228
+ - **GEMINI.md, Copilot, Windsurf and Cline files** are discovered by name only; I did not verify their loading rules, so they get no budget checks.
229
+ - **Auto-memory path derivation is unverified on a real install.** It follows the docs; if your directory is elsewhere use `--claude-memory-dir`. Names over 200 characters carry a hash I cannot compute, so memfresh looks for a directory with the same 200-character prefix.
230
+ - **Rule globs** (`paths:` in `.claude/rules`, `globs:` in Cursor rules) are matched with a small glob engine: `*`, `**`, `?`, `[abc]`, `[!abc]`, nested `{a,b}` braces (so `src/**/*.{ts,tsx}` works), a leading `/` to anchor at the rule's base directory, a trailing `/`, and `!` exclusions; commas split a list only outside braces. A pattern without a slash matches at any depth. Claude Code's behaviour is from its memory docs; Cursor's is assumed to be the same and is unverified.
231
+ - **Scoped rules are not compared with general ones.** A line that names a file kind (`Makefile`, YAML, SQL), a language, a package (`pnpm -F @acme/worker test`, "the worker uses ...") or a path is scoped, and only conflicts with another line scoped the same way.
232
+ - **Internal errors do not stop the run.** If a check throws on a file, that file gets an `internal-error` info finding, the check is re-run without it, and the rest of the report is produced. `--debug` (or `MEMFRESH_DEBUG=1`) prints the stack trace to stderr.
233
+ - **Codex config:** `project_doc_max_bytes` is read from the top level of `~/.codex/config.toml` only (not from profile tables); a project-level `.codex/config.toml` is not read.
234
+ - **Scoping trades recall for precision.** A rule under a heading that names a language, package or path (when the file has at least two such headings), a Cursor rule without globs that is not always-on, and anything that names a file kind or package is only compared with rules scoped the same way. A real conflict between a scoped and a general rule is therefore not reported.
235
+ - **Build output is decided by `.gitignore`** when git is available; without git, `dist/`, `build/`, `out/`, `target/`, `vendor/` and `coverage/` are skipped only at the root or beside a project manifest. Nested git repositories and worktrees are not entered.
236
+ - **A Makefile target named by a variable** (`$(LOCALBIN):`) is ignored; `$(eval ...)`, `$(foreach ...)` and `include` still stop memfresh from checking `make` targets, because they can define any name.
237
+ - **Heuristics produce false positives and misses.** Claims are matched with regular expressions, not understanding. "Use Node 18 for the legacy service" in a general file may be flagged against `.nvmrc`; a contradiction phrased in a way I did not anticipate is missed. Contradictions between a root file and a nested one are deliberately not reported (nested files usually override). User scope versus project scope is reported as info only. Use the ignore comments for the odd false positive.
238
+ - **Paths:** only prose and code spans are scanned for paths, not fenced blocks (they are usually sample output). Paths whose first directory is unknown are skipped, so `acme/widgets` is not mistaken for a missing path, but a typo in such a path is not caught. Lines containing "e.g.", "i.e.", "for instance", "such as", "example", "sample", "placeholder", "create", "generate", "output to/in/into", "writes to", "saves to", "mkdir", "touch" followed by a path, "gitignored", "ignore", "never", "don't", "do not", "avoid", "instead of", "deprecated", "removed", "no longer" and "replaced" are skipped. A mention such as `.test.ts` or `.module.css` (a file suffix) is not a path, `YYYY-MM-DD-slug.md`-style placeholders are skipped, and a bare `tests/` that exists somewhere below the root is accepted.
239
+ - **Scripts:** `pnpm X` and `yarn X` treat anything that is not a known built-in command as a script name; a plugin command I do not know could be flagged. Repos with no package.json, Makefile or justfile cannot be verified for those tools (a `make X` with no Makefile at all is reported).
240
+ - **missing-command** (binaries such as `uv run`, `poetry run`) is not implemented; I could not make it precise enough.
241
+ - **git:** `stale-reference` reads at most the last 20,000 commits and needs history; shallow clones (many CI checkouts) see less, so use `fetch-depth: 0`. Rename detection is git's own 50% similarity rule. `stale-age` is informational: commit dates in a fresh clone are real, but mtimes of untracked files are whatever the filesystem says.
242
+ - **Dependency binaries.** `pnpm eslint`, `yarn tsc`, `bunx vitest` and similar run binaries, not scripts. memfresh checks `node_modules/.bin`, `dependencies` and `devDependencies` and reports unknowns as info, never as an error.
243
+ - **Monorepo paths.** A path that does not exist at the root is also tried relative to the directory named in the nearest heading or earlier on the line, and a unique match elsewhere in the repo is reported as info, not a warning.
244
+ - **Imports outside the project** (for example `~/` files in a project file) are not followed, so their content is not checked.
245
+ - **Git worktrees** share one auto-memory directory (per the docs); memfresh looks for it under the main worktree's path too.
246
+ - **Claude Code defaults can be changed by the user** (for example reading both CLAUDE.md and AGENTS.md); `agents-not-loaded` assumes the documented default and is info for that reason.
247
+ - **Codex `fallback filenames` and per-session working directories** are not modelled; the chain is computed for a session started in each directory that has an AGENTS file.
248
+ - **Windows** is untested (paths are normalised to forward slashes, but I could not run it).
249
+ - Everything described here was run on Linux with Node 22. CI also runs Node 24.
250
+
251
+ ## Contributing
252
+
253
+ ```sh
254
+ git clone https://github.com/boscofoulsham/memfresh && cd memfresh
255
+ npm install # dev dependency: eslint only
256
+ npm run lint
257
+ npm test # node --test, no network needed (needs git and bash)
258
+ npm run coverage
259
+ ```
260
+
261
+ Tests build their fixtures in temporary directories, including scripted git repos. The CLI end-to-end tests run the real binary against `examples/make-demo.sh` output, and one test checks that the Real output block in this README matches a real run, so update both together.
262
+
263
+ ## License
264
+
265
+ MIT. Copyright (c) 2026 Bosco Foulsham.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ // NO_COLOR wins over FORCE_COLOR in memfresh; dropping FORCE_COLOR first also stops Node printing
3
+ // its own "NO_COLOR is ignored" warning when both are set.
4
+ if (process.env.NO_COLOR) delete process.env.FORCE_COLOR;
5
+ const { main } = await import('../src/cli.js');
6
+
7
+ process.exitCode = await main(process.argv.slice(2));
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env bash
2
+ # Build the demo projects used by the README and the tests. Invented data only.
3
+ #
4
+ # examples/make-demo.sh <target-dir> [dirty|clean]
5
+ #
6
+ # dirty (default): <target-dir>/repo is a small project whose memory files contain the problems
7
+ # memfresh looks for, with real (fixed-date) git history so a rename is detectable;
8
+ # <target-dir>/memory is a fake Claude Code auto-memory directory with an
9
+ # over-long MEMORY.md.
10
+ # clean: <target-dir>/repo has consistent memory files and should produce zero findings.
11
+ #
12
+ # Writes only inside <target-dir>, which must not already contain a "repo" directory.
13
+ set -euo pipefail
14
+
15
+ case "${1:-}" in
16
+ -h|--help)
17
+ sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'
18
+ exit 0
19
+ ;;
20
+ esac
21
+
22
+ target="${1:-}"
23
+ kind="${2:-dirty}"
24
+ if [ -z "$target" ] || { [ "$kind" != dirty ] && [ "$kind" != clean ]; }; then
25
+ echo "usage: $0 <target-dir> [dirty|clean]" >&2
26
+ exit 2
27
+ fi
28
+ mkdir -p "$target"
29
+ if [ -e "$target/repo" ]; then
30
+ echo "$target/repo already exists; refusing to overwrite" >&2
31
+ exit 2
32
+ fi
33
+ target="$(cd "$target" && pwd)"
34
+ repo="$target/repo"
35
+ mkdir -p "$repo"
36
+ cd "$repo"
37
+
38
+ export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null
39
+ export GIT_AUTHOR_NAME="Demo Author" GIT_AUTHOR_EMAIL="demo@example.invalid"
40
+ export GIT_COMMITTER_NAME="Demo Author" GIT_COMMITTER_EMAIL="demo@example.invalid"
41
+ git init -q -b main
42
+ git config commit.gpgsign false
43
+
44
+ commit() { # commit <iso-date> <message>
45
+ git add -A
46
+ GIT_AUTHOR_DATE="$1" GIT_COMMITTER_DATE="$1" git commit -q -m "$2"
47
+ }
48
+
49
+ if [ "$kind" = clean ]; then
50
+ mkdir -p src .cursor/rules
51
+ cat > package.json <<'JSON'
52
+ {
53
+ "name": "tidy-widgets",
54
+ "version": "1.0.0",
55
+ "private": true,
56
+ "engines": { "node": ">=22" },
57
+ "scripts": { "build": "node build.js", "test": "node --test", "lint": "eslint ." }
58
+ }
59
+ JSON
60
+ echo '{"lockfileVersion": 3}' > package-lock.json
61
+ echo 22 > .nvmrc
62
+ echo 'console.log("tidy");' > src/index.js
63
+ printf 'node_modules/\n' > .gitignore
64
+ commit 2026-09-01T10:00:00Z "initial project"
65
+ cat > AGENTS.md <<'MD'
66
+ # Agent guide
67
+
68
+ - Install dependencies with `npm install`.
69
+ - Run the tests with `npm test` and the linter with `npm run lint`.
70
+ - The entry point is `src/index.js`.
71
+ - Use 2 spaces for indentation.
72
+ - Target Node 22.
73
+ MD
74
+ cat > CLAUDE.md <<'MD'
75
+ @AGENTS.md
76
+
77
+ ## Claude-specific
78
+ - Prefer small, reviewable diffs over sweeping rewrites.
79
+ MD
80
+ cat > .cursor/rules/style.mdc <<'MD'
81
+ ---
82
+ description: Import ordering
83
+ alwaysApply: true
84
+ ---
85
+ - Keep imports sorted alphabetically within each group.
86
+ MD
87
+ commit 2026-09-05T10:00:00Z "add agent instructions"
88
+ echo "Built clean demo at $repo"
89
+ exit 0
90
+ fi
91
+
92
+ mkdir -p src/legacy src/api docs .cursor/rules services/billing "$target/memory"
93
+ cat > package.json <<'JSON'
94
+ {
95
+ "name": "acme-widgets",
96
+ "version": "2.3.0",
97
+ "private": true,
98
+ "engines": { "node": ">=20" },
99
+ "scripts": { "build": "node build.js", "dev": "node src/api/server.ts", "test": "node --test", "lint": "eslint ." }
100
+ }
101
+ JSON
102
+ printf 'lockfileVersion: 9.0\n' > pnpm-lock.yaml
103
+ echo 20 > .nvmrc
104
+ printf 'node_modules/\ndist/\n' > .gitignore
105
+ cat > src/legacy/auth.ts <<'TS'
106
+ // Session handling for the widget API.
107
+ export function signIn(user: string): string {
108
+ return `session-for-${user}`;
109
+ }
110
+ export function signOut(session: string): void {
111
+ void session;
112
+ }
113
+ TS
114
+ echo 'export const port = 3000;' > src/api/server.ts
115
+ printf '# Contributing\n\nOpen a pull request against main.\n' > docs/CONTRIBUTING.md
116
+ commit 2025-01-10T09:00:00Z "initial project"
117
+
118
+ cat > CLAUDE.md <<'MD'
119
+ # Acme Widgets
120
+
121
+ Instructions for Claude Code.
122
+
123
+ ## Setup
124
+ - Install dependencies with `npm install`.
125
+ - Run the linter and fix issues with `npm run lint:fix` before committing.
126
+ - Run the tests with `npm test`.
127
+
128
+ ## Layout
129
+ - Authentication lives in `src/legacy/auth.ts`.
130
+ - The HTTP server is in `src/api/server.ts`.
131
+ - Contributor docs are in `docs/CONTRIBUTING.md`.
132
+
133
+ ## Style
134
+ - Use 2 spaces for indentation.
135
+ - Always use semicolons.
136
+ - Keep functions small and name them after what they do.
137
+
138
+ ## Runtime
139
+ - The service targets Node 18.
140
+ MD
141
+ commit 2025-02-03T09:00:00Z "add CLAUDE.md"
142
+
143
+ cat > AGENTS.md <<'MD'
144
+ # Agent guide
145
+
146
+ ## Setup
147
+ - Install dependencies with `pnpm install`.
148
+ - Use 4 spaces for indentation.
149
+ - Keep functions small and name them after what they do.
150
+ MD
151
+ cat > .cursor/rules/style.mdc <<'MD'
152
+ ---
153
+ description: Code style
154
+ alwaysApply: true
155
+ ---
156
+ - Use 2 spaces for indentation.
157
+ - Never use semicolons.
158
+ MD
159
+ {
160
+ echo '# Billing service notes'
161
+ echo
162
+ for i in $(seq 1 340); do
163
+ echo "- Reference note $i: the ledger exporter for batch $i groups records in sets of $i and retries twice."
164
+ done
165
+ } > services/billing/AGENTS.md
166
+ commit 2025-03-05T09:00:00Z "add AGENTS.md, Cursor rule and billing notes"
167
+
168
+ mkdir -p src/auth
169
+ git mv src/legacy/auth.ts src/auth/login.ts
170
+ printf '// Session handling for the widget API.\nexport function signIn(user: string): string {\n return `session-for-${user}`;\n}\nexport function signOut(session: string): void {\n void session;\n}\nexport const sessionTtl = 3600;\n' > src/auth/login.ts
171
+ commit 2025-04-02T09:00:00Z "move auth into src/auth"
172
+
173
+ for n in $(seq 1 12); do
174
+ m=$(printf '%02d' $(( (n + 3) % 12 + 1 )))
175
+ y=$(( 2025 + (n + 3) / 12 ))
176
+ echo "export const port = $((3000 + n));" > src/api/server.ts
177
+ commit "$y-$m-15T09:00:00Z" "tune server settings ($n)"
178
+ done
179
+
180
+ {
181
+ for i in $(seq 1 230); do
182
+ echo "- Habit $i: remember to check the widget cache before rebuilding output $i."
183
+ done
184
+ } > "$target/memory/MEMORY.md"
185
+ cat > "$target/memory/build-notes.md" <<'MD'
186
+ # Build notes
187
+
188
+ - The server entry point is `src/api/server.ts`.
189
+ - Docs live in `docs/`.
190
+ MD
191
+ echo "Built dirty demo at $repo (auto-memory dir: $target/memory)"
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "memfresh",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Check coding agents' memory and instruction files (CLAUDE.md, AGENTS.md, auto-memory, Cursor rules) for stale facts, contradictions, duplicates and silent truncation.",
5
+ "type": "module",
6
+ "bin": { "memfresh": "bin/memfresh.js" },
7
+ "files": ["bin", "src", "examples/make-demo.sh", "README.md", "LICENSE", "CHANGELOG.md"],
8
+ "engines": { "node": ">=22" },
9
+ "scripts": {
10
+ "lint": "eslint .",
11
+ "test": "node --test \"test/*.test.js\"",
12
+ "coverage": "node --test --experimental-test-coverage \"test/*.test.js\""
13
+ },
14
+ "keywords": ["claude-code", "claude-md", "agents-md", "codex", "cursor-rules", "ai-agents", "memory", "linter", "ci"],
15
+ "repository": { "type": "git", "url": "git+https://github.com/boscofoulsham/memfresh.git" },
16
+ "homepage": "https://github.com/boscofoulsham/memfresh",
17
+ "bugs": { "url": "https://github.com/boscofoulsham/memfresh/issues" },
18
+ "author": "Bosco Foulsham",
19
+ "license": "MIT",
20
+ "devDependencies": { "eslint": "^10.0.0" }
21
+ }