Skip to content

feat(runtime): approval_mode.set RPC for GUI clients - #24

Open
kousw wants to merge 1 commit into
mainfrom
feat/approval-mode-set
Open

kousw wants to merge 1 commit into
mainfrom
feat/approval-mode-set

Conversation

@kousw

@kousw kousw commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Summary

GUI clients (the GPUI desktop composer's approval-mode chip) need to change the approval mode for the current project. Until now the resolved mode was read-only over RPC (permissions.list). This PR adds a GUI-facing management RPC, following the pattern of the other 5.16+ requests. It is a user action over JSON-RPC and is never exposed as a model tool.

  • Protocol: approval_mode.set { value: "minimal" | "trusted" | "full-access", scope: "project" | "default" } → { scope, value, path, changed, approval_mode: { value, source }, applies: "next_run" }, behind the new server_capabilities.supports_approval_mode_set.
  • Runtime (packages/runtime/src/rpc/approval-mode.ts):
    • Writes one projects.json entry through ProjectsPolicyStore (0600, atomic) and keeps the other entries. The project scope uses the same workspace key the agent factory resolves.
    • Overrides: if --approval-mode or CODELIA_APPROVAL_MODE decides the mode (or holds an invalid value), the request is rejected with -32602 and error.data = { source, value }, and nothing is written. The runtime never reports a write as applied when it cannot take effect.
    • A policy file that cannot be parsed is never overwritten (-32000, and the file contents are not echoed).
    • The write only runs while idle (-32001 during a run) and is rechecked under the run admission lock. A write that changes the file invalidates the cached agent, so the next run rebuilds the sandbox context and PermissionService with the new mode.
    • The result reports the mode resolved after the write, so a default write that is still shadowed by a project entry shows up (source: "project").
    • The capability is advertised only for runtime-owned config with a local runtime. Other hosts always run minimal.
  • Refactors: resolveApprovalModeOverride() and writeApprovalModePolicy() in permissions/approval-mode.ts, and isLocalRuntimeEnabled() in environment.ts, which the agent factory now uses too. Resolution order is unchanged.
  • Specs: ui-protocol.md §4.2 and §5.18, approval-mode.md §5.2 and the new §5.3, plus the AGENTS.md notes.

The desktop app (crates/desktop / crates/agent-host) is not touched and will use this in a follow-up.

Test plan

  • bun test packages/runtime/tests: 781 pass, 13 skip, 0 fail. New file: approval-mode-rpc.test.ts, which covers the capability, project/default writes with 0600 mode, no-op writes, shadowing, CLI/env/invalid overrides, bad params, busy runs, admission lock, a broken store, and host config.
  • bun test packages/protocol/tests
  • bun run typecheck, bun run lint (exit 0, warnings only, none in the changed files)
  • bun run fmt. On main it also reformats an unrelated line in packages/core/src/agent/agent.ts, which is left out of this PR.

🤖 Generated with Claude Code

Add a user-action JSON-RPC request that sets the approval mode of the
current project (or the store-wide default) in projects.json, behind the
new supports_approval_mode_set capability.

- Writes through ProjectsPolicyStore (0600, atomic); other entries kept.
- Refused with -32602 and error.data.source when --approval-mode or
  CODELIA_APPROVAL_MODE decides the mode, so a change that cannot take
  effect is never reported as applied.
- An unparseable policy file is never overwritten.
- Idle-only under the run admission lock; a changed file drops the
  cached agent so the next run rebuilds sandbox/PermissionService.
- Result reports the post-write resolved mode (a default write shadowed
  by a project entry stays visible).

Specs: ui-protocol 4.2/5.18, approval-mode 5.2/5.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant