@aeondave/pi-persona-mind 0.0.0-stage → 0.8.4

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.
Files changed (43) hide show
  1. package/AGENTS.md +78 -0
  2. package/CHANGELOG.md +78 -0
  3. package/LICENSE +24 -0
  4. package/README.md +244 -2
  5. package/assets/banner.png +0 -0
  6. package/docs/DESIGN.md +282 -0
  7. package/docs/MEMORY-RESEARCH.md +112 -0
  8. package/package.json +93 -4
  9. package/src/core/auto-optimize.ts +239 -0
  10. package/src/core/backlog.ts +228 -0
  11. package/src/core/blocked.ts +38 -0
  12. package/src/core/capture.ts +146 -0
  13. package/src/core/context-budget.ts +74 -0
  14. package/src/core/host-compat.ts +13 -0
  15. package/src/core/ids.ts +59 -0
  16. package/src/core/inject.ts +247 -0
  17. package/src/core/memory-read.ts +34 -0
  18. package/src/core/memory.ts +308 -0
  19. package/src/core/migrate.ts +713 -0
  20. package/src/core/mind-settings.ts +54 -0
  21. package/src/core/optimize-history.ts +101 -0
  22. package/src/core/optimize-service.ts +182 -0
  23. package/src/core/optimize.ts +133 -0
  24. package/src/core/retrieval.ts +108 -0
  25. package/src/core/scanner.ts +146 -0
  26. package/src/core/scope.ts +205 -0
  27. package/src/core/service.ts +644 -0
  28. package/src/core/session-memory.ts +71 -0
  29. package/src/core/store.ts +948 -0
  30. package/src/extension/activity.ts +79 -0
  31. package/src/extension/auto-optimize-session.ts +118 -0
  32. package/src/extension/auto-optimize.ts +265 -0
  33. package/src/extension/mind-command.ts +335 -0
  34. package/src/extension/mind-worker.ts +32 -0
  35. package/src/extension/persona-dependency.ts +76 -0
  36. package/src/index.ts +1231 -0
  37. package/src/session-memory.ts +118 -0
  38. package/src/tools/backlog.ts +126 -0
  39. package/src/tools/memory-optimize.ts +133 -0
  40. package/src/tools/memory.ts +400 -0
  41. package/src/ui/mind-result-card.ts +15 -0
  42. package/src/ui/presentation.ts +97 -0
  43. package/src/ui/session-note-card.ts +50 -0
