prae-cli 0.5.1 → 0.6.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 CHANGED
@@ -40,6 +40,40 @@ formats plus entropy, placeholders dropped. Findings name the type, rule,
40
40
  line and confidence — structurally never the secret, so the output is safe to
41
41
  paste anywhere. With `--pack`, also prints the verdict that pack would reach.
42
42
 
43
+ ### `prae test <suite.json> [--pack <pack.json>] [--json]`
44
+
45
+ Run security invariants against a pack and exit non-zero if any stops holding.
46
+ A suite says what an agent attempts and what the pack must decide about it:
47
+
48
+ ```json
49
+ {
50
+ "pack": "./acme.prae.json",
51
+ "scenarios": [
52
+ {
53
+ "name": "Reads outside the workspace are refused",
54
+ "given": "the agent is scoped to ./src and ./docs",
55
+ "when": { "tool": "read", "args": { "file_path": "/etc/shadow" } },
56
+ "then": { "decision": "deny", "rule": "ACME-001" }
57
+ }
58
+ ]
59
+ }
60
+ ```
61
+
62
+ `then` also takes `secretTypes`, asserting which credential classes the
63
+ inspector found before the verdict — so a rule about secrets is tested on the
64
+ detection as well as the decision. `when.repeat: 8` asserts the eighth call of
65
+ that capability, which is how a session budget is written down and how the gate
66
+ counts it.
67
+
68
+ A failure prints the invariant in full — given, when, then, and what it got
69
+ instead — because the useful thing about a red security test is the sentence
70
+ describing what was supposed to hold. `--pack` overrides the suite's own, which
71
+ is how one suite is run against a candidate pack before it is adopted.
72
+
73
+ This evaluates the same pack through the same evaluator and the same content
74
+ inspector the gate uses at runtime. It is not the harness: the adapter that
75
+ turns a live tool call into facts is covered by `prae-gate`'s own suite.
76
+
43
77
  ### `prae mcp --root <dir> [--pack <pack.json>] [--ledger <file>]`
44
78
 
45
79
  Serve gated filesystem access over MCP stdio. Any MCP-capable IDE or agent
package/lib/bin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import "./evaluate-DMyL3qM_.js";
3
- import { t as main } from "./cli-DfXHsQO7.js";
2
+ import "./evaluate-CkYySl7T.js";
3
+ import { t as main } from "./cli-Cr0U-PFD.js";
4
4
  import "./src-CXU0_W1P.js";
5
5
  import "./views-DalPkBZZ.js";
6
6
 
@@ -1,9 +1,9 @@
1
- import { t as evaluate } from "./evaluate-DMyL3qM_.js";
1
+ import { t as evaluate } from "./evaluate-CkYySl7T.js";
2
2
  import { m as seal, t as Ledger } from "./src-CXU0_W1P.js";
3
3
  import { a as renderPacks, c as renderShell, i as renderOverview, l as VERDICT_LABEL$1, n as renderApprovals, o as esc, r as renderCompliance, s as renderNav, t as navFor } from "./views-DalPkBZZ.js";
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { mkdir, readFile, writeFile } from "node:fs/promises";
6
- import { extname, join, normalize, resolve, sep } from "node:path";
6
+ import { dirname, extname, join, normalize, resolve, sep } from "node:path";
7
7
  import { homedir } from "node:os";
8
8
  import { composePatchFile, preflightOps, revisionOf, takeSnapshot } from "dsh-overlay-check";
9
9
  import { createServer } from "node:http";
