@kindgi/guardrails 0.0.0-bootstrap.0 → 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 (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
@@ -0,0 +1,407 @@
1
+ import type { Capability, ModelProvider, ProviderRegistry, TenantPolicy } from '@kindgi/capabilities';
2
+ import type { ComplianceProvider } from '@kindgi/compliance';
3
+ import type { AgentId, FlowId, GuardrailId, ProjectId, RunId, TenantId, Timestamp, ToolId } from '@kindgi/types';
4
+ /**
5
+ * How a guardrail is checked. Open string — the engine dispatches
6
+ * on this value through an `ExecutionStrategyRegistry`. Built-in kinds
7
+ * are `'zero-llm' | 'llm-judge' | 'external'` (see
8
+ * `execution-strategy.ts`). Adapter packages register strategies for
9
+ * their own kinds without touching the engine — e.g. `'sandbox-code'`.
10
+ *
11
+ * The `BUILT_IN_GUARDRAIL_KINDS` constant enumerates the well-known values
12
+ * (the schema lists them as `examples`); the schema accepts any non-empty
13
+ * kind. `defineGuardrail` still requires a registered check of the same
14
+ * kind, and runtime dispatch uses the registered strategies, not this
15
+ * union.
16
+ */
17
+ export type GuardrailKind = string;
18
+ export declare const BUILT_IN_GUARDRAIL_KINDS: readonly ["zero-llm", "llm-judge", "external"];
19
+ export type BuiltInGuardrailKind = (typeof BUILT_IN_GUARDRAIL_KINDS)[number];
20
+ export type GuardrailSeverity = 'info' | 'warn' | 'error' | 'critical';
21
+ /**
22
+ * Actions the engine surfaces when a check fails. Open string — the
23
+ * caller (e.g. the agent runtime) matches on this to decide behavior,
24
+ * and an optional `ActionHandlerRegistry` (see `action-handler.ts`)
25
+ * lets adapters register new actions like `'hitl-review'` or
26
+ * `'redact-then-continue'`. Any non-empty name is accepted when the
27
+ * guardrail is defined; with `EvaluationBindings.actions` set, a name
28
+ * with no registered handler fails with `unknown-action` when the
29
+ * guardrail fires.
30
+ */
31
+ export type OnViolation = string;
32
+ export declare const BUILT_IN_ON_VIOLATIONS: readonly ["halt", "retry", "escalate", "log-only", "compensate"];
33
+ export type BuiltInOnViolation = (typeof BUILT_IN_ON_VIOLATIONS)[number];
34
+ export type ScopeWhen = 'always' | 'ci-only' | 'runtime-only';
35
+ export interface Action {
36
+ readonly 'on-violation': OnViolation;
37
+ readonly retry?: {
38
+ readonly maxAttempts: number;
39
+ };
40
+ readonly escalateTo?: string;
41
+ readonly compensateWith?: string;
42
+ }
43
+ export interface Scope {
44
+ readonly when?: ScopeWhen;
45
+ readonly agents?: readonly AgentId[];
46
+ readonly flows?: readonly FlowId[];
47
+ readonly tenants?: readonly TenantId[];
48
+ }
49
+ export interface Budget {
50
+ readonly maxCostUsd?: number;
51
+ readonly maxLatencyMs?: number;
52
+ }
53
+ /**
54
+ * Isolation posture the runtime enforces around a check's handler. Same
55
+ * three tiers as `ToolManifest.sandbox` in `@kindgi/tools`.
56
+ *
57
+ * Duplicated here rather than imported from `@kindgi/tools` to keep
58
+ * this package free of a tools dependency. Keep the shape literally
59
+ * identical.
60
+ */
61
+ export type SandboxMode = 'none' | 'context-isolated' | 'strict';
62
+ /** Runtime resource caps enforced by the sandbox layer at check dispatch. */
63
+ export interface RuntimeLimits {
64
+ readonly memMB: number;
65
+ readonly cpuMs: number;
66
+ }
67
+ /** Network egress policy honored by the sandbox during a check. */
68
+ export type NetworkPolicy = {
69
+ readonly kind: 'none';
70
+ } | {
71
+ readonly kind: 'allowlist';
72
+ readonly hosts: readonly string[];
73
+ } | {
74
+ readonly kind: 'unrestricted';
75
+ };
76
+ /**
77
+ * JSON Schema for a typed `needs` slot. Author-time Zod is compiled to
78
+ * this at build (`z.toJSONSchema()`).
79
+ */
80
+ export type JsonSchema = Readonly<Record<string, unknown>>;
81
+ /**
82
+ * Discriminated typed-dependency declarations mirroring the Tool
83
+ * manifest's `TypedNeeds` shape (five slots); every slot is optional.
84
+ */
85
+ export interface TypedNeeds {
86
+ readonly env?: Readonly<Record<string, JsonSchema>>;
87
+ readonly secrets?: Readonly<Record<string, JsonSchema>>;
88
+ readonly config?: Readonly<Record<string, JsonSchema>>;
89
+ readonly capabilities?: readonly string[];
90
+ readonly bindings?: readonly string[];
91
+ }
92
+ /**
93
+ * Handler-artifact pointer for the guardrail's CHECK implementation.
94
+ * Same shape as Tool's `CodeArtifactRef` — discriminated on `kind`:
95
+ *
96
+ * - `'oci'` — production. Populated by the deploy pipeline.
97
+ * `modulePath` resolves inside the pinned
98
+ * `imageRef`; `artifactVersion` pins one deploy.
99
+ * - `'filesystem'` — dev-mode. Populated at dev-mode registration.
100
+ * `modulePath` is an absolute host path at the
101
+ * check module. Production servers SHOULD reject
102
+ * this variant.
103
+ *
104
+ * NOTE: `modulePath` points at the check handler bundle (the pack
105
+ * index's `checkModulePath`, see `@kindgi/handler-runtime`); the field
106
+ * name stays `modulePath` for wire symmetry with tools.
107
+ */
108
+ export type CodeArtifactRef = {
109
+ readonly kind: 'oci';
110
+ readonly imageRef: string;
111
+ readonly modulePath: string;
112
+ readonly artifactVersion: string;
113
+ } | {
114
+ readonly kind: 'filesystem';
115
+ readonly modulePath: string;
116
+ };
117
+ /**
118
+ * A guardrail declaration. Same shape at runtime + in CI — one definition,
119
+ * two enforcement paths.
120
+ *
121
+ * `check` references a concrete check implementation:
122
+ * - For `zero-llm`: id of a check in the CheckRegistry (built-in or custom).
123
+ * - For `llm-judge`: id of a registered check of kind `llm-judge`
124
+ * (`defineGuardrail` resolves it); the judge itself is configured by
125
+ * `config` (`LlmJudgeConfig`) + `judgeCapabilities`.
126
+ * - For `external` and adapter kinds: an id the kind's strategy understands.
127
+ *
128
+ * `config` is check-specific — the check implementation validates it.
129
+ *
130
+ * ## Additive extensions
131
+ *
132
+ * `sandbox`, `limits`, `network`, `needsSpec`, `codeArtifactRef` are the
133
+ * same runtime-declaration extensions that ToolManifest carries.
134
+ * Guardrails are code-carrying primitives too (a check ships as a
135
+ * bundle at `checkModulePath` + `node_modules`), so every field applies
136
+ * as-is — none are excluded. The dispatch, SDK and deploy layers
137
+ * populate + honor them; consumers that don't know about them ignore the fields.
138
+ */
139
+ export interface Guardrail {
140
+ /**
141
+ * Globally-unique guardrail identifier. Convention:
142
+ * `<pack-id>.<guardrail-name>` (kebab-case, dot-namespaced). See the
143
+ * `GuardrailId` brand for the naming rule.
144
+ */
145
+ readonly id: GuardrailId;
146
+ /** Short human-readable label shown in violation UI + audit logs. */
147
+ readonly name?: string;
148
+ /** Prose describing what the guardrail guarantees + what happens on violation. Surfaced to reviewers when the guardrail fires. */
149
+ readonly description?: string;
150
+ /**
151
+ * `'zero-llm'` — pure function over the trace (default, fast,
152
+ * deterministic; the recommended kind for most safety rules).
153
+ * `'llm-judge'` — uses a model to score (opt-in, costs money;
154
+ * declare `budget` + `judgeCapabilities`). `'external'` — evaluated
155
+ * outside the engine by a caller-registered strategy (the built-in
156
+ * `external` strategy returns an `invalid-guardrail` error).
157
+ */
158
+ readonly kind: GuardrailKind;
159
+ /**
160
+ * Reference to the concrete check implementation. String id of a
161
+ * `RegisteredCheck` in the runtime `CheckRegistry` — either a
162
+ * built-in from `@kindgi/guardrails` (`BUILT_IN_CHECK_IDS`: `must-cite`,
163
+ * `never-call-tool`, `max-tool-calls`, `output-matches`, `tool-order`,
164
+ * `required-substring`, `forbidden-substring`) or a pack-authored
165
+ * check registered under its id (see `defineCheck`).
166
+ */
167
+ readonly check: string;
168
+ /**
169
+ * Check-specific configuration. Interpreted by the check
170
+ * implementation (validated by the check's `validateConfig`, e.g.
171
+ * derived from its `configSchema`, when `defineGuardrail` runs).
172
+ * Shape is opaque to the engine; e.g. `must-cite` reads
173
+ * `{minCitations?: number}`, `output-matches` reads `{pattern: string}`.
174
+ */
175
+ readonly config?: Readonly<Record<string, unknown>>;
176
+ /**
177
+ * What the framework does when this guardrail fires — `halt`
178
+ * (fail the run), `retry` (re-execute the step with a
179
+ * `maxAttempts` cap), `escalate` (route to HITL review),
180
+ * `log-only` (record but don't block), `compensate` (invoke a
181
+ * named compensation tool). `BUILT_IN_ON_VIOLATIONS` lists the
182
+ * built-in values; `OnViolation` itself is an open string.
183
+ */
184
+ readonly action: Action;
185
+ /**
186
+ * `'info'` / `'warn'` / `'error'` / `'critical'` — orthogonal to
187
+ * `action`. Severity is what LOGS + DASHBOARDS group by; action is
188
+ * what EXECUTION does. A `log-only` guardrail can still be
189
+ * `'critical'` — just doesn't halt.
190
+ */
191
+ readonly severity?: GuardrailSeverity;
192
+ /**
193
+ * When this guardrail applies. `{when: 'always'}` fires everywhere;
194
+ * `{when: 'ci-only'}` blocks CI but not runtime; `{when: 'runtime-only'}`
195
+ * enforces at runtime but not CI. Per-agent / per-flow selectors
196
+ * narrow further (e.g. `{agents: ['acme.support-agent']}`).
197
+ */
198
+ readonly scope?: Scope;
199
+ /**
200
+ * Cost + latency ceiling per guardrail invocation (relevant for
201
+ * `kind: 'llm-judge'` — zero-llm checks are free): `maxCostUsd` +
202
+ * `maxLatencyMs`. Declarative — not enforced by the runtime.
203
+ */
204
+ readonly budget?: Budget;
205
+ /**
206
+ * For `kind: 'llm-judge'` — capability declaration for the judge
207
+ * model, routed through `@kindgi/capabilities` under the tenant policy
208
+ * the caller passes as `EvaluationBindings.tenantPolicy`. Enables BYO
209
+ * judges. Ignored for zero-llm + external.
210
+ */
211
+ readonly judgeCapabilities?: Capability;
212
+ /** Isolation posture — see `SandboxMode`. */
213
+ readonly sandbox?: SandboxMode;
214
+ /** Memory + CPU caps enforced by the sandbox at check dispatch. */
215
+ readonly limits?: RuntimeLimits;
216
+ /** Network egress policy the sandbox honors while the check runs. */
217
+ readonly network?: NetworkPolicy;
218
+ /**
219
+ * Discriminated typed-dependency declarations (env / secrets / config /
220
+ * capabilities / bindings). See `TypedNeeds` for the shape.
221
+ */
222
+ readonly needsSpec?: TypedNeeds;
223
+ /**
224
+ * Pointer at the deploy-time OCI image + module path carrying the
225
+ * check handler bytes. Absent for in-process declarations.
226
+ */
227
+ readonly codeArtifactRef?: CodeArtifactRef;
228
+ }
229
+ /**
230
+ * Recorded events from a run that checks operate on. Callers materialize
231
+ * these from the run's recorded events, memory and provenance —
232
+ * guardrails doesn't read those directly (avoids a hard dep loop; keeps
233
+ * checks pure).
234
+ */
235
+ export interface ToolCallRecord {
236
+ readonly toolId: ToolId;
237
+ readonly toolName: string;
238
+ readonly arguments: Readonly<Record<string, unknown>>;
239
+ readonly at: Timestamp;
240
+ }
241
+ export interface ToolResultRecord {
242
+ readonly toolCallId: string;
243
+ readonly output: unknown;
244
+ readonly at: Timestamp;
245
+ }
246
+ export interface ModelCallRecord {
247
+ readonly providerId: string;
248
+ readonly model: string;
249
+ readonly promptTokens: number;
250
+ readonly completionTokens: number;
251
+ readonly at: Timestamp;
252
+ }
253
+ /**
254
+ * The materialised run trace a check reads. Callers assemble this at the
255
+ * boundary from the run's events / memory / provenance — the check
256
+ * itself is a pure function over this shape.
257
+ *
258
+ * Adapter checks that need data not typed here use
259
+ * `attributes: Record<string, unknown>` as the escape hatch.
260
+ */
261
+ export interface RunTrace {
262
+ readonly runId: RunId;
263
+ readonly tenantId: TenantId;
264
+ /**
265
+ * Content-scope anchor. Threaded to
266
+ * `bindings.compliance.emit()` when a violation surfaces so
267
+ * evidence records land under the same project as the run.
268
+ * Optional; when absent, the violation emit is skipped.
269
+ */
270
+ readonly projectId?: ProjectId;
271
+ readonly agentId?: AgentId;
272
+ readonly flowId?: FlowId;
273
+ /** Final assistant output text. Present when the run produced text. */
274
+ readonly output?: string;
275
+ readonly toolCalls: readonly ToolCallRecord[];
276
+ readonly toolResults: readonly ToolResultRecord[];
277
+ readonly modelCalls: readonly ModelCallRecord[];
278
+ /**
279
+ * The user input that opened the turn / flow invocation. Populated
280
+ * by the agent runtime (`@kindgi/agents`); optional for runs that
281
+ * have no user turn.
282
+ */
283
+ readonly userInput?: string;
284
+ /**
285
+ * Facts pulled by the agent's retrieval intents before the model
286
+ * call. Enables consistency guardrails (e.g. "every citation in
287
+ * output appears in retrieved.factIds").
288
+ */
289
+ readonly retrievedFactIds?: readonly string[];
290
+ /**
291
+ * Conversation id for multi-turn context. Undefined for one-shot
292
+ * runs that don't belong to a conversation.
293
+ */
294
+ readonly conversationId?: string;
295
+ /**
296
+ * 1-indexed turn number within the conversation. Undefined outside
297
+ * agent conversations.
298
+ */
299
+ readonly turnNumber?: number;
300
+ /** Cumulative USD cost for the turn / run. */
301
+ readonly totalCostUsd?: number;
302
+ /** Wall-clock duration in milliseconds. */
303
+ readonly durationMs?: number;
304
+ /**
305
+ * Whether this evaluation is happening in CI or at runtime. Determines
306
+ * which `scope.when` values apply.
307
+ */
308
+ readonly mode: 'ci' | 'runtime';
309
+ /** Free-form attributes checks may consult. Use for niche data not typed above. */
310
+ readonly attributes?: Readonly<Record<string, unknown>>;
311
+ }
312
+ /**
313
+ * Runtime bindings passed alongside the RunTrace so llm-judge guardrails
314
+ * can invoke a model and any guardrail can emit compliance evidence.
315
+ *
316
+ * All fields optional — a `zero-llm` guardrail needs none of them. Callers
317
+ * wire up only what they actually use.
318
+ */
319
+ export interface EvaluationBindings {
320
+ /** Required for `kind: 'llm-judge'` guardrails — resolves + invokes the judge. */
321
+ readonly providerRegistry?: ProviderRegistry;
322
+ /**
323
+ * Aborted when the caller stops waiting: the agent turn was
324
+ * cancelled, or ran past its wall-clock budget. A check that calls out
325
+ * (a judge model, a service) passes it on, so a slow call doesn't
326
+ * hold the turn; the llm-judge strategy passes it to the model call.
327
+ */
328
+ readonly abortSignal?: AbortSignal;
329
+ /**
330
+ * Optional — when present and the trace carries a `projectId`, every
331
+ * failed check emits a `guardrail-violation` compliance evidence
332
+ * record (passing checks emit nothing).
333
+ */
334
+ readonly compliance?: ComplianceProvider;
335
+ /**
336
+ * Override the judge model directly (bypasses the router). Useful for
337
+ * tests + hermetic pinning; production should route through the registry.
338
+ */
339
+ readonly judgeProvider?: ModelProvider;
340
+ /**
341
+ * The tenant's model-routing policy (provider / model allow and deny
342
+ * lists, `regionAllow`, caps). When present, llm-judge models are
343
+ * routed under it, and an explicit `judgeProvider` must satisfy it too
344
+ * — a judge never sends the run to a model the tenant doesn't allow.
345
+ */
346
+ readonly tenantPolicy?: TenantPolicy;
347
+ /**
348
+ * Optional execution-strategy registry. When present, the engine
349
+ * dispatches `guardrail.kind` through this registry instead of the
350
+ * built-in strategies (zero-llm / llm-judge / external). Callers extend
351
+ * by seeding built-ins + adapter strategies. See execution-strategy.ts.
352
+ */
353
+ readonly strategies?: import('./execution-strategy.js').ExecutionStrategyRegistry;
354
+ /**
355
+ * Optional action-handler registry. When present, the engine invokes
356
+ * the appropriate handler after evaluating each guardrail so custom
357
+ * actions (`'hitl-review'`, `'redact-then-continue'`, etc.) fire.
358
+ * Absent → the engine records the action in EvaluationResult but does
359
+ * not invoke a handler; the caller layer consults the action.
360
+ */
361
+ readonly actions?: import('./action-handler.js').ActionHandlerRegistry;
362
+ }
363
+ /** Result of a single check evaluation. */
364
+ export interface CheckResult {
365
+ readonly passed: boolean;
366
+ readonly reason?: string;
367
+ /** For llm-judge checks: the raw response text from the judge. */
368
+ readonly judgeResponse?: string;
369
+ /** Structured attributes attached to the result (evidence + logs). */
370
+ readonly attributes?: Readonly<Record<string, unknown>>;
371
+ }
372
+ /** Result of evaluating a guardrail against a trace, including action to take. */
373
+ export interface EvaluationResult {
374
+ readonly guardrailId: GuardrailId;
375
+ readonly result: CheckResult;
376
+ /** The action the caller should apply — pre-computed from `guardrail.action`. */
377
+ readonly action: OnViolation | 'noop';
378
+ readonly severity: GuardrailSeverity;
379
+ readonly at: Timestamp;
380
+ }
381
+ /**
382
+ * The signature checks implement. Pure function — same input yields same
383
+ * result. LLM-judge implementations are async and take bindings for
384
+ * capability routing.
385
+ */
386
+ export type CheckFunction = (config: Readonly<Record<string, unknown>>, trace: RunTrace, bindings: EvaluationBindings) => Promise<CheckResult>;
387
+ /**
388
+ * A registered check — has an id + optional config validator + evaluator.
389
+ * Config validation runs when the guardrail is defined; the evaluator
390
+ * runs at check time.
391
+ */
392
+ export interface RegisteredCheck {
393
+ readonly id: string;
394
+ readonly kind: GuardrailKind;
395
+ readonly evaluate: CheckFunction;
396
+ readonly validateConfig?: (config: unknown) => string | undefined;
397
+ }
398
+ /**
399
+ * Registry mapping check id → implementation. Built-in checks are
400
+ * pre-populated; consumers can register custom checks at pack init.
401
+ */
402
+ export interface CheckRegistry {
403
+ register(check: RegisteredCheck): void;
404
+ get(id: string): RegisteredCheck | undefined;
405
+ list(): readonly RegisteredCheck[];
406
+ }
407
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EACV,OAAO,EACP,MAAM,EACN,WAAW,EACX,SAAS,EACT,KAAK,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACP,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,eAAO,MAAM,wBAAwB,gDAAiD,CAAC;AACvF,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;AAEvE;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,eAAO,MAAM,sBAAsB,kEAMzB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzE,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,GA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E,EAAE,SAAS,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,kBAAkB,KACzB,OAAO,CAAC,WAAW,CAAC,CAAC;AAE1B;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;CACnE;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IACvC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAC7C,IAAI,IAAI,SAAS,eAAe,EAAE,CAAC;CACpC"}
package/dist/types.js ADDED
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export const BUILT_IN_GUARDRAIL_KINDS = ['zero-llm', 'llm-judge', 'external'];
4
+ export const BUILT_IN_ON_VIOLATIONS = [
5
+ 'halt',
6
+ 'retry',
7
+ 'escalate',
8
+ 'log-only',
9
+ 'compensate',
10
+ ];
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAmCjC,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,CAAU,CAAC;AAiBvF,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,MAAM;IACN,OAAO;IACP,UAAU;IACV,UAAU;IACV,YAAY;CACJ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,67 @@
1
1
  {
2
2
  "name": "@kindgi/guardrails",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Placeholder so a trusted publisher can be attached. Releases are published from https://github.com/kindgi/kindgi-sdk with provenance; use 0.1.0 or later.",
3
+ "version": "0.1.0",
4
+ "description": "Runtime + CI enforcement of agent-behavior guardrails for Kindgi. Same declaration runs at runtime (halt / retry / escalate / log-only / compensate on violation) and in CI (fails the build) — no drift between test and prod. Zero-LLM checks (must-cite, never-call-tool, max-tool-calls, output-matches, tool-order, required-substring, forbidden-substring) are the default fast path; LLM-judge guardrails route via @kindgi/capabilities with explicit budget declarations. Execution strategies and action handlers are pluggable registries, and failed checks optionally emit compliance evidence.",
5
5
  "license": "Apache-2.0",
6
- "repository": { "type": "git", "url": "git+https://github.com/kindgi/kindgi-sdk.git" }
7
- }
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/kindgi/kindgi-sdk.git",
9
+ "directory": "packages/guardrails"
10
+ },
11
+ "homepage": "https://github.com/kindgi/kindgi-sdk/tree/main/packages/guardrails#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/kindgi/kindgi-sdk/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "src",
27
+ "README.md",
28
+ "SPEC.md",
29
+ "type-manifest.json"
30
+ ],
31
+ "dependencies": {
32
+ "@kindgi/capabilities": "0.1.0",
33
+ "@kindgi/compliance": "0.1.0",
34
+ "@kindgi/schema": "0.1.0",
35
+ "@kindgi/types": "0.1.0",
36
+ "ajv": "^8.17.1",
37
+ "ajv-formats": "^3.0.1"
38
+ },
39
+ "peerDependencies": {
40
+ "zod": "^4.0.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "zod": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "devDependencies": {
48
+ "@kindgi/specs": "0.1.0",
49
+ "@types/node": "^22.10.5",
50
+ "typescript": "^5.7.3",
51
+ "vitest": "^2.1.8",
52
+ "zod": "^4.6.5"
53
+ },
54
+ "engines": {
55
+ "node": ">=22.0.0"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public",
59
+ "provenance": true
60
+ },
61
+ "scripts": {
62
+ "build": "tsc -p tsconfig.build.json",
63
+ "typecheck": "tsc --noEmit",
64
+ "test": "vitest run",
65
+ "clean": "rm -rf dist *.tsbuildinfo"
66
+ }
67
+ }