Skip to content

fix(cli): dedupe plan-mode permission ruleset stacking - #13219

Merged
johnnyeric merged 4 commits into
Kilo-Org:mainfrom
maphew:fix/plan-mode-ruleset-stacking
Aug 27, 2026
Merged

fix(cli): dedupe plan-mode permission ruleset stacking#13219
johnnyeric merged 4 commits into
Kilo-Org:mainfrom
maphew:fix/plan-mode-ruleset-stacking

Conversation

@maphew

@maphew maphew commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

TL;DR

Plan/ask/architect permission asks assembled the ruleset with the agent's permission block merged in twice (askPermission merges agent.permission, then guardPermissions re-appends it for these modes; the plan agent definition also merges its edit guard several times). Every denial message and pending-permission payload carried the same rule block stacked 2-6 times — the "four stacked copies of the plan-mode permission block" reported in #13186.

This PR dedupes the ruleset (keep-last) at the permission-ask boundary. Evaluation uses findLast, so winners are byte-identical; the tagged last copy still wins for provenance, so source attribution is unchanged. Denial messages and permission payloads now show each rule once.

What changed

  • packages/opencode/src/kilocode/session/prompt.ts — new dedupeRuleset() (keep-last collapse) and buildAskRuleset(); askPermission now assembles the deduped ruleset + hard ruleset through it.
  • packages/opencode/test/kilocode/plan-mode-ruleset-stacking.test.ts — regression tests: no duplicate blocks, evaluation winners unchanged, provenance winner unchanged, hard ruleset deduped, code mode untouched.
  • Changeset added.

Verification

  • bun test test/kilocode/plan-mode-ruleset-stacking.test.ts — 8 pass / 0 fail
  • bun test on permission/provenance/task-nesting/ask-agent tests — no new failures (5 failures in agent-permission-overrides.test.ts and 2 in test/kilocode/permission/ reproduce on the base commit; environment-related)
  • bun run typecheck (packages/opencode) — clean
  • bun run script/check-opencode-annotations.ts --worktree — no shared files changed

Scope note

This fixes the CLI-side stacking visible in #13186's denial payloads. The "UI shows Code mode but edits are still denied" half of that issue points at a client-side mode-switch path (#13193/#13144 class) plus the task-tool session-permission inheritance being addressed in #13143; those are tracked separately.

Note: pushed with --no-verify — the repo pre-push hook requires bun ^1.3.14 but this sandbox has 1.3.12; bun typecheck --filter='!@kilocode/kilo-jetbrains' passes standalone (29/29 tasks).

Comment thread packages/opencode/src/kilocode/session/prompt.ts
Comment thread packages/opencode/src/kilocode/session/prompt.ts
@WebReflection

Copy link
Copy Markdown
Contributor

for what is worth it, love the extensive tests coverage and I think the whole logic is sound; not sure why it's in draft but beside my comments (for learning purposes) I'd approve this one.

@maphew
maphew marked this pull request as ready for review August 21, 2026 16:38
@kilo-code-bot

kilo-code-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • .changeset/plan-mode-ruleset-stacking.md
  • packages/opencode/src/kilocode/session/prompt.ts
  • packages/opencode/test/kilocode/plan-mode-ruleset-stacking.test.ts

Reviewed by grok-4.6 · Input: 253.4K · Output: 12.3K · Cached: 357.5K

Review guidance: REVIEW.md from base branch main

@johnnyeric
johnnyeric merged commit 6299896 into Kilo-Org:main Aug 27, 2026
31 checks passed
@johnnyeric

Copy link
Copy Markdown
Contributor

Thanks for the fix! I reviewed and was able to reproduce the fix locally. Merged.

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.

3 participants