@peac/policy-kit 0.9.18
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 +23 -0
- package/dist/compiler.d.ts +111 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +304 -0
- package/dist/compiler.js.map +1 -0
- package/dist/evaluate.d.ts +84 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +258 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +80 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +245 -0
- package/dist/loader.js.map +1 -0
- package/dist/types.d.ts +276 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +88 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @peac/policy-kit
|
|
2
|
+
|
|
3
|
+
PEAC Policy Kit - deterministic policy evaluation for CAL semantics
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @peac/policy-kit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
See [peacprotocol.org](https://peacprotocol.org) for full documentation.
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
Apache-2.0
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
PEAC Protocol is an open source project stewarded by Originary and community contributors.
|
|
22
|
+
|
|
23
|
+
[Originary](https://www.originary.xyz) | [Docs](https://peacprotocol.org) | [GitHub](https://github.com/peacprotocol/peac)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PEAC Policy Kit Compiler
|
|
3
|
+
*
|
|
4
|
+
* Compiles policy documents to deployment artifacts:
|
|
5
|
+
* - peac.txt (PEAC discovery file - canonical schema)
|
|
6
|
+
* - robots.txt snippet for AI crawlers
|
|
7
|
+
* - AIPREF header templates (compatibility output)
|
|
8
|
+
* - Human-readable markdown summary
|
|
9
|
+
*
|
|
10
|
+
* All outputs are deterministic (stable ordering where semantically safe).
|
|
11
|
+
* Rule order is preserved where it affects semantics (first-match-wins).
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
import { PolicyDocument } from './types';
|
|
16
|
+
/**
|
|
17
|
+
* Default PEAC protocol version for generated peac.txt
|
|
18
|
+
*
|
|
19
|
+
* Uses major.minor format (e.g., "0.9") by default. Pass a full version
|
|
20
|
+
* (e.g., "0.9.17") via peacVersion option if needed.
|
|
21
|
+
*
|
|
22
|
+
* This matches the wire format version from @peac/kernel.
|
|
23
|
+
*/
|
|
24
|
+
export declare const PEAC_PROTOCOL_VERSION: "0.9";
|
|
25
|
+
/**
|
|
26
|
+
* Options for compilation
|
|
27
|
+
*/
|
|
28
|
+
export interface CompileOptions {
|
|
29
|
+
/** Base URL for the site (used in peac.txt) */
|
|
30
|
+
siteUrl?: string;
|
|
31
|
+
/** Contact email for policy questions */
|
|
32
|
+
contact?: string;
|
|
33
|
+
/** Include comments in output */
|
|
34
|
+
includeComments?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* PEAC protocol version for peac.txt (default: 0.9)
|
|
37
|
+
* Use major.minor (0.9) or full version (0.9.17) as needed.
|
|
38
|
+
*/
|
|
39
|
+
peacVersion?: string;
|
|
40
|
+
/** Attribution requirement: required, optional, or none */
|
|
41
|
+
attribution?: 'required' | 'optional' | 'none';
|
|
42
|
+
/**
|
|
43
|
+
* Receipts requirement: required, optional, or omit (don't include field)
|
|
44
|
+
* Default: 'required' for conditional usage, 'optional' for open usage
|
|
45
|
+
*/
|
|
46
|
+
receipts?: 'required' | 'optional' | 'omit';
|
|
47
|
+
/** Rate limit string (e.g., "100/hour", "unlimited") */
|
|
48
|
+
rateLimit?: string;
|
|
49
|
+
/** Negotiate endpoint URL */
|
|
50
|
+
negotiateUrl?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* AIPREF header template
|
|
54
|
+
*/
|
|
55
|
+
export interface AiprefTemplate {
|
|
56
|
+
/** Header name */
|
|
57
|
+
header: string;
|
|
58
|
+
/** Header value */
|
|
59
|
+
value: string;
|
|
60
|
+
/** Description of when to use */
|
|
61
|
+
description: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compile policy to peac.txt format (canonical schema)
|
|
65
|
+
*
|
|
66
|
+
* Generates a PEAC discovery file that can be served at:
|
|
67
|
+
* - /.well-known/peac.txt (primary)
|
|
68
|
+
* - /peac.txt (fallback)
|
|
69
|
+
*
|
|
70
|
+
* Output uses canonical PEAC schema with `version` and `usage` fields.
|
|
71
|
+
* Rule order is preserved in comments (first-match-wins semantics).
|
|
72
|
+
*
|
|
73
|
+
* @param policy - Policy document
|
|
74
|
+
* @param options - Compilation options
|
|
75
|
+
* @returns peac.txt content (YAML format)
|
|
76
|
+
*/
|
|
77
|
+
export declare function compilePeacTxt(policy: PolicyDocument, options?: CompileOptions): string;
|
|
78
|
+
/**
|
|
79
|
+
* Compile policy to robots.txt snippet for AI crawlers
|
|
80
|
+
*
|
|
81
|
+
* Generates User-agent blocks for known AI crawlers based on policy.
|
|
82
|
+
* Conservative: if default is deny or review, disallows crawling.
|
|
83
|
+
*
|
|
84
|
+
* @param policy - Policy document
|
|
85
|
+
* @param options - Compilation options
|
|
86
|
+
* @returns robots.txt snippet content
|
|
87
|
+
*/
|
|
88
|
+
export declare function compileRobotsSnippet(policy: PolicyDocument, options?: CompileOptions): string;
|
|
89
|
+
/**
|
|
90
|
+
* Compile policy to AIPREF header templates
|
|
91
|
+
*
|
|
92
|
+
* Generates header values for HTTP responses.
|
|
93
|
+
* These are COMPATIBILITY templates, not normative PEAC headers.
|
|
94
|
+
* The authoritative policy is always peac.txt.
|
|
95
|
+
*
|
|
96
|
+
* @param policy - Policy document
|
|
97
|
+
* @param options - Compilation options
|
|
98
|
+
* @returns Array of header templates
|
|
99
|
+
*/
|
|
100
|
+
export declare function compileAiprefTemplates(policy: PolicyDocument, options?: CompileOptions): AiprefTemplate[];
|
|
101
|
+
/**
|
|
102
|
+
* Render policy as human-readable markdown
|
|
103
|
+
*
|
|
104
|
+
* Generates an ai-policy.md file for documentation.
|
|
105
|
+
*
|
|
106
|
+
* @param policy - Policy document
|
|
107
|
+
* @param options - Compilation options
|
|
108
|
+
* @returns Markdown content
|
|
109
|
+
*/
|
|
110
|
+
export declare function renderPolicyMarkdown(policy: PolicyDocument, options?: CompileOptions): string;
|
|
111
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,cAAc,EAAkC,MAAM,SAAS,CAAC;AAEzE;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAG,KAAc,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;IAC/C;;;OAGG;IACH,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;IAC5C,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,CAmE3F;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,CA+CjG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,cAAmB,GAC3B,cAAc,EAAE,CA8BlB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,CA2FjG"}
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PEAC Policy Kit Compiler
|
|
4
|
+
*
|
|
5
|
+
* Compiles policy documents to deployment artifacts:
|
|
6
|
+
* - peac.txt (PEAC discovery file - canonical schema)
|
|
7
|
+
* - robots.txt snippet for AI crawlers
|
|
8
|
+
* - AIPREF header templates (compatibility output)
|
|
9
|
+
* - Human-readable markdown summary
|
|
10
|
+
*
|
|
11
|
+
* All outputs are deterministic (stable ordering where semantically safe).
|
|
12
|
+
* Rule order is preserved where it affects semantics (first-match-wins).
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.PEAC_PROTOCOL_VERSION = void 0;
|
|
18
|
+
exports.compilePeacTxt = compilePeacTxt;
|
|
19
|
+
exports.compileRobotsSnippet = compileRobotsSnippet;
|
|
20
|
+
exports.compileAiprefTemplates = compileAiprefTemplates;
|
|
21
|
+
exports.renderPolicyMarkdown = renderPolicyMarkdown;
|
|
22
|
+
/**
|
|
23
|
+
* Default PEAC protocol version for generated peac.txt
|
|
24
|
+
*
|
|
25
|
+
* Uses major.minor format (e.g., "0.9") by default. Pass a full version
|
|
26
|
+
* (e.g., "0.9.17") via peacVersion option if needed.
|
|
27
|
+
*
|
|
28
|
+
* This matches the wire format version from @peac/kernel.
|
|
29
|
+
*/
|
|
30
|
+
exports.PEAC_PROTOCOL_VERSION = '0.9';
|
|
31
|
+
/**
|
|
32
|
+
* Compile policy to peac.txt format (canonical schema)
|
|
33
|
+
*
|
|
34
|
+
* Generates a PEAC discovery file that can be served at:
|
|
35
|
+
* - /.well-known/peac.txt (primary)
|
|
36
|
+
* - /peac.txt (fallback)
|
|
37
|
+
*
|
|
38
|
+
* Output uses canonical PEAC schema with `version` and `usage` fields.
|
|
39
|
+
* Rule order is preserved in comments (first-match-wins semantics).
|
|
40
|
+
*
|
|
41
|
+
* @param policy - Policy document
|
|
42
|
+
* @param options - Compilation options
|
|
43
|
+
* @returns peac.txt content (YAML format)
|
|
44
|
+
*/
|
|
45
|
+
function compilePeacTxt(policy, options = {}) {
|
|
46
|
+
const lines = [];
|
|
47
|
+
const { includeComments = true, peacVersion = exports.PEAC_PROTOCOL_VERSION } = options;
|
|
48
|
+
if (includeComments) {
|
|
49
|
+
lines.push('# PEAC Policy Discovery File');
|
|
50
|
+
lines.push(`# Generated from: ${policy.name || 'peac-policy.yaml'}`);
|
|
51
|
+
lines.push('#');
|
|
52
|
+
lines.push('# Serve at: /.well-known/peac.txt');
|
|
53
|
+
lines.push('# See: https://peacprotocol.org');
|
|
54
|
+
lines.push('');
|
|
55
|
+
}
|
|
56
|
+
// PEAC protocol version (canonical field)
|
|
57
|
+
lines.push(`version: ${peacVersion}`);
|
|
58
|
+
// Usage: open (allow default) or conditional (deny/review default)
|
|
59
|
+
const usage = policy.defaults.decision === 'allow' ? 'open' : 'conditional';
|
|
60
|
+
lines.push(`usage: ${usage}`);
|
|
61
|
+
lines.push('');
|
|
62
|
+
// List purposes covered by rules (sorted for determinism - safe because informational)
|
|
63
|
+
const purposes = extractPurposes(policy);
|
|
64
|
+
if (purposes.length > 0) {
|
|
65
|
+
lines.push(`purposes: [${purposes.join(', ')}]`);
|
|
66
|
+
}
|
|
67
|
+
// Attribution if specified
|
|
68
|
+
if (options.attribution && options.attribution !== 'none') {
|
|
69
|
+
lines.push(`attribution: ${options.attribution}`);
|
|
70
|
+
}
|
|
71
|
+
// Receipts: configurable, with sensible defaults based on usage
|
|
72
|
+
// - conditional: defaults to 'required' (explicit receipt needed)
|
|
73
|
+
// - open: defaults to 'optional' (receipt accepted but not required)
|
|
74
|
+
const receiptsDefault = usage === 'conditional' ? 'required' : 'optional';
|
|
75
|
+
const receiptsValue = options.receipts ?? receiptsDefault;
|
|
76
|
+
if (receiptsValue !== 'omit') {
|
|
77
|
+
lines.push(`receipts: ${receiptsValue}`);
|
|
78
|
+
}
|
|
79
|
+
// Rate limit (applies to both open and conditional)
|
|
80
|
+
if (options.rateLimit) {
|
|
81
|
+
lines.push(`rate_limit: ${options.rateLimit}`);
|
|
82
|
+
}
|
|
83
|
+
// Negotiate endpoint (typically for conditional access)
|
|
84
|
+
if (options.negotiateUrl) {
|
|
85
|
+
lines.push(`negotiate: ${options.negotiateUrl}`);
|
|
86
|
+
}
|
|
87
|
+
// Contact if provided
|
|
88
|
+
if (options.contact) {
|
|
89
|
+
lines.push(`contact: ${options.contact}`);
|
|
90
|
+
}
|
|
91
|
+
// Show rule summary in comments (preserve author order - semantically significant)
|
|
92
|
+
if (policy.rules.length > 0 && includeComments) {
|
|
93
|
+
lines.push('');
|
|
94
|
+
lines.push('# Policy rules (first-match-wins, author order preserved):');
|
|
95
|
+
lines.push(`# Source: ${policy.name || 'peac-policy.yaml'} (${policy.rules.length} rules)`);
|
|
96
|
+
for (const rule of policy.rules) {
|
|
97
|
+
lines.push(`# ${rule.name}: ${rule.decision}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return lines.join('\n') + '\n';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Compile policy to robots.txt snippet for AI crawlers
|
|
104
|
+
*
|
|
105
|
+
* Generates User-agent blocks for known AI crawlers based on policy.
|
|
106
|
+
* Conservative: if default is deny or review, disallows crawling.
|
|
107
|
+
*
|
|
108
|
+
* @param policy - Policy document
|
|
109
|
+
* @param options - Compilation options
|
|
110
|
+
* @returns robots.txt snippet content
|
|
111
|
+
*/
|
|
112
|
+
function compileRobotsSnippet(policy, options = {}) {
|
|
113
|
+
const lines = [];
|
|
114
|
+
const { includeComments = true } = options;
|
|
115
|
+
// Known AI crawler user agents (sorted for determinism)
|
|
116
|
+
const aiCrawlers = [
|
|
117
|
+
'Anthropic-AI',
|
|
118
|
+
'CCBot',
|
|
119
|
+
'ChatGPT-User',
|
|
120
|
+
'Claude-Web',
|
|
121
|
+
'Cohere-AI',
|
|
122
|
+
'GPTBot',
|
|
123
|
+
'Google-Extended',
|
|
124
|
+
'Meta-ExternalAgent',
|
|
125
|
+
'Meta-ExternalFetcher',
|
|
126
|
+
'PerplexityBot',
|
|
127
|
+
'anthropic-ai',
|
|
128
|
+
'cohere-ai',
|
|
129
|
+
];
|
|
130
|
+
if (includeComments) {
|
|
131
|
+
lines.push('# AI Crawler Directives');
|
|
132
|
+
lines.push(`# Generated from PEAC policy: ${policy.name || 'peac-policy.yaml'}`);
|
|
133
|
+
lines.push('#');
|
|
134
|
+
lines.push('# SNIPPET - Review before adding to your robots.txt');
|
|
135
|
+
lines.push(`# Default policy: ${policy.defaults.decision}`);
|
|
136
|
+
lines.push('');
|
|
137
|
+
}
|
|
138
|
+
// Conservative approach: only allow if default is explicitly 'allow'
|
|
139
|
+
// If default is 'deny' or 'review', disallow and require PEAC receipt
|
|
140
|
+
const isDefaultAllow = policy.defaults.decision === 'allow';
|
|
141
|
+
for (const crawler of aiCrawlers) {
|
|
142
|
+
lines.push(`User-agent: ${crawler}`);
|
|
143
|
+
if (isDefaultAllow) {
|
|
144
|
+
lines.push('Allow: /');
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
lines.push('Disallow: /');
|
|
148
|
+
if (includeComments) {
|
|
149
|
+
lines.push('# Requires PEAC receipt for access');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
lines.push('');
|
|
153
|
+
}
|
|
154
|
+
return lines.join('\n');
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Compile policy to AIPREF header templates
|
|
158
|
+
*
|
|
159
|
+
* Generates header values for HTTP responses.
|
|
160
|
+
* These are COMPATIBILITY templates, not normative PEAC headers.
|
|
161
|
+
* The authoritative policy is always peac.txt.
|
|
162
|
+
*
|
|
163
|
+
* @param policy - Policy document
|
|
164
|
+
* @param options - Compilation options
|
|
165
|
+
* @returns Array of header templates
|
|
166
|
+
*/
|
|
167
|
+
function compileAiprefTemplates(policy, options = {}) {
|
|
168
|
+
const templates = [];
|
|
169
|
+
const { peacVersion = exports.PEAC_PROTOCOL_VERSION } = options;
|
|
170
|
+
const usage = policy.defaults.decision === 'allow' ? 'open' : 'conditional';
|
|
171
|
+
// PEAC-Policy header (debug/compatibility - see peac.txt for authoritative policy)
|
|
172
|
+
templates.push({
|
|
173
|
+
header: 'PEAC-Policy',
|
|
174
|
+
value: `version=${peacVersion}; usage=${usage}; rules=${policy.rules.length}`,
|
|
175
|
+
description: 'Debug/compatibility header - see peac.txt for authoritative policy',
|
|
176
|
+
});
|
|
177
|
+
// X-Robots-Tag for AI (compatibility, widely supported)
|
|
178
|
+
if (policy.defaults.decision === 'deny') {
|
|
179
|
+
templates.push({
|
|
180
|
+
header: 'X-Robots-Tag',
|
|
181
|
+
value: 'noai, noimageai',
|
|
182
|
+
description: 'Compatibility header: signal no AI training (default deny policy)',
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// Note about AIPREF-style headers
|
|
186
|
+
templates.push({
|
|
187
|
+
header: '# Compatibility Note',
|
|
188
|
+
value: 'See /.well-known/peac.txt for authoritative policy',
|
|
189
|
+
description: 'These headers are for compatibility only. AIPREF-style X-AI-* headers are not generated to avoid contradictions with conditional rules.',
|
|
190
|
+
});
|
|
191
|
+
return templates;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Render policy as human-readable markdown
|
|
195
|
+
*
|
|
196
|
+
* Generates an ai-policy.md file for documentation.
|
|
197
|
+
*
|
|
198
|
+
* @param policy - Policy document
|
|
199
|
+
* @param options - Compilation options
|
|
200
|
+
* @returns Markdown content
|
|
201
|
+
*/
|
|
202
|
+
function renderPolicyMarkdown(policy, options = {}) {
|
|
203
|
+
const lines = [];
|
|
204
|
+
// Header
|
|
205
|
+
lines.push(`# ${policy.name || 'AI Access Policy'}`);
|
|
206
|
+
lines.push('');
|
|
207
|
+
lines.push(`> Generated from PEAC policy (${policy.version})`);
|
|
208
|
+
lines.push('');
|
|
209
|
+
// Summary
|
|
210
|
+
lines.push('## Summary');
|
|
211
|
+
lines.push('');
|
|
212
|
+
lines.push(`- **Default Decision:** ${policy.defaults.decision}`);
|
|
213
|
+
if (policy.defaults.reason) {
|
|
214
|
+
lines.push(`- **Default Reason:** ${policy.defaults.reason}`);
|
|
215
|
+
}
|
|
216
|
+
lines.push(`- **Total Rules:** ${policy.rules.length}`);
|
|
217
|
+
lines.push('');
|
|
218
|
+
// Contact
|
|
219
|
+
if (options.contact) {
|
|
220
|
+
lines.push(`For questions about this policy, contact: ${options.contact}`);
|
|
221
|
+
lines.push('');
|
|
222
|
+
}
|
|
223
|
+
// How it works
|
|
224
|
+
lines.push('## How This Policy Works');
|
|
225
|
+
lines.push('');
|
|
226
|
+
lines.push('This policy uses **first-match-wins** semantics (like firewall rules). When an AI agent requests access:');
|
|
227
|
+
lines.push('');
|
|
228
|
+
lines.push('1. Rules are evaluated in order');
|
|
229
|
+
lines.push('2. The first matching rule determines the decision');
|
|
230
|
+
lines.push('3. If no rule matches, the default decision applies');
|
|
231
|
+
lines.push('');
|
|
232
|
+
// Rules (preserve author order - first-match-wins semantics are order-dependent)
|
|
233
|
+
if (policy.rules.length > 0) {
|
|
234
|
+
lines.push('## Rules');
|
|
235
|
+
lines.push('');
|
|
236
|
+
lines.push('> Rules are evaluated in order. The first matching rule wins.');
|
|
237
|
+
lines.push('');
|
|
238
|
+
for (const rule of policy.rules) {
|
|
239
|
+
lines.push(`### ${rule.name}`);
|
|
240
|
+
lines.push('');
|
|
241
|
+
lines.push(`- **Decision:** ${rule.decision}`);
|
|
242
|
+
if (rule.reason) {
|
|
243
|
+
lines.push(`- **Reason:** ${rule.reason}`);
|
|
244
|
+
}
|
|
245
|
+
if (rule.subject) {
|
|
246
|
+
const subjectParts = [];
|
|
247
|
+
if (rule.subject.type) {
|
|
248
|
+
const types = Array.isArray(rule.subject.type)
|
|
249
|
+
? rule.subject.type.join(', ')
|
|
250
|
+
: rule.subject.type;
|
|
251
|
+
subjectParts.push(`type: ${types}`);
|
|
252
|
+
}
|
|
253
|
+
if (rule.subject.labels) {
|
|
254
|
+
subjectParts.push(`labels: ${rule.subject.labels.join(', ')}`);
|
|
255
|
+
}
|
|
256
|
+
if (rule.subject.id) {
|
|
257
|
+
subjectParts.push(`id: ${rule.subject.id}`);
|
|
258
|
+
}
|
|
259
|
+
if (subjectParts.length > 0) {
|
|
260
|
+
lines.push(`- **Subject:** ${subjectParts.join('; ')}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (rule.purpose) {
|
|
264
|
+
const purposes = Array.isArray(rule.purpose) ? rule.purpose.join(', ') : rule.purpose;
|
|
265
|
+
lines.push(`- **Purpose:** ${purposes}`);
|
|
266
|
+
}
|
|
267
|
+
if (rule.licensing_mode) {
|
|
268
|
+
const modes = Array.isArray(rule.licensing_mode)
|
|
269
|
+
? rule.licensing_mode.join(', ')
|
|
270
|
+
: rule.licensing_mode;
|
|
271
|
+
lines.push(`- **Licensing Mode:** ${modes}`);
|
|
272
|
+
}
|
|
273
|
+
lines.push('');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// Footer
|
|
277
|
+
lines.push('---');
|
|
278
|
+
lines.push('');
|
|
279
|
+
lines.push('*This policy is enforced via the PEAC Protocol. See [peacprotocol.org](https://peacprotocol.org) for more information.*');
|
|
280
|
+
lines.push('');
|
|
281
|
+
return lines.join('\n');
|
|
282
|
+
}
|
|
283
|
+
// --- Helper functions ---
|
|
284
|
+
/**
|
|
285
|
+
* Extract all unique purposes from policy rules (sorted for determinism)
|
|
286
|
+
*/
|
|
287
|
+
function extractPurposes(policy) {
|
|
288
|
+
const purposes = new Set();
|
|
289
|
+
for (const rule of policy.rules) {
|
|
290
|
+
if (rule.purpose) {
|
|
291
|
+
if (Array.isArray(rule.purpose)) {
|
|
292
|
+
for (const p of rule.purpose) {
|
|
293
|
+
purposes.add(p);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
purposes.add(rule.purpose);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// Sort for deterministic output
|
|
302
|
+
return Array.from(purposes).sort();
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAoEH,wCAmEC;AAYD,oDA+CC;AAaD,wDAiCC;AAWD,oDA2FC;AAlVD;;;;;;;GAOG;AACU,QAAA,qBAAqB,GAAG,KAAc,CAAC;AA0CpD;;;;;;;;;;;;;GAaG;AACH,SAAgB,cAAc,CAAC,MAAsB,EAAE,UAA0B,EAAE;IACjF,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,EAAE,eAAe,GAAG,IAAI,EAAE,WAAW,GAAG,6BAAqB,EAAE,G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I,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,2BAA2B;AAE3B;;GAEG;AACH,SAAS,eAAe,CAAC,MAAsB;IAC7C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE3C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAChC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBAC7B,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAClB,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;IAED,gCAAgC;IAChC,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PEAC Policy Kit Evaluation
|
|
3
|
+
*
|
|
4
|
+
* Deterministic policy evaluation for CAL semantics.
|
|
5
|
+
* First-match-wins rule semantics.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { PolicyDocument, PolicyRule, EvaluationContext, EvaluationResult } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Evaluate a policy against a context
|
|
12
|
+
*
|
|
13
|
+
* Uses first-match-wins semantics:
|
|
14
|
+
* - Rules are evaluated in order
|
|
15
|
+
* - First matching rule determines the decision
|
|
16
|
+
* - If no rule matches, defaults are applied
|
|
17
|
+
*
|
|
18
|
+
* @param policy - Policy document
|
|
19
|
+
* @param context - Evaluation context
|
|
20
|
+
* @returns Evaluation result
|
|
21
|
+
*/
|
|
22
|
+
export declare function evaluate(policy: PolicyDocument, context: EvaluationContext): EvaluationResult;
|
|
23
|
+
/**
|
|
24
|
+
* Explain which rules could potentially match a context
|
|
25
|
+
*
|
|
26
|
+
* Useful for debugging and policy analysis.
|
|
27
|
+
* Returns all rules that would match if evaluated, in order.
|
|
28
|
+
*
|
|
29
|
+
* @param policy - Policy document
|
|
30
|
+
* @param context - Evaluation context
|
|
31
|
+
* @returns Array of rule names that match, or 'default' if none
|
|
32
|
+
*/
|
|
33
|
+
export declare function explainMatches(policy: PolicyDocument, context: EvaluationContext): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Find the effective rule for a context
|
|
36
|
+
*
|
|
37
|
+
* Same as evaluate() but returns the full rule object.
|
|
38
|
+
*
|
|
39
|
+
* @param policy - Policy document
|
|
40
|
+
* @param context - Evaluation context
|
|
41
|
+
* @returns Matched rule or undefined if default applies
|
|
42
|
+
*/
|
|
43
|
+
export declare function findEffectiveRule(policy: PolicyDocument, context: EvaluationContext): PolicyRule | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a policy would allow a given context
|
|
46
|
+
*
|
|
47
|
+
* Convenience helper for common allow/deny checks.
|
|
48
|
+
*
|
|
49
|
+
* @param policy - Policy document
|
|
50
|
+
* @param context - Evaluation context
|
|
51
|
+
* @returns true if decision is 'allow'
|
|
52
|
+
*/
|
|
53
|
+
export declare function isAllowed(policy: PolicyDocument, context: EvaluationContext): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a policy would deny a given context
|
|
56
|
+
*
|
|
57
|
+
* Convenience helper for common allow/deny checks.
|
|
58
|
+
*
|
|
59
|
+
* @param policy - Policy document
|
|
60
|
+
* @param context - Evaluation context
|
|
61
|
+
* @returns true if decision is 'deny'
|
|
62
|
+
*/
|
|
63
|
+
export declare function isDenied(policy: PolicyDocument, context: EvaluationContext): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Check if a policy requires review for a given context
|
|
66
|
+
*
|
|
67
|
+
* Convenience helper for review checks.
|
|
68
|
+
*
|
|
69
|
+
* @param policy - Policy document
|
|
70
|
+
* @param context - Evaluation context
|
|
71
|
+
* @returns true if decision is 'review'
|
|
72
|
+
*/
|
|
73
|
+
export declare function requiresReview(policy: PolicyDocument, context: EvaluationContext): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Batch evaluate multiple contexts against a policy
|
|
76
|
+
*
|
|
77
|
+
* Useful for testing or bulk authorization checks.
|
|
78
|
+
*
|
|
79
|
+
* @param policy - Policy document
|
|
80
|
+
* @param contexts - Array of evaluation contexts
|
|
81
|
+
* @returns Array of evaluation results (same order as contexts)
|
|
82
|
+
*/
|
|
83
|
+
export declare function evaluateBatch(policy: PolicyDocument, contexts: EvaluationContext[]): EvaluationResult[];
|
|
84
|
+
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,cAAc,EACd,UAAU,EAEV,iBAAiB,EACjB,gBAAgB,EAIjB,MAAM,SAAS,CAAC;AAmJjB;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAmB7F;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAc3F;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CAOxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAGrF;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAGpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAG1F;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,iBAAiB,EAAE,GAC5B,gBAAgB,EAAE,CAEpB"}
|