Skip to content

feat(agent): share plan permission set with review subagent - #165

Merged
mdev34-lab merged 4 commits into
devfrom
review-plan-permissions
Sep 27, 2026
Merged

mdev34-lab merged 4 commits into
devfrom
review-plan-permissions

Conversation

@mdev34-lab

Copy link
Copy Markdown
Owner

Issue for this PR

Closes #164

Type of change

  • New feature

What does this PR do?

The Review subagent was deny-by-default with a bespoke readonly overlay, so it could not run commands to reproduce or verify runtime behavior. Plan already has the intended boundary (inspection plus non-destructive execution including bash), so per #164 the plan set is now the single source of truth:

  • packages/opencode/src/agent/agent.ts: the plan permission overlay is extracted into one shared planPermissions const used verbatim by both plan and review. Equivalence holds by construction — no divergent review-specific policy. Edit denial, the general-subagent task denial, and user-config override order are unchanged for both.
  • Review prompt (src/agent/prompt/review.txt): the structurally-false read-only section now teaches verify-but-do-not-modify (bash for reproduction/verification, read-only commands preferred, never modify the tree), and the tests bullet tells the reviewer to run focused checks itself instead of naming commands for the caller. The no-subagent-dispatch rule, envelope contract, and finish gating are untouched.
  • Routing labels calling review read-only (session/prompt/review-loop.txt, session/prompt/gpt.txt) updated to match; the review agent roster description now states the plan-equivalent inspection capability.

Why this shape: bash allow flows from the shared defaults allow-all exactly as it does for plan today, and edit/write/apply_patch stay gated through the edit permission at the runtime layer (Permission.disabled maps them onto edit), identically for both agents. Session-level child denies (todowrite) and the review finish envelope gate are unaffected.

How did you verify your code works?

  • New equivalence test (test/agent/agent.test.ts): review and plan evaluate identically across read/grep/glob/list/webfetch/bash/question/todowrite; bash allow pinned for both; edit deny and task general-deny/explore-allow pinned; tool-visibility sets asserted equal; prompt asserts the do-not-modify rule.
  • Delegation e2e (test/session/review-delegation.test.ts): the live review request toolset now contains finish, read, bash, and task (verified against a real request, not assumed). Edit denial stays pinned at the permission seam per above.
  • Suites: agent (49) + bypass + finish + task + review-loop: 134 pass, 0 fail. Delegation: 4 pass, 1 fail — the single failure (retry-request count) reproduces identically on clean dev HEAD in this environment and is unrelated to this change.
  • bun typecheck (opencode): clean; pre-push bun turbo typecheck: 17 successful.
  • oxlint on touched files: 0 errors, no new warnings (remaining warnings pre-exist); added lines are prettier-clean (whole-file --check drift pre-exists on dev HEAD, left untouched).
  • git diff inspected: 4 production files, 2 test files, nothing else.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copy link
Copy Markdown
Owner Author

Automation re-review found one concrete defect before merge:

