@agentbouncr/core 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 (95) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +47 -0
  3. package/dist/audit/hash-chain.d.ts +39 -0
  4. package/dist/audit/hash-chain.d.ts.map +1 -0
  5. package/dist/audit/hash-chain.js +63 -0
  6. package/dist/audit/hash-chain.js.map +1 -0
  7. package/dist/audit/index.d.ts +2 -0
  8. package/dist/audit/index.d.ts.map +1 -0
  9. package/dist/audit/index.js +2 -0
  10. package/dist/audit/index.js.map +1 -0
  11. package/dist/core/condition-evaluator.d.ts +20 -0
  12. package/dist/core/condition-evaluator.d.ts.map +1 -0
  13. package/dist/core/condition-evaluator.js +85 -0
  14. package/dist/core/condition-evaluator.js.map +1 -0
  15. package/dist/core/permission-layer.d.ts +24 -0
  16. package/dist/core/permission-layer.d.ts.map +1 -0
  17. package/dist/core/permission-layer.js +58 -0
  18. package/dist/core/permission-layer.js.map +1 -0
  19. package/dist/core/policy-engine.d.ts +35 -0
  20. package/dist/core/policy-engine.d.ts.map +1 -0
  21. package/dist/core/policy-engine.js +131 -0
  22. package/dist/core/policy-engine.js.map +1 -0
  23. package/dist/core/policy-schema.d.ts +50 -0
  24. package/dist/core/policy-schema.d.ts.map +1 -0
  25. package/dist/core/policy-schema.js +59 -0
  26. package/dist/core/policy-schema.js.map +1 -0
  27. package/dist/core/tool-registry.d.ts +31 -0
  28. package/dist/core/tool-registry.d.ts.map +1 -0
  29. package/dist/core/tool-registry.js +53 -0
  30. package/dist/core/tool-registry.js.map +1 -0
  31. package/dist/detection/injection-detector.d.ts +21 -0
  32. package/dist/detection/injection-detector.d.ts.map +1 -0
  33. package/dist/detection/injection-detector.js +61 -0
  34. package/dist/detection/injection-detector.js.map +1 -0
  35. package/dist/events/event-emitter.d.ts +44 -0
  36. package/dist/events/event-emitter.d.ts.map +1 -0
  37. package/dist/events/event-emitter.js +119 -0
  38. package/dist/events/event-emitter.js.map +1 -0
  39. package/dist/importers/json-schema-converter.d.ts +16 -0
  40. package/dist/importers/json-schema-converter.d.ts.map +1 -0
  41. package/dist/importers/json-schema-converter.js +95 -0
  42. package/dist/importers/json-schema-converter.js.map +1 -0
  43. package/dist/importers/mcp-importer.d.ts +30 -0
  44. package/dist/importers/mcp-importer.d.ts.map +1 -0
  45. package/dist/importers/mcp-importer.js +45 -0
  46. package/dist/importers/mcp-importer.js.map +1 -0
  47. package/dist/index.d.ts +27 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +43 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/lifecycle/governance-middleware.d.ts +105 -0
  52. package/dist/lifecycle/governance-middleware.d.ts.map +1 -0
  53. package/dist/lifecycle/governance-middleware.js +610 -0
  54. package/dist/lifecycle/governance-middleware.js.map +1 -0
  55. package/dist/lifecycle/kill-switch.d.ts +46 -0
  56. package/dist/lifecycle/kill-switch.d.ts.map +1 -0
  57. package/dist/lifecycle/kill-switch.js +119 -0
  58. package/dist/lifecycle/kill-switch.js.map +1 -0
  59. package/dist/lifecycle/middleware-schemas.d.ts +49 -0
  60. package/dist/lifecycle/middleware-schemas.d.ts.map +1 -0
  61. package/dist/lifecycle/middleware-schemas.js +33 -0
  62. package/dist/lifecycle/middleware-schemas.js.map +1 -0
  63. package/dist/providers/vercel-ai-adapter.d.ts +42 -0
  64. package/dist/providers/vercel-ai-adapter.d.ts.map +1 -0
  65. package/dist/providers/vercel-ai-adapter.js +96 -0
  66. package/dist/providers/vercel-ai-adapter.js.map +1 -0
  67. package/dist/schema/tool-schema.d.ts +62 -0
  68. package/dist/schema/tool-schema.d.ts.map +1 -0
  69. package/dist/schema/tool-schema.js +88 -0
  70. package/dist/schema/tool-schema.js.map +1 -0
  71. package/dist/tracing/index.d.ts +6 -0
  72. package/dist/tracing/index.d.ts.map +1 -0
  73. package/dist/tracing/index.js +6 -0
  74. package/dist/tracing/index.js.map +1 -0
  75. package/dist/tracing/trace-context.d.ts +37 -0
  76. package/dist/tracing/trace-context.d.ts.map +1 -0
  77. package/dist/tracing/trace-context.js +76 -0
  78. package/dist/tracing/trace-context.js.map +1 -0
  79. package/dist/tracing/trace-provider.d.ts +43 -0
  80. package/dist/tracing/trace-provider.d.ts.map +1 -0
  81. package/dist/tracing/trace-provider.js +89 -0
  82. package/dist/tracing/trace-provider.js.map +1 -0
  83. package/dist/types/index.d.ts +248 -0
  84. package/dist/types/index.d.ts.map +1 -0
  85. package/dist/types/index.js +20 -0
  86. package/dist/types/index.js.map +1 -0
  87. package/dist/utils/external-content.d.ts +9 -0
  88. package/dist/utils/external-content.d.ts.map +1 -0
  89. package/dist/utils/external-content.js +11 -0
  90. package/dist/utils/external-content.js.map +1 -0
  91. package/dist/utils/logger.d.ts +4 -0
  92. package/dist/utils/logger.d.ts.map +1 -0
  93. package/dist/utils/logger.js +13 -0
  94. package/dist/utils/logger.js.map +1 -0
  95. package/package.json +45 -0
