agent-contracts 0.12.1 → 0.12.3

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,7 @@ declare const AgentSchema: z.ZodObject<{
78
78
  target: z.ZodString;
79
79
  required: z.ZodBoolean;
80
80
  }, z.core.$loose>>>;
81
+ guardrails: z.ZodOptional<z.ZodArray<z.ZodString>>;
81
82
  }, z.core.$loose>;
82
83
  type Agent = z.infer<typeof AgentSchema>;
83
84
 
@@ -91,6 +92,7 @@ declare const ArtifactSchema: z.ZodObject<{
91
92
  states: z.ZodArray<z.ZodString>;
92
93
  required_validations: z.ZodDefault<z.ZodArray<z.ZodString>>;
93
94
  visibility: z.ZodOptional<z.ZodString>;
95
+ guardrails: z.ZodOptional<z.ZodArray<z.ZodString>>;
94
96
  }, z.core.$loose>;
95
97
  type Artifact = z.infer<typeof ArtifactSchema>;
96
98
 
@@ -285,6 +287,7 @@ declare const DslSchema: z.ZodObject<{
285
287
  target: z.ZodString;
286
288
  required: z.ZodBoolean;
287
289
  }, z.core.$loose>>>;
290
+ guardrails: z.ZodOptional<z.ZodArray<z.ZodString>>;
288
291
  }, z.core.$loose>>>;
289
292
  tasks: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
290
293
  description: z.ZodString;
@@ -334,6 +337,7 @@ declare const DslSchema: z.ZodObject<{
334
337
  }>;
335
338
  }, z.core.$loose>>>;
336
339
  validations: z.ZodDefault<z.ZodArray<z.ZodString>>;
340
+ guardrails: z.ZodOptional<z.ZodArray<z.ZodString>>;
337
341
  }, z.core.$loose>>>;
338
342
  artifacts: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
339
343
  type: z.ZodString;
@@ -345,6 +349,7 @@ declare const DslSchema: z.ZodObject<{
345
349
  states: z.ZodArray<z.ZodString>;
346
350
  required_validations: z.ZodDefault<z.ZodArray<z.ZodString>>;
347
351
  visibility: z.ZodOptional<z.ZodString>;
352
+ guardrails: z.ZodOptional<z.ZodArray<z.ZodString>>;
348
353
  }, z.core.$loose>>>;
349
354
  tools: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
350
355
  kind: z.ZodString;
@@ -360,6 +365,7 @@ declare const DslSchema: z.ZodObject<{
360
365
  writes: z.ZodDefault<z.ZodArray<z.ZodString>>;
361
366
  purpose: z.ZodOptional<z.ZodString>;
362
367
  }, z.core.$strip>>>;
368
+ guardrails: z.ZodOptional<z.ZodArray<z.ZodString>>;
363
369
  }, z.core.$loose>>>;
364
370
  validations: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
365
371
  target_artifact: z.ZodString;
@@ -721,6 +727,7 @@ declare const TaskSchema: z.ZodObject<{
721
727
  }>;
722
728
  }, z.core.$loose>>>;
723
729
  validations: z.ZodDefault<z.ZodArray<z.ZodString>>;
730
+ guardrails: z.ZodOptional<z.ZodArray<z.ZodString>>;
724
731
  }, z.core.$loose>;
725
732
  type Task = z.infer<typeof TaskSchema>;
726
733
 
@@ -746,6 +753,7 @@ declare const ToolSchema: z.ZodObject<{
746
753
  writes: z.ZodDefault<z.ZodArray<z.ZodString>>;
747
754
  purpose: z.ZodOptional<z.ZodString>;
748
755
  }, z.core.$strip>>>;
756
+ guardrails: z.ZodOptional<z.ZodArray<z.ZodString>>;
749
757
  }, z.core.$loose>;
750
758
  type Tool = z.infer<typeof ToolSchema>;
751
759
 
@@ -1111,6 +1119,15 @@ interface SystemContext {
1111
1119
  bindings?: SoftwareBinding[];
1112
1120
  [key: string]: unknown;
1113
1121
  }
