@matthewfl/pi-contemplator 0.0.9 → 0.1.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/README.md +17 -11
- package/package.json +8 -6
- package/src/agents/contemplator/agent.ts +325 -91
- package/src/agents/contemplator/prompts.ts +6 -6
- package/src/agents/observer/agent.ts +14 -6
- package/src/agents/observer/prompts.ts +16 -7
- package/src/agents/reviewer/agent.ts +24 -4
- package/src/agents/reviewer/prompts.ts +1 -1
- package/src/agents/reviewer/tools.ts +24 -9
- package/src/agents/stream-errors.ts +1 -1
- package/src/agents/summarizer/agent.ts +597 -0
- package/src/agents/summarizer/prompts.ts +46 -0
- package/src/agents/summarizer/sampling.ts +80 -0
- package/src/commands/contemplator-view.ts +22 -1
- package/src/commands/settings.ts +73 -69
- package/src/commands/status.ts +60 -36
- package/src/commands/summarizer-view.ts +58 -0
- package/src/commands/view.ts +22 -10
- package/src/config.ts +25 -32
- package/src/hooks/compaction-hook.ts +36 -19
- package/src/hooks/compaction-resume.ts +4 -4
- package/src/hooks/compaction-trigger.ts +96 -56
- package/src/hooks/consolidation-trigger.ts +213 -196
- package/src/memory-citations.ts +37 -0
- package/src/required-tool-choice.ts +28 -0
- package/src/runtime.ts +116 -33
- package/src/session-ledger/fold.ts +82 -53
- package/src/session-ledger/index.ts +1 -0
- package/src/session-ledger/pools.ts +77 -0
- package/src/session-ledger/progress.ts +7 -18
- package/src/session-ledger/projection.ts +45 -177
- package/src/session-ledger/recall.ts +129 -127
- package/src/session-ledger/render-summary.ts +20 -19
- package/src/session-ledger/search.ts +99 -115
- package/src/session-ledger/types.ts +102 -75
- package/src/tools/compact-context.ts +1 -1
- package/src/tools/recall-observation.ts +99 -459
- package/src/tools/search-memories.ts +31 -72
- package/src/agents/dropper/agent.ts +0 -291
- package/src/agents/dropper/coverage.ts +0 -128
- package/src/agents/dropper/pool.ts +0 -67
- package/src/agents/dropper/prompts.ts +0 -48
- package/src/agents/reflector/agent.ts +0 -213
- package/src/agents/reflector/prompts.ts +0 -81
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`pi-contemplator` is a [Pi](https://pi.dev/) plugin for long-running, largely unsupervised agentic sessions. It does two things:
|
|
4
4
|
|
|
5
|
-
1. **Keeps memory alive across compaction.** A background **observer
|
|
5
|
+
1. **Keeps memory alive across compaction.** A background **observer** records evidence and a **summarizer** progressively condenses older memories into a durable, branch-local citation graph. When Pi compacts the context window, the active memory is rendered deterministically from that ledger — fast, model-free, and lossless enough that important facts survive.
|
|
6
6
|
2. **Gives the primary agent a second set of eyes.** A background **contemplator** reads the accumulated memories and watches for reasoning that is going wrong. When it finds a genuine problem, it can inject a focused, memory-cited question. For deeper, recurring structural issues, it can commission a short-lived **reviewer** that produces a durable, advisory design proposal.
|
|
7
7
|
|
|
8
8
|
The result: a long session is less likely to drift off course, get stuck in an unproductive loop, or silently compound a wrong conclusion — and when it does, it can often catch itself before the mistake poisons the rest of the work.
|
|
@@ -14,7 +14,7 @@ The result: a long session is less likely to drift off course, get stuck in an u
|
|
|
14
14
|
> **Significant token usage:** The plugin runs multiple background agents and will significantly increase model-token consumption and associated API costs, especially during long sessions.
|
|
15
15
|
|
|
16
16
|
> [!NOTE]
|
|
17
|
-
> This project is a fork of the excellent [pi-observational-memory](https://github.com/elpapi42/pi-observational-memory) plugin by [@elpapi42](https://github.com/elpapi42). It
|
|
17
|
+
> This project is a fork of the excellent [pi-observational-memory](https://github.com/elpapi42/pi-observational-memory) plugin by [@elpapi42](https://github.com/elpapi42). It builds on that project's observational-memory and compaction foundations, replacing separate reflection/pruning workers with a provenance-preserving summarizer while adding contemplation and structural review capabilities.
|
|
18
18
|
|
|
19
19
|
## Why use it?
|
|
20
20
|
|
|
@@ -127,9 +127,9 @@ Proposals are deliberately conceptual — the reviewer cannot write code, specif
|
|
|
127
127
|
|
|
128
128
|
The memory system is built to be trustworthy:
|
|
129
129
|
|
|
130
|
-
- **Every memory has provenance.** Observations cite the exact source entries that support them;
|
|
131
|
-
- **
|
|
132
|
-
- **Compaction is deterministic and model-free.** The
|
|
130
|
+
- **Every memory has provenance.** Observations cite the exact source entries that support them; summaries cite at least two source memories inline and retain machine-readable backpointers. Everything gets a deterministic 12-character id computed in code, not guessed by a model.
|
|
131
|
+
- **Condensation stays navigable.** Once a memory is consumed by a summary it leaves the injected active pool, but remains searchable and recallable. `recall` shows immediate backward and forward graph links so the agent can walk from a summary to its evidence or from old evidence to the summaries that consumed it.
|
|
132
|
+
- **Compaction is deterministic and model-free.** The active memory the agent sees is folded from the ledger by code, not rewritten during compaction by a model. That makes compaction fast and cheap, and it means the same session state always produces the same result.
|
|
133
133
|
|
|
134
134
|
## Why you can trust it in the background
|
|
135
135
|
|
|
@@ -144,17 +144,16 @@ Running extra agents in the background can be worrying — what if they take ove
|
|
|
144
144
|
|
|
145
145
|
## Background agents
|
|
146
146
|
|
|
147
|
-
`pi-contemplator` uses
|
|
147
|
+
`pi-contemplator` uses four specialized background agents, all enabled by default:
|
|
148
148
|
|
|
149
149
|
| Agent | What it does | When it runs |
|
|
150
150
|
|---|---|---|
|
|
151
|
-
| **Observer** | Extracts concrete, timestamped observations from the primary session, citing source entries. | In the background after turns, once enough new source text accumulates. |
|
|
152
|
-
| **
|
|
153
|
-
| **Dropper** | Prunes observations that are obsolete, redundant, or safely represented elsewhere, keeping the active memory pool bounded. | Only after a successful reflection, when the memory pool is over target. |
|
|
151
|
+
| **Observer** | Extracts concrete, timestamped observations from the primary session, citing source entries and assigning a simple retention class. | In the background after turns, once enough new source text accumulates. |
|
|
152
|
+
| **Summarizer** | Condenses related old observations and summaries into shorter, citation-linked summaries. Consumed sources leave active context but remain searchable and recallable through the graph. | When the old memory pool exceeds its token target; the newest memory pool remains protected. |
|
|
154
153
|
| **Contemplator** | Watches accumulated memories for reasoning gaps, contradictions, overlooked alternatives, and recurring structural concerns; can send a focused probe or request a review. | Asynchronously after enough new memories accumulate. |
|
|
155
154
|
| **Reviewer** | Performs a deep, scoped (workflow or software) structural investigation and records a durable proposal or a no-proposal conclusion. | Only when the contemplator commissions a review, and only one at a time. |
|
|
156
155
|
|
|
157
|
-
The observer
|
|
156
|
+
The observer and summarizer provide the durable memory substrate. The contemplator reasons over that substrate, while the reviewer is launched only when a concern warrants a deeper structural investigation.
|
|
158
157
|
|
|
159
158
|
## Installation
|
|
160
159
|
|
|
@@ -180,8 +179,9 @@ Useful commands:
|
|
|
180
179
|
- `/om:view` — inspect visible memory (and attempt to copy it).
|
|
181
180
|
- `/om:view full` — inspect the full memory ledger, including everything not yet folded into a compaction.
|
|
182
181
|
- `/om:view contemplator` — inspect the contemplator's private transcript and probes.
|
|
182
|
+
- `/om:view summarizer` — inspect the latest launch-local summarizer transcript, including live thinking/output and completion or failure status.
|
|
183
183
|
- `/om:view reviewer` — inspect structural reviewer transcripts and outcomes.
|
|
184
|
-
- `/om:settings` — inspect or change session-level settings (including `messages on|off`, `reviewer on|off`, `compaction on|off`).
|
|
184
|
+
- `/om:settings` — inspect or change session-level settings (including `messages on|off`, `summarizer on|off`, `reviewer on|off`, `compaction on|off`).
|
|
185
185
|
|
|
186
186
|
Model selection, trigger thresholds, passive mode (which stops all background work), compaction behavior, and other tuning are documented in [docs/configuration.md](docs/configuration.md). See [docs/how-it-works.md](docs/how-it-works.md) for the memory lifecycle and [docs/concepts.md](docs/concepts.md) for the mental model.
|
|
187
187
|
|
|
@@ -190,9 +190,15 @@ Model selection, trigger thresholds, passive mode (which stops all background wo
|
|
|
190
190
|
```bash
|
|
191
191
|
npm install
|
|
192
192
|
npm test
|
|
193
|
+
npm run test:unit
|
|
194
|
+
npm run test:e2e
|
|
193
195
|
npm run typecheck
|
|
194
196
|
```
|
|
195
197
|
|
|
198
|
+
`npm test` runs both the unit and RPC end-to-end suites. Use `test:unit` or `test:e2e` to run either suite independently.
|
|
199
|
+
|
|
200
|
+
`test:e2e` starts a local OpenAI-compatible model server and launches isolated real Pi CLI processes in RPC mode while mocking only the external model-server boundary. The suites cover observer, summarizer, contemplator, reviewer, primary-agent, memory-tool, and compaction flows. They exercise slow and parallel tools, probe races and feedback, hidden/idle delivery, cumulative activity time, process restore, reviewer transcript resume and budget exhaustion, accepted/rejected reviews, manual/failed compaction continuations and non-restarting proactive compaction, compaction observer sidecars, malformed memory records, huge-source bounding, id collisions, role-specific model routing, feature flags, session-tree forks, and concurrent session isolation.
|
|
201
|
+
|
|
196
202
|
## License
|
|
197
203
|
|
|
198
204
|
MIT. See [LICENSE](LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matthewfl/pi-contemplator",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "A Pi extension that keeps long-running agentic sessions on track with background memory, contemplation, and structural review.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|
|
41
41
|
"typecheck": "tsc --noEmit",
|
|
42
|
-
"test": "
|
|
42
|
+
"test": "npm run test:unit && npm run test:e2e",
|
|
43
|
+
"test:unit": "vitest run",
|
|
44
|
+
"test:e2e": "node tests/e2e/rpc-contemplator.mjs && node tests/e2e/rpc-summarizer.mjs && node tests/e2e/rpc-delivery.mjs && node tests/e2e/rpc-restore-review.mjs && node tests/e2e/rpc-compaction.mjs && node tests/e2e/rpc-compaction-resilience.mjs && node tests/e2e/rpc-memory-edges.mjs && node tests/e2e/rpc-routing-isolation.mjs"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
47
|
"@earendil-works/pi-agent-core": "*",
|
|
@@ -48,10 +50,10 @@
|
|
|
48
50
|
"@earendil-works/pi-tui": "*"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@earendil-works/pi-agent-core": "^0.
|
|
52
|
-
"@earendil-works/pi-ai": "^0.
|
|
53
|
-
"@earendil-works/pi-coding-agent": "^0.
|
|
54
|
-
"@earendil-works/pi-tui": "^0.
|
|
53
|
+
"@earendil-works/pi-agent-core": "^0.84.3",
|
|
54
|
+
"@earendil-works/pi-ai": "^0.84.3",
|
|
55
|
+
"@earendil-works/pi-coding-agent": "^0.84.3",
|
|
56
|
+
"@earendil-works/pi-tui": "^0.84.3",
|
|
55
57
|
"@types/node": "^22.0.0",
|
|
56
58
|
"typebox": "^1.1.38",
|
|
57
59
|
"typescript": "^5.6.0",
|