@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.
Files changed (57) hide show
  1. package/README.md +332 -213
  2. package/dist/engine/action-registry.d.ts.map +1 -1
  3. package/dist/engine/action-registry.js +20 -0
  4. package/dist/engine/action-registry.js.map +1 -1
  5. package/dist/index.d.ts +11 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +11 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/tools/archive-extract.d.ts +45 -0
  10. package/dist/tools/archive-extract.d.ts.map +1 -0
  11. package/dist/tools/archive-extract.js +246 -0
  12. package/dist/tools/archive-extract.js.map +1 -0
  13. package/dist/tools/directory-create.d.ts +33 -0
  14. package/dist/tools/directory-create.d.ts.map +1 -0
  15. package/dist/tools/directory-create.js +145 -0
  16. package/dist/tools/directory-create.js.map +1 -0
  17. package/dist/tools/directory-list.d.ts +32 -0
  18. package/dist/tools/directory-list.d.ts.map +1 -0
  19. package/dist/tools/directory-list.js +114 -0
  20. package/dist/tools/directory-list.js.map +1 -0
  21. package/dist/tools/env-read.d.ts +31 -0
  22. package/dist/tools/env-read.d.ts.map +1 -0
  23. package/dist/tools/env-read.js +108 -0
  24. package/dist/tools/env-read.js.map +1 -0
  25. package/dist/tools/file-copy.d.ts +30 -0
  26. package/dist/tools/file-copy.d.ts.map +1 -0
  27. package/dist/tools/file-copy.js +170 -0
  28. package/dist/tools/file-copy.js.map +1 -0
  29. package/dist/tools/file-delete.d.ts +27 -0
  30. package/dist/tools/file-delete.d.ts.map +1 -0
  31. package/dist/tools/file-delete.js +143 -0
  32. package/dist/tools/file-delete.js.map +1 -0
  33. package/dist/tools/file-move.d.ts +30 -0
  34. package/dist/tools/file-move.d.ts.map +1 -0
  35. package/dist/tools/file-move.js +167 -0
  36. package/dist/tools/file-move.js.map +1 -0
  37. package/dist/tools/git-commit.d.ts +33 -0
  38. package/dist/tools/git-commit.d.ts.map +1 -0
  39. package/dist/tools/git-commit.js +176 -0
  40. package/dist/tools/git-commit.js.map +1 -0
  41. package/dist/tools/git-status.d.ts +29 -0
  42. package/dist/tools/git-status.d.ts.map +1 -0
  43. package/dist/tools/git-status.js +159 -0
  44. package/dist/tools/git-status.js.map +1 -0
  45. package/dist/tools/network-dns.d.ts +50 -0
  46. package/dist/tools/network-dns.d.ts.map +1 -0
  47. package/dist/tools/network-dns.js +122 -0
  48. package/dist/tools/network-dns.js.map +1 -0
  49. package/dist/types.d.ts +1 -1
  50. package/dist/types.d.ts.map +1 -1
  51. package/examples/coding-agent.policy.yaml +44 -0
  52. package/examples/data-analyst.policy.yaml +160 -0
  53. package/examples/devops-deploy.policy.yaml +68 -0
  54. package/examples/infrastructure-manager.policy.yaml +209 -0
  55. package/examples/security-audit.policy.yaml +152 -0
  56. package/examples/video-upscaler.policy.yaml +45 -0
  57. package/package.json +4 -4
package/README.md CHANGED
@@ -1,67 +1,96 @@
1
1
  # Deterministic Agent Control Protocol
2
2
 
3
- A governance gateway for AI agents — makes any agent bounded, auditable, reversible, and explainable.
3
+ [![Stars](https://img.shields.io/github/stars/elliot35/deterministic-agent-control-protocol?style=flat)](https://github.com/elliot35/deterministic-agent-control-protocol/stargazers)
4
+ [![Forks](https://img.shields.io/github/forks/elliot35/deterministic-agent-control-protocol?style=flat)](https://github.com/elliot35/deterministic-agent-control-protocol/network/members)
5
+ [![Contributors](https://img.shields.io/github/contributors/elliot35/deterministic-agent-control-protocol?style=flat)](https://github.com/elliot35/deterministic-agent-control-protocol/graphs/contributors)
6
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
+ [![npm version](https://img.shields.io/npm/v/@det-acp/core)](https://www.npmjs.com/package/@det-acp/core)
8
+ ![TypeScript](https://img.shields.io/badge/-TypeScript-3178C6?logo=typescript&logoColor=white)
9
+ ![Node.js](https://img.shields.io/badge/-Node.js-339933?logo=node.js&logoColor=white)
4
10
 
5
- Works transparently with **Cursor**, **Claude Code**, **Codex**, and any MCP-compatible agent via the MCP proxy. Also supports shell command governance and a language-agnostic HTTP API.
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
- Instead of agents executing tools directly, every action flows through the control plane:
37
+ Agents never execute tools directly. Every action flows through the control plane for evaluation, enforcement, and audit:
10
38
 
11
- ```
12
- Agent → Control Protocol (evaluate) → allow / deny / gate
13
- (if allowed)
14
- Agent executes action
15
-
16
- Control Protocol (record result)
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 control protocol **does not execute** actions it evaluates them against a policy, enforces session-level budgets, requires human approval for risky actions, and records everything in a tamper-evident audit ledger.
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
- - **Bounded**: Agents can only perform allowed actions in allowed scopes
24
- - **Session-Aware**: Budget, rate limits, and escalation rules across the full interaction
25
- - **Auditable**: Every action logged in a tamper-evident ledger with SHA-256 hash chaining
26
- - **Reversible**: Compensation plans for undoing executed actions
27
- - **Explainable**: Full reporting what was allowed, denied, gated, and why
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 install deterministic-agent-control-protocol
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 cursor
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. The only file you may want to edit is `policy.yaml` — everything else is handled automatically.
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 (Cursor, Claude Code, etc.) to pick up the MCP server.
89
+ > After running `init`, restart your agent to pick up the MCP server.
61
90
 
62
91
  ### Define a Policy
63
92
 
64
- Create an `agent.policy.yaml`:
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 'deterministic-agent-control-protocol';
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 (or via your agent)
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
- // When done, terminate and get report
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 integration guides for popular AI agents. Each integration includes a policy, config templates, governance rules, test sandbox, and step-by-step instructions.
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 | Integration Mode | Governance Level | Guide |
155
- | --------------------- | ------------------------------------- | ---------------- | --------------------------------------------------- |
156
- | **Cursor** | MCP Proxy + Cursor Rules | Soft | [integrations/cursor/](integrations/cursor/) |
157
- | **Codex CLI** | MCP Proxy + AGENTS.md + OS Sandbox | Soft + Sandbox | [integrations/codex/](integrations/codex/) |
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** | HTTP API + Skill + Docker Sandbox | Hard | [integrations/openclaw/](integrations/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
- ### Governance Levels Explained
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
- - **Soft**: The LLM is instructed (via rules/instructions files) to prefer governed tools. Effective in practice, but a creative prompt could theoretically bypass it.
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 the general MCP Proxy setup below.
199
+ For any MCP-compatible agent not listed above, see [MCP Proxy (General)](#mcp-proxy-general).
168
200
 
169
201
  ---
170
202
 
171
- ## Other Integration Modes
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
- The MCP proxy works with any MCP-compatible client, not just Cursor.
231
+ Works with any MCP-compatible client.
176
232
 
177
- **Simplified mode** — just point it at a policy file and it auto-configures a filesystem backend:
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 # custom project dir
237
+ npx det-acp proxy --policy ./policy.yaml --dir /path/to/project
182
238
  ```
183
239
 
184
- **Full config mode** — for advanced setups with multiple backends, SSE transport, etc.:
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 echo "hello"
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
- ### CLI
300
+ </details>
241
301
 
242
- ```bash
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
- # Validate a policy
248
- npx det-acp validate ./agent.policy.yaml
249
-
250
- # Start MCP proxy (simplified — just a policy file)
251
- npx det-acp proxy --policy ./policy.yaml
252
-
253
- # Start MCP proxy (full config file for advanced use)
254
- npx det-acp proxy ./mcp-proxy.config.yaml
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 ExternalSystems [External Systems]
323
+ subgraph External["External Systems"]
273
324
  BackendMCP["Backend MCP Servers"]
274
- HumanApprover["Human / Webhook Approvers"]
325
+ Approvers["Human / Webhook Approvers"]
275
326
  end
276
327
 
277
- subgraph IntegrationLayer [Integration Layer]
278
- MCPProxy["MCPProxyServer"]
279
- ShellProxyNode["ShellProxy"]
280
- HTTPServer["HTTP Server - Fastify"]
281
- LibrarySDK["Library SDK - TypeScript"]
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 CoreEngine [Core Engine]
285
- Gateway["AgentGateway"]
286
- SessionMgr["SessionManager"]
287
- PolicyEval["PolicyEvaluator"]
288
- GateMgr["GateManager"]
289
- Registry["ActionRegistry"]
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 InfraLayer [Infrastructure]
293
- Ledger["EvidenceLedger - JSONL + SHA-256 Hash Chain"]
294
- Rollback["RollbackManager"]
343
+ subgraph Infra["Infrastructure"]
344
+ Ledger["Evidence Ledger<br/>(JSONL + SHA-256)"]
345
+ Rollback["Rollback Manager"]
295
346
  end
296
347
 
297
- subgraph ToolAdapters [Tool Adapters]
298
- FileRead["file:read"]
299
- FileWrite["file:write"]
300
- CommandRun["command:run"]
301
- HttpReq["http:request"]
302
- GitDiff["git:diff"]
303
- GitApply["git:apply"]
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
- ShellProxyNode --> Gateway
376
+ ShellProxy --> Gateway
308
377
  HTTPServer --> Gateway
309
378
  LibrarySDK --> Gateway
310
379
 
311
380
  Gateway --> SessionMgr
312
- Gateway --> Registry
381
+ Gateway --> ActionReg
313
382
  Gateway --> GateMgr
314
383
 
315
384
  SessionMgr --> PolicyEval
316
385
  SessionMgr --> GateMgr
317
386
  SessionMgr --> Ledger
318
387
 
319
- Registry --> FileRead
320
- Registry --> FileWrite
321
- Registry --> CommandRun
322
- Registry --> HttpReq
323
- Registry --> GitDiff
324
- Registry --> GitApply
388
+ ActionReg --> FileTools
389
+ ActionReg --> DirTools
390
+ ActionReg --> GitTools
391
+ ActionReg --> NetTools
325
392
 
326
- Rollback --> Registry
393
+ Rollback --> ActionReg
327
394
  Rollback --> Ledger
328
395
 
329
396
  MCPProxy --> BackendMCP
330
- GateMgr --> HumanApprover
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 as Integration Layer
339
- participant Gateway as AgentGateway
340
- participant Session as SessionManager
341
- participant Policy as PolicyEvaluator
342
- participant Gate as GateManager
343
- participant Ledger as EvidenceLedger
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, policy, session)
350
- Note right of Policy: 1. Session state check<br/>2. Session constraints<br/>(max_actions, rate_limit, escalation)<br/>3. Forbidden patterns<br/>4. Capability + scope<br/>5. Budget limits<br/>6. Gate lookup
351
- Policy-->>Session: ValidationResult (allow / deny / gate)
352
-
353
- Session->>Ledger: append("action:evaluate", ...)
354
-
355
- alt Verdict is gate
356
- Session->>Gate: requestApproval(sessionId, actionId, action, gate)
357
- alt Auto or handler resolves
358
- Gate-->>Session: approved / rejected
359
- else Human approval pending
360
- Gate-->>Session: pending
361
- Note over Agent,Gate: Session paused until gate resolved
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 Decision is allow
370
- Note over Agent: Agent executes action externally
371
- Agent->>Integration: recordResult(actionId, result)
372
- Integration->>Gateway: recordResult(sessionId, actionId, result)
373
- Gateway->>Session: recordResult(sessionId, actionId, result)
374
- Session->>Session: Update budget (filesChanged, outputBytes)
375
- Session->>Ledger: append("action:result", ...)
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: terminateSession(sessionId)
381
- Gateway->>Session: terminate(sessionId)
382
- Session->>Ledger: append("session:terminate", ...)
383
- Session-->>Gateway: SessionReport
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
- Every interaction is governed through a session:
392
-
393
- ```
394
- Create Session Evaluate Actions → Record Results → Terminate
395
- (repeat) ↕ (repeat)
396
- deny / gate
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
- ### Policy DSL
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
- Policies define:
526
+ | Tool | Description | Rollback |
527
+ |------|-------------|----------|
528
+ | `command:run` | Execute allow-listed binaries with timeout | Compensation actions |
430
529
 
431
- | Section | Purpose |
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
- ### Built-in Tool Adapters
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
- | Tool | Description |
444
- | ---------------- | ------------------------------------------- |
445
- | `file:read` | Read files within scoped paths |
446
- | `file:write` | Write files with backup for rollback |
447
- | `command:run` | Execute allow-listed binaries with timeout |
448
- | `http:request` | HTTP requests to allow-listed domains |
449
- | `git:diff` | Get git diff output |
450
- | `git:apply` | Apply git patches with stash-based rollback |
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
- ### Custom Tool Adapters
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 'deterministic-agent-control-protocol';
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 install
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
- # Type check
481
- npm run lint
594
+ ---
482
595
 
483
- # Run tests
484
- npm test
596
+ ## Contributing
485
597
 
486
- # Build
487
- npm run build
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)