From 9d75abab0619301e8a28fdd7311bd4e79cbbe53e Mon Sep 17 00:00:00 2001 From: Cristhian Hernandez Date: Tue, 24 Nov 2026 13:47:01 +0800 Subject: [PATCH 1/3] docs: add architecture, security assessment and governance pages --- CLAUDE.md | 3 +- README.md | 2 +- docs/ARCHITECTURE.md | 147 ++++++++++++++++++++++++++++++++++++ docs/GOVERNANCE.md | 21 ++++++ docs/SECURITY_ASSESSMENT.md | 83 ++++++++++++++++++++ 5 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 docs/ARCHITECTURE.md create mode 100644 docs/GOVERNANCE.md create mode 100644 docs/SECURITY_ASSESSMENT.md diff --git a/CLAUDE.md b/CLAUDE.md index 0832256..1b39be4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -127,7 +127,7 @@ Other top-level files: - `tests/opencode-config.test.ts` - checks that every `docs/examples/*.jsonc` parses and that each of its `-1h` variants rewrites to 1h (to a 12h breakpoint on the Responses example). - `tests/package-smoke.test.ts` - runs `npm pack` and resolves `/server|tui|rpc` against the tarball the way OpenCode does. - `docs/examples/` - sample provider configs with `-1h` model variants and commented plugin options, one per endpoint kind: `opencode.anthropic.jsonc`, `opencode.openrouter.jsonc`, `opencode.openai-compatible.jsonc`, `opencode.openai.jsonc` (not shipped). Add new examples there; the config test picks up every `.jsonc` file. -- `docs/` - `CONTRIBUTING.md`, `UPGRADE.md`, `SUPPORTED_PROVIDERS.md` (endpoints, Claude classification and per-provider caching, linked from the README), README images in `images/` (the sidebar SVGs are generated by `bun scripts/capture-sidebar.ts --all`, which needs Charm's `freeze`; `picker.svg` is generated too, as a lookalike of OpenCode's dialog), and design notes under `superpowers/`. +- `docs/` - `CONTRIBUTING.md`, `UPGRADE.md`, `SUPPORTED_PROVIDERS.md` (endpoints, Claude classification and per-provider caching, linked from the README), `ARCHITECTURE.md` (actors, actions and every external interface), `SECURITY_ASSESSMENT.md` (risks and what the code does about each), `GOVERNANCE.md` (maintainers, roles and who has access to what), README images in `images/` (the sidebar SVGs are generated by `bun scripts/capture-sidebar.ts --all`, which needs Charm's `freeze`; `picker.svg` is generated too, as a lookalike of OpenCode's dialog), and design notes under `superpowers/`. Where new code goes: @@ -155,6 +155,7 @@ Where new code goes: - Releases go through `.github/workflows/release.yml` with npm OIDC trusted publishing. A push to `main` whose `package.json` version has no `v*` tag yet is pre-checked, tagged, and published from a run dispatched at the tag. Do not tag or publish by hand. - The release workflow and the package smoke test pack with `--ignore-scripts`, so they run `bun run build` explicitly. Keep that if the pack command changes. - A change to features, install steps or requirements also updates `docs/toolkit-page.yaml`, the plugin's page on toolkit.noppu.com. +- A change to a hook, an external interface (package exports, plugin options, the command, the RPC contract, storage keys, the `x-cache-ttl` header) or the keepalive rules also updates `docs/ARCHITECTURE.md`, and `docs/SECURITY_ASSESSMENT.md` when it changes a risk or a safeguard. - Run `bun run fmt:check`, `bun run lint`, `bun test` and `bun run typecheck` before calling work done. diff --git a/README.md b/README.md index fa0e4bd..328ecbe 100644 --- a/README.md +++ b/README.md @@ -334,7 +334,7 @@ Turn the rows off with `savings` in the plugin options, in the picker, or with ` Found a bug or want a feature? Open an issue in the [issue tracker](https://github.com/noppu-labs/opencode-cache-manager/issues). Report security problems privately, as [SECURITY.md](SECURITY.md) describes. Changes come in as pull requests. -See [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md) for the local setup, the checks CI runs and how releases are cut. +See [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md) for the local setup, the checks CI runs and how releases are cut. [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) describes how the plugin works and its interfaces, [docs/SECURITY_ASSESSMENT.md](docs/SECURITY_ASSESSMENT.md) the risks it guards against, and [docs/GOVERNANCE.md](docs/GOVERNANCE.md) who maintains it. --- diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md new file mode 100644 index 0000000..5c17670 --- /dev/null +++ b/docs/ARCHITECTURE.md @@ -0,0 +1,147 @@ +# Architecture + +opencode-cache-manager is an OpenCode V2 plugin. It has no process of its own and opens no listening socket: OpenCode loads its two entry points, calls its hooks, and sends every model request itself. This page describes who takes part (the actors), what each part does (the actions), and every interface the released package exposes. [SECURITY_ASSESSMENT.md](SECURITY_ASSESSMENT.md) covers what can go wrong. + +The file-by-file layout is in [CONTRIBUTING.md](CONTRIBUTING.md#layout). + +## Actors + +| Actor | What it is | What it can do to the others | +| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| User | The person running OpenCode | Sets plugin options in `opencode.jsonc`, runs `/cache-manager`, uses the picker, puts the `x-cache-ttl` header on a model variant | +| OpenCode host | The OpenCode process | Loads the plugin, calls its hooks for each model request and response, sends the requests, provides sessions, storage, the model catalog, commands and the RPC channel | +| Server part | `src/server.ts` and what it wires: the two HTTP hooks, the keepalive engine, the stores, the savings ledger, the server command, the RPC handlers | Rewrites outgoing model requests, reads their responses, asks the host to send keepalive pings, reads and writes plugin storage | +| TUI part | `src/tui.ts` and `src/ui/`: the slash command, the picker, the sidebar | Calls the server part over RPC; reads the host's session data for the sidebar | +| Model provider or proxy | Anthropic, OpenAI, OpenRouter, or a proxy such as OmniRoute | Receives the requests the host sends; its responses are input to the plugin's parsers | +| Plugin storage | The key-value store OpenCode gives the plugin, shared by every OpenCode process on the machine | Holds settings, learned model profiles, keepalive records, ledger totals and the cached price list | +| models.dev | A public price list, used only when `modelsDevPrices` is on | Supplies model prices for the sidebar's dollar figures | +| Other plugins | Anything else hooked into the same requests | Can rewrite the same request before or after this plugin does | +| Debug log file | A local JSONL file, written only when `debug` is on | Receives a trace of what the plugin did | + +## Actions + +### Rewriting a request + +OpenCode calls the `http.request` hook (`src/middleware/request.ts`) before it sends a model request. The hook: + +1. Classifies the request. The wire comes from the URL path (`/messages`, `/chat/completions`, `/responses`). The cache profile (`anthropic`, `openai` or `implicit`) comes from the provider ID, the model name, the `cacheProfiles` option, or what an earlier response reported (`src/services/classify.ts`). A request no profile applies to is left untouched. +2. Resolves the TTL mode: the session's setting, then the stored global one, then the plugin option, then the default. An `x-cache-ttl` header on the request wins over all of them. +3. For a keepalive ping, replaces the ping's messages with those of the session's last real request, so the ping reads the same cached prefix (`src/services/ping-alignment.ts`). Those messages are held in memory only. +4. Lets the profile rewrite the JSON body for the mode: TTLs on `cache_control` blocks, breakpoints where the profile adds them, and the `anthropic-beta` header for 1h (`src/services/cache-ttl.ts`, `src/services/profiles/`). The `x-cache-ttl` header is removed. +5. Tells the keepalive engine a request went out. + +The request keeps its URL and method. The only header changes are the merged `anthropic-beta` value, the removed `x-cache-ttl`, and `content-length`, which is dropped when a ping's body is replaced so that it is recomputed. If the rewrite throws, the request goes out as OpenCode built it and a warning is written to the console. + +### Reading a response + +OpenCode calls the `http.response` hook (`src/middleware/response.ts`) with the response. The hook tees the body (`src/services/response-observer.ts`): OpenCode receives the response unchanged, and the plugin reads its own copy in the background. From that copy it parses token usage, the stop reason and the model the response names, with one parser set per wire (`src/services/usage*.ts`). It then: + +- records which profile the named model belongs to, so the next request to that model is classified by it (`src/services/profile-store.ts`); +- drops a learned profile when a non-Anthropic provider answers a Messages request with 400 or 422; +- reports the usage to the keepalive engine. + +A failure anywhere in this path is swallowed. The response OpenCode sees is never altered. + +### Keeping a cache warm + +The keepalive engine (`src/services/keepalive-engine.ts`) keeps one schedule per session. After a request whose response showed cache activity, it sets a timer for shortly before the cache expires. When the timer fires, it asks the host for a transient generation on that session with a fixed prompt (`ctx.session.generate`); the host builds and sends that request, so it passes through both hooks like any other. A ping that reads at least 90% of the context from cache is a hit and the next ping is scheduled; anything less stops keepalive for the session until its next real request. + +The engine never pings a child session, a session below `minContextTokens`, a session waiting on a tool call, or a session that has used `maxPings` pings since its last real request. [The README](../README.md#keepalive) has the full rules. + +Each armed session has a record in plugin storage, so a schedule survives a plugin reload or a restart (`src/services/keepalive-store.ts`). A record names the process and directory that wrote it, and only that owner, or its directory's next process once the owner has exited, resumes it. Two OpenCode processes therefore never ping the same session. + +### Changing settings + +Settings are layered: built-in defaults, plugin options, a stored global value, a stored per-session value (`src/services/settings-store.ts`). They change in two ways: + +- `/cache-manager` with a typed argument. The TUI registers the slash command and sends the change over RPC. The server part registers the same command, so typed arguments also work headless (`src/controllers/command.ts`). +- The picker, which `/cache-manager` opens when it has no argument. It calls `setSession`, `setGlobal` or `resetSession` over RPC. + +Every change is validated, stored, applied to the keepalive schedule and announced with a `settings.updated` event. + +### Showing the sidebar + +The TUI subscribes to `keepalive.updated` events and also fetches snapshots with `getKeepalive` (`src/ui/snapshot-feed.ts`), then formats them (`src/ui/sidebar-lines.ts`). A Claude Agent session never reaches the HTTP hooks, so for those the sidebar reads token counts from the host's own session data (`src/ui/claude-agent.ts`). + +### Counting savings + +The engine tells the savings ledger about each ping and each idle stretch a ping rescued (`src/services/savings-ledger.ts`). The ledger prices them from OpenCode's model catalog (`src/services/model-prices.ts`) and stores totals per session. With `modelsDevPrices` on, a model the catalog has no price for is looked up in a copy of the models.dev list, fetched at most once a day (`src/services/models-dev.ts`). This is the only network request the plugin makes itself. + +### Starting and stopping + +At setup the server part loads settings and learned profiles, registers the RPC handlers, the command and the two hooks, removes stored entries of sessions that were deleted while it was not running, and resumes the keepalive records it owns. On disposal it cancels every timer and drops the in-memory messages. + +## External interfaces + +These are all the ways anything outside the plugin interacts with the released package. + +### Package entry points + +| Export | Resolves to | What it is | +| ------------------ | --------------- | -------------------------------------------------------------------------------------------------------------------------------- | +| `.` and `./server` | `src/server.ts` | The server plugin, a `Plugin.define` default export OpenCode loads | +| `./tui` | `src/tui.ts` | The TUI plugin, a `Plugin.define` default export OpenCode loads | +| `./rpc` | `src/rpc.ts` | The RPC contract `CacheTtlRpc` and the client types `CacheTtlRpcClient`, `RawCacheTtlRpcClient`, `RpcCallOptions`, `RpcLocation` | +| `./package.json` | `package.json` | The manifest | + +### Plugin options + +Read once at startup from the plugin's entry in `opencode.jsonc`: `defaultMode`, `keepalive.enabled`, `keepalive.maxPings`, `keepalive.minContextTokens`, `savings`, `modelsDevPrices`, `openaiCompatible`, `cacheProfiles`, `debug`. [The README](../README.md#settings) documents each one. An invalid value is ignored and the default applies. + +### The `/cache-manager` command + +Input is the argument text: nothing, `5m`, `1h`, `hybrid`, `keepalive on|off`, `pings <0-100>`, `min ` (`50000` or `50k`), `savings on|off`, `status`, `reset`. With no argument the TUI opens the picker; the server-side command, which is the one that runs headless, toggles the session between `5m` and `1h`. Output is a toast in the TUI and a synthetic message in the session when headless. An argument that doesn't parse changes nothing and prints the list of valid ones. See [Usage](../README.md#usage). + +### The `x-cache-ttl` request header + +A model variant can carry `x-cache-ttl` with a TTL mode. The plugin reads it, applies that mode to the request it is on, and removes it before the request leaves. See [Per-model override](../README.md#per-model-override). + +### RPC + +The contract ID is `opencode-cache-manager`. Inputs and outputs are validated by OpenCode against the JSON schemas in `src/rpc.ts`. + +| Method | Input | Output | +| -------------- | ---------------------- | ---------------------------------------------------------------------------------- | +| `getSettings` | `{ sessionID? }` | `{ global, session }`: the effective global settings and the session's overrides | +| `setGlobal` | `{ patch }` | `{}` | +| `setSession` | `{ sessionID, patch }` | `{}` | +| `resetSession` | `{ sessionID }` | `{}` | +| `getKeepalive` | `{ sessionID }` | A keepalive snapshot: TTL, expiry, next ping, pings used, last cache read, savings | + +A `patch` may hold `mode` (`5m`, `1h`, `hybrid`), `keepalive`, `maxPings` (0 to 100), `minContextTokens` and `savings`. A patch with any other field is rejected. + +| Event | Payload | +| ------------------- | ----------------------------------------------------------- | +| `settings.updated` | `{ sessionID }`, `null` for a global change | +| `keepalive.updated` | A keepalive snapshot, the same shape `getKeepalive` returns | + +### Requests to model providers + +The plugin sends nothing to a provider itself. It changes requests OpenCode is about to send, and only for a model a profile manages: `cache_control` TTLs and breakpoints and the `anthropic-beta` header for Claude, `prompt_cache_breakpoint` and `prompt_cache_options` for GPT-5.6+. [SUPPORTED_PROVIDERS.md](SUPPORTED_PROVIDERS.md) lists what is sent on each endpoint. A keepalive ping is a request OpenCode builds from the session's context and the prompt `Do not perform any work and do not use tools. Reply with exactly: OK`. + +From a response it reads the usage block, the stop or finish reason, and the model and provider names. It writes nothing back into the response. + +### Plugin storage + +| Key | Value | +| ----------------------- | ---------------------------------------------------------------------- | +| `global` | The stored global settings | +| `session/` | A session's setting overrides | +| `learned-models` | A map from `/` to the profile a response revealed | +| `keepalive/` | An armed session's schedule: TTL, last request time, pings used, owner | +| `ledger/` | A session's savings totals | +| `models-dev` | The cached price list, when `modelsDevPrices` is on | + +`mode` is a legacy key that is still read. Every value is validated when it is read, and a malformed one is ignored or removed. No prompt or response content is stored. + +### models.dev + +With `modelsDevPrices` on, one `GET https://models.dev/api.json` at most once a day, with a 10 second timeout. The request carries no data about the user. Only prices are kept from the response. + +### The debug log + +With `debug` on, the plugin appends one JSON object per line to a local file created with mode `0600`. [CONTRIBUTING.md](CONTRIBUTING.md#debug-log) says what it holds. + +### Console + +One warning line, `[opencode-cache-manager] cache rewrite failed, request sent unchanged:`, when a rewrite throws. diff --git a/docs/GOVERNANCE.md b/docs/GOVERNANCE.md new file mode 100644 index 0000000..2a0a7a2 --- /dev/null +++ b/docs/GOVERNANCE.md @@ -0,0 +1,21 @@ +# Governance + +opencode-cache-manager is maintained by [Noppu Labs](https://noppu.com). It has one maintainer, who makes the final call on what is merged and released. + +## Roles + +| Role | Who | Responsibilities | +| ----------- | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Maintainer | [@cris005](https://github.com/cris005) | Reviews and merges pull requests, triages issues, cuts releases by merging a version bump, answers vulnerability reports, manages repository and organization settings | +| Contributor | Anyone who opens an issue or pull request | Follows [CONTRIBUTING.md](CONTRIBUTING.md); has no write access | + +## Access to sensitive resources + +| Resource | Who has access | +| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | +| The GitHub repository (admin, including rulesets and Actions settings) | [@cris005](https://github.com/cris005), the only owner of the `noppu-labs` organization and the only collaborator | +| Vulnerability reports and security advisories | [@cris005](https://github.com/cris005) | +| The npm packages `@noppu-labs/opencode-cache-manager` and `opencode-cache-manager` | The `noppu` npm account | +| Publishing a release | Nobody by hand: `release.yml` publishes through npm trusted publishing, and no npm token is stored | + +The organization requires two-factor authentication. `.github/CODEOWNERS` routes every pull request to the maintainer. diff --git a/docs/SECURITY_ASSESSMENT.md b/docs/SECURITY_ASSESSMENT.md new file mode 100644 index 0000000..ee87e99 --- /dev/null +++ b/docs/SECURITY_ASSESSMENT.md @@ -0,0 +1,83 @@ +# Security assessment + +This is the project's own assessment of what could go wrong in opencode-cache-manager, which problems are most likely or most costly, and what the code does about each. It was last reviewed for version 0.8.3. A change to a hook, a parser, the keepalive rules, storage or the release pipeline should update it. [ARCHITECTURE.md](ARCHITECTURE.md) describes the actors and interfaces named here. + +To report a vulnerability, see [SECURITY.md](../SECURITY.md). + +## What is worth protecting + +- **Credentials in transit.** Every model request carries the user's API key in a header. The plugin handles the request object before OpenCode sends it. +- **Prompt and response content.** The request body is the conversation; the response body is the model's reply. +- **The user's money.** A keepalive ping is a paid provider request, and a rewrite decides what the provider charges for a cache write. +- **The user's turn.** A request the provider rejects fails the user's prompt. +- **The published package.** A tampered release would run inside every user's OpenCode. + +## Trust boundaries + +- The plugin runs inside the OpenCode process with that process's rights. It trusts the host's hook events, session API and storage API. +- Provider and proxy responses are untrusted input. Proxies in particular answer in shapes the official APIs never produce. +- Plugin storage is shared by every OpenCode process on the machine and can be written by anything running as the user, so stored values are treated as untrusted when read. +- Plugin options, command arguments and RPC inputs come from the user or from another local plugin and are validated before use. +- The models.dev response is untrusted input. + +## Risks + +### 1. A request is sent somewhere it wasn't addressed, or carries something it shouldn't + +Impact: high. Likelihood: low. + +The rewrite builds each new request from the original's URL, method and headers; it never changes the destination and adds no header beyond `anthropic-beta`. A keepalive ping reuses the messages of the same session's last request, looked up by session ID and held in memory only, and OpenCode sends it to that session's model. The plugin makes one network request of its own, an opt-in `GET` to models.dev that carries no user data. + +### 2. Keepalive spends more than the user expects + +Impact: medium (money). Likelihood: medium, because it depends on how the user works. + +Pings are bounded by `maxPings` per idle stretch (5 by default, 100 at most; a larger stored or typed value is not accepted). A ping that doesn't read the cache stops keepalive for the session, so a provider that ignores the cache can't become a stream of paid requests. A ping is never sent after the cache would already have expired. Child sessions, small contexts and sessions waiting on a tool are skipped. Each stored schedule has one owning process, so two OpenCode processes don't ping the same session. + +What remains: pings for a session the user never returns to are pure cost, and running this plugin together with OpenCode's own `warming` option pays for both. The README states both. + +### 3. A rewrite makes the provider reject the user's request + +Impact: medium (a failed turn). Likelihood: medium on proxies and router aliases. + +`prompt_cache_breakpoint` and `prompt_cache_options` go only to a model the `openai` profile matched by name or by an explicit `cacheProfiles` entry; a profile learned from a response never widens that. On the Messages wire only known Anthropic provider IDs are trusted as Claude and every other provider is classified by model. A Messages request a non-Anthropic provider answers with 400 or 422 drops the learned profile. A rewrite that throws leaves the request as OpenCode built it. + +What remains: a router alias that switches models runs one turn behind, so the first request after a switch can carry the previous model's fields. + +### 4. A malformed or hostile response breaks the plugin or the host + +Impact: medium. Likelihood: medium, since proxies vary. + +The response OpenCode receives is a pass-through of the original body; the plugin parses a separate copy in the background. Every step of that parsing is inside a `try`, the promises it returns never reject, and a value that fails a type check is treated as absent. The parsers, the rewrites and the input parsing are covered by fast-check property tests, 1,000 runs per property on each pull request and 10,000 weekly. + +What remains: the background copy is read into memory in full, as the host's own copy is. + +### 5. Tampered storage changes behaviour + +Impact: low to medium. Likelihood: low; it needs code already running as the user. + +Stored settings pass the same validation as typed ones. A keepalive record is checked field by field and dropped when malformed or expired, and a resumed schedule is still subject to every keepalive rule. A learned profile must be one of the three known IDs, and a learned `openai` is never enough on its own to send OpenAI-only fields. Ledger totals must be finite, non-negative numbers. + +What remains: a writer can change the TTL mode, switch keepalive on or off and set its limits within the allowed ranges; forge a keepalive record so a session's pings resume on a schedule of the writer's choosing; mark a model on a non-Anthropic provider as Claude, so its next request carries Claude's cache fields; and change the savings figures the sidebar shows. + +### 6. The debug log exposes something sensitive + +Impact: medium. Likelihood: low; the log is off unless the user turns it on. + +Request bodies are never written, apart from `role` and `cache_control` values of up to 16 characters in the breakpoint survey. URLs are logged without their query string or user info. Response excerpts and error messages need the separate `bodies` flag and are capped at 600 characters from each end. The file is created with mode `0600`. + +What remains: a proxy that puts a key in the URL path will have it in the log, and `bodies` output can contain reply text. [CONTRIBUTING.md](CONTRIBUTING.md#debug-log) warns about both. + +### 7. A wrong price from models.dev + +Impact: low. Likelihood: low. + +Prices only affect the dollar figures in the sidebar, never a request. A price must be a finite number with a positive input cost, and a model whose listings disagree is not priced. + +### 8. The release is tampered with + +Impact: high. Likelihood: low. + +The package has no runtime dependencies of its own. CI installs from the committed lockfile with lifecycle scripts off, and every GitHub Action is pinned to a commit. A ruleset on `main` requires a pull request, a code-owner review and the CI check, and a ruleset on release tags blocks moving or deleting them. Publishing uses npm trusted publishing from `release.yml`, so no npm token exists to steal. Each release carries npm provenance, a build provenance attestation and checksums, and the smoke test checks that the tarball holds exactly the tested sources. [SECURITY.md](../SECURITY.md#verifying-releases) shows how to verify a release. + +What remains: whoever can merge to `main` controls the release, and that is one maintainer today (see [GOVERNANCE.md](GOVERNANCE.md)). As the organization's only admin, the maintainer can bypass both rulesets: their own pull requests merge without a second person's approval, and the tag ruleset does not bind them. The checks, the pull request history and the provenance records still apply to every release. From e63608daca17c66c40ce42de3a49416196cb7adf Mon Sep 17 00:00:00 2001 From: Cristhian Hernandez Date: Tue, 24 Nov 2026 13:47:01 +0800 Subject: [PATCH 2/3] docs: document dependency handling, contribution licensing and disclosure policy --- SECURITY.md | 4 ++++ docs/CONTRIBUTING.md | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/SECURITY.md b/SECURITY.md index f2f36bd..573aa93 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -7,6 +7,10 @@ Report suspected vulnerabilities privately via please don't open a public issue. Include enough detail to reproduce: the plugin version, the provider and endpoint involved, and the impact. You can expect an initial response within a week. +## Disclosure policy + +The project follows coordinated disclosure. A report stays private while it is assessed and fixed. Once a fixed version is released, the vulnerability is published as a [GitHub security advisory](https://github.com/noppu-labs/opencode-cache-manager/security/advisories) on this repository, with the affected versions, how to tell whether you are affected, and the version that fixes it. + ## Scope This repository ships an OpenCode plugin that rewrites outgoing model requests and sends hidden diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 9729d30..9b325ea 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -8,6 +8,8 @@ Report bugs and request features in the [issue tracker](https://github.com/noppu Changes come in as pull requests against `main`. Each one needs a review and a passing CI run before it merges. +Contributions are licensed under the repository's [MIT license](../LICENSE). By opening a pull request you state that you have the right to submit the change under that license, as GitHub's Terms of Service require of every contribution to a repository with a license ([section D.6](https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#6-contributions-under-repository-license)). + ## Prerequisites - [Bun](https://bun.sh) 1.4.2 or newer. CI pins 1.4.2, the version OpenCode V2 embeds. On Bun 1.3.x the keepalive tests, which advance fake timers by 50 minutes, can freeze the event loop on a freshly booted machine. @@ -79,6 +81,14 @@ The request rewrites, response parsers and user-input parsing also have [fast-ch A failure prints a seed, a path and the smallest failing input. Reproduce it by passing `{ seed, path }` as the second argument to that `fc.assert`. If it is a real bug, fix it and add the input as an example-based test in the module's normal test file. +## Dependencies + +The package has no runtime dependencies of its own. What it imports at runtime (`@opencode/plugin`, `@opentui/core`, `@opentui/solid`, `solid-js`) is declared under `peerDependencies` and provided by OpenCode. Everything under `devDependencies` is tooling: the type checker, linter, formatter, test libraries, and pinned copies of the peers to build and test against. + +- **Selecting.** A dependency is added or changed only in a pull request, where it is reviewed like any other change. +- **Obtaining.** Dependencies come from the npm registry through `bun install`. `package.json` declares them and `bun.lock` pins the exact versions and integrity hashes of the whole tree; both are committed. CI installs with `--frozen-lockfile --ignore-scripts`, so it uses exactly the locked versions and runs no package's install script. GitHub Actions are pinned to a commit SHA. +- **Tracking.** Dependabot opens weekly pull requests for npm packages and GitHub Actions (`.github/dependabot.yml`) and raises security updates as advisories appear. `overrides` in `package.json` holds a transitive dependency at a patched version when its parent hasn't moved yet. + ## Layout ``` From aaf8f6a8fdfa3e2c90e6130422e4df86937ec902 Mon Sep 17 00:00:00 2001 From: Cristhian Hernandez Date: Tue, 24 Nov 2026 13:52:29 +0800 Subject: [PATCH 3/3] docs: tighten the wording of the new pages --- SECURITY.md | 6 +++++- docs/ARCHITECTURE.md | 16 +++++++--------- docs/CONTRIBUTING.md | 8 +++++--- docs/SECURITY_ASSESSMENT.md | 14 +++++++------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 573aa93..d2a6fd5 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -9,7 +9,11 @@ provider and endpoint involved, and the impact. You can expect an initial respon ## Disclosure policy -The project follows coordinated disclosure. A report stays private while it is assessed and fixed. Once a fixed version is released, the vulnerability is published as a [GitHub security advisory](https://github.com/noppu-labs/opencode-cache-manager/security/advisories) on this repository, with the affected versions, how to tell whether you are affected, and the version that fixes it. +The project follows coordinated disclosure. A report stays private while it is assessed and fixed. +Once a fixed version is released, the project publishes the vulnerability as a +[GitHub security advisory](https://github.com/noppu-labs/opencode-cache-manager/security/advisories) +on this repository, with the affected versions, how to tell whether you are affected, and the +version that fixes it. ## Scope diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 5c17670..fce0d2a 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -1,6 +1,6 @@ # Architecture -opencode-cache-manager is an OpenCode V2 plugin. It has no process of its own and opens no listening socket: OpenCode loads its two entry points, calls its hooks, and sends every model request itself. This page describes who takes part (the actors), what each part does (the actions), and every interface the released package exposes. [SECURITY_ASSESSMENT.md](SECURITY_ASSESSMENT.md) covers what can go wrong. +opencode-cache-manager is an OpenCode V2 plugin. It has no process of its own and opens no listening socket: OpenCode loads its two entry points, calls its hooks, and sends every model request itself. This page covers the actors, what each of them does, and every interface the released package exposes. [SECURITY_ASSESSMENT.md](SECURITY_ASSESSMENT.md) covers what can go wrong. The file-by-file layout is in [CONTRIBUTING.md](CONTRIBUTING.md#layout). @@ -40,7 +40,7 @@ OpenCode calls the `http.response` hook (`src/middleware/response.ts`) with the - drops a learned profile when a non-Anthropic provider answers a Messages request with 400 or 422; - reports the usage to the keepalive engine. -A failure anywhere in this path is swallowed. The response OpenCode sees is never altered. +A failure anywhere in this path is swallowed. ### Keeping a cache warm @@ -73,8 +73,6 @@ At setup the server part loads settings and learned profiles, registers the RPC ## External interfaces -These are all the ways anything outside the plugin interacts with the released package. - ### Package entry points | Export | Resolves to | What it is | @@ -86,7 +84,7 @@ These are all the ways anything outside the plugin interacts with the released p ### Plugin options -Read once at startup from the plugin's entry in `opencode.jsonc`: `defaultMode`, `keepalive.enabled`, `keepalive.maxPings`, `keepalive.minContextTokens`, `savings`, `modelsDevPrices`, `openaiCompatible`, `cacheProfiles`, `debug`. [The README](../README.md#settings) documents each one. An invalid value is ignored and the default applies. +The plugin reads its options once at startup from its entry in `opencode.jsonc`: `defaultMode`, `keepalive.enabled`, `keepalive.maxPings`, `keepalive.minContextTokens`, `savings`, `modelsDevPrices`, `openaiCompatible`, `cacheProfiles`, `debug`. [The README](../README.md#settings) documents each one. An invalid value is ignored and the default applies. ### The `/cache-manager` command @@ -117,9 +115,9 @@ A `patch` may hold `mode` (`5m`, `1h`, `hybrid`), `keepalive`, `maxPings` (0 to ### Requests to model providers -The plugin sends nothing to a provider itself. It changes requests OpenCode is about to send, and only for a model a profile manages: `cache_control` TTLs and breakpoints and the `anthropic-beta` header for Claude, `prompt_cache_breakpoint` and `prompt_cache_options` for GPT-5.6+. [SUPPORTED_PROVIDERS.md](SUPPORTED_PROVIDERS.md) lists what is sent on each endpoint. A keepalive ping is a request OpenCode builds from the session's context and the prompt `Do not perform any work and do not use tools. Reply with exactly: OK`. +OpenCode sends every provider request. The plugin changes a request before it leaves, and only for a model a profile manages: `cache_control` TTLs and breakpoints and the `anthropic-beta` header for Claude, `prompt_cache_breakpoint` and `prompt_cache_options` for GPT-5.6+. [SUPPORTED_PROVIDERS.md](SUPPORTED_PROVIDERS.md) lists what is sent on each endpoint. A keepalive ping is a request OpenCode builds from the session's context and the prompt `Do not perform any work and do not use tools. Reply with exactly: OK`. -From a response it reads the usage block, the stop or finish reason, and the model and provider names. It writes nothing back into the response. +From a response it reads the usage block, the stop or finish reason, and the model and provider names, and it leaves the response as it was. ### Plugin storage @@ -136,7 +134,7 @@ From a response it reads the usage block, the stop or finish reason, and the mod ### models.dev -With `modelsDevPrices` on, one `GET https://models.dev/api.json` at most once a day, with a 10 second timeout. The request carries no data about the user. Only prices are kept from the response. +With `modelsDevPrices` on, the plugin sends one `GET https://models.dev/api.json` at most once a day, with a 10-second timeout. The request carries no data about the user. Only prices are kept from the response. ### The debug log @@ -144,4 +142,4 @@ With `debug` on, the plugin appends one JSON object per line to a local file cre ### Console -One warning line, `[opencode-cache-manager] cache rewrite failed, request sent unchanged:`, when a rewrite throws. +The plugin writes one warning line, `[opencode-cache-manager] cache rewrite failed, request sent unchanged:`, when a rewrite throws. diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 9b325ea..ded36d8 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -85,9 +85,11 @@ A failure prints a seed, a path and the smallest failing input. Reproduce it by The package has no runtime dependencies of its own. What it imports at runtime (`@opencode/plugin`, `@opentui/core`, `@opentui/solid`, `solid-js`) is declared under `peerDependencies` and provided by OpenCode. Everything under `devDependencies` is tooling: the type checker, linter, formatter, test libraries, and pinned copies of the peers to build and test against. -- **Selecting.** A dependency is added or changed only in a pull request, where it is reviewed like any other change. -- **Obtaining.** Dependencies come from the npm registry through `bun install`. `package.json` declares them and `bun.lock` pins the exact versions and integrity hashes of the whole tree; both are committed. CI installs with `--frozen-lockfile --ignore-scripts`, so it uses exactly the locked versions and runs no package's install script. GitHub Actions are pinned to a commit SHA. -- **Tracking.** Dependabot opens weekly pull requests for npm packages and GitHub Actions (`.github/dependabot.yml`) and raises security updates as advisories appear. `overrides` in `package.json` holds a transitive dependency at a patched version when its parent hasn't moved yet. +A dependency is added or changed only in a pull request, where it is reviewed like any other change. + +Dependencies come from the npm registry through `bun install`. `package.json` declares them and `bun.lock` pins the exact versions and integrity hashes of the whole tree; both are committed. CI installs with `--frozen-lockfile --ignore-scripts`, so it uses exactly the locked versions and runs no package's install script. GitHub Actions are pinned to a commit SHA. + +Dependabot tracks updates: it opens weekly pull requests for npm packages and GitHub Actions (`.github/dependabot.yml`) and raises security updates as advisories appear. `overrides` in `package.json` holds a transitive dependency at a patched version when its parent hasn't moved yet. ## Layout diff --git a/docs/SECURITY_ASSESSMENT.md b/docs/SECURITY_ASSESSMENT.md index ee87e99..6e5c897 100644 --- a/docs/SECURITY_ASSESSMENT.md +++ b/docs/SECURITY_ASSESSMENT.md @@ -1,16 +1,16 @@ # Security assessment -This is the project's own assessment of what could go wrong in opencode-cache-manager, which problems are most likely or most costly, and what the code does about each. It was last reviewed for version 0.8.3. A change to a hook, a parser, the keepalive rules, storage or the release pipeline should update it. [ARCHITECTURE.md](ARCHITECTURE.md) describes the actors and interfaces named here. +This page lists what could go wrong in opencode-cache-manager, how likely and how costly each problem is, and what the code does about it. It was last reviewed for version 0.8.3. A change to a hook, a parser, the keepalive rules, storage or the release pipeline should update it. [ARCHITECTURE.md](ARCHITECTURE.md) describes the actors and interfaces named here. To report a vulnerability, see [SECURITY.md](../SECURITY.md). ## What is worth protecting -- **Credentials in transit.** Every model request carries the user's API key in a header. The plugin handles the request object before OpenCode sends it. -- **Prompt and response content.** The request body is the conversation; the response body is the model's reply. -- **The user's money.** A keepalive ping is a paid provider request, and a rewrite decides what the provider charges for a cache write. -- **The user's turn.** A request the provider rejects fails the user's prompt. -- **The published package.** A tampered release would run inside every user's OpenCode. +- The user's API key. Every model request carries it in a header, and the plugin handles the request object before OpenCode sends it. +- The conversation in each request body and the model's reply in each response body. +- The user's money. A keepalive ping is a paid provider request, and a rewrite decides what the provider charges for a cache write. +- The user's turn, because a request the provider rejects fails their prompt. +- The published package, because a tampered release would run inside every user's OpenCode. ## Trust boundaries @@ -72,7 +72,7 @@ What remains: a proxy that puts a key in the URL path will have it in the log, a Impact: low. Likelihood: low. -Prices only affect the dollar figures in the sidebar, never a request. A price must be a finite number with a positive input cost, and a model whose listings disagree is not priced. +A price is used only for the dollar figures in the sidebar and has no effect on any request. A price must be a finite number with a positive input cost, and a model whose listings disagree is not priced. ### 8. The release is tampered with