pi-observational-memory 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -94,12 +94,14 @@ That's it. The extension hooks into Pi's compaction lifecycle automatically. No
94
94
 
95
95
  ### Extension settings
96
96
 
97
- Create `~/.pi/agent/observational-memory.json` (or `.pi/observational-memory.json` per project):
97
+ Settings live under the `observational-memory` key in Pi's `settings.json` — globally at `~/.pi/agent/settings.json`, or per-project at `.pi/settings.json`. Project values override global.
98
98
 
99
99
  ```json
100
100
  {
101
- "observationThreshold": 50000,
102
- "reflectionThreshold": 30000
101
+ "observational-memory": {
102
+ "observationThreshold": 50000,
103
+ "reflectionThreshold": 30000
104
+ }
103
105
  }
104
106
  ```
105
107
 
@@ -115,13 +117,15 @@ The observer and reflector don't need the same capabilities as your coding agent
115
117
 
116
118
  ```json
117
119
  {
118
- "compactionModel": { "provider": "openrouter", "id": "google/gemma-4-31b-it" }
120
+ "observational-memory": {
121
+ "compactionModel": { "provider": "openrouter", "id": "google/gemma-4-31b-it" }
122
+ }
119
123
  }
120
124
  ```
121
125
 
122
126
  ### Pi compaction settings
123
127
 
124
- The extension works with Pi's built-in compaction settings in `~/.pi/agent/settings.json`:
128
+ The extension works alongside Pi's built-in compaction settings in the same `settings.json`:
125
129
 
126
130
  ```json
127
131
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-observational-memory",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Observational memory extension for pi — cache-friendly tiered compaction with observations and reflections.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/config.ts CHANGED
@@ -13,24 +13,26 @@ export const DEFAULTS: Config = {
13
13
  reflectionThreshold: 30_000,
14
14
  };
15
15
 
16
- export function loadConfig(cwd: string): Config {
17
- const globalPath = join(getAgentDir(), "observational-memory.json");
18
- const projectPath = join(cwd, ".pi", "observational-memory.json");
19
-
20
- let globalConfig: Partial<Config> = {};
21
- let projectConfig: Partial<Config> = {};
16
+ const SETTINGS_KEY = "observational-memory";
22
17
 
23
- if (existsSync(globalPath)) {
24
- try {
25
- globalConfig = JSON.parse(readFileSync(globalPath, "utf-8"));
26
- } catch {}
18
+ function readNamespacedConfig(path: string): Partial<Config> {
19
+ if (!existsSync(path)) return {};
20
+ try {
21
+ const raw = JSON.parse(readFileSync(path, "utf-8")) as Record<string, unknown>;
22
+ const nested = raw[SETTINGS_KEY];
23
+ return nested && typeof nested === "object" ? (nested as Partial<Config>) : {};
24
+ } catch {
25
+ return {};
27
26
  }
27
+ }
28
28
 
29
- if (existsSync(projectPath)) {
30
- try {
31
- projectConfig = JSON.parse(readFileSync(projectPath, "utf-8"));
32
- } catch {}
33
- }
29
+ export function loadConfig(cwd: string): Config {
30
+ const globalPath = join(getAgentDir(), "settings.json");
31
+ const projectPath = join(cwd, ".pi", "settings.json");
34
32
 
35
- return { ...DEFAULTS, ...globalConfig, ...projectConfig };
33
+ return {
34
+ ...DEFAULTS,
35
+ ...readNamespacedConfig(globalPath),
36
+ ...readNamespacedConfig(projectPath),
37
+ };
36
38
  }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { completeSimple } from "@mariozechner/pi-ai";
2
2
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
3
- import { convertToLlm, serializeConversation } from "@mariozechner/pi-coding-agent";
3
+ import { convertToLlm, serializeConversation, SettingsManager } from "@mariozechner/pi-coding-agent";
4
4
  import { DEFAULTS, loadConfig } from "./config.js";
5
5
  import type { Config } from "./config.js";
6
6
  import { CONTEXT_USAGE_INSTRUCTIONS, OBSERVER_SYSTEM, REFLECTOR_SYSTEM } from "./prompts.js";
@@ -199,6 +199,7 @@ export default function observationalMemory(pi: ExtensionAPI) {
199
199
  const rawTokens = estimateRawTailTokens(entries);
200
200
  const obsTokens = estimateTokens(state.observations);
201
201
  const refTokens = estimateTokens(state.reflections);
202
+ const keepRecentTokens = SettingsManager.create(ctx.cwd).getCompactionKeepRecentTokens();
202
203
 
203
204
  const lines = [
204
205
  "── Observational Memory ──",
@@ -209,6 +210,7 @@ export default function observationalMemory(pi: ExtensionAPI) {
209
210
  "── Parameters ──",
210
211
  `Observation threshold: ${config.observationThreshold.toLocaleString()}`,
211
212
  `Reflection threshold: ${config.reflectionThreshold.toLocaleString()}`,
213
+ `Keep recent tokens: ${keepRecentTokens.toLocaleString()} (pi compaction)`,
212
214
  ];
213
215
 
214
216
  ctx.ui.notify(lines.join("\n"), "info");