Skip to content
Open
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
118 changes: 116 additions & 2 deletions hindsight-integrations/opencode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,127 @@ Create `~/.hindsight/opencode.json` for persistent configuration:
}
```

### Per-Agent API Keys

OpenCode drives sessions with named agents (e.g. `build`, `code-reviewer`, or
your own custom agents). You can give each agent its own Hindsight API key —
the plugin resolves the key at request time from the **name of the agent**
running the current turn:

```json
{
"plugin": [
[
"@vectorize-io/opencode-hindsight",
{
"hindsightApiToken": "fallback-key",
"hindsightApiTokens": {
"build": "build-agent-key",
"code-reviewer": "reviewer-key",
"angular-dev-expert": "angular-key"
}
}
]
]
}
```

Resolution order (first non-empty value wins):

1. `hindsightApiTokens[<current agent name>]` — the agent driving the turn.
Tools read the agent from OpenCode's tool context; hooks read it from the
most recent user message in the session.
2. `hindsightApiTokens[agentName]` — the entry for the configured default
`agentName`.
3. `hindsightApiToken` — the single static fallback key (legacy behavior).

Agents with no entry in the map fall back to `hindsightApiToken`, so existing
single-key setups keep working unchanged. Set `"dynamicApiKey": false` to
disable per-agent resolution and force use of `hindsightApiToken` everywhere.

The per-agent map can also be supplied via the `HINDSIGHT_API_TOKENS`
environment variable as a JSON object (see below).

### Per-Agent Bank IDs

By default every agent in a project shares one memory bank (derived from
`bankId`, or the dynamic `agent::project` composition). You can give each
agent its **own memory bank** — the plugin resolves the bank at request time
from the **name of the agent** driving the turn. There are two ways to map
agents to bank IDs.

#### Agent file frontmatter (highest precedence)

Add a `bankid` field to the YAML frontmatter of any agent definition file
(`.opencode/agent/<name>.md`, `~/.config/opencode/agents/<name>.md`, etc.):

```markdown
---
description: Reviews recently written code
mode: all
bankid: opencode-code-reviewer
---

You are an elite code reviewer…
```

When present, this value **takes precedence over every other source**
(including `hindsightBankIds` and the static `bankId`). The `bankIdPrefix`
is applied. File results are cached per agent name, keyed on file mtime, so
repeated lookups during a session are cheap. Project-scoped agent files
(`.opencode/agent(s)/`) take precedence over global ones
(`~/.config/opencode/agent(s)/`), mirroring how OpenCode merges configs.

#### Config-file map (`hindsightBankIds`)

Map agent names to bank IDs in `opencode.json` or `~/.hindsight/opencode.json`:

```json
{
"plugin": [
[
"@vectorize-io/opencode-hindsight",
{
"bankId": "fallback-bank",
"hindsightBankIds": {
"build": "build-bank",
"code-reviewer": "reviewer-bank",
"angular-dev-expert": "angular-bank"
}
}
]
]
}
```

#### Resolution order (first defined value wins)

1. **Agent `.md` frontmatter `bankid`** — read from the agent's definition
file (highest precedence). `bankIdPrefix` is applied.
2. `hindsightBankIds[<current agent name>]` — the agent driving the turn
(read from the tool context, or the most recent user message in a session).
`bankIdPrefix` is applied.
3. `hindsightBankIds[agentName]` — the entry for the configured default
`agentName`. `bankIdPrefix` is applied.
4. The normal `deriveBankId` result — static `bankId`, or the dynamic
`dynamicBankGranularity` composition (`agent::project`, `gitProject`, …).
`bankIdPrefix` is already applied by the derivation.

Agents with no `bankid` in their `.md` file and no entry in the map fall back
to the shared bank, so existing single-bank setups keep working unchanged. The
per-agent map can also be supplied via the `HINDSIGHT_BANK_IDS` environment
variable as a JSON object.

### Environment Variables

| Variable | Description | Default |
| ----------------------------- | -------------------------------------------------------- | ------------------------------------- |
| `HINDSIGHT_API_URL` | Hindsight API base URL | `https://api.hindsight.vectorize.io` |
| `HINDSIGHT_API_TOKEN` | API key for authentication | (none — required for Hindsight Cloud) |
| `HINDSIGHT_BANK_ID` | Static memory bank ID | `opencode` |
| `HINDSIGHT_API_TOKEN` | API key for authentication (fallback for unmapped agents) | (none — required for Hindsight Cloud) |
| `HINDSIGHT_API_TOKENS` | JSON object mapping agent name → API key | `{}` |
| `HINDSIGHT_DYNAMIC_API_KEY` | Enable per-agent key resolution from `hindsightApiTokens` | `true` |
| `HINDSIGHT_BANK_ID` | Static memory bank ID (fallback for unmapped agents) | `opencode` |
| `HINDSIGHT_BANK_IDS` | JSON object mapping agent name → bank ID | `{}` |
| `HINDSIGHT_AGENT_NAME` | Agent name for dynamic bank IDs | `opencode` |
| `HINDSIGHT_AUTO_RECALL` | Auto-recall on session start | `true` |
| `HINDSIGHT_AUTO_RETAIN` | Auto-retain on session idle | `true` |
Expand Down
4 changes: 2 additions & 2 deletions hindsight-integrations/opencode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading