feat(rpc): impl pledge/set + pledge/clear (#228)#289
Merged
Destynova2 merged 1 commit intomainfrom Apr 26, 2026
Merged
Conversation
Replaces the `TODO(#228)` stubs in `server::rpc::pledge_ns::set` and `clear` with working in-memory mutations of `config.pledge`. Follows the P1/P2 pattern (atomic state swap, no disk persistence). Behaviour: - `set(profile, source)`: upserts a per-source rule, or replaces the default profile when source is None. Always flips `config.pledge.enabled = true`. - `clear()` drops all rules and resets `default_profile` to `full`. - Profile names validated against the built-in catalogue (read_only, execute, full, none). - Disk persistence out of scope per #228. Mutation logic split into pure sync helpers `apply_set` / `apply_clear` + `is_known_profile` for unit testability without an `AppState`. # Errors - `ERR_FORBIDDEN` when the caller is below `Admin`. - `INVALID_PARAMS_CODE` for empty profile, unknown profile, empty source. - `ERR_INTERNAL` when the registry rebuild or atomic swap fails. Tests: 11/11 passing. Implements P3 of the cli-forge-chef brigade plan for #228. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4 tasks
Destynova2
pushed a commit
that referenced
this pull request
Apr 26, 2026
…228) Replaces the two `TODO(#228)` stubs in `server::rpc::hit_ns::set_policy` and `resolve` with working implementations. Closes the last of the four RPC namespaces tracked by issue #228. set_policy(name, policy_json): - Deserializes the JSON payload into `PolicyConfig`. - The `name` argument always wins over `policy.name` (path-vs-payload). - Upserts in `config.policies` (replace if same name, append otherwise). - Compiles a fresh `PolicyMatcher` BEFORE the swap so a malformed glob is rejected without dirtying the running registry. - Atomic-swaps the ReloadableState; the matcher is rebuilt by `ReloadableState::new`, so the new policy is live before the RPC returns. resolve(context): - Builds a `RequestContext` field-by-field from a JSON object (the type has no Deserialize derive — it is constructed imperatively in the dispatch path; we keep parity here). - Missing fields fall back to permissive defaults so a partial probe ("just match on model") still works. - Calls `PolicyMatcher::evaluate` and projects the merged `ResolvedPolicy` to JSON for transport. Both functions are gated on `#[cfg(feature = "policies")]` with a graceful no-op fallback when the feature is off. # Errors - `ERR_FORBIDDEN` when the caller is below `Admin` (set_policy) or `Operator` (resolve). - `INVALID_PARAMS_CODE` for empty name, malformed policy JSON, malformed glob in match_rules, non-object context. - `ERR_INTERNAL` when the registry rebuild or atomic swap fails. Tests: 10/10 passing. Implements P4 of the cli-forge-chef brigade plan for #228. With #286 (P1), #287 (P2), #289 (P3), #228 closes when this lands. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
TODO(#228)stubs inserver::rpc::pledge_ns::setandclearwith working in-memory mutations ofconfig.pledge. Follows the P1 (config) / P2 (tools) pattern.Behaviour
set(profile, source):sourceisSome, upserts aPledgeRule { source, profile }(replaces any rule with the same source).sourceisNone, replacesconfig.pledge.default_profile.config.pledge.enabled = true.clear()drops all rules and resetsdefault_profiletofull.read_only,execute,full,none).Mutation logic split into pure sync helpers (
apply_set,apply_clear,is_known_profile) for unit testability without anAppState.Tests — 11/11 passing
set_default_profile_with_no_source,set_per_source_appends_rule,set_per_source_upserts_existing,set_rejects_unknown_profile,set_rejects_empty_profile,set_rejects_empty_source,clear_drops_rules_and_resets_default,require_role_denies_observer_for_admin_methods+ 3 pre-existingPledgeProfileInfotests.Test plan
cargo nextest run -E 'test(pledge_ns)' --features mcp— 11/11cargo fmt --all -- --checkcleancargo clippy --all-features -- -D warningscleanImplements P3 of the cli-forge-chef brigade plan for #228. P4 (hit) follows.
🤖 Generated with Claude Code