authority-layer 0.1.0 → 0.1.2

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.
@@ -0,0 +1,2 @@
1
+ export declare function runSimulate(): Promise<void>;
2
+ //# sourceMappingURL=simulate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../src/cli/simulate.ts"],"names":[],"mappings":"AAqBA,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CA4DjD"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ // ─────────────────────────────────────────────────────────────────────────────
3
+ // authority-layer simulate
4
+ //
5
+ // Runs a short simulated agent execution that intentionally exceeds the
6
+ // budget cap so developers can see enforcement halt output without writing
7
+ // any code.
8
+ //
9
+ // Usage:
10
+ // npx authority-layer simulate
11
+ // ─────────────────────────────────────────────────────────────────────────────
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.runSimulate = runSimulate;
14
+ const AuthorityLayer_1 = require("../AuthorityLayer");
15
+ const EnforcementHalt_1 = require("../EnforcementHalt");
16
+ const RESET = "\x1b[0m";
17
+ const GREEN = "\x1b[1;32m";
18
+ const RED = "\x1b[1;31m";
19
+ const YELLOW = "\x1b[1;33m";
20
+ const BOLD = "\x1b[1m";
21
+ const DIM = "\x1b[2m";
22
+ async function runSimulate() {
23
+ console.log(`\n${BOLD}AuthorityLayer Simulation${RESET}`);
24
+ console.log(`${DIM}Demonstrating runtime enforcement.${RESET}\n`);
25
+ const authority = new AuthorityLayer_1.AuthorityLayer({
26
+ budget: { dailyUSD: 0.05 },
27
+ loopGuard: { maxToolCallsPerRun: 10 },
28
+ toolThrottle: { maxCallsPerMinute: 100 },
29
+ });
30
+ console.log(`${DIM}Config: $0.05 budget cap · 10 calls/run max · 100 calls/min${RESET}\n`);
31
+ console.log("Starting simulated agent run...\n");
32
+ let callCount = 0;
33
+ try {
34
+ await authority.wrap(async () => {
35
+ // 7 calls × $0.01 = $0.07 — exceeds the $0.05 cap after call 6
36
+ for (let i = 1; i <= 7; i++) {
37
+ callCount++;
38
+ await authority.tool("llm.chat", async () => "LLM response");
39
+ console.log(` Tool call #${i} ${DIM}llm.chat${RESET}`);
40
+ authority.recordSpend(0.01);
41
+ }
42
+ });
43
+ }
44
+ catch (err) {
45
+ if (err instanceof EnforcementHalt_1.EnforcementHalt) {
46
+ console.log(`\n${RED}${BOLD}⛔ Execution halted by AuthorityLayer${RESET}\n`);
47
+ const h = err.enforcement;
48
+ const display = {
49
+ status: h.status,
50
+ reason: h.reason,
51
+ limit: Math.round(h.limit * 100) / 100,
52
+ spent: Math.round(h.spent * 100) / 100,
53
+ event_id: h.event_id,
54
+ };
55
+ console.log(YELLOW + JSON.stringify(display, null, 2) + RESET);
56
+ }
57
+ else {
58
+ throw err;
59
+ }
60
+ }
61
+ // ── Integrity check ───────────────────────────────────────────────────────
62
+ const valid = authority.verifyChain();
63
+ const chain = authority.getChain();
64
+ console.log(`\n${DIM}─── Event chain ${"─".repeat(44)}${RESET}`);
65
+ for (const event of chain) {
66
+ const ts = new Date(event.timestamp).toISOString().slice(11, 23);
67
+ console.log(` ${DIM}[${ts}]${RESET} ${event.type.padEnd(20)} ${DIM}${event.event_id}${RESET}`);
68
+ }
69
+ console.log();
70
+ if (valid) {
71
+ console.log(`Event chain integrity: ${GREEN}${BOLD}VERIFIED${RESET}`);
72
+ }
73
+ else {
74
+ console.log(`Event chain integrity: ${RED}${BOLD}TAMPERED${RESET}`);
75
+ }
76
+ console.log(`Total events: ${chain.length}\n`);
77
+ }
78
+ //# sourceMappingURL=simulate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulate.js","sourceRoot":"","sources":["../../src/cli/simulate.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,2BAA2B;AAC3B,EAAE;AACF,wEAAwE;AACxE,2EAA2E;AAC3E,YAAY;AACZ,EAAE;AACF,SAAS;AACT,iCAAiC;AACjC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AC;QACjE,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,IAAI,KAAK,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,GAAG,GAAG,KAAK,CAAC,QAAQ,GAAG,KAAK,EAAE,CAAC,CAAC;IACtG,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,IAAI,KAAK,EAAE,CAAC;QACR,OAAO,CAAC,GAAG,CAAC,0BAA0B,KAAK,GAAG,IAAI,WAAW,KAAK,EAAE,CAAC,CAAC;IAC1E,CAAC;SAAM,CAAC;QACJ,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,GAAG,IAAI,WAAW,KAAK,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;AACnD,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ declare const RESET = "\u001B[0m";
3
+ declare const BOLD = "\u001B[1m";
4
+ declare const DIM = "\u001B[2m";
5
+ declare const CYAN = "\u001B[1;36m";
6
+ declare const YELLOW = "\u001B[1;33m";
7
+ declare const subcommand: string;
8
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAYA,QAAA,MAAM,KAAK,cAAY,CAAC;AACxB,QAAA,MAAM,IAAI,cAAY,CAAC;AACvB,QAAA,MAAM,GAAG,cAAY,CAAC;AACtB,QAAA,MAAM,IAAI,iBAAe,CAAC;AAC1B,QAAA,MAAM,MAAM,iBAAe,CAAC;AAE5B,QAAA,MAAM,UAAU,QAAkB,CAAC"}
package/dist/cli.js ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // ─────────────────────────────────────────────────────────────────────────────
4
+ // authority-layer CLI dispatcher
5
+ //
6
+ // Routes subcommands to their implementations.
7
+ // All new subcommands should be added here.
8
+ //
9
+ // Usage:
10
+ // npx authority-layer doctor
11
+ // npx authority-layer simulate
12
+ // ─────────────────────────────────────────────────────────────────────────────
13
+ const RESET = "\x1b[0m";
14
+ const BOLD = "\x1b[1m";
15
+ const DIM = "\x1b[2m";
16
+ const CYAN = "\x1b[1;36m";
17
+ const YELLOW = "\x1b[1;33m";
18
+ const subcommand = process.argv[2];
19
+ switch (subcommand) {
20
+ case "doctor": {
21
+ // Doctor runs its own top-level logic — require the compiled file directly
22
+ require("./doctor");
23
+ break;
24
+ }
25
+ case "simulate": {
26
+ const { runSimulate } = require("./cli/simulate");
27
+ runSimulate().catch((err) => {
28
+ console.error(err);
29
+ process.exit(1);
30
+ });
31
+ break;
32
+ }
33
+ default: {
34
+ const pkg = require("../package.json");
35
+ console.log(`\n${BOLD}${pkg.name}${RESET} ${DIM}v${pkg.version}${RESET}\n`);
36
+ console.log("Usage:\n");
37
+ console.log(` ${CYAN}authority-layer doctor${RESET} ${DIM}Run environment checks${RESET}`);
38
+ console.log(` ${CYAN}authority-layer simulate${RESET} ${DIM}Run a live enforcement simulation${RESET}`);
39
+ console.log();
40
+ if (subcommand) {
41
+ console.log(`${YELLOW}Unknown command: ${subcommand}${RESET}\n`);
42
+ process.exit(1);
43
+ }
44
+ process.exit(0);
45
+ }
46
+ }
47
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AACA,gFAAgF;AAChF,iCAAiC;AACjC,EAAE;AACF,+CAA+C;AAC/C,4CAA4C;AAC5C,EAAE;AACF,SAAS;AACT,+BAA+B;AAC/B,iCAAiC;AACjC,gFAAgF;AAEhF,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,IAAI,GAAG,SAAS,CAAC;AACvB,MAAM,GAAG,GAAG,SAAS,CAAC;AACtB,MAAM,I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IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authority-layer",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Hard execution and budget limits for autonomous agents — enforced locally.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "bin": {
11
- "authority-layer": "dist/doctor.js"
11
+ "authority-layer": "dist/cli.js"
12
12
  },
