Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ Your agent remembers what you tell it - across sessions, across projects.
bunx opencode-supermemory@latest install
```

Then get your API key from [console.supermemory.ai](https://console.supermemory.ai) and set it:
Then get your API key from [app.supermemory.ai](https://app.supermemory.ai/?view=integrations) and set it:

```bash
export SUPERMEMORY_API_KEY="sm_..."
```

**Or let your agent do it** - paste this into OpenCode:

```
Install opencode-supermemory by following https://raw.githubusercontent.com/supermemoryai/opencode-supermemory/main/README.md
```
Expand All @@ -37,6 +38,7 @@ bunx opencode-supermemory@latest install --no-tui
```

This will:

- Register the plugin in `~/.config/opencode/opencode.jsonc`
- Create the `/supermemory-init` command

Expand All @@ -47,6 +49,7 @@ cat ~/.config/opencode/opencode.jsonc
```

Should contain:

```json
{
"plugin": ["opencode-supermemory"]
Expand All @@ -56,16 +59,18 @@ Should contain:
If not, add it manually:

**JSONC:**

```jsonc
{
"plugin": [
"opencode-supermemory"
"opencode-supermemory",
// ... other plugins
]
],
}
```

**JSON:**

```json
{
"plugin": ["opencode-supermemory"]
Expand All @@ -74,7 +79,7 @@ If not, add it manually:

#### Step 3: Configure API key

Ask the user to get their API key from [console.supermemory.ai](https://console.supermemory.ai).
Ask the user to get their API key from [app.supermemory.ai](https://app.supermemory.ai/?view=integrations).

Then set it via environment variable:

Expand All @@ -86,7 +91,7 @@ Or create `~/.config/opencode/supermemory.jsonc`:

```jsonc
{
"apiKey": "sm_..."
"apiKey": "sm_...",
}
```

Expand All @@ -99,6 +104,7 @@ opencode -c
```

They should see `supermemory` in the tools list. If not, check:

1. Is `SUPERMEMORY_API_KEY` set?
2. Is the plugin in `opencode.jsonc`?
3. Check logs: `tail ~/.opencode-supermemory.log`
Expand All @@ -114,11 +120,13 @@ Run `/supermemory-init` to have the agent explore and memorize the codebase.
### Context Injection

On first message, the agent receives (invisible to user):

- User profile (cross-project preferences)
- Project memories (all project knowledge)
- Relevant user memories (semantic search)

Example of what the agent sees:

```
[SUPERMEMORY]

Expand Down Expand Up @@ -154,6 +162,7 @@ Run `/supermemory-init` to explore and memorize your codebase structure, pattern
### Preemptive Compaction

When context hits 80% capacity:

1. Triggers OpenCode's summarization
2. Injects project memories into summary context
3. Saves session summary as a memory
Expand All @@ -172,23 +181,23 @@ Content in `<private>` tags is never stored.

The `supermemory` tool is available to the agent:

| Mode | Args | Description |
|------|------|-------------|
| `add` | `content`, `type?`, `scope?` | Store memory |
| `search` | `query`, `scope?` | Search memories |
| `profile` | `query?` | View user profile |
| `list` | `scope?`, `limit?` | List memories |
| `forget` | `memoryId`, `scope?` | Delete memory |
| Mode | Args | Description |
| --------- | ---------------------------- | ----------------- |
| `add` | `content`, `type?`, `scope?` | Store memory |
| `search` | `query`, `scope?` | Search memories |
| `profile` | `query?` | View user profile |
| `list` | `scope?`, `limit?` | List memories |
| `forget` | `memoryId`, `scope?` | Delete memory |

**Scopes:** `user` (cross-project), `project` (default)

**Types:** `project-config`, `architecture`, `error-solution`, `preference`, `learned-pattern`, `conversation`

## Memory Scoping

| Scope | Tag | Persists |
|-------|-----|----------|
| User | `opencode_user_{sha256(git email)}` | All projects |
| Scope | Tag | Persists |
| ------- | -------------------------------------- | ------------ |
| User | `opencode_user_{sha256(git email)}` | All projects |
| Project | `opencode_project_{sha256(directory)}` | This project |

## Configuration
Expand Down Expand Up @@ -228,7 +237,7 @@ Create `~/.config/opencode/supermemory.jsonc`:
"keywordPatterns": ["log\\s+this", "write\\s+down"],

// Context usage ratio that triggers compaction (0-1)
"compactionThreshold": 0.80
"compactionThreshold": 0.8,
}
```

Expand All @@ -237,6 +246,7 @@ All fields optional. Env var `SUPERMEMORY_API_KEY` takes precedence over config
### Container Tag Selection

By default, container tags are auto-generated using `containerTagPrefix` plus a hash:

- User tag: `{prefix}_user_{hash(git_email)}`
- Project tag: `{prefix}_project_{hash(directory)}`

Expand All @@ -248,11 +258,12 @@ You can override this by specifying exact container tags:
"userContainerTag": "my-team-workspace",

// Use a specific container tag for project memories
"projectContainerTag": "my-awesome-project"
"projectContainerTag": "my-awesome-project",
}
```

This is useful when you want to:

- Share memories across team members (same `userContainerTag`)
- Sync memories between different machines for the same project
- Organize memories using your own naming scheme
Expand Down Expand Up @@ -282,7 +293,7 @@ Local install:

```jsonc
{
"plugin": ["file:///path/to/opencode-supermemory"]
"plugin": ["file:///path/to/opencode-supermemory"],
}
```

Expand Down
22 changes: 20 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,24 @@ This will:

Wait for the command to complete, then inform the user whether authentication succeeded or failed.

If the user wants to log out instead, run:
If the user wants to log out instead, tell them to use the /supermemory-logout command.
`;

