@reactive-agents/guardrails 0.1.0 → 0.5.5

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/dist/index.d.ts CHANGED
@@ -78,6 +78,89 @@ declare const detectToxicity: (text: string, customBlocklist?: readonly string[]
78
78
 
79
79
  declare const checkContract: (text: string, contract: AgentContract) => Effect.Effect<DetectionResult, never>;
80
80
 
81
+ declare const KillSwitchService_base: Context.TagClass<KillSwitchService, "KillSwitchService", {
82
+ /** Trigger the kill switch for an agent. Execution halts at next phase boundary. */
83
+ readonly trigger: (agentId: string, reason: string) => Effect.Effect<void>;
84
+ /** Check if the kill switch has been triggered for an agent. */
85
+ readonly isTriggered: (agentId: string) => Effect.Effect<{
86
+ triggered: boolean;
87
+ reason?: string;
88
+ }>;
89
+ /** Clear the kill switch for an agent (re-enable execution). */
90
+ readonly clear: (agentId: string) => Effect.Effect<void>;
91
+ /** Trigger a global kill switch — halts ALL agents. */
92
+ readonly triggerGlobal: (reason: string) => Effect.Effect<void>;
93
+ /** Check if global kill switch is active. */
94
+ readonly isGlobalTriggered: () => Effect.Effect<{
95
+ triggered: boolean;
96
+ reason?: string;
97
+ }>;
98
+ /** Clear the global kill switch. */
99
+ readonly clearGlobal: () => Effect.Effect<void>;
100
+ /** Pause agent execution at the next phase boundary (blocks until resume). */
101
+ readonly pause: (agentId: string) => Effect.Effect<void>;
102
+ /** Resume a paused agent. */
103
+ readonly resume: (agentId: string) => Effect.Effect<void>;
104
+ /** Signal agent to stop gracefully at the next phase boundary. */
105
+ readonly stop: (agentId: string, reason: string) => Effect.Effect<void>;
106
+ /** Immediately terminate agent (also triggers kill switch). */
107
+ readonly terminate: (agentId: string, reason: string) => Effect.Effect<void>;
108
+ /** Get the current lifecycle state for an agent. */
109
+ readonly getLifecycle: (agentId: string) => Effect.Effect<"running" | "paused" | "stopping" | "terminated" | "unknown">;
110
+ /**
111
+ * If paused, block until resumed. Emits AgentPaused when blocking starts and
112
+ * AgentResumed when unblocked — so events carry the real taskId from the
113
+ * execution context rather than a synthetic "lifecycle" placeholder.
114
+ * Returns "stopping" if stop() was called while paused, else "ok".
115
+ */
116
+ readonly waitIfPaused: (agentId: string, taskId: string) => Effect.Effect<"ok" | "stopping">;
117
+ }>;
118
+ /**
119
+ * KillSwitchService — emergency stop for agent execution.
120
+ *
121
+ * When triggered, the execution engine will halt at the next phase
122
+ * transition and return a TaskResult with the kill reason.
123
+ */
124
+ declare class KillSwitchService extends KillSwitchService_base {
125
+ }
126
+ declare const KillSwitchServiceLive: () => Layer.Layer<KillSwitchService, never, never>;
127
+
128
+ declare const BehavioralContractSchema: Schema.Struct<{
129
+ /** Tools the agent is NOT allowed to call. */
130
+ deniedTools: Schema.optional<Schema.Array$<typeof Schema.String>>;
131
+ /** If set, ONLY these tools may be called (allowlist). */
132
+ allowedTools: Schema.optional<Schema.Array$<typeof Schema.String>>;
133
+ /** Maximum number of tool calls per execution. */
134
+ maxToolCalls: Schema.optional<typeof Schema.Number>;
135
+ /** Maximum iterations before forced halt. */
136
+ maxIterations: Schema.optional<typeof Schema.Number>;
137
+ /** Maximum output length in characters. */
138
+ maxOutputLength: Schema.optional<typeof Schema.Number>;
139
+ /** Topics the agent must not address. */
140
+ deniedTopics: Schema.optional<Schema.Array$<typeof Schema.String>>;
141
+ /** If true, agent must disclose it is an AI. */
142
+ requireDisclosure: Schema.optional<typeof Schema.Boolean>;
143
+ }>;
144
+ type BehavioralContract = typeof BehavioralContractSchema.Type;
145
+ interface ContractViolation {
146
+ readonly rule: string;
147
+ readonly message: string;
148
+ readonly severity: "warning" | "block";
149
+ }
150
+ declare const BehavioralContractService_base: Context.TagClass<BehavioralContractService, "BehavioralContractService", {
151
+ /** Check if a tool call is allowed by the contract. */
152
+ readonly checkToolCall: (toolName: string, toolCallCount: number) => Effect.Effect<ContractViolation | null>;
153
+ /** Check if output complies with the contract. */
154
+ readonly checkOutput: (output: string) => Effect.Effect<ContractViolation | null>;
155
+ /** Check iteration count against contract. */
156
+ readonly checkIteration: (iteration: number) => Effect.Effect<ContractViolation | null>;
157
+ /** Get the active contract. */
158
+ readonly getContract: () => Effect.Effect<BehavioralContract>;
159
+ }>;
160
+ declare class BehavioralContractService extends BehavioralContractService_base {
161
+ }
162
+ declare const BehavioralContractServiceLive: (contract: BehavioralContract) => Layer.Layer<BehavioralContractService, never, never>;
163
+
81
164
  declare const GuardrailService_base: Context.TagClass<GuardrailService, "GuardrailService", {
82
165
  /** Check input text against all configured guardrails. */
83
166
  readonly check: (text: string) => Effect.Effect<GuardrailResult, GuardrailError>;
@@ -92,4 +175,4 @@ declare const GuardrailServiceLive: (config: GuardrailConfig) => Layer.Layer<Gua
92
175
 
93
176
  declare const createGuardrailsLayer: (config?: Partial<GuardrailConfig>) => effect_Layer.Layer<GuardrailService, never, never>;
94
177
 
95
- export { type AgentContract, AgentContractSchema, type DetectionResult, type GuardrailConfig, GuardrailConfigSchema, GuardrailError, type GuardrailResult, GuardrailResultSchema, GuardrailService, GuardrailServiceLive, Severity, Severity as SeveritySchema, ViolationError, ViolationType, ViolationType as ViolationTypeSchema, checkContract, createGuardrailsLayer, defaultGuardrailConfig, detectInjection, detectPii, detectToxicity };
178
+ export { type AgentContract, AgentContractSchema, type BehavioralContract, BehavioralContractSchema, BehavioralContractService, BehavioralContractServiceLive, type ContractViolation, type DetectionResult, type GuardrailConfig, GuardrailConfigSchema, GuardrailError, type GuardrailResult, GuardrailResultSchema, GuardrailService, GuardrailServiceLive, KillSwitchService, KillSwitchServiceLive, Severity, Severity as SeveritySchema, ViolationError, ViolationType, ViolationType as ViolationTypeSchema, checkContract, createGuardrailsLayer, defaultGuardrailConfig, detectInjection, detectPii, detectToxicity };
package/dist/index.js CHANGED
@@ -214,12 +214,210 @@ var checkContract = (text, contract) => Effect4.sync(() => {
214
214
  };
215
215
  });
216
216
 
217
+ // src/kill-switch.ts
218
+ import { Effect as Effect5, Context, Layer, Ref, Deferred } from "effect";
219
+ import { EventBus } from "@reactive-agents/core";
220
+ var KillSwitchService = class extends Context.Tag("KillSwitchService")() {
221
+ };
222
+ var KillSwitchServiceLive = () => Layer.effect(
223
+ KillSwitchService,
224
+ Effect5.gen(function* () {
225
+ const agentKills = yield* Ref.make(/* @__PURE__ */ new Map());
226
+ const globalKill = yield* Ref.make(null);
227
+ const lifecycleRef = yield* Ref.make(/* @__PURE__ */ new Map());
228
+ const pauseDeferreds = yield* Ref.make(/* @__PURE__ */ new Map());
229
+ const ebOpt = yield* Effect5.serviceOption(EventBus).pipe(
230
+ Effect5.catchAll(() => Effect5.succeed({ _tag: "None" }))
231
+ );
232
+ const eb = ebOpt._tag === "Some" ? ebOpt.value : null;
233
+ return KillSwitchService.of({
234
+ trigger: (agentId, reason) => Ref.update(agentKills, (m) => {
235
+ const newMap = new Map(m);
236
+ newMap.set(agentId, reason);
237
+ return newMap;
238
+ }),
239
+ isTriggered: (agentId) => Effect5.gen(function* () {
240
+ const globalReason = yield* Ref.get(globalKill);
241
+ if (globalReason != null) {
242
+ return { triggered: true, reason: globalReason };
243
+ }
244
+ const kills = yield* Ref.get(agentKills);
245
+ const reason = kills.get(agentId);
246
+ return reason != null ? { triggered: true, reason } : { triggered: false };
247
+ }),
248
+ clear: (agentId) => Ref.update(agentKills, (m) => {
249
+ const newMap = new Map(m);
250
+ newMap.delete(agentId);
251
+ return newMap;
252
+ }),
253
+ triggerGlobal: (reason) => Ref.set(globalKill, reason),
254
+ isGlobalTriggered: () => Effect5.gen(function* () {
255
+ const reason = yield* Ref.get(globalKill);
256
+ return reason != null ? { triggered: true, reason } : { triggered: false };
257
+ }),
258
+ clearGlobal: () => Ref.set(globalKill, null),
259
+ pause: (agentId) => Effect5.gen(function* () {
260
+ const d = yield* Deferred.make();
261
+ yield* Ref.update(pauseDeferreds, (m) => {
262
+ const n = new Map(m);
263
+ n.set(agentId, d);
264
+ return n;
265
+ });
266
+ yield* Ref.update(lifecycleRef, (m) => {
267
+ const n = new Map(m);
268
+ n.set(agentId, "paused");
269
+ return n;
270
+ });
271
+ }),
272
+ resume: (agentId) => Effect5.gen(function* () {
273
+ const deferreds = yield* Ref.get(pauseDeferreds);
274
+ const d = deferreds.get(agentId);
275
+ if (d) {
276
+ yield* Deferred.succeed(d, void 0);
277
+ yield* Ref.update(pauseDeferreds, (m) => {
278
+ const n = new Map(m);
279
+ n.delete(agentId);
280
+ return n;
281
+ });
282
+ }
283
+ yield* Ref.update(lifecycleRef, (m) => {
284
+ const n = new Map(m);
285
+ n.set(agentId, "running");
286
+ return n;
287
+ });
288
+ }),
289
+ stop: (agentId, _reason) => Ref.update(lifecycleRef, (m) => {
290
+ const n = new Map(m);
291
+ n.set(agentId, "stopping");
292
+ return n;
293
+ }),
294
+ terminate: (agentId, reason) => Effect5.gen(function* () {
295
+ yield* Ref.update(lifecycleRef, (m) => {
296
+ const n = new Map(m);
297
+ n.set(agentId, "terminated");
298
+ return n;
299
+ });
300
+ yield* Ref.update(agentKills, (m) => {
301
+ const n = new Map(m);
302
+ n.set(agentId, reason);
303
+ return n;
304
+ });
305
+ }),
306
+ getLifecycle: (agentId) => Ref.get(lifecycleRef).pipe(
307
+ Effect5.map((m) => m.get(agentId) ?? "unknown")
308
+ ),
309
+ waitIfPaused: (agentId, taskId) => Effect5.gen(function* () {
310
+ const lifecycle = yield* Ref.get(lifecycleRef).pipe(
311
+ Effect5.map((m) => m.get(agentId))
312
+ );
313
+ if (lifecycle === "paused") {
314
+ if (eb) {
315
+ yield* eb.publish({ _tag: "AgentPaused", agentId, taskId }).pipe(Effect5.catchAll(() => Effect5.void));
316
+ }
317
+ const deferreds = yield* Ref.get(pauseDeferreds);
318
+ const d = deferreds.get(agentId);
319
+ if (d) {
320
+ yield* Deferred.await(d);
321
+ }
322
+ if (eb) {
323
+ yield* eb.publish({ _tag: "AgentResumed", agentId, taskId }).pipe(Effect5.catchAll(() => Effect5.void));
324
+ }
325
+ }
326
+ const newLifecycle = yield* Ref.get(lifecycleRef).pipe(
327
+ Effect5.map((m) => m.get(agentId))
328
+ );
329
+ return newLifecycle === "stopping" ? "stopping" : "ok";
330
+ })
331
+ });
332
+ })
333
+ );
334
+
335
+ // src/behavioral-contracts.ts
336
+ import { Effect as Effect6, Context as Context2, Layer as Layer2, Schema as Schema2 } from "effect";
337
+ var BehavioralContractSchema = Schema2.Struct({
338
+ /** Tools the agent is NOT allowed to call. */
339
+ deniedTools: Schema2.optional(Schema2.Array(Schema2.String)),
340
+ /** If set, ONLY these tools may be called (allowlist). */
341
+ allowedTools: Schema2.optional(Schema2.Array(Schema2.String)),
342
+ /** Maximum number of tool calls per execution. */
343
+ maxToolCalls: Schema2.optional(Schema2.Number),
344
+ /** Maximum iterations before forced halt. */
345
+ maxIterations: Schema2.optional(Schema2.Number),
346
+ /** Maximum output length in characters. */
347
+ maxOutputLength: Schema2.optional(Schema2.Number),
348
+ /** Topics the agent must not address. */
349
+ deniedTopics: Schema2.optional(Schema2.Array(Schema2.String)),
350
+ /** If true, agent must disclose it is an AI. */
351
+ requireDisclosure: Schema2.optional(Schema2.Boolean)
352
+ });
353
+ var BehavioralContractService = class extends Context2.Tag("BehavioralContractService")() {
354
+ };
355
+ var BehavioralContractServiceLive = (contract) => Layer2.succeed(BehavioralContractService, {
356
+ checkToolCall: (toolName, toolCallCount) => Effect6.sync(() => {
357
+ if (contract.deniedTools?.some((d) => d.toLowerCase() === toolName.toLowerCase())) {
358
+ return {
359
+ rule: "denied-tool",
360
+ message: `Tool "${toolName}" is not allowed by behavioral contract`,
361
+ severity: "block"
362
+ };
363
+ }
364
+ if (contract.allowedTools && !contract.allowedTools.some((a) => a.toLowerCase() === toolName.toLowerCase())) {
365
+ return {
366
+ rule: "tool-not-in-allowlist",
367
+ message: `Tool "${toolName}" is not in the allowed tools list`,
368
+ severity: "block"
369
+ };
370
+ }
371
+ if (contract.maxToolCalls != null && toolCallCount >= contract.maxToolCalls) {
372
+ return {
373
+ rule: "max-tool-calls",
374
+ message: `Tool call limit reached (${contract.maxToolCalls})`,
375
+ severity: "block"
376
+ };
377
+ }
378
+ return null;
379
+ }),
380
+ checkOutput: (output) => Effect6.sync(() => {
381
+ if (contract.maxOutputLength != null && output.length > contract.maxOutputLength) {
382
+ return {
383
+ rule: "max-output-length",
384
+ message: `Output exceeds maximum length (${output.length} > ${contract.maxOutputLength})`,
385
+ severity: "block"
386
+ };
387
+ }
388
+ if (contract.deniedTopics) {
389
+ const lower = output.toLowerCase();
390
+ for (const topic of contract.deniedTopics) {
391
+ if (lower.includes(topic.toLowerCase())) {
392
+ return {
393
+ rule: "denied-topic",
394
+ message: `Output references denied topic: "${topic}"`,
395
+ severity: "block"
396
+ };
397
+ }
398
+ }
399
+ }
400
+ return null;
401
+ }),
402
+ checkIteration: (iteration) => Effect6.sync(() => {
403
+ if (contract.maxIterations != null && iteration > contract.maxIterations) {
404
+ return {
405
+ rule: "max-iterations",
406
+ message: `Iteration ${iteration} exceeds contract limit of ${contract.maxIterations}`,
407
+ severity: "block"
408
+ };
409
+ }
410
+ return null;
411
+ }),
412
+ getContract: () => Effect6.succeed(contract)
413
+ });
414
+
217
415
  // src/guardrail-service.ts
218
- import { Effect as Effect5, Context, Layer } from "effect";
219
- var GuardrailService = class extends Context.Tag("GuardrailService")() {
416
+ import { Effect as Effect7, Context as Context3, Layer as Layer3 } from "effect";
417
+ var GuardrailService = class extends Context3.Tag("GuardrailService")() {
220
418
  };
221
- var GuardrailServiceLive = (config) => Layer.succeed(GuardrailService, {
222
- check: (text) => Effect5.gen(function* () {
419
+ var GuardrailServiceLive = (config) => Layer3.succeed(GuardrailService, {
420
+ check: (text) => Effect7.gen(function* () {
223
421
  const violations = [];
224
422
  if (config.enableInjectionDetection) {
225
423
  const result = yield* detectInjection(text);
@@ -273,7 +471,7 @@ var GuardrailServiceLive = (config) => Layer.succeed(GuardrailService, {
273
471
  checkedAt: /* @__PURE__ */ new Date()
274
472
  };
275
473
  }),
276
- checkOutput: (text) => Effect5.gen(function* () {
474
+ checkOutput: (text) => Effect7.gen(function* () {
277
475
  const violations = [];
278
476
  if (config.enablePiiDetection) {
279
477
  const result = yield* detectPii(text);
@@ -316,7 +514,7 @@ var GuardrailServiceLive = (config) => Layer.succeed(GuardrailService, {
316
514
  checkedAt: /* @__PURE__ */ new Date()
317
515
  };
318
516
  }),
319
- getConfig: () => Effect5.succeed(config)
517
+ getConfig: () => Effect7.succeed(config)
320
518
  });
321
519
 
322
520
  // src/runtime.ts
@@ -326,11 +524,16 @@ var createGuardrailsLayer = (config) => GuardrailServiceLive({
326
524
  });
327
525
  export {
328
526
  AgentContractSchema,
527
+ BehavioralContractSchema,
528
+ BehavioralContractService,
529
+ BehavioralContractServiceLive,
329
530
  GuardrailConfigSchema,
330
531
  GuardrailError,
331
532
  GuardrailResultSchema,
332
533
  GuardrailService,
333
534
  GuardrailServiceLive,
535
+ KillSwitchService,
536
+ KillSwitchServiceLive,
334
537
  Severity as SeveritySchema,
335
538
  ViolationError,
336
539
  ViolationType as ViolationTypeSchema,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/errors.ts","../src/detectors/injection-detector.ts","../src/detectors/pii-detector.ts","../src/detectors/toxicity-detector.ts","../src/contracts/agent-contract.ts","../src/guardrail-service.ts","../src/runtime.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n// ─── Violation Type ───\n\nexport const ViolationType = Schema.Literal(\n \"prompt-injection\",\n \"pii-detected\",\n \"toxicity\",\n \"scope-violation\",\n \"contract-violation\",\n);\nexport type ViolationType = typeof ViolationType.Type;\n\n// ─── Severity ───\n\nexport const Severity = Schema.Literal(\"low\", \"medium\", \"high\", \"critical\");\nexport type Severity = typeof Severity.Type;\n\n// ─── Guardrail Result ───\n\nexport const GuardrailResultSchema = Schema.Struct({\n passed: Schema.Boolean,\n violations: Schema.Array(\n Schema.Struct({\n type: ViolationType,\n severity: Severity,\n message: Schema.String,\n details: Schema.optional(Schema.String),\n }),\n ),\n score: Schema.Number, // 0-1, 1 = fully safe\n checkedAt: Schema.DateFromSelf,\n});\nexport type GuardrailResult = typeof GuardrailResultSchema.Type;\n\n// ─── Agent Contract ───\n\nexport const AgentContractSchema = Schema.Struct({\n allowedTopics: Schema.Array(Schema.String),\n deniedTopics: Schema.Array(Schema.String),\n allowedActions: Schema.Array(Schema.String),\n deniedActions: Schema.Array(Schema.String),\n maxOutputLength: Schema.optional(Schema.Number),\n requireDisclosure: Schema.optional(Schema.Boolean),\n});\nexport type AgentContract = typeof AgentContractSchema.Type;\n\n// ─── Guardrail Config ───\n\nexport const GuardrailConfigSchema = Schema.Struct({\n enableInjectionDetection: Schema.Boolean,\n enablePiiDetection: Schema.Boolean,\n enableToxicityDetection: Schema.Boolean,\n contract: Schema.optional(AgentContractSchema),\n customBlocklist: Schema.optional(Schema.Array(Schema.String)),\n});\nexport type GuardrailConfig = typeof GuardrailConfigSchema.Type;\n\nexport const defaultGuardrailConfig: GuardrailConfig = {\n enableInjectionDetection: true,\n enablePiiDetection: true,\n enableToxicityDetection: true,\n};\n","import { Data } from \"effect\";\n\nexport class GuardrailError extends Data.TaggedError(\"GuardrailError\")<{\n readonly message: string;\n readonly cause?: unknown;\n}> {}\n\nexport class ViolationError extends Data.TaggedError(\"ViolationError\")<{\n readonly message: string;\n readonly violationType: string;\n readonly severity: string;\n}> {}\n","import { Effect } from \"effect\";\nimport type { ViolationType, Severity } from \"../types.js\";\n\nexport interface DetectionResult {\n readonly detected: boolean;\n readonly type: ViolationType;\n readonly severity: Severity;\n readonly message: string;\n readonly details?: string;\n}\n\n// Common prompt injection patterns\nconst INJECTION_PATTERNS: Array<{ pattern: RegExp; severity: Severity; description: string }> = [\n { pattern: /ignore\\s+(all\\s+)?previous\\s+(instructions|prompts)/i, severity: \"critical\", description: \"Instruction override attempt\" },\n { pattern: /disregard\\s+(all\\s+)?previous/i, severity: \"critical\", description: \"Instruction disregard attempt\" },\n { pattern: /forget\\s+(all\\s+)?(your\\s+)?previous/i, severity: \"high\", description: \"Memory reset attempt\" },\n { pattern: /you\\s+are\\s+now\\s+a/i, severity: \"high\", description: \"Role reassignment attempt\" },\n { pattern: /act\\s+as\\s+(if\\s+)?(you\\s+are|a)\\s/i, severity: \"medium\", description: \"Role play injection\" },\n { pattern: /system\\s*:\\s*you\\s+are/i, severity: \"critical\", description: \"System prompt injection\" },\n { pattern: /\\[SYSTEM\\]/i, severity: \"high\", description: \"System tag injection\" },\n { pattern: /\\<\\/?system\\>/i, severity: \"high\", description: \"System XML tag injection\" },\n { pattern: /do\\s+not\\s+follow\\s+(your\\s+)?(rules|guidelines)/i, severity: \"critical\", description: \"Rule override attempt\" },\n { pattern: /pretend\\s+(that\\s+)?you\\s+(don't|do\\s+not)\\s+have/i, severity: \"high\", description: \"Capability override attempt\" },\n { pattern: /\\bDAN\\b.*\\bmode\\b/i, severity: \"critical\", description: \"DAN jailbreak attempt\" },\n { pattern: /jailbreak/i, severity: \"critical\", description: \"Explicit jailbreak reference\" },\n];\n\nexport const detectInjection = (text: string): Effect.Effect<DetectionResult, never> =>\n Effect.sync(() => {\n for (const { pattern, severity, description } of INJECTION_PATTERNS) {\n if (pattern.test(text)) {\n return {\n detected: true,\n type: \"prompt-injection\" as ViolationType,\n severity,\n message: `Prompt injection detected: ${description}`,\n details: `Matched pattern: ${pattern.source}`,\n };\n }\n }\n return {\n detected: false,\n type: \"prompt-injection\" as ViolationType,\n severity: \"low\" as Severity,\n message: \"No injection detected\",\n };\n });\n","import { Effect } from \"effect\";\nimport type { ViolationType, Severity } from \"../types.js\";\nimport type { DetectionResult } from \"./injection-detector.js\";\n\n// PII patterns\nconst PII_PATTERNS: Array<{ pattern: RegExp; label: string; severity: Severity }> = [\n { pattern: /\\b\\d{3}-\\d{2}-\\d{4}\\b/, label: \"SSN\", severity: \"critical\" },\n { pattern: /\\b\\d{9}\\b/, label: \"SSN (no dashes)\", severity: \"high\" },\n { pattern: /\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}\\b/, label: \"Email\", severity: \"medium\" },\n { pattern: /\\b\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}\\b/, label: \"Credit card\", severity: \"critical\" },\n { pattern: /\\b(?:\\+?1[-.\\s]?)?\\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4}\\b/, label: \"Phone number\", severity: \"medium\" },\n { pattern: /\\b\\d{1,5}\\s\\w+\\s(?:Street|St|Avenue|Ave|Road|Rd|Drive|Dr|Lane|Ln|Boulevard|Blvd)\\b/i, label: \"Street address\", severity: \"high\" },\n { pattern: /\\b[A-Z]{1,2}\\d{1,2}\\s?\\d[A-Z]{2}\\b/, label: \"UK postcode\", severity: \"medium\" },\n { pattern: /\\bpassword\\s*[:=]\\s*\\S+/i, label: \"Password\", severity: \"critical\" },\n { pattern: /\\b(sk-|sk_live_|pk_live_|sk_test_)\\S{20,}/i, label: \"API key\", severity: \"critical\" },\n];\n\nexport const detectPii = (text: string): Effect.Effect<DetectionResult, never> =>\n Effect.sync(() => {\n const found: string[] = [];\n let maxSeverity: Severity = \"low\";\n const severityOrder: Severity[] = [\"low\", \"medium\", \"high\", \"critical\"];\n\n for (const { pattern, label, severity } of PII_PATTERNS) {\n if (pattern.test(text)) {\n found.push(label);\n if (severityOrder.indexOf(severity) > severityOrder.indexOf(maxSeverity)) {\n maxSeverity = severity;\n }\n }\n }\n\n if (found.length > 0) {\n return {\n detected: true,\n type: \"pii-detected\" as ViolationType,\n severity: maxSeverity,\n message: `PII detected: ${found.join(\", \")}`,\n details: `Found ${found.length} PII pattern(s)`,\n };\n }\n\n return {\n detected: false,\n type: \"pii-detected\" as ViolationType,\n severity: \"low\" as Severity,\n message: \"No PII detected\",\n };\n });\n","import { Effect } from \"effect\";\nimport type { ViolationType, Severity } from \"../types.js\";\nimport type { DetectionResult } from \"./injection-detector.js\";\n\n// Toxicity keyword categories (simplified blocklist)\nconst TOXIC_PATTERNS: Array<{ pattern: RegExp; category: string; severity: Severity }> = [\n { pattern: /\\b(kill|murder|assassinate)\\s+(yourself|himself|herself|themselves|someone|people)\\b/i, severity: \"critical\", category: \"violence\" },\n { pattern: /\\bhow\\s+to\\s+(make|build|create)\\s+(a\\s+)?(bomb|weapon|explosive)/i, severity: \"critical\", category: \"weapons\" },\n { pattern: /\\b(hack|exploit|breach)\\s+(into|a|the)\\s/i, severity: \"high\", category: \"hacking\" },\n { pattern: /\\b(steal|rob|burglarize)\\s/i, severity: \"high\", category: \"theft\" },\n { pattern: /\\b(hate|despise)\\s+(all\\s+)?(women|men|blacks|whites|jews|muslims|christians)/i, severity: \"critical\", category: \"hate-speech\" },\n { pattern: /\\b(racial|ethnic)\\s+(slur|epithet)/i, severity: \"critical\", category: \"hate-speech\" },\n { pattern: /\\bself[- ]?harm\\b/i, severity: \"critical\", category: \"self-harm\" },\n { pattern: /\\bsuicide\\s+(method|how|way)/i, severity: \"critical\", category: \"self-harm\" },\n];\n\nexport const detectToxicity = (\n text: string,\n customBlocklist: readonly string[] = [],\n): Effect.Effect<DetectionResult, never> =>\n Effect.sync(() => {\n // Check built-in patterns\n for (const { pattern, category, severity } of TOXIC_PATTERNS) {\n if (pattern.test(text)) {\n return {\n detected: true,\n type: \"toxicity\" as ViolationType,\n severity,\n message: `Toxic content detected: ${category}`,\n details: `Category: ${category}`,\n };\n }\n }\n\n // Check custom blocklist\n const lower = text.toLowerCase();\n for (const word of customBlocklist) {\n if (lower.includes(word.toLowerCase())) {\n return {\n detected: true,\n type: \"toxicity\" as ViolationType,\n severity: \"high\" as Severity,\n message: `Blocked term detected: \"${word}\"`,\n details: `Custom blocklist match`,\n };\n }\n }\n\n return {\n detected: false,\n type: \"toxicity\" as ViolationType,\n severity: \"low\" as Severity,\n message: \"No toxic content detected\",\n };\n });\n","import { Effect } from \"effect\";\nimport type { AgentContract, ViolationType, Severity } from \"../types.js\";\nimport type { DetectionResult } from \"../detectors/injection-detector.js\";\n\nexport const checkContract = (\n text: string,\n contract: AgentContract,\n): Effect.Effect<DetectionResult, never> =>\n Effect.sync(() => {\n const lower = text.toLowerCase();\n\n // Check denied topics\n for (const topic of contract.deniedTopics) {\n if (lower.includes(topic.toLowerCase())) {\n return {\n detected: true,\n type: \"contract-violation\" as ViolationType,\n severity: \"high\" as Severity,\n message: `Denied topic referenced: \"${topic}\"`,\n details: `Contract prohibits this topic`,\n };\n }\n }\n\n // Check denied actions\n for (const action of contract.deniedActions) {\n if (lower.includes(action.toLowerCase())) {\n return {\n detected: true,\n type: \"scope-violation\" as ViolationType,\n severity: \"high\" as Severity,\n message: `Denied action referenced: \"${action}\"`,\n details: `Contract prohibits this action`,\n };\n }\n }\n\n // Check output length\n if (contract.maxOutputLength !== undefined && text.length > contract.maxOutputLength) {\n return {\n detected: true,\n type: \"contract-violation\" as ViolationType,\n severity: \"medium\" as Severity,\n message: `Output exceeds max length (${text.length} > ${contract.maxOutputLength})`,\n };\n }\n\n return {\n detected: false,\n type: \"contract-violation\" as ViolationType,\n severity: \"low\" as Severity,\n message: \"Contract check passed\",\n };\n });\n","import { Effect, Context, Layer } from \"effect\";\nimport type { GuardrailResult, GuardrailConfig } from \"./types.js\";\nimport { GuardrailError } from \"./errors.js\";\nimport { detectInjection } from \"./detectors/injection-detector.js\";\nimport { detectPii } from \"./detectors/pii-detector.js\";\nimport { detectToxicity } from \"./detectors/toxicity-detector.js\";\nimport { checkContract } from \"./contracts/agent-contract.js\";\n\n// ─── Service Tag ───\n\nexport class GuardrailService extends Context.Tag(\"GuardrailService\")<\n GuardrailService,\n {\n /** Check input text against all configured guardrails. */\n readonly check: (text: string) => Effect.Effect<GuardrailResult, GuardrailError>;\n\n /** Check output text (may have different rules). */\n readonly checkOutput: (text: string) => Effect.Effect<GuardrailResult, GuardrailError>;\n\n /** Get current config. */\n readonly getConfig: () => Effect.Effect<GuardrailConfig, never>;\n }\n>() {}\n\n// ─── Live Implementation ───\n\nexport const GuardrailServiceLive = (config: GuardrailConfig) =>\n Layer.succeed(GuardrailService, {\n check: (text) =>\n Effect.gen(function* () {\n const violations: Array<{ type: GuardrailResult[\"violations\"][number][\"type\"]; severity: GuardrailResult[\"violations\"][number][\"severity\"]; message: string; details?: string }> = [];\n\n if (config.enableInjectionDetection) {\n const result = yield* detectInjection(text);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.enablePiiDetection) {\n const result = yield* detectPii(text);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.enableToxicityDetection) {\n const result = yield* detectToxicity(text, config.customBlocklist ?? []);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.contract) {\n const result = yield* checkContract(text, config.contract);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n const score = violations.length === 0 ? 1 : Math.max(0, 1 - violations.length * 0.25);\n\n return {\n passed: violations.length === 0,\n violations: [...violations],\n score,\n checkedAt: new Date(),\n } satisfies GuardrailResult;\n }),\n\n checkOutput: (text) =>\n Effect.gen(function* () {\n const violations: Array<{ type: GuardrailResult[\"violations\"][number][\"type\"]; severity: GuardrailResult[\"violations\"][number][\"severity\"]; message: string; details?: string }> = [];\n\n // Output checks: PII and toxicity (not injection)\n if (config.enablePiiDetection) {\n const result = yield* detectPii(text);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.enableToxicityDetection) {\n const result = yield* detectToxicity(text, config.customBlocklist ?? []);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.contract) {\n const result = yield* checkContract(text, config.contract);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n const score = violations.length === 0 ? 1 : Math.max(0, 1 - violations.length * 0.25);\n\n return {\n passed: violations.length === 0,\n violations: [...violations],\n score,\n checkedAt: new Date(),\n } satisfies GuardrailResult;\n }),\n\n getConfig: () => Effect.succeed(config),\n });\n","import type { GuardrailConfig } from \"./types.js\";\nimport { defaultGuardrailConfig } from \"./types.js\";\nimport { GuardrailServiceLive } from \"./guardrail-service.js\";\n\nexport const createGuardrailsLayer = (config?: Partial<GuardrailConfig>) =>\n GuardrailServiceLive({\n ...defaultGuardrailConfig,\n ...config,\n });\n"],"mappings":";AAAA,SAAS,cAAc;AAIhB,IAAM,gBAAgB,OAAO;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKO,IAAM,WAAW,OAAO,QAAQ,OAAO,UAAU,QAAQ,UAAU;AAKnE,IAAM,wBAAwB,OAAO,OAAO;AAAA,EACjD,QAAQ,OAAO;AAAA,EACf,YAAY,OAAO;AAAA,IACjB,OAAO,OAAO;AAAA,MACZ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS,OAAO;AAAA,MAChB,SAAS,OAAO,SAAS,OAAO,MAAM;AAAA,IACxC,CAAC;AAAA,EACH;AAAA,EACA,OAAO,OAAO;AAAA;AAAA,EACd,WAAW,OAAO;AACpB,CAAC;AAKM,IAAM,sBAAsB,OAAO,OAAO;AAAA,EAC/C,eAAe,OAAO,MAAM,OAAO,MAAM;AAAA,EACzC,cAAc,OAAO,MAAM,OAAO,MAAM;AAAA,EACxC,gBAAgB,OAAO,MAAM,OAAO,MAAM;AAAA,EAC1C,eAAe,OAAO,MAAM,OAAO,MAAM;AAAA,EACzC,iBAAiB,OAAO,SAAS,OAAO,MAAM;AAAA,EAC9C,mBAAmB,OAAO,SAAS,OAAO,OAAO;AACnD,CAAC;AAKM,IAAM,wBAAwB,OAAO,OAAO;AAAA,EACjD,0BAA0B,OAAO;AAAA,EACjC,oBAAoB,OAAO;AAAA,EAC3B,yBAAyB,OAAO;AAAA,EAChC,UAAU,OAAO,SAAS,m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AC;;;AC1II,IAAM,wBAAwB,CAAC,WACpC,qBAAqB;AAAA,EACnB,GAAG;AAAA,EACH,GAAG;AACL,CAAC;","names":["Effect","Effect","Effect","Effect","Effect"]}
1
+ {"version":3,"sources":["../src/types.ts","../src/errors.ts","../src/detectors/injection-detector.ts","../src/detectors/pii-detector.ts","../src/detectors/toxicity-detector.ts","../src/contracts/agent-contract.ts","../src/kill-switch.ts","../src/behavioral-contracts.ts","../src/guardrail-service.ts","../src/runtime.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n// ─── Violation Type ───\n\nexport const ViolationType = Schema.Literal(\n \"prompt-injection\",\n \"pii-detected\",\n \"toxicity\",\n \"scope-violation\",\n \"contract-violation\",\n);\nexport type ViolationType = typeof ViolationType.Type;\n\n// ─── Severity ───\n\nexport const Severity = Schema.Literal(\"low\", \"medium\", \"high\", \"critical\");\nexport type Severity = typeof Severity.Type;\n\n// ─── Guardrail Result ───\n\nexport const GuardrailResultSchema = Schema.Struct({\n passed: Schema.Boolean,\n violations: Schema.Array(\n Schema.Struct({\n type: ViolationType,\n severity: Severity,\n message: Schema.String,\n details: Schema.optional(Schema.String),\n }),\n ),\n score: Schema.Number, // 0-1, 1 = fully safe\n checkedAt: Schema.DateFromSelf,\n});\nexport type GuardrailResult = typeof GuardrailResultSchema.Type;\n\n// ─── Agent Contract ───\n\nexport const AgentContractSchema = Schema.Struct({\n allowedTopics: Schema.Array(Schema.String),\n deniedTopics: Schema.Array(Schema.String),\n allowedActions: Schema.Array(Schema.String),\n deniedActions: Schema.Array(Schema.String),\n maxOutputLength: Schema.optional(Schema.Number),\n requireDisclosure: Schema.optional(Schema.Boolean),\n});\nexport type AgentContract = typeof AgentContractSchema.Type;\n\n// ─── Guardrail Config ───\n\nexport const GuardrailConfigSchema = Schema.Struct({\n enableInjectionDetection: Schema.Boolean,\n enablePiiDetection: Schema.Boolean,\n enableToxicityDetection: Schema.Boolean,\n contract: Schema.optional(AgentContractSchema),\n customBlocklist: Schema.optional(Schema.Array(Schema.String)),\n});\nexport type GuardrailConfig = typeof GuardrailConfigSchema.Type;\n\nexport const defaultGuardrailConfig: GuardrailConfig = {\n enableInjectionDetection: true,\n enablePiiDetection: true,\n enableToxicityDetection: true,\n};\n","import { Data } from \"effect\";\n\nexport class GuardrailError extends Data.TaggedError(\"GuardrailError\")<{\n readonly message: string;\n readonly cause?: unknown;\n}> {}\n\nexport class ViolationError extends Data.TaggedError(\"ViolationError\")<{\n readonly message: string;\n readonly violationType: string;\n readonly severity: string;\n}> {}\n","import { Effect } from \"effect\";\nimport type { ViolationType, Severity } from \"../types.js\";\n\nexport interface DetectionResult {\n readonly detected: boolean;\n readonly type: ViolationType;\n readonly severity: Severity;\n readonly message: string;\n readonly details?: string;\n}\n\n// Common prompt injection patterns\nconst INJECTION_PATTERNS: Array<{ pattern: RegExp; severity: Severity; description: string }> = [\n { pattern: /ignore\\s+(all\\s+)?previous\\s+(instructions|prompts)/i, severity: \"critical\", description: \"Instruction override attempt\" },\n { pattern: /disregard\\s+(all\\s+)?previous/i, severity: \"critical\", description: \"Instruction disregard attempt\" },\n { pattern: /forget\\s+(all\\s+)?(your\\s+)?previous/i, severity: \"high\", description: \"Memory reset attempt\" },\n { pattern: /you\\s+are\\s+now\\s+a/i, severity: \"high\", description: \"Role reassignment attempt\" },\n { pattern: /act\\s+as\\s+(if\\s+)?(you\\s+are|a)\\s/i, severity: \"medium\", description: \"Role play injection\" },\n { pattern: /system\\s*:\\s*you\\s+are/i, severity: \"critical\", description: \"System prompt injection\" },\n { pattern: /\\[SYSTEM\\]/i, severity: \"high\", description: \"System tag injection\" },\n { pattern: /\\<\\/?system\\>/i, severity: \"high\", description: \"System XML tag injection\" },\n { pattern: /do\\s+not\\s+follow\\s+(your\\s+)?(rules|guidelines)/i, severity: \"critical\", description: \"Rule override attempt\" },\n { pattern: /pretend\\s+(that\\s+)?you\\s+(don't|do\\s+not)\\s+have/i, severity: \"high\", description: \"Capability override attempt\" },\n { pattern: /\\bDAN\\b.*\\bmode\\b/i, severity: \"critical\", description: \"DAN jailbreak attempt\" },\n { pattern: /jailbreak/i, severity: \"critical\", description: \"Explicit jailbreak reference\" },\n];\n\nexport const detectInjection = (text: string): Effect.Effect<DetectionResult, never> =>\n Effect.sync(() => {\n for (const { pattern, severity, description } of INJECTION_PATTERNS) {\n if (pattern.test(text)) {\n return {\n detected: true,\n type: \"prompt-injection\" as ViolationType,\n severity,\n message: `Prompt injection detected: ${description}`,\n details: `Matched pattern: ${pattern.source}`,\n };\n }\n }\n return {\n detected: false,\n type: \"prompt-injection\" as ViolationType,\n severity: \"low\" as Severity,\n message: \"No injection detected\",\n };\n });\n","import { Effect } from \"effect\";\nimport type { ViolationType, Severity } from \"../types.js\";\nimport type { DetectionResult } from \"./injection-detector.js\";\n\n// PII patterns\nconst PII_PATTERNS: Array<{ pattern: RegExp; label: string; severity: Severity }> = [\n { pattern: /\\b\\d{3}-\\d{2}-\\d{4}\\b/, label: \"SSN\", severity: \"critical\" },\n { pattern: /\\b\\d{9}\\b/, label: \"SSN (no dashes)\", severity: \"high\" },\n { pattern: /\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}\\b/, label: \"Email\", severity: \"medium\" },\n { pattern: /\\b\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}\\b/, label: \"Credit card\", severity: \"critical\" },\n { pattern: /\\b(?:\\+?1[-.\\s]?)?\\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4}\\b/, label: \"Phone number\", severity: \"medium\" },\n { pattern: /\\b\\d{1,5}\\s\\w+\\s(?:Street|St|Avenue|Ave|Road|Rd|Drive|Dr|Lane|Ln|Boulevard|Blvd)\\b/i, label: \"Street address\", severity: \"high\" },\n { pattern: /\\b[A-Z]{1,2}\\d{1,2}\\s?\\d[A-Z]{2}\\b/, label: \"UK postcode\", severity: \"medium\" },\n { pattern: /\\bpassword\\s*[:=]\\s*\\S+/i, label: \"Password\", severity: \"critical\" },\n { pattern: /\\b(sk-|sk_live_|pk_live_|sk_test_)\\S{20,}/i, label: \"API key\", severity: \"critical\" },\n];\n\nexport const detectPii = (text: string): Effect.Effect<DetectionResult, never> =>\n Effect.sync(() => {\n const found: string[] = [];\n let maxSeverity: Severity = \"low\";\n const severityOrder: Severity[] = [\"low\", \"medium\", \"high\", \"critical\"];\n\n for (const { pattern, label, severity } of PII_PATTERNS) {\n if (pattern.test(text)) {\n found.push(label);\n if (severityOrder.indexOf(severity) > severityOrder.indexOf(maxSeverity)) {\n maxSeverity = severity;\n }\n }\n }\n\n if (found.length > 0) {\n return {\n detected: true,\n type: \"pii-detected\" as ViolationType,\n severity: maxSeverity,\n message: `PII detected: ${found.join(\", \")}`,\n details: `Found ${found.length} PII pattern(s)`,\n };\n }\n\n return {\n detected: false,\n type: \"pii-detected\" as ViolationType,\n severity: \"low\" as Severity,\n message: \"No PII detected\",\n };\n });\n","import { Effect } from \"effect\";\nimport type { ViolationType, Severity } from \"../types.js\";\nimport type { DetectionResult } from \"./injection-detector.js\";\n\n// Toxicity keyword categories (simplified blocklist)\nconst TOXIC_PATTERNS: Array<{ pattern: RegExp; category: string; severity: Severity }> = [\n { pattern: /\\b(kill|murder|assassinate)\\s+(yourself|himself|herself|themselves|someone|people)\\b/i, severity: \"critical\", category: \"violence\" },\n { pattern: /\\bhow\\s+to\\s+(make|build|create)\\s+(a\\s+)?(bomb|weapon|explosive)/i, severity: \"critical\", category: \"weapons\" },\n { pattern: /\\b(hack|exploit|breach)\\s+(into|a|the)\\s/i, severity: \"high\", category: \"hacking\" },\n { pattern: /\\b(steal|rob|burglarize)\\s/i, severity: \"high\", category: \"theft\" },\n { pattern: /\\b(hate|despise)\\s+(all\\s+)?(women|men|blacks|whites|jews|muslims|christians)/i, severity: \"critical\", category: \"hate-speech\" },\n { pattern: /\\b(racial|ethnic)\\s+(slur|epithet)/i, severity: \"critical\", category: \"hate-speech\" },\n { pattern: /\\bself[- ]?harm\\b/i, severity: \"critical\", category: \"self-harm\" },\n { pattern: /\\bsuicide\\s+(method|how|way)/i, severity: \"critical\", category: \"self-harm\" },\n];\n\nexport const detectToxicity = (\n text: string,\n customBlocklist: readonly string[] = [],\n): Effect.Effect<DetectionResult, never> =>\n Effect.sync(() => {\n // Check built-in patterns\n for (const { pattern, category, severity } of TOXIC_PATTERNS) {\n if (pattern.test(text)) {\n return {\n detected: true,\n type: \"toxicity\" as ViolationType,\n severity,\n message: `Toxic content detected: ${category}`,\n details: `Category: ${category}`,\n };\n }\n }\n\n // Check custom blocklist\n const lower = text.toLowerCase();\n for (const word of customBlocklist) {\n if (lower.includes(word.toLowerCase())) {\n return {\n detected: true,\n type: \"toxicity\" as ViolationType,\n severity: \"high\" as Severity,\n message: `Blocked term detected: \"${word}\"`,\n details: `Custom blocklist match`,\n };\n }\n }\n\n return {\n detected: false,\n type: \"toxicity\" as ViolationType,\n severity: \"low\" as Severity,\n message: \"No toxic content detected\",\n };\n });\n","import { Effect } from \"effect\";\nimport type { AgentContract, ViolationType, Severity } from \"../types.js\";\nimport type { DetectionResult } from \"../detectors/injection-detector.js\";\n\nexport const checkContract = (\n text: string,\n contract: AgentContract,\n): Effect.Effect<DetectionResult, never> =>\n Effect.sync(() => {\n const lower = text.toLowerCase();\n\n // Check denied topics\n for (const topic of contract.deniedTopics) {\n if (lower.includes(topic.toLowerCase())) {\n return {\n detected: true,\n type: \"contract-violation\" as ViolationType,\n severity: \"high\" as Severity,\n message: `Denied topic referenced: \"${topic}\"`,\n details: `Contract prohibits this topic`,\n };\n }\n }\n\n // Check denied actions\n for (const action of contract.deniedActions) {\n if (lower.includes(action.toLowerCase())) {\n return {\n detected: true,\n type: \"scope-violation\" as ViolationType,\n severity: \"high\" as Severity,\n message: `Denied action referenced: \"${action}\"`,\n details: `Contract prohibits this action`,\n };\n }\n }\n\n // Check output length\n if (contract.maxOutputLength !== undefined && text.length > contract.maxOutputLength) {\n return {\n detected: true,\n type: \"contract-violation\" as ViolationType,\n severity: \"medium\" as Severity,\n message: `Output exceeds max length (${text.length} > ${contract.maxOutputLength})`,\n };\n }\n\n return {\n detected: false,\n type: \"contract-violation\" as ViolationType,\n severity: \"low\" as Severity,\n message: \"Contract check passed\",\n };\n });\n","import { Effect, Context, Layer, Ref, Deferred } from \"effect\";\nimport { EventBus } from \"@reactive-agents/core\";\n\n/**\n * KillSwitchService — emergency stop for agent execution.\n *\n * When triggered, the execution engine will halt at the next phase\n * transition and return a TaskResult with the kill reason.\n */\nexport class KillSwitchService extends Context.Tag(\"KillSwitchService\")<\n KillSwitchService,\n {\n /** Trigger the kill switch for an agent. Execution halts at next phase boundary. */\n readonly trigger: (agentId: string, reason: string) => Effect.Effect<void>;\n /** Check if the kill switch has been triggered for an agent. */\n readonly isTriggered: (agentId: string) => Effect.Effect<{ triggered: boolean; reason?: string }>;\n /** Clear the kill switch for an agent (re-enable execution). */\n readonly clear: (agentId: string) => Effect.Effect<void>;\n /** Trigger a global kill switch — halts ALL agents. */\n readonly triggerGlobal: (reason: string) => Effect.Effect<void>;\n /** Check if global kill switch is active. */\n readonly isGlobalTriggered: () => Effect.Effect<{ triggered: boolean; reason?: string }>;\n /** Clear the global kill switch. */\n readonly clearGlobal: () => Effect.Effect<void>;\n /** Pause agent execution at the next phase boundary (blocks until resume). */\n readonly pause: (agentId: string) => Effect.Effect<void>;\n /** Resume a paused agent. */\n readonly resume: (agentId: string) => Effect.Effect<void>;\n /** Signal agent to stop gracefully at the next phase boundary. */\n readonly stop: (agentId: string, reason: string) => Effect.Effect<void>;\n /** Immediately terminate agent (also triggers kill switch). */\n readonly terminate: (agentId: string, reason: string) => Effect.Effect<void>;\n /** Get the current lifecycle state for an agent. */\n readonly getLifecycle: (agentId: string) => Effect.Effect<\"running\" | \"paused\" | \"stopping\" | \"terminated\" | \"unknown\">;\n /**\n * If paused, block until resumed. Emits AgentPaused when blocking starts and\n * AgentResumed when unblocked — so events carry the real taskId from the\n * execution context rather than a synthetic \"lifecycle\" placeholder.\n * Returns \"stopping\" if stop() was called while paused, else \"ok\".\n */\n readonly waitIfPaused: (agentId: string, taskId: string) => Effect.Effect<\"ok\" | \"stopping\">;\n }\n>() {}\n\nexport const KillSwitchServiceLive = () =>\n Layer.effect(\n KillSwitchService,\n Effect.gen(function* () {\n const agentKills = yield* Ref.make<Map<string, string>>(new Map());\n const globalKill = yield* Ref.make<string | null>(null);\n const lifecycleRef = yield* Ref.make<Map<string, \"running\" | \"paused\" | \"stopping\" | \"terminated\">>(new Map());\n const pauseDeferreds = yield* Ref.make<Map<string, Deferred.Deferred<void>>>(new Map());\n\n // EventBus is optional — publish lifecycle events when available\n const ebOpt = yield* Effect.serviceOption(EventBus).pipe(\n Effect.catchAll(() => Effect.succeed({ _tag: \"None\" as const })),\n );\n const eb = ebOpt._tag === \"Some\" ? ebOpt.value : null;\n\n return KillSwitchService.of({\n trigger: (agentId, reason) =>\n Ref.update(agentKills, (m) => {\n const newMap = new Map(m);\n newMap.set(agentId, reason);\n return newMap;\n }),\n\n isTriggered: (agentId) =>\n Effect.gen(function* () {\n // Global takes precedence\n const globalReason = yield* Ref.get(globalKill);\n if (globalReason != null) {\n return { triggered: true, reason: globalReason };\n }\n const kills = yield* Ref.get(agentKills);\n const reason = kills.get(agentId);\n return reason != null\n ? { triggered: true, reason }\n : { triggered: false };\n }),\n\n clear: (agentId) =>\n Ref.update(agentKills, (m) => {\n const newMap = new Map(m);\n newMap.delete(agentId);\n return newMap;\n }),\n\n triggerGlobal: (reason) => Ref.set(globalKill, reason),\n\n isGlobalTriggered: () =>\n Effect.gen(function* () {\n const reason = yield* Ref.get(globalKill);\n return reason != null\n ? { triggered: true, reason }\n : { triggered: false };\n }),\n\n clearGlobal: () => Ref.set(globalKill, null),\n\n pause: (agentId) =>\n Effect.gen(function* () {\n const d = yield* Deferred.make<void>();\n yield* Ref.update(pauseDeferreds, (m) => {\n const n = new Map(m);\n n.set(agentId, d);\n return n;\n });\n yield* Ref.update(lifecycleRef, (m) => {\n const n = new Map(m);\n n.set(agentId, \"paused\");\n return n;\n });\n // AgentPaused is emitted from waitIfPaused() so it carries the real\n // taskId from the execution context and fires exactly when execution blocks.\n }),\n\n resume: (agentId) =>\n Effect.gen(function* () {\n const deferreds = yield* Ref.get(pauseDeferreds);\n const d = deferreds.get(agentId);\n if (d) {\n yield* Deferred.succeed(d, undefined);\n yield* Ref.update(pauseDeferreds, (m) => {\n const n = new Map(m);\n n.delete(agentId);\n return n;\n });\n }\n yield* Ref.update(lifecycleRef, (m) => {\n const n = new Map(m);\n n.set(agentId, \"running\");\n return n;\n });\n // AgentResumed is emitted from waitIfPaused() after the deferred resolves,\n // so it carries the real taskId and fires as execution actually unblocks.\n }),\n\n stop: (agentId, _reason) =>\n Ref.update(lifecycleRef, (m) => {\n const n = new Map(m);\n n.set(agentId, \"stopping\");\n return n;\n }),\n\n terminate: (agentId, reason) =>\n Effect.gen(function* () {\n yield* Ref.update(lifecycleRef, (m) => {\n const n = new Map(m);\n n.set(agentId, \"terminated\");\n return n;\n });\n yield* Ref.update(agentKills, (m) => {\n const n = new Map(m);\n n.set(agentId, reason);\n return n;\n });\n }),\n\n getLifecycle: (agentId) =>\n Ref.get(lifecycleRef).pipe(\n Effect.map((m) => (m.get(agentId) ?? \"unknown\") as \"running\" | \"paused\" | \"stopping\" | \"terminated\" | \"unknown\"),\n ),\n\n waitIfPaused: (agentId, taskId) =>\n Effect.gen(function* () {\n const lifecycle = yield* Ref.get(lifecycleRef).pipe(\n Effect.map((m) => m.get(agentId)),\n );\n if (lifecycle === \"paused\") {\n // Emit AgentPaused here — execution has reached a phase boundary and\n // is actually about to block, so the event carries the real taskId.\n if (eb) {\n yield* eb.publish({ _tag: \"AgentPaused\", agentId, taskId })\n .pipe(Effect.catchAll(() => Effect.void));\n }\n const deferreds = yield* Ref.get(pauseDeferreds);\n const d = deferreds.get(agentId);\n if (d) {\n yield* Deferred.await(d);\n }\n // Emit AgentResumed now — execution is actually continuing.\n if (eb) {\n yield* eb.publish({ _tag: \"AgentResumed\", agentId, taskId })\n .pipe(Effect.catchAll(() => Effect.void));\n }\n }\n const newLifecycle = yield* Ref.get(lifecycleRef).pipe(\n Effect.map((m) => m.get(agentId)),\n );\n return newLifecycle === \"stopping\" ? (\"stopping\" as const) : (\"ok\" as const);\n }),\n });\n }),\n );\n","import { Effect, Context, Layer, Schema } from \"effect\";\n\n// ─── Behavioral Contract Schema ───\n\nexport const BehavioralContractSchema = Schema.Struct({\n /** Tools the agent is NOT allowed to call. */\n deniedTools: Schema.optional(Schema.Array(Schema.String)),\n /** If set, ONLY these tools may be called (allowlist). */\n allowedTools: Schema.optional(Schema.Array(Schema.String)),\n /** Maximum number of tool calls per execution. */\n maxToolCalls: Schema.optional(Schema.Number),\n /** Maximum iterations before forced halt. */\n maxIterations: Schema.optional(Schema.Number),\n /** Maximum output length in characters. */\n maxOutputLength: Schema.optional(Schema.Number),\n /** Topics the agent must not address. */\n deniedTopics: Schema.optional(Schema.Array(Schema.String)),\n /** If true, agent must disclose it is an AI. */\n requireDisclosure: Schema.optional(Schema.Boolean),\n});\nexport type BehavioralContract = typeof BehavioralContractSchema.Type;\n\n// ─── Violation Types ───\n\nexport interface ContractViolation {\n readonly rule: string;\n readonly message: string;\n readonly severity: \"warning\" | \"block\";\n}\n\n// ─── Service ───\n\nexport class BehavioralContractService extends Context.Tag(\"BehavioralContractService\")<\n BehavioralContractService,\n {\n /** Check if a tool call is allowed by the contract. */\n readonly checkToolCall: (toolName: string, toolCallCount: number) => Effect.Effect<ContractViolation | null>;\n /** Check if output complies with the contract. */\n readonly checkOutput: (output: string) => Effect.Effect<ContractViolation | null>;\n /** Check iteration count against contract. */\n readonly checkIteration: (iteration: number) => Effect.Effect<ContractViolation | null>;\n /** Get the active contract. */\n readonly getContract: () => Effect.Effect<BehavioralContract>;\n }\n>() {}\n\nexport const BehavioralContractServiceLive = (contract: BehavioralContract) =>\n Layer.succeed(BehavioralContractService, {\n checkToolCall: (toolName, toolCallCount) =>\n Effect.sync(() => {\n // Check denied tools\n if (contract.deniedTools?.some((d) => d.toLowerCase() === toolName.toLowerCase())) {\n return {\n rule: \"denied-tool\",\n message: `Tool \"${toolName}\" is not allowed by behavioral contract`,\n severity: \"block\" as const,\n };\n }\n\n // Check allowed tools (allowlist)\n if (contract.allowedTools && !contract.allowedTools.some((a) => a.toLowerCase() === toolName.toLowerCase())) {\n return {\n rule: \"tool-not-in-allowlist\",\n message: `Tool \"${toolName}\" is not in the allowed tools list`,\n severity: \"block\" as const,\n };\n }\n\n // Check max tool calls\n if (contract.maxToolCalls != null && toolCallCount >= contract.maxToolCalls) {\n return {\n rule: \"max-tool-calls\",\n message: `Tool call limit reached (${contract.maxToolCalls})`,\n severity: \"block\" as const,\n };\n }\n\n return null;\n }),\n\n checkOutput: (output) =>\n Effect.sync(() => {\n // Check max output length\n if (contract.maxOutputLength != null && output.length > contract.maxOutputLength) {\n return {\n rule: \"max-output-length\",\n message: `Output exceeds maximum length (${output.length} > ${contract.maxOutputLength})`,\n severity: \"block\" as const,\n };\n }\n\n // Check denied topics\n if (contract.deniedTopics) {\n const lower = output.toLowerCase();\n for (const topic of contract.deniedTopics) {\n if (lower.includes(topic.toLowerCase())) {\n return {\n rule: \"denied-topic\",\n message: `Output references denied topic: \"${topic}\"`,\n severity: \"block\" as const,\n };\n }\n }\n }\n\n return null;\n }),\n\n checkIteration: (iteration) =>\n Effect.sync(() => {\n if (contract.maxIterations != null && iteration > contract.maxIterations) {\n return {\n rule: \"max-iterations\",\n message: `Iteration ${iteration} exceeds contract limit of ${contract.maxIterations}`,\n severity: \"block\" as const,\n };\n }\n return null;\n }),\n\n getContract: () => Effect.succeed(contract),\n });\n","import { Effect, Context, Layer } from \"effect\";\nimport type { GuardrailResult, GuardrailConfig } from \"./types.js\";\nimport { GuardrailError } from \"./errors.js\";\nimport { detectInjection } from \"./detectors/injection-detector.js\";\nimport { detectPii } from \"./detectors/pii-detector.js\";\nimport { detectToxicity } from \"./detectors/toxicity-detector.js\";\nimport { checkContract } from \"./contracts/agent-contract.js\";\n\n// ─── Service Tag ───\n\nexport class GuardrailService extends Context.Tag(\"GuardrailService\")<\n GuardrailService,\n {\n /** Check input text against all configured guardrails. */\n readonly check: (text: string) => Effect.Effect<GuardrailResult, GuardrailError>;\n\n /** Check output text (may have different rules). */\n readonly checkOutput: (text: string) => Effect.Effect<GuardrailResult, GuardrailError>;\n\n /** Get current config. */\n readonly getConfig: () => Effect.Effect<GuardrailConfig, never>;\n }\n>() {}\n\n// ─── Live Implementation ───\n\nexport const GuardrailServiceLive = (config: GuardrailConfig) =>\n Layer.succeed(GuardrailService, {\n check: (text) =>\n Effect.gen(function* () {\n const violations: Array<{ type: GuardrailResult[\"violations\"][number][\"type\"]; severity: GuardrailResult[\"violations\"][number][\"severity\"]; message: string; details?: string }> = [];\n\n if (config.enableInjectionDetection) {\n const result = yield* detectInjection(text);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.enablePiiDetection) {\n const result = yield* detectPii(text);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.enableToxicityDetection) {\n const result = yield* detectToxicity(text, config.customBlocklist ?? []);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.contract) {\n const result = yield* checkContract(text, config.contract);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n const score = violations.length === 0 ? 1 : Math.max(0, 1 - violations.length * 0.25);\n\n return {\n passed: violations.length === 0,\n violations: [...violations],\n score,\n checkedAt: new Date(),\n } satisfies GuardrailResult;\n }),\n\n checkOutput: (text) =>\n Effect.gen(function* () {\n const violations: Array<{ type: GuardrailResult[\"violations\"][number][\"type\"]; severity: GuardrailResult[\"violations\"][number][\"severity\"]; message: string; details?: string }> = [];\n\n // Output checks: PII and toxicity (not injection)\n if (config.enablePiiDetection) {\n const result = yield* detectPii(text);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.enableToxicityDetection) {\n const result = yield* detectToxicity(text, config.customBlocklist ?? []);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n if (config.contract) {\n const result = yield* checkContract(text, config.contract);\n if (result.detected) {\n violations.push({\n type: result.type,\n severity: result.severity,\n message: result.message,\n details: result.details,\n });\n }\n }\n\n const score = violations.length === 0 ? 1 : Math.max(0, 1 - violations.length * 0.25);\n\n return {\n passed: violations.length === 0,\n violations: [...violations],\n score,\n checkedAt: new Date(),\n } satisfies GuardrailResult;\n }),\n\n getConfig: () => Effect.succeed(config),\n });\n","import type { GuardrailConfig } from \"./types.js\";\nimport { defaultGuardrailConfig } from \"./types.js\";\nimport { GuardrailServiceLive } from \"./guardrail-service.js\";\n\nexport const createGuardrailsLayer = (config?: Partial<GuardrailConfig>) =>\n GuardrailServiceLive({\n ...defaultGuardrailConfig,\n ...config,\n });\n"],"mappings":";AAAA,SAAS,cAAc;AAIhB,IAAM,gBAAgB,OAAO;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKO,IAAM,WAAW,OAAO,QAAQ,OAAO,UAAU,QAAQ,UAAU;AAKnE,IAAM,wBAAwB,OAAO,OAAO;AAAA,EACjD,QAAQ,OAAO;AAAA,EACf,YAAY,OAAO;AAAA,IACjB,OAAO,OAAO;AAAA,MACZ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS,OAAO;AAAA,MAChB,SAAS,OAAO,SAAS,OAAO,MAAM;AAAA,IACxC,CAAC;AAAA,EACH;AAAA,EACA,OAAO,OAAO;AAAA;AAAA,EACd,WAAW,OAAO;AACpB,CAAC;AAKM,IAAM,sBAAsB,OAAO,OAAO;AAAA,EAC/C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OAAO;AAAA,UAChB,SAAS,OAAO;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAEA,UAAM,QAAQ,WAAW,WAAW,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI,WAAW,SAAS,IAAI;AAEpF,WAAO;AAAA,MACL,QAAQ,WAAW,WAAW;AAAA,MAC9B,YAAY,CAAC,GAAG,UAAU;AAAA,MAC1B;AAAA,MACA,WAAW,oBAAI,KAAK;AAAA,IACtB;AAAA,EACF,CAAC;AAAA,EAEH,WAAW,MAAMA,QAAO,QAAQ,MAAM;AACxC,CAAC;;;AC1II,IAAM,wBAAwB,CAAC,WACpC,qBAAqB;AAAA,EACnB,GAAG;AAAA,EACH,GAAG;AACL,CAAC;","names":["Effect","Effect","Effect","Effect","Effect","Context","Layer","Schema","Effect","Context","Layer","Context","Layer","Effect"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactive-agents/guardrails",
3
- "version": "0.1.0",
3
+ "version": "0.5.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "effect": "^3.10.0",
15
- "@reactive-agents/core": "0.1.0",
16
- "@reactive-agents/llm-provider": "0.1.0"
15
+ "@reactive-agents/core": "0.2.0",
16
+ "@reactive-agents/llm-provider": "0.5.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "typescript": "^5.7.0",