pi-observational-memory-extension 0.1.2 → 0.2.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,83 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ### 📖 How to Work with This Changelog
11
+
12
+ When preparing a new release:
13
+ 1. **Always use Semantic Versioning** (`[Major.Minor.Patch]`).
14
+ 2. **Group changes under standard subheadings**:
15
+ - `Added` for new features.
16
+ - `Changed` for changes in existing functionality.
17
+ - `Deprecated` for soon-to-be removed features.
18
+ - `Removed` for now removed features.
19
+ - `Fixed` for any bug fixes.
20
+ - `Security` in case of vulnerabilities or security updates.
21
+ 3. **Keep descriptions concise, technical, and objective** (lowcase, founder-builder voice).
22
+ 4. **Link references or commit highlights** if appropriate.
23
+
24
+ ---
25
+
26
+ ## [0.2.0] - 2026-06-23
27
+
28
+ ### Added
29
+ - **retrieval**: Added vector retrieval for observations before context injection.
30
+ - **retrieval**: Added local hash/BOW retrieval as the default offline provider.
31
+ - **retrieval**: Added configurable Gemini embedding retrieval with `gemini-embedding-001`.
32
+ - **scope**: Added `session` and `project` memory scopes with separate durable storage paths.
33
+ - **attachments**: Added `auto`, `on`, and `off` attachment observation modes with image and size safeguards.
34
+ - **caveman**: Replaced the simplified terse mode with Mastra-style caveman compression instructions.
35
+ - **dedupe**: Added exact-hash and similarity-based duplicate suppression before appending observations.
36
+
37
+ ### Changed
38
+ - **state**: Migrated OM state schema to v3 for retrieval, vectors, attachment modes, and scoped storage.
39
+ - **settings**: Extended `/om set` with `scope`, `retrieval`, `retrieval-model`, `retrieval-top-k`, and `retrieval-threshold`.
40
+
41
+ ### Fixed
42
+ - **state**: Resolved JSON state file corruption caused by running regex redactions after serialization.
43
+ - **redaction**: Refined token/secret sanitization to avoid over-redacting non-sensitive metrics (e.g., `observationTokens`).
44
+ - **scope**: Added durable session pointer resolution, ensuring project scope selection persists across separate run processes.
45
+ - **durability**: Added automatic `.corrupted` rename recovery for unparseable state files instead of crashing.
46
+
47
+ ### Tested
48
+ - **regression**: Added tests for scope settings, attachment gates, duplicate suppression, and local retrieval.
49
+ - **provider**: Smoke-tested Gemini embeddings against `gemini-embedding-001` with valid 3072-dimensional normalized vectors.
50
+
51
+ ## [0.1.3] - 2026-06-23
52
+
53
+ ### Added
54
+ - **settings**: Added the unified `/om` command with `status`, `set`, `reset`, `enable`, `disable`, `observe`, `reflect`, and `memory` actions.
55
+ - **settings**: Persisted model overrides, thresholds, caveman compression mode, attachment observation toggle, and scope configuration in OM state.
56
+ - **tests**: Added a focused regression test suite for redaction, prompt limiting, stale lock recovery, settings parsing, v1→v2 migration, and atomic writes.
57
+
58
+ ### Fixed
59
+ - **durability**: State files now use atomic temp-file writes with `.bak` recovery support.
60
+ - **stability**: Stale operation locks are recovered automatically instead of blocking future OM runs forever.
61
+ - **security**: State, debug logs, recall/observer serialization, and model outputs now redact common API keys, npm tokens, GitHub tokens, bearer tokens, passwords, and secret fields.
62
+ - **context**: Observer prompts now cap previous observations to a bounded tail to prevent observation-context bloat.
63
+
64
+ ## [0.1.2] - 2026-06-22
65
+
66
+ ### Fixed
67
+ - **om**: Resolved "stale context" errors during asynchronous `session_shutdown` handlers and background buffer tasks.
68
+ - **om**: Safely caught uncaught promise rejections within internal `bufferObservation` tasks when contexts are deactivated by Pi.
69
+
70
+ ## [0.1.1] - 2026-06-22
71
+
72
+ ### Added
73
+ - **om**: Added capability to force immediate observational compaction on `session_shutdown` if pending message tokens exist. This guarantees subagent and short-lived loopflow sessions persist their memories before exiting.
74
+
75
+ ## [0.1.0] - 2026-06-22
76
+
77
+ ### Added
78
+ - **om**: First release of the Mastra-style **Observational Memory (OM)** extension.
79
+ - **om**: Implemented the 3-Agent psychological memory model: Actor (Main Agent), Observer (Extraction Agent), and Reflector (Consolidation/Compression Agent).
80
+ - **om**: Automatically intercepts `/compact` and `session_before_compact` events.
81
+ - **om**: Real-time TUI status bar panel underneath the input showing memory, message, and token thresholds.
82
+ - **om**: Color-coded, responsive status indicators for high (🔴), medium (🟡), and low (🟢) priority observations.
83
+ - **om**: Dedicated interactive, fullscreen overlay `/om-memory` with interactive tab switching (`Memory`, `Status`, `Debug`) and ANSI word wrapping.
package/README.md CHANGED
@@ -25,29 +25,50 @@ Legacy compaction compresses raw history into a single monolithic block of text,
25
25
  - **Async Buffering:** Extracts observations in the background at regular intervals (every 20% of the threshold) so that when the main threshold is hit, the accumulated memory is swapped/activated instantly with zero LLM-latency overhead.
26
26
  - **Adaptive Thresholds:** The active message-observation threshold expands dynamically based on remaining memory capacity in the reflection pool, maximizing raw context usage safely.