const SUPERMEMORY_LOGOUT_COMMAND = `---
description: Log out from Supermemory and clear credentials
---

# Supermemory Logout

Run this command to log out and clear Supermemory credentials:

\`\`\`bash
bunx opencode-supermemory@latest logout
\`\`\`

This will remove the saved credentials from ~/.supermemory-opencode/credentials.json.

Inform the user whether logout succeeded and that they'll need to run /supermemory-login to re-authenticate.
`;

function createReadline(): readline.Interface {
Expand Down Expand Up @@ -298,6 +312,10 @@ function createCommands(): boolean {
writeFileSync(loginPath, SUPERMEMORY_LOGIN_COMMAND);
console.log(`✓ Created /supermemory-login command`);

const logoutPath = join(OPENCODE_COMMAND_DIR, "supermemory-logout.md");
writeFileSync(logoutPath, SUPERMEMORY_LOGOUT_COMMAND);
console.log(`✓ Created /supermemory-logout command`);

return true;
}

Expand Down Expand Up @@ -389,7 +407,7 @@ async function install(options: InstallOptions): Promise<number> {
}

// Step 2: Create commands
console.log("\nStep 2: Create /supermemory-init and /supermemory-login commands");
console.log("\nStep 2: Create /supermemory-init, /supermemory-login, and /supermemory-logout commands");
if (options.tui) {
const shouldCreate = await confirm(rl!, "Add supermemory commands?");
if (!shouldCreate) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { homedir } from "node:os";
const CREDENTIALS_DIR = join(homedir(), ".supermemory-opencode");
const CREDENTIALS_FILE = join(CREDENTIALS_DIR, "credentials.json");
const AUTH_PORT = 19877;
const AUTH_BASE_URL = "https://console.supermemory.ai/auth/connect";
const AUTH_BASE_URL = process.env.SUPERMEMORY_AUTH_URL || "https://app.supermemory.ai/auth/connect";
const CLIENT_NAME = "opencode";

interface Credentials {
Expand Down