13
13
  "scripts": {
14
14
  "build": "tsc -p tsconfig.json",
@@ -16,7 +16,8 @@
16
16
  "typecheck": "tsc -p tsconfig.json --noEmit",
17
17
  "validate": "tsc -p tsconfig.json && node dist/index.js",
18
18
  "example": "node ../../examples/run.js",
19
- "doctor": "node dist/doctor.js",
19
+ "doctor": "node dist/cli.js doctor",
20
+ "simulate": "node dist/cli.js simulate",
20
21
  "prepublishOnly": "npm run build && npm run typecheck"
21
22
  },
22
23
  "keywords": [
@@ -25,11 +26,20 @@
25
26
  "guardrails",
26
27
  "runtime",
27
28
  "budget",
28
- "limits"
29
+ "limits",
30
+ "enforcement",
31
+ "autonomous-agents",
32
+ "llm",
33
+ "agentic",
34
+ "safety",
35
+ "rate-limiting",
36
+ "cost-control",
37
+ "openai",
38
+ "tool-calls"
29
39
  ],
30
40
  "repository": {
31
41
  "type": "git",
32
- "url": "https://github.com/032383justin/authority-layer"
42
+ "url": "git+https://github.com/032383justin/authority-layer.git"
33
43
  },
34
44
  "homepage": "https://github.com/032383justin/authority-layer",
35
45
  "bugs": {