Skip to content

fix(opencode): ask before PowerContext writes under default permissions - #2534

Merged
hidb4ai merged 3 commits into
oceanbase:masterfrom
Fengzdadi:fix/opencode-mutation-confirmation
Nov 11, 2026
Merged

hidb4ai merged 3 commits into
oceanbase:masterfrom
Fengzdadi:fix/opencode-mutation-confirmation

Conversation

@Fengzdadi

@Fengzdadi Fengzdadi commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

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 powercontext permission 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 only doom_loop, external_directory, question, plan_enter, plan_exit, and some read patterns, so powercontext falls under the catch-all allow. As a result, pc_remember and the other durable pc_* 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?

  • New config hook. The plugin's new config hook adds an ask rule for its powercontext permission ahead of every permission rule the user configures.
    • OpenCode applies the last matching rule, so each user rule still decides the operations it matches. Every other operation asks.
    • The rule's key is powercontex?. OpenCode matches permission names against keys as wildcards, and ? matches one character, so this key matches only powercontext.
    • Because the key differs from a powercontext key the user writes, the default can sit ahead of that rule too.
    • If the configuration already uses powercontex?, the rule takes the next key of the same form, such as powerconte?t. A user rule under powercontex? keeps its place and decides only the operations it matches.
    • A string permission applies to every permission, so the hook leaves it unchanged. OpenCode 1.19.5 turns it into {"*": value} before plugins run.
    • The added rule appears in OpenCode's resolved configuration (GET /config).
  • Shared constant. The hook and the tools' request use the same PERMISSION constant.
  • Unit test. plugin.spec.ts covers the hook's output, including rules the user writes for some PowerContext operations and a user rule under the default's own key.
  • Docs. The English and Chinese integration pages and the plugin README now say:
    • The confirmation is the powercontext permission, and a configured rule that matches it takes precedence.
    • Each request uses the operation as its pattern. An example shows a rule that saves memories without asking while other writes still ask.
    • "Allow always" approves only the current call.
    • In 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.
  • Bundle. lib/index.js is rebuilt.

Are there any user-facing changes?

Yes.

  • Default configuration: OpenCode now asks before each PowerContext write, as documented.
  • 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.
    • Non-interactive runs should allow the operations they need, for example with "permission": {"powercontext": "allow"}.
    • In OpenCode 1.19.5, --auto also approves them, but it approves every other permission that is not denied as well.
  • Existing rules: an operation that a user rule already covers keeps that rule's decision, for example under "*": "allow".
  • Evaluation: the OFF/ON evaluation is unaffected, because Harbor's OpenCode agent runs opencode run --dangerously-skip-permissions.
  • "Allow always": it still approves only the current call, because the plugin sends no always patterns. 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?

  • Plugin package checks: pnpm test (111 passed), pnpm run typecheck and pnpm run build in integrations/opencode/plugins/powercontext. These are the make opencode-test steps, with dependencies installed offline. A fresh build matches the committed bundle.
  • Real OpenCode: OpenCode 1.19.5 with this bundle against a real Server, running test(opencode): run OpenCode with the plugin against a real Server #2533's four cases with that PR's explicit "permission": {"powercontext": "ask"} removed.
    • With no permission configuration, 4 passed.
    • Control: with master's bundle, the permission case fails because OpenCode never asks.
    • The permission case still gets a request when no rule covers remember_memory:
      • {"powercontext": {"commit_handoff": "allow"}} in the config
      • the same rule set through OPENCODE_PERMISSION
      • {"bash": "ask"}
      • {"powercontex?": {"commit_handoff": "allow"}}
    • It gets no request when a user rule covers the operation:
      • {"powercontext": {"remember_memory": "allow"}}, the docs example
      • {"powercontext": "allow"}
      • {"*": "allow"}
      • {"power*": "allow", "powercontext": {"commit_handoff": "ask"}}
      • "agent": {"build": {"permission": {"powercontext": "allow"}}}
    • Under {"powercontext": {"commit_handoff": "allow"}, "*": "deny", "bash": "ask"}, GET /agent lists powercontex? after OpenCode's defaults and ahead of those three rules, in their order, for the build, plan, and general agents. GET /config includes it among the configured permissions. Under {"powercontex?": {"commit_handoff": "allow"}}, the agents list powerconte?t ahead of that rule.
  • Repository checks:
    • make check: passed.
    • Website pnpm lint, pnpm test, and pnpm build: passed.
    • tests/test_integration_guidance_evaluation.py::test_native_adapter_handoff_uses_real_request_mapping_and_response_envelopes[opencode]: passed.
  • Self-review: a review by Claude Code in the session and an independent review agent. Their findings are addressed here, except that "Allow always" keeps approving only the current call, as described above.
  • Not validated:
    • The TUI's permission dialog was not driven.
    • Only OpenCode 1.19.5 ran; the documented minimum is 1.18.21. If an older release ignores the hook's change, writes keep running without asking, as they do today.

Merge order with #2533

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.

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.
Copilot AI balanced review requested due to automatic review settings November 7, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copilot AI balanced review requested due to automatic review settings November 8, 2026 05:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AlexStocks AlexStocks added the 1.5.2 v1.5.2 release tracking label Nov 9, 2026

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 23:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hidb4ai
hidb4ai merged commit 45acb50 into oceanbase:master Nov 11, 2026
40 checks passed
hidb4ai pushed a commit that referenced this pull request Nov 12, 2026
…2600)

The OpenCode service-chain E2E configured `"permission": {"powercontext":
"ask"}` because OpenCode allowed PowerContext writes by default. Since
#2534 the plugin adds that rule itself, so the permission case now runs
with no permission configuration and fails if the default goes away.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.5.2 v1.5.2 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants