attenu-guard 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.
Files changed (112) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +202 -0
  3. package/README.md +200 -0
  4. package/SECURITY.md +34 -0
  5. package/bin/attenu-guard.js +4 -0
  6. package/dist/cjs/adapters/langgraph.d.ts +174 -0
  7. package/dist/cjs/adapters/langgraph.d.ts.map +1 -0
  8. package/dist/cjs/adapters/langgraph.js +242 -0
  9. package/dist/cjs/adapters/langgraph.js.map +1 -0
  10. package/dist/cjs/audit.d.ts +82 -0
  11. package/dist/cjs/audit.d.ts.map +1 -0
  12. package/dist/cjs/audit.js +195 -0
  13. package/dist/cjs/audit.js.map +1 -0
  14. package/dist/cjs/authority.d.ts +114 -0
  15. package/dist/cjs/authority.d.ts.map +1 -0
  16. package/dist/cjs/authority.js +238 -0
  17. package/dist/cjs/authority.js.map +1 -0
  18. package/dist/cjs/canonical.d.ts +91 -0
  19. package/dist/cjs/canonical.d.ts.map +1 -0
  20. package/dist/cjs/canonical.js +372 -0
  21. package/dist/cjs/canonical.js.map +1 -0
  22. package/dist/cjs/ceilings.d.ts +211 -0
  23. package/dist/cjs/ceilings.d.ts.map +1 -0
  24. package/dist/cjs/ceilings.js +476 -0
  25. package/dist/cjs/ceilings.js.map +1 -0
  26. package/dist/cjs/chain.d.ts +106 -0
  27. package/dist/cjs/chain.d.ts.map +1 -0
  28. package/dist/cjs/chain.js +0 -0
  29. package/dist/cjs/chain.js.map +1 -0
  30. package/dist/cjs/cli.d.ts +16 -0
  31. package/dist/cjs/cli.d.ts.map +1 -0
  32. package/dist/cjs/cli.js +100 -0
  33. package/dist/cjs/cli.js.map +1 -0
  34. package/dist/cjs/evidence.d.ts +163 -0
  35. package/dist/cjs/evidence.d.ts.map +1 -0
  36. package/dist/cjs/evidence.js +409 -0
  37. package/dist/cjs/evidence.js.map +1 -0
  38. package/dist/cjs/guard.d.ts +186 -0
  39. package/dist/cjs/guard.d.ts.map +1 -0
  40. package/dist/cjs/guard.js +432 -0
  41. package/dist/cjs/guard.js.map +1 -0
  42. package/dist/cjs/index.d.ts +52 -0
  43. package/dist/cjs/index.d.ts.map +1 -0
  44. package/dist/cjs/index.js +99 -0
  45. package/dist/cjs/index.js.map +1 -0
  46. package/dist/cjs/package.json +3 -0
  47. package/dist/cjs/reasons.d.ts +93 -0
  48. package/dist/cjs/reasons.d.ts.map +1 -0
  49. package/dist/cjs/reasons.js +139 -0
  50. package/dist/cjs/reasons.js.map +1 -0
  51. package/dist/cjs/strikes.d.ts +24 -0
  52. package/dist/cjs/strikes.d.ts.map +1 -0
  53. package/dist/cjs/strikes.js +30 -0
  54. package/dist/cjs/strikes.js.map +1 -0
  55. package/dist/cjs/wire.d.ts +83 -0
  56. package/dist/cjs/wire.d.ts.map +1 -0
  57. package/dist/cjs/wire.js +165 -0
  58. package/dist/cjs/wire.js.map +1 -0
  59. package/dist/esm/adapters/langgraph.d.ts +174 -0
  60. package/dist/esm/adapters/langgraph.d.ts.map +1 -0
  61. package/dist/esm/adapters/langgraph.js +199 -0
  62. package/dist/esm/adapters/langgraph.js.map +1 -0
  63. package/dist/esm/audit.d.ts +82 -0
  64. package/dist/esm/audit.d.ts.map +1 -0
  65. package/dist/esm/audit.js +189 -0
  66. package/dist/esm/audit.js.map +1 -0
  67. package/dist/esm/authority.d.ts +114 -0
  68. package/dist/esm/authority.d.ts.map +1 -0
  69. package/dist/esm/authority.js +233 -0
  70. package/dist/esm/authority.js.map +1 -0
  71. package/dist/esm/canonical.d.ts +91 -0
  72. package/dist/esm/canonical.d.ts.map +1 -0
  73. package/dist/esm/canonical.js +359 -0
  74. package/dist/esm/canonical.js.map +1 -0
  75. package/dist/esm/ceilings.d.ts +211 -0
  76. package/dist/esm/ceilings.d.ts.map +1 -0
  77. package/dist/esm/ceilings.js +460 -0
  78. package/dist/esm/ceilings.js.map +1 -0
  79. package/dist/esm/chain.d.ts +106 -0
  80. package/dist/esm/chain.d.ts.map +1 -0
  81. package/dist/esm/chain.js +0 -0
  82. package/dist/esm/chain.js.map +1 -0
  83. package/dist/esm/cli.d.ts +16 -0
  84. package/dist/esm/cli.d.ts.map +1 -0
  85. package/dist/esm/cli.js +97 -0
  86. package/dist/esm/cli.js.map +1 -0
  87. package/dist/esm/evidence.d.ts +163 -0
  88. package/dist/esm/evidence.d.ts.map +1 -0
  89. package/dist/esm/evidence.js +398 -0
  90. package/dist/esm/evidence.js.map +1 -0
  91. package/dist/esm/guard.d.ts +186 -0
  92. package/dist/esm/guard.d.ts.map +1 -0
  93. package/dist/esm/guard.js +427 -0
  94. package/dist/esm/guard.js.map +1 -0
  95. package/dist/esm/index.d.ts +52 -0
  96. package/dist/esm/index.d.ts.map +1 -0
  97. package/dist/esm/index.js +42 -0
  98. package/dist/esm/index.js.map +1 -0
  99. package/dist/esm/package.json +3 -0
  100. package/dist/esm/reasons.d.ts +93 -0
  101. package/dist/esm/reasons.d.ts.map +1 -0
  102. package/dist/esm/reasons.js +134 -0
  103. package/dist/esm/reasons.js.map +1 -0
  104. package/dist/esm/strikes.d.ts +24 -0
  105. package/dist/esm/strikes.d.ts.map +1 -0
  106. package/dist/esm/strikes.js +26 -0
  107. package/dist/esm/strikes.js.map +1 -0
  108. package/dist/esm/wire.d.ts +83 -0
  109. package/dist/esm/wire.d.ts.map +1 -0
  110. package/dist/esm/wire.js +159 -0
  111. package/dist/esm/wire.js.map +1 -0
  112. package/package.json +89 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence.js","sourceRoot":"","sources":["../../src/evidence.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAmGH,0CAwBC;AAGD,8BAkBC;AAsBD,oCAwCC;AAuED,0CAwCC;AAoBD,0BAkCC;AA4BD,oCA8EC;AAGD,kCAEC;AAheD,iDAOwB;AACxB,6CAAyC;AAEzC,yCAAoH;AACpH,iDAA2C;AAI3C;;;;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OAAO;QACL,EAAE;QACF,MAAM;QACN,QAAQ;QACR,KAAK,EAAE,IAAI,CAAC,IAAI;QAChB,eAAe,EAAE,OAAO;QACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;KAClC,CAAC;AACJ,CAAC;AAED,6EAA6E;AAC7E,SAAgB,WAAW,CAAC,IAAY;IACtC,OAAO,IAAA,wBAAS,EAAC,IAAI,CAAsB,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Guard — the runtime object a developer actually holds.
