pi-automem-bridge 0.2.0 → 0.2.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 +75 -29
- package/examples/config.advanced.json +61 -59
- package/package.json +61 -58
- package/src/config.ts +262 -251
- package/src/mcp-client.ts +401 -361
- package/src/project-detect.ts +96 -94
- package/src/recall.ts +283 -254
- package/src/tools/memory-tools.ts +307 -307
- package/src/tools/relationship-tools.ts +121 -114
- package/src/write-policy.ts +148 -142
package/README.md
CHANGED
|
@@ -1,19 +1,48 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
# pi-automem-bridge
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
> **AutoMem is the memory. This bridge ensures pi actually uses it.**
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
pi install npm:pi-automem-bridge
|
|
9
11
|
```
|
|
10
12
|
|
|
13
|
+
[](https://badge.fury.io/js/pi-automem-bridge)
|
|
14
|
+
[](https://www.npmjs.com/package/pi-automem-bridge)
|
|
15
|
+
|
|
11
16
|
[](https://ko-fi.com/L2J320X82M)
|
|
12
17
|
|
|
13
18
|
</div>
|
|
14
19
|
|
|
15
20
|
---
|
|
16
21
|
|
|
22
|
+
## Why pi-automem-bridge
|
|
23
|
+
|
|
24
|
+
Plenty of agents can store a memory. Far fewer reach for it when it counts — or check what they're scribbling down. pi-automem-bridge makes pi do both, automatically: startup + per-turn recall injected straight into the prompt, and a secret-scanning, policy-gated write pipeline guarding the door to AutoMem.
|
|
25
|
+
|
|
26
|
+
- **Per-project scoping** — recall limits and filters tuned to the repo or folder you're working in.
|
|
27
|
+
- **Bring your own AutoMem** — talks to your existing instance over MCP. No duplicate credentials or storage to manage.
|
|
28
|
+
|
|
29
|
+
> The storage and the recall/similarity intelligence are [AutoMem](https://github.com/verygoodplugins/automem)'s. This package is the guardrail-and-automation layer that makes them automatic inside pi.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## How it works
|
|
34
|
+
|
|
35
|
+
Once installed, the bridge hooks into pi's session lifecycle:
|
|
36
|
+
|
|
37
|
+
- **At session start** it runs your startup recall queries against AutoMem and injects the results — your preferences, working style, and environment — into the system prompt.
|
|
38
|
+
- **Before each turn** it recalls memories relevant to the current task and the detected project, again injected silently.
|
|
39
|
+
- **When the agent writes a memory** the candidate passes through the write pipeline — normalize → secret-scan → policy check → dedupe → confirm or auto-store — so nothing unvetted reaches AutoMem.
|
|
40
|
+
- **Relationship tools** let the agent link memories or record corrections with provenance, building a connected graph over time.
|
|
41
|
+
|
|
42
|
+
Recall display, write policy, and per-project scoping are all configurable — see the [Configuration reference](#configuration-reference).
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
17
46
|
## Before you begin
|
|
18
47
|
|
|
19
48
|
This package does not include pi or AutoMem — it connects them. You need both running independently first:
|
|
@@ -22,24 +51,25 @@ This package does not include pi or AutoMem — it connects them. You need both
|
|
|
22
51
|
2. **[AutoMem](https://github.com/verygoodplugins/automem)** — the graph-vector memory service (self-hosted or Railway)
|
|
23
52
|
3. **[mcp-automem](https://github.com/verygoodplugins/mcp-automem)** — the MCP bridge that exposes AutoMem's tools over the MCP protocol
|
|
24
53
|
|
|
25
|
-
Once those three are in place,
|
|
54
|
+
Once those three are in place, follow the setup below.
|
|
26
55
|
|
|
27
56
|
---
|
|
28
57
|
|
|
29
|
-
##
|
|
58
|
+
## Setup
|
|
30
59
|
|
|
31
|
-
|
|
32
|
-
- **Turn-level recall** — before each agent prompt, retrieves memories relevant to the current task and detected project
|
|
33
|
-
- **Silent injection** — memory context is injected into the system prompt, not the chat window
|
|
34
|
-
- **Policy-gated writes** — every memory write is validated, secret-scanned, deduplicated, and confirmed before storage
|
|
35
|
-
- **Relationship tools** — link memories to each other or record corrections with provenance history
|
|
36
|
-
- **Per-project tuning** — configure different recall limits and filters per detected project
|
|
60
|
+
Three steps to a working install, then optional tuning. The package install is automatic — the **only** thing you must configure by hand is the connection to your own AutoMem server, because that carries your private server URL and token, and no package can (or should) write those for you.
|
|
37
61
|
|
|
38
|
-
|
|
62
|
+
### 1. Install the package
|
|
39
63
|
|
|
40
|
-
|
|
64
|
+
```bash
|
|
65
|
+
pi install npm:pi-automem-bridge
|
|
66
|
+
```
|
|
41
67
|
|
|
42
|
-
|
|
68
|
+
This registers the extension's tools, commands, and recall hooks with pi automatically. Nothing runs yet — it has no server to talk to.
|
|
69
|
+
|
|
70
|
+
### 2. Connect it to your AutoMem server — *required*
|
|
71
|
+
|
|
72
|
+
Add an MCP server entry named `automem` to `~/.pi/agent/mcp.json`, pointing at the AutoMem instance from [Before you begin](#before-you-begin):
|
|
43
73
|
|
|
44
74
|
```json
|
|
45
75
|
{
|
|
@@ -54,9 +84,17 @@ Once those three are in place, add `mcp-automem` to pi's MCP config and install
|
|
|
54
84
|
}
|
|
55
85
|
```
|
|
56
86
|
|
|
57
|
-
Use `${ENV_VAR}` interpolation for secrets.
|
|
87
|
+
This is the one step that can't be automated: the package has no way to know your server's address or auth token, and writing credentials on your behalf would be unsafe. Use `${ENV_VAR}` interpolation for the token — never hardcode secrets. The entry must be named `automem` (the name the extension looks for by default), or set a different name via `mcpServerName` in step 4.
|
|
88
|
+
|
|
89
|
+
**Don't want to hand-edit JSON?** pi is a coding agent — tell it to do it: *"add an `automem` MCP server to my `mcp.json` at `https://my-server.example.com/mcp`, using `${AUTOMEM_TOKEN}` for auth."* Keep the real token in your environment so it never touches the file or the chat.
|
|
90
|
+
|
|
91
|
+
### 3. Reload pi
|
|
92
|
+
|
|
93
|
+
Start a new session or run `/reload`. **That's it — recall is now automatic and the bridge runs on sensible defaults** (`safe-auto` writes, `summary` recall display). From here, just work: pi recalls on its own and saves routine decisions automatically — tell it *"remember this"* anytime you want something kept. Confirm everything's live with `/automem-status`.
|
|
58
94
|
|
|
59
|
-
|
|
95
|
+
### 4. Tune behavior — *optional*
|
|
96
|
+
|
|
97
|
+
The bridge works fully without this file. To customize recall queries, write policy, per-project scoping, or display mode, create `~/.pi/agent/automem.json` — any value you leave out falls back to its default. (Or just tell pi what you want — *"only auto-save bug fixes and technical decisions, and hide the recall block"* — and have it write the file for you.)
|
|
60
98
|
|
|
61
99
|
```json
|
|
62
100
|
{
|
|
@@ -74,7 +112,7 @@ Use `${ENV_VAR}` interpolation for secrets. Never hardcode credentials.
|
|
|
74
112
|
}
|
|
75
113
|
```
|
|
76
114
|
|
|
77
|
-
|
|
115
|
+
Every option — with real values you can copy — is in the [Configuration reference](#configuration-reference) below.
|
|
78
116
|
|
|
79
117
|
---
|
|
80
118
|
|
|
@@ -87,6 +125,8 @@ Use `${ENV_VAR}` interpolation for secrets. Never hardcode credentials.
|
|
|
87
125
|
|
|
88
126
|
## Tools
|
|
89
127
|
|
|
128
|
+
You don't type these — pi does, in plain conversation. Tell it *"remember that I prefer Vitest over Jest"* and it runs the thought through the write pipeline before storing; say *"actually, we moved off Railway"* and it records a correction with provenance. In `safe-auto` mode it also captures routine decisions on its own, no prompting needed.
|
|
129
|
+
|
|
90
130
|
| Tool | What it does |
|
|
91
131
|
|---|---|
|
|
92
132
|
| `automem_propose_memory` | Preview a memory candidate — validates, scans for secrets, checks for duplicates. Does not write. |
|
|
@@ -130,16 +170,6 @@ When a commit finds a close match, `automem_commit_memory` returns `DUPLICATE_DE
|
|
|
130
170
|
|
|
131
171
|
---
|
|
132
172
|
|
|
133
|
-
## Recall display modes
|
|
134
|
-
|
|
135
|
-
| Mode | Behavior |
|
|
136
|
-
|---|---|
|
|
137
|
-
| `hidden` | Inject into system prompt only. Nothing shown in chat. |
|
|
138
|
-
| `summary` | Inject into system prompt + show a compact notification. |
|
|
139
|
-
| `full` | Show the full recall block. Useful for debugging. |
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
173
|
## Configuration reference
|
|
144
174
|
|
|
145
175
|
Config file: `~/.pi/agent/automem.json` (or `AUTOMEM_CONFIG_PATH`)
|
|
@@ -147,14 +177,31 @@ Config file: `~/.pi/agent/automem.json` (or `AUTOMEM_CONFIG_PATH`)
|
|
|
147
177
|
| Section | Purpose |
|
|
148
178
|
|---|---|
|
|
149
179
|
| `mcpServerName` | Which server in `mcp.json` to use |
|
|
150
|
-
| `startupRecall` | Queries, tags, limits, byte budget for session-start recall |
|
|
151
|
-
| `turnRecall` | Per-prompt recall: limits, memory types, relation/entity expansion |
|
|
180
|
+
| `startupRecall` | Queries, tags, limits, byte budget, and timeout for session-start recall |
|
|
181
|
+
| `turnRecall` | Per-prompt recall: limits, memory types, relation/entity expansion, and timeout |
|
|
152
182
|
| `projectDetection` | Map git repos and folder names to project tags for scoped recall |
|
|
153
183
|
| `projectOverrides` | Per-project overrides for turn recall limits and filters |
|
|
154
184
|
| `writePolicy` | Write mode, categories, importance threshold, dedupe settings |
|
|
155
185
|
| `behavior` | Display mode and content-length preferences |
|
|
156
186
|
|
|
157
|
-
|
|
187
|
+
Set only the keys you want to change — everything else uses its default. Two ready-to-edit starting points ship with the package:
|
|
188
|
+
|
|
189
|
+
- **[`config.minimal.json`](https://github.com/vaniteav/pi-automem-bridge/blob/main/examples/config.minimal.json)** — the smallest useful config.
|
|
190
|
+
- **[`config.advanced.json`](https://github.com/vaniteav/pi-automem-bridge/blob/main/examples/config.advanced.json)** — every option above, filled in with real values and sensible defaults. Copy it, trim what you don't need.
|
|
191
|
+
|
|
192
|
+
### Recall display (`behavior.displayRecall`)
|
|
193
|
+
|
|
194
|
+
Controls how much of the recalled context shows in chat. Injection into the system prompt happens regardless.
|
|
195
|
+
|
|
196
|
+
| Mode | Behavior |
|
|
197
|
+
|---|---|
|
|
198
|
+
| `hidden` | Inject into system prompt only. Nothing shown in chat. |
|
|
199
|
+
| `summary` | Inject into system prompt + show a compact notification. |
|
|
200
|
+
| `full` | Show the full recall block. Useful for debugging. |
|
|
201
|
+
|
|
202
|
+
### Recall timeouts
|
|
203
|
+
|
|
204
|
+
Recall is best-effort context enrichment, so it runs on a short, bounded timeout instead of the full MCP request timeout — a slow or unreachable AutoMem server degrades gracefully to no injection rather than blocking your prompt. Tune with `turnRecall.timeoutMs` (default `8000`) and `startupRecall.timeoutMs` (default `15000`).
|
|
158
205
|
|
|
159
206
|
---
|
|
160
207
|
|
|
@@ -169,7 +216,6 @@ npm run test:smoke # live smoke test (requires AutoMem)
|
|
|
169
216
|
npm run test:live # full round-trip write test (requires AutoMem)
|
|
170
217
|
```
|
|
171
218
|
|
|
172
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for architecture notes, test descriptions, and release process.
|
|
173
219
|
|
|
174
220
|
---
|
|
175
221
|
|
|
@@ -1,59 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mcpServerName": "automem",
|
|
3
|
-
"startupRecall": {
|
|
4
|
-
"queries": [
|
|
5
|
-
"user preferences working style",
|
|
6
|
-
"agent operating guidelines",
|
|
7
|
-
"local development environment",
|
|
8
|
-
"active projects recent decisions"
|
|
9
|
-
],
|
|
10
|
-
"tags": ["source:pi"],
|
|
11
|
-
"tagMode": "any",
|
|
12
|
-
"limit": 6,
|
|
13
|
-
"maxBytes": 5000
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"mcpServerName": "automem",
|
|
3
|
+
"startupRecall": {
|
|
4
|
+
"queries": [
|
|
5
|
+
"user preferences working style",
|
|
6
|
+
"agent operating guidelines",
|
|
7
|
+
"local development environment",
|
|
8
|
+
"active projects recent decisions"
|
|
9
|
+
],
|
|
10
|
+
"tags": ["source:pi"],
|
|
11
|
+
"tagMode": "any",
|
|
12
|
+
"limit": 6,
|
|
13
|
+
"maxBytes": 5000,
|
|
14
|
+
"timeoutMs": 15000
|
|
15
|
+
},
|
|
16
|
+
"turnRecall": {
|
|
17
|
+
"enabled": true,
|
|
18
|
+
"limit": 5,
|
|
19
|
+
"maxBytes": 3000,
|
|
20
|
+
"contextTypes": ["Preference", "Decision", "Pattern", "Insight", "Context"],
|
|
21
|
+
"expandRelations": true,
|
|
22
|
+
"expandEntities": true,
|
|
23
|
+
"timeoutMs": 8000
|
|
24
|
+
},
|
|
25
|
+
"projectDetection": {
|
|
26
|
+
"tagPrefix": "project:",
|
|
27
|
+
"folderTags": {
|
|
28
|
+
"projects": ["project"],
|
|
29
|
+
"areas": ["area"],
|
|
30
|
+
"resources": ["resource"]
|
|
31
|
+
},
|
|
32
|
+
"gitRepoToTag": {
|
|
33
|
+
"my-project": "project:my-project"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"writePolicy": {
|
|
37
|
+
"mode": "safe-auto",
|
|
38
|
+
"autoWriteCategories": ["technical-decision", "agent-pattern", "bug-fix", "tooling-lesson"],
|
|
39
|
+
"confirmCategories": ["personal", "financial", "private", "identity"],
|
|
40
|
+
"blockedCategories": ["secret", "credential", "api-key", "raw-transcript"],
|
|
41
|
+
"alwaysTag": ["source:pi"],
|
|
42
|
+
"minImportanceToWrite": 0.7,
|
|
43
|
+
"dedupeBeforeWrite": true,
|
|
44
|
+
"dedupeLimit": 3
|
|
45
|
+
},
|
|
46
|
+
"behavior": {
|
|
47
|
+
"displayRecall": "hidden",
|
|
48
|
+
"maxContentLength": 2000,
|
|
49
|
+
"preferredContentLength": 500
|
|
50
|
+
},
|
|
51
|
+
"projectOverrides": {
|
|
52
|
+
"project:my-large-project": {
|
|
53
|
+
"limit": 10,
|
|
54
|
+
"maxBytes": 6000
|
|
55
|
+
},
|
|
56
|
+
"project:quick-scripts": {
|
|
57
|
+
"limit": 2,
|
|
58
|
+
"maxBytes": 1000
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,58 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pi-automem-bridge",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Automatic long-term memory recall and policy-gated writes for pi agents via AutoMem MCP",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"pi-package",
|
|
7
|
-
"pi-extension",
|
|
8
|
-
"automem",
|
|
9
|
-
"mcp",
|
|
10
|
-
"memory",
|
|
11
|
-
"long-term-memory",
|
|
12
|
-
"semantic-memory",
|
|
13
|
-
"memory-write-policy",
|
|
14
|
-
"agent-memory"
|
|
15
|
-
],
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"author": "vaniteav",
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "https://github.com/vaniteav/pi-automem-bridge.git"
|
|
21
|
-
},
|
|
22
|
-
"peerDependencies": {
|
|
23
|
-
"@earendil-works/pi-coding-agent": ">=0.78.0",
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"test
|
|
29
|
-
"test:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
},
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"./
|
|
41
|
-
],
|
|
42
|
-
"
|
|
43
|
-
"./
|
|
44
|
-
]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-automem-bridge",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Automatic long-term memory recall and policy-gated writes for pi agents via AutoMem MCP",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-extension",
|
|
8
|
+
"automem",
|
|
9
|
+
"mcp",
|
|
10
|
+
"memory",
|
|
11
|
+
"long-term-memory",
|
|
12
|
+
"semantic-memory",
|
|
13
|
+
"memory-write-policy",
|
|
14
|
+
"agent-memory"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "vaniteav",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/vaniteav/pi-automem-bridge.git"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@earendil-works/pi-coding-agent": ">=0.78.0",
|
|
24
|
+
"@verygoodplugins/mcp-automem": "*",
|
|
25
|
+
"typebox": "*"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "tsx tests/unit.ts && tsx tests/phase2-policy.ts && tsx tests/review-fixes.ts",
|
|
29
|
+
"test:smoke": "tsx tests/phase1-smoke.ts",
|
|
30
|
+
"test:live": "tsx tests/phase2-live-write.ts",
|
|
31
|
+
"preflight": "node scripts/preflight.mjs",
|
|
32
|
+
"prepublishOnly": "node scripts/preflight.mjs"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsx": "^4.20.6"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {},
|
|
38
|
+
"pi": {
|
|
39
|
+
"extensions": [
|
|
40
|
+
"./src/index.ts"
|
|
41
|
+
],
|
|
42
|
+
"skills": [
|
|
43
|
+
"./skills"
|
|
44
|
+
],
|
|
45
|
+
"prompts": [
|
|
46
|
+
"./prompts"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/vaniteav/pi-automem-bridge/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/vaniteav/pi-automem-bridge#readme",
|
|
53
|
+
"files": [
|
|
54
|
+
"src",
|
|
55
|
+
"skills",
|
|
56
|
+
"prompts",
|
|
57
|
+
"examples",
|
|
58
|
+
"README.md",
|
|
59
|
+
"LICENSE"
|
|
60
|
+
]
|
|
61
|
+
}
|