@reinconsole/policy-engine 0.1.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/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +852 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +287 -0
- package/dist/server.js +829 -0
- package/dist/server.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rein contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @reinconsole/policy-engine
|
|
2
|
+
|
|
3
|
+
The rule engine of **[Rein](https://github.com/bugiiiii11/rein)** — the control plane for AI agent payments. A sandboxed, declarative policy engine that judges every payment intent (`deny > escalate > allow > default`), with every decision ed25519-signed and sha256 hash-chained into a tamper-evident audit log.
|
|
4
|
+
|
|
5
|
+
> **Status: v0.1 — early open-source infrastructure, live on testnet.** APIs may change before 1.0. See it running: [Rein console](https://reinconsole-production.up.railway.app/).
|
|
6
|
+
|
|
7
|
+
## Install & run
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @reinconsole/policy-engine
|
|
11
|
+
# or just run it:
|
|
12
|
+
npx -p @reinconsole/policy-engine rein-policy-engine # HTTP API on :8787 (PORT/HOST env)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Point [`@reinconsole/sdk`](https://www.npmjs.com/package/@reinconsole/sdk)'s guard at it (`engineUrl`) and every x402 paywall your agent hits is evaluated here first.
|
|
16
|
+
|
|
17
|
+
## In-process
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { PolicyEngine, buildServer } from '@reinconsole/policy-engine';
|
|
21
|
+
|
|
22
|
+
const engine = new PolicyEngine(); // in-memory stores by default
|
|
23
|
+
const app = buildServer(engine); // Fastify instance (not yet listening)
|
|
24
|
+
await app.listen({ port: 8787 });
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## What it does
|
|
28
|
+
|
|
29
|
+
- **Declarative policies** — budgets over rolling windows, per-tx caps, vendor allow/deny lists by glob, escalation, and reputation rules (`vendorReputationLt`, fed by [`@reinconsole/graph`](https://www.npmjs.com/package/@reinconsole/graph)). Precedence is `deny > escalate > allow > default`.
|
|
30
|
+
- **Kill switch** — freeze an agent and there is no allow; the check happens before evaluation.
|
|
31
|
+
- **Signed decisions** — each decision commits to the exact intent it judged (`intentHash`), is ed25519-signed, and links to the previous decision's hash. `verifyDecisionChain` validates the whole history offline; the `{intent, decision}` pair is a self-contained spend voucher downstream tiers verify without calling back.
|
|
32
|
+
- **Store ports** — agents, policies, rolling spend, and the decision log sit behind injectable ports (`SpendStorePort`, `PolicyStorePort`, `AgentRegistryPort`). In-memory implementations ship here; the durable Postgres-backed variant lives in the [monorepo](https://github.com/bugiiiii11/rein) (`@reinconsole/store`) and keeps the hash chain continuous across restarts.
|
|
33
|
+
- **HTTP API** — `POST /v1/evaluate`, agent + policy CRUD, decision reads. Zod-validated 400s, not 500s.
|
|
34
|
+
|
|
35
|
+
MIT © Rein contributors · [Repository](https://github.com/bugiiiii11/rein) · [Issues](https://github.com/bugiiiii11/rein/issues)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { A as AgentRegistryPort, D as DecisionInput, a as DecisionLog, b as DecisionLogKeyPair, c as DecisionLogOptions, E as EngineStores, d as EvaluateOutput, e as EvaluationResult, I as InMemoryAgentRegistry, f as InMemoryPolicyStore, g as InMemorySpendStore, h as IntentInput, M as MaybePromise, P as PolicyEngine, i as PolicyStorePort, S as SpendContext, j as SpendRecord, k as SpendStorePort, buildServer, l as conditionMatches, m as evaluate, p as parseWindowMs, n as policyApplies, v as verifyDecisionChain } from './server.js';
|
|
2
|
+
export { globMatch, globMatchAny } from '@reinconsole/core';
|
|
3
|
+
import 'zod';
|
|
4
|
+
import 'node:crypto';
|
|
5
|
+
import 'fastify';
|