1122
+ interface EntityGuardrailEntry {
1123
+ guardrail_id: string;
1124
+ description: string;
1125
+ rationale?: string;
1126
+ tags: string[];
1127
+ source: "entity" | "scope" | "both";
1128
+ severity?: string;
1129
+ action?: string;
1130
+ }
1114
1131
  interface PerTaskContext {
1115
1132
  task: Task & {
1116
1133
  id: string;
@@ -1118,6 +1135,7 @@ interface PerTaskContext {
1118
1135
  targetAgent: (Agent & {
1119
1136
  id: string;
1120
1137
  }) | null;
1138
+ relatedGuardrails: EntityGuardrailEntry[];
1121
1139
  dsl: Dsl;
1122
1140
  [key: string]: unknown;
1123
1141
  }
@@ -1131,6 +1149,7 @@ interface PerArtifactContext {
1131
1149
  consumerAgents: Dsl["agents"];
1132
1150
  editorAgents: Dsl["agents"];
1133
1151
  createdInWorkflows: string[];
1152
+ relatedGuardrails: EntityGuardrailEntry[];
1134
1153
  dsl: Dsl;
1135
1154
  [key: string]: unknown;
1136
1155
  }
@@ -1141,6 +1160,7 @@ interface PerToolContext {
1141
1160
  invokableAgents: Dsl["agents"];
1142
1161
  inputArtifactDetails: Dsl["artifacts"];
1143
1162
  outputArtifactDetails: Dsl["artifacts"];
1163
+ relatedGuardrails: EntityGuardrailEntry[];
1144
1164
  dsl: Dsl;
1145
1165
  [key: string]: unknown;
1146
1166
  }
@@ -1231,6 +1251,7 @@ interface PerAgentContext {
1231
1251
  relatedTools: Dsl["tools"];
1232
1252
  relatedHandoffTypes: Dsl["handoff_types"];
1233
1253
  mergedBehavior: MergedBehavioralSpec;
1254
+ relatedGuardrails: EntityGuardrailEntry[];
1234
1255
  dsl: Dsl;
1235
1256
  [key: string]: unknown;
1236
1257
  }
@@ -1239,6 +1260,8 @@ declare function buildSystemContext(dsl: Dsl, options?: {
1239
1260
  loadedBindings?: LoadedBinding[];
1240
1261
  activeGuardrailPolicy?: string;
1241
1262
  }): SystemContext;
1263
+ type EntityType = "agents" | "tasks" | "tools" | "artifacts";
1264
+ declare function resolveEffectiveGuardrails(dsl: Dsl, entityType: EntityType, entityId: string): EntityGuardrailEntry[];
1242
1265
  declare function buildTaskContext(dsl: Dsl, taskId: string): PerTaskContext;
1243
1266
  declare function buildArtifactContext(dsl: Dsl, artifactId: string): PerArtifactContext;
1244
1267
  declare function buildToolContext(dsl: Dsl, toolId: string): PerToolContext;
@@ -1330,4 +1353,4 @@ interface PathResolveResult {
1330
1353
  }
1331
1354
  declare function resolveBindingTargetPath(target: string, paths: Record<string, string>, bindingSoftware: string): PathResolveResult;
1332
1355
 
1333
- export { type Agent, type AgentContractsConfig, AgentContractsConfigSchema, AgentSchema, type AppendOperator, AppendOperatorSchema, type Artifact, ArtifactSchema, BaseResolveError, type BindingOutput, BindingOutputSchema, CONTEXT_TYPES, type Check, CheckSchema, type Command, CommandSchema, type Components, ComponentsSchema, ConfigLoadError, type ContextType, ContextTypeSchema, type DelegatableTaskView, type DiagnosticMessage, type DimensionResult, type Dsl, DslLoadError, DslSchema, type EscalationCriterion, EscalationCriterionSchema, type ExecutionStep, ExecutionStepSchema, type Extends, ExtendsSchema, type ExternalParticipant, type GenerateDiagnostic, type GenerateGuardrailsOptions, type GenerateResult, type GlobalContext, type Guardrail, type GuardrailGenerationContext, type GuardrailPolicy, type GuardrailPolicyRule, type GuardrailPolicyRuleEscalation, GuardrailPolicyRuleEscalationSchema, GuardrailPolicyRuleSchema, GuardrailPolicySchema, GuardrailSchema, type GuardrailScope, GuardrailScopeSchema, type HandoffType, HandoffTypeSchema, type InsertAfterOperator, InsertAfterOperatorSchema, type LintDiagnostic, type LintRule, type LoadResult, type LoadedBinding, type Matcher, MatcherSchema, MergeError, type MergeableRecord, type MergedBehavioralSpec, type PathResolveResult, type PerAgentContext, type PerArtifactContext, type PerGuardrailContext, type PerGuardrailPolicyContext, type PerHandoffTypeContext, type PerPolicyContext, type PerTaskContext, type PerToolContext, type PerValidationContext, type PerWorkflowContext, type Policy, PolicySchema, type PolicyWhen, PolicyWhenSchema, type PrependOperator, PrependOperatorSchema, type Prerequisite, PrerequisiteSchema, type ReferenceDiagnostic, type RemoveOperator, RemoveOperatorSchema, type RenderTarget, RenderTargetSchema, type ReplaceOperator, ReplaceOperatorSchema, type Reporting, ReportingSchema, type ResolveChecksResult, type ResolveResult, type ResolvedCheck, type ResolvedConfig, type ResolvedRenderTarget, type Retry, type Rule, RuleSchema, type SchemaValidationResult, type ScoreResult, type Severity, type SoftwareBinding, SoftwareBindingSchema, type System, type SystemContext, SystemSchema, type Task, TaskSchema, type Tool, ToolSchema, type Validation, ValidationSchema, type VersionLiteral, VersionLiteralSchema, type Workflow, WorkflowSchema, type WorkflowStep, WorkflowStepSchema, type XExtensionDecl, XExtensionDeclSchema, buildArtifactContext, buildGlobalContext, buildGuardrailContext, buildGuardrailPolicyContext, buildHandoffTypeContext, buildPerAgentContext, buildPolicyContext, buildSystemContext, buildTaskContext, buildToolContext, buildValidationContext, buildWorkflowContext, builtinRules, checkDriftFromConfig, checkReferences, expandDefaults, generateGuardrails, lint, loadBindings, loadConfig, loadDsl, mergeDsl, renderFromConfig, resolve, resolveAllOf, resolveBase, resolveBindingTargetPath, resolveChecks, resolveDslPath, score, spectralLint, validateHandoffSchemas, validateSchema, yamlReservedKeySafetyRule };
1356
+ export { type Agent, type AgentContractsConfig, AgentContractsConfigSchema, AgentSchema, type AppendOperator, AppendOperatorSchema, type Artifact, ArtifactSchema, BaseResolveError, type BindingOutput, BindingOutputSchema, CONTEXT_TYPES, type Check, CheckSchema, type Command, CommandSchema, type Components, ComponentsSchema, ConfigLoadError, type ContextType, ContextTypeSchema, type DelegatableTaskView, type DiagnosticMessage, type DimensionResult, type Dsl, DslLoadError, DslSchema, type EntityGuardrailEntry, type EscalationCriterion, EscalationCriterionSchema, type ExecutionStep, ExecutionStepSchema, type Extends, ExtendsSchema, type ExternalParticipant, type GenerateDiagnostic, type GenerateGuardrailsOptions, type GenerateResult, type GlobalContext, type Guardrail, type GuardrailGenerationContext, type GuardrailPolicy, type GuardrailPolicyRule, type GuardrailPolicyRuleEscalation, GuardrailPolicyRuleEscalationSchema, GuardrailPolicyRuleSchema, GuardrailPolicySchema, GuardrailSchema, type GuardrailScope, GuardrailScopeSchema, type HandoffType, HandoffTypeSchema, type InsertAfterOperator, InsertAfterOperatorSchema, type LintDiagnostic, type LintRule, type LoadResult, type LoadedBinding, type Matcher, MatcherSchema, MergeError, type MergeableRecord, type MergedBehavioralSpec, type PathResolveResult, type PerAgentContext, type PerArtifactContext, type PerGuardrailContext, type PerGuardrailPolicyContext, type PerHandoffTypeContext, type PerPolicyContext, type PerTaskContext, type PerToolContext, type PerValidationContext, type PerWorkflowContext, type Policy, PolicySchema, type PolicyWhen, PolicyWhenSchema, type PrependOperator, PrependOperatorSchema, type Prerequisite, PrerequisiteSchema, type ReferenceDiagnostic, type RemoveOperator, RemoveOperatorSchema, type RenderTarget, RenderTargetSchema, type ReplaceOperator, ReplaceOperatorSchema, type Reporting, ReportingSchema, type ResolveChecksResult, type ResolveResult, type ResolvedCheck, type ResolvedConfig, type ResolvedRenderTarget, type Retry, type Rule, RuleSchema, type SchemaValidationResult, type ScoreResult, type Severity, type SoftwareBinding, SoftwareBindingSchema, type System, type SystemContext, SystemSchema, type Task, TaskSchema, type Tool, ToolSchema, type Validation, ValidationSchema, type VersionLiteral, VersionLiteralSchema, type Workflow, WorkflowSchema, type WorkflowStep, WorkflowStepSchema, type XExtensionDecl, XExtensionDeclSchema, buildArtifactContext, buildGlobalContext, buildGuardrailContext, buildGuardrailPolicyContext, buildHandoffTypeContext, buildPerAgentContext, buildPolicyContext, buildSystemContext, buildTaskContext, buildToolContext, buildValidationContext, buildWorkflowContext, builtinRules, checkDriftFromConfig, checkReferences, expandDefaults, generateGuardrails, lint, loadBindings, loadConfig, loadDsl, mergeDsl, renderFromConfig, resolve, resolveAllOf, resolveBase, resolveBindingTargetPath, resolveChecks, resolveDslPath, resolveEffectiveGuardrails, score, spectralLint, validateHandoffSchemas, validateSchema, yamlReservedKeySafetyRule };
package/dist/index.js CHANGED
@@ -50463,7 +50463,8 @@ var AgentSchema = z.object({
50463
50463
  rules: z.array(RuleSchema).optional(),
50464
50464
  anti_patterns: z.array(z.string()).optional(),
50465
50465
  escalation_criteria: z.array(EscalationCriterionSchema).optional(),
50466
- prerequisites: z.array(PrerequisiteSchema).optional()
50466
+ prerequisites: z.array(PrerequisiteSchema).optional(),
50467
+ guardrails: z.array(z.string()).optional()
50467
50468
  }).passthrough();
50468
50469
 
50469
50470
  // src/schema/artifact.ts
@@ -50477,7 +50478,8 @@ var ArtifactSchema = z2.object({
50477
50478
  consumers: z2.array(z2.string()),
50478
50479
  states: z2.array(z2.string()),
50479
50480
  required_validations: z2.array(z2.string()).default([]),
50480
- visibility: z2.string().optional()
50481
+ visibility: z2.string().optional(),
50482
+ guardrails: z2.array(z2.string()).optional()
50481
50483
  }).passthrough();
50482
50484
 
50483
50485
  // src/schema/binding.ts
@@ -50641,7 +50643,8 @@ var TaskSchema = z8.object({
50641
50643
  rules: z8.array(RuleSchema).optional(),
50642
50644
  anti_patterns: z8.array(z8.string()).optional(),
50643
50645
  escalation_criteria: z8.array(EscalationCriterionSchema).optional(),
50644
- validations: z8.array(z8.string()).default([])
50646
+ validations: z8.array(z8.string()).default([]),
50647
+ guardrails: z8.array(z8.string()).optional()
50645
50648
  }).passthrough();
50646
50649
 
50647
50650
  // src/schema/tool.ts
@@ -50660,7 +50663,8 @@ var ToolSchema = z9.object({
50660
50663
  output_artifacts: z9.array(z9.string()).default([]),
50661
50664
  invokable_by: z9.array(z9.string()),
50662
50665
  side_effects: z9.array(z9.string()).default([]),
50663
- commands: z9.array(CommandSchema).default([])
50666
+ commands: z9.array(CommandSchema).default([]),
50667
+ guardrails: z9.array(z9.string()).optional()
50664
50668
  }).passthrough();
50665
50669
 
50666
50670
  // src/schema/validation.ts
@@ -51776,6 +51780,34 @@ function checkReferences(dsl) {
51776
51780
  }
51777
51781
  }
51778
51782
  }
51783
+ for (const [id, agent] of Object.entries(dsl.agents)) {
51784
+ if (agent.guardrails) {
51785
+ for (const ref of agent.guardrails) {
51786
+ checkExists(ref, guardrailIds, "guardrails", `agents.${id}.guardrails`, "entity-guardrail-ref-not-found");
51787
+ }
51788
+ }
51789
+ }
51790
+ for (const [id, task] of Object.entries(dsl.tasks)) {
51791
+ if (task.guardrails) {
51792
+ for (const ref of task.guardrails) {
51793
+ checkExists(ref, guardrailIds, "guardrails", `tasks.${id}.guardrails`, "entity-guardrail-ref-not-found");
51794
+ }
51795
+ }
51796
+ }
51797
+ for (const [id, tool] of Object.entries(dsl.tools)) {
51798
+ if (tool.guardrails) {
51799
+ for (const ref of tool.guardrails) {
51800
+ checkExists(ref, guardrailIds, "guardrails", `tools.${id}.guardrails`, "entity-guardrail-ref-not-found");
51801
+ }
51802
+ }
51803
+ }
51804
+ for (const [id, art] of Object.entries(dsl.artifacts)) {
51805
+ if (art.guardrails) {
51806
+ for (const ref of art.guardrails) {
51807
+ checkExists(ref, guardrailIds, "guardrails", `artifacts.${id}.guardrails`, "entity-guardrail-ref-not-found");
51808
+ }
51809
+ }
51810
+ }
51779
51811
  for (const [id, guardrail] of Object.entries(dsl.guardrails)) {
51780
51812
  if (guardrail.scope.agents) {
51781
51813
  for (const ref of guardrail.scope.agents) {
@@ -52457,6 +52489,114 @@ var semanticValidationPhaseCoverageRule = {
52457
52489
  }
52458
52490
  };
52459
52491
 
52492
+ // src/linter/rules/entity-guardrail-binding.ts
52493
+ var entityGuardrailUndefinedRule = {
52494
+ id: "entity-guardrail-undefined",
52495
+ description: "Entity references a guardrail ID not defined in guardrails",
52496
+ run(dsl) {
52497
+ const diagnostics = [];
52498
+ const guardrailIds = new Set(Object.keys(dsl.guardrails));
52499
+ const sections = [
52500
+ { name: "agents", entities: dsl.agents },
52501
+ { name: "tasks", entities: dsl.tasks },
52502
+ { name: "tools", entities: dsl.tools },
52503
+ { name: "artifacts", entities: dsl.artifacts }
52504
+ ];
52505
+ for (const { name, entities } of sections) {
52506
+ for (const [entityId, entity] of Object.entries(entities)) {
52507
+ for (const ref of entity.guardrails ?? []) {
52508
+ if (!guardrailIds.has(ref)) {
52509
+ diagnostics.push({
52510
+ ruleId: "entity-guardrail-undefined",
52511
+ severity: "error",
52512
+ path: `${name}.${entityId}.guardrails`,
52513
+ message: `${name.slice(0, -1)} "${entityId}" references guardrail "${ref}" which is not defined in guardrails`
52514
+ });
52515
+ }
52516
+ }
52517
+ }
52518
+ }
52519
+ return diagnostics;
52520
+ }
52521
+ };
52522
+ var entityNoGuardrailsRule = {
52523
+ id: "entity-no-guardrails",
52524
+ description: "Entity has no effective guardrails (neither entity-side nor scope-side)",
52525
+ run(dsl) {
52526
+ const diagnostics = [];
52527
+ const scopeBindings = {
52528
+ agents: /* @__PURE__ */ new Set(),
52529
+ tasks: /* @__PURE__ */ new Set(),
52530
+ tools: /* @__PURE__ */ new Set(),
52531
+ artifacts: /* @__PURE__ */ new Set()
52532
+ };
52533
+ for (const guardrail of Object.values(dsl.guardrails)) {
52534
+ for (const key of Object.keys(scopeBindings)) {
52535
+ const ids = guardrail.scope[key];
52536
+ if (ids) {
52537
+ for (const id of ids) scopeBindings[key].add(id);
52538
+ }
52539
+ }
52540
+ }
52541
+ const sections = [
52542
+ { name: "agents", entities: dsl.agents },
52543
+ { name: "tasks", entities: dsl.tasks },
52544
+ { name: "tools", entities: dsl.tools },
52545
+ { name: "artifacts", entities: dsl.artifacts }
52546
+ ];
52547
+ for (const { name, entities } of sections) {
52548
+ for (const [entityId, entity] of Object.entries(entities)) {
52549
+ const hasEntitySide = (entity.guardrails ?? []).length > 0;
52550
+ const hasScopeSide = scopeBindings[name].has(entityId);
52551
+ if (!hasEntitySide && !hasScopeSide) {
52552
+ diagnostics.push({
52553
+ ruleId: "entity-no-guardrails",
52554
+ severity: "info",
52555
+ path: `${name}.${entityId}`,
52556
+ message: `${name.slice(0, -1)} "${entityId}" has no effective guardrails`
52557
+ });
52558
+ }
52559
+ }
52560
+ }
52561
+ return diagnostics;
52562
+ }
52563
+ };
52564
+ var guardrailOrphanedRule = {
52565
+ id: "guardrail-orphaned",
52566
+ description: "Guardrail is not referenced by any entity and not bound to any entity via scope",
52567
+ run(dsl) {
52568
+ const diagnostics = [];
52569
+ const referencedByEntities = /* @__PURE__ */ new Set();
52570
+ const sections = [
52571
+ dsl.agents,
52572
+ dsl.tasks,
52573
+ dsl.tools,
52574
+ dsl.artifacts
52575
+ ];
52576
+ for (const entities of sections) {
52577
+ for (const entity of Object.values(entities)) {
52578
+ for (const ref of entity.guardrails ?? []) {
52579
+ referencedByEntities.add(ref);
52580
+ }
52581
+ }
52582
+ }
52583
+ for (const [guardrailId, guardrail] of Object.entries(dsl.guardrails)) {
52584
+ const hasEntityRef = referencedByEntities.has(guardrailId);
52585
+ const scope = guardrail.scope;
52586
+ const hasScopeBinding = (scope.agents?.length ?? 0) > 0 || (scope.tasks?.length ?? 0) > 0 || (scope.tools?.length ?? 0) > 0 || (scope.artifacts?.length ?? 0) > 0 || (scope.workflows?.length ?? 0) > 0;
52587
+ if (!hasEntityRef && !hasScopeBinding) {
52588
+ diagnostics.push({
52589
+ ruleId: "guardrail-orphaned",
52590
+ severity: "warning",
52591
+ path: `guardrails.${guardrailId}`,
52592
+ message: `Guardrail "${guardrailId}" is not referenced by any entity and has no scope bindings`
52593
+ });
52594
+ }
52595
+ }
52596
+ return diagnostics;
52597
+ }
52598
+ };
52599
+
52460
52600
  // src/linter/linter.ts
52461
52601
  var builtinRules = [
52462
52602
  validationCoverageRule,
@@ -52469,7 +52609,10 @@ var builtinRules = [
52469
52609
  yamlReservedKeySafetyRule,
52470
52610
  artifactRequiredValidationWiringRule,
52471
52611
  taskOutputValidationCompletenessRule,
52472
- semanticValidationPhaseCoverageRule
52612
+ semanticValidationPhaseCoverageRule,
52613
+ entityGuardrailUndefinedRule,
52614
+ entityNoGuardrailsRule,
52615
+ guardrailOrphanedRule
52473
52616
  ];
52474
52617
  function lint(dsl, rules = builtinRules) {
52475
52618
  const diagnostics = [];
@@ -53183,12 +53326,55 @@ function buildGuardrailEnforcement(dsl, policy, loadedBindings) {
53183
53326
  }
53184
53327
  return entries;
53185
53328
  }
53329
+ function resolveEffectiveGuardrails(dsl, entityType, entityId) {
53330
+ const entityDef = dsl[entityType][entityId];
53331
+ const entitySide = new Set(entityDef?.guardrails ?? []);
53332
+ const scopeSide = /* @__PURE__ */ new Set();
53333
+ for (const [guardrailId, guardrail] of Object.entries(dsl.guardrails)) {
53334
+ const scopeIds = guardrail.scope[entityType];
53335
+ if (scopeIds?.includes(entityId)) {
53336
+ scopeSide.add(guardrailId);
53337
+ }
53338
+ }
53339
+ const allIds = /* @__PURE__ */ new Set([...entitySide, ...scopeSide]);
53340
+ const activePolicyRules = /* @__PURE__ */ new Map();
53341
+ for (const policy of Object.values(dsl.guardrail_policies)) {
53342
+ for (const rule of policy.rules) {
53343
+ if (!activePolicyRules.has(rule.guardrail)) {
53344
+ activePolicyRules.set(rule.guardrail, {
53345
+ severity: rule.severity,
53346
+ action: rule.action
53347
+ });
53348
+ }
53349
+ }
53350
+ }
53351
+ const entries = [];
53352
+ for (const id of allIds) {
53353
+ const guardrail = dsl.guardrails[id];
53354
+ if (!guardrail) continue;
53355
+ const fromEntity = entitySide.has(id);
53356
+ const fromScope = scopeSide.has(id);
53357
+ const source = fromEntity && fromScope ? "both" : fromEntity ? "entity" : "scope";
53358
+ const policyInfo = activePolicyRules.get(id);
53359
+ entries.push({
53360
+ guardrail_id: id,
53361
+ description: guardrail.description,
53362
+ rationale: guardrail.rationale,
53363
+ tags: guardrail.tags,
53364
+ source,
53365
+ severity: policyInfo?.severity,
53366
+ action: policyInfo?.action
53367
+ });
53368
+ }
53369
+ return entries;
53370
+ }
53186
53371
  function buildTaskContext(dsl, taskId) {
53187
53372
  const taskDef = dsl.tasks[taskId];
53188
53373
  const task = { ...taskDef, id: taskId };
53189
53374
  const agentDef = dsl.agents[taskDef.target_agent];
53190
53375
  const targetAgent = agentDef ? { ...agentDef, id: taskDef.target_agent } : null;
53191
- return { task, targetAgent, dsl };
53376
+ const relatedGuardrails = resolveEffectiveGuardrails(dsl, "tasks", taskId);
53377
+ return { task, targetAgent, relatedGuardrails, dsl };
53192
53378
  }
53193
53379
  function buildArtifactContext(dsl, artifactId) {
53194
53380
  const artifactDef = dsl.artifacts[artifactId];
@@ -53231,6 +53417,7 @@ function buildArtifactContext(dsl, artifactId) {
53231
53417
  }
53232
53418
  }
53233
53419
  }
53420
+ const relatedGuardrails = resolveEffectiveGuardrails(dsl, "artifacts", artifactId);
53234
53421
  return {
53235
53422
  artifact,
53236
53423
  relatedTools,
@@ -53239,6 +53426,7 @@ function buildArtifactContext(dsl, artifactId) {
53239
53426
  consumerAgents,
53240
53427
  editorAgents,
53241
53428
  createdInWorkflows,
53429
+ relatedGuardrails,
53242
53430
  dsl
53243
53431
  };
53244
53432
  }
@@ -53256,11 +53444,13 @@ function buildToolContext(dsl, toolId) {
53256
53444
  }
53257
53445
  return result;
53258
53446
  };
53447
+ const relatedGuardrails = resolveEffectiveGuardrails(dsl, "tools", toolId);
53259
53448
  return {
53260
53449
  tool,
53261
53450
  invokableAgents,
53262
53451
  inputArtifactDetails: pickArtifacts(toolDef.input_artifacts),
53263
53452
  outputArtifactDetails: pickArtifacts(toolDef.output_artifacts),
53453
+ relatedGuardrails,
53264
53454
  dsl
53265
53455
  };
53266
53456
  }
