feat: policy simulation sandbox for dry-running rules - #135
Merged
K1NGD4VID merged 2 commits intoSep 2, 2026
Conversation
Adds a policy simulation sandbox modal that lets administrators dry-run proposed spending rules against custom transactions before enforcing them on-chain, preventing misconfigured rules from locking agent funds. - policySimulation.ts: pure first-match evaluation engine over the Zod-validated PolicyRule clauses, returning allowed/flagged/rejected verdicts with an ordered per-clause breakdown - PolicySimulationModal.tsx: Zod-validated simulation form (amount, asset, recipient, agent tags) inside the accessible Dialog primitive (focus trap, Esc-to-close), verdict banner with polite live-region announcement and step-by-step evaluation breakdown - Exported via the policies feature index 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@Timmatt112 is attempting to deploy a commit to the Cjay's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Timmatt112 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #50
Summary
Adds a policy simulation sandbox modal that lets administrators dry-run proposed spending rules against custom (historical or simulated) agent transactions before enforcing them on-chain — preventing misconfigured rules from locking up agent funds.
What was built
src/features/policies/policySimulation.ts(new)Pure, React/DOM-free evaluation engine:
rulesSchema.ts(PolicyRule,RuleField,RuleOperator,RuleAction).simulateTransaction(tx, rules)evaluates every clause in order, firewall-style first-match semantics, and escalates the verdict across matched actions (allow<flag/require_approval<block).SimulationVerdict(allowed|flagged|rejected), a human-readable summary, an orderedEvaluatedClause[]trail (each clause shows the actual value checked, the operator, the rule value, and whether it matched), andmatchedClauseIndices.src/features/policies/PolicySimulationModal.tsx(new)react-hook-form+zodResolver, matching the validation patterns already used inSpendingPolicyBuilder.tsx.isValidStellarPublicKeyfrom the freighter store).If <field> <operator> <value> then <action>, the engine's actual comparison detail, and a Matched/No-match badge per clause.Dialogprimitive: portal rendering, focus trap, Escape-to-close, overlay dismissal, focus restoration on close.aria-live="polite"status region announces the verdict after each run, sr-only verdict text, labelled inputs,aria-haspopup="dialog"on the launcher.PolicySimulationSandbox(button + modal pair) and a default sample ruleset; accepts a customrulesprop so it can be pointed at live builder state.Wiring
src/features/policies/index.ts(PolicySimulationModal,PolicySimulationSandbox,defaultSimulationRules, engine types/helpers).Acceptance criteria
rulesSchema.ts)npx eslintclean on all touched files;npm run typecheckintroduces no new errors (the only remaining errors pre-exist onmaininsrc/app/(dashboard)/transactions/page.tsxand are untouched by this PR)Edge cases covered by the engine
min(0)on the form; engine treats amount as a plain number forgreater_than/less_than)>/<are strict, so a transaction exactly at the limit does not triggergreater_than— matches the builder's wording)in_whitelist+containsonDestination Target)Test plan
npx eslinton touched files — clean.npm run typecheck— no new errors vsmain.require_approvalclause fires → Flagged; amount 11000 → Rejected; whitelisted recipient under the ceiling → Allowed; malformed recipient → inline Zod error; Esc closes the modal and focus returns to the launcher.