Skip to content

Commit f92dfae

Browse files
committed
v1.9.7: first-class opencode plugin + setup auto-wiring
1 parent a458e85 commit f92dfae

8 files changed

Lines changed: 859 additions & 27 deletions

File tree

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# Changelog
22

3+
## 1.9.7 (2026-04-21) — first-class OpenCode plugin + setup auto-wiring
4+
5+
OpenCode parity for the lifecycle hooks that were previously Claude-Code-only.
6+
7+
### Added
8+
9+
- **`scripts/plugins/opencode/agent-knowledge.ts`** — in-repo opencode plugin, exposed via the new `"./opencode"` subpath export in `package.json`. Users register it with a single line in `opencode.json`: `"plugin": ["agent-knowledge/opencode"]`. Covers four of the six Claude Code lifecycle hooks:
10+
- `event: session.created` → session-start announce (dashboard URL toast + clears stale first-prompt marker on resume)
11+
- `chat.message` → first-prompt-inject (searches KB via dashboard `/api/knowledge/search`, prepends rendered hits block to user parts, sets marker, emits a `"injected N hits"` toast)
12+
- `experimental.session.compacting` → precompact-flush (pushes the "save unsaved knowledge before compaction" nudge into `output.context`)
13+
- `event: session.deleted` → sessionend-distill (walks `client.session.messages`, writes `~/agent-knowledge/projects/session-opencode-<slug>.md` with turn counts, tool uses, and first 20 user prompts)
14+
15+
Honours the same env vars as the Claude hooks (`AGENT_KNOWLEDGE_MEMORY_DIR`, `AGENT_KNOWLEDGE_DATA_DIR`, `AGENT_KNOWLEDGE_PORT`, `AGENT_KNOWLEDGE_FIRSTPROMPT_*`). Fails open on every handler — search timeout, toast failure (CLI mode), SDK error on session walk, disk write failure — so the user is never blocked.
16+
17+
- **`scripts/setup.js --host=opencode|all`** — new flag alongside the existing `--agent` (kept for back-compat). Auto-detects `~/.config/opencode/opencode.json` (Linux/macOS) or `%APPDATA%\opencode\opencode.json` (Windows); `--workspace=<path>` configures a project-local config. Idempotently ensures `mcp.agent-knowledge` + `plugin` array contain the plugin id.
18+
19+
- **`tests/plugins/opencode.test.ts`** — direct-import vitest suite covering plugin shape, first-prompt gating (short / slash / bang prompts skipped, marker set even on zero-hit, second turn does not re-inject), `AGENT_KNOWLEDGE_FIRSTPROMPT_INJECT=0` kill-switch, compacting context push, session.deleted distill disk output, and fail-open on toast + session-walk errors.
20+
21+
### Not ported (no opencode analog)
22+
23+
- `session-start-ingest.mjs` — paired with the `/knowledge-ingest` skill flow, which is Claude-Code-specific.
24+
- `precompact-distill.mjs` — opencode compaction does not expose the transcript to plugins.
25+
- L0 identity auto-load — opencode has no `additionalContext` equivalent; identity lives in `AGENTS.md` or on-demand `knowledge(action="wakeup")` calls.
26+
27+
### Tests
28+
29+
571 → 583 passing (12 new assertions across plugin shape, first-prompt gating, compacting context, and session.deleted distill). No changes to the Claude hook suite.
30+
331
## 1.9.6 (2026-04-21) — visible SessionEnd receipts + live dashboard toasts
432

533
Three-layer visibility for the SessionEnd distill hook, so "did it actually run?" never has to be guessed again.

agent-desk-plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "agent-knowledge",
33
"name": "Knowledge",
44
"icon": "psychology",
5-
"version": "1.9.6",
5+
"version": "1.9.7",
66
"description": "Knowledge base — entries, sessions, search, graph relationships",
77
"ui": "./dist/ui/app.js",
88
"css": "./dist/ui/styles.css",

docs/SETUP.md

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,62 @@ See [`docs/HOOKS.md`](HOOKS.md) for the full hook reference including environmen
258258

259259
### OpenCode Plugins
260260

261-
OpenCode supports lifecycle hooks via JavaScript/TypeScript plugins. Create a plugin in `.opencode/plugins/` or `~/.config/opencode/plugins/`:
261+
agent-knowledge ships a first-class opencode plugin at `scripts/plugins/opencode/agent-knowledge.ts`, exposed via the `"./opencode"` subpath export. Register it by adding one line to your `opencode.json`:
262262

