Skip to content

feat: project-scoped memory + user guide - #60

Open
fktpp2022 wants to merge 43 commits into
jayzeng:mainfrom
fktpp2022:feat/project-scoped-memory
Open

fktpp2022 wants to merge 43 commits into
jayzeng:mainfrom
fktpp2022:feat/project-scoped-memory

Conversation

@fktpp2022

@fktpp2022 fktpp2022 commented Nov 2, 2026 •

Copy link
Copy Markdown

Summary

Adds project-scoped memory: each git project gets its own isolated memory under ~/.pi/agent/memory/projects/<slug>-<hash>/, with an optional opt-in global/ scope. Sessions see their own scope plus any configured extras; the scope set is configured by command > env var > project config > default.

All seven tools support an optional scope/scopes parameter; writes are restricted to own scope + global, reads can widen to any existing scope. Migration from the old flat layout is one command: /memory migrate.

The new user guide docs/PROJECT_SCOPED_MEMORY.md explains the feature from a user's perspective: why it exists, how scopes work, common use cases, and how to migrate.

Evidence

  • Before: a single global MEMORY.md and daily/ tree; no way to keep project A's conventions from leaking into project B.
  • After: each project scope is isolated on disk and in search (one qmd collection per scope, round-robin merge). The full spec lives in docs/spec/project-scoped-memory.md; test coverage is in test/unit.test.ts (395 passing) and test/e2e.ts.

Merge Danger

Door: two-way — removing the feature restores the single global layout; no data is destroyed.

Blast Radius: medium. The on-disk layout changes from a flat tree to a scoped tree; users run /memory migrate once to move existing memory. The global qmd collection name stays pi-memory for back-compat.

Fan Kai and others added 30 commits October 29, 2026 11:31
Assemble the decision map (#1) into a self-contained spec:
docs/spec/project-scoped-memory.md plus the qmd spike transcript and the pi
cwd/session-lifecycle research it cites. Doc-only: no code changes.
Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Pure layer for ticket #12: parse global | project:<slug>[#<hash>],
derive the memory-scope extension's <slug>-<8 hex sha1> directory name,
and resolve extras from command > env > .pi/memory.json > default,
including present-but-empty clearing.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
feat: resolve scope ids, slugs, and the active scope set (#12)
memory_root/global and memory_root/projects/<slug>-<hash> each hold
MEMORY.md, SCRATCHPAD.md, daily/ and recovery/. The seven tools now
default to the session scope set resolved in session_start from
ctx.cwd; writes accept the own scope or global, reads accept a scopes
list and group results per scope when several are read. Unknown project
ids are rejected without creating a directory.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
…he git root

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Create, match, and re-point one qmd collection per scope at session start,
with lazy creation on write and a guarded legacy global re-point. Fix the
qmd context calls to use qmd://<collection>/<path> instead of the invalid
-c flag, and report per-scope collection state plus orphan collections and
orphaned embedding chunks in memory_status.

Tests: npm test (279 pass), npm run build, biome check index.ts test/unit.test.ts.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
feat: per-scope file layout and scope-aware tool surface (#13)
feat: manage qmd collections per scope (#14)
Add a ## Scopes section listing each active scope with its resolved
directory, existence, and qmd collection name/state without requiring
qmd, and extend the tool details with the same per-scope rows. Display
ids never carry the hash.

Grouped reads now omit scopes with no content, and all seven tool
descriptions document the scope parameter semantics.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
- buildMemoryContext emits one `## Scope: <id>` block per active scope
  (own first, extras in set order) with `###` sub-sections; empty scopes
  contribute no block, and the shared search section moves after all blocks.
- split the 16k budget equally across scopes after reserving the search cap,
  redistributing the search share when there are no results; truncate the
  lowest-priority sections first and mark truncated scopes visibly.
- search each scope's own collection and merge hits round-robin in set order,
  prefixing each hit with its scope id.
- add applyScopeSetChange to rebuild the active set atomically, ensure the new
  scopes' collections, and invalidate the snapshot (scope_change in stable
  mode, dirty in refresh mode).
- cover the layout, budget, truncation, search merge, and snapshot
  invalidation in unit tests; add an API-key-gated cross-project marker
  isolation e2e case.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
# Conflicts:
#	test/unit.test.ts
Register one /memory command that prints the active scope set, its source
layer and the project config path; supports scope <id>..., reset-to-layer,
scopes listing and migration delegation. The override lives in module state
only and is cleared at session_start.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
PI_MEMORY_DIR is the memory root. Detect a directory containing
MEMORY.md directly, warn once per session at session_start, and surface
the conflict in memory_status and /memory while still honouring the
override.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
README, AGENTS.md and CLAUDE.md still described one flat memory directory and
four tools. Document the scope model, the per-scope layout, `/memory`, and
`PI_MEMORY_DIR` as the memory root, and add the breaking migration change to the
changelog.

The spec said the slug is lowercased, but the four adopted project directories
preserve case (`Lenovo-94672f7c`), and so does the implementation. Correct that
line, and move `.migration-manifest.json` to the memory root where chapter 7.6
writes it.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
…the spec

Search every resolved scope's own collection and group the results per
scope, resolve sessions outside a repo to the global scope, put global
last in injected context, reject unknown env scope ids with a warning,
gate project config on trust, complete /memory scope arguments, fix the
PI_MEMORY_DIR warning without a session manager, and drop dead migration
plan fields.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Bare /memory in a TUI now opens a flat scope panel: the own scope is
pinned and locked, project scopes follow A-Z (hash-qualified when a bare
slug is ambiguous), and global is offered as an extra. Space/tab stage a
toggle, enter applies the staged set through the existing command-layer
machinery, and esc discards. Print, JSON and RPC keep the plain report.

The list state (rows, toggle, activate, header) is exported as pure
functions and unit-tested without a terminal.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Enter on the Status row toggles an in-header block with the memory root,
each active scope's directory and qmd collection/embeddings readiness.
The data comes from a shared gatherer now used by memory_status too, so
its output is unchanged. Staged scope toggling and apply keep working
while the block is expanded.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Fan Kai and others added 13 commits October 29, 2026 23:11
Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
# Conflicts:
#	index.ts
#	test/unit.test.ts
Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
applyScopeSetChange dropped any extra whose display id matched the own
scope, so an explicitly qualified sibling project vanished on apply from
both the panel and /memory scope. Skip only the own id itself.

Also folds the review findings in: one shared ambiguity-label helper,
a one-line header using it with an explicit own scope, a post-apply
summary line, gate the global row on its directory existing, rename the
panel row identity off scopeId, make gatherMemoryStatus own its ensureDirs
precondition, pin the pi-tui dev dependency, and refresh GLOSSARY,
CLAUDE.md and the README.

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Expanding Status now renders each active scope's directory immediately with
qmd checking, merges readiness when the snapshot lands, and reports a failed
probe instead of leaving the block blank.

Fixes #30

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
The pending Status block now animates pi's Loader braille frames at the same
80 ms cadence, so a slow probe reads as background work, and collapsing the
block mid-probe cancels it with a "status check canceled" notice.

Refs #30

Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
fix: paint the /memory Status block before the qmd probe lands
feat: project-scoped and global memory
Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Signed-off-by: Fan Kai <fankai@prismtech.com.cn>
Signed-off-by: FKtPp <kai.fktpp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant