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
35 changes: 31 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# AGENTS.md

## Dual-host fork notes (override the upstream host notes below)

- `src/opencode-session-recall.ts` default-exports one combined object, with lazy
V1 `server()` and V2 `setup()`. V1 requires >=1.18.29 (tested with 1.18.35).
`src/v1-plugin.ts` supplies the V1 transport and primary-tools config hook;
`src/v2-plugin.ts` registers native V2 transforms/hooks. `src/runtime.ts` is shared.
- `src/v2-client.ts` is the V2 history boundary. Use public V2 APIs and
JSON cursors, never private SDK transports or direct OpenCode DB access.
V1's SDK is runtime-only in the lazy V1 adapter. The legacy plugin package is
still types-only. Keep V2's plugin peer optional so V1 does not require it.
- Use `plugins` and object-form options in V2 config. The V2 cache defaults to
`store-opencode-v2.db`; do not share a cache with V1. `primary` is a retained
no-op in V2 because V2 uses normal agent permissions; V1 retains its behavior.
- Automatic recall and the nudge edit outgoing V2 context, not persisted user
input. Compaction preservation edits the compaction request's system context.
- `test/v2.test.ts` exercises native registration, public client pagination,
HTTP retrieval, context hooks, and cleanup. Run the full `npm run check` too.
- The normal workflow discovers an existing matching-version managed service.
Explicit/standalone servers need `options.server.url` (and optional headers).
Never call `Service.ensure` from the plugin or modify global config in tests.
- Build `dist/` before host testing. A new TUI session may still reuse a loaded
background-server plugin; reload/restart the server when needed, with the
user's approval if live sessions would be affected.
- Test `test/v1.test.ts` and `test/v2.test.ts`, plus the isolated V1 loader/API
probe `bun scripts/test-v1-host.mjs /path/to/opencode-v1`. Never point
V1 and V2 at the same explicit storePath; defaults remain separate.

Operational notes for agents working on this plugin. This is the stuff that is
**not** obvious from the code and cost real time to learn. Architecture, build
steps, and conventions live in [CONTRIBUTING.md](CONTRIBUTING.md) — read that for
Expand Down Expand Up @@ -72,16 +99,16 @@ import `bun:*` or `node:*` directly.

## How the plugin is loaded (why a rebuild is needed to test live)

- The global opencode config (`~/.config/opencode/opencode.json`) loads this
plugin **by directory path**, and opencode resolves it via `package.json`
`main` → `dist/opencode-session-recall.js`. **Source changes do nothing until
- V2 local-directory discovery uses the conventional `server.js` bridge →
`dist/opencode-session-recall.js`, not `package.json` exports or `main`.
Keep the bridge in the published files too. **Source changes do nothing until
you rebuild `dist/`** (`npm run compile`, or `npx tsup ... --format esm` for a
quick JS-only rebuild during debugging).
- A **running** opencode process has already loaded the old `dist/`. After
rebuilding you must **restart the session** (or relaunch) for it to pick up
changes. Live testing loop: edit → rebuild dist → restart the tuistory session
→ reproduce.
- `files: ["dist"]` in `package.json` means only `dist/` is published to npm;
- `files: ["dist", "server.js"]` in `package.json` controls what is published to npm;
CHANGELOG, AGENTS.md, src, etc. never ship.

## Live end-to-end testing with tuistory (when unit tests can't reach it)
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ All notable changes to this project are documented here. This project follows

## Unreleased

### Dual-host OpenCode fork

- Add a native V2 plugin entrypoint, JSON Schema tool registration, context and
compaction hooks, event subscription cleanup, and public V2 history client.
- Preserve bounded newest-first message pagination and paginate session discovery.
- Normalize V2 text, reasoning, tool output, shell and compaction records for the
existing search engine; tolerate user messages without a model selection.
- Discover the existing matching-version background service lazily, with an
explicit-server option; never start or replace a service from plugin setup.
- Isolate the V2 derived store as `store-opencode-v2.db`; V1 caches are untouched.
- Expose lazy V1 `server()` and V2 `setup()` from one default export. V1 >=1.18.29
can use the same built directory; V1 1.18.35 and V2 2.0.26 have host smoke tests.
- Restore V1 supplied-transport/authentication handling, primary-tools opt-out,
hooks and cleanup. Keep `primary` a no-op in V2 and caches separate by host.
- Move the legacy SDK to runtime dependencies for the V1 adapter and make the
V2 plugin peer optional. Neither adapter loads the other's host API eagerly.
- Make V2 service discovery channel-aware (`service-local.json` for source runs).
- Add V2 HTTP/registration regression tests and close summarizer test databases
before removing their directories on Windows.

### Added

- **`authorship` filter on `recall`**: ask for what a human actually typed.
Expand Down
16 changes: 14 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ cd opencode-session-recall
npm install
npm run typecheck # type-check without emitting
npm run compile # build with tsup + tsc declarations
npm run dev # run in opencode plugin dev mode
# Load the absolute checkout path through V2's `plugins` config after compiling.
```

### Requirements

- Node.js 20+
- TypeScript 6+
- An [OpenCode](https://github.com/opencode-ai/opencode) installation (for live testing)
- OpenCode V1 >=1.18.29 or V2; host smoke tests target V1 1.18.35 and V2 2.0.26

### Build

Expand All @@ -27,6 +27,18 @@ npm run typecheck && npm run compile

Output goes to `dist/`. The single entry point is `src/opencode-session-recall.ts`.

The entrypoint lazily dispatches V1 `server()` to `src/v1-plugin.ts` and V2
`setup()` to `src/v2-plugin.ts`. V1 reuses the supplied legacy SDK transport;
V2 registers native tools and context/compaction hooks. `src/runtime.ts` retains
the shared engine and `src/v2-client.ts` normalizes V2 history. Keep host SDKs
external and the V2 plugin peer optional; neither host should load the other's
adapter at import time. Build all generated chunks alongside the root entry.

See README's install section for service discovery and explicit-server options.
For focused checks, run `npx vitest run test/v1.test.ts test/v2.test.ts`.
Run `bun scripts/test-v1-host.mjs /path/to/opencode-v1` for V1's real
loader/API check; use an isolated standalone server for full V2 host testing.

## Architecture

### High-level overview
Expand Down
Loading