@letterblack/lbe-exec 1.2.7 → 1.2.10

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 (3) hide show
  1. package/README.md +258 -255
  2. package/dist/cli.js +0 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,255 +1,258 @@
1
- # @letterblack/lbe-exec
2
-
3
- **Local-first execution governance for AI agents.**
4
-
5
- > Use `@letterblack/lbe-exec` if you want LBE to control agent actions in a workspace.
6
- > Use `@letterblack/lbe-sdk` if you only need validation decisions inside your own tool.
7
-
8
- Every action any agent proposes — file write, shell command, anything — passes
9
- through a local validation gate before it can execute. One package, any agent,
10
- zero cloud dependency, no daemon required.
11
-
12
- ---
13
-
14
- ## The problem
15
-
16
- AI agents are capable. They can write files, invoke tools, and change state —
17
- and they will, the moment they are given a reason to. The host is the only
18
- thing standing between a plausible-looking request and irreversible damage.
19
-
20
- That is not enough.
21
-
22
- `@letterblack/lbe-exec` puts a deterministic local gate between what the agent
23
- proposes and what the system actually executes — fully in-process, no cloud
24
- dependency, no daemon required.
25
-
26
- ---
27
-
28
- ## How every request travels
29
-
30
- ![LBE gate sequence — Request flows through Policy, Identity, and Scope gates before reaching Action. A rejected request is routed to denial before it reaches execution.](https://unpkg.com/@letterblack/lbe-exec/assets/lbe-gates.jpg)
31
-
32
- Every request the agent produces enters a 7-gate pipeline. A failure at any
33
- gate returns a structured denial — the remaining gates are not evaluated.
34
-
35
- ```
36
- [1] Schema required fields and structural validity
37
-
38
- [2] Timestamp permitted clock-skew window (±10 minutes)
39
-
40
- [3] Key lifecycle trusted key, active, not expired
41
-
42
- [4] Signature Ed25519 request authenticity (signed locally, no network)
43
-
44
- [5] Rate limit per-requester sliding-window limit
45
-
46
- [6] Nonce single-use replay protection
47
-
48
- [7] Policy configured authorization (deny-wins)
49
-
50
- allow / deny / error — structured result returned to host
51
- ```
52
-
53
- The executor signs every request with a host-held key before validation.
54
- No key material leaves the process.
55
-
56
- ---
57
-
58
- ## When a request is approved
59
-
60
- ![Happy path — agent proposes action, identity confirmed, policy approved, governed write executed, audit chain extended, result returned to app.](https://unpkg.com/@letterblack/lbe-exec/assets/story-allow.jpg)
61
-
62
- When a request clears every gate:
63
-
64
- 1. The agent calls a convenience method — `lbe.writeFile()`, `lbe.runShell()`, etc.
65
- 2. The executor constructs and signs the request locally with a host-held Ed25519 key.
66
- 3. All seven gates pass. The project policy approves the action.
67
- 4. The write or command executes inside the configured project root.
68
- 5. The audit chain is extended — every approved action appends a hash-linked
69
- entry to `.lbe/audit.jsonl`, permanently verifiable, impossible to silently remove.
70
- 6. A structured result returns: whether it succeeded, which rules matched, and
71
- the audit entry identifier.
72
-
73
- The application stays in control. The executor decides whether the action was
74
- permitted and hands the answer back.
75
-
76
- ---
77
-
78
- ## When a request is blocked
79
-
80
- ![Deny path — rogue agent bypass attempt, policy gate immediate rejection, shell untouched, filesystem unchanged, immutable audit entry written, final state clean.](https://unpkg.com/@letterblack/lbe-exec/assets/story-deny.jpg)
81
-
82
- When a request fails any gate:
83
-
84
- 1. The agent attempts an action — whether by mistake, misconfiguration,
85
- or a deliberate bypass attempt.
86
- 2. The policy gate closes immediately. The request is denied before any adapter
87
- is reached.
88
- 3. The shell is untouched. The filesystem is unchanged. Nothing that should not
89
- have happened, happened.
90
- 4. The denial is written to the immutable audit log — chain sealed, evidence
91
- preserved.
92
- 5. The final state is clean, verifiable, and consistent.
93
-
94
- No partial execution. No silent failures. Denial is a first-class outcome, not
95
- an error.
96
-
97
- ---
98
-
99
- ## Policy — who writes the rules
100
-
101
- Only the host application writes policy. Agents may propose a rule — the
102
- proposal is returned as a plain object for the host to review. Until the host
103
- explicitly accepts and writes it, the proposal has no effect on any gate.
104
-
105
- This separation is intentional. An agent that can write its own policy rules
106
- is an agent that can grant itself permission.
107
-
108
- ---
109
-
110
- ## What this covers
111
-
112
- | Threat | Gate |
113
- |---|---|
114
- | Agent writes outside the project root | Scope — sandbox path check |
115
- | Replayed or stale request | Identity — nonce and timestamp |
116
- | Tampered or expired key | Identity — key lifecycle |
117
- | Excessive requests | Identity — rate limit |
118
- | Action not permitted by project policy | Policy — deny-wins evaluation |
119
- | Unauthorized shell command | Scope — explicit command allowlist |
120
- | Injected payload (eval, exec, __proto__) | Content scan before pipeline |
121
-
122
- ---
123
-
124
- ## Observer mode — start here
125
-
126
- Not ready to block? Start in observer mode. Every request is fully validated
127
- and logged exactly as it would be in enforcement — but nothing is blocked.
128
-
129
- Watch what the agent is doing before you decide what to deny. Your rules take
130
- effect the moment you switch to enforcement.
131
-
132
- ---
133
-
134
- ## Install
135
-
136
- ```bash
137
- npm install @letterblack/lbe-exec
138
- npx lbe-exec init
139
- ```
140
-
141
- `npx lbe-exec init` scans the project, writes `lbe.policy.json` in observer
142
- mode, generates `CLAUDE.md` and `.github/copilot-instructions.md` so every AI
143
- agent automatically discovers and follows governance, and creates
144
- `.lbe/AGENT_CONTRACT.md` as a machine-readable contract.
145
-
146
- Requires Node.js ≥ 20.9.0.
147
-
148
- ---
149
-
150
- ## Use in agent code
151
-
152
- ```js
153
- import { createLocalExecutor } from '@letterblack/lbe-exec';
154
-
155
- const lbe = createLocalExecutor({ rootDir: process.cwd() });
156
-
157
- // Every call routes through the full 7-gate pipeline
158
- await lbe.writeFile('output/report.md', content);
159
- await lbe.readFile('src/config.json');
160
- await lbe.patchFile('src/index.js', patch);
161
- await lbe.deleteFile('tmp/scratch.txt');
162
- await lbe.runShell('node', ['scripts/build.js']);
163
-
164
- // Result shape
165
- const result = await lbe.writeFile('output/result.md', data);
166
- // { ok: true, decision: 'allow', executed: true, auditId: '...' }
167
- // { ok: false, decision: 'deny', executed: false, error: { code, message } }
168
- ```
169
-
170
- No knowledge of the pipeline, request format, or policy internals required.
171
- All signing, validation, and auditing happens automatically.
172
-
173
- ### Options
174
-
175
- ```js
176
- const lbe = createLocalExecutor({
177
- rootDir: process.cwd(), // sandbox root — no writes escape this path
178
- mode: 'observe', // 'observe' (log only) or 'enforce' (block)
179
- shell: {
180
- allowCommands: ['node', 'npm'], // only these commands may run
181
- denyCommands: ['rm', 'curl'], // always blocked regardless of policy
182
- maxRequests: 20 // per-minute shell rate limit
183
- }
184
- });
185
- ```
186
-
187
- ### Policy management
188
-
189
- ```js
190
- // Propose a rule — returns an object for the host to review, writes nothing
191
- const proposal = lbe.policy.proposeRule({
192
- effect: 'deny',
193
- type: 'path',
194
- pattern: 'secrets/**',
195
- from: 'agent: these files should not be modified'
196
- });
197
-
198
- // Host accepts and writes the rule
199
- lbe.policy.addRule(proposal);
200
-
201
- // Read current policy
202
- const policy = lbe.policy.read();
203
-
204
- // Verify the audit chain has not been tampered with
205
- lbe.audit.verify();
206
- ```
207
-
208
- ---
209
-
210
- ## CLI reference
211
-
212
- ```bash
213
- npx lbe-exec init # create lbe.policy.json in observer mode
214
- npx lbe-exec status # show mode, rule count, and audit entry count
215
- npx lbe-exec enforce # switch to blocking
216
- npx lbe-exec observe # switch back to advisory
217
- npx lbe-exec policy # list active rules
218
- ```
219
-
220
- | Command | Purpose |
221
- |---|---|
222
- | `npx lbe-exec init` | Bootstrap governance — policy, keys, agent files |
223
- | `npx lbe-exec status` | Show mode, rule count, audit entry count |
224
- | `npx lbe-exec policy` | List active rules |
225
- | `npx lbe-exec observe` | Set advisory (log-only) mode |
226
- | `npx lbe-exec enforce` | Set blocking mode |
227
- | `npx lbe-exec execute` | Pipe a JSON request from stdin or `--input <file>` |
228
-
229
- ---
230
-
231
- ## What ships
232
-
233
- ```
234
- dist/index.js In-process executor — createLocalExecutor()
235
- dist/cli.js Local CLI (npx lbe-exec)
236
- dist/lbe_engine.wasm Verified WASM runtime binary
237
- dist/wasm.lock.json Runtime integrity lock (SHA-256 of wasm binary)
238
- assets/lbe-gates.png Gate sequence diagram
239
- assets/story-allow.png Approved-request storyboard
240
- assets/story-deny.png Blocked-request storyboard
241
- assets/runtime-boundary.svg Runtime boundary diagram
242
- types.d.ts TypeScript declarations
243
- ```
244
-
245
- Source code, tests, keys, and runtime state are not included.
246
-
247
- ---
248
-
249
- ## Limits
250
-
251
- This package governs actions routed through its executor. It does not provide
252
- kernel-level process isolation, network-egress control, multi-tenant separation,
253
- or a hosted control plane.
254
-
255
- For the raw WASM runtime without a controller, see `@letterblack/lbe-sdk`.
1
+ # @letterblack/lbe-exec
2
+
3
+ **Local-first execution governance for AI agents.**
4
+
5
+ > Use `@letterblack/lbe-exec` if you want LBE to control agent actions in a workspace.
6
+ > Use `@letterblack/lbe-sdk` if you only need validation decisions inside your own tool.
7
+
8
+ Every action any agent proposes — file write, shell command, anything — passes
9
+ through a local validation gate before it can execute. One package, any agent,
10
+ zero cloud dependency, no daemon required.
11
+
12
+ ---
13
+
14
+ ## The problem
15
+
16
+ AI agents are capable. They can write files, invoke tools, and change state —
17
+ and they will, the moment they are given a reason to. The host is the only
18
+ thing standing between a plausible-looking request and irreversible damage.
19
+
20
+ That is not enough.
21
+
22
+ `@letterblack/lbe-exec` puts a deterministic local gate between what the agent
23
+ proposes and what the system actually executes — fully in-process, no cloud
24
+ dependency, no daemon required.
25
+
26
+ ---
27
+
28
+ ## How every request travels
29
+
30
+ ![LBE gate sequence — Request flows through Policy, Identity, and Scope gates before reaching Action. A rejected request is routed to denial before it reaches execution.](https://unpkg.com/@letterblack/lbe-exec/assets/lbe-gates.jpg)
31
+
32
+ Every request the agent produces enters a 7-gate pipeline. A failure at any
33
+ gate returns a structured denial — the remaining gates are not evaluated.
34
+
35
+ ```
36
+ [1] Schema required fields and structural validity
37
+
38
+ [2] Timestamp permitted clock-skew window (±10 minutes)
39
+
40
+ [3] Key lifecycle trusted key, active, not expired
41
+
42
+ [4] Signature Ed25519 request authenticity (signed locally, no network)
43
+
44
+ [5] Rate limit per-requester sliding-window limit
45
+
46
+ [6] Nonce single-use replay protection
47
+
48
+ [7] Policy configured authorization (deny-wins)
49
+
50
+ allow / deny / error — structured result returned to host
51
+ ```
52
+
53
+ The executor signs every request with a host-held key before validation.
54
+ No key material leaves the process.
55
+
56
+ ---
57
+
58
+ ## When a request is approved
59
+
60
+ ![Happy path — agent proposes action, identity confirmed, policy approved, governed write executed, audit chain extended, result returned to app.](https://unpkg.com/@letterblack/lbe-exec/assets/story-allow.jpg)
61
+
62
+ When a request clears every gate:
63
+
64
+ 1. The agent calls a convenience method — `lbe.writeFile()`, `lbe.runShell()`, etc.
65
+ 2. The executor constructs and signs the request locally with a host-held Ed25519 key.
66
+ 3. All seven gates pass. The project policy approves the action.
67
+ 4. The write or command executes inside the configured project root.
68
+ 5. The audit chain is extended — every approved action appends a hash-linked
69
+ entry to `.lbe/audit.jsonl`, permanently verifiable, impossible to silently remove.
70
+ 6. A structured result returns: whether it succeeded, which rules matched, and
71
+ the audit entry identifier.
72
+
73
+ The application stays in control. The executor decides whether the action was
74
+ permitted and hands the answer back.
75
+
76
+ ---
77
+
78
+ ## When a request is blocked
79
+
80
+ ![Deny path — rogue agent bypass attempt, policy gate immediate rejection, shell untouched, filesystem unchanged, immutable audit entry written, final state clean.](https://unpkg.com/@letterblack/lbe-exec/assets/story-deny.jpg)
81
+
82
+ When a request fails any gate:
83
+
84
+ 1. The agent attempts an action — whether by mistake, misconfiguration,
85
+ or a deliberate bypass attempt.
86
+ 2. The policy gate closes immediately. The request is denied before any adapter
87
+ is reached.
88
+ 3. The shell is untouched. The filesystem is unchanged. Nothing that should not
89
+ have happened, happened.
90
+ 4. The denial is written to the immutable audit log — chain sealed, evidence
91
+ preserved.
92
+ 5. The final state is clean, verifiable, and consistent.
93
+
94
+ No partial execution. No silent failures. Denial is a first-class outcome, not
95
+ an error.
96
+
97
+ ---
98
+
99
+ ## Policy — who writes the rules
100
+
101
+ Only the host application writes policy. Agents may propose a rule — the
102
+ proposal is returned as a plain object for the host to review. Until the host
103
+ explicitly accepts and writes it, the proposal has no effect on any gate.
104
+
105
+ This separation is intentional. An agent that can write its own policy rules
106
+ is an agent that can grant itself permission.
107
+
108
+ ---
109
+
110
+ ## What this covers
111
+
112
+ | Threat | Gate |
113
+ |---|---|
114
+ | Agent writes outside the project root | Scope — sandbox path check |
115
+ | Replayed or stale request | Identity — nonce and timestamp |
116
+ | Tampered or expired key | Identity — key lifecycle |
117
+ | Excessive requests | Identity — rate limit |
118
+ | Action not permitted by project policy | Policy — deny-wins evaluation |
119
+ | Unauthorized shell command | Scope — explicit command allowlist |
120
+ | Injected payload (eval, exec, __proto__) | Content scan before pipeline |
121
+
122
+ ---
123
+
124
+ ## Observer mode — start here
125
+
126
+ Not ready to block? Start in observer mode. Every request is fully validated
127
+ and logged exactly as it would be in enforcement — but nothing is blocked.
128
+
129
+ Watch what the agent is doing before you decide what to deny. Your rules take
130
+ effect the moment you switch to enforcement.
131
+
132
+ ---
133
+
134
+ ## Install
135
+
136
+ ```bash
137
+ npm install @letterblack/lbe-exec
138
+ npx lbe-exec init
139
+ ```
140
+
141
+ `npx lbe-exec init` scans the project, writes `lbe.policy.json` in observer
142
+ mode, generates `CLAUDE.md` and `.github/copilot-instructions.md` so every AI
143
+ agent automatically discovers and follows governance, and creates
144
+ `.lbe/AGENT_CONTRACT.md` as a machine-readable contract.
145
+
146
+ Requires Node.js ≥ 20.9.0.
147
+
148
+ ---
149
+
150
+ ## Use in agent code
151
+
152
+ ```js
153
+ import { createLocalExecutor } from '@letterblack/lbe-exec';
154
+
155
+ const lbe = createLocalExecutor({ rootDir: process.cwd() });
156
+
157
+ // Every call routes through the full 7-gate pipeline
158
+ await lbe.writeFile('output/report.md', content);
159
+ await lbe.readFile('src/config.json');
160
+ await lbe.patchFile('src/index.js', patch);
161
+ await lbe.deleteFile('tmp/scratch.txt');
162
+ await lbe.runShell('node', ['scripts/build.js']);
163
+
164
+ // Result shape
165
+ const result = await lbe.writeFile('output/result.md', data);
166
+ // { ok: true, decision: 'allow', executed: true, auditId: '...' }
167
+ // { ok: false, decision: 'deny', executed: false, error: { code, message } }
168
+ ```
169
+
170
+ No knowledge of the pipeline, request format, or policy internals required.
171
+ All signing, validation, and auditing happens automatically.
172
+
173
+ ### Options
174
+
175
+ ```js
176
+ const lbe = createLocalExecutor({
177
+ rootDir: process.cwd(), // sandbox root — no writes escape this path
178
+ mode: 'observe', // 'observe' (log only) or 'enforce' (block)
179
+ shell: {
180
+ allowCommands: ['node', 'npm'], // only these commands may run
181
+ denyCommands: ['rm', 'curl'], // always blocked regardless of policy
182
+ maxRequests: 20 // per-minute shell rate limit
183
+ }
184
+ });
185
+ ```
186
+
187
+ ### Policy management
188
+
189
+ ```js
190
+ // Propose a rule — returns an object for the host to review, writes nothing
191
+ const proposal = lbe.policy.proposeRule({
192
+ effect: 'deny',
193
+ type: 'path',
194
+ pattern: 'secrets/**',
195
+ from: 'agent: these files should not be modified'
196
+ });
197
+
198
+ // Host accepts and writes the rule
199
+ lbe.policy.addRule(proposal);
200
+
201
+ // Read current policy
202
+ const policy = lbe.policy.read();
203
+
204
+ // Verify the audit chain has not been tampered with
205
+ lbe.audit.verify();
206
+ ```
207
+
208
+ ---
209
+
210
+ ## CLI reference
211
+
212
+ ```bash
213
+ npx lbe-exec init # create lbe.policy.json in observer mode
214
+ npx lbe-exec status # show mode, rule count, and audit entry count
215
+ npx lbe-exec enforce # switch to blocking
216
+ npx lbe-exec observe # switch back to advisory
217
+ npx lbe-exec policy # list active rules
218
+ ```
219
+
220
+ | Command | Purpose |
221
+ |---|---|
222
+ | `npx lbe-exec init` | Bootstrap governance — policy, keys, agent files |
223
+ | `npx lbe-exec status` | Show mode, rule count, audit entry count |
224
+ | `npx lbe-exec policy` | List active rules |
225
+ | `npx lbe-exec observe` | Set advisory (log-only) mode |
226
+ | `npx lbe-exec enforce` | Set blocking mode |
227
+ | `npx lbe-exec execute` | Pipe a JSON request from stdin or `--input <file>` |
228
+
229
+ ---
230
+
231
+ ## What ships
232
+
233
+ ```
234
+ dist/index.js In-process executor — createLocalExecutor()
235
+ dist/cli.js Local CLI (npx lbe-exec)
236
+ dist/lbe_engine.wasm Verified WASM runtime binary
237
+ dist/wasm.lock.json Runtime integrity lock (SHA-256 of wasm binary)
238
+ assets/lbe-gates.jpg Gate sequence diagram
239
+ assets/story-allow.jpg Approved-request storyboard
240
+ assets/story-deny.jpg Blocked-request storyboard
241
+ assets/runtime-boundary.svg Runtime boundary diagram
242
+ assets/lbe-gates.png Gate sequence diagram (full resolution)
243
+ assets/story-allow.png Approved-request storyboard (full resolution)
244
+ assets/story-deny.png Blocked-request storyboard (full resolution)
245
+ types.d.ts TypeScript declarations
246
+ ```
247
+
248
+ Source code, tests, keys, and runtime state are not included.
249
+
250
+ ---
251
+
252
+ ## Limits
253
+
254
+ This package governs actions routed through its executor. It does not provide
255
+ kernel-level process isolation, network-egress control, multi-tenant separation,
256
+ or a hosted control plane.
257
+
258
+ For the raw WASM runtime without a controller, see `@letterblack/lbe-sdk`.
package/dist/cli.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterblack/lbe-exec",
3
- "version": "1.2.7",
3
+ "version": "1.2.10",
4
4
  "description": "Local host-signed execution layer for LetterBlack LBE.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",