kontext-sdk 0.3.2 → 0.5.2

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
@@ -1,98 +1,207 @@
1
1
  # kontext-sdk
2
2
 
3
- Trust and compliance layer for agentic crypto workflows.
3
+ Compliance audit trail CLI and SDK for AI agents making stablecoin payments on Base.
4
4
 
5
- Kontext provides structured action logging, tamper-evident audit trails, trust scoring, anomaly detection, and compliance tooling for AI agents operating in crypto and stablecoin ecosystems.
5
+ **USDC** · **USDT** · **DAI** · **EURC** · **USDP** · **USDG** · **x402** · **Circle Programmable Wallets**
6
+
7
+ ---
8
+
9
+ ## 30-Second Demo
10
+
11
+ ```bash
12
+ npx kontext-sdk check 0xAgentWallet 0xMerchant --amount 5000 --token USDC
13
+ ```
14
+
15
+ ```
16
+ OFAC Sanctions: CLEAR
17
+ Travel Rule: TRIGGERED ($5,000 >= $3,000 EDD threshold)
18
+ CTR Threshold: CLEAR ($5,000 < $10,000)
19
+ Large TX Alert: CLEAR ($5,000 < $50,000)
20
+ Risk Level: medium
21
+ ```
22
+
23
+ No install. No config. No API key. One command.
6
24
 
7
25
  ## Install
8
26
 
9
27
  ```bash
10
- npm install kontext-sdk
28
+ npm install -g kontext-sdk
11
29
  ```
12
30
 
13
- ## Quick Start
31
+ Then run `kontext` from anywhere. Or use `npx kontext-sdk` for one-off checks.
14
32
 
15
- ```typescript
16
- import { Kontext } from 'kontext-sdk';
33
+ ## Claude Code / Cursor / Windsurf
17
34
 
18
- // Initialize in local mode (no API key needed)
19
- const kontext = Kontext.init({
20
- projectId: 'my-project',
21
- environment: 'development',
22
- });
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "kontext": {
39
+ "command": "npx",
40
+ "args": ["-y", "kontext-sdk", "mcp"]
41
+ }
42
+ }
43
+ }
44
+ ```
45
+
46
+ Then ask: *"verify this USDC transaction for compliance"*
47
+
48
+ ## CLI Commands
49
+
50
+ ### `kontext check <from> <to>` — stateless compliance check
51
+
52
+ ```bash
53
+ npx kontext-sdk check 0xSender 0xReceiver --amount 5000 --token USDC
54
+ ```
55
+
56
+ Instant OFAC screening + threshold checks. No state, no persistence.
57
+
58
+ ### `kontext verify` — log + check + digest proof
23
59
 
