@kindgi/guardrails 0.0.0-bootstrap.0 → 0.1.1

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 (55) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +78 -1
  3. package/dist/action-handler.d.ts +82 -0
  4. package/dist/action-handler.d.ts.map +1 -0
  5. package/dist/action-handler.js +120 -0
  6. package/dist/action-handler.js.map +1 -0
  7. package/dist/checks.d.ts +9 -0
  8. package/dist/checks.d.ts.map +1 -0
  9. package/dist/checks.js +235 -0
  10. package/dist/checks.js.map +1 -0
  11. package/dist/define-check.d.ts +93 -0
  12. package/dist/define-check.d.ts.map +1 -0
  13. package/dist/define-check.js +110 -0
  14. package/dist/define-check.js.map +1 -0
  15. package/dist/define.d.ts +27 -0
  16. package/dist/define.d.ts.map +1 -0
  17. package/dist/define.js +126 -0
  18. package/dist/define.js.map +1 -0
  19. package/dist/engine.d.ts +49 -0
  20. package/dist/engine.d.ts.map +1 -0
  21. package/dist/engine.js +198 -0
  22. package/dist/engine.js.map +1 -0
  23. package/dist/errors.d.ts +91 -0
  24. package/dist/errors.d.ts.map +1 -0
  25. package/dist/errors.js +4 -0
  26. package/dist/errors.js.map +1 -0
  27. package/dist/execution-strategy.d.ts +80 -0
  28. package/dist/execution-strategy.d.ts.map +1 -0
  29. package/dist/execution-strategy.js +96 -0
  30. package/dist/execution-strategy.js.map +1 -0
  31. package/dist/guardrail.schema.json +261 -0
  32. package/dist/index.d.ts +16 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +11 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/judge.d.ts +31 -0
  37. package/dist/judge.d.ts.map +1 -0
  38. package/dist/judge.js +171 -0
  39. package/dist/judge.js.map +1 -0
  40. package/dist/types.d.ts +407 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/types.js +11 -0
  43. package/dist/types.js.map +1 -0
  44. package/package.json +64 -4
  45. package/src/action-handler.ts +179 -0
  46. package/src/checks.ts +236 -0
  47. package/src/define-check.ts +207 -0
  48. package/src/define.ts +146 -0
  49. package/src/engine.ts +271 -0
  50. package/src/errors.ts +107 -0
  51. package/src/execution-strategy.ts +184 -0
  52. package/src/guardrail.schema.json +261 -0
  53. package/src/index.ts +79 -0
  54. package/src/judge.ts +221 -0
  55. package/src/types.ts +455 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
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 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 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 those 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 describing the origin of the Work and
141
+ 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Kindgi Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,80 @@
1
1
  # @kindgi/guardrails
2
2
 
3
- A placeholder. Releases come from https://github.com/kindgi/kindgi-sdk.
3
+ Runtime + CI enforcement of agent-behavior guardrails for Kindgi. Every declared guardrail references a **check** (built-in or custom) that decides whether the run trace passes. `evaluateGuardrail` / `evaluateAll` run guardrails against a `RunTrace`, dispatching each `kind` through an execution-strategy registry (`zero-llm`, `llm-judge`, `external` built in). See `@kindgi/specs/guardrail.schema.json` for the wire contract.
4
+
5
+ ## Schema authoring for custom checks
6
+
7
+ Custom checks accept an optional `configSchema` — **either** a JSON Schema Draft 2020-12 object **or** a Zod v4 schema. When set, `defineCheck` derives the check's `validateConfig` function from the schema so authors don't repeat themselves. The wire form of a guardrail's `config` stays a plain JSON object; Zod is TS-user sugar that `defineCheck` converts when the check is defined.
8
+
9
+ ### JSON Schema authoring
10
+
11
+ ```ts
12
+ import { defineCheck, createCheckRegistry } from '@kindgi/guardrails';
13
+
14
+ const maxCitations = defineCheck({
15
+ id: 'demo.max-citations',
16
+ kind: 'zero-llm',
17
+ configSchema: {
18
+ type: 'object',
19
+ properties: { max: { type: 'integer', minimum: 1 } },
20
+ required: ['max'],
21
+ additionalProperties: false,
22
+ },
23
+ evaluate: async (config, trace) => {
24
+ const max = (config as { max: number }).max;
25
+ const matches = (trace.output ?? '').match(/\[[^\]]+\]/g) ?? [];
26
+ return matches.length <= max
27
+ ? { passed: true }
28
+ : { passed: false, reason: `too many citations (${matches.length} > ${max})` };
29
+ },
30
+ });
31
+
32
+ const registry = createCheckRegistry([maxCitations]);
33
+ ```
34
+
35
+ ### Zod v4 authoring
36
+
37
+ ```ts
38
+ import { defineCheck, createCheckRegistry } from '@kindgi/guardrails';
39
+ import { z } from 'zod';
40
+
41
+ const ConfigSchema = z.object({
42
+ max: z.number().int().min(1),
43
+ pattern: z.string().optional(),
44
+ });
45
+
46
+ const maxCitations = defineCheck({
47
+ id: 'demo.max-citations',
48
+ kind: 'zero-llm',
49
+ configSchema: ConfigSchema,
50
+ evaluate: async (config, trace) => {
51
+ // config is typed as z.infer<typeof ConfigSchema> — no cast needed.
52
+ const re = new RegExp(config.pattern ?? '\\[[^\\]]+\\]', 'g');
53
+ const matches = (trace.output ?? '').match(re) ?? [];
54
+ return matches.length <= config.max
55
+ ? { passed: true }
56
+ : { passed: false, reason: `too many citations (${matches.length} > ${config.max})` };
57
+ },
58
+ });
59
+
60
+ // Static type of the derived config:
61
+ type Config = z.infer<typeof maxCitations.configZod>;
62
+ // -> { max: number; pattern?: string }
63
+ ```
64
+
65
+ ### When to pick which
66
+
67
+ Same trade-off as `@kindgi/tools`: JSON Schema for portable / MCP-published checks, Zod for TS-first authoring with `z.infer` derivation. Both coexist; you can also leave `configSchema` off entirely and supply a hand-written `validateConfig`.
68
+
69
+ ## The `Guardrail` wire shape
70
+
71
+ Note that `Guardrail.config` on the wire is always `object` with `additionalProperties: true` — the check declares the concrete schema. Authors extend the guardrail registration surface (`defineCheck`); the guardrail surface itself takes an opaque `config` payload that the resolved check validates when `defineGuardrail` runs.
72
+
73
+ ## Peer dependency
74
+
75
+ `zod` (>= 4.0.0) is a peer dependency. Workspaces that never author with Zod never install it. Zod schemas that fail to convert (unrepresentable constructs like `z.function()`) surface as `invalid-check-definition` thrown at pack init — same failure model as an uncompilable JSON Schema.
76
+
77
+ ## Related
78
+
79
+ - `packages/schema/SPEC.md` — §"Zod as optional authoring surface".
80
+ - `packages/tools/README.md` — the mirror pattern for tool authoring.
@@ -0,0 +1,82 @@
1
+ import type { EvaluationResult, Guardrail, RunTrace } from './types.js';
2
+ /**
3
+ * A handler that knows how to APPLY one action (`halt`, `retry`,
4
+ * `escalate`, `log-only`, `compensate`, or custom). Registered once at
5
+ * boot. When `EvaluationBindings.actions` is set, the engine calls the
6
+ * handler for a violation's action after evaluating the guardrail;
7
+ * without it, the engine only reports the action and the caller applies
8
+ * it.
9
+ *
10
+ * Handlers don't mutate the trace; they emit side effects (schedule
11
+ * retry, enqueue HITL review, run compensating tool). The engine
12
+ * computes `action` from the guardrail's declaration and hands off to
13
+ * the registered handler.
14
+ *
15
+ * Adapter packages register their own action handlers (e.g. escalate →
16
+ * a HITL queue) without touching the engine.
17
+ */
18
+ export interface ActionHandler {
19
+ /** Discriminant matching `guardrail.action['on-violation']`. */
20
+ readonly action: string;
21
+ /** Human-friendly name for diagnostics. */
22
+ readonly name?: string;
23
+ /**
24
+ * Apply the action. Called after the engine identifies a violation.
25
+ * An `err` result is attached to the evaluation as
26
+ * `result.attributes.actionHandlerError`; it doesn't roll back the
27
+ * evaluation (violation still recorded, compliance evidence still
28
+ * emitted).
29
+ */
30
+ apply(context: ActionContext): Promise<ActionResult>;
31
+ }
32
+ export interface ActionContext {
33
+ readonly guardrail: Guardrail;
34
+ readonly evaluation: EvaluationResult;
35
+ readonly trace: RunTrace;
36
+ }
37
+ export type ActionResult = {
38
+ readonly kind: 'ok';
39
+ } | {
40
+ readonly kind: 'err';
41
+ readonly error: {
42
+ readonly code: string;
43
+ readonly message: string;
44
+ };
45
+ };
46
+ /** Registry the engine consults when a violation surfaces. */
47
+ export interface ActionHandlerRegistry {
48
+ register(handler: ActionHandler): void;
49
+ get(action: string): ActionHandler | undefined;
50
+ list(): readonly ActionHandler[];
51
+ }
52
+ export declare function createActionHandlerRegistry(seed?: readonly ActionHandler[]): ActionHandlerRegistry;
53
+ /**
54
+ * `halt` — the caller (e.g. the agent runtime) is expected to stop the
55
+ * run. This handler is a no-op record; the enforcement happens in the
56
+ * caller, which sees the `halt` action in the EvaluationResult.
57
+ */
58
+ export declare const haltHandler: ActionHandler;
59
+ /** `log-only` — record + carry on. */
60
+ export declare const logOnlyHandler: ActionHandler;
61
+ /** `noop` — action synthesized when the check passes; nothing to do. */
62
+ export declare const noopHandler: ActionHandler;
63
+ /**
64
+ * `retry` — records the retry intent. Actual retry scheduling happens
65
+ * in the caller. Handler validates the guardrail's action.retry policy
66
+ * is well-formed.
67
+ */
68
+ export declare const retryHandler: ActionHandler;
69
+ /**
70
+ * `escalate` — records the escalate intent. Actual routing (e.g. to a
71
+ * HITL review queue) happens in the caller or an adapter handler.
72
+ * Handler validates `guardrail.action.escalateTo` is set.
73
+ */
74
+ export declare const escalateHandler: ActionHandler;
75
+ /**
76
+ * `compensate` — records the compensation intent. The caller invokes
77
+ * the compensating tool via `guardrail.action.compensateWith`.
78
+ */
79
+ export declare const compensateHandler: ActionHandler;
80
+ /** Convenience seed with all built-in handlers. */
81
+ export declare const BUILT_IN_ACTION_HANDLERS: readonly ActionHandler[];
82
+ //# sourceMappingURL=action-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-handler.d.ts","sourceRoot":"","sources":["../src/action-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,aAAa;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;CAC1B;AAED,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAElG,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IACvC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAC/C,IAAI,IAAI,SAAS,aAAa,EAAE,CAAC;CAClC;AAED,wBAAgB,2BAA2B,CACzC,IAAI,GAAE,SAAS,aAAa,EAAO,GAClC,qBAAqB,CAcvB;AAID;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,aAMzB,CAAC;AAEF,sCAAsC;AACtC,eAAO,MAAM,cAAc,EAAE,aAM5B,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,WAAW,EAAE,aAMzB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,aAgB1B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,aAe7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAe/B,CAAC;AAEF,mDAAmD;AACnD,eAAO,MAAM,wBAAwB,EAAE,SAAS,aAAa,EAO5D,CAAC"}
@@ -0,0 +1,120 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export function createActionHandlerRegistry(seed = []) {
4
+ const handlers = new Map();
5
+ for (const h of seed)
6
+ handlers.set(h.action, h);
7
+ return {
8
+ register(handler) {
9
+ handlers.set(handler.action, handler);
10
+ },
11
+ get(action) {
12
+ return handlers.get(action);
13
+ },
14
+ list() {
15
+ return [...handlers.values()];
16
+ },
17
+ };
18
+ }
19
+ // ============ built-in action handlers (record-only defaults) ============
20
+ /**
21
+ * `halt` — the caller (e.g. the agent runtime) is expected to stop the
22
+ * run. This handler is a no-op record; the enforcement happens in the
23
+ * caller, which sees the `halt` action in the EvaluationResult.
24
+ */
25
+ export const haltHandler = {
26
+ action: 'halt',
27
+ name: 'Halt run',
28
+ async apply() {
29
+ return { kind: 'ok' };
30
+ },
31
+ };
32
+ /** `log-only` — record + carry on. */
33
+ export const logOnlyHandler = {
34
+ action: 'log-only',
35
+ name: 'Log only',
36
+ async apply() {
37
+ return { kind: 'ok' };
38
+ },
39
+ };
40
+ /** `noop` — action synthesized when the check passes; nothing to do. */
41
+ export const noopHandler = {
42
+ action: 'noop',
43
+ name: 'No-op (check passed)',
44
+ async apply() {
45
+ return { kind: 'ok' };
46
+ },
47
+ };
48
+ /**
49
+ * `retry` — records the retry intent. Actual retry scheduling happens
50
+ * in the caller. Handler validates the guardrail's action.retry policy
51
+ * is well-formed.
52
+ */
53
+ export const retryHandler = {
54
+ action: 'retry',
55
+ name: 'Retry (caller-scheduled)',
56
+ async apply(ctx) {
57
+ const retry = ctx.guardrail.action.retry;
58
+ if (retry === undefined || retry.maxAttempts <= 0) {
59
+ return {
60
+ kind: 'err',
61
+ error: {
62
+ code: 'invalid-action-config',
63
+ message: `retry action on guardrail "${ctx.guardrail.id}" needs action.retry.maxAttempts > 0`,
64
+ },
65
+ };
66
+ }
67
+ return { kind: 'ok' };
68
+ },
69
+ };
70
+ /**
71
+ * `escalate` — records the escalate intent. Actual routing (e.g. to a
72
+ * HITL review queue) happens in the caller or an adapter handler.
73
+ * Handler validates `guardrail.action.escalateTo` is set.
74
+ */
75
+ export const escalateHandler = {
76
+ action: 'escalate',
77
+ name: 'Escalate (caller-routed)',
78
+ async apply(ctx) {
79
+ if (ctx.guardrail.action.escalateTo === undefined) {
80
+ return {
81
+ kind: 'err',
82
+ error: {
83
+ code: 'invalid-action-config',
84
+ message: `escalate action on guardrail "${ctx.guardrail.id}" needs action.escalateTo`,
85
+ },
86
+ };
87
+ }
88
+ return { kind: 'ok' };
89
+ },
90
+ };
91
+ /**
92
+ * `compensate` — records the compensation intent. The caller invokes
93
+ * the compensating tool via `guardrail.action.compensateWith`.
94
+ */
95
+ export const compensateHandler = {
96
+ action: 'compensate',
97
+ name: 'Compensate (caller-invoked)',
98
+ async apply(ctx) {
99
+ if (ctx.guardrail.action.compensateWith === undefined) {
100
+ return {
101
+ kind: 'err',
102
+ error: {
103
+ code: 'invalid-action-config',
104
+ message: `compensate action on guardrail "${ctx.guardrail.id}" needs action.compensateWith`,
105
+ },
106
+ };
107
+ }
108
+ return { kind: 'ok' };
109
+ },
110
+ };
111
+ /** Convenience seed with all built-in handlers. */
112
+ export const BUILT_IN_ACTION_HANDLERS = [
113
+ haltHandler,
114
+ logOnlyHandler,
115
+ noopHandler,
116
+ retryHandler,
117
+ escalateHandler,
118
+ compensateHandler,
119
+ ];
120
+ //# sourceMappingURL=action-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-handler.js","sourceRoot":"","sources":["../src/action-handler.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,9 @@
1
+ import type { CheckRegistry, RegisteredCheck } from './types.js';
2
+ /**
3
+ * Create a fresh CheckRegistry pre-populated with built-in checks.
4
+ * Consumers register custom checks at pack init.
5
+ */
6
+ export declare function createCheckRegistry(seed?: readonly RegisteredCheck[]): CheckRegistry;
7
+ /** Exported for tests + downstream introspection. */
8
+ export declare const BUILT_IN_CHECK_IDS: string[];
9
+ //# sourceMappingURL=checks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../src/checks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiB,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAkNhF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,GAAE,SAAS,eAAe,EAAO,GAAG,aAAa,CAexF;AAED,qDAAqD;AACrD,eAAO,MAAM,kBAAkB,UAAmC,CAAC"}