packages/opencode/src/agent/agent.ts still gives Review the Plan-specific edit exceptions for .opencode/plans/*.md and the global plans path. That conflicts with review.txt, which says Review must not edit, write, create, or delete files. The existing test only checks generic edit, so it does not catch path-sensitive allows.

Required follow-up: keep Plan's exceptions unchanged, make Review's edit rule deny all paths, and add a regression assertion for a plan path plus a normal path. Current CI for b7ba77857ca78597d40a9ed2d0138bab30939fb7: test PASS, typecheck PASS, nix-eval still QUEUED.

@mdev34-lab mdev34-lab left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Re-review of head b7ba77857ca78597d40a9ed2d0138bab30939fb7.

Finding: packages/opencode/src/agent/agent.ts:237-248 gives Review the same path-specific edit exceptions as Plan (.opencode/plans/*.md and the global plans path), while packages/opencode/src/agent/prompt/review.txt says Review must not edit, write, create, or delete any files. The generic test evalPerm(review, "edit") === "deny" does not catch those path-sensitive allows.

Required fix: Keep Review's permission block independent, but remove the Plan-only edit exceptions from Review so every edit path remains denied. Add a regression assertion for a path such as .opencode/plans/review.md.

Other reviewed areas looked consistent. CI/status for the current head is still pending with no reported checks yet.

@mdev34-lab

Copy link
Copy Markdown
Owner Author

@kilocode-bot Get this PR looking good (perform the fixes). Then I'll merge manually.

Review inherited Plan's plan-path edit exceptions (.opencode/plans/*.md
and the global plans path), which contradicts review.txt's directive that
Review must not edit, write, create, or delete files. Plan's edit
exceptions are unchanged; Review now denies edits on every path.

Tests pin a plan path and a normal path as denied for Review while Plan
still allows its plan-path edits.
@kilo-code-bot

kilo-code-bot Bot commented Sep 27, 2026

Copy link
Copy Markdown

Cloud Agent result for mdev34-lab/alphacode (code, agent_cf07ded0-f727-4897-8f1e-c02976ab1e95, completed):

Done. Pushed to the existing PR branch review-plan-permissions (fast-forward, new commit d9f54d48d, no new PR).

Changes (packages/opencode):

  • src/agent/agent.ts:244-246 — Dropped Review's two Plan-path edit exceptions so its rule is edit: { "*": "deny" } (deny all paths). Plan's planPermissions (lines 143-157) is untouched. The review roster description (line 250) already states "plan-equivalent inspection permissions, including bash for reproducing and verifying runtime behavior", satisfying that requirement.
  • test/agent/agent.test.ts — Renamed the test to reflect the edit divergence, fixed the pre-existing Permission.disabled equality (which only held because Review wrongly mirrored Plan's edit exceptions), and added regression assertions: Review denies edit on .opencode/plans/review.md and on a normal path (packages/opencode/src/index.ts), while Plan still allows .opencode/plans/foo.md.

Verification: bun run typecheck (tsc --noEmit) passed; the focused bun test for both the Review and Plan edit cases pass (Review test: 1 pass / 24 expects; Plan test: 1 pass).

Note: this sandbox is missing the optional @opentui/solid package (not a workspace package), so bun test's configured [test] preload can't load. I ran the affected tests by temporarily clearing that preload (restored before commit) and unsetting the sandbox's injected OPENCODE_CONFIG_CONTENT (which was broadly granting edit and made every permission test report allow). Neither change is part of the fix — the working tree commits only agent.ts and agent.test.ts.

@kilo-code-bot

kilo-code-bot Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • packages/opencode/src/agent/agent.ts - reviewed; prior edit-exception defect fixed
  • packages/opencode/src/agent/prompt/review.txt - reviewed; verify-but-do-not-modify guidance consistent
  • packages/opencode/src/session/prompt/gpt.txt - reviewed; routing label updated
  • packages/opencode/src/session/prompt/review-loop.txt - reviewed; routing label updated
  • packages/opencode/test/agent/agent.test.ts - reviewed; regression assertions added
  • packages/opencode/test/session/review-delegation.test.ts - reviewed; toolset assertions updated

Reviewed by free · Input: 0 · Output: 0 · Cached: 0

@mdev34-lab

Copy link
Copy Markdown
Owner Author

LGTM. Merging

@mdev34-lab
mdev34-lab merged commit e16c46d into dev Sep 27, 2026
6 of 7 checks passed
mdev34-lab added a commit that referenced this pull request Sep 27, 2026
Issue #113. The generic `review` subagent is now a request rather than an
identity: the task tool resolves which reviewer actually runs from the parent
agent, so Work dispatches work-review, Code dispatches code-review, and every
other parent keeps the generic reviewer.

All three reviewers share one `reviewPermissions` block, extracted from the
existing `review` definition, so they keep the plan-equivalent inspection
permissions including bash for reproducing and verifying runtime behaviour,
with edit denial enforced at the permission seam. The split is domain focus
only: the reviewers are identical in capability and in the standard they apply.

The report gate requiring every reviewer to deliver a parseable
<alphacode-review> envelope is name-based, so reviewer names live in one module
(REVIEW_AGENTS for the gate, REVIEW_ROUTING for dispatch) rather than being
compared inline at each of the four call sites. A reviewer outside REVIEW_AGENTS
still completes without a verdict, which centralising reduces but does not
remove.

Parent-agent resolution reads the newest user message. MessageV2.page returns
oldest-first, so a session whose agent changed mid-session would otherwise be
routed by its first agent; the resolution is shared with the background
notification path, which has the same requirement. The task permission prompt
stays keyed on the requested subagent_type so existing grants and deny rules
keep matching, since dispatching a different reviewer is a runtime detail.

Stale read-only wording that #165 made false is corrected, and the two new
reviewer prompts no longer claim they cannot run commands.
mdev34-lab added a commit that referenced this pull request Sep 27, 2026
Issue #113. The generic `review` subagent becomes a request rather than an
identity: the task tool resolves which reviewer runs from the parent agent, so
`work` dispatches work-review, `code` dispatches code-review, and any other
parent keeps the existing generic `review`. Every routing target is itself a
member of the reviewer set, so a routed request still passes the report gate.

All three reviewers share one `reviewPermissions` block, extracted from the
existing `review` definition, so they keep the plan-equivalent inspection
permissions including `bash` for reproducing and verifying runtime behaviour,
with edit denial enforced at the permission seam. The split is domain focus
only: identical capability, identical standard, no description implying a
weaker bar.

The report gate is keyed on agent name, and a name missing from the set
completes a review without a verdict rather than failing loudly. The names
therefore live in one module, `REVIEW_AGENTS` for the gate and `REVIEW_ROUTING`
for dispatch, with a `ReviewAgent` union making "a routed target is itself a
reviewer" a compile error. Centralising reduces the failure mode; it does not
remove it, and the module says so.

Parent-agent resolution reads the session row, then the newest user message
naming an agent, because a session row's `agent` is null for the default
session. `MessageV2.page` returns messages oldest-first, so this uses
`findLast`; reading the oldest message would invert the routing in exactly the
mid-session agent switch it exists to handle. `ctx.agent` is deliberately not
consulted, because on the subtask path it is the child's agent. The read is
memoized and yielded only when a review routes or a background result is
delivered, so other delegations never pay for it.

An unreadable parent fails the dispatch explicitly instead of resolving to no
agent and silently falling back to the generic reviewer with the wrong prompt
and permissions. The catch is narrowed to `NotFound` so any other cause stays a
defect rather than being reinterpreted.

The task permission prompt is keyed on the requested `subagent_type` together
with the resolved name, because stored always-allow grants and user config
rules are written against either, and a deny on one name must not be bypassed
by an allow on the other.

Stale read-only wording that #165 made false is corrected, and the two new
reviewer prompts no longer claim they cannot run commands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(agent): give Review subagent Bash with Plan-equivalent permissions

1 participant