Skip to content

Commit 4f50f72

Browse files
authored
Add scripted impression recall and memory linting
Squash merge V0.2.2 scripted impression recall, token-only engine scan, memory linting, package bins, and adoption docs.
1 parent fb687a8 commit 4f50f72

35 files changed

Lines changed: 900 additions & 92 deletions

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.2.2] - 2026-04-21
6+
7+
- Made engine impression scans token-only so query embeddings are deferred until chunk retrieval is needed.
8+
- Added CLI `--memory-root` and `--file` options and aligned `matched` with weak/strong scan levels.
9+
- Added `deja-vu-scan-memory` and `deja-vu-lint-memory` package binaries.
10+
- Added memory linting for impression schema, duplicate ids, and linked record paths.
11+
- Updated adoption docs, handshake, templates, and example project to make impression-first recall the default path.
12+
- Updated protocol naming to v0.2 and clarified project-local plain text storage.
13+
14+
## [0.2.1] - 2026-04-21
15+
16+
- Added a protocol-level impression layer for compact keyword-first familiarity scans.
17+
- Added scripted recall documentation and a default `scripts/dejavu-scan-memory.mjs` scanner.
18+
- Added `memory/impressions.jsonl` and `memory/events/` templates for cheap long-term continuity.
19+
- Updated workflow, protocol, storage, bootstrap, and AGENTS templates around impression-first recall.
20+
- Extended the optional TypeScript engine with `impressionTokens` and `scanImpressions()`.
21+
- Added tests for scanning impressions without loading deeper memory.
22+
523
## [0.2.0] - 2026-04-20
624

725
- Repositioned Deja Vu as a protocol-first memory system for AI agents.

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,38 @@ It answers:
2121
- how memory should be stored in ordinary project files
2222
- when memory should be updated, compacted, or retired
2323

24-
The minimum viable setup uses Markdown files only. No npm package, embeddings, vector search, or database is required.
24+
The minimum viable setup uses project-local plain text files. No npm package, embeddings, vector search, or database is required.
2525

2626
## Start Here
2727

2828
If you want to adopt Deja Vu in a project without extra infrastructure:
2929

3030
1. Read [docs/protocol.md](./docs/protocol.md).
3131
2. Read [docs/workflow.md](./docs/workflow.md).
32-
3. Copy the templates from [docs/templates](./docs/templates).
33-
4. Add the generated rules and memory files to your project.
32+
3. Read [docs/impression-layer.md](./docs/impression-layer.md).
33+
4. Read [docs/scripted-recall.md](./docs/scripted-recall.md).
34+
5. Copy the templates from [docs/templates](./docs/templates).
35+
6. Add the generated rules and memory files to your project.
3436

3537
Recommended first files:
3638

3739
- [docs/templates/AGENTS.template.md](./docs/templates/AGENTS.template.md)
3840
- [docs/templates/memory/index.md](./docs/templates/memory/index.md)
3941
- [docs/templates/memory/summary.md](./docs/templates/memory/summary.md)
42+
- [docs/templates/memory/impressions.jsonl](./docs/templates/memory/impressions.jsonl)
43+
- [docs/templates/memory/events/YYYY-MM.md](./docs/templates/memory/events/YYYY-MM.md)
4044
- [docs/templates/memory/decisions/decision-template.md](./docs/templates/memory/decisions/decision-template.md)
4145
- [docs/templates/memory/open-loops/open-loop-template.md](./docs/templates/memory/open-loops/open-loop-template.md)
4246

4347
## The Protocol in One Page
4448

4549
Deja Vu follows a simple lifecycle:
4650

47-
1. Recall before substantial planning, coding, or answering.
48-
2. Work using only the smallest memory slice needed.
49-
3. Write back only durable, reusable outcomes.
50-
4. Compact or supersede memories when detail becomes repetitive or stale.
51+
1. Scan a tiny impression index before substantial planning, coding, or answering.
52+
2. Load summaries only when the scan finds weak familiarity.
53+
3. Load detailed records only when the scan finds strong familiarity or the task requires depth.
54+
4. Write back durable outcomes and a cheap event trace.
55+
5. Compact or supersede memories when detail becomes repetitive or stale.
5156

