@remnic/plugin-pi 1.0.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/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/chunk-VGPUF4JQ.js +26 -0
- package/dist/chunk-VGPUF4JQ.js.map +1 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +849 -0
- package/dist/index.js.map +1 -0
- package/dist/publisher.d.ts +13 -0
- package/dist/publisher.js +235 -0
- package/dist/publisher.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Joshua Warren
|
|
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,168 @@
|
|
|
1
|
+
# @remnic/plugin-pi
|
|
2
|
+
|
|
3
|
+
Remnic memory and context for [Pi Coding Agent](https://pi.dev).
|
|
4
|
+
|
|
5
|
+
This package is the first-class Remnic extension for Pi. It uses Pi's extension hooks directly, so Remnic can recall context before a model call, observe useful session events after the turn, expose Remnic MCP tools inside Pi, and coordinate Pi compaction with Remnic's long-context memory archive.
|
|
6
|
+
|
|
7
|
+
## What It Does
|
|
8
|
+
|
|
9
|
+
- Recalls relevant Remnic context in Pi's `context` hook before an agent turn.
|
|
10
|
+
- Observes Pi user, assistant, and tool messages with `sourceFormat: "pi"`.
|
|
11
|
+
- Flushes Remnic long-context memory before Pi compacts a session.
|
|
12
|
+
- Records Pi compaction checkpoints and token deltas back to Remnic.
|
|
13
|
+
- Registers Remnic MCP tools as Pi tools when daemon authentication is configured.
|
|
14
|
+
- Persists lightweight dedupe state with Pi custom entries so repeated turns are not re-observed.
|
|
15
|
+
|
|
16
|
+
## Recommended Install
|
|
17
|
+
|
|
18
|
+
Install through the Remnic CLI. This writes the Pi auto-discovery wrapper, private connector config, and local operator notes into Pi's extension directory.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g @remnic/cli
|
|
22
|
+
remnic daemon start
|
|
23
|
+
remnic connectors install pi
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The connector installer writes:
|
|
27
|
+
|
|
28
|
+
- `~/.pi/agent/extensions/remnic/index.ts`
|
|
29
|
+
- `~/.pi/agent/extensions/remnic/remnic.config.json`
|
|
30
|
+
- `~/.pi/agent/extensions/remnic/README.md`
|
|
31
|
+
|
|
32
|
+
The generated `remnic.config.json` contains the Remnic daemon URL, namespace, and connector auth token. Remnic writes it with owner-only permissions where the platform supports file modes.
|
|
33
|
+
|
|
34
|
+
To install the token and connector config without writing the Pi extension files:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
remnic connectors install pi --config installExtension=false
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Direct Pi Load
|
|
41
|
+
|
|
42
|
+
You can also load the npm package directly from Pi after configuring the daemon URL and auth token:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pi -e npm:@remnic/plugin-pi
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For direct loading, provide either `REMNIC_PI_CONFIG` or the default config file at `~/.pi/agent/extensions/remnic/remnic.config.json`.
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
The extension loads configuration in this order:
|
|
53
|
+
|
|
54
|
+
1. `REMNIC_PI_CONFIG`
|
|
55
|
+
2. `~/.pi/agent/extensions/remnic/remnic.config.json`
|
|
56
|
+
|
|
57
|
+
Supported environment variables:
|
|
58
|
+
|
|
59
|
+
| Variable | Description |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `REMNIC_PI_CONFIG` | Path to the Remnic Pi JSON config file |
|
|
62
|
+
| `REMNIC_DAEMON_URL` | Remnic daemon URL when the config file does not set `remnicDaemonUrl` |
|
|
63
|
+
| `REMNIC_PI_AUTH_TOKEN` | Connector token when the config file does not set `authToken` |
|
|
64
|
+
| `PI_CODING_AGENT_DIR` | Pi agent home override used to resolve the extension directory |
|
|
65
|
+
| `PI_AGENT_HOME` | Alternate Pi agent home override |
|
|
66
|
+
| `PI_HOME` | Alternate Pi agent home override |
|
|
67
|
+
|
|
68
|
+
Supported config keys:
|
|
69
|
+
|
|
70
|
+
| Key | Default | Description |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `remnicDaemonUrl` | `http://127.0.0.1:4318` | Remnic HTTP/MCP daemon URL |
|
|
73
|
+
| `authToken` | unset | Connector token generated by `remnic connectors install pi` |
|
|
74
|
+
| `namespace` | unset | Remnic namespace for recall, observe, store, and LCM requests |
|
|
75
|
+
| `recallMode` | `auto` | Recall mode: `auto`, `minimal`, `full`, `graph_mode`, or `no_recall` |
|
|
76
|
+
| `recallTopK` | `8` | Maximum recalled results |
|
|
77
|
+
| `recallBudgetChars` | `12000` | Maximum recalled context injected into Pi |
|
|
78
|
+
| `recallEnabled` | `true` | Enable context-hook recall |
|
|
79
|
+
| `observeEnabled` | `true` | Enable Pi turn observation |
|
|
80
|
+
| `observeSkipExtraction` | `false` | Archive observed messages without extraction |
|
|
81
|
+
| `compactionEnabled` | `true` | Enable LCM flush and checkpoint coordination |
|
|
82
|
+
| `mcpToolsEnabled` | `true` | Register Remnic MCP tools as Pi tools |
|
|
83
|
+
| `statusEnabled` | `true` | Set Pi UI status from daemon health |
|
|
84
|
+
| `requestTimeoutMs` | `5000` | HTTP/MCP request timeout |
|
|
85
|
+
|
|
86
|
+
Boolean-like strings such as `"false"`, `"0"`, `"no"`, and `"off"` are treated as false.
|
|
87
|
+
|
|
88
|
+
Example:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"remnicDaemonUrl": "http://127.0.0.1:4318",
|
|
93
|
+
"namespace": "work",
|
|
94
|
+
"recallMode": "auto",
|
|
95
|
+
"recallTopK": 8,
|
|
96
|
+
"recallBudgetChars": 12000,
|
|
97
|
+
"recallEnabled": true,
|
|
98
|
+
"observeEnabled": true,
|
|
99
|
+
"compactionEnabled": true,
|
|
100
|
+
"mcpToolsEnabled": true,
|
|
101
|
+
"statusEnabled": true,
|
|
102
|
+
"requestTimeoutMs": 5000
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Pi Commands
|
|
107
|
+
|
|
108
|
+
The extension registers these Pi slash commands:
|
|
109
|
+
|
|
110
|
+
| Command | Description |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `/remnic-status` | Check Remnic daemon health |
|
|
113
|
+
| `/remnic-recall <query>` | Recall Remnic context for a query |
|
|
114
|
+
| `/remnic-remember <memory>` | Explicitly store a memory |
|
|
115
|
+
| `/remnic-lcm-search <query>` | Search archived Pi context |
|
|
116
|
+
| `/remnic-why` | Inspect the last recall explanation |
|
|
117
|
+
| `/remnic-compact` | Request Pi compaction with Remnic LCM coordination |
|
|
118
|
+
|
|
119
|
+
## Security And Boundaries
|
|
120
|
+
|
|
121
|
+
- Remnic routes Pi traffic with the active Pi session key, working directory, and configured namespace.
|
|
122
|
+
- MCP tool calls strip caller-provided `sessionKey`, `namespace`, and `cwd` before the extension injects trusted values from the Pi runtime.
|
|
123
|
+
- The connector config stores the daemon token locally and is written with `0600` permissions by the Remnic installer.
|
|
124
|
+
- Invalid config values fail closed instead of silently falling back to unsafe defaults.
|
|
125
|
+
- The default daemon URL is local: `http://127.0.0.1:4318`.
|
|
126
|
+
|
|
127
|
+
## Troubleshooting
|
|
128
|
+
|
|
129
|
+
If Pi cannot reach Remnic, start the daemon and check the configured URL:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
remnic daemon start
|
|
133
|
+
remnic status
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
If commands return `401` or MCP tools do not appear, reinstall the connector so the Pi config receives a fresh token:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
remnic token generate pi
|
|
140
|
+
remnic connectors install pi --force
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
If Pi uses a non-default home directory, set one of the supported Pi home variables before installing:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
PI_CODING_AGENT_DIR=/path/to/pi/agent remnic connectors install pi
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Development
|
|
150
|
+
|
|
151
|
+
From the Remnic monorepo:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
pnpm install
|
|
155
|
+
pnpm --filter @remnic/plugin-pi test
|
|
156
|
+
pnpm --filter @remnic/plugin-pi build
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
The package exports:
|
|
160
|
+
|
|
161
|
+
- `@remnic/plugin-pi` - Pi extension entrypoint and `createRemnicPiExtension`
|
|
162
|
+
- `@remnic/plugin-pi/publisher` - Remnic connector publisher used by `remnic connectors install pi`
|
|
163
|
+
|
|
164
|
+
## More
|
|
165
|
+
|
|
166
|
+
- Full integration guide: https://github.com/joshuaswarren/remnic/blob/main/docs/integration/pi.md
|
|
167
|
+
- Remnic: https://github.com/joshuaswarren/remnic
|
|
168
|
+
- Pi Coding Agent: https://pi.dev
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// openclaw-engram: Local-first memory plugin
|
|
2
|
+
|
|
3
|
+
// src/paths.ts
|
|
4
|
+
import os from "os";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { expandTildePath } from "@remnic/core";
|
|
7
|
+
var REMNIC_PI_EXTENSION_DIR_NAME = "remnic";
|
|
8
|
+
function resolvePiAgentHome(env) {
|
|
9
|
+
const explicitCodingAgentDir = env.PI_CODING_AGENT_DIR?.trim();
|
|
10
|
+
if (explicitCodingAgentDir) return path.resolve(expandTildePath(explicitCodingAgentDir));
|
|
11
|
+
const explicitAgentHome = env.PI_AGENT_HOME?.trim();
|
|
12
|
+
if (explicitAgentHome) return path.resolve(expandTildePath(explicitAgentHome));
|
|
13
|
+
const explicitPiHome = env.PI_HOME?.trim();
|
|
14
|
+
if (explicitPiHome) return path.join(path.resolve(expandTildePath(explicitPiHome)), "agent");
|
|
15
|
+
return path.join(env.HOME ?? env.USERPROFILE ?? os.homedir(), ".pi", "agent");
|
|
16
|
+
}
|
|
17
|
+
function resolvePiExtensionRoot(env) {
|
|
18
|
+
return path.join(resolvePiAgentHome(env), "extensions", REMNIC_PI_EXTENSION_DIR_NAME);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
REMNIC_PI_EXTENSION_DIR_NAME,
|
|
23
|
+
resolvePiAgentHome,
|
|
24
|
+
resolvePiExtensionRoot
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-VGPUF4JQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/paths.ts"],"sourcesContent":["import os from \"node:os\";\nimport path from \"node:path\";\n\nimport { expandTildePath } from \"@remnic/core\";\n\nexport const REMNIC_PI_EXTENSION_DIR_NAME = \"remnic\";\n\nexport function resolvePiAgentHome(env: NodeJS.ProcessEnv): string {\n const explicitCodingAgentDir = env.PI_CODING_AGENT_DIR?.trim();\n if (explicitCodingAgentDir) return path.resolve(expandTildePath(explicitCodingAgentDir));\n\n const explicitAgentHome = env.PI_AGENT_HOME?.trim();\n if (explicitAgentHome) return path.resolve(expandTildePath(explicitAgentHome));\n\n const explicitPiHome = env.PI_HOME?.trim();\n if (explicitPiHome) return path.join(path.resolve(expandTildePath(explicitPiHome)), \"agent\");\n\n return path.join(env.HOME ?? env.USERPROFILE ?? os.homedir(), \".pi\", \"agent\");\n}\n\nexport function resolvePiExtensionRoot(env: NodeJS.ProcessEnv): string {\n return path.join(resolvePiAgentHome(env), \"extensions\", REMNIC_PI_EXTENSION_DIR_NAME);\n}\n"],"mappings":";;;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,SAAS,uBAAuB;AAEzB,IAAM,+BAA+B;AAErC,SAAS,mBAAmB,KAAgC;AACjE,QAAM,yBAAyB,IAAI,qBAAqB,KAAK;AAC7D,MAAI,uBAAwB,QAAO,KAAK,QAAQ,gBAAgB,sBAAsB,CAAC;AAEvF,QAAM,oBAAoB,IAAI,eAAe,KAAK;AAClD,MAAI,kBAAmB,QAAO,KAAK,QAAQ,gBAAgB,iBAAiB,CAAC;AAE7E,QAAM,iBAAiB,IAAI,SAAS,KAAK;AACzC,MAAI,eAAgB,QAAO,KAAK,KAAK,KAAK,QAAQ,gBAAgB,cAAc,CAAC,GAAG,OAAO;AAE3F,SAAO,KAAK,KAAK,IAAI,QAAQ,IAAI,eAAe,GAAG,QAAQ,GAAG,OAAO,OAAO;AAC9E;AAEO,SAAS,uBAAuB,KAAgC;AACrE,SAAO,KAAK,KAAK,mBAAmB,GAAG,GAAG,cAAc,4BAA4B;AACtF;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { TSchema } from '@sinclair/typebox';
|
|
2
|
+
|
|
3
|
+
interface RemnicPiConfig {
|
|
4
|
+
remnicDaemonUrl: string;
|
|
5
|
+
authToken?: string;
|
|
6
|
+
namespace?: string;
|
|
7
|
+
recallMode: "auto" | "minimal" | "full" | "graph_mode" | "no_recall";
|
|
8
|
+
recallTopK: number;
|
|
9
|
+
recallBudgetChars: number;
|
|
10
|
+
recallEnabled: boolean;
|
|
11
|
+
observeEnabled: boolean;
|
|
12
|
+
observeSkipExtraction: boolean;
|
|
13
|
+
compactionEnabled: boolean;
|
|
14
|
+
mcpToolsEnabled: boolean;
|
|
15
|
+
statusEnabled: boolean;
|
|
16
|
+
requestTimeoutMs: number;
|
|
17
|
+
}
|
|
18
|
+
interface LoadConfigOptions {
|
|
19
|
+
configPath?: string;
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface RecallResponse {
|
|
24
|
+
context?: string;
|
|
25
|
+
results?: Array<{
|
|
26
|
+
id?: string;
|
|
27
|
+
content?: string;
|
|
28
|
+
score?: number;
|
|
29
|
+
category?: string;
|
|
30
|
+
}>;
|
|
31
|
+
count?: number;
|
|
32
|
+
}
|
|
33
|
+
interface ObserveMessagePart {
|
|
34
|
+
ordinal?: number;
|
|
35
|
+
kind: "text" | "tool_call" | "tool_result" | "patch" | "file_read" | "file_write" | "step_start" | "step_finish" | "snapshot" | "retry";
|
|
36
|
+
payload: Record<string, unknown>;
|
|
37
|
+
toolName?: string | null;
|
|
38
|
+
filePath?: string | null;
|
|
39
|
+
createdAt?: string | null;
|
|
40
|
+
}
|
|
41
|
+
interface ObserveMessage {
|
|
42
|
+
role: "user" | "assistant";
|
|
43
|
+
content: string;
|
|
44
|
+
sourceFormat?: "pi";
|
|
45
|
+
rawContent?: unknown;
|
|
46
|
+
parts?: ObserveMessagePart[];
|
|
47
|
+
}
|
|
48
|
+
interface McpTool {
|
|
49
|
+
name: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
inputSchema?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
declare class RemnicClient {
|
|
54
|
+
private readonly config;
|
|
55
|
+
private requestId;
|
|
56
|
+
constructor(config: RemnicPiConfig);
|
|
57
|
+
health(): Promise<Record<string, unknown>>;
|
|
58
|
+
recall(query: string, sessionKey: string, cwd: string): Promise<RecallResponse>;
|
|
59
|
+
recallExplain(sessionKey: string): Promise<Record<string, unknown>>;
|
|
60
|
+
observe(sessionKey: string, cwd: string, messages: ObserveMessage[]): Promise<Record<string, unknown>>;
|
|
61
|
+
storeMemory(content: string, sessionKey: string): Promise<Record<string, unknown>>;
|
|
62
|
+
lcmSearch(query: string, sessionKey: string, limit?: number): Promise<Record<string, unknown>>;
|
|
63
|
+
lcmCompactionFlush(sessionKey: string): Promise<Record<string, unknown>>;
|
|
64
|
+
lcmCompactionRecord(sessionKey: string, tokensBefore: number, tokensAfter: number): Promise<Record<string, unknown>>;
|
|
65
|
+
contextCheckpoint(sessionKey: string, context: string): Promise<Record<string, unknown>>;
|
|
66
|
+
mcpListTools(): Promise<McpTool[]>;
|
|
67
|
+
mcpTool(name: string, args: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
68
|
+
private request;
|
|
69
|
+
private mcpRequest;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare function textFromMessage(message: unknown): string;
|
|
73
|
+
|
|
74
|
+
type PiApi = {
|
|
75
|
+
on(event: string, handler: (event: any, ctx: any) => unknown | Promise<unknown>): void;
|
|
76
|
+
registerCommand(name: string, options: {
|
|
77
|
+
description?: string;
|
|
78
|
+
handler: (args: string, ctx: any) => Promise<void>;
|
|
79
|
+
}): void;
|
|
80
|
+
registerTool(tool: Record<string, unknown>): void;
|
|
81
|
+
appendEntry<T = unknown>(customType: string, data?: T): void;
|
|
82
|
+
};
|
|
83
|
+
interface RemnicPiExtensionOptions extends LoadConfigOptions {
|
|
84
|
+
config?: RemnicPiConfig;
|
|
85
|
+
}
|
|
86
|
+
declare function createRemnicPiExtension(options?: RemnicPiExtensionOptions): (pi: PiApi) => Promise<void>;
|
|
87
|
+
declare function remnicPiExtension(pi: PiApi): Promise<void>;
|
|
88
|
+
declare function toPiToolParametersSchema(inputSchema: unknown): TSchema;
|
|
89
|
+
declare function stripSessionOwnedSchemaFields(inputSchema: unknown): Record<string, unknown>;
|
|
90
|
+
declare function observeMessages(ctx: any, client: RemnicClient, rawMessages: unknown[], observedHashes: Set<string>, liveObservedReplayKeys?: Map<string, number>): Promise<void>;
|
|
91
|
+
declare function buildCompactionSummary(preparation: any): string;
|
|
92
|
+
|
|
93
|
+
export { type RemnicPiExtensionOptions, buildCompactionSummary, createRemnicPiExtension, remnicPiExtension as default, observeMessages, stripSessionOwnedSchemaFields, textFromMessage, toPiToolParametersSchema };
|