27
27
  - **Recall-driven Retrieval:** Exposes an `om_recall` tool to the Actor so it can retrieve full, raw message payloads from observed history when exact code, quotes, or numbers are needed.
28
+ - **Vector Retrieval:** Ranks relevant observations before context injection. Local hash/BOW retrieval is enabled by default; Gemini embeddings (`gemini-embedding-001`) are available through `/om set retrieval gemini`.
29
+ - **Session or Project Scope:** Stores memory either per session head or shared project memory via `/om set scope session|project`.
30
+ - **Attachment Observation Modes:** Supports `auto`, `on`, and `off` with image-only auto mode and size limits to avoid unsafe prompt bloat.
31
+ - **Duplicate Suppression:** Skips exact and near-duplicate observations before appending new memory.
28
32
  - **Custom Compaction Hook:** Plugs directly into Pi's `session_before_compact` lifecycle event. Typing `/compact` or triggering auto-compaction launches the Observer/Reflector memory consolidation flow instead of Pi's legacy summary compaction.
29
33
  - **TUI Overlay Panel:** Fully custom, responsive, multi-tab overlay (`/om-memory`) in interactive mode for inspecting memory. Features tabbed navigation, smooth scroll, and precise border framing.
30
- - **Durable Persistence:** Serializes and loads state files safely under `.pi/om/<session-id>.json`. Outputs JSON-formatted diagnostic logs to `.pi/om/debug/` for every operation.
34
+ - **Durable Persistence:** Serializes and loads state files safely under `.pi/om/sessions/<session-id>.json` or `.pi/om/projects/project.json` using atomic writes and `.bak` recovery. Outputs JSON-formatted diagnostic logs to `.pi/om/debug/` for every operation.
35
+ - **Secret Redaction:** Redacts common API keys, npm/GitHub tokens, bearer tokens, passwords, and secret fields before writing state/debug artifacts or observer text.
36
+ - **Stale Lock Recovery:** Recovers old interrupted OM operation locks automatically so a crashed or killed process does not block future memory runs.
37
+ - **Bounded Observer Context:** Sends only a safe tail of previous observations to the Observer, preventing recursive prompt bloat while preserving full memory in the main runtime.
31
38
 
32
39
  ---
33
40
 
34
41
  ## 📋 Configuration & Settings
35
42
 
36
- You can customize Observational Memory behaviors by specifying fields inside your project's `.pi/settings.json` or globally inside `~/.pi/agent/settings.json`.
43
+ Use `/om` in Pi to inspect and update runtime settings. Settings are persisted in the OM state file under `.pi/om/sessions/<session-id>.json` or `.pi/om/projects/project.json`.
37
44
 
38
- ```json
39
- {
40
- "compaction": {
41
- "enabled": true,
42
- "reserveTokens": 16384,
43
- "keepRecentTokens": 20000
44
- }
45
- }
45
+ ```bash
46
+ /om
47
+ /om set observation-threshold 30000
48
+ /om set reflection-threshold 40000
49
+ /om set block-after 36000
50
+ /om set buffer-tokens 6000
51
+ /om set buffer-activation 80%
52
+ /om set observation-model google/gemini-2.5-flash
53
+ /om set reflection-model google/gemini-2.5-flash
54
+ /om set caveman on
55
+ /om set attachments auto
56
+ /om set scope project
57
+ /om set retrieval local
58
+ /om set retrieval gemini
59
+ /om set retrieval-model gemini-embedding-001
60
+ /om set retrieval-top-k 6
61
+ /om set retrieval-threshold 12%
62
+ /om reset
46
63
  ```
47
64
 
48
- - **Observation Trigger Threshold:** ~`30,000` raw message tokens.
49
- - **Reflection Trigger Threshold:** ~`40,000` observation tokens.
65
+ - **Observation Trigger Threshold:** default `30,000` raw message tokens.
66
+ - **Reflection Trigger Threshold:** default `40,000` observation tokens.
50
67
  - **Default Models:** `google/gemini-2.5-flash` with 0.3 temperature for Observer, and 0.0 temperature for Reflector.
68
+ - **Caveman Mode:** optional terse compression style for denser memory.
69
+ - **Attachment Observation Mode:** `auto` observes small images only, `on` allows supported attachments, and `off` omits them.
70
+ - **Scope:** `session` keeps each session isolated; `project` shares one memory file for the current project.
71
+ - **Retrieval:** `local` is the default and works offline; `gemini` uses Gemini embeddings when `GEMINI_API_KEY` or `GOOGLE_GENERATIVE_AI_API_KEY` is available; `off` disables vector retrieval.
51
72
 
52
73
  ---
53
74
 
@@ -55,6 +76,7 @@ You can customize Observational Memory behaviors by specifying fields inside you
55
76
 
56
77
  This extension registers the following slash commands in Pi:
57
78
 
79
+ - `/om` — Unified settings/status command. Supports `set`, `reset`, `enable`, `disable`, `observe`, `reflect`, and `memory`.
58
80
  - `/om-status` — Shows a detailed breakdown of pending/observation tokens, active locks, thresholds, and last operation results.
59
81
  - `/om-memory` — Opens the interactive multi-tab overlay panel (observations, status stats, and background debug details).
60
82
  - `/om-observe` — Forces an immediate Observation pass on all pending raw message history.
@@ -88,6 +110,7 @@ Run the typechecker and validation scripts before packaging or releasing:
88
110
  ```bash
89
111
  npm run typecheck
90
112
  npm run validate
113
+ npm test
91
114
  ```
92
115
 
93
116
  ### Commit Guidelines