Skip to main content
Glama
evidiq

EVIDIQ Clause

Official
by evidiq
README.md
<p align="center">
  <img src="./banner.png" alt="EVIDIQ Clause" width="100%" />
</p>

<p align="center">
  <h1 align="center">EVIDIQ Clause</h1>
</p>

<p align="center"><strong>Plain-language decoding of agreements and policy documents, proven</strong></p>

<p align="center">
  Every statement quoted and checked against your document, every inference
  running inside a TEE-attested enclave, every report signed and anchored —
  and the checking is free. Service #23 of the EVIDIQ fleet.
</p>

<p align="center">
  <a href="https://evidiq.dev">evidiq.dev</a> &middot;
  <a href="https://mcp.evidiq.dev/clause/skill.md">Agent Skill</a> &middot;
  <a href="https://github.com/evidiq/evidiq-clause-mcp">Clause MCP</a>
</p>

<p align="center">
  <a href="https://mcp.evidiq.dev/clause/mcp"><img src="https://img.shields.io/badge/MCP%20Server-Active-3CCF4E?style=flat-square" alt="MCP Server active" /></a>
  <a href="https://www.oklink.com/xlayer"><img src="https://img.shields.io/badge/X%20Layer-USDT0-3CCF4E?style=flat-square" alt="X Layer USDT0" /></a>
  <a href="https://mcp.evidiq.dev/clause/x402"><img src="https://img.shields.io/badge/x402-0.05%E2%80%930.25%20USDT0-2563EB?style=flat-square" alt="x402: 0.05 to 0.25 USDT0" /></a>
  <a href="https://web3.okx.com/onchainos/dev-docs/payments/service-seller-sdk"><img src="https://img.shields.io/badge/Payments-Official%20OKX%20SDK-121212?style=flat-square&logo=okx&logoColor=white" alt="Official OKX Payment SDK" /></a>
  <a href="https://www.oklink.com/xlayer/tx/0x5ac9ef154280b4a65c76a7566c1522b53e8ee59dc433736592c1adf0f4ff3c8a"><img src="https://img.shields.io/badge/Settlement-Proven%20on%20X%20Layer-3CCF4E?style=flat-square" alt="Settlement proven on X Layer" /></a>
  <a href="./LICENSE"><img src="https://img.shields.io/badge/License-MIT-3DA639?style=flat-square" alt="License: MIT" /></a>
</p>

---

**Live on OKX.AI** as Agent #10584 (ASP, 8 services, A2MCP only). Endpoint
`https://mcp.evidiq.dev/clause/mcp`, x402 gate enforced, USDT0 on X Layer.

## Tools

| Tool | Price | What it does |
| --- | --- | --- |
| `decode_document` | 0.05 | Plain-language rendering, section by section, every statement cited |
| `risk_flags` | 0.10 | Seven hazards enumerated with severity, quote and why it matters |
| `obligation_calendar` | 0.10 | Dated duties as a schedule, relative dates resolved |
| `compare_documents` | 0.15 | Two documents diffed on meaning, with which side each change favours |
| `verdict_report` | 0.25 | Decode + flags + calendar + bottom line, two-pass, EIP-191 signed, 0G-anchored |
| `capabilities` | free | Tools, prices, models with TEE status, limits |
| `verify_report` | free | Re-verifies digest, signature, chain and every citation — no model, ever |
| `quote` | free | x402 challenge for any paid tool |

## The three promises

1. **Citations are checked, not trusted.** Every statement carries a quote plus
   offsets; the server locates the quote verbatim in your document and **drops**
   any statement whose quote is not there (`citationsDropped`). An invented
   clause is mechanically impossible.
2. **The reasoning step is attributable.** Inference runs on 0G Compute, only on
   models whose `tee_attested` is true, checked against the router's live
   registry at call time. Each report records model, provider, request id, TDX
   attestation and cost in wei.
3. **The record is sealed.** JCS digest, EIP-191 signature, chained (a removed
   record shows as a sequence gap), anchored to 0G Storage — the anchored body
   sealed with AES-256-GCM unless `anchorInClear` is set. Checking is free:
   `verify_report` re-verifies everything against your source.

Models: `qwen3-vl-30b` (extraction; the only one that accepts images) ·
`deepseek-v4-flash` (independent review pass, `verdict_report` only) ·
`0gm-1.0-35b-a3b` (fallback) — all TDX/dstack.

## Architecture

