Repository navigation
fix(opencode): ask before PowerContext writes under default permissions - #2534
Conversation
OpenCode's built-in agents allow every permission their defaults do not name. The plugin's request for the `powercontext` permission before a durable mutation was therefore allowed without asking, although the docs say OpenCode asks for confirmation. The plugin's config hook now sets that permission to `ask` ahead of the user's own rules. OpenCode applies the last matching rule, so a configured rule that matches it, including `*`, still decides.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed commit 837bc83. No correctness findings in the changed paths. Real OpenCode 1.18.21 with a real PowerContext Server confirms that default writes wait for permission, rejection leaves no Memory write, approval permits persistence and retrieval, and explicit user rules retain precedence. The base bundle writes without prompting in the same control. No database tables or public interfaces were added.
CI remains red: tests (3.11, unit) fails in the unchanged test_blocked_recheck_errors_preserve_spacing_diagnostics_and_explicit_wakes[deadline], and opencode-package was skipped. I have not attributed that failure to this patch. Please resolve or rerun the failed CI and obtain the package check before merging; this approval covers the reviewed change, not CI readiness.
A user rule for some PowerContext operations disabled the plugin's ask default, so every other durable write ran without confirmation. The default now uses the `powercontex?` key, which OpenCode matches only against the `powercontext` permission, and always comes before the user's rules, so those rules still decide the operations they match. The docs explain that `opencode run` stops at the first PowerContext write, recommend a scoped allow rule for non-interactive runs, and say that "Allow always" approves only the current call.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
hidb4ai
left a comment
There was a problem hiding this comment.
One reproducible permission fallback gap remains in the updated hook: a valid partial wildcard rule lets an uncovered write run without confirmation. See the inline reproduction.
| // The SDK's Config type predates permissions keyed by name. | ||
| const settings = config as { permission?: string | Record<string, unknown> } | ||
| const permission = settings.permission | ||
| if (typeof permission === 'string' || (permission && DEFAULT_PERMISSION_RULE in permission)) return |
There was a problem hiding this comment.
[P2] Preserve the fallback when its wildcard key contains user rules
The presence check also matches a user-owned per-operation rule, not just the scalar fallback installed by this hook. With {"permission":{"powercontex?":{"commit_handoff":"allow"}}}, it returns before installing an ask fallback. Using the exact bundle on real OpenCode 1.18.21 with a real Server, pc_remember then falls through to the built-in * = allow, emits no permission request, and persists the Memory even though no user rule covers remember_memory. Please retain ask for unmatched operations when this key is already configured, while preserving the user's matching rules.
There was a problem hiding this comment.
Fixed in 9bdb6d1. When the configuration already uses powercontex?, the hook now adds its ask rule under the next key of the same form (powerconte?t, then powercont?xt, …), still ahead of every user rule. With {"permission": {"powercontex?": {"commit_handoff": "allow"}}}, commit_handoff stays allowed and every other operation asks.
Verified with the exact bundle on OpenCode 1.19.5 against a real Server: under that configuration, pc_remember now raises a powercontext request for remember_memory, a rejected request stores nothing, and an approved one stores the Memory. c57a603's bundle fails the same case without a request. GET /agent lists powerconte?t:*=ask before powercontex?:commit_handoff=allow for build, plan, and general. plugin.spec.ts covers this configuration and a repeated run of the hook. I did not run 1.18.21.
A user rule under the `powercontex?` key made the config hook skip its ask default, so a write that no user rule covered ran without confirmation. The default now takes the first key of the same form that the configuration does not use, such as `powerconte?t`, and still comes before every user rule.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
hidb4ai
left a comment
There was a problem hiding this comment.
The reported wildcard-key fallback gap is fixed in 9bdb6d1. Replayed the original case on real OpenCode 1.18.21 with a real PowerContext Server: it now asks, rejection writes nothing, and one-time approval persists a searchable Memory. Consecutive fallback-key collisions also retain confirmation, and explicit user rules keep their precedence. No new database tables or public interfaces.
Which issue or RFC does this PR close?
No tracking issue. The OpenCode service-chain E2E in #2533 found this defect.
Rationale for this change
The OpenCode integration docs say "OpenCode asks for confirmation before a durable mutation". The plugin requests the
powercontextpermission before each one, but under OpenCode's default configuration the request is allowed without asking.OpenCode's built-in agents start from
"*": "allow". Beyond that rule they name onlydoom_loop,external_directory,question,plan_enter,plan_exit, and somereadpatterns, sopowercontextfalls under the catch-allallow. As a result,pc_rememberand the other durablepc_*operations ran with no prompt.The default belongs in the plugin rather than in a config file written by
powercontext setup opencode. That way it covers every way the bundle is installed and edits no user file.What changes are included in this PR?
confighook. The plugin's newconfighook adds anaskrule for itspowercontextpermission ahead of every permission rule the user configures.powercontex?. OpenCode matches permission names against keys as wildcards, and?matches one character, so this key matches onlypowercontext.powercontextkey the user writes, the default can sit ahead of that rule too.powercontex?, the rule takes the next key of the same form, such aspowerconte?t. A user rule underpowercontex?keeps its place and decides only the operations it matches.permissionapplies to every permission, so the hook leaves it unchanged. OpenCode 1.19.5 turns it into{"*": value}before plugins run.GET /config).PERMISSIONconstant.plugin.spec.tscovers the hook's output, including rules the user writes for some PowerContext operations and a user rule under the default's own key.powercontextpermission, and a configured rule that matches it takes precedence.opencode run, OpenCode rejects each permission request and ends the turn. For non-interactive runs, the pages recommend allowing the operations the run needs rather than approving every permission.lib/index.jsis rebuilt.Are there any user-facing changes?
Yes.
opencode run: a run now stops at its first PowerContext write. OpenCode rejects the request and ends the turn; before this change the write ran without asking."permission": {"powercontext": "allow"}.--autoalso approves them, but it approves every other permission that is not denied as well."*": "allow".opencode run --dangerously-skip-permissions.alwayspatterns. This PR documents that limit. Making the answer cover later calls of the same operation would change what one approval grants, so it is left as a separate decision.How was this change tested?
pnpm test(111 passed),pnpm run typecheckandpnpm run buildinintegrations/opencode/plugins/powercontext. These are themake opencode-teststeps, with dependencies installed offline. A fresh build matches the committed bundle."permission": {"powercontext": "ask"}removed.remember_memory:{"powercontext": {"commit_handoff": "allow"}}in the configOPENCODE_PERMISSION{"bash": "ask"}{"powercontex?": {"commit_handoff": "allow"}}{"powercontext": {"remember_memory": "allow"}}, the docs example{"powercontext": "allow"}{"*": "allow"}{"power*": "allow", "powercontext": {"commit_handoff": "ask"}}"agent": {"build": {"permission": {"powercontext": "allow"}}}{"powercontext": {"commit_handoff": "allow"}, "*": "deny", "bash": "ask"},GET /agentlistspowercontex?after OpenCode's defaults and ahead of those three rules, in their order, for thebuild,plan, andgeneralagents.GET /configincludes it among the configured permissions. Under{"powercontex?": {"commit_handoff": "allow"}}, the agents listpowerconte?tahead of that rule.make check: passed.pnpm lint,pnpm test, andpnpm build: passed.tests/test_integration_guidance_evaluation.py::test_native_adapter_handoff_uses_real_request_mapping_and_response_envelopes[opencode]: passed.Merge order with #2533
"permission": {"powercontext": "ask"}fromtests/e2e/test_opencode_service_chain.py, so that the E2E asserts the plugin's default. This PR does not touch that file. Locally, the case passes with this bundle and fails with master's.AI usage statement
This PR was prepared with Claude Code (Claude Opus 5.5). It inspected OpenCode 1.19.5's permission defaults, rule matching, and plugin config handling. It wrote the change, test, and docs, ran the checks, the real-host verification, and the reviews, and drafted this description. I reviewed the changes and the results.