apex-psi-mcp 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -99,6 +99,112 @@ fingerprint the same bytes: `fingerprint({"b":1,"a":[1,2],"c":"x"})` is
99
99
  `95c12ab4ca0e8f3c485ea1b1b1a2b24976d07180baf5ecad0d81b5bbaf07532b` in both, and a CI check on each
100
100
  side pins that number.
101
101
 
102
+ ## The receiver gate: refusing an action that was not permitted
103
+
104
+ The gate above lives on the sender's side, and it is optional: an agent that
105
+ never calls `seal` leaves no gap in the ledger, and the ledger stays complete
106
+ and says nothing about that action. The receiver gate is the half that is not
107
+ optional, because it sits in the process that performs the side effect.
108
+
109
+ ```js
110
+ import { createReceiverGate } from "apex-psi-mcp/receiver";
111
+
112
+ const gate = createReceiverGate({
113
+ resolveKey: (kid) => keyring[kid], // kid -> Ed25519 public key
114
+ mode: "enforce", // "shadow" observes without blocking
115
+ });
116
+
117
+ const result = await gate.authorize({
118
+ envelope,
119
+ mandate,
120
+ proposal,
121
+ decision,
122
+ tool: "transfer",
123
+ args: { amount: "10.00", to: "acct-42" },
124
+ actorKid: "agent-key",
125
+ });
126
+ ```
127
+
128
+ `authorize` returns `{ allowed, enforced, wouldAllow, reason, report, permit }`.
129
+ In `enforce` mode a refused action never runs: `gate.run(request, fn)` throws
130
+ `ReceiverRefusedError` and `fn` is not called. `reason` is a stable code —
131
+ `missing_authority`, `decision_not_allow`, `outside_window`, `over_spend`,
132
+ `over_actions`, `replay`, `args_mismatch`, `scope_not_permitted`,
133
+ `currency_not_permitted`, `settlement_did_mismatch`, `signature_invalid`,
134
+ `key_unresolved`, `algorithm_unavailable`, `decision_key_is_action_key`,
135
+ `mandate_key_is_decision_key`, `mandate_key_is_action_key` — and the report
136
+ carries the reason codes of `draft-singh-psi-agent-03` for the checks the
137
+ contract defines.
138
+
139
+ `shadow` mode turns the gate on without breaking anything: it reports the same
140
+ reasons and lets the action through, recording what would have been refused.
141
+ It does not refuse.
142
+
143
+ What the receiver recomputes, from `draft-singh-psi-agent-03`:
144
+
145
+ - The mandate, proposal, decision and envelope each recompute to the identifier
146
+ they carry, and each signature verifies under the key it names. An algorithm
147
+ this server does not implement is reported, never guessed at.
148
+ - Every statement carries the run identifier of the envelope. The proposal
149
+ names the mandate, and the decision names the proposal.
150
+ - Amounts are decimal strings compared exactly — never as floating point — and
151
+ the asset is compared as an exact, case-sensitive string.
152
+ - The mandate's window, action count and spend limit hold.
153
+ - A proposal already accepted once is a replay and is refused.
154
+ - The acting key is neither the decision key nor the mandate key.
155
+
156
+ Settlement statuses stay distinct. `authorised` records that a limit was
157
+ reserved; it does not record that money moved, and nothing here reports it as
158
+ money moved.
159
+
160
+ ## The sender: seal first, act second, bind the settlement
161
+
162
+ `createMandatedSender` wraps an action in the mandate that permitted it:
163
+
164
+ ```js
165
+ import { createNotarySealer } from "apex-psi-mcp/gate";
166
+ import { createMandatedSender } from "apex-psi-mcp/sender";
167
+
168
+ const sender = createMandatedSender({
169
+ mandate,
170
+ proposal,
171
+ decision,
172
+ sealer: createNotarySealer(),
173
+ actorKid: "agent-key",
174
+ });
175
+
176
+ const { value, receipt, actionRecord, chainRoot } = await sender.execute(
177
+ "transfer",
178
+ { amount: "10.00", to: "acct-42" },
179
+ () => payments.transfer({ amount: "10.00", to: "acct-42" }),
180
+ );
181
+ ```
182
+
183
+ The sender refuses arguments the proposal never described, a decision that did
184
+ not say `allow`, and a tool outside the mandate's scope. The seal happens
185
+ before the action, so a failed seal leaves the action uncalled. A retry of the
186
+ same proposal runs the action once. `bindSettlement` refuses a settlement whose
187
+ decision does not match, whose currency the mandate does not permit, or whose
188
+ amount exceeds the mandate's limit.
189
+
190
+ ## Prove the gate in two commands
191
+
192
+ ```
193
+ npm run check:agent # the built receiver refuses every case it must refuse
194
+ npm run check:parity # Node and Python sign the same bytes
195
+ ```
196
+
197
+ `conformance/agent-03.json` holds the frozen contract: the profile, the signed
198
+ bytes rule, the decimal rule, and the refusal cases the suite proves.
199
+
200
+ `conformance/agent-03-example.json` holds one signed run you can verify
201
+ yourself: the statements, the public keyring, one request that must be
202
+ permitted, and seventeen requests that must each be refused for a stated reason.
203
+ Those reasons were measured against the built gate, and
204
+ `npm run check:example` fails if the gate ever answers differently. The keys in
205
+ that file are test keys, made for the file and discarded when it was written;
206
+ they sign nothing outside the file.
207
+
102
208
  ## Configuration
103
209
 
104
210
  Environment variables (both optional):