5257
This keeps memory project-local, readable, and easy to maintain across new conversations.
5358

@@ -57,6 +62,8 @@ This keeps memory project-local, readable, and easy to maintain across new conve
5762
memory/
5863
index.md
5964
summary.md
65+
impressions.jsonl
66+
events/
6067
context/
6168
project-context.md
6269
decisions/
@@ -71,7 +78,7 @@ The canonical layout and field rules are specified in [docs/storage-markdown.md]
7178

7279
- Use a single-project scope only in MVP: `project:<project-id>`.
7380
- Recall before substantial work.
74-
- Prefer summary memory first; open detailed records only when needed.
81+
- Prefer scripted impression scans first; open summary or detailed records only when needed.
7582
- Write back only durable memory:
7683
- decisions
7784
- architecture intent
@@ -132,6 +139,7 @@ The npm package provides the optional TypeScript engine. It is not required for
132139
const engine = new SemanticRecallEngine(config);
133140

134141
await engine.addMemory(input);
142+
await engine.scanImpressions(query);
135143
await engine.recall(query);
136144
await engine.getSummary(id);
137145
await engine.getChunks(id);
@@ -141,6 +149,8 @@ await engine.deleteMemory(id);
141149

142150
The public TypeScript exports remain intact for hosts that want semantic recall.
143151

152+
`scanImpressions()` performs token-only familiarity scanning and does not load summaries or chunks.
153+
144154
## Examples
145155

