opencode/packages/plugin
Luke Parker 391d5d369c fix(core): make the experimental.rules hook deny-only
Review finding M1. An experimental.rules hook could rewrite the whole
ruleset, so one appended allow outranked every configured deny for
calls and listing. Agents and sessions showed nothing. The rule
objects were also the agent state's own, so an edit in place changed
the agent for every session.

The new shape is { sessionID, agent, rules, session, deny }.
- rules (agent then session) and session are fresh copies of each
  rule. Core ignores them after the hooks run.
- Core reads only event.deny and decodes it with
  Schema.Array(Struct({ action: String, resource: String })). Other
  fields of an entry, such as effect, are dropped, so each entry is a
  deny.
- Core returns [...agent, ...session, ...denies], in the order the
  hooks pushed them. Nothing a hook writes can allow, remove or
  reorder a rule.

Before this, a configured deny was final: evaluateInput returned deny
before any hook ran. That holds again. A hook can only add denies,
and they are checked in the same place.

A deny entry that is not two strings dies with 'A permission
"experimental.rules" hook added an invalid deny: ...'. The request
or step fails closed instead of running without the hook's denies.

L2: the TSDoc says that the hook runs for every permission check and
every step, must be quick, and must not request permissions itself.
A request would run the hook again without end. The evaluate hook
next to it has no re-entrancy guard, so this hook documents the
constraint in the same way.

Tests (permission.test.ts):
- A hook pushes an allow, edits rules in place, changes the arrays
  and adds an entry with effect "allow". None of this reaches the
  rules or the agent state, and configured denies and asks still
  decide.
- Two hooks' denies are appended in order.
- A hook's deny refuses a request before any evaluate hook runs.
- A malformed entry fails closed and names the hook.
2026-11-17 08:51:27 +10:00
..
script feat(plugin): add OpenCode Desktop GUI plugins (#55246) 2026-10-27 10:54:50 +10:00
src fix(core): make the experimental.rules hook deny-only 2026-11-17 08:51:27 +10:00
test feat(plugin): add OpenCode Desktop GUI plugins (#55246) 2026-10-27 10:54:50 +10:00
.gitignore wip: plugins 2025-08-02 18:50:19 -04:00
AGENTS.md feat(plugin): add OpenCode Desktop GUI plugins (#55246) 2026-10-27 10:54:50 +10:00
package.json release: v2.3.0 (#63719) 2026-11-13 09:04:03 +00:00
README.md chore: upgrade Effect to 4.0.1 (#54198) 2026-10-10 00:55:24 -07:00
tsconfig.build.json feat(plugin): add OpenCode Desktop GUI plugins (#55246) 2026-10-27 10:54:50 +10:00
tsconfig.json chore: upgrade typecheck to TypeScript 7.0.2 (#56300) 2026-10-17 13:26:46 -07:00

@opencode/plugin

Authoring interfaces and runtime loader support for OpenCode V2 plugins:

  • @opencode/plugin — Promise plugin API
  • @opencode/plugin/effect — Effect plugin API
  • @opencode/plugin/rpc — portable RPC contract definitions
  • @opencode/plugin/tui — terminal UI plugin API

Packaging And Runtime effect

When the OpenCode CLI loads server or TUI plugins, it resolves imports of effect, exported effect/* subpaths, and @opencode/plugin entrypoints (including imports from dependencies inside a plugin's node_modules) to the host's runtime module instances so fibers, loggers, and Schema parsers share one copy.

  • Declare "effect": "^4.0.0" as a peerDependency (and devDependency for local type-checking and testing) rather than a bundled runtime dependency.
  • Do not bundle effect into published plugin files; if you build with a bundler, keep effect and effect/* external. Two copies of effect do not share fiber, logger, or Schema internals.
  • Plugins and their node_modules dependencies always receive OpenCode's host effect instance. Use effect APIs and module paths compatible with the OpenCode release you target; dependencies built on another effect major (such as Effect 3) are not supported.
  • Only public effect subpaths are provided. A plugin that imports one of Effect's private internal modules fails to load with an error naming the path.
  • The compiled OpenCode binary does not include the Scalar and Swagger UI assets used by Effect's HTTP API docs pages; serving those pages from a plugin shows a notice instead.