3
+ *
4
+ * `Guard.issue(...)` a fresh root Guard, starting a new delegation chain.
5
+ * `delegate(...)` a child Guard whose authority is the attenuated meet of
6
+ * this guard's authority and what was requested. It never
7
+ * widens — there is no method that can. Throws
8
+ * `AuthorityError` on a STRUCTURAL failure (revoked or
9
+ * expired parent, integrity failure, depth/fanout).
10
+ * `check(...)` authorize an action. Returns a `Decision`; it never
11
+ * throws on a policy denial, because a denial is a normal
12
+ * outcome to reason about, not a bug. Every allow and
13
+ * deny is appended to the audit log.
14
+ * `enforce(...)` `check` and throw `AuthorityDenied` if not allowed —
15
+ * the hard-stop gate for callers that want to fail fast.
16
+ * `wouldAllow(...)` the same policy evaluation as `check`, as a pure
17
+ * dry-run: it writes NOTHING to the audit log, so a
18
+ * planner can ask "could I do this?" without leaving a
19
+ * record as though the action had been attempted.
20
+ * `revoke(...)` cascade-revoke a node (by default this one) and its
21
+ * whole subtree.
22
+ *
23
+ * `AuthorityError` and `AuthorityDenied` are deliberately distinct: a policy
24
+ * denial is not an error.
25
+ *
26
+ * The audit log's `event` strings keep the original vocabulary
27
+ * (`spawn`/`spawn_denied`/`kill`) even though the API reads
28
+ * issue/delegate/revoke. That field is a separately-versioned published wire
29
+ * contract that verifiers depend on.
30
+ */
31
+ import type { Json } from "./canonical.js";
32
+ import { Authority } from "./authority.js";
33
+ import { AuditLog, type Sink } from "./audit.js";
34
+ import { type Clock } from "./chain.js";
35
+ import { type Context } from "./ceilings.js";
36
+ import { Decision, Reason } from "./reasons.js";
37
+ import type { StrikePolicy } from "./strikes.js";
38
+ /**
39
+ * Thrown only by `enforce`. Carries the full `Decision`, so a caller can branch
40
+ * on `err.decision.reasons[0].code` instead of parsing a message string.
41
+ */
42
+ export declare class AuthorityDenied extends Error {
43
+ readonly decision: Decision;
44
+ constructor(decision: Decision);
45
+ }
46
+ export interface IssueOptions {
47
+ task?: string;
48
+ chainId?: string;
49
+ maxDepth?: number;
50
+ maxFanout?: number;
51
+ /** Where to write the `.jsonl` ledger. Omit for an in-memory log. */
52
+ auditPath?: string | null;
53
+ clock?: Clock;
54
+ /** Refuse a metered call that omits a held metered ceiling's context field. */
55
+ strictMetering?: boolean;
56
+ strikes?: StrikePolicy | null;
57
+ auditSinks?: readonly Sink[];
58
+ }
59
+ export interface CheckOptions {
60
+ context?: Context | null;
61
+ /** Marks the call as consuming a metered resource; see `strictMetering`. */
62
+ metered?: boolean;
63
+ /** The tool label recorded on the ledger entry. */
64
+ tool?: string | null;
65
+ /** What the caller knows about WHY this scope would be absent. */
66
+ disposition?: string | null;
67
+ }
68
+ export interface RecordDenialOptions {
69
+ scope?: string | null;
70
+ tool?: string | null;
71
+ context?: Context | null;
72
+ disposition?: string | null;
73
+ }
74
+ export declare class Guard {
75
+ private readonly node;
76
+ private readonly chain;
77
+ private readonly audit;
78
+ private readonly seq;
79
+ private readonly strict;
80
+ private readonly strikes;
81
+ private constructor();
82
+ /** A fresh root Guard, starting a new delegation chain. */
83
+ static issue(agentId: string, authority: Authority, options?: IssueOptions): Guard;
84
+ get nodeId(): string;
85
+ get chainId(): string;
86
+ get authority(): Authority;
87
+ /** The `agentId` this Guard was issued or delegated to. */
88
+ get agentId(): string;
89
+ /** Has this node — or an ancestor — been revoked? */
90
+ get isRevoked(): boolean;
91
+ /** Has this node's TTL elapsed? */
92
+ get isExpired(): boolean;
93
+ /** Did the holder mark this node's work finished? */
94
+ get isComplete(): boolean;
95
+ /** Is `other` an ancestor of this guard in the same chain? */
96
+ isDescendantOf(other: Guard): boolean;
97
+ /**
98
+ * Mark this node's work FINISHED — one `done` event, idempotent. Purely a
99
+ * lifecycle marker for the ledger and downstream analytics (a delegation that
100
+ * never reached `done` was cut short); it does NOT change authority.
101
+ * Revocation is the hard stop.
102
+ */
103
+ complete(): boolean;
104
+ /**
105
+ * Create a child Guard. The child's authority is `this.authority.meet(request)`
106
+ * — provably narrower than this guard's by construction. A request wider than
107
+ * what this guard holds comes back narrowed, not refused.
108
+ *
109
+ * Throws `AuthorityError` for structural failures (revoked or expired parent,
110
+ * integrity failure, depth/fanout overflow). Those are invalid calls, not
111
+ * policy outcomes, so they are not expressed as a Decision.
112
+ */
113
+ delegate(agentId: string, request: Authority, task: string): Guard;
114
+ /**
115
+ * A pure dry-run of `delegate`'s structural preconditions (revoked or expired
116
+ * parent, banned agent, depth/fanout ceilings): creates no node, consumes no
117
+ * fanout, writes nothing. The granted authority would be
118
+ * `this.authority.meet(request)`.
119
+ */
120
+ wouldDelegate(agentId: string, _request?: Authority): Decision;
121
+ private append;
122
+ /**
123
+ * The actual policy evaluation, shared verbatim by `check` and `wouldAllow`.
124
+ * Node state (integrity, revocation, TTL) is checked before scope and
125
+ * ceilings, because a compromised or revoked node's scope grants are moot.
126
+ */
127
+ private evaluate;
128
+ private static checkDisposition;
129
+ private logDecision;
130
+ private callLimits;
131
+ /**
132
+ * Fill in `calls` / `calls[<pattern>]` for every held call ceiling the caller
133
+ * left undeclared, reading the per-(node, pattern) meter. Returns the limits
134
+ * that were auto-filled AND apply to this scope, to be counted on allow.
135
+ */
136
+ private autoMeter;
137
+ /**
138
+ * Authorize an action. Returns a `Decision`; it does not throw on a denial.
139
+ * Every call — allow or deny — is appended to the audit log.
140
+ *
141
+ * Auto-metering: when this node holds a `CallLimit` and the caller did not
142
+ * supply `calls`, the guard supplies the running count for (node, pattern)
143
+ * itself, including this call, and increments it on allow. An explicit
144
+ * `calls` in the context always wins.
145
+ */
146
+ check(scope: string, options?: CheckOptions): Decision;
147
+ /**
148
+ * `check`, and throw `AuthorityDenied` if not allowed. The hard-stop gate:
149
+ * use this where a denial should abort the caller rather than be branched on.
150
+ */
151
+ enforce(scope: string, options?: CheckOptions): void;
152
+ /**
153
+ * A pure dry-run: identical policy evaluation to `check`, but it never throws
154
+ * and — critically — writes NOTHING to the audit log.
155
+ */
156
+ wouldAllow(scope: string, options?: CheckOptions): Decision;
157
+ /**
158
+ * Put an ADAPTER-LEVEL refusal on the audit trail as a `deny` event and
159
+ * return it as a Decision — for denials that happen UPSTREAM of policy
160
+ * evaluation: an agent the chain never delegated to, a tool with no declared
161
+ * permissions, unparseable tool arguments. Nothing is evaluated; the caller
162
+ * has already decided, and this records it in the same tamper-evident log.
163
+ *
164
+ * `scope` defaults to `tool` (or "-"), because the published schema requires
165
+ * a string scope on allow and deny events.
166
+ */
167
+ recordDenial(reason: Reason | string, message?: string, options?: RecordDenialOptions): Decision;
168
+ /** Cascade-revoke a node — by default this one — and its whole subtree. */
169
+ revoke(nodeId?: string | null): string[];
170
+ /**
171
+ * Revoke an agent BY NAME, chain-wide: every node it holds is cascade-revoked
172
+ * and no node may `delegate` to it again. Use this — not `revoke(nodeId)` —
173
+ * when the intent is "this principal is done", because frameworks hand off to
174
+ * the same agent freely and a fresh `delegate` would otherwise mint it clean
175
+ * authority.
176
+ */
177
+ revokeAgent(agentId: string): string[];
178
+ /**
179
+ * Is this guard's authority provably narrower than `parent`'s? Exactly the
180
+ * relation an offline verifier applies to two wire tokens.
181
+ */
182
+ isNarrowerThan(parent: Guard): boolean;
183
+ auditLog(): AuditLog;
184
+ graph(): Record<string, Json>;
185
+ }
186
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB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AQ;IA4DhB,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAS/B,OAAO,CAAC,WAAW;IAmCnB,OAAO,CAAC,UAAU;IAIlB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAYjB;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,QAAQ;IAiC1D;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI;IAKxD;;;OAGG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,QAAQ;IAM/D;;;;;;;;;OASG;IACH,YAAY,CACV,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,OAAO,SAAK,EACZ,OAAO,GAAE,mBAAwB,GAChC,QAAQ;IAiBX,2EAA2E;IAC3E,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,EAAE;IAOxC;;;;;;OAMG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAatC;;;OAGG;IACH,cAAc,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO;IAMtC,QAAQ,IAAI,QAAQ;IAIpB,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;CAG9B"}
@@ -0,0 +1,432 @@
1
+ "use strict";
2
+ /**
3
+ * Guard — the runtime object a developer actually holds.
4
+ *
5
+ * `Guard.issue(...)` a fresh root Guard, starting a new delegation chain.
6
+ * `delegate(...)` a child Guard whose authority is the attenuated meet of
7
+ * this guard's authority and what was requested. It never
8
+ * widens — there is no method that can. Throws
9
+ * `AuthorityError` on a STRUCTURAL failure (revoked or
10
+ * expired parent, integrity failure, depth/fanout).
11
+ * `check(...)` authorize an action. Returns a `Decision`; it never
12
+ * throws on a policy denial, because a denial is a normal
13
+ * outcome to reason about, not a bug. Every allow and
14
+ * deny is appended to the audit log.
15
+ * `enforce(...)` `check` and throw `AuthorityDenied` if not allowed —
16
+ * the hard-stop gate for callers that want to fail fast.
17
+ * `wouldAllow(...)` the same policy evaluation as `check`, as a pure
18
+ * dry-run: it writes NOTHING to the audit log, so a
19
+ * planner can ask "could I do this?" without leaving a
20
+ * record as though the action had been attempted.
21
+ * `revoke(...)` cascade-revoke a node (by default this one) and its
22
+ * whole subtree.
23
+ *
24
+ * `AuthorityError` and `AuthorityDenied` are deliberately distinct: a policy
25
+ * denial is not an error.
26
+ *
27
+ * The audit log's `event` strings keep the original vocabulary
28
+ * (`spawn`/`spawn_denied`/`kill`) even though the API reads
29
+ * issue/delegate/revoke. That field is a separately-versioned published wire
30
+ * contract that verifiers depend on.
31
+ */
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.Guard = exports.AuthorityDenied = void 0;
34
+ const authority_js_1 = require("./authority.js");
35
+ const audit_js_1 = require("./audit.js");
36
+ const chain_js_1 = require("./chain.js");
37
+ const ceilings_js_1 = require("./ceilings.js");
38
+ const reasons_js_1 = require("./reasons.js");
39
+ /**
40
+ * Thrown only by `enforce`. Carries the full `Decision`, so a caller can branch
41
+ * on `err.decision.reasons[0].code` instead of parsing a message string.
42
+ */
43
+ class AuthorityDenied extends Error {
44
+ decision;
45
+ constructor(decision) {
46
+ super(decision.explain());
47
+ this.decision = decision;
48
+ this.name = "AuthorityDenied";
49
+ }
50
+ }
51
+ exports.AuthorityDenied = AuthorityDenied;
52
+ /**
53
+ * A monotonic integer for audit sequencing, distinct from the wall clock used
54
+ * for TTL expiry — it keeps the log's ordering deterministic regardless of
55
+ * clock resolution.
56
+ */
57
+ class SeqClock {
58
+ t = 0;
59
+ now() {
60
+ this.t += 1;
61
+ return this.t;
62
+ }
63
+ }
64
+ class Guard {
65
+ node;
66
+ chain;
67
+ audit;
68
+ seq;
69
+ strict;
70
+ strikes;
71
+ constructor(node, chain, audit, seq, strict, strikes) {
72
+ this.node = node;
73
+ this.chain = chain;
74
+ this.audit = audit;
75
+ this.seq = seq;
76
+ this.strict = strict;
77
+ this.strikes = strikes;
78
+ }
79
+ // ---- factory ----------------------------------------------------------
80
+ /** A fresh root Guard, starting a new delegation chain. */
81
+ static issue(agentId, authority, options = {}) {
82
+ const chainId = options.chainId ?? "chain";
83
+ const chain = new chain_js_1.Chain(chainId, {
84
+ maxDepth: options.maxDepth ?? 6,
85
+ maxFanout: options.maxFanout ?? 16,
86
+ clock: options.clock ?? new chain_js_1.MonotonicClock(),
87
+ });
88
+ const audit = new audit_js_1.AuditLog({
89
+ path: options.auditPath ?? null,
90
+ sinks: options.auditSinks ?? [],
91
+ });
92
+ const seq = new SeqClock();
93
+ const node = chain.addRoot(agentId, authority, options.task ?? "root");
94
+ audit.append("root", seq.now(), {
95
+ chain_id: chainId,
96
+ node: node.nodeId,
97
+ agent: agentId,
98
+ authority: authority.toWire(),
99
+ });
100
+ return new Guard(node, chain, audit, seq, options.strictMetering ?? false, options.strikes ?? null);
101
+ }
102
+ // ---- identity ---------------------------------------------------------
103
+ get nodeId() {
104
+ return this.node.nodeId;
105
+ }
106
+ get chainId() {
107
+ return this.chain.chainId;
108
+ }
109
+ get authority() {
110
+ return this.node.authority;
111
+ }
112
+ /** The `agentId` this Guard was issued or delegated to. */
113
+ get agentId() {
114
+ return this.node.agentId;
115
+ }
116
+ /** Has this node — or an ancestor — been revoked? */
117
+ get isRevoked() {
118
+ return this.chain.isRevoked(this.node.nodeId);
119
+ }
120
+ /** Has this node's TTL elapsed? */
121
+ get isExpired() {
122
+ return this.chain.isExpired(this.node);
123
+ }
124
+ /** Did the holder mark this node's work finished? */
125
+ get isComplete() {
126
+ return this.node.complete;
127
+ }
128
+ /** Is `other` an ancestor of this guard in the same chain? */
129
+ isDescendantOf(other) {
130
+ if (other.chain !== this.chain)
131
+ return false;
132
+ let node = this.node;
133
+ while (node !== undefined && node.parentId !== null) {
134
+ if (node.parentId === other.node.nodeId)
135
+ return true;
136
+ node = this.chain.nodes.get(node.parentId);
137
+ }
138
+ return false;
139
+ }
140
+ /**
141
+ * Mark this node's work FINISHED — one `done` event, idempotent. Purely a
142
+ * lifecycle marker for the ledger and downstream analytics (a delegation that
143
+ * never reached `done` was cut short); it does NOT change authority.
144
+ * Revocation is the hard stop.
145
+ */
146
+ complete() {
147
+ if (this.node.complete)
148
+ return false;
149
+ this.node.complete = true;
150
+ this.append("done", {
151
+ chain_id: this.chainId,
152
+ node: this.node.nodeId,
153
+ agent: this.node.agentId,
154
+ });
155
+ return true;
156
+ }
157
+ // ---- delegation -------------------------------------------------------
158
+ /**
159
+ * Create a child Guard. The child's authority is `this.authority.meet(request)`
160
+ * — provably narrower than this guard's by construction. A request wider than
161
+ * what this guard holds comes back narrowed, not refused.
162
+ *
163
+ * Throws `AuthorityError` for structural failures (revoked or expired parent,
164
+ * integrity failure, depth/fanout overflow). Those are invalid calls, not
165
+ * policy outcomes, so they are not expressed as a Decision.
166
+ */
167
+ delegate(agentId, request, task) {
168
+ let child;
169
+ try {
170
+ child = this.chain.addChild(this.node.nodeId, agentId, request, task);
171
+ }
172
+ catch (e) {
173
+ if (e instanceof authority_js_1.AuthorityError) {
174
+ this.append("spawn_denied", {
175
+ chain_id: this.chainId,
176
+ parent: this.node.nodeId,
177
+ agent: agentId,
178
+ task,
179
+ reason: e.reason,
180
+ detail: e.detail,
181
+ });
182
+ }
183
+ throw e;
184
+ }
185
+ this.append("spawn", {
186
+ chain_id: this.chainId,
187
+ parent: this.node.nodeId,
188
+ node: child.nodeId,
189
+ agent: agentId,
190
+ task,
191
+ requested: request.toWire(),
192
+ granted: child.authority.toWire(),
193
+ });
194
+ return new Guard(child, this.chain, this.audit, this.seq, this.strict, this.strikes);
195
+ }
196
+ /**
197
+ * A pure dry-run of `delegate`'s structural preconditions (revoked or expired
198
+ * parent, banned agent, depth/fanout ceilings): creates no node, consumes no
199
+ * fanout, writes nothing. The granted authority would be
200
+ * `this.authority.meet(request)`.
201
+ */
202
+ wouldDelegate(agentId, _request) {
203
+ const err = this.chain.delegationError(this.node.nodeId, agentId);
204
+ if (err === null)
205
+ return reasons_js_1.Decision.allow(this.node.nodeId);
206
+ return reasons_js_1.Decision.deny(new reasons_js_1.Reason(err.reason, { message: err.message }), this.node.nodeId);
207
+ }
208
+ append(event, fields) {
209
+ return this.audit.append(event, this.seq.now(), fields);
210
+ }
211
+ // ---- policy evaluation ------------------------------------------------
212
+ /**
213
+ * The actual policy evaluation, shared verbatim by `check` and `wouldAllow`.
214
+ * Node state (integrity, revocation, TTL) is checked before scope and
215
+ * ceilings, because a compromised or revoked node's scope grants are moot.
216
+ */
217
+ evaluate(scope, context, metered) {
218
+ const { node, chain } = this;
219
+ const auth = node.authority;
220
+ const nid = node.nodeId;
221
+ if (!chain.verifyIntegrity(node)) {
222
+ return reasons_js_1.Decision.deny(new reasons_js_1.Reason(reasons_js_1.ReasonCode.INTEGRITY, { message: "authority state failed its integrity seal" }), nid);
223
+ }
224
+ if (chain.isRevoked(nid)) {
225
+ return reasons_js_1.Decision.deny(new reasons_js_1.Reason(reasons_js_1.ReasonCode.REVOKED, { message: "node has been revoked" }), nid);
226
+ }
227
+ if (chain.isExpired(node)) {
228
+ const age = chain.clock.now() - node.issuedAt;
229
+ return reasons_js_1.Decision.deny(new reasons_js_1.Reason(reasons_js_1.ReasonCode.EXPIRED, {
230
+ limit: auth.ttl,
231
+ requested: age,
232
+ message: "authority ttl has elapsed",
233
+ }), nid);
234
+ }
235
+ // Strict metering: a call flagged as consuming a metered resource must
236
+ // DECLARE every metered dimension this node holds a ceiling on; any it
237
+ // omits is refused rather than silently treated as free. Checked PER
238
+ // CEILING, not "is the context empty?" — a partial context that mentions
239
+ // egress but forgets rows would otherwise let the row ceiling go
240
+ // unevaluated, which is the exact slip a per-tool context function makes.
241
+ if (this.strict && metered) {
242
+ const missing = auth.ceilings
243
+ .filter((c) => (0, ceilings_js_1.isMetered)(c) && !((0, ceilings_js_1.ctxFieldOf)(c) in context))
244
+ .map((c) => c.key);
245
+ if (missing.length > 0) {
246
+ const held = auth.ceilings.filter(ceilings_js_1.isMetered).map((c) => c.key);
247
+ return reasons_js_1.Decision.deny(new reasons_js_1.Reason(reasons_js_1.ReasonCode.UNMETERED, {
248
+ constraint: missing.join(","),
249
+ message: `metered=True but context omits [${missing.map((m) => `'${m}'`).join(", ")}]; ` +
250
+ `metered ceilings held: [${held.map((m) => `'${m}'`).join(", ")}]`,
251
+ }), nid);
252
+ }
253
+ }
254
+ const decision = auth.permits(scope, context);
255
+ if (decision.determiningNode === null) {
256
+ return new reasons_js_1.Decision(decision.allowed, decision.reasons, nid);
257
+ }
258
+ return decision;
259
+ }
260
+ static checkDisposition(disposition) {
261
+ if (disposition !== null && disposition !== undefined && !reasons_js_1.DISPOSITIONS.has(disposition)) {
262
+ throw new Error(`unknown disposition ${JSON.stringify(disposition)}; expected one of ` +
263
+ `${Array.from(reasons_js_1.DISPOSITIONS).sort().join(", ")}`);
264
+ }
265
+ }
266
+ logDecision(decision, scope, tool, context, disposition) {
267
+ const event = decision.allowed ? "allow" : "deny";
268
+ const fields = {
269
+ chain_id: this.chainId,
270
+ node: this.node.nodeId,
271
+ scope,
272
+ tool,
273
+ context: { ...context },
274
+ };
275
+ if (!decision.allowed) {
276
+ // "reason" is a single code string, the shape the published schema
277
+ // documents and every existing consumer reads. "reasons" is the full
278
+ // structured list for anyone who wants every violated Reason.
279
+ const reason = decision.reasons.length > 0 ? decision.reasons[0].code : null;
280
+ fields["reason"] = reason;
281
+ fields["reasons"] = decision.reasons.map((r) => r.toDict());
282
+ // "disposition": WHY the scope was absent — the caller's statement, or,
283
+ // for a plain scope_not_granted the caller did not explain, the library's
284
+ // own truth: out_of_authority. Allow entries never carry it.
285
+ const d = disposition ??
286
+ (reason === reasons_js_1.ReasonCode.SCOPE_NOT_GRANTED ? reasons_js_1.Disposition.OUT_OF_AUTHORITY : null);
287
+ if (d !== null)
288
+ fields["disposition"] = d;
289
+ }
290
+ this.append(event, fields);
291
+ }
292
+ // ---- enforcement ------------------------------------------------------
293
+ callLimits() {
294
+ return this.node.authority.ceilings.filter((c) => String(c.key).startsWith("max_calls"));
295
+ }
296
+ /**
297
+ * Fill in `calls` / `calls[<pattern>]` for every held call ceiling the caller
298
+ * left undeclared, reading the per-(node, pattern) meter. Returns the limits
299
+ * that were auto-filled AND apply to this scope, to be counted on allow.
300
+ */
301
+ autoMeter(scope, ctx) {
302
+ const filled = [];
303
+ for (const c of this.callLimits()) {
304
+ const field = c.ctxField ?? "calls";
305
+ if (field in ctx)
306
+ continue; // an explicit count wins
307
+ const applies = c.appliesToScope ? c.appliesToScope(scope) : true;
308
+ ctx[field] = this.chain.callsSoFar(this.node.nodeId, c.meterKey ?? "*") + (applies ? 1 : 0);
309
+ if (applies)
310
+ filled.push(c);
311
+ }
312
+ return filled;
313
+ }
314
+ /**
315
+ * Authorize an action. Returns a `Decision`; it does not throw on a denial.
316
+ * Every call — allow or deny — is appended to the audit log.
317
+ *
318
+ * Auto-metering: when this node holds a `CallLimit` and the caller did not
319
+ * supply `calls`, the guard supplies the running count for (node, pattern)
320
+ * itself, including this call, and increments it on allow. An explicit
321
+ * `calls` in the context always wins.
322
+ */
323
+ check(scope, options = {}) {
324
+ const disposition = options.disposition ?? null;
325
+ Guard.checkDisposition(disposition); // refuse before anything reaches the ledger
326
+ const ctx = { ...(options.context ?? {}) };
327
+ const filled = this.autoMeter(scope, ctx);
328
+ const decision = this.evaluate(scope, ctx, options.metered ?? false);
329
+ if (decision.allowed) {
330
+ for (const c of filled)
331
+ this.chain.countCall(this.node.nodeId, c.meterKey ?? "*");
332
+ }
333
+ this.logDecision(decision, scope, options.tool ?? null, ctx, disposition);
334
+ if (!decision.allowed &&
335
+ this.strikes !== null &&
336
+ this.strikes.enabled &&
337
+ !this.chain.isRevoked(this.node.nodeId)) {
338
+ const count = this.chain.recordStrike(this.strikes.key(this.node.nodeId, scope));
339
+ if (count >= this.strikes.n) {
340
+ const revoked = this.chain.revoke(this.node.nodeId);
341
+ this.append("kill", {
342
+ chain_id: this.chainId,
343
+ target: this.node.nodeId,
344
+ reason: "strike_policy",
345
+ scope,
346
+ strikes: count,
347
+ mode: this.strikes.mode,
348
+ revoked,
349
+ });
350
+ }
351
+ }
352
+ return decision;
353
+ }
354
+ /**
355
+ * `check`, and throw `AuthorityDenied` if not allowed. The hard-stop gate:
356
+ * use this where a denial should abort the caller rather than be branched on.
357
+ */
358
+ enforce(scope, options = {}) {
359
+ const decision = this.check(scope, options);
360
+ if (!decision.allowed)
361
+ throw new AuthorityDenied(decision);
362
+ }
363
+ /**
364
+ * A pure dry-run: identical policy evaluation to `check`, but it never throws
365
+ * and — critically — writes NOTHING to the audit log.
366
+ */
367
+ wouldAllow(scope, options = {}) {
368
+ const ctx = { ...(options.context ?? {}) };
369
+ this.autoMeter(scope, ctx); // read the meters, never consume them
370
+ return this.evaluate(scope, ctx, options.metered ?? false);
371
+ }
372
+ /**
373
+ * Put an ADAPTER-LEVEL refusal on the audit trail as a `deny` event and
374
+ * return it as a Decision — for denials that happen UPSTREAM of policy
375
+ * evaluation: an agent the chain never delegated to, a tool with no declared
376
+ * permissions, unparseable tool arguments. Nothing is evaluated; the caller
377
+ * has already decided, and this records it in the same tamper-evident log.
378
+ *
379
+ * `scope` defaults to `tool` (or "-"), because the published schema requires
380
+ * a string scope on allow and deny events.
381
+ */
382
+ recordDenial(reason, message = "", options = {}) {
383
+ Guard.checkDisposition(options.disposition ?? null);
384
+ const r = reason instanceof reasons_js_1.Reason ? reason : new reasons_js_1.Reason(String(reason), { message });
385
+ const decision = reasons_js_1.Decision.deny(r, this.node.nodeId);
386
+ const tool = options.tool ?? null;
387
+ this.logDecision(decision, options.scope ?? tool ?? "-", tool, { ...(options.context ?? {}) }, options.disposition ?? null);
388
+ return decision;
389
+ }
390
+ // ---- chain controls ---------------------------------------------------
391
+ /** Cascade-revoke a node — by default this one — and its whole subtree. */
392
+ revoke(nodeId) {
393
+ const target = nodeId ?? this.node.nodeId;
394
+ const revoked = this.chain.revoke(target);
395
+ this.append("kill", { chain_id: this.chainId, target, revoked });
396
+ return revoked;
397
+ }
398
+ /**
399
+ * Revoke an agent BY NAME, chain-wide: every node it holds is cascade-revoked
400
+ * and no node may `delegate` to it again. Use this — not `revoke(nodeId)` —
401
+ * when the intent is "this principal is done", because frameworks hand off to
402
+ * the same agent freely and a fresh `delegate` would otherwise mint it clean
403
+ * authority.
404
+ */
405
+ revokeAgent(agentId) {
406
+ const revoked = this.chain.revokeAgent(agentId);
407
+ this.append("kill", {
408
+ chain_id: this.chainId,
409
+ target: this.node.nodeId,
410
+ agent: agentId,
411
+ revoked,
412
+ });
413
+ return revoked;
414
+ }
415
+ // ---- provable narrowing -----------------------------------------------
416
+ /**
417
+ * Is this guard's authority provably narrower than `parent`'s? Exactly the
418
+ * relation an offline verifier applies to two wire tokens.
419
+ */
420
+ isNarrowerThan(parent) {
421
+ return this.authority.isNarrowerThan(parent.authority);
422
+ }
423
+ // ---- introspection ----------------------------------------------------
424
+ auditLog() {
425
+ return this.audit;
426
+ }
427
+ graph() {
428
+ return this.chain.graph();
429
+ }
430
+ }
431
+ exports.Guard = Guard;
432
+ //# sourceMappingURL=guard.js.map