@det-acp/core 0.2.0 → 0.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 +332 -213
- package/dist/engine/action-registry.d.ts.map +1 -1
- package/dist/engine/action-registry.js +20 -0
- package/dist/engine/action-registry.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/archive-extract.d.ts +45 -0
- package/dist/tools/archive-extract.d.ts.map +1 -0
- package/dist/tools/archive-extract.js +246 -0
- package/dist/tools/archive-extract.js.map +1 -0
- package/dist/tools/directory-create.d.ts +33 -0
- package/dist/tools/directory-create.d.ts.map +1 -0
- package/dist/tools/directory-create.js +145 -0
- package/dist/tools/directory-create.js.map +1 -0
- package/dist/tools/directory-list.d.ts +32 -0
- package/dist/tools/directory-list.d.ts.map +1 -0
- package/dist/tools/directory-list.js +114 -0
- package/dist/tools/directory-list.js.map +1 -0
- package/dist/tools/env-read.d.ts +31 -0
- package/dist/tools/env-read.d.ts.map +1 -0
- package/dist/tools/env-read.js +108 -0
- package/dist/tools/env-read.js.map +1 -0
- package/dist/tools/file-copy.d.ts +30 -0
- package/dist/tools/file-copy.d.ts.map +1 -0
- package/dist/tools/file-copy.js +170 -0
- package/dist/tools/file-copy.js.map +1 -0
- package/dist/tools/file-delete.d.ts +27 -0
- package/dist/tools/file-delete.d.ts.map +1 -0
- package/dist/tools/file-delete.js +143 -0
- package/dist/tools/file-delete.js.map +1 -0
- package/dist/tools/file-move.d.ts +30 -0
- package/dist/tools/file-move.d.ts.map +1 -0
- package/dist/tools/file-move.js +167 -0
- package/dist/tools/file-move.js.map +1 -0
- package/dist/tools/git-commit.d.ts +33 -0
- package/dist/tools/git-commit.d.ts.map +1 -0
- package/dist/tools/git-commit.js +176 -0
- package/dist/tools/git-commit.js.map +1 -0
- package/dist/tools/git-status.d.ts +29 -0
- package/dist/tools/git-status.d.ts.map +1 -0
- package/dist/tools/git-status.js +159 -0
- package/dist/tools/git-status.js.map +1 -0
- package/dist/tools/network-dns.d.ts +50 -0
- package/dist/tools/network-dns.d.ts.map +1 -0
- package/dist/tools/network-dns.js +122 -0
- package/dist/tools/network-dns.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/examples/coding-agent.policy.yaml +44 -0
- package/examples/data-analyst.policy.yaml +160 -0
- package/examples/devops-deploy.policy.yaml +68 -0
- package/examples/infrastructure-manager.policy.yaml +209 -0
- package/examples/security-audit.policy.yaml +152 -0
- package/examples/video-upscaler.policy.yaml +45 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,67 +1,96 @@
|
|
|
1
1
|
# Deterministic Agent Control Protocol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/elliot35/deterministic-agent-control-protocol/stargazers)
|
|
4
|
+
[](https://github.com/elliot35/deterministic-agent-control-protocol/network/members)
|
|
5
|
+
[](https://github.com/elliot35/deterministic-agent-control-protocol/graphs/contributors)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://www.npmjs.com/package/@det-acp/core)
|
|
8
|
+

|
|
9
|
+

|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
**A governance gateway for AI agents — making every action bounded, auditable, reversible, and explainable.**
|
|
12
|
+
|
|
13
|
+
Works transparently with **Cursor**, **Claude Code**, **Codex**, and any MCP-compatible agent. Also supports shell command governance and a language-agnostic HTTP API.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Table of Contents
|
|
18
|
+
|
|
19
|
+
- [How It Works](#how-it-works)
|
|
20
|
+
- [Core Principles](#core-principles)
|
|
21
|
+
- [Quick Start](#quick-start)
|
|
22
|
+
- [Agent Integrations](#agent-integrations)
|
|
23
|
+
- [Built-in Policies](#built-in-policies)
|
|
24
|
+
- [Integration Modes](#integration-modes)
|
|
25
|
+
- [Architecture](#architecture)
|
|
26
|
+
- [Policy DSL Reference](#policy-dsl-reference)
|
|
27
|
+
- [Built-in Tool Adapters](#built-in-tool-adapters)
|
|
28
|
+
- [Custom Tool Adapters](#custom-tool-adapters)
|
|
29
|
+
- [Development](#development)
|
|
30
|
+
- [Contributing](#contributing)
|
|
31
|
+
- [License](#license)
|
|
32
|
+
|
|
33
|
+
---
|
|
6
34
|
|
|
7
35
|
## How It Works
|
|
8
36
|
|
|
9
|
-
|
|
37
|
+
Agents never execute tools directly. Every action flows through the control plane for evaluation, enforcement, and audit:
|
|
10
38
|
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
39
|
+
```mermaid
|
|
40
|
+
flowchart LR
|
|
41
|
+
A["Agent"] -->|"action request"| CP["Control Protocol"]
|
|
42
|
+
CP -->|"evaluate against policy"| D{"Decision"}
|
|
43
|
+
D -->|"allow"| E["Agent Executes Action"]
|
|
44
|
+
D -->|"deny"| F["Blocked + Reason Logged"]
|
|
45
|
+
D -->|"gate"| G["Human Approval Required"]
|
|
46
|
+
E -->|"record result"| L["Evidence Ledger"]
|
|
47
|
+
G -->|"approved"| E
|
|
17
48
|
```
|
|
18
49
|
|
|
19
|
-
The
|
|
50
|
+
The protocol **does not execute** actions itself. It evaluates them against a policy, enforces session-level budgets, requires human approval for risky operations, and records everything in a tamper-evident audit ledger.
|
|
51
|
+
|
|
52
|
+
---
|
|
20
53
|
|
|
21
54
|
## Core Principles
|
|
22
55
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
56
|
+
| Principle | Description |
|
|
57
|
+
|-----------|-------------|
|
|
58
|
+
| **Bounded** | Agents can only perform allowed actions within allowed scopes |
|
|
59
|
+
| **Session-Aware** | Budget, rate limits, and escalation rules across the full interaction |
|
|
60
|
+
| **Auditable** | Every action logged in a tamper-evident ledger with SHA-256 hash chaining |
|
|
61
|
+
| **Reversible** | Compensation plans for undoing executed actions |
|
|
62
|
+
| **Explainable** | Full reporting — what was allowed, denied, gated, and why |
|
|
63
|
+
|
|
64
|
+
---
|
|
28
65
|
|
|
29
66
|
## Quick Start
|
|
30
67
|
|
|
31
68
|
### Install
|
|
32
69
|
|
|
33
70
|
```bash
|
|
34
|
-
npm
|
|
71
|
+
npm i @det-acp/core
|
|
35
72
|
```
|
|
36
73
|
|
|
37
74
|
### Set Up Governance (One Command)
|
|
38
75
|
|
|
39
|
-
The fastest way to add governance to your AI agent:
|
|
40
|
-
|
|
41
76
|
```bash
|
|
42
|
-
# Cursor
|
|
43
|
-
npx det-acp init
|
|
44
|
-
|
|
45
|
-
# Codex CLI
|
|
46
|
-
npx det-acp init codex
|
|
47
|
-
|
|
48
|
-
# Claude Code
|
|
49
|
-
npx det-acp init claude-code
|
|
77
|
+
npx det-acp init cursor # Cursor
|
|
78
|
+
npx det-acp init codex # Codex CLI
|
|
79
|
+
npx det-acp init claude-code # Claude Code
|
|
50
80
|
```
|
|
51
81
|
|
|
52
|
-
This generates all required files (policy, MCP config, governance rules) with sensible defaults.
|
|
53
|
-
|
|
54
|
-
To use your own policy instead of the default:
|
|
82
|
+
This generates all required files (policy, MCP config, governance rules) with sensible defaults. Edit `policy.yaml` to customize — everything else is handled automatically.
|
|
55
83
|
|
|
56
84
|
```bash
|
|
85
|
+
# Use your own policy instead of the default
|
|
57
86
|
npx det-acp init cursor --policy ./my-policy.yaml
|
|
58
87
|
```
|
|
59
88
|
|
|
60
|
-
After running `init`, restart your agent
|
|
89
|
+
> After running `init`, restart your agent to pick up the MCP server.
|
|
61
90
|
|
|
62
91
|
### Define a Policy
|
|
63
92
|
|
|
64
|
-
Create
|
|
93
|
+
Create `agent.policy.yaml`:
|
|
65
94
|
|
|
66
95
|
```yaml
|
|
67
96
|
version: "1.0"
|
|
@@ -110,7 +139,7 @@ session:
|
|
|
110
139
|
### Use as a Library
|
|
111
140
|
|
|
112
141
|
```typescript
|
|
113
|
-
import { AgentGateway } from '
|
|
142
|
+
import { AgentGateway } from '@det-acp/core';
|
|
114
143
|
|
|
115
144
|
const gateway = await AgentGateway.create({
|
|
116
145
|
ledgerDir: './ledgers',
|
|
@@ -129,7 +158,7 @@ const verdict = await gateway.evaluate(session.id, {
|
|
|
129
158
|
});
|
|
130
159
|
|
|
131
160
|
if (verdict.decision === 'allow') {
|
|
132
|
-
// Execute the action yourself
|
|
161
|
+
// Execute the action yourself
|
|
133
162
|
const content = fs.readFileSync('./src/index.ts', 'utf-8');
|
|
134
163
|
|
|
135
164
|
// Record the result
|
|
@@ -140,7 +169,7 @@ if (verdict.decision === 'allow') {
|
|
|
140
169
|
});
|
|
141
170
|
}
|
|
142
171
|
|
|
143
|
-
//
|
|
172
|
+
// Terminate and get report
|
|
144
173
|
const report = await gateway.terminateSession(session.id, 'task complete');
|
|
145
174
|
console.log(`Allowed: ${report.allowed}, Denied: ${report.denied}`);
|
|
146
175
|
```
|
|
@@ -149,42 +178,71 @@ console.log(`Allowed: ${report.allowed}, Denied: ${report.denied}`);
|
|
|
149
178
|
|
|
150
179
|
## Agent Integrations
|
|
151
180
|
|
|
152
|
-
Ready-to-use
|
|
181
|
+
Ready-to-use guides for popular AI agents. Each integration includes policy, config templates, governance rules, test sandbox, and step-by-step instructions.
|
|
153
182
|
|
|
154
|
-
| Agent
|
|
155
|
-
|
|
156
|
-
| **Cursor**
|
|
157
|
-
| **Codex CLI**
|
|
183
|
+
| Agent | Integration Mode | Governance Level | Guide |
|
|
184
|
+
|-------|-----------------|-----------------|-------|
|
|
185
|
+
| **Cursor** | MCP Proxy + Cursor Rules | Soft | [integrations/cursor/](integrations/cursor/) |
|
|
186
|
+
| **Codex CLI** | MCP Proxy + AGENTS.md + OS Sandbox | Soft + Sandbox | [integrations/codex/](integrations/codex/) |
|
|
158
187
|
| **Claude Code** | MCP Proxy + CLAUDE.md + settings.json | Soft + Semi-Hard | [integrations/claude-code/](integrations/claude-code/) |
|
|
159
|
-
| **OpenClaw**
|
|
188
|
+
| **OpenClaw** | HTTP API + Skill + Docker Sandbox | Hard | [integrations/openclaw/](integrations/openclaw/) |
|
|
189
|
+
|
|
190
|
+
<details>
|
|
191
|
+
<summary><strong>Governance Levels Explained</strong></summary>
|
|
160
192
|
|
|
161
|
-
|
|
193
|
+
- **Soft** — The LLM is instructed (via rules/instructions files) to prefer governed tools. Effective in practice, but a creative prompt could theoretically bypass it.
|
|
194
|
+
- **Semi-Hard** — Soft instructions combined with the agent's built-in permission system that can deny direct tool access (e.g., Claude Code's `settings.json`).
|
|
195
|
+
- **Hard** — The agent physically cannot access tools outside the governance layer. Achieved via Docker sandboxing, tool allow/deny lists, or custom agent harnesses.
|
|
162
196
|
|
|
163
|
-
|
|
164
|
-
- **Semi-Hard**: Soft instructions combined with the agent's built-in permission system that can deny direct tool access (e.g., Claude Code's `settings.json`).
|
|
165
|
-
- **Hard**: The agent physically cannot access tools outside the governance layer. Achieved via Docker sandboxing, tool allow/deny lists, or custom agent harnesses.
|
|
197
|
+
</details>
|
|
166
198
|
|
|
167
|
-
For any MCP-compatible agent not listed above, see
|
|
199
|
+
For any MCP-compatible agent not listed above, see [MCP Proxy (General)](#mcp-proxy-general).
|
|
168
200
|
|
|
169
201
|
---
|
|
170
202
|
|
|
171
|
-
##
|
|
203
|
+
## Built-in Policies
|
|
204
|
+
|
|
205
|
+
Production-ready policies in `examples/` — usable out of the box:
|
|
206
|
+
|
|
207
|
+
| Policy | File | Use Case | Tools Used |
|
|
208
|
+
|--------|------|----------|------------|
|
|
209
|
+
| Coding Agent | [`coding-agent.policy.yaml`](examples/coding-agent.policy.yaml) | AI coding agents operating on a project | 13 tools |
|
|
210
|
+
| DevOps Deploy | [`devops-deploy.policy.yaml`](examples/devops-deploy.policy.yaml) | Deployment agents that build, test, and deploy code | 16 tools |
|
|
211
|
+
| Video Upscaler | [`video-upscaler.policy.yaml`](examples/video-upscaler.policy.yaml) | Media processing agents running upscaling pipelines | 11 tools |
|
|
212
|
+
| Data Analyst | [`data-analyst.policy.yaml`](examples/data-analyst.policy.yaml) | Data analysis agents processing datasets and generating reports | 12 tools |
|
|
213
|
+
| Security Audit | [`security-audit.policy.yaml`](examples/security-audit.policy.yaml) | Security scanning agents auditing code and dependencies | 11 tools |
|
|
214
|
+
| Infrastructure Manager | [`infrastructure-manager.policy.yaml`](examples/infrastructure-manager.policy.yaml) | Infrastructure management agents handling IaC, deployments, and monitoring | 16 tools |
|
|
215
|
+
|
|
216
|
+
> Validate any policy with: `npx det-acp validate ./policy.yaml`
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Integration Modes
|
|
221
|
+
|
|
222
|
+
| Mode | How It Works | Best For |
|
|
223
|
+
|------|-------------|----------|
|
|
224
|
+
| **MCP Proxy** | Transparent proxy between agent and MCP servers | Cursor, Claude Code, any MCP client |
|
|
225
|
+
| **Shell Proxy** | Command wrapper that validates before executing | CLI agents, shell-based workflows |
|
|
226
|
+
| **HTTP API** | REST endpoints for session management | Any language, custom integrations |
|
|
227
|
+
| **Library SDK** | TypeScript API for in-process governance | Custom TypeScript agents |
|
|
172
228
|
|
|
173
229
|
### MCP Proxy (General)
|
|
174
230
|
|
|
175
|
-
|
|
231
|
+
Works with any MCP-compatible client.
|
|
176
232
|
|
|
177
|
-
**Simplified mode** —
|
|
233
|
+
**Simplified mode** — point at a policy file, auto-configures filesystem backend:
|
|
178
234
|
|
|
179
235
|
```bash
|
|
180
236
|
npx det-acp proxy --policy ./policy.yaml
|
|
181
|
-
npx det-acp proxy --policy ./policy.yaml --dir /path/to/project
|
|
237
|
+
npx det-acp proxy --policy ./policy.yaml --dir /path/to/project
|
|
182
238
|
```
|
|
183
239
|
|
|
184
|
-
|
|
240
|
+
<details>
|
|
241
|
+
<summary><strong>Full config mode</strong></summary>
|
|
242
|
+
|
|
243
|
+
For advanced setups with multiple backends, SSE transport, etc.:
|
|
185
244
|
|
|
186
245
|
```bash
|
|
187
|
-
# Create a proxy config
|
|
188
246
|
cat > mcp-proxy.config.yaml << 'EOF'
|
|
189
247
|
policy: ./agent.policy.yaml
|
|
190
248
|
ledger_dir: ./.det-acp/ledgers
|
|
@@ -196,28 +254,30 @@ backends:
|
|
|
196
254
|
args: ["-y", "@modelcontextprotocol/server-filesystem", "./src"]
|
|
197
255
|
EOF
|
|
198
256
|
|
|
199
|
-
# Start the proxy
|
|
200
257
|
npx det-acp proxy ./mcp-proxy.config.yaml
|
|
201
258
|
```
|
|
202
259
|
|
|
260
|
+
</details>
|
|
261
|
+
|
|
203
262
|
### Shell Proxy
|
|
204
263
|
|
|
205
264
|
Execute commands through the policy gateway:
|
|
206
265
|
|
|
207
266
|
```bash
|
|
208
|
-
# Allowed
|
|
209
|
-
npx det-acp exec ./agent.policy.yaml
|
|
210
|
-
|
|
211
|
-
# Denied (rm -rf is forbidden)
|
|
212
|
-
npx det-acp exec ./agent.policy.yaml rm -rf /tmp
|
|
267
|
+
npx det-acp exec ./agent.policy.yaml echo "hello" # Allowed
|
|
268
|
+
npx det-acp exec ./agent.policy.yaml rm -rf /tmp # Denied (forbidden)
|
|
213
269
|
```
|
|
214
270
|
|
|
215
271
|
### HTTP Session Server
|
|
216
272
|
|
|
217
273
|
```bash
|
|
218
|
-
# Start the server
|
|
219
274
|
npx det-acp serve --port 3100
|
|
275
|
+
```
|
|
220
276
|
|
|
277
|
+
<details>
|
|
278
|
+
<summary><strong>HTTP API Examples</strong></summary>
|
|
279
|
+
|
|
280
|
+
```bash
|
|
221
281
|
# Create a session
|
|
222
282
|
curl -X POST http://localhost:3100/sessions \
|
|
223
283
|
-H "Content-Type: application/json" \
|
|
@@ -237,97 +297,104 @@ curl -X POST http://localhost:3100/sessions/<session-id>/record \
|
|
|
237
297
|
curl -X POST http://localhost:3100/sessions/<session-id>/terminate
|
|
238
298
|
```
|
|
239
299
|
|
|
240
|
-
|
|
300
|
+
</details>
|
|
241
301
|
|
|
242
|
-
|
|
243
|
-
# Set up governance for an integration (generates all config files)
|
|
244
|
-
npx det-acp init cursor # or codex, claude-code
|
|
245
|
-
npx det-acp init cursor --policy ./my-policy.yaml # use custom policy
|
|
302
|
+
### CLI Reference
|
|
246
303
|
|
|
247
|
-
|
|
248
|
-
npx det-acp
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
npx det-acp proxy --policy
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
npx det-acp
|
|
255
|
-
|
|
256
|
-
# Execute a command through shell proxy
|
|
257
|
-
npx det-acp exec ./agent.policy.yaml echo "hello"
|
|
258
|
-
|
|
259
|
-
# View audit report from ledger
|
|
260
|
-
npx det-acp report ./.det-acp/ledgers/<session-id>.jsonl
|
|
261
|
-
|
|
262
|
-
# Start HTTP session server
|
|
263
|
-
npx det-acp serve
|
|
304
|
+
```bash
|
|
305
|
+
npx det-acp init <agent> # Set up governance (cursor, codex, claude-code)
|
|
306
|
+
npx det-acp init <agent> --policy <file> # Use custom policy
|
|
307
|
+
npx det-acp validate <policy-file> # Validate a policy
|
|
308
|
+
npx det-acp proxy --policy <policy-file> # Start MCP proxy (simplified)
|
|
309
|
+
npx det-acp proxy <config-file> # Start MCP proxy (full config)
|
|
310
|
+
npx det-acp exec <policy-file> <command> # Execute via shell proxy
|
|
311
|
+
npx det-acp report <ledger-file> # View audit report
|
|
312
|
+
npx det-acp serve [--port <port>] # Start HTTP session server
|
|
264
313
|
```
|
|
265
314
|
|
|
315
|
+
---
|
|
316
|
+
|
|
266
317
|
## Architecture
|
|
267
318
|
|
|
268
319
|
### Component Architecture
|
|
269
320
|
|
|
270
321
|
```mermaid
|
|
271
322
|
graph TB
|
|
272
|
-
subgraph
|
|
323
|
+
subgraph External["External Systems"]
|
|
273
324
|
BackendMCP["Backend MCP Servers"]
|
|
274
|
-
|
|
325
|
+
Approvers["Human / Webhook Approvers"]
|
|
275
326
|
end
|
|
276
327
|
|
|
277
|
-
subgraph
|
|
278
|
-
MCPProxy["
|
|
279
|
-
|
|
280
|
-
HTTPServer["HTTP Server
|
|
281
|
-
LibrarySDK["Library SDK
|
|
328
|
+
subgraph Integration["Integration Layer"]
|
|
329
|
+
MCPProxy["MCP Proxy Server"]
|
|
330
|
+
ShellProxy["Shell Proxy"]
|
|
331
|
+
HTTPServer["HTTP Server"]
|
|
332
|
+
LibrarySDK["Library SDK"]
|
|
282
333
|
end
|
|
283
334
|
|
|
284
|
-
subgraph
|
|
285
|
-
Gateway["
|
|
286
|
-
SessionMgr["
|
|
287
|
-
PolicyEval["
|
|
288
|
-
GateMgr["
|
|
289
|
-
|
|
335
|
+
subgraph Core["Core Engine"]
|
|
336
|
+
Gateway["Agent Gateway"]
|
|
337
|
+
SessionMgr["Session Manager"]
|
|
338
|
+
PolicyEval["Policy Evaluator"]
|
|
339
|
+
GateMgr["Gate Manager"]
|
|
340
|
+
ActionReg["Action Registry"]
|
|
290
341
|
end
|
|
291
342
|
|
|
292
|
-
subgraph
|
|
293
|
-
Ledger["
|
|
294
|
-
Rollback["
|
|
343
|
+
subgraph Infra["Infrastructure"]
|
|
344
|
+
Ledger["Evidence Ledger<br/>(JSONL + SHA-256)"]
|
|
345
|
+
Rollback["Rollback Manager"]
|
|
295
346
|
end
|
|
296
347
|
|
|
297
|
-
subgraph
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
348
|
+
subgraph Tools["Tool Adapters"]
|
|
349
|
+
subgraph FileTools["File Operations"]
|
|
350
|
+
FR["file:read"]
|
|
351
|
+
FW["file:write"]
|
|
352
|
+
FD["file:delete"]
|
|
353
|
+
FM["file:move"]
|
|
354
|
+
FC["file:copy"]
|
|
355
|
+
end
|
|
356
|
+
subgraph DirTools["Directory Operations"]
|
|
357
|
+
DL["directory:list"]
|
|
358
|
+
DC["directory:create"]
|
|
359
|
+
end
|
|
360
|
+
subgraph GitTools["Git Operations"]
|
|
361
|
+
GD["git:diff"]
|
|
362
|
+
GA["git:apply"]
|
|
363
|
+
GC["git:commit"]
|
|
364
|
+
GS["git:status"]
|
|
365
|
+
end
|
|
366
|
+
subgraph NetTools["Network & System"]
|
|
367
|
+
CR["command:run"]
|
|
368
|
+
HR["http:request"]
|
|
369
|
+
ND["network:dns"]
|
|
370
|
+
ER["env:read"]
|
|
371
|
+
AE["archive:extract"]
|
|
372
|
+
end
|
|
304
373
|
end
|
|
305
374
|
|
|
306
375
|
MCPProxy --> Gateway
|
|
307
|
-
|
|
376
|
+
ShellProxy --> Gateway
|
|
308
377
|
HTTPServer --> Gateway
|
|
309
378
|
LibrarySDK --> Gateway
|
|
310
379
|
|
|
311
380
|
Gateway --> SessionMgr
|
|
312
|
-
Gateway -->
|
|
381
|
+
Gateway --> ActionReg
|
|
313
382
|
Gateway --> GateMgr
|
|
314
383
|
|
|
315
384
|
SessionMgr --> PolicyEval
|
|
316
385
|
SessionMgr --> GateMgr
|
|
317
386
|
SessionMgr --> Ledger
|
|
318
387
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
Registry --> GitDiff
|
|
324
|
-
Registry --> GitApply
|
|
388
|
+
ActionReg --> FileTools
|
|
389
|
+
ActionReg --> DirTools
|
|
390
|
+
ActionReg --> GitTools
|
|
391
|
+
ActionReg --> NetTools
|
|
325
392
|
|
|
326
|
-
Rollback -->
|
|
393
|
+
Rollback --> ActionReg
|
|
327
394
|
Rollback --> Ledger
|
|
328
395
|
|
|
329
396
|
MCPProxy --> BackendMCP
|
|
330
|
-
GateMgr -->
|
|
397
|
+
GateMgr --> Approvers
|
|
331
398
|
```
|
|
332
399
|
|
|
333
400
|
### Action Evaluation Flow
|
|
@@ -335,83 +402,76 @@ graph TB
|
|
|
335
402
|
```mermaid
|
|
336
403
|
sequenceDiagram
|
|
337
404
|
participant Agent
|
|
338
|
-
participant Integration
|
|
339
|
-
participant Gateway as
|
|
340
|
-
participant Session as
|
|
341
|
-
participant Policy as
|
|
342
|
-
participant Gate as
|
|
343
|
-
participant Ledger as
|
|
344
|
-
|
|
345
|
-
Agent->>Integration: Action request (tool, input)
|
|
346
|
-
Integration->>Gateway: evaluate(sessionId, action)
|
|
347
|
-
Gateway->>Session: evaluate(sessionId, action)
|
|
348
|
-
|
|
349
|
-
Session->>Policy: evaluateSessionAction(action
|
|
350
|
-
|
|
351
|
-
Policy
|
|
352
|
-
|
|
353
|
-
Session
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Gate-->>Session:
|
|
361
|
-
|
|
405
|
+
participant Integration
|
|
406
|
+
participant Gateway as Agent Gateway
|
|
407
|
+
participant Session as Session Manager
|
|
408
|
+
participant Policy as Policy Evaluator
|
|
409
|
+
participant Gate as Gate Manager
|
|
410
|
+
participant Ledger as Evidence Ledger
|
|
411
|
+
|
|
412
|
+
Agent ->> Integration: Action request (tool, input)
|
|
413
|
+
Integration ->> Gateway: evaluate(sessionId, action)
|
|
414
|
+
Gateway ->> Session: evaluate(sessionId, action)
|
|
415
|
+
|
|
416
|
+
Session ->> Policy: evaluateSessionAction(action)
|
|
417
|
+
|
|
418
|
+
Note right of Policy: 1. Session state check<br/>2. Rate limits & escalation<br/>3. Forbidden patterns<br/>4. Capability & scope match<br/>5. Budget limits<br/>6. Gate lookup
|
|
419
|
+
|
|
420
|
+
Policy -->> Session: allow / deny / gate
|
|
421
|
+
|
|
422
|
+
Session ->> Ledger: append(action:evaluate)
|
|
423
|
+
|
|
424
|
+
alt Gate required
|
|
425
|
+
Session ->> Gate: requestApproval(action, gate)
|
|
426
|
+
alt Approved
|
|
427
|
+
Gate -->> Session: approved
|
|
428
|
+
else Pending
|
|
429
|
+
Gate -->> Session: pending
|
|
430
|
+
Note over Agent, Gate: Session paused until resolved
|
|
362
431
|
end
|
|
363
432
|
end
|
|
364
433
|
|
|
365
|
-
Session-->>Gateway: EvaluateResponse
|
|
366
|
-
Gateway-->>Integration: decision + reasons
|
|
367
|
-
Integration-->>Agent: allow / deny / gate
|
|
368
|
-
|
|
369
|
-
alt
|
|
370
|
-
Note over Agent:
|
|
371
|
-
Agent->>Integration: recordResult(actionId, result)
|
|
372
|
-
Integration->>Gateway: recordResult(sessionId, actionId, result)
|
|
373
|
-
Gateway->>Session: recordResult(
|
|
374
|
-
Session->>Session: Update budget
|
|
375
|
-
Session->>Ledger: append(
|
|
434
|
+
Session -->> Gateway: EvaluateResponse
|
|
435
|
+
Gateway -->> Integration: decision + reasons
|
|
436
|
+
Integration -->> Agent: allow / deny / gate
|
|
437
|
+
|
|
438
|
+
alt Allowed
|
|
439
|
+
Note over Agent: Executes action externally
|
|
440
|
+
Agent ->> Integration: recordResult(actionId, result)
|
|
441
|
+
Integration ->> Gateway: recordResult(sessionId, actionId, result)
|
|
442
|
+
Gateway ->> Session: recordResult(result)
|
|
443
|
+
Session ->> Session: Update budget tracking
|
|
444
|
+
Session ->> Ledger: append(action:result)
|
|
376
445
|
end
|
|
377
446
|
|
|
378
447
|
opt Session complete
|
|
379
|
-
Agent->>Integration: terminateSession()
|
|
380
|
-
Integration->>Gateway:
|
|
381
|
-
Gateway->>Session: terminate(sessionId)
|
|
382
|
-
Session->>Ledger: append(
|
|
383
|
-
Session-->>
|
|
384
|
-
Gateway-->>Integration: SessionReport
|
|
385
|
-
Integration-->>Agent: SessionReport
|
|
448
|
+
Agent ->> Integration: terminateSession()
|
|
449
|
+
Integration ->> Gateway: terminate(sessionId)
|
|
450
|
+
Gateway ->> Session: terminate(sessionId)
|
|
451
|
+
Session ->> Ledger: append(session:terminate)
|
|
452
|
+
Session -->> Agent: Session Report
|
|
386
453
|
end
|
|
387
454
|
```
|
|
388
455
|
|
|
389
456
|
### Session Lifecycle
|
|
390
457
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
458
|
+
```mermaid
|
|
459
|
+
stateDiagram-v2
|
|
460
|
+
[*] --> Created: createSession()
|
|
461
|
+
Created --> Evaluating: evaluate(action)
|
|
462
|
+
Evaluating --> Allowed: policy allows
|
|
463
|
+
Evaluating --> Denied: policy denies
|
|
464
|
+
Evaluating --> Gated: gate required
|
|
465
|
+
Gated --> Allowed: approved
|
|
466
|
+
Gated --> Denied: rejected
|
|
467
|
+
Allowed --> Recording: recordResult()
|
|
468
|
+
Recording --> Evaluating: next action
|
|
469
|
+
Denied --> Evaluating: next action
|
|
470
|
+
Recording --> Terminated: terminateSession()
|
|
471
|
+
Evaluating --> Terminated: terminateSession()
|
|
472
|
+
Terminated --> [*]
|
|
397
473
|
```
|
|
398
474
|
|
|
399
|
-
Sessions track:
|
|
400
|
-
|
|
401
|
-
- Cumulative budget (runtime, files changed, cost)
|
|
402
|
-
- Action history (for rate limiting and escalation)
|
|
403
|
-
- Pending gates (human approval required)
|
|
404
|
-
- Evidence ledger (tamper-evident audit trail)
|
|
405
|
-
|
|
406
|
-
### Integration Modes
|
|
407
|
-
|
|
408
|
-
| Mode | How it works | Best for |
|
|
409
|
-
| --------------------- | ----------------------------------------------- | ----------------------------------- |
|
|
410
|
-
| **MCP Proxy** | Transparent proxy between agent and MCP servers | Cursor, Claude Code, any MCP client |
|
|
411
|
-
| **Shell Proxy** | Command wrapper that validates before executing | CLI agents, shell-based workflows |
|
|
412
|
-
| **HTTP API** | REST endpoints for session management | Any language, custom integrations |
|
|
413
|
-
| **Library SDK** | TypeScript API for in-process governance | Custom TypeScript agents |
|
|
414
|
-
|
|
415
475
|
### Evidence Ledger
|
|
416
476
|
|
|
417
477
|
Every action produces an immutable audit record in JSONL format with SHA-256 hash chaining:
|
|
@@ -424,42 +484,89 @@ Every action produces an immutable audit record in JSONL format with SHA-256 has
|
|
|
424
484
|
|
|
425
485
|
If any entry is tampered with, the hash chain breaks and integrity verification fails.
|
|
426
486
|
|
|
427
|
-
|
|
487
|
+
---
|
|
488
|
+
|
|
489
|
+
## Policy DSL Reference
|
|
490
|
+
|
|
491
|
+
| Section | Purpose |
|
|
492
|
+
|---------|---------|
|
|
493
|
+
| `capabilities` | Allowed tools and their scoped paths, binaries, or domains |
|
|
494
|
+
| `limits` | Runtime, cost, file change, and retry budgets |
|
|
495
|
+
| `gates` | Actions requiring human or webhook approval |
|
|
496
|
+
| `evidence` | Artifacts that must be recorded (checksums, diffs) |
|
|
497
|
+
| `forbidden` | Patterns that are always blocked |
|
|
498
|
+
| `session` | Max actions, rate limits, escalation rules |
|
|
499
|
+
| `remediation` | Error handling rules and fallback chains |
|
|
500
|
+
|
|
501
|
+
See [examples/](examples/) for complete policy files.
|
|
502
|
+
|
|
503
|
+
---
|
|
504
|
+
|
|
505
|
+
## Built-in Tool Adapters
|
|
506
|
+
|
|
507
|
+
### File Operations
|
|
508
|
+
|
|
509
|
+
| Tool | Description | Rollback |
|
|
510
|
+
|------|-------------|----------|
|
|
511
|
+
| `file:read` | Read files within scoped paths | N/A (read-only) |
|
|
512
|
+
| `file:write` | Write files with backup for rollback | Restores previous content |
|
|
513
|
+
| `file:delete` | Delete files within scoped paths | Restores file from backup |
|
|
514
|
+
| `file:move` | Move/rename files within scoped paths | Moves file back to original location |
|
|
515
|
+
| `file:copy` | Copy files within scoped paths | Removes copied file |
|
|
516
|
+
|
|
517
|
+
### Directory Operations
|
|
518
|
+
|
|
519
|
+
| Tool | Description | Rollback |
|
|
520
|
+
|------|-------------|----------|
|
|
521
|
+
| `directory:list` | List files and directories within scoped paths | N/A (read-only) |
|
|
522
|
+
| `directory:create` | Create directories within scoped paths | Removes created directories |
|
|
523
|
+
|
|
524
|
+
### Command Execution
|
|
428
525
|
|
|
429
|
-
|
|
526
|
+
| Tool | Description | Rollback |
|
|
527
|
+
|------|-------------|----------|
|
|
528
|
+
| `command:run` | Execute allow-listed binaries with timeout | Compensation actions |
|
|
430
529
|
|
|
431
|
-
|
|
432
|
-
| ---------------- | ---------------------------------------------------------------- |
|
|
433
|
-
| `capabilities` | What tools the agent can use and where |
|
|
434
|
-
| `limits` | Runtime, cost, file change, and retry budgets |
|
|
435
|
-
| `gates` | Actions that require human/webhook approval |
|
|
436
|
-
| `evidence` | What artifacts must be recorded |
|
|
437
|
-
| `forbidden` | Patterns that are always blocked |
|
|
438
|
-
| `session` | Session-level constraints (max actions, rate limits, escalation) |
|
|
439
|
-
| `remediation` | Error handling rules and fallback chains |
|
|
530
|
+
### Git Operations
|
|
440
531
|
|
|
441
|
-
|
|
532
|
+
| Tool | Description | Rollback |
|
|
533
|
+
|------|-------------|----------|
|
|
534
|
+
| `git:diff` | Get git diff output | N/A (read-only) |
|
|
535
|
+
| `git:apply` | Apply git patches with stash-based rollback | `git checkout . && git stash pop` |
|
|
536
|
+
| `git:commit` | Stage and commit changes | `git reset --soft HEAD~1` |
|
|
537
|
+
| `git:status` | Get working tree status | N/A (read-only) |
|
|
442
538
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
|
446
|
-
|
|
447
|
-
| `
|
|
448
|
-
| `
|
|
449
|
-
|
|
450
|
-
|
|
539
|
+
### Network & HTTP
|
|
540
|
+
|
|
541
|
+
| Tool | Description | Rollback |
|
|
542
|
+
|------|-------------|----------|
|
|
543
|
+
| `http:request` | HTTP requests to allow-listed domains | Compensation actions |
|
|
544
|
+
| `network:dns` | DNS lookups for allow-listed domains | N/A (read-only) |
|
|
545
|
+
|
|
546
|
+
### Environment & System
|
|
547
|
+
|
|
548
|
+
| Tool | Description | Rollback |
|
|
549
|
+
|------|-------------|----------|
|
|
550
|
+
| `env:read` | Read environment variables with auto-redaction of secrets | N/A (read-only) |
|
|
551
|
+
| `archive:extract` | Extract tar/zip archives within scoped paths | Removes extracted files |
|
|
552
|
+
|
|
553
|
+
---
|
|
451
554
|
|
|
452
|
-
|
|
555
|
+
## Custom Tool Adapters
|
|
453
556
|
|
|
454
|
-
Extend the `ToolAdapter` base class:
|
|
557
|
+
Extend the `ToolAdapter` base class to add your own tools:
|
|
455
558
|
|
|
456
559
|
```typescript
|
|
457
|
-
import { ToolAdapter } from '
|
|
560
|
+
import { ToolAdapter } from '@det-acp/core';
|
|
561
|
+
import { z } from 'zod';
|
|
458
562
|
|
|
459
563
|
class MyCustomTool extends ToolAdapter {
|
|
460
|
-
name = 'custom:mytool';
|
|
461
|
-
description = 'My custom tool';
|
|
462
|
-
inputSchema = z.object({
|
|
564
|
+
readonly name = 'custom:mytool';
|
|
565
|
+
readonly description = 'My custom tool';
|
|
566
|
+
readonly inputSchema = z.object({
|
|
567
|
+
target: z.string().min(1),
|
|
568
|
+
options: z.record(z.string()).optional(),
|
|
569
|
+
});
|
|
463
570
|
|
|
464
571
|
validate(input, policy) { /* ... */ }
|
|
465
572
|
async dryRun(input, ctx) { /* ... */ }
|
|
@@ -471,22 +578,34 @@ class MyCustomTool extends ToolAdapter {
|
|
|
471
578
|
gateway.getRegistry().register(new MyCustomTool());
|
|
472
579
|
```
|
|
473
580
|
|
|
581
|
+
Every tool adapter follows the execution lifecycle: **validate** -> **dryRun** -> **(gate check)** -> **execute** -> **verify**. Each step is recorded in the evidence ledger.
|
|
582
|
+
|
|
583
|
+
---
|
|
584
|
+
|
|
474
585
|
## Development
|
|
475
586
|
|
|
476
587
|
```bash
|
|
477
|
-
# Install dependencies
|
|
478
|
-
npm
|
|
588
|
+
npm install # Install dependencies
|
|
589
|
+
npm run lint # Type check (TypeScript strict)
|
|
590
|
+
npm test # Run tests (Vitest)
|
|
591
|
+
npm run build # Build
|
|
592
|
+
```
|
|
479
593
|
|
|
480
|
-
|
|
481
|
-
npm run lint
|
|
594
|
+
---
|
|
482
595
|
|
|
483
|
-
|
|
484
|
-
npm test
|
|
596
|
+
## Contributing
|
|
485
597
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
598
|
+
Contributions are welcome! Please follow these guidelines:
|
|
599
|
+
|
|
600
|
+
1. **Fork** the repository and create a feature branch
|
|
601
|
+
2. **Follow** the coding standards (TypeScript strict, ESM, Zod validation)
|
|
602
|
+
3. **Write tests** mirroring `src/` structure under `tests/`
|
|
603
|
+
4. **Run** `npm test && npm run lint` before submitting
|
|
604
|
+
5. **Use** [Conventional Commits](https://www.conventionalcommits.org/) for commit messages
|
|
605
|
+
6. **Open a PR** with a clear description of changes
|
|
606
|
+
|
|
607
|
+
---
|
|
489
608
|
|
|
490
609
|
## License
|
|
491
610
|
|
|
492
|
-
MIT
|
|
611
|
+
[MIT](LICENSE)
|