24
- // Log an agent action
25
- await kontext.log({
26
- type: 'transfer',
27
- description: 'Agent initiated USDC transfer',
28
- agentId: 'payment-agent-1',
60
+ ```bash
61
+ npx kontext-sdk verify --tx 0xabc123 --amount 5000 --token USDC \
62
+ --from 0xAgent --to 0xMerchant --agent my-bot
63
+ ```
64
+
65
+ Runs compliance checks, logs the transaction, appends to the tamper-evident digest chain. Persists to `.kontext/` in the current directory.
66
+
67
+ ### `kontext reason` — log agent reasoning
68
+
69
+ ```bash
70
+ npx kontext-sdk reason "API returned data I need. Price within budget." \
71
+ --agent my-bot --session sess_abc --step 1
72
+ ```
73
+
74
+ ### `kontext cert` — export compliance certificate
75
+
76
+ ```bash
77
+ npx kontext-sdk cert --agent my-bot --output cert.json
78
+ ```
79
+
80
+ ### `kontext audit` — verify digest chain integrity
81
+
82
+ ```bash
83
+ npx kontext-sdk audit --verify
84
+ ```
85
+
86
+ ### `kontext mcp` — MCP server mode
87
+
88
+ ```bash
89
+ npx kontext-sdk mcp
90
+ ```
91
+
92
+ Starts an MCP server on stdio for Claude Code, Cursor, and Windsurf.
93
+
94
+ ### Flags
95
+
96
+ - `--json` on any command outputs structured JSON
97
+ - `--amount <number>` transaction amount in token units
98
+ - `--token <symbol>` one of USDC, USDT, DAI, EURC, USDP, USDG
99
+
100
+ ## SDK — Programmatic Usage
101
+
102
+ For tighter integration, use the SDK directly:
103
+
104
+ ```typescript
105
+ import { Kontext, FileStorage } from 'kontext-sdk';
106
+
107
+ const ctx = Kontext.init({
108
+ projectId: 'my-agent',
109
+ environment: 'production',
110
+ storage: new FileStorage('.kontext'),
29
111
  });
30
112
 
31
- // Log a transaction with full chain details
32
- await kontext.logTransaction({
113
+ // One-call: compliance check + transaction log + digest proof
114
+ const result = await ctx.verify({
33
115
  txHash: '0xabc...',
34
116
  chain: 'base',
35
- amount: '100',
117
+ amount: '5000',
36
118
  token: 'USDC',
37
- from: '0xSender...',
38
- to: '0xReceiver...',
39
- agentId: 'payment-agent-1',
119
+ from: '0xAgent...',
120
+ to: '0xMerchant...',
121
+ agentId: 'payment-agent',
40
122
  });
41
123
 
42
- // Get trust score for an agent
43
- const score = await kontext.getTrustScore('payment-agent-1');
44
- console.log(`Trust: ${score.score}/100 (${score.level})`);
124
+ // result.compliant = true/false
125
+ // result.checks = [{ name: 'OFAC Sanctions', passed: true }, ...]
126
+ // result.riskLevel = 'low' | 'medium' | 'high' | 'critical'
127
+ // result.digestProof = 'sha256:a1b2c3...'
128
+ ```
45
129
 
46
- // Export audit data
47
- const audit = await kontext.export({ format: 'json' });
130
+ ### Log Reasoning
48
131
 
49
- // Verify digest chain integrity
50
- const verification = kontext.verifyDigestChain();
51
- console.log(`Chain valid: ${verification.valid}`);
132
+ ```typescript
133
+ await ctx.logReasoning({
134
+ agentId: 'payment-agent',
135
+ action: 'approve-transfer',
136
+ reasoning: 'Price within budget. Merchant verified.',
137
+ confidence: 0.95,
138
+ });
52
139
  ```
53
140
 
54
- ## Features
141
+ ### Compliance Certificate
55
142
 
56
- - **Action Logging** -- Structured logging for all agent actions with timestamps, correlation IDs, and metadata.
57
- - **Transaction Tracking** -- Full chain details for crypto transactions across Base, Ethereum, Polygon, Arbitrum, and Optimism.
58
- - **Tamper-Evident Digest Chain** -- Patented cryptographic digest chain that detects any modification to the audit trail.
59
- - **Trust Scoring** -- Rule-based trust scores for agents based on history, task completion, anomaly rate, and consistency.
60
- - **Anomaly Detection** -- Configurable rules for unusual amounts, frequency spikes, new destinations, off-hours activity, rapid succession, and round amounts.
61
- - **Task Confirmation** -- Evidence-based task tracking with required proof for completion.
62
- - **USDC Compliance** -- Pre-built compliance checks aligned with stablecoin regulatory requirements across all supported chains.
63
- - **CCTP Integration** -- Cross-chain transfer tracking for Circle's Cross-Chain Transfer Protocol with full lifecycle management.
64
- - **Webhook Notifications** -- Event-driven webhooks for anomalies, task updates, and trust score changes with retry logic.
65
- - **Audit Export** -- JSON and CSV export with date range and entity filtering.
66
- - **SAR/CTR Templates** -- Structured report templates for suspicious activity and currency transaction reporting.
143
+ ```typescript
144
+ const cert = await ctx.generateComplianceCertificate({
145
+ agentId: 'payment-agent',
146
+ includeReasoning: true,
147
+ });
148
+ ```
149
+
150
+ ### Trust Score
67
151
 
68
- ## Supported Chains
152
+ ```typescript
153
+ const score = await ctx.getTrustScore('payment-agent');
154
+ // score.score = 87, score.level = 'high'
155
+ ```
69
156
 
70
- | Chain | USDC Contract | CCTP Domain |
71
- |----------|---------------|-------------|
72
- | Ethereum | 0xA0b8...eB48 | 0 |
73
- | Base | 0x8335...2913 | 6 |
74
- | Polygon | 0x3c49...3359 | 7 |
75
- | Arbitrum | 0xaf88...5831 | 3 |
76
- | Optimism | 0x0b2C...Ff85 | 2 |
157
+ ### Verify Digest Chain
77
158
 
78
- ## Operating Modes
159
+ ```typescript
160
+ const chain = ctx.verifyDigestChain();
161
+ console.log(chain.valid); // true — no tampering
162
+ ```
79
163
 
80
- - **Local mode** (no API key): All data stored in-memory and optionally written to local JSON files. Suitable for development and open-source usage.
81
- - **Cloud mode** (with API key): Data synced to Kontext API for persistent storage and advanced features.
164
+ ### Persist Across Restarts
82
165
 
83
166
  ```typescript
84
- // Cloud mode
85
- const kontext = Kontext.init({
86
- apiKey: 'sk_live_...',
87
- projectId: 'my-project',
167
+ import { FileStorage } from 'kontext-sdk';
168
+
169
+ const ctx = Kontext.init({
170
+ projectId: 'my-agent',
88
171
  environment: 'production',
172
+ storage: new FileStorage('.kontext'),
89
173
  });
174
+
175
+ // Data persists to .kontext/ directory
176
+ // Call ctx.flush() to write, ctx.restore() to reload
90
177
  ```
91
178
 
92
- ## Documentation
179
+ ## Compliance Thresholds
180
+
181
+ | Threshold | Amount | Trigger |
182
+ |-----------|--------|---------|
183
+ | **EDD / Travel Rule** | $3,000 | Enhanced Due Diligence required |
184
+ | **CTR** | $10,000 | Currency Transaction Report |
185
+ | **Large TX Alert** | $50,000 | Large Transaction Alert |
186
+
187
+ OFAC sanctions screening uses the built-in SDN list. No API key required.
93
188
 
94
- For full documentation, visit [getkontext.com](https://getkontext.com).
189
+ ## What's Included
190
+
191
+ - Tamper-evident audit trail (patented digest chain)
192
+ - OFAC sanctions screening (SDN list, no API key)
193
+ - Compliance certificates with SHA-256 proof
194
+ - Agent reasoning logs
195
+ - Trust scoring and anomaly detection
196
+ - MCP server mode for AI coding tools
197
+ - Zero runtime dependencies
95
198
 
96
199
  ## License
97
200
 
98
- MIT -- see [LICENSE](./LICENSE) for details.
201
+ MIT
202
+
203
+ ---
204
+
205
+ Kontext provides compliance logging tools. Regulatory responsibility remains with the operator. This software does not constitute legal advice and does not guarantee regulatory compliance. Consult qualified legal counsel for your specific obligations.
206
+
207
+ Built by [Legaci Labs](https://www.getkontext.com)