@matthewfl/pi-contemplator 0.0.1
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/LICENSE +21 -0
- package/README.md +120 -0
- package/package.json +60 -0
- package/src/agents/contemplator/agent.ts +718 -0
- package/src/agents/contemplator/prompts.ts +212 -0
- package/src/agents/dropper/agent.ts +291 -0
- package/src/agents/dropper/coverage.ts +128 -0
- package/src/agents/dropper/pool.ts +67 -0
- package/src/agents/dropper/prompts.ts +48 -0
- package/src/agents/observer/agent.ts +207 -0
- package/src/agents/observer/prompts.ts +119 -0
- package/src/agents/reflector/agent.ts +213 -0
- package/src/agents/reflector/prompts.ts +81 -0
- package/src/agents/reviewer/agent.ts +187 -0
- package/src/agents/reviewer/history-tools.ts +337 -0
- package/src/agents/reviewer/prompts.ts +135 -0
- package/src/agents/reviewer/tools.ts +84 -0
- package/src/agents/stream-errors.ts +22 -0
- package/src/clipboard.ts +63 -0
- package/src/commands/contemplator-view.ts +128 -0
- package/src/commands/reviewer-view.ts +89 -0
- package/src/commands/settings.ts +257 -0
- package/src/commands/status.ts +176 -0
- package/src/commands/view.ts +171 -0
- package/src/config.ts +284 -0
- package/src/debug-log.ts +72 -0
- package/src/hooks/compaction-hook.ts +99 -0
- package/src/hooks/compaction-resume.ts +124 -0
- package/src/hooks/compaction-trigger.ts +122 -0
- package/src/hooks/consolidation-trigger.ts +488 -0
- package/src/ids.ts +5 -0
- package/src/index.ts +32 -0
- package/src/model-budget.ts +16 -0
- package/src/runtime.ts +316 -0
- package/src/serialize.ts +274 -0
- package/src/session-ledger/fold.ts +115 -0
- package/src/session-ledger/index.ts +7 -0
- package/src/session-ledger/progress.ts +156 -0
- package/src/session-ledger/projection.ts +243 -0
- package/src/session-ledger/recall.ts +258 -0
- package/src/session-ledger/render-summary.ts +31 -0
- package/src/session-ledger/search.ts +184 -0
- package/src/session-ledger/types.ts +329 -0
- package/src/tokens.ts +27 -0
- package/src/tools/compact-context.ts +54 -0
- package/src/tools/recall-observation.ts +532 -0
- package/src/tools/search-memories.ts +131 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pi-contemplator contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# pi-contemplator
|
|
2
|
+
|
|
3
|
+
`pi-contemplator` is a [Pi](https://pi.dev/) plugin designed to help long-running, unsupervised agentic sessions stay on track.
|
|
4
|
+
|
|
5
|
+
It adds a background **contemplator** agent that examines accumulated session memories for logical fallacies, unsupported assumptions, contradictions, and incorrect conclusions. When it finds a meaningful reasoning problem, it can interject with a focused question that helps the primary agent reconsider its reasoning before a mistaken premise poisons the rest of the session.
|
|
6
|
+
|
|
7
|
+
> [!WARNING]
|
|
8
|
+
> **Alpha-quality software:** `pi-contemplator` is under active development. Expect bugs, behavioral changes, and breaking configuration or memory-format changes.
|
|
9
|
+
|
|
10
|
+
> [!WARNING]
|
|
11
|
+
> **Significant token usage:** The plugin runs multiple background agents and will significantly increase model-token consumption and associated API costs, especially during long sessions.
|
|
12
|
+
|
|
13
|
+
> [!NOTE]
|
|
14
|
+
> 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 retains that project's observer, reflector, dropper, memory, and compaction foundations while adding contemplation and structural review capabilities.
|
|
15
|
+
|
|
16
|
+
## Why use it?
|
|
17
|
+
|
|
18
|
+
A long-running agent can draw the wrong conclusion from valid evidence and then repeatedly reinforce that conclusion. As the mistake accumulates in context, the agent becomes less likely to question it and less able to discover the real problem.
|
|
19
|
+
|
|
20
|
+
Without a contemplator, a session can look like this:
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
Run test X
|
|
24
|
+
|
|
25
|
+
Conclude Y from the output of X
|
|
26
|
+
|
|
27
|
+
Y is true
|
|
28
|
+
|
|
29
|
+
Y is true
|
|
30
|
+
|
|
31
|
+
Y is true
|
|
32
|
+
|
|
33
|
+
...
|
|
34
|
+
|
|
35
|
+
Y is true
|
|
36
|
+
|
|
37
|
+
The agent is now stuck. Its context has been poisoned by the repeated
|
|
38
|
+
assumption that Y is true, so it cannot identify the actual issue.
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
With the contemplator running in the background, the session can recover before that conclusion becomes entrenched:
|
|
42
|
+
|
|
43
|
+
```text
|
|
44
|
+
Run test X
|
|
45
|
+
|
|
46
|
+
Conclude Y from the output of X
|
|
47
|
+
|
|
48
|
+
Y is true
|
|
49
|
+
|
|
50
|
+
Contemplator interjection: You ran a test for X and then concluded that Y is
|
|
51
|
+
true. Did you consider A, B, and C? Each could also explain the result you
|
|
52
|
+
observed. A quick distinguishing test could be ...
|
|
53
|
+
|
|
54
|
+
That is a good point. Let me run a quick test to determine which of Y, A, B,
|
|
55
|
+
or C is true.
|
|
56
|
+
|
|
57
|
+
Run test ... It appears that Y and B are false, while A or C is a much better
|
|
58
|
+
explanation for the issue.
|
|
59
|
+
|
|
60
|
+
A or C is true
|
|
61
|
+
|
|
62
|
+
A or C is true
|
|
63
|
+
|
|
64
|
+
...
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The contemplator does not take over the primary agent's work. It provides occasional, evidence-grounded challenges when reconsidering the current reasoning is more valuable than allowing the session to continue along the same path.
|
|
68
|
+
|
|
69
|
+
## Background agents
|
|
70
|
+
|
|
71
|
+
`pi-contemplator` uses five specialized background agents:
|
|
72
|
+
|
|
73
|
+
| Agent | Purpose | Compared with `pi-observational-memory` |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| **Observer** | Extracts concrete, durable observations from the primary session. | Same as `pi-observational-memory` |
|
|
76
|
+
| **Reflector** | Finds higher-level patterns and relationships across observations. | Same as `pi-observational-memory` |
|
|
77
|
+
| **Dropper** | Removes observations that are obsolete, redundant, or safely represented elsewhere. | Same as `pi-observational-memory` |
|
|
78
|
+
| **Contemplator** | Watches accumulated memories for reasoning gaps, contradictions, overlooked alternatives, and recurring structural concerns; it can send a focused probe to the primary agent. | Added by `pi-contemplator` |
|
|
79
|
+
| **Reviewer** | Performs a deeper, scoped workflow or software-design investigation when the contemplator identifies a well-supported recurring structural issue. | Added by `pi-contemplator` |
|
|
80
|
+
|
|
81
|
+
The observer, reflector, and dropper 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.
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
Install the published package through Pi:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pi install npm:@matthewfl/pi-contemplator
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Or run it directly from a local checkout:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pi -e ./src/index.ts
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Configuration and commands
|
|
98
|
+
|
|
99
|
+
The plugin works with its defaults, including the contemplator and reviewer. Model selection, trigger thresholds, passive mode, compaction behavior, and other settings are documented in [docs/configuration.md](docs/configuration.md).
|
|
100
|
+
|
|
101
|
+
Useful commands include:
|
|
102
|
+
|
|
103
|
+
- `/om:status` — show memory and background-agent status.
|
|
104
|
+
- `/om:view contemplator` — inspect the contemplator's persisted private transcript.
|
|
105
|
+
- `/om:view reviewer` — inspect structural reviewer transcripts and outcomes.
|
|
106
|
+
- `/om:settings` — inspect or change session-level settings.
|
|
107
|
+
|
|
108
|
+
See [docs/how-it-works.md](docs/how-it-works.md) for the memory lifecycle and detailed behavior.
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install
|
|
114
|
+
npm test
|
|
115
|
+
npm run typecheck
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT. See [LICENSE](LICENSE).
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@matthewfl/pi-contemplator",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A Pi extension that keeps long-running agentic sessions on track with background memory, contemplation, and structural review.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "matthewfl",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/matthewfl/pi-contemplator.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/matthewfl/pi-contemplator#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/matthewfl/pi-contemplator/issues"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"pi",
|
|
21
|
+
"pi-agent",
|
|
22
|
+
"pi-package",
|
|
23
|
+
"extension",
|
|
24
|
+
"contemplator",
|
|
25
|
+
"observational-memory",
|
|
26
|
+
"memory",
|
|
27
|
+
"compaction",
|
|
28
|
+
"agentic"
|
|
29
|
+
],
|
|
30
|
+
"pi": {
|
|
31
|
+
"extensions": [
|
|
32
|
+
"./src/index.ts"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"src/",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"test": "vitest run"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@earendil-works/pi-agent-core": "*",
|
|
46
|
+
"@earendil-works/pi-ai": "*",
|
|
47
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
48
|
+
"@earendil-works/pi-tui": "*"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@earendil-works/pi-agent-core": "^0.81.0",
|
|
52
|
+
"@earendil-works/pi-ai": "^0.81.0",
|
|
53
|
+
"@earendil-works/pi-coding-agent": "^0.81.0",
|
|
54
|
+
"@earendil-works/pi-tui": "^0.81.0",
|
|
55
|
+
"@types/node": "^22.0.0",
|
|
56
|
+
"typebox": "^1.1.38",
|
|
57
|
+
"typescript": "^5.6.0",
|
|
58
|
+
"vitest": "^4.1.5"
|
|
59
|
+
}
|
|
60
|
+
}
|