agent-contracts 0.19.3 → 0.19.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
@@ -1757,7 +1757,7 @@ declare function buildAuditContext(auditType: AuditType, dsl: Dsl, config: Resol
1757
1757
 
1758
1758
  declare function formatAuditResult(r: AuditRunResult, format: OutputFormat): string;
1759
1759
  declare function formatAuditResults(results: AuditRunResult[], format: OutputFormat): string;
1760
- declare function computeExitCode(results: AuditRunResult[]): number;
1760
+ declare function computeExitCode(results: AuditRunResult[], failOn?: string): number;
1761
1761
 
1762
1762
  interface ResolvedCheck {
1763
1763
  guardrail_id: string;
package/dist/index.js CHANGED
@@ -49347,18 +49347,27 @@ async function resolveRefsDeep(data, baseDir, resolving, rootDoc) {
49347
49347
  }
49348
49348
  resolving.add(refValue);
49349
49349
  const target = resolveJsonPointer(rootDoc, refValue);
49350
- const resolved2 = await resolveRefsDeep(
49350
+ const resolved = await resolveRefsDeep(
49351
49351
  deepClone(target),
49352
49352
  baseDir,
49353
49353
  resolving,
49354
49354
  rootDoc
49355
49355
  );
49356
49356
  resolving.delete(refValue);
49357
- return resolved2;
49357
+ return resolved;
49358
49358
  }
49359
- const refTarget = resolve(baseDir, refValue);
49359
+ const hashIdx = refValue.indexOf("#");
49360
+ const filePart = hashIdx >= 0 ? refValue.slice(0, hashIdx) : refValue;
49361
+ const fragment = hashIdx >= 0 ? refValue.slice(hashIdx) : null;
49362
+ const refTarget = resolve(baseDir, filePart);
49360
49363
  const s2 = await fsStat(refTarget).catch(() => null);
49361
49364
  if (s2?.isDirectory()) {
49365
+ if (fragment) {
49366
+ throw new DslLoadError(
49367
+ `Cannot use JSON Pointer fragment with directory $ref: ${refValue}`,
49368
+ refTarget
49369
+ );
49370
+ }
49362
49371
  if (resolving.has(refTarget)) {
49363
49372
  throw new DslLoadError(
49364
49373
  `Circular $ref detected: ${refTarget}`,
@@ -49381,14 +49390,24 @@ async function resolveRefsDeep(data, baseDir, resolving, rootDoc) {
49381
49390
  }
49382
49391
  resolving.add(refTarget);
49383
49392
  const content = await readYaml(refTarget);
49384
- const resolved = await resolveRefsDeep(
49393
+ const fileRoot = fragment ? content : rootDoc;
49394
+ let fileData = await resolveRefsDeep(
49385
49395
  content,
49386
49396
  dirname(refTarget),
49387
49397
  resolving,
49388
- rootDoc
49398
+ fileRoot
49389
49399
  );
49390
49400
  resolving.delete(refTarget);
49391
- return resolved;
49401
+ if (fragment && fragment.startsWith("#/")) {
49402
+ if (!isRecord(fileData)) {
49403
+ throw new DslLoadError(
49404
+ `Cannot resolve fragment "${fragment}" in ${refTarget}: file content is not an object`,
49405
+ refTarget
49406
+ );
49407
+ }
49408
+ fileData = resolveJsonPointer(fileData, fragment);
49409
+ }
49410
+ return fileData;
49392
49411
  }
49393
49412
  let obj = data;
49394
49413
  if (hasRefs(obj)) {
@@ -55080,16 +55099,22 @@ function formatAuditResults(results, format2) {
55080
55099
  }
55081
55100
  return results.map((r3) => formatAuditResult(r3, format2)).join("\n\n");
55082
55101
  }
55083
- function computeExitCode(results) {
55102
+ function computeExitCode(results, failOn) {
55084
55103
  for (const r3 of results) {
55085
55104
  if (r3.status === "error") {
55086
- if (r3.errorMessage?.includes("not installed") || r3.errorMessage?.includes("adapter")) return 3;
55087
- return 2;
55105
+ if (r3.errorMessage?.includes("not installed")) return 11;
55106
+ if (r3.errorMessage?.includes("adapter") || r3.errorMessage?.includes("API")) return 12;
55107
+ return 1;
55088
55108
  }
55089
55109
  }
55110
+ const severityRank = { info: 0, warning: 1, error: 2, critical: 3 };
55111
+ const threshold = severityRank[failOn ?? "critical"] ?? 3;
55090
55112
  for (const r3 of results) {
55091
- if (r3.data?.critical_gaps && r3.data.critical_gaps.some((g2) => g2.severity === "critical")) {
55092
- return 1;
55113
+ if (r3.data?.critical_gaps) {
55114
+ for (const gap of r3.data.critical_gaps) {
55115
+ const rank = severityRank[gap.severity ?? ""] ?? 0;
55116
+ if (rank >= threshold) return 10;
55117
+ }
55093
55118
  }
55094
55119
  }
55095
55120
  return 0;