@agentlaw/gateway 0.1.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 ADDED
@@ -0,0 +1,39 @@
1
+ # @agentlaw/gateway
2
+
3
+ The `agentlaw` CLI and MCP policy gateway — the enforcement point of [AgentLaw](https://github.com/Mounaji-Webs/agentlaw). Wraps any MCP server behind a signed policy manifest: every tool call is checked by the deterministic engine in `@agentlaw/core` and allowed, paused for human approval, or denied — fail-closed, hash-chain audited.
4
+
5
+ ## Quickstart
6
+
7
+ ```sh
8
+ npx @agentlaw/gateway wizard .
9
+ ```
10
+
11
+ Scaffolds a signed, ready-to-run `policy.yaml` (template + thresholds + keypair) and prints the `.mcp.json` snippet to wrap your MCP servers:
12
+
13
+ ```jsonc
14
+ {
15
+ "mcpServers": {
16
+ "safe-fs": {
17
+ "command": "npx",
18
+ "args": ["-y", "@agentlaw/gateway", "--policy", "policy.yaml", "--trust", "policy.pub",
19
+ "--", "npx", "-y", "@modelcontextprotocol/server-filesystem", "/sandbox"]
20
+ }
21
+ }
22
+ }
23
+ ```
24
+
25
+ ## CLI
26
+
27
+ | Command | What it does |
28
+ | --- | --- |
29
+ | `agentlaw wizard .` | Guided setup: template, thresholds, signed policy + keypair. |
30
+ | `agentlaw sign` | Sign a manifest with your Ed25519 private key. |
31
+ | `agentlaw verify` | Verify a manifest's signature against a trusted public key. |
32
+ | `agentlaw explain` | Dry-run: the verdict a tool call would receive, naming the rule. |
33
+ | `agentlaw audit verify` | Check the integrity of the hash-chained audit log. |
34
+
35
+ Human-in-the-loop `approve` rules prompt on the enforcement host's own terminal — no external service; no terminal means deny, never silent allow.
36
+
37
+ Spec and threat model: [RFC-0001](https://github.com/Mounaji-Webs/agentlaw/blob/main/spec/rfc-0001-policy-manifest.md).
38
+
39
+ Apache-2.0.
@@ -0,0 +1,13 @@
1
+ import type { ApprovalChannel, ApprovalRequest } from "./types.js";
2
+ export type ApprovalOutcome = "approved" | "denied" | "timeout";
3
+ export interface ApprovalResult {
4
+ outcome: ApprovalOutcome;
5
+ }
6
+ /**
7
+ * Races a channel's answer against `timeoutMs` (manifest.approvals.timeoutMs,
8
+ * onTimeout is always "deny" per the schema). Any thrown or rejected channel
9
+ * error is also treated as denied — the channel can only ever open the
10
+ * door, it can never fail open.
11
+ */
12
+ export declare function requestApprovalWithTimeout(channel: ApprovalChannel, request: ApprovalRequest, timeoutMs: number): Promise<ApprovalResult>;
13
+ //# sourceMappingURL=broker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/approvals/broker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhE,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,cAAc,CAAC,CAkBzB"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Races a channel's answer against `timeoutMs` (manifest.approvals.timeoutMs,
3
+ * onTimeout is always "deny" per the schema). Any thrown or rejected channel
4
+ * error is also treated as denied — the channel can only ever open the
5
+ * door, it can never fail open.
6
+ */
7
+ export async function requestApprovalWithTimeout(channel, request, timeoutMs) {
8
+ let timer;
9
+ const timeout = new Promise((resolveTimeout) => {
10
+ timer = setTimeout(() => resolveTimeout({ outcome: "timeout" }), timeoutMs);
11
+ });
12
+ const answer = (async () => {
13
+ try {
14
+ const approved = await channel.requestApproval(request);
15
+ return { outcome: approved ? "approved" : "denied" };
16
+ }
17
+ catch {
18
+ return { outcome: "denied" };
19
+ }
20
+ })();
21
+ try {
22
+ return await Promise.race([answer, timeout]);
23
+ }
24
+ finally {
25
+ clearTimeout(timer);
26
+ }
27
+ }
28
+ //# sourceMappingURL=broker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/approvals/broker.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAAwB,EACxB,OAAwB,EACxB,SAAiB;IAEjB,IAAI,KAAqB,CAAC;IAC1B,MAAM,OAAO,GAAG,IAAI,OAAO,CAAiB,CAAC,cAAc,EAAE,EAAE;QAC7D,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,CAAC,KAAK,IAA6B,EAAE;QAClD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YACxD,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QACvD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IACL,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/C,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAM,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { ApprovalChannel, ApprovalRequest } from "./types.js";
2
+ /**
3
+ * Prompts a human on the enforcement host's controlling terminal.
4
+ *
5
+ * The gateway process's own stdin/stdout are already the MCP JSON-RPC pipe
6
+ * to the connected client (see proxy/facade.ts's StdioServerTransport) — a
7
+ * prompt cannot use process.stdin/stdout without corrupting that protocol
8
+ * stream. This channel opens the console device directly instead: `/dev/tty`
9
+ * on POSIX, `CONIN$`/`CONOUT$` on Windows.
10
+ *
11
+ * No controlling terminal (e.g. a GUI-hosted agent host with no console at
12
+ * all) => the open fails and this channel denies, loudly, on stderr. It
13
+ * never silently allows.
14
+ */
15
+ export declare class TerminalApprovalChannel implements ApprovalChannel {
16
+ requestApproval(request: ApprovalRequest): Promise<boolean>;
17
+ }
18
+ //# sourceMappingURL=terminal-channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal-channel.d.ts","sourceRoot":"","sources":["../../src/approvals/terminal-channel.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQnE;;;;;;;;;;;;GAYG;AACH,qBAAa,uBAAwB,YAAW,eAAe;IACvD,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;CAgClE"}
@@ -0,0 +1,54 @@
1
+ import tty from "node:tty";
2
+ import fs from "node:fs";
3
+ import { createInterface } from "node:readline/promises";
4
+ function ttyPaths() {
5
+ return process.platform === "win32"
6
+ ? { inPath: "\\\\.\\CONIN$", outPath: "\\\\.\\CONOUT$" }
7
+ : { inPath: "/dev/tty", outPath: "/dev/tty" };
8
+ }
9
+ /**
10
+ * Prompts a human on the enforcement host's controlling terminal.
11
+ *
12
+ * The gateway process's own stdin/stdout are already the MCP JSON-RPC pipe
13
+ * to the connected client (see proxy/facade.ts's StdioServerTransport) — a
14
+ * prompt cannot use process.stdin/stdout without corrupting that protocol
15
+ * stream. This channel opens the console device directly instead: `/dev/tty`
16
+ * on POSIX, `CONIN$`/`CONOUT$` on Windows.
17
+ *
18
+ * No controlling terminal (e.g. a GUI-hosted agent host with no console at
19
+ * all) => the open fails and this channel denies, loudly, on stderr. It
20
+ * never silently allows.
21
+ */
22
+ export class TerminalApprovalChannel {
23
+ async requestApproval(request) {
24
+ const { inPath, outPath } = ttyPaths();
25
+ let inFd;
26
+ let outFd;
27
+ try {
28
+ inFd = fs.openSync(inPath, "r");
29
+ outFd = fs.openSync(outPath, "w");
30
+ }
31
+ catch (err) {
32
+ process.stderr.write(`[agentlaw] no controlling terminal available for approval prompt ` +
33
+ `(${err.message}) — denying rule=${request.ruleId}\n`);
34
+ return false;
35
+ }
36
+ const input = new tty.ReadStream(inFd);
37
+ const output = new tty.WriteStream(outFd);
38
+ const rl = createInterface({ input, output });
39
+ try {
40
+ const reason = request.reason ? ` (${request.reason})` : "";
41
+ const question = `\n[agentlaw] APPROVAL REQUIRED — rule=${request.ruleId} server=${request.server} tool=${request.tool}${reason}\n` +
42
+ ` args: ${JSON.stringify(request.args)}\n` +
43
+ ` approve this call? [y/N] `;
44
+ const answer = await rl.question(question);
45
+ return /^y(es)?$/i.test(answer.trim());
46
+ }
47
+ finally {
48
+ rl.close();
49
+ input.destroy();
50
+ output.destroy();
51
+ }
52
+ }
53
+ }
54
+ //# sourceMappingURL=terminal-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal-channel.js","sourceRoot":"","sources":["../../src/approvals/terminal-channel.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,SAAS,QAAQ;IACf,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO;QACjC,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,gBAAgB,EAAE;QACxD,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,uBAAuB;IAClC,KAAK,CAAC,eAAe,CAAC,OAAwB;QAC5C,MAAM,EAAE,MAAM,EAAE,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,KAAK,CAAC,OAAO,EAAE,CAAC;YAChB,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ export interface ApprovalRequest {
2
+ ruleId: string;
3
+ server: string;
4
+ tool: string;
5
+ args: Record<string, unknown>;
6
+ reason?: string;
7
+ }
8
+ /**
9
+ * A pluggable human-in-the-loop channel. `requestApproval` must resolve
10
+ * `true`/`false` — it must never leave the caller hanging. Any thrown or
11
+ * rejected call is treated as denied by the broker (defense in depth): a
12
+ * buggy channel can never fail open.
13
+ */
14
+ export interface ApprovalChannel {
15
+ requestApproval(request: ApprovalRequest): Promise<boolean>;
16
+ }
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/approvals/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/approvals/types.ts"],"names":[],"mappings":""}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}