```mermaid
flowchart TB
    agent["<b>AI agent / caller</b><br/>MCP client"]
    request{"Tool call<br/>free or paid?"}
    agent -->|POST /clause/mcp| request

    free["Free preflight & verification<br/>capabilities · verify_report · quote<br/>never call the model"]
    gate["x402 v2 gate<br/>EIP-3009 exact · pay per answer<br/>402 unpaid · settles on X Layer"]
    xlayer[("X Layer<br/>USD₮0 · eip155:196")]
    request -->|free helper| free
    request -->|paid answer| gate
    gate -. verify and settle .-> xlayer

    subgraph clause["EVIDIQ Clause trust boundary"]
        direction TB
        intake["1. Document intake<br/>text or base64 pages in the request<br/>no URL fetching · size limits"]
        teegate["2. TEE gate<br/>tee_attested read live from the router registry<br/>non-attested model refuses"]
        extract["3. Extract pass<br/>qwen3-vl-30b (0gm fallback)<br/>every statement citation-checked; fakes dropped"]
        review["4. Review pass<br/>deepseek-v4-flash · verdict_report only<br/>justify or drop each flag"]
        seal["5. Seal<br/>JCS digest + EIP-191 + chain (seq/prevHash)<br/>AES-256-GCM sealed anchor · manifest readable"]
        intake --> teegate
        teegate --> extract
        extract --> review
        review --> seal
    end

    og[("0G Storage<br/>sealed body + readable manifest<br/>chain 16661")]
    free --> seal
    gate --> seal
    seal -. root + tx .-> og
    og -. anchor .-> response

    response["<b>MCP response</b><br/>report + citations + compute trace<br/>digest · signature · anchorKey"]

    classDef client fill:#312e81,stroke:#a78bfa,color:#ffffff,stroke-width:2px;
    classDef payment fill:#052e16,stroke:#4ade80,color:#ffffff,stroke-width:2px;
    classDef core fill:#0f172a,stroke:#38bdf8,color:#ffffff,stroke-width:2px;
    classDef output fill:#4c1d95,stroke:#c4b5fd,color:#ffffff,stroke-width:2px;
    class agent,request client;
    class free,gate,xlayer,og payment;
    class intake,teegate,extract,review,seal core;
    class response output;
    style clause fill:#0f172a,stroke:#38bdf8,color:#e0f2fe,stroke-width:2px;
```

---

## Settled on X Layer (2026-08-06)

| Tool | Amount | Settlement |
| --- | --- | --- |
| `decode_document` | 0.05 | [`0x5f6a50dc…f87e2`](https://www.oklink.com/xlayer/tx/0x5f6a50dce42aecff239dce08c302c0575e2c49e39a29db6f27388f9fa4bf87e2) |
| `risk_flags` | 0.10 | [`0x69f37d98…eda6e`](https://www.oklink.com/xlayer/tx/0x69f37d98462585a932f2c465b11a55c25251335017e6da736fab980ec88eda6e) |
| `obligation_calendar` | 0.10 | [`0x8a1f9831…f99a`](https://www.oklink.com/xlayer/tx/0x8a1f9831bbaf28ec3704d636b4f5ebce68d77d66cb09e5b4ff65009ed301f99a) |
| `compare_documents` | 0.15 | [`0x909eacc1…55a8f`](https://www.oklink.com/xlayer/tx/0x909eacc110a359f40bffacd9b811d31296712b85759367dce931b438d8f55a8f) |
| `verdict_report` | 0.25 | [`0x5ac9ef15…ff3c8a`](https://www.oklink.com/xlayer/tx/0x5ac9ef154280b4a65c76a7566c1522b53e8ee59dc433736592c1adf0f4ff3c8a) |

Total 0.65 USDT0, every one status `settled`. Signed verdict from that run (seq 6,
`citationsDropped` 0, 0G anchor [`0x832f9330…17d92`](https://chainscan.0g.ai/tx/0x832f933046bd22ce2ced423429f43f77fb8ab143dc551b772d30a08c15d17e92))
and all five outputs: `docs/live-test/`.

## Live test recording

![EVIDIQ Clause — live test recording](./docs/live-test/clause-livetest.gif)

MP4: [`clause-livetest.mp4`](./docs/live-test/clause-livetest.mp4) · raw log:
[`clause-livetest-out.log`](./docs/live-test/clause-livetest-out.log). Genuine
asciinema capture with `--idle-time-limit 2` (waits over two seconds shortened;
session ~3 min, GIF 19.3s; no frame edited; latencies are wall-clock from the log).

## Tests

40/40, twelve gates C1 C2 C3 T1 T2 F1 F2 G1 V1 B1 S1 L1 — the three that guard
the promises: a fabricated citation is dropped (C1), a non-attested model is
refused (T1), no free tool ever reaches the router (F1).

## Boundaries

A reading aid, not legal advice. No outbound fetching (documents arrive as text,
up to 200,000 characters, or 20 base64 image pages). Not verified yet: scanned
image input (code exists, fails safe) and an independent 0G indexer re-check in
`verify_report`.

## Fast start

```bash
npm install && npm run build && npm test
```

Environment in `.env.example` (slots empty). Container `evidiq-clause`, port
3024, Traefik at `mcp.evidiq.dev/clause`.

## TypeScript SDK

A typed client for the live endpoint lives in [`sdk/index.ts`](sdk/index.ts) — 8 tools (3 free, 5 paid). Free tools answer a bare call; paid tools run the x402 flow automatically (402 challenge → `pay` hook → replay with the `x-payment` header). No key lives in the file.

```ts
import { ClauseClient } from "./sdk/index.js";

const client = new ClauseClient(); // endpoint defaults to https://mcp.evidiq.dev/clause/mcp

// free
const caps = await client.callTool("clause_capabilities", {});

// paid — settle the 402 challenge via the constructor's pay hook, or omit it
// to receive a PaymentRequiredError carrying the full x402 v2 challenge
const result = await client.callTool("some_paid_tool", { arg: "value" });
```

The `pay` hook receives the decoded x402 v2 challenge (`{ x402Version, resource, accepts[] }` — payTo, asset, amount) and returns the value for the `x-payment` header, e.g. an EIP-3009 `transferWithAuthorization` settled via the official OKX SDK. Without a hook, paid calls throw `PaymentRequiredError` so the caller can settle however it wants.