opencode-supermemory 0.1.1 → 0.1.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 +94 -27
- package/dist/cli.js +91 -108
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,45 +2,123 @@
|
|
|
2
2
|
|
|
3
3
|
OpenCode plugin for persistent memory using [Supermemory](https://supermemory.ai).
|
|
4
4
|
|
|
5
|
+
Your agent remembers what you tell it - across sessions, across projects.
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
9
|
+
### For Humans
|
|
10
|
+
|
|
7
11
|
```bash
|
|
8
|
-
|
|
12
|
+
bunx opencode-supermemory install
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then get your API key from [console.supermemory.ai](https://console.supermemory.ai) and set it:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
export SUPERMEMORY_API_KEY="sm_..."
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Or let your agent do it** - paste this into OpenCode:
|
|
22
|
+
```
|
|
23
|
+
Install opencode-supermemory by following https://raw.githubusercontent.com/supermemoryai/opencode-supermemory/main/README.md
|
|
9
24
|
```
|
|
10
25
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
### For LLM Agents
|
|
27
|
+
|
|
28
|
+
<details>
|
|
29
|
+
<summary>Instructions for LLM Agents (click to expand)</summary>
|
|
30
|
+
|
|
31
|
+
If you're an LLM agent helping set up opencode-supermemory, follow these steps:
|
|
15
32
|
|
|
16
|
-
|
|
33
|
+
#### Step 1: Run the installer
|
|
17
34
|
|
|
18
35
|
```bash
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
bunx opencode-supermemory install --no-tui
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
This will:
|
|
40
|
+
- Register the plugin in `~/.config/opencode/opencode.jsonc`
|
|
41
|
+
- Create the `/supermemory-init` command
|
|
42
|
+
|
|
43
|
+
#### Step 2: Verify the config
|
|
22
44
|
|
|
23
|
-
|
|
24
|
-
|
|
45
|
+
```bash
|
|
46
|
+
cat ~/.config/opencode/opencode.jsonc
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Should contain:
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"plugin": ["opencode-supermemory"]
|
|
53
|
+
}
|
|
25
54
|
```
|
|
26
55
|
|
|
27
|
-
|
|
56
|
+
If not, add it manually:
|
|
28
57
|
|
|
58
|
+
**JSONC:**
|
|
59
|
+
```jsonc
|
|
60
|
+
{
|
|
61
|
+
"plugin": [
|
|
62
|
+
"opencode-supermemory"
|
|
63
|
+
// ... other plugins
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**JSON:**
|
|
29
69
|
```json
|
|
30
70
|
{
|
|
31
71
|
"plugin": ["opencode-supermemory"]
|
|
32
72
|
}
|
|
33
73
|
```
|
|
34
74
|
|
|
75
|
+
#### Step 3: Configure API key
|
|
76
|
+
|
|
77
|
+
Ask the user to get their API key from [console.supermemory.ai](https://console.supermemory.ai).
|
|
78
|
+
|
|
79
|
+
Then set it via environment variable:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
export SUPERMEMORY_API_KEY="sm_..."
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Or create `~/.config/opencode/supermemory.jsonc`:
|
|
86
|
+
|
|
87
|
+
```jsonc
|
|
88
|
+
{
|
|
89
|
+
"apiKey": "sm_..."
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Step 4: Verify setup
|
|
94
|
+
|
|
95
|
+
Tell the user to restart OpenCode and run:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
opencode -c
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
They should see `supermemory` in the tools list. If not, check:
|
|
102
|
+
1. Is `SUPERMEMORY_API_KEY` set?
|
|
103
|
+
2. Is the plugin in `opencode.jsonc`?
|
|
104
|
+
3. Check logs: `tail ~/.opencode-supermemory.log`
|
|
105
|
+
|
|
106
|
+
#### Step 5: Initialize codebase memory (optional)
|
|
107
|
+
|
|
108
|
+
Run `/supermemory-init` to have the agent explore and memorize the codebase.
|
|
109
|
+
|
|
110
|
+
</details>
|
|
111
|
+
|
|
35
112
|
## Features
|
|
36
113
|
|
|
37
114
|
### Context Injection
|
|
38
115
|
|
|
39
|
-
On first message,
|
|
116
|
+
On first message, the agent receives (invisible to user):
|
|
40
117
|
- User profile (cross-project preferences)
|
|
41
118
|
- Project memories (all project knowledge)
|
|
42
119
|
- Relevant user memories (semantic search)
|
|
43
120
|
|
|
121
|
+
Example of what the agent sees:
|
|
44
122
|
```
|
|
45
123
|
[SUPERMEMORY]
|
|
46
124
|
|
|
@@ -56,6 +134,8 @@ Relevant Memories:
|
|
|
56
134
|
- [82%] Build fails if .env.local missing
|
|
57
135
|
```
|
|
58
136
|
|
|
137
|
+
The agent uses this context automatically - no manual prompting needed.
|
|
138
|
+
|
|
59
139
|
### Keyword Detection
|
|
60
140
|
|
|
61
141
|
Say "remember", "save this", "don't forget" etc. and the agent auto-saves to memory.
|
|
@@ -134,17 +214,12 @@ Create `~/.config/opencode/supermemory.jsonc`:
|
|
|
134
214
|
"injectProfile": true,
|
|
135
215
|
|
|
136
216
|
// Prefix for container tags
|
|
137
|
-
"containerTagPrefix": "opencode"
|
|
138
|
-
|
|
139
|
-
// LLM filter prompt for memory relevance
|
|
140
|
-
"filterPrompt": "You are a stateful coding agent. Remember all the information, including but not limited to user's coding preferences, tech stack, behaviours, workflows, and any other relevant details."
|
|
217
|
+
"containerTagPrefix": "opencode"
|
|
141
218
|
}
|
|
142
219
|
```
|
|
143
220
|
|
|
144
221
|
All fields optional. Env var `SUPERMEMORY_API_KEY` takes precedence over config file.
|
|
145
222
|
|
|
146
|
-
API timeout: 30s
|
|
147
|
-
|
|
148
223
|
## Usage with Oh My OpenCode
|
|
149
224
|
|
|
150
225
|
If you're using [Oh My OpenCode](https://github.com/code-yeongyu/oh-my-opencode), disable its built-in auto-compact hook to let supermemory handle context compaction:
|
|
@@ -157,14 +232,6 @@ Add to `~/.config/opencode/oh-my-opencode.json`:
|
|
|
157
232
|
}
|
|
158
233
|
```
|
|
159
234
|
|
|
160
|
-
This ensures supermemory's preemptive compaction (which preserves memories across sessions) works correctly instead of oh-my-opencode's default compaction.
|
|
161
|
-
|
|
162
|
-
## Hooks
|
|
163
|
-
|
|
164
|
-
Registered in `package.json`:
|
|
165
|
-
- `chat.message` - Context injection on first message, keyword detection
|
|
166
|
-
- `event` - Compaction monitoring and summary capture
|
|
167
|
-
|
|
168
235
|
## Development
|
|
169
236
|
|
|
170
237
|
```bash
|
package/dist/cli.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
-
for (let key of __getOwnPropNames(mod))
|
|
12
|
-
if (!__hasOwnProp.call(to, key))
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: () => mod[key],
|
|
15
|
-
enumerable: true
|
|
16
|
-
});
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
2
|
|
|
21
3
|
// src/cli.ts
|
|
22
4
|
import { mkdirSync, writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
@@ -25,7 +7,7 @@ import { homedir } from "node:os";
|
|
|
25
7
|
import * as readline from "node:readline";
|
|
26
8
|
var OPENCODE_CONFIG_DIR = join(homedir(), ".config", "opencode");
|
|
27
9
|
var OPENCODE_COMMAND_DIR = join(OPENCODE_CONFIG_DIR, "command");
|
|
28
|
-
var PLUGIN_NAME = "opencode-supermemory
|
|
10
|
+
var PLUGIN_NAME = "opencode-supermemory";
|
|
29
11
|
var SUPERMEMORY_INIT_COMMAND = `---
|
|
30
12
|
description: Initialize Supermemory with comprehensive codebase knowledge
|
|
31
13
|
---
|
|
@@ -190,42 +172,10 @@ async function confirm(rl, question) {
|
|
|
190
172
|
});
|
|
191
173
|
});
|
|
192
174
|
}
|
|
193
|
-
async function installPlugin() {
|
|
194
|
-
const { execSync } = await import("node:child_process");
|
|
195
|
-
let pm = "npm";
|
|
196
|
-
try {
|
|
197
|
-
execSync("bun --version", { stdio: "ignore" });
|
|
198
|
-
pm = "bun";
|
|
199
|
-
} catch {
|
|
200
|
-
try {
|
|
201
|
-
execSync("pnpm --version", { stdio: "ignore" });
|
|
202
|
-
pm = "pnpm";
|
|
203
|
-
} catch {}
|
|
204
|
-
}
|
|
205
|
-
console.log(`Installing ${PLUGIN_NAME} with ${pm}...`);
|
|
206
|
-
try {
|
|
207
|
-
execSync(`${pm} install -g ${PLUGIN_NAME}`, { stdio: "inherit" });
|
|
208
|
-
return true;
|
|
209
|
-
} catch {
|
|
210
|
-
console.error("Failed to install plugin globally.");
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function createCommand() {
|
|
215
|
-
mkdirSync(OPENCODE_COMMAND_DIR, { recursive: true });
|
|
216
|
-
const commandPath = join(OPENCODE_COMMAND_DIR, "supermemory-init.md");
|
|
217
|
-
if (existsSync(commandPath)) {
|
|
218
|
-
console.log(`Command already exists at ${commandPath}`);
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
writeFileSync(commandPath, SUPERMEMORY_INIT_COMMAND);
|
|
222
|
-
console.log(`Created /supermemory-init command`);
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
175
|
function findOpencodeConfig() {
|
|
226
176
|
const candidates = [
|
|
227
|
-
join(OPENCODE_CONFIG_DIR, "
|
|
228
|
-
join(OPENCODE_CONFIG_DIR, "
|
|
177
|
+
join(OPENCODE_CONFIG_DIR, "opencode.jsonc"),
|
|
178
|
+
join(OPENCODE_CONFIG_DIR, "opencode.json")
|
|
229
179
|
];
|
|
230
180
|
for (const path of candidates) {
|
|
231
181
|
if (existsSync(path)) {
|
|
@@ -238,7 +188,7 @@ function addPluginToConfig(configPath) {
|
|
|
238
188
|
try {
|
|
239
189
|
const content = readFileSync(configPath, "utf-8");
|
|
240
190
|
if (content.includes("opencode-supermemory")) {
|
|
241
|
-
console.log("Plugin already in config");
|
|
191
|
+
console.log("✓ Plugin already registered in config");
|
|
242
192
|
return true;
|
|
243
193
|
}
|
|
244
194
|
const jsonContent = content.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
@@ -246,7 +196,7 @@ function addPluginToConfig(configPath) {
|
|
|
246
196
|
try {
|
|
247
197
|
config = JSON.parse(jsonContent);
|
|
248
198
|
} catch {
|
|
249
|
-
console.error("Failed to parse config file");
|
|
199
|
+
console.error("✗ Failed to parse config file");
|
|
250
200
|
return false;
|
|
251
201
|
}
|
|
252
202
|
const plugins = config.plugin || [];
|
|
@@ -274,91 +224,124 @@ function addPluginToConfig(configPath) {
|
|
|
274
224
|
} else {
|
|
275
225
|
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
276
226
|
}
|
|
277
|
-
console.log(
|
|
227
|
+
console.log(`✓ Added plugin to ${configPath}`);
|
|
278
228
|
return true;
|
|
279
229
|
} catch (err) {
|
|
280
|
-
console.error("Failed to update config:", err);
|
|
230
|
+
console.error("✗ Failed to update config:", err);
|
|
281
231
|
return false;
|
|
282
232
|
}
|
|
283
233
|
}
|
|
284
234
|
function createNewConfig() {
|
|
285
|
-
const configPath = join(OPENCODE_CONFIG_DIR, "
|
|
235
|
+
const configPath = join(OPENCODE_CONFIG_DIR, "opencode.jsonc");
|
|
286
236
|
mkdirSync(OPENCODE_CONFIG_DIR, { recursive: true });
|
|
287
|
-
const config = {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
237
|
+
const config = `{
|
|
238
|
+
"plugin": ["${PLUGIN_NAME}"]
|
|
239
|
+
}
|
|
240
|
+
`;
|
|
241
|
+
writeFileSync(configPath, config);
|
|
242
|
+
console.log(`✓ Created ${configPath}`);
|
|
292
243
|
return true;
|
|
293
244
|
}
|
|
294
|
-
|
|
295
|
-
|
|
245
|
+
function createCommand() {
|
|
246
|
+
mkdirSync(OPENCODE_COMMAND_DIR, { recursive: true });
|
|
247
|
+
const commandPath = join(OPENCODE_COMMAND_DIR, "supermemory-init.md");
|
|
248
|
+
writeFileSync(commandPath, SUPERMEMORY_INIT_COMMAND);
|
|
249
|
+
console.log(`✓ Created /supermemory-init command`);
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
async function install(options) {
|
|
296
253
|
console.log(`
|
|
297
|
-
opencode-supermemory
|
|
254
|
+
\uD83E\uDDE0 opencode-supermemory installer
|
|
298
255
|
`);
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
console.log("Aborted.");
|
|
302
|
-
rl.close();
|
|
303
|
-
process.exit(0);
|
|
304
|
-
}
|
|
305
|
-
const installed = await installPlugin();
|
|
306
|
-
if (!installed) {
|
|
307
|
-
console.log("Aborted.");
|
|
308
|
-
rl.close();
|
|
309
|
-
process.exit(1);
|
|
310
|
-
}
|
|
311
|
-
const shouldCreateCommand = await confirm(rl, "Add /supermemory-init command?");
|
|
312
|
-
if (!shouldCreateCommand) {
|
|
313
|
-
console.log("Aborted.");
|
|
314
|
-
rl.close();
|
|
315
|
-
process.exit(0);
|
|
316
|
-
}
|
|
317
|
-
createCommand();
|
|
256
|
+
const rl = options.tui ? createReadline() : null;
|
|
257
|
+
console.log("Step 1: Register plugin in OpenCode config");
|
|
318
258
|
const configPath = findOpencodeConfig();
|
|
319
259
|
if (configPath) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
260
|
+
if (options.tui) {
|
|
261
|
+
const shouldModify = await confirm(rl, `Add plugin to ${configPath}?`);
|
|
262
|
+
if (!shouldModify) {
|
|
263
|
+
console.log("Skipped.");
|
|
264
|
+
} else {
|
|
265
|
+
addPluginToConfig(configPath);
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
addPluginToConfig(configPath);
|
|
325
269
|
}
|
|
326
|
-
addPluginToConfig(configPath);
|
|
327
270
|
} else {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
271
|
+
if (options.tui) {
|
|
272
|
+
const shouldCreate = await confirm(rl, "No OpenCode config found. Create one?");
|
|
273
|
+
if (!shouldCreate) {
|
|
274
|
+
console.log("Skipped.");
|
|
275
|
+
} else {
|
|
276
|
+
createNewConfig();
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
createNewConfig();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
console.log(`
|
|
283
|
+
Step 2: Create /supermemory-init command`);
|
|
284
|
+
if (options.tui) {
|
|
285
|
+
const shouldCreate = await confirm(rl, "Add /supermemory-init command?");
|
|
286
|
+
if (!shouldCreate) {
|
|
287
|
+
console.log("Skipped.");
|
|
288
|
+
} else {
|
|
289
|
+
createCommand();
|
|
333
290
|
}
|
|
334
|
-
|
|
291
|
+
} else {
|
|
292
|
+
createCommand();
|
|
335
293
|
}
|
|
336
294
|
console.log(`
|
|
337
|
-
|
|
338
|
-
console.log(
|
|
339
|
-
|
|
295
|
+
` + "─".repeat(50));
|
|
296
|
+
console.log(`
|
|
297
|
+
\uD83D\uDD11 Final step: Set your API key
|
|
298
|
+
`);
|
|
299
|
+
console.log("Get your API key from: https://console.supermemory.ai");
|
|
300
|
+
console.log(`
|
|
301
|
+
Then add to your shell profile:
|
|
302
|
+
`);
|
|
303
|
+
console.log(' export SUPERMEMORY_API_KEY="sm_..."');
|
|
304
|
+
console.log(`
|
|
305
|
+
Or create ~/.config/opencode/supermemory.jsonc:
|
|
306
|
+
`);
|
|
307
|
+
console.log(' { "apiKey": "sm_..." }');
|
|
308
|
+
console.log(`
|
|
309
|
+
` + "─".repeat(50));
|
|
310
|
+
console.log(`
|
|
311
|
+
✓ Setup complete! Restart OpenCode to activate.
|
|
312
|
+
`);
|
|
313
|
+
if (rl)
|
|
314
|
+
rl.close();
|
|
315
|
+
return 0;
|
|
340
316
|
}
|
|
341
317
|
function printHelp() {
|
|
342
318
|
console.log(`
|
|
343
|
-
opencode-supermemory
|
|
319
|
+
opencode-supermemory - Persistent memory for OpenCode agents
|
|
344
320
|
|
|
345
321
|
Commands:
|
|
346
|
-
|
|
322
|
+
install Install and configure the plugin
|
|
323
|
+
--no-tui Run in non-interactive mode (for LLM agents)
|
|
347
324
|
|
|
348
325
|
Examples:
|
|
349
|
-
|
|
350
|
-
bunx opencode-supermemory
|
|
326
|
+
bunx opencode-supermemory install
|
|
327
|
+
bunx opencode-supermemory install --no-tui
|
|
351
328
|
`);
|
|
352
329
|
}
|
|
353
330
|
var args = process.argv.slice(2);
|
|
354
|
-
if (args.length === 0 || args[0] === "help" || args[0] === "--help") {
|
|
331
|
+
if (args.length === 0 || args[0] === "help" || args[0] === "--help" || args[0] === "-h") {
|
|
355
332
|
printHelp();
|
|
356
333
|
process.exit(0);
|
|
357
334
|
}
|
|
358
|
-
if (args[0] === "
|
|
359
|
-
|
|
335
|
+
if (args[0] === "install") {
|
|
336
|
+
const noTui = args.includes("--no-tui");
|
|
337
|
+
install({ tui: !noTui }).then((code) => process.exit(code));
|
|
338
|
+
} else if (args[0] === "setup") {
|
|
339
|
+
console.log(`Note: 'setup' is deprecated. Use 'install' instead.
|
|
340
|
+
`);
|
|
341
|
+
const noTui = args.includes("--no-tui");
|
|
342
|
+
install({ tui: !noTui }).then((code) => process.exit(code));
|
|
360
343
|
} else {
|
|
361
|
-
console.error(`Unknown command: ${args
|
|
344
|
+
console.error(`Unknown command: ${args[0]}`);
|
|
362
345
|
printHelp();
|
|
363
346
|
process.exit(1);
|
|
364
347
|
}
|