feat: add fail-closed pre-fund policy hook - #39
Open
AgentTanuki wants to merge 10 commits into
Open
Conversation
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.
Why
session.fund()currently prepares a transaction without an optional counterparty/policy decision point. Wallet agents need a last-mile gate on the exact provider, chain, amount, and hydrated job.What
fundPolicytoAcpAgent.create{ allow: true }FundPolicyDeniedErrorwith machine-readable evidenceValidation
AI disclosure: implemented with significant Codex assistance and independently reviewed against the transaction ordering and compiled/tested locally.
Note
Medium Risk
Touches the on-chain funding gate for all
session.fund()paths; mistakes could block legitimate funds or use stale job data, though behavior is unchanged when no policy is set and snapshot pinning mitigates async races.Overview
Adds an optional
fundPolicyonAcpAgent.createso wallet agents can approve or block funding using the exact provider, chain, amount, and hydratedAcpJobbefore any fund transaction is prepared.session.fund()now callsenforceFundPolicyfirst (fail-closed: only{ allow: true }proceeds; denial, missing decision, or thrown errors abort withFundPolicyDeniedError). Funding branches use a fixed job snapshot taken at the start offund()so a slow policy or concurrentfetchJob()cannot change the job the policy saw. OmittingfundPolicyleaves prior behavior unchanged.New
src/core/fundPolicy.tstypes and helper are exported from the package; README documents the hook.npm testruns compile plus Node tests for allow/deny, missing decision, errors, and snapshot stability.Reviewed by Cursor Bugbot for commit cbaf094. Bugbot is set up for automated code reviews on this repo. Configure here.