You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: docs/SETUP.md
+52-14Lines changed: 52 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -258,24 +258,62 @@ See [`docs/HOOKS.md`](HOOKS.md) for the full hook reference including environmen
258
258
259
259
### OpenCode Plugins
260
260
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`:
0 commit comments