package/AGENTS.md ADDED
@@ -0,0 +1,78 @@
1
+ # AGENTS.md — pi-persona-mind
2
+
3
+ An extension requiring a compatible loaded pi-persona: durable persona-aware memory + backlog,
4
+ coupled through a versioned local companion handshake to
5
+ [`pi-persona`](https://github.com/AeonDave/pi-persona). Binding design: [`docs/DESIGN.md`](docs/DESIGN.md).
6
+
7
+ ## Commands
8
+
9
+ - Typecheck: `npm run typecheck` (`tsc --noEmit`, strict + `exactOptionalPropertyTypes`)
10
+ - Tests: `npm test` · both: `npm run verify`
11
+ - Hermetic choke point: `node --import tsx --import ./test/setup/hermetic-env.ts --test test/*.test.ts`
12
+ - Installed Pi 1.4 qualification: `node --import tsx scripts/qualify-host.mjs <absolute-pi-package-root> <absolute-pi-persona-extension-path> [<absolute-packed-mind-extension-path>]`
13
+ (isolated profile, offline synthetic provider; no cloud authentication/model-quality claim).
14
+
15
+ ## Conventions
16
+
17
+ - Erasable-syntax-only TS. `src/core/*` is pure (no Pi imports) and unit-tested.
18
+ - Target the latest stable Pi only (currently 1.4.0), Node 22.19.0+. Keep host packages and
19
+ typebox as optional peers on `*`, with all four Pi development packages pinned together.
20
+ No historical-host branches; never bundle a second host runtime. Scope development security
21
+ overrides to their affected parent/version and remove them when that graph no longer needs them.
22
+ - Tests clear `PI_PERSONA_*` case-insensitively and pin `PI_AGENT_DIR` to a throwaway directory.
23
+ Keep the hermetic import on every direct test invocation. Real SDK tests use an offline provider.
24
+ - Require the loaded companion protocol at session activation and tool call time; missing or
25
+ incompatible Persona means no capture, storage/migration, injection or scheduler activity.
26
+ Settings files alone do not prove presence. Resolve the actual active persona through the
27
+ session-bound `pi-persona:memory-owner:v1` runtime contract; never reconstruct it from CLI or saved
28
+ selection. Before that owner is ready, do no memory IO. Delegated engines freeze the parent's
29
+ persona for their lifetime. Canonical `<agentDir>/persona/settings.json` supplies only Mind's
30
+ `mindCapture`/`mindNudge` session preference snapshots. Do not interpret retired state markers.
31
+ Contribute effective Mind settings
32
+ only from a supervisor via the shared settings event bus. Mirror `PI_PERSONA_LEG` /
33
+ `PI_PERSONA_CHILD`, and `pi-persona-deferred-input` by env/customType only.
34
+ - Model configuration changes are not persona switches;
35
+ `/persona models` must leave Mind's scope unchanged. Do not duplicate persona discovery here.
36
+ - Wakes are display-only (`appendEntry` + toast). Never `sendUserMessage` / `triggerTurn`.
37
+ - Lifecycle generations bound capture/injection UI state to the accepting session. An accepted
38
+ explicit capture may finish in its original store; its acknowledgement must not leak to a new turn.
39
+ - Nested tool results reach only their caller. Nudge on a blocked report only when the top-level
40
+ result actually relays it; bound provenance by `parentToolCallId` and clear it on lifecycle change.
41
+ - Persona/shared and repository LTM are durable across sessions. `scope: project` with long term
42
+ stays in the repository; promotion defaults there and requires an owned source. `project-long`
43
+ is the optimizer target; `project` still means working STM. Shared writes use `scope: shared`,
44
+ not a boolean. Existing persona facts are not automatically reassigned. STM/backlog auto-delete after ~48h. Explicit session notes live
45
+ in Pi's native active branch, survive compaction/resume, and stay absent from delegated workers.
46
+ A non-persistent host session reports in-memory storage; forget is a branch-local tombstone.
47
+ - Optimization is inspect → stage exact replacements → apply a short-lived plan ID. Similarity
48
+ is advisory. Compare the original raw store fingerprint under its lock; reject stale/expired
49
+ plans, invalid stores, ownership mixing, provenance overflow and extended STM expiry.
50
+ Lifecycle changes invalidate plans. Automatic semantic review is user-authorized and on by default
51
+ unless `PI_PERSONA_MIND_OPTIMIZE=off`; session commands may switch it immediately. Queue after a
52
+ successful remember/promotion. First eligible burst has no token floor; later attempts need dirty
53
+ memories AND 1M main-session input tokens since the prior launch (exclude output/cache/worker usage).
54
+ Usage alone never marks memories dirty. Coalesce 2s after `agent_settled` while idle with no queued
55
+ work; cool down 5min between actual attempts. Only the interrupted attempt can retry without the
56
+ token floor, after a later settled event and cooldown. One worker per instance; unchanged semantic
57
+ digests skip review. New input, agent start,
58
+ off or owner changes cancel and invalidate plans. Use a real visible
59
+ Persona-hosted Mind worker on exactly the session model, no fallback or arbitrary tools. Give it
60
+ at most 12 full source records/24k JSON characters, a 180s deadline and at most 4 strict JSON
61
+ replacement operations/12 source IDs each, then validate/apply through parent-owned
62
+ provenance/freshness/CAS checks. Shared memories and age-based deletion remain excluded. Preserve
63
+ durable before/after operator cards; worker completion is not proof of semantic truth.
64
+ - Rotate completed automatic review over older records/pages; account for actual byte admission,
65
+ preserve newest-fact inclusion, and never mark stopped/interrupted work as completed. No unbounded
66
+ sweeper. Optimizer receipts precede replacement and persist at most 32/2MiB per target; unresolved
67
+ prepared receipts are protected. Undo compares affected facts and owner generation under lock,
68
+ never restores expired STM or clobbers unrelated writes. Propagate uncertain-finalization warnings.
69
+ - Retrieval uses one lexical/tag/path ranker; do not introduce a second recall policy. All injected
70
+ tiers share a 2400-token planning estimate (UTF-8 bytes/3); session notes use up to 600. Include
71
+ wrappers, separators and omission counts, keep whole excerpts, and never exempt pinned facts from
72
+ the bound. The estimate and synthetic evaluation are not billing or semantic-quality guarantees.
73
+ - `exactOptionalPropertyTypes`: omit optional props; do not assign `undefined`.
74
+
75
+ ## Done
76
+
77
+ `npm run typecheck` clean, `npm test` green, full `npm audit --audit-level=low`, and package dry-run
78
+ inspection. Re-run after final edits. Keep published files explicit; no tests, drafts or local artifacts.
package/CHANGELOG.md ADDED
@@ -0,0 +1,78 @@
1
+ # Changelog
2
+
3
+ ## [0.8.4](https://github.com/AeonDave/pi-persona-mind/releases/tag/v0.8.4) - 2026-10-25
4
+
5
+ - Add durable project memory and scope-preserving promotion; expose project/persona/shared scope
6
+ consistently in tools, snapshots and diagnostics. Replace the shared-write boolean with scope.
7
+ - Rank injected context and recall by task words, tags and repository paths; apply a combined
8
+ token estimate across archive and session context, retaining explicit omissions and full reads.
9
+ - Rotate bounded automatic reviews over older records and retain durable consolidation receipts.
10
+ Add history and guarded undo that preserves unrelated writes and refuses stale affected facts.
11
+ - Add deterministic retrieval evaluation with an explicit baseline and no semantic-quality claim.
12
+
13
+ - Add automatic semantic consolidation through a visible asynchronous Mind worker on the current
14
+ session model. The first new-memory burst queues an idle review; subsequent attempts require new
15
+ memories and 1M main-session input tokens, excluding output/cache/worker usage. Rapid saves coalesce;
16
+ new input cancels the worker. Parent validation and fingerprint checks protect application; shared
17
+ memory is excluded.
18
+ `/mind optimize auto [status|on|off]` controls this session, doctor reports its state, and
19
+ `PI_PERSONA_MIND_OPTIMIZE=off` changes the initial default.
20
+ - Require the loaded pi-persona companion protocol; without it Mind remains inactive, including
21
+ direct programmatic calls. Local optimization appears as a Mind activity row in Persona's tree/F9.
22
+ - Use the actual live persona for memory ownership even with selection persistence disabled;
23
+ delegated workers keep their launching persona on both engines. Remove the obsolete selection mirror.
24
+ - Target Pi 1.4.0 exclusively; align development packages and native event contracts, and remove
25
+ the retired companion state-marker fallback. Existing memory-data imports remain available.
26
+ - Add active-branch session notes, honest persistent/in-memory receipts, and full ID-based memory
27
+ reads. Session notes preserve their origin across forks and never enter delegated worker context.
28
+ - Add explicit, bounded memory consolidation: inspect candidates, stage exact replacements, then
29
+ apply a fingerprint-checked plan. Preserve source lineage and STM expiry; refuse stale plans.
30
+ - Paginate inspection to reach older facts, and distinguish slow background imports from persistent
31
+ failures instead of leaving a successful import marked with a warning.
32
+ - Add `/persona-mind` with `/mind` as the same-handler alias, strict command parsing, session and
33
+ optimization commands, and consistent expandable command cards.
34
+ - Include inline flow reports in the blocked-work hint and preserve concurrent backlog additions
35
+ during expiry cleanup. Qualify package and companion integration on the current host.
36
+
37
+ ## [0.8.3](https://github.com/AeonDave/pi-persona-mind/releases/tag/v0.8.3) - 2026-10-20
38
+
39
+ - Read persona selection and startup `defaultPersona`/`persist` preferences from pi-persona's
40
+ canonical settings store, preserving legacy marker fallback only when canonical settings are absent.
41
+ - Contribute Mind's capture/nudge settings to pi-persona's unified settings panel, while retaining
42
+ environment overrides and session-start snapshot behavior.
43
+ - Scope marker latches and Mind-specific preference snapshots to Pi session IDs so child sessions
44
+ cannot reset their supervisor's active scope or companion controls.
45
+ - Match pi-persona's extension-factory snapshot for the scalar persona selectors, keeping Mind's
46
+ memory scope aligned across `/new` sessions until Pi reloads/restarts extensions.
47
+ - Reject malformed UTF-8 in canonical and legacy persona markers rather than deriving a replacement-character memory scope.
48
+
49
+ ## [0.8.2](https://github.com/AeonDave/pi-persona-mind/releases/tag/v0.8.2) - 2026-10-19
50
+
51
+ - Respect Pi's `--` CLI separator when resolving persona memory scope; prompt text resembling
52
+ `--persona` no longer selects a different memory store.
53
+ - Add isolated installed-Pi 1.3 qualification alongside the minimum-Pi 1.0 SDK suite, including
54
+ optional pi-persona integration for model refresh and delegated read-only memory.
55
+
56
+ ## [0.8.1](https://github.com/AeonDave/pi-persona-mind/releases/tag/v0.8.1) - 2026-10-13
57
+
58
+ - Handle Pi 1.2 custom-triggered completion reports from their attributed `before_agent_start`
59
+ message event, deduplicate follow-up nudges, and keep custom report text out of direct-user capture.
60
+
61
+ ## [0.8.0](https://github.com/AeonDave/pi-persona-mind/releases/tag/v0.8.0) - 2026-10-03
62
+
63
+ - Require Pi 1.0.0+ and Node.js 22.19.0+; keep host libraries and typebox as host-provided peers.
64
+ - Reset capture hints and empty-store announcements when a session changes; prevent late capture
65
+ notices and memory injection from leaking into the next session.
66
+ - Skip migration/storage waits for ordinary input with no capture cue.
67
+ - Preserve undelivered backlog alarms across slow storage reads and concurrent re-arm calls; a
68
+ newly queued reminder that is already due is shown immediately, without restarting Pi.
69
+ - Deduplicate a reminder's displayed deadline while acknowledgement persists, including re-arms
70
+ triggered by background migration; a later deadline remains eligible.
71
+ - Suggest backlog capture only for blocked nested output actually relayed by its outer tool.
72
+ - Enforce erasable-only TypeScript, including store/service constructors.
73
+ - Isolate test profiles; exercise capture, persistence, tool execution, display-only reminders and
74
+ read-only workers in real Pi 1.0 SDK sessions with an offline provider.
75
+ - Align package/lock metadata, upgrade development dependencies and pin three-platform CI actions.
76
+
77
+ Older storage roots remain readable through non-destructive migration. No existing store is deleted
78
+ or moved by the host compatibility update.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AeonDave
4
+
5
+ Portions of src/core/store.ts adapt the durable atomic-store pattern from
6
+ OpenLore (clay-good/openlore), also MIT-licensed.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,245 @@
1
- # Temporary Holding Version
1
+ <h1 align="center">pi-persona-mind</h1>
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
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/AeonDave/pi-persona-mind/v0.8.4/assets/banner.png" alt="pi-persona-mind — durable memory for Pi">
5
+ </p>
6
+
7
+ [![CI](https://github.com/AeonDave/pi-persona-mind/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/AeonDave/pi-persona-mind/actions/workflows/test.yml) [![npm version](https://img.shields.io/npm/v/@aeondave/pi-persona-mind?logo=npm)](https://www.npmjs.com/package/@aeondave/pi-persona-mind) [![License](https://img.shields.io/github/license/AeonDave/pi-persona-mind)](LICENSE)
8
+
9
+ Local memory for [Pi](https://github.com/earendil-works/pi): durable facts, session notes and
10
+ unfinished work. Bounded excerpts enter each turn; the agent can retrieve full entries when needed.
11
+
12
+ Requires a compatible loaded [pi-persona](https://github.com/AeonDave/pi-persona). The current
13
+ release pair is Mind 0.8.4 with Persona 1.17.5 or later.
14
+ Stores use local files and Pi's session history, without embeddings, a database or a separate service.
15
+ Automatic consolidation uses a visible Mind worker on your current session model. Memory injection and
16
+ worker review consume normal model tokens. A saved claim is not automatically a verified fact.
17
+
18
+ ## Install
19
+
20
+ Requires the **latest stable Pi (currently 1.4.0)** and **Node.js 22.19.0+**. Historical Pi releases
21
+ are not maintained. Windows, Linux and macOS are supported.
22
+
23
+ ```bash
24
+ pi install npm:@aeondave/pi-persona
25
+ pi install npm:@aeondave/pi-persona-mind
26
+ ```
27
+
28
+ Keep both extensions on a compatible release pair. Restart Pi or run `/reload` after installing or
29
+ updating them. Mind stays inactive when the compatible Persona companion is missing or incompatible,
30
+ with no memory capture, writes, injection or reminders.
31
+
32
+ | Install option | Command |
33
+ |---|---|
34
+ | This project only | `pi install -l npm:@aeondave/pi-persona-mind` |
35
+ | Pin Mind 0.8.4 | `pi install npm:@aeondave/pi-persona-mind@0.8.4` |
36
+ | Update the unpinned pair | `pi update npm:@aeondave/pi-persona`<br>`pi update npm:@aeondave/pi-persona-mind` |
37
+
38
+ When switching either extension from a Git install to npm, remove its exact Git source first (use
39
+ your pinned source if applicable):
40
+
41
+ ```bash
42
+ pi remove git:github.com/AeonDave/pi-persona
43
+ pi remove git:github.com/AeonDave/pi-persona-mind
44
+ ```
45
+
46
+ Keep only one source configured for each extension to avoid loading it twice.
47
+
48
+ ## Choose the right memory
49
+
50
+ | Kind | Scope | Lifetime |
51
+ |---|---|---|
52
+ | Long-term facts | Active persona, plus an explicit shared tier | Until explicitly changed or forgotten |
53
+ | Durable project facts | Current repository, with author persona recorded | Until explicitly changed or forgotten |
54
+ | Short-term facts | Current project, with author persona recorded | 48 hours by default |
55
+ | Session notes | Active Pi session branch | Follows that session's history |
56
+ | Backlog | Current project's deferred work | 48 hours by default; later reminders extend it |
57
+
58
+ Session notes survive compaction and resume of a persisted session. A new session starts without
59
+ them; a fork inherits its selected history and keeps each note's original session ID. With
60
+ `--no-session` or an in-memory SDK session, notes last only as long as that session. Forgetting a
61
+ note hides it on the current branch; it does not erase old transcript bytes.
62
+
63
+ Promote project knowledge that must outlive its expiry: promotion defaults to durable project memory,
64
+ keeping repository decisions out of other projects. Explicit `scope: persona|shared` broadens the
65
+ destination. Existing persona facts are not automatically moved or guessed to belong to a project.
66
+ Mind never imports private worker archives:
67
+ the supervisor reads a result through Intercom, checks it, then saves the useful fact and optional
68
+ source reference. A result reference is provenance, not permission to read another session.
69
+
70
+ ## Commands
71
+
72
+ `/mind` is an alias of `/persona-mind`; both execute the same handler.
73
+
74
+ | Command | Effect |
75
+ |---|---|
76
+ | `/persona-mind` | Project/persona memory snapshot |
77
+ | `/persona-mind help` | Command reference |
78
+ | `/persona-mind doctor` | Scope, capture policy, paths and recovery warnings |
79
+ | `/persona-mind session` | Bounded list of active-branch session notes |
80
+ | `/persona-mind reset` | Clear this project's short-term facts and backlog |
81
+ | `/persona-mind reset workspace` | Same explicit workspace reset |
82
+ | `/persona-mind migrate-persona` | Recover an ambiguous historical persona-data alias |
83
+ | `/persona-mind optimize [project\|project-long\|persona\|shared]` | Inspect a bounded selection; no changes |
84
+ | `/persona-mind optimize show <planId>` | Display an already staged plan |
85
+ | `/persona-mind optimize apply <planId>` | Apply that exact plan if still current |
86
+ | `/persona-mind optimize history [target]` | Review retained before/after receipts; default `project` |
87
+ | `/persona-mind optimize undo <receiptId> [target]` | Restore unchanged affected facts; default `project` |
88
+ | `/persona-mind optimize auto [status\|on\|off]` | Inspect or switch automatic review for this session |
89
+
90
+ Reset preserves long-term facts and session notes. `reset all` and unexpected extra arguments are
91
+ refused. Reports use expandable cards and short status notifications. Tool results have compact
92
+ previews with Pi's expand key, usually `ctrl+o`.
93
+
94
+ ## Agent tools
95
+
96
+ - `memory remember`: `term: long|short|session`, `kind`, `text`. Long/short facts also support tags,
97
+ source, lineage and supersession. For long facts choose `scope: project|persona|shared`; default
98
+ is persona. The old `shared` boolean is removed: use `scope: shared`.
99
+ - `memory recall`: lexical/path/tag discovery with `query`, `max`, and
100
+ `scope: long|short|both|project|persona|shared|session`. Project includes its durable and working
101
+ facts; long includes all durable tiers; both includes all active archives. Session is separate.
102
+ - `memory read`: full text and provenance by ID, including `session:<UUID>` notes.
103
+ - `memory forget`: remove a fact by ID, optionally restricted by scope, or tombstone a session note.
104
+ - `memory promote`: make an owned short-term fact durable in this project, unless another scope is explicit.
105
+ - `memory optimize`: inspect, stage, apply, history and undo; undo requires `receiptId` and explicit `target`.
106
+ - `backlog add|list|take|done|drop`: defer, inspect, claim or close work; reminders are optional.
107
+
108
+ Prefer declarative facts such as “The project uses Node 22.” An `objective` is prioritized in
109
+ durable injection; a session objective stays in its session.
110
+
111
+ Injection ranks current-task words, explicit tags and repository paths, with a small priority core
112
+ for objectives/invariants. Persona/shared, project, working context, backlog and session notes share
113
+ a **2,400-token planning estimate** (UTF-8 bytes / 3), including wrappers and omission notices.
114
+ Session notes use up to 600 of that estimate. This is not a provider tokenizer or a billing guarantee.
115
+ Whole excerpts are admitted under the budget, omitted facts are counted, and full reads remain available.
116
+ The retrieval is deterministic; it does not infer arbitrary synonyms or establish factual truth.
117
+
118
+ ## Review and consolidate
119
+
120
+ Ask the agent to inspect memories against new evidence and propose a consolidation.
121
+ The slash command alone is a local inspection, not a hidden model request. The agent evaluates
122
+ the evidence during its normal foreground turn.
123
+
124
+ 1. `memory {action:"optimize", mode:"inspect", target:"project"}` returns IDs and a fingerprint.
125
+ 2. Read full facts, then stage explicit replacements with that fingerprint and
126
+ `operations: [{sourceIds, kind, text, tags?, source?}]`.
127
+ 3. Review the before/after plan and apply its `planId` through the tool or slash command.
128
+
129
+ One source rewrites a fact; several sources merge them. Each transaction affects one tier.
130
+ `project` changes only the active persona's short-term rows; `project-long` changes that persona's
131
+ durable repository facts; `persona` targets that persona's
132
+ durable store across projects; `shared` targets shared durable facts. Inspect further pages through
133
+ `offset`/`nextOffset`; restart if the fingerprint changes. Similarity compares the current page,
134
+ so absence from its candidate list does not prove the store is duplicate-free.
135
+
136
+ Plans last ten minutes, at most four per active owner. Session/persona/workspace changes invalidate
137
+ them. Concurrent writes refuse application. Consolidation preserves origins and lineage, never
138
+ extends short-term expiry, and never trims unrelated records to fit storage limits. Lineage IDs
139
+ alone are not a full archive of removed text. Each applied consolidation now has a durable before/after
140
+ receipt written before replacement. History retains at most 32 receipts / 2 MiB per target, plus the
141
+ store's recovery backup. Undo preserves unrelated later writes and refuses altered replacements,
142
+ collisions, foreign ownership or expired source facts. A `prepared` receipt means an interrupted
143
+ intent whose commit may or may not have happened; it is kept rather than guessing. Ambiguous IO
144
+ failures can therefore require manual recovery if unresolved receipts fill the history budget.
145
+
146
+ Exact deduplication and expiry cleanup already run automatically. Lexical similarity only suggests
147
+ comparisons; it cannot distinguish agreement from contradiction. Age never deletes a durable fact.
148
+ See [research and decisions](docs/MEMORY-RESEARCH.md).
149
+
150
+ During inspection, staging and application, **Mind** appears in pi-persona's activity tree and F9
151
+ view. The row distinguishes local work, a prepared proposal and a terminal result.
152
+ It does not invent a worker model, tokens or a cancellable agent. Finished rows are bounded and
153
+ remain visible, so a fast local operation does not disappear before it can be read.
154
+
155
+ Automatic review is on by default. Successful saves/promotions mark project or persona memories
156
+ for review; shared memories are excluded. The first eligible burst can run after the main agent
157
+ settles. Every later attempt requires both new pending memories and **1,000,000 main-session input
158
+ tokens since the preceding attempt**. Output, cache and worker tokens do not count. Token usage
159
+ alone never schedules a review, and rapid additions stay queued together instead of launching a
160
+ worker for every save. This is a cost-control policy, not a research-derived optimum.
161
+ Requests coalesce for two seconds after the main agent settles, with no queued work, and actual
162
+ attempts have a five-minute cooldown. Only one review can run at a time; unchanged completed reviews
163
+ are skipped. New input cancels it; that interrupted attempt may retry after a later settled turn and
164
+ the cooldown without waiting for another million tokens. `/mind optimize auto off` cancels and clears
165
+ pending review; saves while off do not queue automatic work. Turning it on waits for the next save.
166
+ `on` and `off` apply immediately to this session. Set `PI_PERSONA_MIND_OPTIMIZE=off` for the initial
167
+ session default, and use `/mind doctor` to inspect the current state.
168
+
169
+ This is a real asynchronous Mind subagent with its own Persona view. It uses exactly the session's
170
+ model, without a substitute or fallback, and has no arbitrary tools. It receives at most 12 full memory
171
+ records within 24,000 JSON characters. Repeated admitted reviews rotate within inspection pages and
172
+ through older pages, reserving room for the newest eligible fact. Rotation resets with its owner;
173
+ it does not launch an unbounded cleanup loop or claim the whole store has been reviewed. It has a
174
+ three-minute deadline and proposes at most four strict
175
+ JSON replacements. The parent validates provenance, owner, freshness and the store fingerprint before
176
+ applying anything. A durable operator card records the before/after proposal before application;
177
+ rejected or stale proposals do not alter their target store. Automatic review does not authorize age-based
178
+ deletion, shared-memory editing or inference that an old fact is false.
179
+
180
+ ## Capture, reminders and collaboration
181
+
182
+ Explicit direct-user requests such as “remember that I prefer small changes” are saved before
183
+ the model starts, with a visible receipt. Casual cues suggest capture instead.
184
+
185
+ | Setting | Effect |
186
+ |---|---|
187
+ | `PI_PERSONA_MIND_CAPTURE=auto` | Capture explicit direct-user cues; default |
188
+ | `PI_PERSONA_MIND_CAPTURE=prompt` | Suggest a tool call without automatic writes |
189
+ | `PI_PERSONA_MIND_CAPTURE=off` | Disable cue detection and capture |
190
+ | `PI_PERSONA_MIND_NUDGE=off` | Disable suggestions, not explicit automatic capture |
191
+
192
+ The same preferences appear in pi-persona's settings panel. Environment overrides win; Mind refreshes
193
+ its capture/nudge preferences on session start. The loaded Persona runtime supplies the actual active
194
+ persona, including with selection persistence disabled. Changing council models does not switch memory
195
+ scope. Mind does not infer the active persona from old files or saved selection.
196
+
197
+ Quoted text, worker reports and Intercom/Exocom messages are not direct user input.
198
+ The reserved `pi-persona-deferred-input` replay preserves queued direct-user requests. This is
199
+ a convention between trusted extensions, not protection from arbitrary code in the same process.
200
+
201
+ Workers marked `PI_PERSONA_LEG` or `PI_PERSONA_CHILD` receive only durable identity/objectives:
202
+ their memory scope stays on the persona that launched them, even if the parent switches later.
203
+ They receive no project notes, session notes, backlog, memory tools or wakes. Blocked delegate/council/flow
204
+ reports can suggest backlog capture; they never write it automatically. Discarded nested reports
205
+ do not create invisible reminders.
206
+
207
+ A due backlog item creates one display-only card and a short toast, never an agent turn.
208
+ Opening Pi from the home directory suppresses project injection and wakes.
209
+
210
+ ## Storage and development
211
+
212
+ Under `<agentDir>/persona-mind/`: persona/shared facts in `memory/ltm/`, durable repository facts
213
+ in `memory/project/`, working facts in `memory/stm/`,
214
+ deferred work in `backlog/`. Session notes live in Pi's session file. Writes use exclusive locks,
215
+ ownership checks, atomic rename and a last-known-good backup. Imports of old memory data remain
216
+ non-destructive. Scanning and escaped injection reduce unsafe-content exposure; they do not
217
+ prove saved facts true or arbitrary text harmless.
218
+
219
+ An import exceeding the turn's wait budget continues in the background with a temporary information
220
+ notice. That alone does not mean data loss; older entries may become available later. Use
221
+ `/persona-mind doctor` for its state and actual warnings. After fixing a reported import problem,
222
+ `/reload` rechecks the retained original files.
223
+
224
+ ```bash
225
+ npm ci
226
+ npm run typecheck
227
+ npm test
228
+ npm run eval:memory
229
+ npm audit --audit-level=low
230
+ ```
231
+
232
+ Tests isolate profile/environment and exercise the real Pi 1.4 SDK with an offline provider.
233
+ Qualify an installed host with current pi-persona and optionally an extracted Mind tarball:
234
+
235
+ ```bash
236
+ node --import tsx scripts/qualify-host.mjs <pi-package-root> <pi-persona-extension> [<packed-mind-extension>]
237
+ node --import tsx scripts/qualify-package.ts <extracted-package>/src/index.ts <pi-persona-extension>
238
+ ```
239
+
240
+ The evaluation reports deterministic retrieval on a small synthetic corpus, including a prior
241
+ substring baseline and context estimates. It does not measure model merge quality or cloud cost.
242
+ These checks verify host integration, not provider authentication or semantic memory quality. Pi supplies
243
+ runtime peers. Development security overrides do not patch a separately installed Pi.
244
+
245
+ [Design and limits](docs/DESIGN.md) · [Changes](CHANGELOG.md) · [MIT license](LICENSE)
Binary file