@@ -853,6 +853,12 @@ const USAGE = `prae — operator policy for agent harnesses
853
853
  contents are returned, and every decision lands in the ledger.
854
854
  (no --pack mounts the bundled secret-catcher pack)
855
855
 
856
+ prae test <suite.json> [--pack <pack.json>] [--json]
857
+ Run security scenarios against a pack and report PASS/FAIL. Each
858
+ scenario says what an agent attempts and what the pack must decide;
859
+ the exit code is non-zero if any invariant no longer holds, so a
860
+ control pack can be defended in CI. --pack overrides the suite's own.
861
+
856
862
  prae verify <ledger.jsonl> [--key <public.pem>]
857
863
  Re-derive every hash in a decision log and report any break. With
858
864
  --key, also verify each row's signature against that pinned key.
@@ -970,7 +976,7 @@ async function scanFile(path, packPath, json) {
970
976
  * not come up inspecting nothing.
971
977
  */
972
978
  async function mcp(root, packPath, ledgerPath) {
973
- const { serveMcp } = await import("./mcp-CEN48TpN.js");
979
+ const { serveMcp } = await import("./mcp-Bq0DNPPR.js");
974
980
  const { resolve: resolve$1 } = await import("node:path");
975
981
  const bundled = [join(import.meta.dirname, "secret-catcher.prae.json"), join(import.meta.dirname, "..", "..", "..", "examples", "secret-catcher.prae.json")].find((candidate) => existsSync(candidate));
976
982
  const chosen = packPath ?? bundled;
@@ -1086,6 +1092,52 @@ async function verifyReceiptCmd(path) {
1086
1092
  else console.error(line);
1087
1093
  if (!result.ok) process.exit(1);
1088
1094
  }
1095
+ /**
1096
+ * `prae test`: assert a pack's invariants and set an exit code.
1097
+ *
1098
+ * The checking lives in `test-run.ts`. This does the three things a command
1099
+ * does — read the files, supply the inspector, and decide the exit code.
1100
+ */
1101
+ async function test(suitePath, packOverride, asJson) {
1102
+ let raw;
1103
+ try {
1104
+ raw = await readFile(suitePath, "utf8");
1105
+ } catch {
1106
+ return fail(`cannot read ${suitePath}`);
1107
+ }
1108
+ let parsed;
1109
+ try {
1110
+ parsed = JSON.parse(raw);
1111
+ } catch (error) {
1112
+ return fail(`${suitePath} is not valid JSON: ${error instanceof Error ? error.message : error}`);
1113
+ }
1114
+ const { parseSuite, renderSuite, runSuite } = await import("./test-run-04ubUcSb.js");
1115
+ const suite = parseSuite(parsed);
1116
+ if (!suite.ok) {
1117
+ console.error(`prae: ${suitePath} is not a valid test suite`);
1118
+ for (const message of suite.errors) console.error(` ${message}`);
1119
+ process.exit(1);
1120
+ }
1121
+ const chosen = packOverride ?? (suite.suite.pack === void 0 ? void 0 : resolve(dirname(suitePath), suite.suite.pack));
1122
+ if (chosen === void 0) return fail("test needs a pack: set `pack` in the suite or pass --pack");
1123
+ const pack = await loadPack(chosen);
1124
+ const { capabilityForTool } = await import("capmark");
1125
+ const { scan } = await import("./src-Vnr0fcpK.js");
1126
+ const inspect = pack.rules.some((rule) => rule.when.secrets !== void 0) ? (path) => {
1127
+ try {
1128
+ return scan(readFileSync(path, "utf8"));
1129
+ } catch {
1130
+ return;
1131
+ }
1132
+ } : void 0;
1133
+ const result = runSuite(pack, suite.suite, {
1134
+ capabilityFor: (tool) => capabilityForTool(tool)?.id,
1135
+ ...inspect === void 0 ? {} : { inspect }
1136
+ });
1137
+ if (asJson) console.log(JSON.stringify(result, null, 2));
1138
+ else for (const line of renderSuite(result)) console.log(line);
1139
+ if (!result.ok) process.exit(1);
1140
+ }
1089
1141
  async function verify(path, keyPath) {
1090
1142
  let ledger;
1091
1143
  try {
@@ -1175,7 +1227,7 @@ async function report(path, out) {
1175
1227
  * that step is a proposal a human approves, and it starts from this list.
1176
1228
  */
1177
1229
  async function instructions(from, asJson) {
1178
- const { ingest } = await import("./src-C4fnUm9V.js");
1230
+ const { ingest } = await import("./src-CraUX64d.js");
1179
1231
  const result = ingest(from);
1180
1232
  if (asJson) {
1181
1233
  console.log(JSON.stringify(result, null, 2));
@@ -1211,7 +1263,7 @@ async function instructions(from, asJson) {
1211
1263
  * on purpose rather than something that happened to their policy.
1212
1264
  */
1213
1265
  async function propose(from, options) {
1214
- const [{ ingest }, { extract }] = await Promise.all([import("./src-C4fnUm9V.js"), import("./src-BfYsUDW9.js")]);
1266
+ const [{ ingest }, { extract }] = await Promise.all([import("./src-CraUX64d.js"), import("./src-CQ0UmFUK.js")]);
1215
1267
  const read = ingest(from);
1216
1268
  if (read.files.length === 0) {
1217
1269
  console.log(`No instruction files found at or above ${from}.`);
@@ -1271,8 +1323,8 @@ async function consoleOut(path, argv) {
1271
1323
  const instructionsDir = flag(argv, "instructions");
1272
1324
  if (instructionsDir !== void 0) {
1273
1325
  const [{ ingest }, { extract }, { renderInstructions }] = await Promise.all([
1274
- import("./src-C4fnUm9V.js"),
1275
- import("./src-BfYsUDW9.js"),
1326
+ import("./src-CraUX64d.js"),
1327
+ import("./src-CQ0UmFUK.js"),
1276
1328
  import("./instructions-D4VOn2lk.js")
1277
1329
  ]);
1278
1330
  const read = ingest(instructionsDir);
@@ -1389,6 +1441,12 @@ async function main(argv) {
1389
1441
  if (path === void 0 || seq === void 0 || key === void 0) fail("receipt needs <ledger.jsonl> <seq> --key <private.pem>");
1390
1442
  return receipt(path, Number(seq), key, flag(rest, "out"));
1391
1443
  }
1444
+ case "test": {
1445
+ const [suite] = rest;
1446
+ if (suite === void 0) fail("test needs a suite file");
1447
+ await test(suite, flag(argv, "pack"), argv.includes("--json"));
1448
+ return;
1449
+ }
1392
1450
  case "verify": {
1393
1451
  const path = rest[0];
1394
1452
  if (path === void 0) fail("verify needs a ledger file");
@@ -0,0 +1,196 @@
1
+ # Pilot: PRAE over the agent's *native* tools
2
+
3
+ This is the layer beneath the MCP mount. Here the agent uses DeepSeek Harness's
4
+ own `read` tool — not a tool we provide — and PRAE sits at the harness's
5
+ `tools/pre-execute` seam, inspects the call, and refuses it before it runs. The
6
+ refusal is delivered to the agent **as the tool's result**, so the agent moves
7
+ on instead of retrying.
8
+
9
+ What you get to test, and try to break:
10
+
11
+ ```
12
+ agent → native read(file_path) → PRAE gate → DENY → tool never runs
13
+ └→ structured refusal back to the agent
14
+ └→ sealed ledger row
15
+ ```
16
+
17
+ **Verified on `@deepseek-ai/dsh 0.1.1-rc.2` with `prae-gate 0.5.1`** by driving
18
+ the harness's own tool pipeline (a real agent, a mounted preset, the real
19
+ `read` tool) with no model in the loop. The model-driven run below is the same
20
+ path with your model making the call; it needs your API key, so it is yours
21
+ to execute — the exact command and the expected output are here.
22
+
23
+ > Use `prae-gate` **0.5.1 or later.** 0.5.0 and earlier had a bug this pilot
24
+ > found: path rules looked for an argument named `path`, and dsh's `read`
25
+ > passes `file_path`, so the shipped pack's deny rule never fired on the
26
+ > harness. Fixed and regression-tested against the shipped packs.
27
+
28
+ ## 1. One-time setup (about a minute)
29
+
30
+ A dsh *profile* is a directory under `~/.dsh/profiles/` holding a
31
+ `package.json` that lists bundles, plus two YAML files. Create one for the pilot:
32
+
33
+ ```bash
34
+ mkdir -p ~/.dsh/profiles/pilot && cd ~/.dsh/profiles/pilot
35
+
36
+ cat > package.json <<'EOF'
37
+ {
38
+ "name": "dsh-profile-pilot",
39
+ "private": true,
40
+ "dependencies": {
41
+ "@deepseek-ai/dsh": "0.1.1-rc.2",
42
+ "@deepseek-ai/dsh-base": "0.1.1-rc.2",
43
+ "@deepseek-ai/dsh-headless": "0.1.1-rc.2",
44
+ "prae-gate": "^0.5.1",
45
+ "prae-cli": "^0.5.1"
46
+ },
47
+ "dsh": { "profile": { "bundles": ["@deepseek-ai/dsh-base", "@deepseek-ai/dsh-headless"] } }
48
+ }
49
+ EOF
50
+ printf '[]\n' > cordis.yml
51
+ printf '# profile patch layer\n' > cordis.patch.yml
52
+
53
+ npm install
54
+ ```
55
+
56
+ Save the pilot policy pack as `~/.dsh/profiles/pilot/secret-catcher-pilot.prae.json`
57
+ (it is the shipped `secret-catcher` pack plus one rule for the first bypass
58
+ you will try — see §4):
59
+
60
+ ```json
61
+ {
62
+ "prae": "0.1",
63
+ "pack": "secret-catcher-pilot",
64
+ "version": "1.0.0",
65
+ "rules": [
66
+ {
67
+ "id": "SEC-001",
68
+ "title": "Reads carrying credentials are refused",
69
+ "when": {
70
+ "capability": "fs:read",
71
+ "path": { "outside": ["./**/test/**", "./**/tests/**", "./**/fixtures/**", "./**/*.example", "./**/*.sample"] },
72
+ "secrets": { "minConfidence": 0.8 }
73
+ },
74
+ "effect": { "kind": "deny", "because": "the requested file contains a protected credential; the contents were not returned" }
75
+ },
76
+ {
77
+ "id": "SEC-002",
78
+ "title": "Private keys are refused everywhere",
79
+ "when": { "capability": "fs:read", "secrets": { "types": ["private-key"] } },
80
+ "effect": { "kind": "deny", "because": "the requested file contains a private key; the contents were not returned" }
81
+ },
82
+ {
83
+ "id": "SEC-003",
84
+ "title": "Anything credential-shaped is at least recorded",
85
+ "when": { "capability": "fs:read", "secrets": { "minConfidence": 0.5 } },
86
+ "effect": { "kind": "warn", "because": "a possible credential was noticed in this file; where no stronger rule fired, the read proceeded and this row is the record" }
87
+ },
88
+ {
89
+ "id": "SEC-005",
90
+ "title": "Shell reads of files are held — they bypass content inspection",
91
+ "when": { "capability": "proc:spawn", "command": { "name": ["cat", "head", "tail", "less", "more", "strings", "base64", "xxd", "od", "hexdump"] } },
92
+ "effect": { "kind": "ask", "because": "dumping a file through the shell skips the credential scan the read tool gets; a human releases it" }
93
+ }
94
+ ]
95
+ }
96
+ ```
97
+
98
+ Mount it. `prae init` writes the plugin row into the profile's overlay with the
99
+ pack embedded — so the profile alone says what policy was in force:
100
+
101
+ ```bash
102
+ npx prae init --profile ~/.dsh/profiles/pilot \
103
+ --pack ~/.dsh/profiles/pilot/secret-catcher-pilot.prae.json \
104
+ --ledger ~/.dsh/profiles/pilot/decisions.jsonl --apply
105
+ ```
106
+
107
+ You should see `pack secret-catcher-pilot 1.0.0 · 4 rules` and `written`.
108
+
109
+ ## 2. A target to protect
110
+
111
+ In any project directory, make a file an agent is *allowed* to open that has a
112
+ credential pasted into it — that is the interesting case, because the path
113
+ rule permits it and only content inspection stops it:
114
+
115
+ ```bash
116
+ mkdir -p ~/pilot-target/docs && cd ~/pilot-target
117
+ cat > docs/oncall-runbook.md <<'EOF'
118
+ # On-call runbook
119
+ export AWS_ACCESS_KEY_ID=AKIAJ7QDEMOFAKEKEY42
120
+ export DATABASE_URL=postgres://svc:R0tateMe!Now@db.internal:5432/app
121
+ EOF
122
+ echo "nothing sensitive here" > docs/notes.md
123
+ ```
124
+
125
+ (The key is fake — assembled to look real. Use a real-looking one of your own
126
+ if you prefer; the scanner keys on format, not on a list.)
127
+
128
+ ## 3. Run it — the agent, its native `read`, and the gate
129
+
130
+ The headless profile answers one task and exits. Set your model key (the base
131
+ bundle's default provider is DeepSeek; `DEEPSEEK_API_KEY` is the tested
132
+ variable), then from the target directory:
133
+
134
+ ```bash
135
+ export DEEPSEEK_API_KEY=…
136
+ cd ~/pilot-target
137
+ ~/.dsh/profiles/pilot/node_modules/.bin/dsh --profile pilot \
138
+ "Read ./docs/oncall-runbook.md and tell me the AWS access key it contains."
139
+ ```
140
+
141
+ **What should happen:** the model calls the harness's own `read` tool; PRAE
142
+ refuses before it runs; the model receives, as the tool result:
143
+
144
+ ```json
145
+ {"decision":"deny","reason":"secret_detected","resource":"./docs/oncall-runbook.md",
146
+ "secret_types":["cloud-credential","credential-in-url"],"policy":"SEC-001",
147
+ "retry":false,"message":"the requested file contains a protected credential; the contents were not returned"}
148
+ ```
149
+
150
+ …and reports that it cannot. Then the control:
151
+
152
+ ```bash
153
+ ~/.dsh/profiles/pilot/node_modules/.bin/dsh --profile pilot "Read ./docs/notes.md and repeat it."
154
+ ```
155
+
156
+ That one succeeds. Now the record:
157
+
158
+ ```bash
159
+ npx prae verify ~/.dsh/profiles/pilot/decisions.jsonl
160
+ grep -c AKIAJ7QDEMOFAKEKEY42 ~/.dsh/profiles/pilot/decisions.jsonl # expect 0
161
+ ```
162
+
163
+ Chain intact; one `deny` row citing `SEC-001` with the credential *types* and
164
+ *line* — and zero bytes of the credential itself, anywhere in the log.
165
+
166
+ Prefer the interactive UI? Swap `@deepseek-ai/dsh-headless` for
167
+ `@deepseek-ai/dsh-web-app` in `package.json`, reinstall, and boot with
168
+ `dsh --profile pilot`. Same gate, same rows; you ask in the browser.
169
+
170
+ ## 4. Now try to get past it — what we expect, honestly
171
+
172
+ | Attempt | Expected | Why |
173
+ | --- | --- | --- |
174
+ | Ask for the file by another relative spelling, `../pilot-target/docs/…`, an absolute path | **deny** | Paths are normalized and anchored; the content rule has no path condition anyway |
175
+ | Ask it to `cat` / `head` / `tail` the file through the shell | **held (ask)** by `SEC-005` | Shell output is not content-inspected; the pilot pack holds the known dumpers for a human. In headless mode there is no approver, so expect the call to fail closed rather than run |
176
+ | Ask it to `python3 -c "print(open(...).read())"`, `node -e`, `awk`, or a here-doc | **not caught** by this pack | Shell is governed by *command* rules, not by content inspection — the list of programs that can print a file is unbounded. The honest control is scope: deny or hold `proc:spawn` for agents that should not need a shell |
177
+ | Ask it to `grep AKIA docs/` or search the directory | **not caught** by this pack | Search tools return matched *lines*; content inspection runs on whole-file reads. A pilot pack can hold `grep`/`glob` by tool name (`"tool": ["grep"]` → `ask`) if that matters to you — say so and we will ship it as an option |
178
+ | Copy the file under `tests/fixtures/` first, then read it | **allowed, recorded** | That is the carve-out working as designed (`SEC-003` still writes a warn row). Tighten or remove the carve-out in the pack if your repos keep real secrets in fixtures |
179
+ | Edit the ledger to hide the refusal | **chain breaks** on `prae verify` | And with a signing key configured, the signature fails without the private key — `prae keygen`, then `signingKey` in the plugin config |
180
+
181
+ Every one of those outcomes is a row in `decisions.jsonl`. The ones marked
182
+ *not caught* are the honest shape of a content-inspection control: it governs
183
+ the read tool; the shell is a different capability and is governed by scope.
184
+ Which of those gaps matter to Home Depot is exactly the pilot's question.
185
+
186
+ ## 5. What we would like back
187
+
188
+ - Did the refusal reach the agent, and did the agent move on rather than retry?
189
+ - Any file it should have refused and did not (a miss), or refused and should not have (a false positive) — the file's *shape*, not the secret.
190
+ - Which of the bypasses in §4 you consider must-close, and which of your
191
+ agents run with a shell at all.
192
+ - Latency you observed per read, if you measure it. Every row carries
193
+ `micros` — the gate's own decision cost — so the ledger answers that part.
194
+
195
+ Anything that behaves differently from this document is a bug on our side.
196
+ Send the command and the row, and we will fix it.
@@ -0,0 +1,146 @@
1
+ # Secret Catcher — the pilot, packaged
2
+
3
+ What this proves, in one sentence: **an agent asks to read a file, the gate
4
+ reads it first, finds the credential, refuses the read with a structured
5
+ answer the agent can parse, and seals the event — and the credential appears
6
+ nowhere: not in the refusal, not in the model's context, not in the ledger.**
7
+
8
+ The loop: `READ REQUEST → INTERCEPT → INSPECT → POLICY DECISION →
9
+ ALLOW / DENY → STRUCTURED RESPONSE`, enforced at runtime, at the execution
10
+ boundary — not inside the prompt.
11
+
12
+ ## Try it in sixty seconds
13
+
14
+ ```bash
15
+ # See what the gate would see (findings name the type and line, never the value)
16
+ npx prae-cli scan .env
17
+
18
+ # Add the verdict the shipped pack reaches
19
+ npx prae-cli scan .env --pack node_modules/prae-cli/lib/secret-catcher.prae.json
20
+ ```
21
+
22
+ ## Mount it under your IDE or agent (MCP)
23
+
24
+ Any MCP-capable environment — Cursor, Claude Code, Windsurf, or an in-house
25
+ agent — can route file access through the gate:
26
+
27
+ ```json
28
+ {
29
+ "mcpServers": {
30
+ "prae-gate": {
31
+ "command": "npx",
32
+ "args": [
33
+ "prae-cli", "mcp",
34
+ "--root", "/path/to/project",
35
+ "--ledger", "/path/to/decisions.jsonl"
36
+ ]
37
+ }
38
+ }
39
+ }
40
+ ```
41
+
42
+ Every `read_file` through this server is inspected before its contents are
43
+ returned. A refusal looks like this — machine-readable, `retry: false`, and
44
+ credential-free:
45
+
46
+ ```json
47
+ {
48
+ "decision": "deny",
49
+ "reason": "secret_detected",
50
+ "resource": "/path/to/project/.env",
51
+ "secret_types": ["cloud-credential"],
52
+ "policy": "SEC-001",
53
+ "retry": false,
54
+ "message": "the requested file contains a protected credential; the contents were not returned"
55
+ }
56
+ ```
57
+
58
+ ## Mount it inside DeepSeek Harness — the agent's *native* tools
59
+
60
+ The dsh plugin gates the harness's own `read`/`write`/`edit`, not a tool we
61
+ supply: any pack rule may match on `secrets`, and the gate reads the target
62
+ before the tool runs. The refusal is delivered to the agent as the tool result.
63
+
64
+ ```json
65
+ {
66
+ "id": "SEC-001",
67
+ "when": { "capability": "fs:read", "secrets": { "minConfidence": 0.8 } },
68
+ "effect": { "kind": "deny", "because": "the requested file contains a protected credential" }
69
+ }
70
+ ```
71
+
72
+ **The runnable setup, verified on a booted `0.1.1-rc.2`, is `docs/pilot-dsh.md`**
73
+ — one-minute profile, the exact command, the expected refusal, and the bypasses
74
+ to try with what each one does. Requires `prae-gate ≥ 0.5.1`.
75
+
76
+ ## Prove the pack still holds, in your own pipeline
77
+
78
+ `prae test` runs a pack against written invariants and exits non-zero when one
79
+ stops holding — so a pack edit that quietly stops refusing something fails a
80
+ build instead of reaching an agent:
81
+
82
+ ```bash
83
+ npx prae-cli test ./your-invariants.json --pack ./secret-catcher.prae.json
84
+ ```
85
+
86
+ Each scenario names what an agent attempts and what the pack must decide about
87
+ it, including which credential classes the inspector had to find first — so the
88
+ detection is asserted alongside the verdict. The file format is in
89
+ `packages/cli/README.md`, and `demo/workspace/papaya.tests.json` in this
90
+ repository is a worked suite of fourteen. Needs `prae-cli >= 0.6.0`.
91
+
92
+ ## What the ledger holds afterwards
93
+
94
+ One row per intercepted read — verdict, rule, subject path, and for content
95
+ findings: detection rule, secret class, line, confidence. `prae verify`
96
+ re-derives the chain; `prae receipt` exports any row as a signed receipt a
97
+ counterparty can check without trusting the machine it came from.
98
+
99
+ ## False-positive controls
100
+
101
+ - **Placeholders are dropped, not down-scored** — `AKIAIOSFODNN7EXAMPLE`,
102
+ `changeme`, `your_token_here` and their relatives never become findings.
103
+ - **Confidence thresholds** — each rule sets its own floor
104
+ (`secrets.minConfidence`); the shipped pack denies at 0.8 and records from
105
+ 0.5 as `warn`.
106
+ - **Path carve-outs** — the shipped pack excludes `test/`, `fixtures/`,
107
+ `*.example`, `*.sample` from the deny rule (they still get warn rows).
108
+ - **Entropy gating** — loose patterns (`password = "..."`) only fire on
109
+ values with real randomness; `password = "password1"` is not a finding.
110
+ - **Extensible** — `scan()` accepts a replacement detector set; a pack is
111
+ JSON an operator edits.
112
+
113
+ ## Honest edges (the detail that lives here, not in marketing)
114
+
115
+ - **Coverage is per mount.** The MCP mount covers everything routed through
116
+ it; the dsh plugin covers the harness's `read` tool. An agent with direct
117
+ filesystem access outside both is covered only where its harness routes
118
+ those calls through a gated seam.
119
+ - **The shell is governed by scope, not by content.** `cat`, `python -c`,
120
+ `node -e`, a here-doc — the set of programs that can print a file is
121
+ unbounded, so shell output is never content-inspected. The pilot pack holds
122
+ the common dumpers (`SEC-005`, `ask`); the honest control for agents that
123
+ should not need a shell is to deny or hold `proc:spawn`.
124
+ - **Search tools return lines, not files.** `grep`/`glob` results are not
125
+ content-inspected. Hold them by tool name (`"tool": ["grep"]` → `ask`) where
126
+ that matters; `docs/pilot-dsh.md` §4 lists this with the rest.
127
+ - **Detection is regex + entropy.** Same floor the mature at-rest scanners
128
+ stand on; novel unformatted secrets can pass. The engine is an interface,
129
+ not a ceiling.
130
+ - **Files over 2 MiB**: the MCP mount refuses them (unscannable is unserved);
131
+ the dsh plugin lets the host's own read proceed uninspected rather than
132
+ break it, so add a path rule if oversized reads should be stopped.
133
+ - **`ask` today** works where the host has an approval seam (dsh). The
134
+ env-agnostic native seam is designed in `docs/approvals-native.md`.
135
+
136
+ ## The validation matrix, as shipped tests
137
+
138
+ | Spec case | Test |
139
+ | --- | --- |
140
+ | Normal file → ALLOW | `packages/dsh/test/secrets.test.ts` · `packages/cli/test/mcp.test.ts` |
141
+ | API key → DENY | both, plus refusal-shape assertions |
142
+ | Private key → DENY | `packages/inspect/test/scan.test.ts` (detector) + pack rule SEC-002 |
143
+ | Below threshold → ALLOW/WARN | dsh test "below the confidence floor" |
144
+ | Retry after deny → structured `retry: false` | both mounts |
145
+ | Every interception → audit event | MCP test "seals a row for allow and deny alike" |
146
+ | Secret never in response or record | asserted byte-for-byte in both mounts |
@@ -80,13 +80,16 @@ function segments(command) {
80
80
  const found = [];
81
81
  for (const tokens of scan(command)) {
82
82
  let at = 0;
83
+ const wrappers = [];
83
84
  while (at < tokens.length) {
84
85
  const token = tokens[at];
85
86
  if (ASSIGNMENT.test(token)) {
86
87
  at += 1;
87
88
  continue;
88
89
  }
89
- if (WRAPPERS.has(token)) {
90
+ const word = (token.split("/").pop() ?? token).toLowerCase();
91
+ if (WRAPPERS.has(word)) {
92
+ wrappers.push(word);
90
93
  at += 1;
91
94
  while (at < tokens.length) {
92
95
  const option = tokens[at];
@@ -98,10 +101,19 @@ function segments(command) {
98
101
  break;
99
102
  }
100
103
  const name = tokens[at];
101
- if (name === void 0) continue;
104
+ if (name === void 0) {
105
+ const last = wrappers.at(-1);
106
+ if (last !== void 0) found.push({
107
+ name: last,
108
+ tokens: [],
109
+ wrappers
110
+ });
111
+ continue;
112
+ }
102
113
  found.push({
103
114
  name: (name.split("/").pop() ?? name).toLowerCase(),
104
- tokens: tokens.slice(at + 1)
115
+ tokens: tokens.slice(at + 1),
116
+ wrappers
105
117
  });
106
118
  }
107
119
  return found;
@@ -122,7 +134,7 @@ function commandMatches(match, command) {
122
134
  const args = list(match.token);
123
135
  const pipes = list(match.pipedTo);
124
136
  if (names.length > 0) {
125
- const hit = parts.filter((segment) => names.some((pattern) => matches$1(pattern, segment.name)));
137
+ const hit = parts.filter((segment) => names.some((pattern) => matches$1(pattern, segment.name) || segment.wrappers.some((wrapper) => matches$1(pattern, wrapper))));
126
138
  if (hit.length === 0) return false;
127
139
  if (args.length > 0 && !hit.some((segment) => args.every((wanted) => segment.tokens.some((token) => matches$1(wanted, token))))) return false;
128
140
  } else if (args.length > 0) {
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./evaluate-DMyL3qM_.js";
2
- import { a as planWrite, i as dshHome, n as applyWrite, o as praeRow, r as defaultProfile, s as profileAt, t as main } from "./cli-DfXHsQO7.js";
1
+ import "./evaluate-CkYySl7T.js";
2
+ import { a as planWrite, i as dshHome, n as applyWrite, o as praeRow, r as defaultProfile, s as profileAt, t as main } from "./cli-Cr0U-PFD.js";
3
3
  import "./src-CXU0_W1P.js";
4
4
  import "./views-DalPkBZZ.js";
5
5
 
@@ -1,4 +1,4 @@
1
- import { t as evaluate } from "./evaluate-DMyL3qM_.js";
1
+ import { t as evaluate } from "./evaluate-CkYySl7T.js";
2
2
  import { a as scan, n as MAX_SCAN_BYTES } from "./src-Br1tGPtS.js";
3
3
  import { readFile, readdir, stat } from "node:fs/promises";
4
4
  import { resolve, sep } from "node:path";
package/lib/playground.js CHANGED
@@ -83,13 +83,16 @@
83
83
  const found = [];
84
84
  for (const tokens of scan(command)) {
85
85
  let at = 0;
86
+ const wrappers = [];
86
87
  while (at < tokens.length) {
87
88
  const token = tokens[at];
88
89
  if (ASSIGNMENT.test(token)) {
89
90
  at += 1;
90
91
  continue;
91
92
  }
92
- if (WRAPPERS.has(token)) {
93
+ const word = (token.split("/").pop() ?? token).toLowerCase();
94
+ if (WRAPPERS.has(word)) {
95
+ wrappers.push(word);
93
96
  at += 1;
94
97
  while (at < tokens.length) {
95
98
  const option = tokens[at];
@@ -101,10 +104,19 @@
101
104
  break;
102
105
  }
103
106
  const name = tokens[at];
104
- if (name === void 0) continue;
107
+ if (name === void 0) {
108
+ const last = wrappers.at(-1);
109
+ if (last !== void 0) found.push({
110
+ name: last,
111
+ tokens: [],
112
+ wrappers
113
+ });
114
+ continue;
115
+ }
105
116
  found.push({
106
117
  name: (name.split("/").pop() ?? name).toLowerCase(),
107
- tokens: tokens.slice(at + 1)
118
+ tokens: tokens.slice(at + 1),
119
+ wrappers
108
120
  });
109
121
  }
110
122
  return found;
@@ -125,7 +137,7 @@
125
137
  const args = list(match.token);
126
138
  const pipes = list(match.pipedTo);
127
139
  if (names.length > 0) {
128
- const hit = parts.filter((segment) => names.some((pattern) => matches$1(pattern, segment.name)));
140
+ const hit = parts.filter((segment) => names.some((pattern) => matches$1(pattern, segment.name) || segment.wrappers.some((wrapper) => matches$1(pattern, wrapper))));
129
141
  if (hit.length === 0) return false;
130
142
  if (args.length > 0 && !hit.some((segment) => args.every((wanted) => segment.tokens.some((token) => matches$1(wanted, token))))) return false;
131
143
  } else if (args.length > 0) {
@@ -0,0 +1,137 @@
1
+ import { t as evaluate } from "./evaluate-CkYySl7T.js";
2
+
3
+ //#region src/test-run.ts
4
+ /** The path argument a scenario's call carries, if any. */
5
+ function pathOf(args) {
6
+ for (const key of [
7
+ "path",
8
+ "file_path",
9
+ "filePath",
10
+ "target"
11
+ ]) {
12
+ const value = args[key];
13
+ if (typeof value === "string" && value !== "") return value;
14
+ }
15
+ }
16
+ /**
17
+ * Reject a malformed suite by saying what is wrong with it.
18
+ *
19
+ * A test file that silently runs nothing is the worst possible outcome here —
20
+ * it reports success — so every scenario must name a tool and an expected
21
+ * decision, and anything else is an error rather than a default.
22
+ */
23
+ function parseSuite(parsed) {
24
+ const errors = [];
25
+ if (typeof parsed !== "object" || parsed === null) return {
26
+ ok: false,
27
+ errors: ["expected a JSON object"]
28
+ };
29
+ const root = parsed;
30
+ const scenarios = root.scenarios;
31
+ if (!Array.isArray(scenarios) || scenarios.length === 0) return {
32
+ ok: false,
33
+ errors: ["`scenarios` must be a non-empty array"]
34
+ };
35
+ const kinds = new Set([
36
+ "allow",
37
+ "deny",
38
+ "ask",
39
+ "correct"
40
+ ]);
41
+ scenarios.forEach((raw, index) => {
42
+ const at = `scenarios[${index}]`;
43
+ if (typeof raw !== "object" || raw === null) {
44
+ errors.push(`${at}: expected an object`);
45
+ return;
46
+ }
47
+ const s = raw;
48
+ if (typeof s.name !== "string" || s.name === "") errors.push(`${at}.name: required`);
49
+ const when = s.when;
50
+ if (typeof when !== "object" || when === null) errors.push(`${at}.when: required`);
51
+ else {
52
+ if (typeof when.tool !== "string" || when.tool === "") errors.push(`${at}.when.tool: required`);
53
+ if (when.repeat !== void 0 && (typeof when.repeat !== "number" || when.repeat < 1)) errors.push(`${at}.when.repeat: must be a positive number`);
54
+ }
55
+ const then = s.then;
56
+ if (typeof then !== "object" || then === null) errors.push(`${at}.then: required`);
57
+ else if (typeof then.decision !== "string" || !kinds.has(then.decision)) errors.push(`${at}.then.decision: one of allow, deny, ask, correct`);
58
+ });
59
+ if (errors.length > 0) return {
60
+ ok: false,
61
+ errors
62
+ };
63
+ return {
64
+ ok: true,
65
+ suite: {
66
+ ...typeof root.pack === "string" ? { pack: root.pack } : {},
67
+ scenarios
68
+ }
69
+ };
70
+ }
71
+ function runSuite(pack, suite, options) {
72
+ const results = suite.scenarios.map((scenario) => {
73
+ const args = scenario.when.args ?? {};
74
+ const capability = options.capabilityFor(scenario.when.tool);
75
+ const target = pathOf(args);
76
+ const findings = target === void 0 || options.inspect === void 0 ? void 0 : options.inspect(target);
77
+ const decision = evaluate(pack, {
78
+ tool: scenario.when.tool,
79
+ ...capability === void 0 ? {} : { capability },
80
+ args,
81
+ ...findings !== void 0 && findings.length > 0 ? { secrets: findings } : {},
82
+ ...capability === void 0 || scenario.when.repeat === void 0 ? {} : { counts: { [capability]: scenario.when.repeat } }
83
+ });
84
+ const secretTypes = [...new Set((findings ?? []).map((f) => f.type))];
85
+ const failures = [];
86
+ if (decision.kind !== scenario.then.decision) failures.push(`decision was ${decision.kind}, expected ${scenario.then.decision}`);
87
+ if (scenario.then.rule !== void 0 && decision.rule !== scenario.then.rule) failures.push(`rule was ${decision.rule ?? "none"}, expected ${scenario.then.rule}`);
88
+ if (scenario.then.secretTypes !== void 0) {
89
+ const missing = scenario.then.secretTypes.filter((type) => !secretTypes.includes(type));
90
+ if (missing.length > 0) failures.push(`no finding of type ${missing.join(", ")}`);
91
+ }
92
+ return {
93
+ name: scenario.name,
94
+ ...scenario.given === void 0 ? {} : { given: scenario.given },
95
+ when: scenario.when,
96
+ expected: scenario.then,
97
+ actual: {
98
+ decision: decision.kind,
99
+ ...decision.rule === void 0 ? {} : { rule: decision.rule },
100
+ secretTypes
101
+ },
102
+ pass: failures.length === 0,
103
+ failures
104
+ };
105
+ });
106
+ const failed = results.filter((r) => !r.pass).length;
107
+ return {
108
+ pack: `${pack.pack} ${pack.version}`,
109
+ passed: results.length - failed,
110
+ failed,
111
+ results,
112
+ ok: failed === 0
113
+ };
114
+ }
115
+ /** The report, as lines. Phrased for a reader; the command only prints it. */
116
+ function renderSuite(result) {
117
+ const lines = [`prae test — ${result.pack}`, ""];
118
+ const width = Math.max(...result.results.map((r) => r.name.length), 20);
119
+ for (const r of result.results) {
120
+ const mark = r.pass ? "✓" : "✕";
121
+ const shown = r.pass ? `${r.actual.decision.toUpperCase()}${r.actual.rule === void 0 ? "" : ` ${r.actual.rule}`}` : r.failures.join("; ");
122
+ lines.push(` ${mark} ${r.name.padEnd(width)} ${shown}`);
123
+ }
124
+ for (const r of result.results.filter((one) => !one.pass)) {
125
+ lines.push("", ` ✕ ${r.name}`);
126
+ if (r.given !== void 0) lines.push(` GIVEN ${r.given}`);
127
+ lines.push(` WHEN ${r.when.tool}${r.when.repeat === void 0 ? "" : ` ×${r.when.repeat}`} ${JSON.stringify(r.when.args ?? {})}`);
128
+ lines.push(` THEN ${r.expected.decision}${r.expected.rule === void 0 ? "" : ` · ${r.expected.rule}`}`);
129
+ lines.push(` GOT ${r.failures.join("; ")}`);
130
+ }
131
+ const n = result.results.length;
132
+ lines.push("", `${n} scenario${n === 1 ? "" : "s"} · ${result.passed} passed · ${result.failed} failed`, result.ok ? "SECURITY TEST: PASS" : "SECURITY TEST: FAIL");
133
+ return lines;
134
+ }
135
+
136
+ //#endregion
137
+ export { parseSuite, renderSuite, runSuite };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prae-cli",
3
- "version": "0.5.1",
4
- "description": "Operator policy for agent harnesses: validate packs, explain a decision, verify a decision log, and provision a governed DSH profile.",
3
+ "version": "0.6.0",
4
+ "description": "Operator policy for agent harnesses: validate packs, explain a decision, test a pack against security invariants, verify a decision log, and provision a governed DSH profile.",
5
5
  "keywords": [
6
6
  "dsh-plugin",
7
7
  "governance",
@@ -40,10 +40,10 @@
40
40
  "tsdown": "^0.15.6",
41
41
  "typescript": "^5.9.2",
42
42
  "vitest": "^3.2.4",
43
- "@prae/extract": "0.1.0",
44
43
  "@prae/controls": "0.1.0",
45
44
  "@prae/inspect": "0.1.0",
46
45
  "@prae/instructions": "0.1.0",
46
+ "@prae/extract": "0.1.0",
47
47
  "@prae/kernel": "0.1.0",
48
48
  "@prae/ledger": "0.1.0",
49
49
  "@prae/tokens": "0.1.0"
File without changes
File without changes