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 +9 -5
- package/package.json +1 -1
- package/src/config.ts +18 -16
- package/src/index.ts +3 -1
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
|
-
|
|
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
|
-
"
|
|
102
|
-
|
|
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
|
-
"
|
|
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
|
|
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
package/src/config.ts
CHANGED
|
@@ -13,24 +13,26 @@ export const DEFAULTS: Config = {
|
|
|
13
13
|
reflectionThreshold: 30_000,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 {
|
|
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");
|