@@ -53492,6 +53682,7 @@ function buildPerAgentContext(dsl, agent) {
53492
53682
  }
53493
53683
  const rawReceivableTasks = receivableTasks.map(({ id: _id, ...rest }) => rest);
53494
53684
  const mergedBehavior = mergeBehavioralSpec(agent, rawReceivableTasks);
53685
+ const relatedGuardrails = resolveEffectiveGuardrails(dsl, "agents", agentId);
53495
53686
  return {
53496
53687
  agent,
53497
53688
  tasks: receivableTasks,
@@ -53501,6 +53692,7 @@ function buildPerAgentContext(dsl, agent) {
53501
53692
  relatedTools,
53502
53693
  relatedHandoffTypes,
53503
53694
  mergedBehavior,
53695
+ relatedGuardrails,
53504
53696
  dsl
53505
53697
  };
53506
53698
  }
@@ -54911,6 +55103,52 @@ function crossReferenceBidirectionality(dsl) {
54911
55103
  recommendations: issues.length > 0 ? [`${issues.length} unreciprocated cross-references: ${issues.slice(0, 5).join(", ")}${issues.length > 5 ? `, ... (${issues.length - 5} more)` : ""}`] : []
54912
55104
  };
54913
55105
  }
55106
+ function entityGuardrailCoverage(dsl) {
55107
+ const entitySections = [
55108
+ { name: "agents", entities: dsl.agents },
55109
+ { name: "tasks", entities: dsl.tasks },
55110
+ { name: "tools", entities: dsl.tools },
55111
+ { name: "artifacts", entities: dsl.artifacts }
55112
+ ];
55113
+ const scopeBindings = {
55114
+ agents: /* @__PURE__ */ new Set(),
55115
+ tasks: /* @__PURE__ */ new Set(),
55116
+ tools: /* @__PURE__ */ new Set(),
55117
+ artifacts: /* @__PURE__ */ new Set()
55118
+ };
55119
+ for (const guardrail of Object.values(dsl.guardrails)) {
55120
+ for (const key of Object.keys(scopeBindings)) {
55121
+ const ids = guardrail.scope[key];
55122
+ if (ids) {
55123
+ for (const id of ids) scopeBindings[key].add(id);
55124
+ }
55125
+ }
55126
+ }
55127
+ let total = 0;
55128
+ let covered = 0;
55129
+ const missing = [];
55130
+ for (const { name, entities } of entitySections) {
55131
+ for (const [entityId, entity] of Object.entries(entities)) {
55132
+ total++;
55133
+ const hasEntitySide = (entity.guardrails ?? []).length > 0;
55134
+ const hasScopeSide = scopeBindings[name].has(entityId);
55135
+ if (hasEntitySide || hasScopeSide) {
55136
+ covered++;
55137
+ } else {
55138
+ missing.push(`${name}.${entityId}`);
55139
+ }
55140
+ }
55141
+ }
55142
+ return {
55143
+ id: "entity-guardrail-coverage",
55144
+ label: "Entity guardrail coverage",
55145
+ score: covered,
55146
+ total,
55147
+ percent: pct(covered, total),
55148
+ weight: 1,
55149
+ recommendations: missing.length > 0 ? [`${missing.length} entities without guardrails: ${missing.slice(0, 5).join(", ")}${missing.length > 5 ? `, ... (${missing.length - 5} more)` : ""}`] : []
55150
+ };
55151
+ }
54914
55152
  function guardrailScopeResolution(dsl) {
54915
55153
  let totalRefs = 0;
54916
55154
  let resolvedRefs = 0;
@@ -54956,7 +55194,8 @@ function score(dsl) {
54956
55194
  workflowValidationIntegration(dsl),
54957
55195
  schemaCompleteness(dsl),
54958
55196
  crossReferenceBidirectionality(dsl),
54959
- guardrailScopeResolution(dsl)
55197
+ guardrailScopeResolution(dsl),
55198
+ entityGuardrailCoverage(dsl)
54960
55199
  ];
54961
55200
  const totalWeight = dimensions.reduce((s2, d2) => s2 + d2.weight, 0);
54962
55201
  const weightedSum = dimensions.reduce(
@@ -55383,6 +55622,7 @@ export {
55383
55622
  resolveBindingTargetPath,
55384
55623
  resolveChecks,
55385
55624
  resolveDslPath,
55625
+ resolveEffectiveGuardrails,
55386
55626
  score,
55387
55627
  spectralLint,
55388
55628
  validateHandoffSchemas,