263-
```typescript
264-
// .opencode/plugins/agent-knowledge.ts
265-
import type { Plugin } from '@opencode-ai/plugin';
263+
```json
264+
{
265+
"$schema": "https://opencode.ai/config.json",
266+
"mcp": {
267+
"agent-knowledge": {
268+
"type": "local",
269+
"command": ["node", "/absolute/path/to/agent-knowledge/dist/index.js"],
270+
"enabled": true,
271+
"timeout": 60000
272+
}
273+
},
274+
"plugin": ["agent-knowledge/opencode"]
275+
}
276+
```
266277

267-
export const AgentKnowledgePlugin: Plugin = async ({ client }) => {
268-
return {
269-
event: async (event) => {
270-
if (event.type === 'session.created') {
271-
// Knowledge base instructions provided via AGENTS.md
272-
}
273-
},
274-
};
275-
};
278+
Or let `scripts/setup.js` wire it automatically:
279+
280+
```bash
281+
node scripts/setup.js --host=opencode # global ~/.config/opencode/opencode.json
282+
node scripts/setup.js --host=opencode --workspace=/proj # workspace-local opencode.json
283+
node scripts/setup.js --host=all # both Claude Code and OpenCode
276284
```
277285

278-
Available events: `session.created`, `session.idle`, `tool.execute.before`, `tool.execute.after`, `message.updated`, `file.edited`.
286+
#### What the plugin does
287+
288+
Mirrors the Claude Code hooks where opencode has an equivalent event:
289+
290+
| Claude Code hook | OpenCode analog | Behavior |
291+
| ------------------------- | --------------------------------- | --------------------------------------------------------------------- |
292+
| `session-start.js` | `event: session.created` | Dashboard URL toast + clears stale first-prompt marker on resume. |
293+
| `first-prompt-inject.mjs` | `chat.message` | Searches the KB and prepends a rendered hits block to the user parts. |
294+
| `precompact-flush.mjs` | `experimental.session.compacting` | Pushes a "save unsaved knowledge before compaction" nudge. |
295+
| `sessionend-distill.mjs` | `event: session.deleted` | Writes `~/agent-knowledge/projects/session-opencode-<slug>.md`. |
296+
297+
Not ported (opencode has no equivalent surface):
298+
299+
- `session-start-ingest.mjs` (paired with the `/knowledge-ingest` skill flow).
300+
- `precompact-distill.mjs` (opencode compaction does not expose the transcript to plugins).
301+
- L0 identity auto-load (no `additionalContext` equivalent — put identity in `AGENTS.md` or call `knowledge(action="wakeup")` manually).
302+
303+
#### Environment variables
304+
305+
Same as the Claude hooks, all optional:
306+
307+
| Variable | Default | Description |
308+
| -------------------------------------- | ------------------- | -------------------------------------------------------- |
309+
| `AGENT_KNOWLEDGE_MEMORY_DIR` | `~/agent-knowledge` | Knowledge base root. |
310+
| `AGENT_KNOWLEDGE_DATA_DIR` | `<memory>/.data` | Marker/cache dir (first-prompt-seen markers live here). |
311+
| `AGENT_KNOWLEDGE_PORT` | `3423` | Dashboard port (plugin queries `/api/knowledge/search`). |
312+
| `AGENT_KNOWLEDGE_FIRSTPROMPT_INJECT` | `1` | Set `0` / `false` / `off` to disable inject entirely. |
313+
| `AGENT_KNOWLEDGE_FIRSTPROMPT_BUDGET` | `600` | Max inject tokens (chars/4), clamped `[100, 8000]`. |
314+
| `AGENT_KNOWLEDGE_FIRSTPROMPT_MAX_HITS` | `4` | Max rendered hits, clamped `[1, 20]`. |
315+
316+
Every hook fails open — errors during search, toast, session walk, or disk write are swallowed and the user is never blocked.
279317

280318
Combine with `AGENTS.md` instructions (see below).
281319

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agent-knowledge",
3-
"version": "1.9.6",
3+
"version": "1.9.7",
44
"description": "Cross-session memory and recall for AI agents — git-synced knowledge base, knowledge graph, confidence scoring, hybrid semantic+TF-IDF search, auto-distillation with secrets scrubbing",
55
"type": "module",
66
"main": "dist/index.js",
@@ -17,7 +17,8 @@
1717
"./dist/lib.js": {
1818
"types": "./dist/lib.d.ts",
1919
"default": "./dist/lib.js"
20-
}
20+
},
21+
"./opencode": "./scripts/plugins/opencode/agent-knowledge.ts"
2122
},
2223
"bin": {
2324
"agent-knowledge": "dist/index.js"
@@ -67,7 +68,8 @@
6768
"model-context-protocol",
6869
"ai-agents",
6970
"coding-assistants",
70-
"claude-code"
71+
"claude-code",
72+
"opencode"
7173
],
7274
"author": "keshrath",
7375
"mcpName": "io.github.keshrath/agent-knowledge",

0 commit comments

Comments
 (0)