@red-codes/policy 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Jared Pleva
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,41 @@
1
+ import type { LoadedPolicy } from './evaluator.js';
2
+ export interface CompositionSource {
3
+ path: string;
4
+ layer: 'user' | 'project' | 'explicit';
5
+ policy: LoadedPolicy;
6
+ }
7
+ export interface CompositionResult {
8
+ policies: LoadedPolicy[];
9
+ sources: CompositionSource[];
10
+ layers: {
11
+ user: number;
12
+ project: number;
13
+ explicit: number;
14
+ };
15
+ /** Merged set of invariant IDs disabled across all composed policies.
16
+ * Union of all disabledInvariants arrays — an invariant is disabled if any
17
+ * loaded policy disables it. This is the authoritative merged list for
18
+ * the kernel; the CLI should prefer this over iterating policyDefs directly. */
19
+ disabledInvariants: string[];
20
+ }
21
+ /**
22
+ * Compose multiple policy sources into a single ordered policy array.
23
+ *
24
+ * Precedence order (lowest to highest):
25
+ * 1. User-level policies (`~/.agentguard/policy.yaml`) — org-wide defaults
26
+ * 2. Project-level policies (`./agentguard.yaml`) — project-specific rules
27
+ * 3. Explicit policies (`--policy` flags) — command-line overrides
28
+ *
29
+ * Within each layer, policies are ordered as provided. Later policies
30
+ * in the final array have higher precedence during evaluation.
31
+ *
32
+ * The evaluator checks deny rules first across all policies (first match wins),
33
+ * then allow rules (first match wins). This means deny is authoritative —
34
+ * a deny in any layer blocks the action regardless of allows in higher layers.
35
+ */
36
+ export declare function composePolicies(sources: CompositionSource[]): CompositionResult;
37
+ /**
38
+ * Build a summary of the composed policy stack for audit/display purposes.
39
+ */
40
+ export declare function describeComposition(result: CompositionResult): string;
41
+ //# sourceMappingURL=composer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composer.d.ts","sourceRoot":"","sources":["../src/composer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAC;IACvC,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF;;;oFAGgF;IAChF,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,CAwB/E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAcrE"}
@@ -0,0 +1,55 @@
1
+ // Policy composer — merges multiple policy sources with defined precedence.
2
+ // Supports layered policy composition: base → project → explicit overrides.
3
+ // Pure domain logic. No DOM, no process-specific APIs.
4
+ /**
5
+ * Compose multiple policy sources into a single ordered policy array.
6
+ *
7
+ * Precedence order (lowest to highest):
8
+ * 1. User-level policies (`~/.agentguard/policy.yaml`) — org-wide defaults
9
+ * 2. Project-level policies (`./agentguard.yaml`) — project-specific rules
10
+ * 3. Explicit policies (`--policy` flags) — command-line overrides
11
+ *
12
+ * Within each layer, policies are ordered as provided. Later policies
13
+ * in the final array have higher precedence during evaluation.
14
+ *
15
+ * The evaluator checks deny rules first across all policies (first match wins),
16
+ * then allow rules (first match wins). This means deny is authoritative —
17
+ * a deny in any layer blocks the action regardless of allows in higher layers.
18
+ */
19
+ export function composePolicies(sources) {
20
+ const layerOrder = ['user', 'project', 'explicit'];
21
+ const sorted = [...sources].sort((a, b) => layerOrder.indexOf(a.layer) - layerOrder.indexOf(b.layer));
22
+ const policies = sorted.map((s) => s.policy);
23
+ const layers = {
24
+ user: sorted.filter((s) => s.layer === 'user').length,
25
+ project: sorted.filter((s) => s.layer === 'project').length,
26
+ explicit: sorted.filter((s) => s.layer === 'explicit').length,
27
+ };
28
+ // Merge disabledInvariants across all composed policies (union).
29
+ // An invariant is disabled if any loaded policy disables it.
30
+ const disabledInvariantsSet = new Set();
31
+ for (const policy of policies) {
32
+ for (const id of policy.disabledInvariants ?? []) {
33
+ disabledInvariantsSet.add(id);
34
+ }
35
+ }
36
+ const disabledInvariants = [...disabledInvariantsSet];
37
+ return { policies, sources: sorted, layers, disabledInvariants };
38
+ }
39
+ /**
40
+ * Build a summary of the composed policy stack for audit/display purposes.
41
+ */
42
+ export function describeComposition(result) {
43
+ if (result.sources.length === 0)
44
+ return 'No policies loaded (fail-open)';
45
+ if (result.sources.length === 1)
46
+ return result.sources[0].path;
47
+ const lines = [];
48
+ lines.push(`${result.sources.length} policies composed:`);
49
+ for (const source of result.sources) {
50
+ const label = source.layer === 'user' ? 'user' : source.layer === 'project' ? 'project' : 'override';
51
+ lines.push(` [${label}] ${source.path} (${source.policy.rules.length} rules)`);
52
+ }
53
+ return lines.join('\n');
54
+ }
55
+ //# sourceMappingURL=composer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composer.js","sourceRoot":"","sources":["../src/composer.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,uDAAuD;AAyBvD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAAC,OAA4B;IAC1D,MAAM,UAAU,GAAiC,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IACjF,MAAM,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAC9B,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CACpE,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,MAAM,CAAC,MA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,KAAK,GACT,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;QACzF,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,182 @@
1
+ import type { AgentPersona } from '@red-codes/core';
2
+ export interface PersonaCondition {
3
+ trustTier?: string[];
4
+ role?: string[];
5
+ autonomy?: string[];
6
+ riskTolerance?: string[];
7
+ tags?: string[];
8
+ }
9
+ /**
10
+ * Forecast-based policy condition — evaluates against impact forecast data
11
+ * attached to the intent. Allows predictive governance rules such as
12
+ * "deny if predicted test risk > 50" or "escalate if blast radius > 30".
13
+ *
14
+ * Each numeric field is a threshold: the condition matches when the intent's
15
+ * forecast value meets or exceeds the threshold. For riskLevel, the condition
16
+ * matches when the forecast risk level is included in the specified array.
17
+ */
18
+ export interface ForecastCondition {
19
+ /** Match when predicted test risk score >= this value (0–100) */
20
+ testRiskScore?: number;
21
+ /** Match when predicted blast radius score >= this value */
22
+ blastRadiusScore?: number;
23
+ /** Match when predicted risk level is one of these */
24
+ riskLevel?: Array<'low' | 'medium' | 'high'>;
25
+ /** Match when predicted file count >= this value */
26
+ predictedFileCount?: number;
27
+ /** Match when predicted dependency count >= this value */
28
+ dependencyCount?: number;
29
+ }
30
+ /**
31
+ * Captures the actual vs. threshold comparison for each evaluated forecast field.
32
+ * Populated in conditionDetails when a forecast condition is present, giving
33
+ * operators a concrete audit trail (e.g. testRiskScore: { actual: 60, threshold: 50 }).
34
+ */
35
+ export interface ForecastMatchValues {
36
+ testRiskScore?: {
37
+ actual: number;
38
+ threshold: number;
39
+ };
40
+ blastRadiusScore?: {
41
+ actual: number;
42
+ threshold: number;
43
+ };
44
+ riskLevel?: {
45
+ actual: 'low' | 'medium' | 'high';
46
+ required: Array<'low' | 'medium' | 'high'>;
47
+ };
48
+ predictedFileCount?: {
49
+ actual: number;
50
+ threshold: number;
51
+ };
52
+ dependencyCount?: {
53
+ actual: number;
54
+ threshold: number;
55
+ };
56
+ }
57
+ /**
58
+ * Forecast data that can be attached to a NormalizedIntent for
59
+ * predictive policy evaluation. Mirrors the shape of ImpactForecast
60
+ * from the kernel simulation package without creating a dependency.
61
+ */
62
+ export interface IntentForecast {
63
+ predictedFiles: string[];
64
+ dependenciesAffected: string[];
65
+ testRiskScore: number;
66
+ blastRadiusScore: number;
67
+ riskLevel: 'low' | 'medium' | 'high';
68
+ }
69
+ export interface PolicyRule {
70
+ action: string | string[];
71
+ effect: 'allow' | 'deny';
72
+ conditions?: {
73
+ scope?: string[];
74
+ limit?: number;
75
+ branches?: string[];
76
+ requireTests?: boolean;
77
+ requireFormat?: boolean;
78
+ requireWorktree?: boolean;
79
+ persona?: PersonaCondition;
80
+ forecast?: ForecastCondition;
81
+ };
82
+ reason?: string;
83
+ /** Optional intervention type override for deny rules. When set, the kernel uses this
84
+ * instead of the severity-based default (e.g., `intervention: 'pause'` or `'rollback'`). */
85
+ intervention?: 'pause' | 'rollback' | 'deny' | 'modify';
86
+ }
87
+ export interface LoadedPolicy {
88
+ id: string;
89
+ name: string;
90
+ description?: string;
91
+ rules: PolicyRule[];
92
+ severity: number;
93
+ persona?: AgentPersona;
94
+ /** Semantic version of the policy pack (e.g., "1.2.0") */
95
+ version?: string;
96
+ /** Required AgentGuard version range (e.g., ">=2.0.0", "^2.1.0") */
97
+ agentguardVersion?: string;
98
+ /** Invariant IDs to disable for this policy (human-operator override) */
99
+ disabledInvariants?: string[];
100
+ /** Enforcement mode: 'monitor' (warn) or 'enforce' (block). Defaults to 'monitor'. */
101
+ mode?: 'monitor' | 'enforce';
102
+ /** Per-invariant mode overrides from yaml config or pack */
103
+ invariantModes?: Record<string, 'monitor' | 'enforce'>;
104
+ /** Named pack reference (resolved by the hook layer) */
105
+ pack?: string;
106
+ }
107
+ export interface NormalizedIntent {
108
+ action: string;
109
+ target: string;
110
+ agent: string;
111
+ branch?: string;
112
+ command?: string;
113
+ filesAffected?: number;
114
+ metadata?: Record<string, unknown>;
115
+ persona?: AgentPersona;
116
+ /** Impact forecast data from simulation, used for predictive policy rules */
117
+ forecast?: IntentForecast;
118
+ destructive: boolean;
119
+ }
120
+ /** Evaluation result for a single rule against an intent */
121
+ export interface RuleEvaluation {
122
+ policyId: string;
123
+ policyName: string;
124
+ ruleIndex: number;
125
+ rule: PolicyRule;
126
+ actionMatched: boolean;
127
+ conditionsMatched: boolean;
128
+ conditionDetails: {
129
+ scopeMatched?: boolean;
130
+ limitExceeded?: boolean;
131
+ branchMatched?: boolean;
132
+ personaMatched?: boolean;
133
+ forecastMatched?: boolean;
134
+ /** Actual vs. threshold values for each evaluated forecast field */
135
+ forecastValues?: ForecastMatchValues;
136
+ requireWorktreeMatched?: boolean;
137
+ };
138
+ outcome: 'match' | 'no-match' | 'skipped';
139
+ }
140
+ /** Full evaluation trace capturing every rule checked during policy evaluation */
141
+ export interface PolicyEvaluationTrace {
142
+ rulesEvaluated: RuleEvaluation[];
143
+ totalRulesChecked: number;
144
+ phaseThatMatched: 'deny' | 'allow' | 'default' | null;
145
+ durationMs: number;
146
+ }
147
+ export interface EvalResult {
148
+ allowed: boolean;
149
+ decision: 'allow' | 'deny';
150
+ matchedRule: PolicyRule | null;
151
+ matchedPolicy: LoadedPolicy | null;
152
+ reason: string;
153
+ severity: number;
154
+ /** Detailed evaluation trace — which rules were checked, which matched, and why */
155
+ trace?: PolicyEvaluationTrace;
156
+ /** Policy-specified intervention override (from the matched deny rule, if any) */
157
+ policyIntervention?: 'pause' | 'rollback' | 'deny' | 'modify';
158
+ /** Security warning when the evaluation outcome may indicate a configuration risk */
159
+ warning?: string;
160
+ }
161
+ /** Options for the policy evaluator */
162
+ export interface EvaluateOptions {
163
+ /**
164
+ * When true (default), actions with no matching policy rule are denied (fail-closed).
165
+ * This implements the "default deny" principle required by reference monitors.
166
+ *
167
+ * Set to false to opt into fail-open mode. The production hooks use this
168
+ * conditionally: default-deny when policies are loaded, fail-open when no
169
+ * policy file is found (to avoid blocking users who haven't configured governance).
170
+ */
171
+ defaultDeny?: boolean;
172
+ }
173
+ declare function matchAction(pattern: string, action: string): boolean;
174
+ declare function matchScope(scopePatterns: string[], target: string): boolean;
175
+ declare function matchPersonaCondition(personaCond: PersonaCondition, persona: AgentPersona | undefined): boolean;
176
+ declare function matchForecastCondition(forecastCond: ForecastCondition, forecast: IntentForecast | undefined): {
177
+ matched: boolean;
178
+ values: ForecastMatchValues;
179
+ };
180
+ export declare function evaluate(intent: NormalizedIntent, policies: LoadedPolicy[], options?: EvaluateOptions): EvalResult;
181
+ export { matchAction, matchScope, matchPersonaCondition, matchForecastCondition };
182
+ //# sourceMappingURL=evaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../src/evaluator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,SAAS,CAAC,EAAE,K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