package/LICENSE ADDED
@@ -0,0 +1,93 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ Copyright 2026 Aventilis UG (haftungsbeschränkt) i.Gr.
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor's trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to
37
+ the software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms.
47
+
48
+ If you modify the software, you must include in any modified copies of the
49
+ software prominent notices stating that you have modified the software.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not imply any licenses other than those expressly granted in
54
+ these terms.
55
+
56
+ ## Termination
57
+
58
+ If you use the software in violation of these terms, such use is not licensed,
59
+ and your licenses will automatically terminate. If the licensor provides you
60
+ with a notice of your violation, and you cease all violation of this license no
61
+ later than 30 days after you receive that notice, your licenses will be
62
+ reinstated retroactively. However, if you violate these terms after such
63
+ reinstatement, any additional violation of these terms will cause your licenses
64
+ to terminate automatically and permanently.
65
+
66
+ ## No Liability
67
+
68
+ As far as the law allows, the software comes as is, without any warranty or
69
+ condition, and the licensor will not be liable to you for any damages arising
70
+ out of these terms or the use or nature of the software, under any kind of legal
71
+ claim.
72
+
73
+ ## Definitions
74
+
75
+ The "licensor" is the entity offering these terms, and the "software" is the
76
+ software the licensor makes available under these terms, including any portion
77
+ of it.
78
+
79
+ "you" refers to the individual or entity agreeing to these terms.
80
+
81
+ "your company" is any legal entity, sole proprietorship, or other kind of
82
+ organization that you work for, plus all organizations that have control over,
83
+ are under the control of, or are under common control with that organization.
84
+ "control" means ownership of substantially all the assets of an entity, or the
85
+ power to direct its management and policies by vote, contract, or otherwise.
86
+ Control can be direct or indirect.
87
+
88
+ "your licenses" are all the licenses granted to you for the software under
89
+ these terms.
90
+
91
+ "use" means anything you do with the software requiring one of your licenses.
92
+
93
+ "trademark" means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @agentbouncr/core
2
+
3
+ The governance layer for AI agents. Policy Engine, Audit Trail, Kill-Switch, Event System, and Injection Detection.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @agentbouncr/core
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { GovernanceMiddleware } from '@agentbouncr/core';
15
+
16
+ const governance = new GovernanceMiddleware();
17
+
18
+ governance.setPolicy({
19
+ name: 'basic-security',
20
+ version: '1.0',
21
+ rules: [
22
+ {
23
+ tool: 'file_write',
24
+ effect: 'deny',
25
+ condition: { path: { startsWith: '/etc/' } },
26
+ reason: 'Writing to /etc/ is not permitted',
27
+ },
28
+ { tool: '*', effect: 'allow' },
29
+ ],
30
+ createdAt: new Date().toISOString(),
31
+ updatedAt: new Date().toISOString(),
32
+ });
33
+
34
+ const result = await governance.evaluate({
35
+ agentId: 'my-agent',
36
+ tool: 'file_write',
37
+ params: { path: '/etc/passwd' },
38
+ });
39
+
40
+ console.log(result.allowed); // false
41
+ ```
42
+
43
+ For full documentation, examples, and architecture overview, see the [main repository](https://github.com/agentbouncr/agentbouncr).
44
+
45
+ ## License
46
+
47
+ Elastic License 2.0 (ELv2) — see [LICENSE](./LICENSE)
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @agentbouncr/core — Audit Trail Hash-Chain
3
+ *
4
+ * SHA-256 Hash-Chain fuer manipulationssicheren Audit Trail.
5
+ * <100 LOC, keine externe Dependency — nur Node.js crypto.
6
+ *
7
+ * Jeder Eintrag enthaelt den Hash des vorherigen Eintrags.
8
+ * Erster Eintrag: previousHash = null → strukturell unterscheidbar.
9
+ *
10
+ * Serialisierung: JSON-Array (keine Delimiter-Injection moeglich).
11
+ * Timing-sicherer Vergleich via crypto.timingSafeEqual.
12
+ */
13
+ export interface HashInput {
14
+ traceId: string;
15
+ timestamp: string;
16
+ agentId: string;
17
+ tool: string;
18
+ params?: Record<string, unknown>;
19
+ result: string;
20
+ reason?: string;
21
+ durationMs: number;
22
+ failureCategory?: string;
23
+ previousHash: string | null;
24
+ }
25
+ /**
26
+ * Compute SHA-256 hash for an audit event.
27
+ *
28
+ * Serialization: JSON array of all fields (no delimiter injection possible).
29
+ * First event uses ["GENESIS_NULL"] sentinel; chained events use ["CHAIN", hash].
30
+ */
31
+ export declare function computeAuditHash(input: HashInput): string;
32
+ /**
33
+ * Verify that an audit event's hash matches its content.
34
+ * Uses timing-safe comparison to prevent side-channel attacks.
35
+ */
36
+ export declare function verifyAuditEventHash(event: HashInput & {
37
+ hash: string;
38
+ }): boolean;
39
+ //# sourceMappingURL=hash-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-chain.d.ts","sourceRoot":"","sources":["../../src/audit/hash-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAkBD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAgBzD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAMjF"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @agentbouncr/core — Audit Trail Hash-Chain
3
+ *
4
+ * SHA-256 Hash-Chain fuer manipulationssicheren Audit Trail.
5
+ * <100 LOC, keine externe Dependency — nur Node.js crypto.
6
+ *
7
+ * Jeder Eintrag enthaelt den Hash des vorherigen Eintrags.
8
+ * Erster Eintrag: previousHash = null → strukturell unterscheidbar.
9
+ *
10
+ * Serialisierung: JSON-Array (keine Delimiter-Injection moeglich).
11
+ * Timing-sicherer Vergleich via crypto.timingSafeEqual.
12
+ */
13
+ import { createHash, timingSafeEqual } from 'node:crypto';
14
+ // --- Hash Functions ---
15
+ /**
16
+ * Canonical JSON for params: sorted keys for determinism.
17
+ * Returns empty string for undefined/null.
18
+ */
19
+ function canonicalParams(params) {
20
+ if (!params)
21
+ return '';
22
+ const keys = Object.keys(params).sort();
23
+ const sorted = {};
24
+ for (const key of keys) {
25
+ sorted[key] = params[key];
26
+ }
27
+ return JSON.stringify(sorted);
28
+ }
29
+ /**
30
+ * Compute SHA-256 hash for an audit event.
31
+ *
32
+ * Serialization: JSON array of all fields (no delimiter injection possible).
33
+ * First event uses ["GENESIS_NULL"] sentinel; chained events use ["CHAIN", hash].
34
+ */
35
+ export function computeAuditHash(input) {
36
+ const fields = [
37
+ input.previousHash === null ? 'GENESIS_NULL' : `CHAIN:${input.previousHash}`,
38
+ input.traceId,
39
+ input.timestamp,
40
+ input.agentId,
41
+ input.tool,
42
+ canonicalParams(input.params),
43
+ input.result,
44
+ input.reason ?? '',
45
+ String(input.durationMs),
46
+ input.failureCategory ?? '',
47
+ ];
48
+ const payload = JSON.stringify(fields);
49
+ return createHash('sha256').update(payload).digest('hex');
50
+ }
51
+ /**
52
+ * Verify that an audit event's hash matches its content.
53
+ * Uses timing-safe comparison to prevent side-channel attacks.
54
+ */
55
+ export function verifyAuditEventHash(event) {
56
+ const computed = computeAuditHash(event);
57
+ const computedBuf = Buffer.from(computed, 'hex');
58
+ const storedBuf = Buffer.from(event.hash, 'hex');
59
+ if (computedBuf.length !== storedBuf.length)
60
+ return false;
61
+ return timingSafeEqual(computedBuf, storedBuf);
62
+ }
63
+ //# sourceMappingURL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AM,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAmC;IACtE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACzC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACjD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACjD,IAAI,WAAW,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1D,OAAO,eAAe,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { computeAuditHash, verifyAuditEventHash, type HashInput, } from './hash-chain.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/audit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { computeAuditHash, verifyAuditEventHash, } from './hash-chain.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/audit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,GAErB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @agentbouncr/core — Condition Evaluator
3
+ *
4
+ * Pure function. Evaluates a PolicyCondition against tool call params.
5
+ * 11 operators, deterministic, no external dependencies.
6
+ *
7
+ * Returns true if ALL conditions match (AND-logic across param keys,
8
+ * AND-logic across operators within a single param).
9
+ *
10
+ * Fail-Secure: missing param = false, type mismatch = false,
11
+ * unknown operator = false, invalid regex = false.
12
+ */
13
+ import type { PolicyCondition } from '../types/index.js';
14
+ /**
15
+ * Evaluate a condition against the provided params.
16
+ * Returns true if condition is undefined/empty (no condition = always matches).
17
+ * Returns false if a referenced param is missing from params (fail-secure).
18
+ */
19
+ export declare function evaluateCondition(condition: PolicyCondition | undefined, params: Record<string, unknown> | undefined): boolean;
20
+ //# sourceMappingURL=condition-evaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-evaluator.d.ts","sourceRoot":"","sources":["../../src/core/condition-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAqB,MAAM,mBAAmB,CAAC;AAE5E;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,eAAe,GAAG,SAAS,EACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC1C,OAAO,CAoBT"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @agentbouncr/core — Condition Evaluator
3
+ *
4
+ * Pure function. Evaluates a PolicyCondition against tool call params.
5
+ * 11 operators, deterministic, no external dependencies.
6
+ *
7
+ * Returns true if ALL conditions match (AND-logic across param keys,
8
+ * AND-logic across operators within a single param).
9
+ *
10
+ * Fail-Secure: missing param = false, type mismatch = false,
11
+ * unknown operator = false, invalid regex = false.
12
+ */
13
+ import safe from 'safe-regex2';
14
+ /**
15
+ * Evaluate a condition against the provided params.
16
+ * Returns true if condition is undefined/empty (no condition = always matches).
17
+ * Returns false if a referenced param is missing from params (fail-secure).
18
+ */
19
+ export function evaluateCondition(condition, params) {
20
+ if (!condition || Object.keys(condition).length === 0) {
21
+ return true;
22
+ }
23
+ if (!params) {
24
+ return false;
25
+ }
26
+ for (const [paramName, operators] of Object.entries(condition)) {
27
+ const paramValue = params[paramName];
28
+ for (const [op, operand] of Object.entries(operators)) {
29
+ if (!evaluateOperator(op, paramValue, operand)) {
30
+ return false;
31
+ }
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+ function evaluateOperator(operator, paramValue, operand) {
37
+ switch (operator) {
38
+ case 'equals':
39
+ return paramValue === operand;
40
+ case 'notEquals':
41
+ if (paramValue === undefined)
42
+ return false;
43
+ return paramValue !== operand;
44
+ case 'startsWith':
45
+ return typeof paramValue === 'string' && typeof operand === 'string'
46
+ && paramValue.startsWith(operand);
47
+ case 'endsWith':
48
+ return typeof paramValue === 'string' && typeof operand === 'string'
49
+ && paramValue.endsWith(operand);
50
+ case 'contains':
51
+ return typeof paramValue === 'string' && typeof operand === 'string'
52
+ && paramValue.includes(operand);
53
+ case 'gt':
54
+ return typeof paramValue === 'number' && typeof operand === 'number'
55
+ && paramValue > operand;
56
+ case 'lt':
57
+ return typeof paramValue === 'number' && typeof operand === 'number'
58
+ && paramValue < operand;
59
+ case 'gte':
60
+ return typeof paramValue === 'number' && typeof operand === 'number'
61
+ && paramValue >= operand;
62
+ case 'lte':
63
+ return typeof paramValue === 'number' && typeof operand === 'number'
64
+ && paramValue <= operand;
65
+ case 'in':
66
+ return Array.isArray(operand) && operand.includes(paramValue);
67
+ case 'matches': {
68
+ if (typeof paramValue !== 'string' || typeof operand !== 'string')
69
+ return false;
70
+ if (operand.length > 200)
71
+ return false;
72
+ if (!safe(operand))
73
+ return false; // ReDoS protection: reject catastrophic backtracking patterns
74
+ try {
75
+ return new RegExp(operand).test(paramValue);
76
+ }
77
+ catch {
78
+ return false;
79
+ }
80
+ }
81
+ default:
82
+ return false;
83
+ }
84
+ }
85
+ //# sourceMappingURL=condition-evaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-evaluator.js","sourceRoot":"","sources":["../../src/core/condition-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,IAAI,MAAM,aAAa,CAAC;AAG/B;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,SAAsC,EACtC,MAA2C;IAE3C,IAAI,CAAC,SA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tool call whether the agent has permission.
5
+ * Decisions are deterministic — no LLM involved.
6
+ * Uses dependency injection (ToolRegistry via constructor).
7
+ */
8
+ import type pino from 'pino';
9
+ import type { PermissionResult } from '../types/index.js';
10
+ import type { ToolRegistry } from './tool-registry.js';
11
+ export declare class PermissionLayer {
12
+ private readonly toolRegistry;
13
+ private readonly logger;
14
+ constructor(toolRegistry: ToolRegistry, logger: pino.Logger);
15
+ /**
16
+ * Check if an agent has permission to use a tool.
17
+ * Step 1: Tool must exist in registry.
18
+ * Step 2: Tool must be in the agent's allowed tools list.
19
+ *
20
+ * Fail-Secure: Any internal error results in denial (never pass-through).
21
+ */
22
+ checkPermission(agentId: string, toolName: string, agentToolsList: string[]): PermissionResult;
23
+ }
24
+ //# sourceMappingURL=permission-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-layer.d.ts","sourceRoot":"","sources":["../../src/core/permission-layer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,IAAI,CAAC,MAAM;IAGtC;;;;;;OAMG;IACH,eAAe,CACb,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EAAE,GACvB,gBAAgB;CA6CpB"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @agentbouncr/core — Permission Layer
3
+ *
4
+ * Checks before every tool call whether the agent has permission.
5
+ * Decisions are deterministic — no LLM involved.
6
+ * Uses dependency injection (ToolRegistry via constructor).
7
+ */
8
+ export class PermissionLayer {
9
+ toolRegistry;
10
+ logger;
11
+ constructor(toolRegistry, logger) {
12
+ this.toolRegistry = toolRegistry;
13
+ this.logger = logger;
14
+ }
15
+ /**
16
+ * Check if an agent has permission to use a tool.
17
+ * Step 1: Tool must exist in registry.
18
+ * Step 2: Tool must be in the agent's allowed tools list.
19
+ *
20
+ * Fail-Secure: Any internal error results in denial (never pass-through).
21
+ */
22
+ checkPermission(agentId, toolName, agentToolsList) {
23
+ try {
24
+ // Step 1: Does the tool exist in the registry?
25
+ if (!this.toolRegistry.has(toolName)) {
26
+ this.logger.warn({ agentId, toolName, event: 'tool_not_found' }, 'Tool call denied: tool not registered');
27
+ return {
28
+ allowed: false,
29
+ reason: `Tool '${toolName}' is not registered`,
30
+ toolName,
31
+ agentId,
32
+ };
33
+ }
34
+ // Step 2: Is the tool in the agent's allowed tools list?
35
+ if (!agentToolsList.includes(toolName)) {
36
+ this.logger.warn({ agentId, toolName, event: 'permission_denied' }, 'Tool call denied: not in agent permissions');
37
+ return {
38
+ allowed: false,
39
+ reason: `Agent '${agentId}' is not permitted to use '${toolName}'`,
40
+ toolName,
41
+ agentId,
42
+ };
43
+ }
44
+ return { allowed: true, toolName, agentId };
45
+ }
46
+ catch (err) {
47
+ // Fail-Secure: internal error = deny
48
+ this.logger.error({ agentId, toolName, error: String(err), event: 'permission_check_error' }, 'Permission check failed — denying (fail-secure)');
49
+ return {
50
+ allowed: false,
51
+ reason: `Permission check failed: ${String(err)}`,
52
+ toolName,
53
+ agentId,
54
+ };
55
+ }
56
+ }
57
+ }
58
+ //# sourceMappingURL=permission-layer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-layer.js","sourceRoot":"","sources":["../../src/core/permission-layer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,MAAM,OAAO,eAAe;IAEP;IACA;IAFnB,YACmB,YAA0B,EAC1B,MAAmB;QADnB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,WAAM,GAAN,MAAM,CAAa;IACnC,CAAC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CACF"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @agentbouncr/core — Policy Engine
3
+ *
4
+ * Evaluates tool-call requests against JSON policies.
5
+ * Deterministic — no LLM, no randomness.
6
+ * Fail-Secure — errors result in denial.
7
+ *
8
+ * Priority: tool+condition > tool-only > wildcard(*)
9
+ * Tiebreaker: deny before allow at equal specificity.
10
+ *
11
+ * rateLimit field is accepted but NOT evaluated in Stufe 1.
12
+ * requireApproval is surfaced in appliedRules for GovernanceMiddleware.
13
+ */
14
+ import type pino from 'pino';
15
+ import type { Policy, EvaluateRequest, EvaluateResult } from '../types/index.js';
16
+ export declare class PolicyEngine {
17
+ private readonly logger;
18
+ constructor(logger: pino.Logger);
19
+ /**
20
+ * Evaluate a tool-call request against a policy.
21
+ *
22
+ * No policy = deny (fail-secure).
23
+ * No matching rules = deny (fail-secure).
24
+ * Internal error = deny (fail-secure).
25
+ */
26
+ evaluate(request: EvaluateRequest, policy: Policy | null): EvaluateResult;
27
+ private findMatchingRules;
28
+ private computeSpecificity;
29
+ /**
30
+ * Sort: highest specificity first.
31
+ * At equal specificity: deny before allow (fail-secure).
32
+ */
33
+ private sortByPriority;
34
+ }
35
+ //# sourceMappingURL=policy-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-engine.d.ts","sourceRoot":"","sources":["../../src/core/policy-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EACV,MAAM,EAEN,eAAe,EACf,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAoB3B,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,IAAI,CAAC,MAAM;IAEhD;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc;IA6EzE,OAAO,CAAC,iBAAiB;IAmBzB,OAAO,CAAC,kBAAkB;IAW1B;;;OAGG;IACH,OAAO,CAAC,cAAc;CAWvB"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @agentbouncr/core — Policy Engine
3
+ *
4
+ * Evaluates tool-call requests against JSON policies.
5
+ * Deterministic — no LLM, no randomness.
6
+ * Fail-Secure — errors result in denial.
7
+ *
8
+ * Priority: tool+condition > tool-only > wildcard(*)
9
+ * Tiebreaker: deny before allow at equal specificity.
10
+ *
11
+ * rateLimit field is accepted but NOT evaluated in Stufe 1.
12
+ * requireApproval is surfaced in appliedRules for GovernanceMiddleware.
13
+ */
14
+ import { evaluateCondition } from './condition-evaluator.js';
15
+ import { generateTraceId } from '../tracing/trace-context.js';
16
+ // --- Specificity Tiers ---
17
+ const SPECIFICITY_WILDCARD = 0;
18
+ const SPECIFICITY_TOOL_ONLY = 1;
19
+ const SPECIFICITY_TOOL_CONDITION = 2;
20
+ // --- Policy Engine ---
21
+ export class PolicyEngine {
22
+ logger;
23
+ constructor(logger) {
24
+ this.logger = logger;
25
+ }
26
+ /**
27
+ * Evaluate a tool-call request against a policy.
28
+ *
29
+ * No policy = deny (fail-secure).
30
+ * No matching rules = deny (fail-secure).
31
+ * Internal error = deny (fail-secure).
32
+ */
33
+ evaluate(request, policy) {
34
+ const traceId = request.traceId ?? generateTraceId();
35
+ try {
36
+ if (!policy) {
37
+ this.logger.warn({ agentId: request.agentId, tool: request.tool, traceId }, 'No policy found — denying (fail-secure)');
38
+ return {
39
+ allowed: false,
40
+ traceId,
41
+ reason: `No policy found for agent '${request.agentId}'`,
42
+ appliedRules: [],
43
+ };
44
+ }
45
+ const matches = this.findMatchingRules(policy, request);
46
+ if (matches.length === 0) {
47
+ this.logger.info({ agentId: request.agentId, tool: request.tool, policyName: policy.name, traceId }, 'No matching rules — denying (fail-secure)');
48
+ return {
49
+ allowed: false,
50
+ traceId,
51
+ reason: `No matching rule for tool '${request.tool}' in policy '${policy.name}'`,
52
+ appliedRules: [],
53
+ };
54
+ }
55
+ const sorted = this.sortByPriority(matches);
56
+ const winner = sorted[0];
57
+ const allowed = winner.rule.effect === 'allow';
58
+ const appliedRules = sorted.map((m) => ({
59
+ policyName: m.policyName,
60
+ ruleName: m.rule.name,
61
+ effect: m.rule.effect,
62
+ requireApproval: m.rule.requireApproval,
63
+ }));
64
+ if (allowed) {
65
+ this.logger.info({ agentId: request.agentId, tool: request.tool, policyName: policy.name, traceId }, 'Tool call allowed by policy');
66
+ }
67
+ else {
68
+ this.logger.warn({
69
+ agentId: request.agentId,
70
+ tool: request.tool,
71
+ policyName: policy.name,
72
+ ruleName: winner.rule.name,
73
+ reason: winner.rule.reason,
74
+ traceId,
75
+ }, 'Tool call denied by policy');
76
+ }
77
+ return { allowed, traceId, reason: winner.rule.reason, appliedRules };
78
+ }
79
+ catch (err) {
80
+ this.logger.error({ agentId: request.agentId, tool: request.tool, error: String(err), traceId }, 'Policy evaluation failed — denying (fail-secure)');
81
+ return {
82
+ allowed: false,
83
+ traceId,
84
+ reason: `Policy evaluation failed: ${String(err)}`,
85
+ appliedRules: [],
86
+ };
87
+ }
88
+ }
89
+ findMatchingRules(policy, request) {
90
+ const matches = [];
91
+ for (const rule of policy.rules) {
92
+ const toolMatches = rule.tool === request.tool || rule.tool === '*';
93
+ if (!toolMatches)
94
+ continue;
95
+ if (!evaluateCondition(rule.condition, request.params))
96
+ continue;
97
+ matches.push({
98
+ rule,
99
+ policyName: policy.name,
100
+ specificity: this.computeSpecificity(rule),
101
+ });
102
+ }
103
+ return matches;
104
+ }
105
+ computeSpecificity(rule) {
106
+ if (rule.tool === '*')
107
+ return SPECIFICITY_WILDCARD;
108
+ if (rule.condition && Object.keys(rule.condition).length > 0) {
109
+ const hasOperators = Object.values(rule.condition).some((ops) => Object.keys(ops).length > 0);
110
+ if (hasOperators)
111
+ return SPECIFICITY_TOOL_CONDITION;
112
+ }
113
+ return SPECIFICITY_TOOL_ONLY;
114
+ }
115
+ /**
116
+ * Sort: highest specificity first.
117
+ * At equal specificity: deny before allow (fail-secure).
118
+ */
119
+ sortByPriority(matches) {
120
+ return [...matches].sort((a, b) => {
121
+ if (a.specificity !== b.specificity) {
122
+ return b.specificity - a.specificity;
123
+ }
124
+ if (a.rule.effect !== b.rule.effect) {
125
+ return a.rule.effect === 'deny' ? -1 : 1;
126
+ }
127
+ return 0;
128
+ });
129
+ }
130
+ }
131
+ //# sourceMappingURL=policy-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-engine.js","sourceRoot":"","sources":["../../src/core/policy-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,4BAA4B;AAE5B,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAUrC,wBAAwB;AAExB,MAAM,OAAO,YAAY;IACM;IAA7B,YAA6B,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAG,CAAC;IAEpD;;;;;;OAMG;IACH,QAAQ,CAAC,OAAwB,EAAE,MAAqB;QACtD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;QAErD,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,EACzD,yCAAyC,CAC1C,CAAC;gBACF,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,OAAO;oBACP,MAAM,EAAE,8BAA8B,OAAO,CAAC,OAAO,GAAG;oBACxD,YAAY,EAAE,EAAE;iBACjB,CAAC;YACJ,CAAC;YAED,MAAM,OAAO,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