146156
- Protocol-first example: [examples/protocol-project](./examples/protocol-project)
@@ -175,13 +185,16 @@ deja-vu/
175185
npm install
176186
npm run build
177187
npm run test:src
188+
npm run lint:memory
178189
```
179190

180191
## References
181192

182193
- [docs/protocol.md](./docs/protocol.md)
183194
- [docs/workflow.md](./docs/workflow.md)
184195
- [docs/storage-markdown.md](./docs/storage-markdown.md)
196+
- [docs/impression-layer.md](./docs/impression-layer.md)
197+
- [docs/scripted-recall.md](./docs/scripted-recall.md)
185198
- [docs/bootstrap-instructions.md](./docs/bootstrap-instructions.md)
186199
- [docs/project-rules-template.md](./docs/project-rules-template.md)
187200
- [llms.txt](./llms.txt)

docs/agent-handshake.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ Deja Vu is a protocol-first memory system, not just a TypeScript package.
88

99
An agent that discovers this repository should infer:
1010

11-
1. the primary adoption path is rules + workflow + Markdown memory files
11+
1. the primary adoption path is rules + workflow + project-local memory files
1212
2. the project scope is `project:<project-id>` in MVP
1313
3. memory should stay project-local
14-
4. the optional TypeScript engine is an enhancement layer, not the base requirement
14+
4. impression-first scripted recall is the default low-cost recall path
15+
5. the optional TypeScript engine is an enhancement layer, not the base requirement
1516

1617
## Read order
1718

@@ -21,7 +22,9 @@ Read these files first:
2122
2. `docs/protocol.md`
2223
3. `docs/workflow.md`
2324
4. `docs/storage-markdown.md`
24-
5. `docs/templates/AGENTS.template.md`
25+
5. `docs/impression-layer.md`
26+
6. `docs/scripted-recall.md`
27+
7. `docs/templates/AGENTS.template.md`
2528

2629
Read these files only if the host wants semantic recall:
2730

@@ -36,8 +39,8 @@ Read these files only if the host wants semantic recall:
3639
Unless the host explicitly needs engine-backed retrieval, start with:
3740

3841
- project rules
39-
- Markdown memory layout
40-
- pre-task recall
42+
- memory layout
43+
- pre-task impression scan
4144
- post-task writeback
4245
- manual or host-driven compaction
4346

docs/architecture.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The engine layer adds:
2222
- chunk retrieval
2323
- plugin seams for embeddings, storage, and vector search
2424

25+
This is product layering, not a reduction of the memory model.
26+
2527
## Engine flow
2628

2729
1. `addMemory(input)` runs a write pipeline.
@@ -34,10 +36,12 @@ The engine layer adds:
3436

3537
## Layer model
3638

37-
- Familiarity Index: fast ANN-friendly metadata and short summaries only.
39+
- Impression/Familiarity Index: fast ANN-friendly metadata, short summaries, and compact keyword tokens.
3840
- Summary Layer: compact agent-readable understanding of the memory.
3941
- Memory Chunks: detailed recall units scoped to a single memory id.
4042

43+
The protocol-first path mirrors this with `memory/impressions.jsonl`, `memory/summary.md`, and detailed Markdown records.
44+
4145
## Plugin seams
4246

4347
- `EmbeddingProvider`

docs/bootstrap-instructions.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ Read:
3333
2. `docs/protocol.md`
3434
3. `docs/workflow.md`
3535
4. `docs/storage-markdown.md`
36-
5. `docs/templates/AGENTS.template.md`
36+
5. `docs/impression-layer.md`
37+
6. `docs/scripted-recall.md`
38+
7. `docs/templates/AGENTS.template.md`
3739

3840
### 3. Check whether memory already exists
3941

@@ -52,19 +54,28 @@ Create or update:
5254
- `AGENTS.md`
5355
- `memory/index.md`
5456
- `memory/summary.md`
57+
- `memory/impressions.jsonl`
58+
- `memory/events/`
5559
- `memory/context/project-context.md`
5660
- `memory/decisions/`
5761
- `memory/open-loops/`
62+
- `scripts/dejavu-scan-memory.mjs`
5863

5964
### 5. Apply the workflow
6065

6166
Ensure future work follows:
6267

63-
1. pre-task recall from the memory files
64-
2. minimal detailed reads
65-
3. selective post-task writeback
68+
1. pre-task recall through the impression scan script
69+
2. minimal summary and detailed reads based on scan strength
70+
3. selective post-task writeback plus a cheap event trace
6671
4. compaction when records become repetitive or stale
6772

73+
After bootstrap, run:
74+
75+
```bash
76+
node scripts/dejavu-lint-memory.mjs
77+
```
78+
6879
### 6. Optional engine adoption
6980

7081
Only if the host needs semantic recall at higher scale:

docs/impression-layer.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Impression Layer
2+
3+
The impression layer is the thinnest Deja Vu memory surface.
4+
5+
Its job is not to explain a memory. Its job is to answer one cheap question:
6+
7+
> Does this task feel familiar enough to justify opening deeper memory?
8+
9+
## Position in the Memory Stack
10+
11+
Deja Vu keeps the optional engine's three-layer memory model:
12+
13+
1. Impression or familiarity index
14+
2. Summary layer
15+
3. Detailed chunks or records
16+
17+
The protocol-first path now mirrors that model with project files:
18+
19+
1. `memory/impressions.jsonl`
20+
2. `memory/summary.md` and linked summaries
21+
3. detailed records under `memory/context/`, `memory/decisions/`, and `memory/open-loops/`
22+
23+
## Impression Record
24+
25+
Use JSON Lines so a host script can scan records without parsing the whole memory tree.
26+
27+
Required fields:
28+
29+
- `schema_version`
30+
- `id`
31+
- `scope`
32+
- `title`
33+
- `keywords`
34+
- `record_path`
35+
- `updated`
36+
37+
Optional fields:
38+
39+
- `aliases`
40+
- `weight`
41+
- `status`
42+
43+
Example:
44+
45+
```json
46+
{"schema_version":1,"id":"decision-protocol-first","scope":"project:example-project","title":"Protocol-first positioning","keywords":["protocol","workflow","markdown","memory"],"aliases":["repo-first"],"record_path":"memory/decisions/protocol-first-positioning.md","updated":"2026-04-21","weight":0.9,"status":"active"}
47+
```
48+
49+
## Recall Behavior
50+
51+
Before substantial work:
52+
53+
1. Run the impression scan script against the current user request.
54+
2. If there is no match, avoid opening detailed memory by default.
55+
3. If there is a weak match, open only the active summary or one linked summary record.
56+
4. If there is a strong match, open the linked detailed record.
57+
5. Load chunks or raw detail only when the task explicitly needs deeper recall.
58+
59+
## Writeback Behavior
60+
61+
When durable memory is created or updated, update the impression record at the same time.
62+
63+
Keep impression keywords short and reusable:
64+
65+
- project terms
66+
- stable feature names
67+
- decision names
68+
- architecture nouns
69+
- user preference terms
70+
- unresolved follow-up names
71+
72+
Do not store full summaries, transcripts, secrets, or long prose in the impression layer.
73+
74+
## Retention Behavior
75+
76+
The impression layer may grow over time, but it should remain cheap to scan.
77+
78+
Ask the host whether to prune impressions, compact durable records, or archive stale records when:
79+
80+
- too many impression records match the same query
81+
- many records repeat the same keyword set
82+
- `memory/events/` grows without promotion into durable memory
83+
- detailed records are no longer needed after a newer summary supersedes them
84+
85+
Impression pruning may remove low-value keyword routes. Durable record compaction should preserve historical links through supersession or archival records.

docs/protocol.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Deja Vu Protocol v0.1
1+
# Deja Vu Protocol v0.2
22

33
Deja Vu is a protocol-first memory system for AI agents.
44

@@ -10,7 +10,7 @@ Enable any agent to maintain useful project memory using only:
1010

1111
- project rules
1212
- a repeatable workflow
13-
- project-local Markdown files
13+
- project-local plain text memory files
1414

1515
The protocol must work without a custom runtime, package install, embedding model, or vector database.
1616

@@ -49,6 +49,8 @@ An implementation of Deja Vu MVP must provide these artifacts inside the project
4949
- `AGENTS.md` or equivalent rules file with Deja Vu rules
5050
- `memory/index.md`
5151
- `memory/summary.md`
52+
- `memory/impressions.jsonl`
53+
- `memory/events/`
5254
- `memory/context/project-context.md`
5355
- `memory/decisions/`
5456
- `memory/open-loops/`
@@ -62,9 +64,10 @@ These files are the canonical memory surface. Agents should treat them as the pr
6264
Before substantial planning, coding, or answering:
6365

6466
1. Determine whether the task is substantial.
65-
2. If yes, read `memory/index.md` and `memory/summary.md`.
66-
3. Open only the detailed records needed for the current task.
67-
4. Prefer the smallest useful memory slice.
67+
2. If yes, run the project impression scan script when available.
68+
3. If the scan is weak, read `memory/summary.md` and the minimum linked records.
69+
4. If the scan is strong, open only the detailed records needed for the current task.
70+
5. If no script is available, fall back to `memory/index.md` and `memory/summary.md`.
6871

6972
### 2. Work
7073

@@ -81,7 +84,9 @@ After meaningful work completes:
8184
1. Decide whether the outcome is durable.
8285
2. If it is durable, write or update the appropriate memory artifact.
8386
3. Update `memory/index.md` so future recall can find the new record quickly.
84-
4. Update `memory/summary.md` when the project-level understanding has changed.
87+
4. Update `memory/impressions.jsonl` with compact keywords for future cheap scans.
88+
5. Update `memory/events/` with a short trace when the work should remain discoverable.
89+
6. Update `memory/summary.md` when the project-level understanding has changed.
8590

8691
### 4. Compaction
8792

docs/release-v0.2.1.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Deja Vu v0.2.1
2+
3+
Deja Vu v0.2.1 adds scripted impression-first recall.
4+
5+
This release keeps the v0.2.0 product layering:
6+
7+
1. protocol layer
8+
2. optional semantic engine layer
9+
10+
It also makes the memory stack explicit again:
11+
12+
1. impression or familiarity index
13+
2. summary layer
14+
3. detailed records or chunks
15+
16+
## Highlights
17+
18+
- Added `docs/impression-layer.md`.
19+
- Added `docs/scripted-recall.md`.
20+
- Added `scripts/dejavu-scan-memory.mjs`.
21+
- Added `memory/impressions.jsonl` and `memory/events/` templates.
22+
- Updated protocol workflow so hosts scan the impression index before loading summaries or detailed records.
23+
- Added `scanImpressions()` to the optional TypeScript engine.
24+
25+
## Goal
26+
27+
Use the smallest possible memory surface to detect familiarity, then spend context only when the scan justifies deeper recall.
28+
29+
## Validation
30+
31+
- `npm run build`
32+
- `npm run test:src`
33+
- `npm test`

0 commit comments

Comments
 (0)