mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
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.
|
||
|---|---|---|
| .. | ||
| script | ||
| src | ||
| test | ||
| .gitignore | ||
| AGENTS.md | ||
| package.json | ||
| README.md | ||
| tsconfig.build.json | ||
| tsconfig.json | ||
@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 apeerDependency(anddevDependencyfor local type-checking and testing) rather than a bundled runtime dependency. - Do not bundle
effectinto published plugin files; if you build with a bundler, keepeffectandeffect/*external. Two copies ofeffectdo not share fiber, logger, orSchemainternals. - Plugins and their
node_modulesdependencies always receive OpenCode's hosteffectinstance. UseeffectAPIs and module paths compatible with the OpenCode release you target; dependencies built on anothereffectmajor (such as Effect 3) are not supported. - Only public
effectsubpaths are provided. A plugin that imports one of Effect's privateinternalmodules 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.