Plan: memory in two pools, project and machine

Closes: #814. Relates to: #728 (session rulings as a later third pool), #30 (the original design). Branch: feat/memory-pools. Status: Done (2026-11-14) — the pools, the migration and the docs landed together

Context

The operator’s request (2026-11-14): machine memories take up the room and leave none for project details; separate them, ten per project and ten shared across the projects on a machine. His /memory listing showed ten notes, seven of them about other projects, under the line "injection: 10 candidates" though four were confirmed.

What packages/pi-modes/memory.ts does today, measured by running its functions on that listing and on built stores, in memory only (recorded on #814; the run reproduces the listing’s order and last line exactly):

Question Result

What "10 candidates" counts

Every record in scope: 4 confirmed and 6 unconfirmed; 7 developer-scope, 3 box, 0 repo.

Does the project decide what shows

No. A developer note is keyed by the git email, a box note by the hostname: the same ten show from any repository.

Can other projects block this one’s proposals

Yes. Staging is one pool of 10 for the whole store (stagingProblem). Ten proposals staged by another repository, none visible here, refuse this project’s first.

Does the confirmed cap make room

No. It is 30 per scope key (withinCap): 35 added, 30 kept.

Can other notes keep project notes out of the prompt

Yes. The block is 2,000 characters filled confirmed, pinned, hits, most recently seen (selectForInjection, renderMemoryBlock); scope plays no part. With 14 other notes of ordinary length, 0 of 3 older project notes are in it.

A repository with no origin remote

Has no repo key (computeScopeKeys). A repo-scope proposal is refused; the same note as box or developer is accepted and shows everywhere. /remember with no prefix falls back to box without saying so.

So project notes are crowded out because project facts are filed under scopes that go everywhere, because staging is shared, and because the prompt block reserves nothing for the project.

The operator’s rulings (2026-11-14): two pools of ten; existing developer-scope notes are archived and listed once for him to re-file with /remember.

Design

D1. Two pools. A record belongs to the project pool (stored scope repo, keyed by the project) or the machine pool (stored scope box, keyed by the hostname). MemoryScope becomes "repo" | "box". The stored words stay repo and box, so records, tests and the prompt label keep their spelling; the docs and messages say project and machine.

D2. One cap per pool: ten records, confirmed and unconfirmed together. MEMORY_CAPS.activePerScope (30) and stagingMax (10, whole store) are replaced by perPool: 10, counted over the records of one scope key. What happens at a full pool depends on who writes:

  • An agent’s proposal (remember tool, tier observed) is refused. The refusal names the pool, how many of its ten are confirmed, and its three oldest proposals as today’s does (stagedLine), each of them this pool’s own. A proposal therefore displaces nothing.

  • The human’s /remember of a new note is stored, and one other record of that pool goes to the archive (cause cap-eviction): the oldest unconfirmed proposal when there is one, else the least useful confirmed record by today’s evictionOrder. The command says which, as today.

  • /memory promote, and a /remember that repeats a proposal, confirm a record the pool already counts: the tier changes in place, the count does not move, and nothing is evicted. A repeat of any note refreshes it, in a full pool too.

Proposals keep their seven-day life (stagingTtlDays, pruneStaging, unchanged).

D3. Every record in scope is in the prompt. With at most ten records a pool and 140 characters a note, the section is at most twenty lines (about 3,300 characters; today’s ceiling is 2,000). injectMaxChars and the "more within budget limits" line go: the caps are the budget. renderMemoryBlock writes the project pool’s lines, then the machine pool’s, each pool ordered as today (confirmed, pinned, hits, most recently seen), in today’s line form - [kind/repo] text.

D4. A project always has an identity inside a repository. computeScopeKeys keeps today’s key for a repository with an origin (the hash of its URL as written). For a repository without one, the key is the hash of path: followed by the resolved path of its git directory (the common one for a worktree, so worktrees share it, as they share the origin today). Outside any repository there is no project pool, as today; /remember with no prefix then stores to the machine pool and its notice says "remembered (machine: no project here)".

D5. The developer scope is retired. The remember tool’s scope parameter offers repo and box; its description says a note about one repository belongs at repo, and box is for a fact about this machine that holds in any project. /remember dev: … is refused with the usage line, so the text is not stored as a project note beginning "dev:". ScopeKeys.developer and developerKey are removed. The usage line becomes usage: /remember [box:] <text>. Notices say the pool in words: remembered (project), remembered (machine), and (pool at cap) where today’s say (scope at cap); the prompt and listing lines keep the stored words repo and box.

D6. The store is version 2, migrated once. The conversion is a pure function in memory.ts, migrateStore(v1) → { store, retired, trimmed }, beside evictionOrder, which stays private; memory-wiring.ts does the reading, archiving, writing and the notice. memorySessionStart reads the file; a version-1 store is converted before anything else:

  1. every developer record goes to the archive with cause scope-retired;

  2. each remaining pool over ten is trimmed by evictionOrder (unconfirmed first), the surplus archived with cause cap-eviction;

  3. the store is written as { version: 2, records };

  4. one notice lists what was archived, by id and text, and says how to re-file (/remember, or /remember box:) and where the records are (the archive, cause scope-retired).

readStore accepts version 2 only. A session still running the previous release reads a version-2 file as an unexpected shape, which disables its memory loudly and writes nothing (today’s behaviour for an unreadable store).

D7. The listing says what it counts. renderMemoryList prints a header per pool, project: 3 of 10 (2 confirmed, 1 unconfirmed) and machine: …, then that pool’s records in today’s line form. The closing line becomes in the prompt: all N notes, C chars. The word "candidates" goes.

Erratum (2026-11-14): a pinned record is never the one displaced, so the human’s note is refused only by a pool of ten pinned records; and the path key is the git directory’s real path, so a checkout reached through a link and its worktree share it. Both from the commit’s review.

Erratum (2026-11-14): the code landed as one commit, not two: memory-wiring.ts does not compile against the new memory.ts until it changes too.

Scope

In: packages/pi-modes/memory.ts, packages/pi-modes/memory-wiring.ts, their tests (test/memory.test.ts, test/memory-wiring.test.ts, the memory cases of test/wiring-lifecycle.test.ts, and test/tool-surfaces.test.ts, whose keyFor("developer", …) assertion at lines 173-179 goes with the scope), docs/modules/ROOT/pages/tuning.adoc (the Memory section), docs/modules/ROOT/pages/public-surface.adoc (the store’s row, if its wording names scopes), CHANGELOG.adoc, this plan under docs/modules/ROOT/pages/plans/memory-pools.adoc with its nav.adoc line.

Out, each an issue filed at approval or already open:

  • The project key as a normalised host and path, so one project cloned over https and over ssh shares its notes (measured on #814: two keys today). It needs a re-keying of stored records and is its own change.

  • Session-scoped rulings as a third pool (#728).

  • The pinned field, which no command sets.

  • tools/model-battery/cases/explore/pi/12-memory-scopes-and-eviction.json asks about the developer scope. A battery case and its stored records are the operator’s; mentioned on the issue, not edited here.

  • A lock on the store; two writes in the same instant can still lose one, as documented today.

Risks

Risk Mode Mitigation

The migration drops a record it should keep or archive

silent

Property test: every version-1 record is in the version-2 store or in the archive lines, never neither and never both. The archive is append-only and written before the store is replaced.

The one-time notice is missed (first session after the update is headless, or the line scrolls away)

silent

The records are in the archive under a cause of their own; the CHANGELOG entry and tuning.adoc give the one command that lists them. The notice is best-effort and is not the record.

Two new sessions start at once on a version-1 store

silent

The conversion is deterministic, so both write the same version-2 store; the archive may hold each retired record twice, which loses nothing. Stated in the code comment; no lock is added.

A session of the previous release runs beside a new one

fail-closed

It reads version 2 as an unexpected shape: memory off for that session with a warning, nothing written. Stated in the CHANGELOG.

A full pool of confirmed notes refuses every proposal, so an agent stops recording project pitfalls

fail-closed

The refusal says so and names the forget tool; the human’s /remember makes its own room. tuning.adoc says a pool is ten.

The human’s write evicts a note he wanted

silent

Unchanged from today: the command names the evicted note, and the archive keeps it.

A repository gains an origin later, so its path-keyed notes no longer show

silent

Stated in tuning.adoc; the notes stay in the store and expire or are found by /memory from a checkout without the origin. Folded into the key-normalisation issue.

A standing preference of the human’s (not about any project or machine) has no scope of its own: re-filed, it takes a machine slot, and must be re-filed on each box

silent

Stated in tuning.adoc and in the migration notice. Agency-wide preferences belong in guidance, which ships with the package; the machine pool is for what is left.

The prompt section grows from 2,000 to at most about 3,300 characters

fail-open

Bounded by the caps; the listing prints the size. A test holds the bound.

Tests

Contract (the stored format and the prompt wire):

  • A version-1 store with developer, repo and box records migrates to version 2: developer records archived with cause scope-retired, the rest kept; the notice names each archived id and text.

  • A version-1 pool of twelve is trimmed to ten, unconfirmed first, the two archived with cause cap-eviction.

  • readStore refuses version 1 after migration and any other version, loudly, without writing.

  • The block is the project pool’s lines then the machine pool’s, in today’s line form; the listing’s headers count confirmed and unconfirmed apart.

Regression (each is a case that would have caught what the operator saw):

  • His ten-record listing as a version-1 store: after migration, from a project with no notes, the section holds the three machine notes and no developer note.

  • Ten proposals staged by another repository do not refuse this project’s first proposal.

  • Fourteen machine notes cannot exist (the pool is ten), and with ten machine notes of 140 characters, three older project notes with equal hits are all in the block.

  • A repository with no origin accepts a repo-scope proposal, and a second such repository at another path does not see it.

  • /remember dev: x is refused and stores nothing.

  • Promoting a proposal in a full pool evicts nothing and leaves ten.

Property (fast-check, as elsewhere in pi-modes' tests):

  • After any sequence of proposals, human writes, promotions and forgets, every pool holds at most ten records ("a pool never exceeds ten").

  • A proposal never removes a record ("a proposal displaces nothing"): the store before is a subset of the store after, or the proposal was refused.

  • The block contains every record in scope, and its length is within the bound of D3 ("every record in scope is in the prompt").

  • Migration loses nothing (the Risks table’s first row).

Unit: the path key for a plain repository, a worktree (same key as its main checkout) and a non-repository (none); the eviction choice at a full pool (oldest proposal, else evictionOrder).

Existing tests that pin the old numbers or the developer scope are rewritten to the new rule, not deleted: the staging-full message (memory.test.ts), the dev: prefix cases and the usage line (memory-wiring.test.ts, wiring-lifecycle.test.ts), the developer key (tool-surfaces.test.ts).

Not tested here: two releases side by side on one box (stated above, by reading readStore).

Delivery

  1. One branch, feat/memory-pools, in three commits: the pools, caps and block (memory.ts); the wiring, the tool’s parameter and the migration (memory-wiring.ts); the docs.

  2. Canonical doc: tuning.adoc’s Memory section, rewritten for two pools, the cap of ten, what a full pool does to an agent and to the human, the retired dev: prefix, the project identity without an origin, and how to list the archived developer notes.

  3. CHANGELOG, under Unreleased: a Changed entry saying what a person sees after updating (the notice, the listing, proposals no longer blocked by another project) and that a session of the previous release loses memory until restarted.

  4. node tools/task.mjs validate, MR with Closes #814, merge with squash off, the merge SHA on the issue; the out-of-scope issues filed and linked there.

  5. Released with the next release; @gadhs/pi-modes and its dependents move.

Edit this page · latest