@agentcontract/core 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.
- package/LICENSE +112 -0
- package/README.md +106 -0
- package/dist/audit-DNON4W2Q.mjs +7 -0
- package/dist/audit-DNON4W2Q.mjs.map +1 -0
- package/dist/chunk-BVUHPJDU.mjs +50 -0
- package/dist/chunk-BVUHPJDU.mjs.map +1 -0
- package/dist/chunk-UHNX2RBZ.mjs +526 -0
- package/dist/chunk-UHNX2RBZ.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +577 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +105 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +259 -0
- package/dist/index.d.ts +259 -0
- package/dist/index.js +654 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +29 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
// src/loader.ts
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { extname } from "path";
|
|
4
|
+
import yaml from "js-yaml";
|
|
5
|
+
|
|
6
|
+
// src/models.ts
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
var JudgeType = z.enum(["deterministic", "llm"]).default("deterministic");
|
|
9
|
+
var ViolationAction = z.enum(["warn", "block", "rollback", "halt_and_alert"]).default("block");
|
|
10
|
+
var AssertionType = z.enum(["pattern", "schema", "llm", "cost", "latency", "custom"]);
|
|
11
|
+
var ClauseObject = z.object({
|
|
12
|
+
text: z.string().min(1),
|
|
13
|
+
judge: JudgeType,
|
|
14
|
+
description: z.string().default("")
|
|
15
|
+
});
|
|
16
|
+
var Clause = z.union([z.string().min(1), ClauseObject]);
|
|
17
|
+
var PreconditionClause = z.union([
|
|
18
|
+
z.string().min(1),
|
|
19
|
+
z.object({
|
|
20
|
+
text: z.string().min(1),
|
|
21
|
+
judge: JudgeType,
|
|
22
|
+
on_fail: z.enum(["block", "warn"]).default("block"),
|
|
23
|
+
description: z.string().default("")
|
|
24
|
+
})
|
|
25
|
+
]);
|
|
26
|
+
var Assertion = z.object({
|
|
27
|
+
name: z.string().regex(/^[a-z][a-z0-9_]*$/),
|
|
28
|
+
type: AssertionType,
|
|
29
|
+
description: z.string().default(""),
|
|
30
|
+
// pattern
|
|
31
|
+
must_not_match: z.string().optional(),
|
|
32
|
+
must_match: z.string().optional(),
|
|
33
|
+
// schema
|
|
34
|
+
schema: z.record(z.string(), z.unknown()).optional(),
|
|
35
|
+
// llm
|
|
36
|
+
prompt: z.string().optional(),
|
|
37
|
+
pass_when: z.string().optional(),
|
|
38
|
+
model: z.string().optional(),
|
|
39
|
+
// cost
|
|
40
|
+
max_usd: z.number().nonnegative().optional(),
|
|
41
|
+
// latency
|
|
42
|
+
max_ms: z.number().int().positive().optional(),
|
|
43
|
+
// custom
|
|
44
|
+
plugin: z.string().optional()
|
|
45
|
+
}).passthrough();
|
|
46
|
+
var Limits = z.object({
|
|
47
|
+
max_tokens: z.number().int().positive().optional(),
|
|
48
|
+
max_input_tokens: z.number().int().positive().optional(),
|
|
49
|
+
max_latency_ms: z.number().int().positive().optional(),
|
|
50
|
+
max_cost_usd: z.number().nonnegative().optional(),
|
|
51
|
+
max_tool_calls: z.number().int().nonnegative().optional(),
|
|
52
|
+
max_steps: z.number().int().positive().optional()
|
|
53
|
+
}).default({});
|
|
54
|
+
var OnViolation = z.object({
|
|
55
|
+
default: ViolationAction
|
|
56
|
+
}).catchall(z.string()).default({ default: "block" });
|
|
57
|
+
var Contract = z.object({
|
|
58
|
+
agent: z.string().min(1),
|
|
59
|
+
"spec-version": z.string(),
|
|
60
|
+
version: z.string(),
|
|
61
|
+
description: z.string().default(""),
|
|
62
|
+
author: z.string().default(""),
|
|
63
|
+
created: z.string().default(""),
|
|
64
|
+
tags: z.array(z.string()).default([]),
|
|
65
|
+
extends: z.string().optional(),
|
|
66
|
+
must: z.array(Clause).default([]),
|
|
67
|
+
must_not: z.array(Clause).default([]),
|
|
68
|
+
can: z.array(z.string()).default([]),
|
|
69
|
+
requires: z.array(PreconditionClause).default([]),
|
|
70
|
+
ensures: z.array(Clause).default([]),
|
|
71
|
+
invariant: z.array(Clause).default([]),
|
|
72
|
+
assert: z.array(Assertion).default([]),
|
|
73
|
+
limits: Limits,
|
|
74
|
+
on_violation: OnViolation
|
|
75
|
+
});
|
|
76
|
+
function getClauseText(clause) {
|
|
77
|
+
return typeof clause === "string" ? clause : clause.text;
|
|
78
|
+
}
|
|
79
|
+
function getClauseJudge(clause) {
|
|
80
|
+
return typeof clause === "string" ? "deterministic" : clause.judge;
|
|
81
|
+
}
|
|
82
|
+
function getViolationAction(onViolation, name) {
|
|
83
|
+
return onViolation[name] ?? onViolation.default;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/exceptions.ts
|
|
87
|
+
var ContractError = class extends Error {
|
|
88
|
+
constructor(message) {
|
|
89
|
+
super(message);
|
|
90
|
+
this.name = "ContractError";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var ContractLoadError = class extends ContractError {
|
|
94
|
+
constructor(message) {
|
|
95
|
+
super(message);
|
|
96
|
+
this.name = "ContractLoadError";
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
var ContractPreconditionError = class extends ContractError {
|
|
100
|
+
clause;
|
|
101
|
+
details;
|
|
102
|
+
constructor(clause, details = "") {
|
|
103
|
+
super(`[PRECONDITION FAILED] ${clause}${details ? ": " + details : ""}`);
|
|
104
|
+
this.name = "ContractPreconditionError";
|
|
105
|
+
this.clause = clause;
|
|
106
|
+
this.details = details;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var ContractViolation = class extends ContractError {
|
|
110
|
+
violations;
|
|
111
|
+
constructor(violations) {
|
|
112
|
+
const lines = violations.map(
|
|
113
|
+
(v) => `[${v.action_taken.toUpperCase()}] ${v.clause_type.toUpperCase()}: "${v.clause_text}"`
|
|
114
|
+
);
|
|
115
|
+
super("AgentContractViolation:\n" + lines.join("\n"));
|
|
116
|
+
this.name = "ContractViolation";
|
|
117
|
+
this.violations = violations;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/loader.ts
|
|
122
|
+
function loadContract(filePath) {
|
|
123
|
+
const ext = extname(filePath).toLowerCase();
|
|
124
|
+
if (![".yaml", ".yml", ".json"].includes(ext)) {
|
|
125
|
+
throw new ContractLoadError(
|
|
126
|
+
`Unsupported file format: ${ext}. Use .contract.yaml or .contract.json`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
let raw;
|
|
130
|
+
try {
|
|
131
|
+
raw = readFileSync(filePath, "utf-8");
|
|
132
|
+
} catch {
|
|
133
|
+
throw new ContractLoadError(`Contract file not found: ${filePath}`);
|
|
134
|
+
}
|
|
135
|
+
let data;
|
|
136
|
+
try {
|
|
137
|
+
data = ext === ".json" ? JSON.parse(raw) : yaml.load(raw);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
throw new ContractLoadError(`Failed to parse contract file: ${e}`);
|
|
140
|
+
}
|
|
141
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
142
|
+
throw new ContractLoadError("Contract file must be a YAML/JSON object at the root level.");
|
|
143
|
+
}
|
|
144
|
+
const result = Contract.safeParse(data);
|
|
145
|
+
if (!result.success) {
|
|
146
|
+
const issues = result.error.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
147
|
+
throw new ContractLoadError(`Contract schema validation failed:
|
|
148
|
+
${issues}`);
|
|
149
|
+
}
|
|
150
|
+
return result.data;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/runner.ts
|
|
154
|
+
import { randomUUID } from "crypto";
|
|
155
|
+
|
|
156
|
+
// src/validators/pattern.ts
|
|
157
|
+
var PatternValidator = class {
|
|
158
|
+
constructor(name, mustNotMatch, mustMatch, description = "") {
|
|
159
|
+
this.name = name;
|
|
160
|
+
this.mustNotMatch = mustNotMatch;
|
|
161
|
+
this.mustMatch = mustMatch;
|
|
162
|
+
this.description = description;
|
|
163
|
+
}
|
|
164
|
+
validate(context) {
|
|
165
|
+
const output = context.output;
|
|
166
|
+
if (this.mustNotMatch) {
|
|
167
|
+
const re = new RegExp(this.mustNotMatch);
|
|
168
|
+
const match = re.exec(output);
|
|
169
|
+
if (match) {
|
|
170
|
+
return {
|
|
171
|
+
passed: false,
|
|
172
|
+
clauseName: this.name,
|
|
173
|
+
clauseText: this.description || `must_not_match: ${this.mustNotMatch}`,
|
|
174
|
+
clauseType: "assert",
|
|
175
|
+
judge: "deterministic",
|
|
176
|
+
details: `Forbidden pattern found: '${match[0].slice(0, 50)}'`
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (this.mustMatch) {
|
|
181
|
+
const re = new RegExp(this.mustMatch);
|
|
182
|
+
if (!re.test(output)) {
|
|
183
|
+
return {
|
|
184
|
+
passed: false,
|
|
185
|
+
clauseName: this.name,
|
|
186
|
+
clauseText: this.description || `must_match: ${this.mustMatch}`,
|
|
187
|
+
clauseType: "assert",
|
|
188
|
+
judge: "deterministic",
|
|
189
|
+
details: "Required pattern not found in output."
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
passed: true,
|
|
195
|
+
clauseName: this.name,
|
|
196
|
+
clauseText: this.description || this.name,
|
|
197
|
+
clauseType: "assert",
|
|
198
|
+
judge: "deterministic",
|
|
199
|
+
details: ""
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/validators/cost.ts
|
|
205
|
+
var CostValidator = class {
|
|
206
|
+
constructor(name, maxUsd, description = "") {
|
|
207
|
+
this.name = name;
|
|
208
|
+
this.maxUsd = maxUsd;
|
|
209
|
+
this.description = description;
|
|
210
|
+
}
|
|
211
|
+
validate(context) {
|
|
212
|
+
const passed = context.costUsd <= this.maxUsd;
|
|
213
|
+
return {
|
|
214
|
+
passed,
|
|
215
|
+
clauseName: this.name,
|
|
216
|
+
clauseText: this.description || `cost must not exceed $${this.maxUsd.toFixed(4)} USD`,
|
|
217
|
+
clauseType: "assert",
|
|
218
|
+
judge: "deterministic",
|
|
219
|
+
details: passed ? "" : `Run cost $${context.costUsd.toFixed(4)} exceeded limit $${this.maxUsd.toFixed(4)}`
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/validators/latency.ts
|
|
225
|
+
var LatencyValidator = class {
|
|
226
|
+
constructor(name, maxMs, description = "") {
|
|
227
|
+
this.name = name;
|
|
228
|
+
this.maxMs = maxMs;
|
|
229
|
+
this.description = description;
|
|
230
|
+
}
|
|
231
|
+
validate(context) {
|
|
232
|
+
const passed = context.durationMs <= this.maxMs;
|
|
233
|
+
return {
|
|
234
|
+
passed,
|
|
235
|
+
clauseName: this.name,
|
|
236
|
+
clauseText: this.description || `latency must not exceed ${this.maxMs}ms`,
|
|
237
|
+
clauseType: "assert",
|
|
238
|
+
judge: "deterministic",
|
|
239
|
+
details: passed ? "" : `Run took ${Math.round(context.durationMs)}ms, exceeded limit of ${this.maxMs}ms`
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// src/validators/llm.ts
|
|
245
|
+
var DEFAULT_JUDGE_MODEL = "claude-haiku-4-5-20251001";
|
|
246
|
+
var JUDGE_SYSTEM_PROMPT = "You are an impartial compliance judge evaluating an AI agent's behavior against a specific contract clause. Evaluate objectively based only on the evidence provided. Your response must be a single word: YES or NO, followed optionally by one sentence of reasoning.";
|
|
247
|
+
var LLMValidator = class {
|
|
248
|
+
constructor(name, clauseText, clauseType, prompt, passWhen = "NO", model = DEFAULT_JUDGE_MODEL, description = "") {
|
|
249
|
+
this.name = name;
|
|
250
|
+
this.clauseText = clauseText;
|
|
251
|
+
this.clauseType = clauseType;
|
|
252
|
+
this.prompt = prompt;
|
|
253
|
+
this.passWhen = passWhen;
|
|
254
|
+
this.model = model;
|
|
255
|
+
this.description = description;
|
|
256
|
+
}
|
|
257
|
+
async validate(context) {
|
|
258
|
+
let Anthropic;
|
|
259
|
+
try {
|
|
260
|
+
const mod = await import("@anthropic-ai/sdk");
|
|
261
|
+
Anthropic = mod.default;
|
|
262
|
+
} catch {
|
|
263
|
+
return {
|
|
264
|
+
passed: false,
|
|
265
|
+
clauseName: this.name,
|
|
266
|
+
clauseText: this.clauseText,
|
|
267
|
+
clauseType: this.clauseType,
|
|
268
|
+
judge: "llm",
|
|
269
|
+
details: "@anthropic-ai/sdk not installed. Run: npm install @anthropic-ai/sdk"
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const client = new Anthropic();
|
|
273
|
+
const userPrompt = this.prompt ? `${this.prompt}
|
|
274
|
+
|
|
275
|
+
--- AGENT INPUT ---
|
|
276
|
+
${context.input}
|
|
277
|
+
|
|
278
|
+
--- AGENT OUTPUT ---
|
|
279
|
+
${context.output}` : `Contract clause: "${this.clauseText}"
|
|
280
|
+
|
|
281
|
+
--- AGENT INPUT ---
|
|
282
|
+
${context.input}
|
|
283
|
+
|
|
284
|
+
--- AGENT OUTPUT ---
|
|
285
|
+
${context.output}
|
|
286
|
+
|
|
287
|
+
Does the agent's output satisfy the contract clause? Answer YES if satisfied, NO if violated.`;
|
|
288
|
+
try {
|
|
289
|
+
const response = await client.messages.create({
|
|
290
|
+
model: this.model,
|
|
291
|
+
max_tokens: 64,
|
|
292
|
+
system: JUDGE_SYSTEM_PROMPT,
|
|
293
|
+
messages: [{ role: "user", content: userPrompt }]
|
|
294
|
+
});
|
|
295
|
+
const raw = response.content[0].type === "text" ? response.content[0].text.trim() : "";
|
|
296
|
+
const firstWord = raw.split(/\s+/)[0]?.toUpperCase().replace(/[.,;:]$/, "") ?? "";
|
|
297
|
+
const passed = firstWord === this.passWhen.toUpperCase();
|
|
298
|
+
const reasoning = raw.slice(firstWord.length).trim();
|
|
299
|
+
return {
|
|
300
|
+
passed,
|
|
301
|
+
clauseName: this.name,
|
|
302
|
+
clauseText: this.clauseText,
|
|
303
|
+
clauseType: this.clauseType,
|
|
304
|
+
judge: "llm",
|
|
305
|
+
details: reasoning
|
|
306
|
+
};
|
|
307
|
+
} catch (e) {
|
|
308
|
+
return {
|
|
309
|
+
passed: false,
|
|
310
|
+
clauseName: this.name,
|
|
311
|
+
clauseText: this.clauseText,
|
|
312
|
+
clauseType: this.clauseType,
|
|
313
|
+
judge: "llm",
|
|
314
|
+
details: `Judge model error: ${e}`
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// src/runner.ts
|
|
321
|
+
var ContractRunner = class {
|
|
322
|
+
constructor(contract) {
|
|
323
|
+
this.contract = contract;
|
|
324
|
+
}
|
|
325
|
+
async run(context, runId) {
|
|
326
|
+
const rid = runId ?? randomUUID();
|
|
327
|
+
const violations = [];
|
|
328
|
+
const c = this.contract;
|
|
329
|
+
const ov = c.on_violation;
|
|
330
|
+
violations.push(...this._checkLimits(context));
|
|
331
|
+
for (const assertion of c.assert) {
|
|
332
|
+
const result = await this._runAssertion(assertion, context);
|
|
333
|
+
if (!result.passed) {
|
|
334
|
+
const action = getViolationAction(ov, assertion.name);
|
|
335
|
+
violations.push({
|
|
336
|
+
clauseType: "assert",
|
|
337
|
+
clauseName: assertion.name,
|
|
338
|
+
clauseText: result.clauseText,
|
|
339
|
+
severity: action,
|
|
340
|
+
actionTaken: action,
|
|
341
|
+
judge: result.judge,
|
|
342
|
+
details: result.details
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
for (const clause of c.must) {
|
|
347
|
+
const text = getClauseText(clause);
|
|
348
|
+
const judge = getClauseJudge(clause);
|
|
349
|
+
const result = await this._evaluateClause(text, "must", judge, context);
|
|
350
|
+
if (!result.passed) {
|
|
351
|
+
const action = getViolationAction(ov, `must:${text.slice(0, 30)}`);
|
|
352
|
+
violations.push({ clauseType: "must", clauseName: `must:${text.slice(0, 30)}`, clauseText: text, severity: action, actionTaken: action, judge, details: result.details });
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
for (const clause of c.must_not) {
|
|
356
|
+
const text = getClauseText(clause);
|
|
357
|
+
const judge = getClauseJudge(clause);
|
|
358
|
+
const result = await this._evaluateClause(text, "must_not", judge, context);
|
|
359
|
+
if (!result.passed) {
|
|
360
|
+
const action = getViolationAction(ov, `must_not:${text.slice(0, 30)}`);
|
|
361
|
+
violations.push({ clauseType: "must_not", clauseName: `must_not:${text.slice(0, 30)}`, clauseText: text, severity: action, actionTaken: action, judge, details: result.details });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
for (const clause of c.ensures) {
|
|
365
|
+
const text = getClauseText(clause);
|
|
366
|
+
const judge = getClauseJudge(clause);
|
|
367
|
+
const result = await this._evaluateClause(text, "ensures", judge, context);
|
|
368
|
+
if (!result.passed) {
|
|
369
|
+
const action = getViolationAction(ov, `ensures:${text.slice(0, 30)}`);
|
|
370
|
+
violations.push({ clauseType: "ensures", clauseName: `ensures:${text.slice(0, 30)}`, clauseText: text, severity: action, actionTaken: action, judge, details: result.details });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const blocking = ["block", "rollback", "halt_and_alert"];
|
|
374
|
+
const passed = !violations.some((v) => blocking.includes(v.actionTaken));
|
|
375
|
+
return { passed, runId: rid, agent: c.agent, contractVersion: c.version, violations, context, outcome: passed ? "pass" : "violation" };
|
|
376
|
+
}
|
|
377
|
+
_checkLimits(context) {
|
|
378
|
+
const records = [];
|
|
379
|
+
const limits = this.contract.limits;
|
|
380
|
+
const ov = this.contract.on_violation;
|
|
381
|
+
if (limits.max_latency_ms != null) {
|
|
382
|
+
const r = new LatencyValidator("max_latency_ms", limits.max_latency_ms).validate(context);
|
|
383
|
+
if (!r.passed) {
|
|
384
|
+
const action = getViolationAction(ov, "max_latency_ms");
|
|
385
|
+
records.push({ clauseType: "limits", clauseName: "max_latency_ms", clauseText: r.clauseText, severity: action, actionTaken: action, judge: "deterministic", details: r.details });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (limits.max_cost_usd != null) {
|
|
389
|
+
const r = new CostValidator("max_cost_usd", limits.max_cost_usd).validate(context);
|
|
390
|
+
if (!r.passed) {
|
|
391
|
+
const action = getViolationAction(ov, "max_cost_usd");
|
|
392
|
+
records.push({ clauseType: "limits", clauseName: "max_cost_usd", clauseText: r.clauseText, severity: action, actionTaken: action, judge: "deterministic", details: r.details });
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (limits.max_tokens != null && context.output) {
|
|
396
|
+
const estimated = Math.floor(context.output.length / 4);
|
|
397
|
+
if (estimated > limits.max_tokens) {
|
|
398
|
+
const action = getViolationAction(ov, "max_tokens");
|
|
399
|
+
records.push({ clauseType: "limits", clauseName: "max_tokens", clauseText: `output must not exceed ${limits.max_tokens} tokens`, severity: action, actionTaken: action, judge: "deterministic", details: `Estimated ${estimated} tokens exceeds limit of ${limits.max_tokens}` });
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return records;
|
|
403
|
+
}
|
|
404
|
+
async _runAssertion(assertion, context) {
|
|
405
|
+
switch (assertion.type) {
|
|
406
|
+
case "pattern":
|
|
407
|
+
return new PatternValidator(assertion.name, assertion.must_not_match, assertion.must_match, assertion.description).validate(context);
|
|
408
|
+
case "cost":
|
|
409
|
+
return new CostValidator(assertion.name, assertion.max_usd ?? 0, assertion.description).validate(context);
|
|
410
|
+
case "latency":
|
|
411
|
+
return new LatencyValidator(assertion.name, assertion.max_ms ?? 0, assertion.description).validate(context);
|
|
412
|
+
case "llm":
|
|
413
|
+
return new LLMValidator(assertion.name, assertion.description || assertion.name, "assert", assertion.prompt, assertion.pass_when ?? "NO", assertion.model).validate(context);
|
|
414
|
+
default:
|
|
415
|
+
return { passed: false, clauseName: assertion.name, clauseText: assertion.description || assertion.name, clauseType: "assert", judge: "deterministic", details: `Unsupported assertion type: ${assertion.type}` };
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async _evaluateClause(text, clauseType, judge, context) {
|
|
419
|
+
if (judge === "llm") {
|
|
420
|
+
return new LLMValidator(`${clauseType}:${text.slice(0, 30)}`, text, clauseType).validate(context);
|
|
421
|
+
}
|
|
422
|
+
return { passed: true, clauseName: `${clauseType}:${text.slice(0, 30)}`, clauseText: text, clauseType, judge: "deterministic", details: "" };
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
// src/validators/base.ts
|
|
427
|
+
function makeContext(partial) {
|
|
428
|
+
return {
|
|
429
|
+
durationMs: 0,
|
|
430
|
+
costUsd: 0,
|
|
431
|
+
toolCalls: [],
|
|
432
|
+
steps: 0,
|
|
433
|
+
metadata: {},
|
|
434
|
+
...partial
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/enforce.ts
|
|
439
|
+
function enforce(contract, fn, options = {}) {
|
|
440
|
+
const { audit = true, auditPath = "agentcontract-audit.jsonl", costFn } = options;
|
|
441
|
+
const runner = new ContractRunner(contract);
|
|
442
|
+
return async (input) => {
|
|
443
|
+
await checkPreconditions(contract, input);
|
|
444
|
+
const start = performance.now();
|
|
445
|
+
const result = await Promise.resolve(fn(input));
|
|
446
|
+
const durationMs = performance.now() - start;
|
|
447
|
+
const output = String(result ?? "");
|
|
448
|
+
const costUsd = costFn ? costFn(result) : 0;
|
|
449
|
+
const ctx = makeContext({ input, output, durationMs, costUsd });
|
|
450
|
+
const runResult = await runner.run(ctx);
|
|
451
|
+
if (audit) {
|
|
452
|
+
const { AuditWriter: AuditWriter2 } = await import("./audit-DNON4W2Q.mjs");
|
|
453
|
+
new AuditWriter2(auditPath).write(runResult);
|
|
454
|
+
}
|
|
455
|
+
const warnViolations = runResult.violations.filter((v) => v.actionTaken === "warn");
|
|
456
|
+
for (const v of warnViolations) {
|
|
457
|
+
process.stderr.write(
|
|
458
|
+
`[AgentContract WARN] ${v.clauseType.toUpperCase()}: "${v.clauseText}" \u2014 ${v.details}
|
|
459
|
+
`
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
const blocking = runResult.violations.filter(
|
|
463
|
+
(v) => ["block", "rollback", "halt_and_alert"].includes(v.actionTaken)
|
|
464
|
+
);
|
|
465
|
+
if (blocking.length > 0) {
|
|
466
|
+
throw new ContractViolation(
|
|
467
|
+
blocking.map((v) => ({
|
|
468
|
+
clause_type: v.clauseType,
|
|
469
|
+
clause_text: v.clauseText,
|
|
470
|
+
action_taken: v.actionTaken
|
|
471
|
+
}))
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
return output;
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
async function checkPreconditions(contract, input) {
|
|
478
|
+
for (const precondition of contract.requires) {
|
|
479
|
+
let text;
|
|
480
|
+
let judge;
|
|
481
|
+
let onFail;
|
|
482
|
+
if (typeof precondition === "string") {
|
|
483
|
+
text = precondition;
|
|
484
|
+
judge = "deterministic";
|
|
485
|
+
onFail = "block";
|
|
486
|
+
} else {
|
|
487
|
+
text = precondition.text;
|
|
488
|
+
judge = precondition.judge;
|
|
489
|
+
onFail = precondition.on_fail;
|
|
490
|
+
}
|
|
491
|
+
let passed = true;
|
|
492
|
+
let details = "";
|
|
493
|
+
if (judge === "deterministic") {
|
|
494
|
+
if (/non-empty|not empty/i.test(text)) {
|
|
495
|
+
passed = input.trim().length > 0;
|
|
496
|
+
details = passed ? "" : "Input is empty.";
|
|
497
|
+
}
|
|
498
|
+
} else if (judge === "llm") {
|
|
499
|
+
const ctx = makeContext({ input, output: "" });
|
|
500
|
+
const result = await new LLMValidator(`requires:${text.slice(0, 30)}`, text, "requires").validate(ctx);
|
|
501
|
+
passed = result.passed;
|
|
502
|
+
details = result.details;
|
|
503
|
+
}
|
|
504
|
+
if (!passed && onFail === "block") {
|
|
505
|
+
throw new ContractPreconditionError(text, details);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/index.ts
|
|
511
|
+
var VERSION = "0.1.0";
|
|
512
|
+
var SPEC_VERSION = "0.1.0";
|
|
513
|
+
|
|
514
|
+
export {
|
|
515
|
+
ContractError,
|
|
516
|
+
ContractLoadError,
|
|
517
|
+
ContractPreconditionError,
|
|
518
|
+
ContractViolation,
|
|
519
|
+
loadContract,
|
|
520
|
+
ContractRunner,
|
|
521
|
+
makeContext,
|
|
522
|
+
enforce,
|
|
523
|
+
VERSION,
|
|
524
|
+
SPEC_VERSION
|
|
525
|
+
};
|
|
526
|
+
//# sourceMappingURL=chunk-UHNX2RBZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/loader.ts","../src/models.ts","../src/exceptions.ts","../src/runner.ts","../src/validators/pattern.ts","../src/validators/cost.ts","../src/validators/latency.ts","../src/validators/llm.ts","../src/validators/base.ts","../src/enforce.ts","../src/index.ts"],"sourcesContent":["/** Contract loading and validation. */\n\nimport { readFileSync } from 'fs';\nimport { extname } from 'path';\nimport yaml from 'js-yaml';\nimport { Contract } from './models.js';\nimport { ContractLoadError } from './exceptions.js';\n\nexport function loadContract(filePath: string): Contract {\n const ext = extname(filePath).toLowerCase();\n if (!['.yaml', '.yml', '.json'].includes(ext)) {\n throw new ContractLoadError(\n `Unsupported file format: ${ext}. Use .contract.yaml or .contract.json`\n );\n }\n\n let raw: string;\n try {\n raw = readFileSync(filePath, 'utf-8');\n } catch {\n throw new ContractLoadError(`Contract file not found: ${filePath}`);\n }\n\n let data: unknown;\n try {\n data = ext === '.json' ? JSON.parse(raw) : yaml.load(raw);\n } catch (e) {\n throw new ContractLoadError(`Failed to parse contract file: ${e}`);\n }\n\n if (typeof data !== 'object' || data === null || Array.isArray(data)) {\n throw new ContractLoadError('Contract file must be a YAML/JSON object at the root level.');\n }\n\n const result = Contract.safeParse(data);\n if (!result.success) {\n const issues = result.error.issues\n .map((i) => ` ${i.path.join('.')}: ${i.message}`)\n .join('\\n');\n throw new ContractLoadError(`Contract schema validation failed:\\n${issues}`);\n }\n\n return result.data;\n}\n","/** Zod schemas for the AgentContract specification. */\n\nimport { z } from 'zod';\n\nexport const JudgeType = z.enum(['deterministic', 'llm']).default('deterministic');\nexport type JudgeType = z.infer<typeof JudgeType>;\n\nexport const ViolationAction = z.enum(['warn', 'block', 'rollback', 'halt_and_alert']).default('block');\nexport type ViolationAction = z.infer<typeof ViolationAction>;\n\nexport const AssertionType = z.enum(['pattern', 'schema', 'llm', 'cost', 'latency', 'custom']);\nexport type AssertionType = z.infer<typeof AssertionType>;\n\n/** A clause is either a plain string or an object with text + judge. */\nexport const ClauseObject = z.object({\n text: z.string().min(1),\n judge: JudgeType,\n description: z.string().default(''),\n});\nexport type ClauseObject = z.infer<typeof ClauseObject>;\n\nexport const Clause = z.union([z.string().min(1), ClauseObject]);\nexport type Clause = z.infer<typeof Clause>;\n\nexport const PreconditionClause = z.union([\n z.string().min(1),\n z.object({\n text: z.string().min(1),\n judge: JudgeType,\n on_fail: z.enum(['block', 'warn']).default('block'),\n description: z.string().default(''),\n }),\n]);\nexport type PreconditionClause = z.infer<typeof PreconditionClause>;\n\nexport const Assertion = z.object({\n name: z.string().regex(/^[a-z][a-z0-9_]*$/),\n type: AssertionType,\n description: z.string().default(''),\n // pattern\n must_not_match: z.string().optional(),\n must_match: z.string().optional(),\n // schema\n schema: z.record(z.string(), z.unknown()).optional(),\n // llm\n prompt: z.string().optional(),\n pass_when: z.string().optional(),\n model: z.string().optional(),\n // cost\n max_usd: z.number().nonnegative().optional(),\n // latency\n max_ms: z.number().int().positive().optional(),\n // custom\n plugin: z.string().optional(),\n}).passthrough();\nexport type Assertion = z.infer<typeof Assertion>;\n\nexport const Limits = z.object({\n max_tokens: z.number().int().positive().optional(),\n max_input_tokens: z.number().int().positive().optional(),\n max_latency_ms: z.number().int().positive().optional(),\n max_cost_usd: z.number().nonnegative().optional(),\n max_tool_calls: z.number().int().nonnegative().optional(),\n max_steps: z.number().int().positive().optional(),\n}).default({});\nexport type Limits = z.infer<typeof Limits>;\n\nexport const OnViolation = z.object({\n default: ViolationAction,\n}).catchall(z.string()).default({ default: 'block' });\nexport type OnViolation = z.infer<typeof OnViolation>;\n\nexport const Contract = z.object({\n agent: z.string().min(1),\n 'spec-version': z.string(),\n version: z.string(),\n description: z.string().default(''),\n author: z.string().default(''),\n created: z.string().default(''),\n tags: z.array(z.string()).default([]),\n extends: z.string().optional(),\n must: z.array(Clause).default([]),\n must_not: z.array(Clause).default([]),\n can: z.array(z.string()).default([]),\n requires: z.array(PreconditionClause).default([]),\n ensures: z.array(Clause).default([]),\n invariant: z.array(Clause).default([]),\n assert: z.array(Assertion).default([]),\n limits: Limits,\n on_violation: OnViolation,\n});\nexport type Contract = z.infer<typeof Contract>;\n\n/** Helpers */\nexport function getClauseText(clause: Clause): string {\n return typeof clause === 'string' ? clause : clause.text;\n}\n\nexport function getClauseJudge(clause: Clause): JudgeType {\n return typeof clause === 'string' ? 'deterministic' : clause.judge;\n}\n\nexport function getViolationAction(onViolation: OnViolation, name: string): string {\n return (onViolation as Record<string, string>)[name] ?? onViolation.default;\n}\n","/** AgentContract exceptions. */\n\nexport class ContractError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ContractError';\n }\n}\n\nexport class ContractLoadError extends ContractError {\n constructor(message: string) {\n super(message);\n this.name = 'ContractLoadError';\n }\n}\n\nexport class ContractPreconditionError extends ContractError {\n clause: string;\n details: string;\n\n constructor(clause: string, details = '') {\n super(`[PRECONDITION FAILED] ${clause}${details ? ': ' + details : ''}`);\n this.name = 'ContractPreconditionError';\n this.clause = clause;\n this.details = details;\n }\n}\n\nexport class ContractViolation extends ContractError {\n violations: Array<{ clause_type: string; clause_text: string; action_taken: string }>;\n\n constructor(violations: Array<{ clause_type: string; clause_text: string; action_taken: string }>) {\n const lines = violations.map(\n (v) => `[${v.action_taken.toUpperCase()}] ${v.clause_type.toUpperCase()}: \"${v.clause_text}\"`\n );\n super('AgentContractViolation:\\n' + lines.join('\\n'));\n this.name = 'ContractViolation';\n this.violations = violations;\n }\n}\n","/** Contract validation runner — orchestrates all validators per spec §6.1. */\n\nimport { randomUUID } from 'crypto';\nimport {\n Contract,\n Assertion,\n getClauseText,\n getClauseJudge,\n getViolationAction,\n} from './models.js';\nimport type { RunContext, ValidationResult } from './validators/base.js';\nimport { PatternValidator } from './validators/pattern.js';\nimport { CostValidator } from './validators/cost.js';\nimport { LatencyValidator } from './validators/latency.js';\nimport { LLMValidator } from './validators/llm.js';\n\nexport interface ViolationRecord {\n clauseType: string;\n clauseName: string;\n clauseText: string;\n severity: string;\n actionTaken: string;\n judge: string;\n details: string;\n}\n\nexport interface RunResult {\n passed: boolean;\n runId: string;\n agent: string;\n contractVersion: string;\n violations: ViolationRecord[];\n context: RunContext;\n outcome: 'pass' | 'violation';\n}\n\nexport class ContractRunner {\n constructor(private contract: Contract) {}\n\n async run(context: RunContext, runId?: string): Promise<RunResult> {\n const rid = runId ?? randomUUID();\n const violations: ViolationRecord[] = [];\n const c = this.contract;\n const ov = c.on_violation;\n\n // 1. limits\n violations.push(...this._checkLimits(context));\n\n // 2. assert\n for (const assertion of c.assert) {\n const result = await this._runAssertion(assertion, context);\n if (!result.passed) {\n const action = getViolationAction(ov, assertion.name);\n violations.push({\n clauseType: 'assert',\n clauseName: assertion.name,\n clauseText: result.clauseText,\n severity: action,\n actionTaken: action,\n judge: result.judge,\n details: result.details,\n });\n }\n }\n\n // 3. must\n for (const clause of c.must) {\n const text = getClauseText(clause);\n const judge = getClauseJudge(clause);\n const result = await this._evaluateClause(text, 'must', judge, context);\n if (!result.passed) {\n const action = getViolationAction(ov, `must:${text.slice(0, 30)}`);\n violations.push({ clauseType: 'must', clauseName: `must:${text.slice(0, 30)}`, clauseText: text, severity: action, actionTaken: action, judge, details: result.details });\n }\n }\n\n // 4. must_not\n for (const clause of c.must_not) {\n const text = getClauseText(clause);\n const judge = getClauseJudge(clause);\n const result = await this._evaluateClause(text, 'must_not', judge, context);\n if (!result.passed) {\n const action = getViolationAction(ov, `must_not:${text.slice(0, 30)}`);\n violations.push({ clauseType: 'must_not', clauseName: `must_not:${text.slice(0, 30)}`, clauseText: text, severity: action, actionTaken: action, judge, details: result.details });\n }\n }\n\n // 5. ensures\n for (const clause of c.ensures) {\n const text = getClauseText(clause);\n const judge = getClauseJudge(clause);\n const result = await this._evaluateClause(text, 'ensures', judge, context);\n if (!result.passed) {\n const action = getViolationAction(ov, `ensures:${text.slice(0, 30)}`);\n violations.push({ clauseType: 'ensures', clauseName: `ensures:${text.slice(0, 30)}`, clauseText: text, severity: action, actionTaken: action, judge, details: result.details });\n }\n }\n\n const blocking = ['block', 'rollback', 'halt_and_alert'];\n const passed = !violations.some((v) => blocking.includes(v.actionTaken));\n\n return { passed, runId: rid, agent: c.agent, contractVersion: c.version, violations, context, outcome: passed ? 'pass' : 'violation' };\n }\n\n private _checkLimits(context: RunContext): ViolationRecord[] {\n const records: ViolationRecord[] = [];\n const limits = this.contract.limits;\n const ov = this.contract.on_violation;\n\n if (limits.max_latency_ms != null) {\n const r = new LatencyValidator('max_latency_ms', limits.max_latency_ms).validate(context);\n if (!r.passed) {\n const action = getViolationAction(ov, 'max_latency_ms');\n records.push({ clauseType: 'limits', clauseName: 'max_latency_ms', clauseText: r.clauseText, severity: action, actionTaken: action, judge: 'deterministic', details: r.details });\n }\n }\n\n if (limits.max_cost_usd != null) {\n const r = new CostValidator('max_cost_usd', limits.max_cost_usd).validate(context);\n if (!r.passed) {\n const action = getViolationAction(ov, 'max_cost_usd');\n records.push({ clauseType: 'limits', clauseName: 'max_cost_usd', clauseText: r.clauseText, severity: action, actionTaken: action, judge: 'deterministic', details: r.details });\n }\n }\n\n if (limits.max_tokens != null && context.output) {\n const estimated = Math.floor(context.output.length / 4);\n if (estimated > limits.max_tokens) {\n const action = getViolationAction(ov, 'max_tokens');\n records.push({ clauseType: 'limits', clauseName: 'max_tokens', clauseText: `output must not exceed ${limits.max_tokens} tokens`, severity: action, actionTaken: action, judge: 'deterministic', details: `Estimated ${estimated} tokens exceeds limit of ${limits.max_tokens}` });\n }\n }\n\n return records;\n }\n\n private async _runAssertion(assertion: Assertion, context: RunContext): Promise<ValidationResult> {\n switch (assertion.type) {\n case 'pattern':\n return new PatternValidator(assertion.name, assertion.must_not_match, assertion.must_match, assertion.description).validate(context);\n case 'cost':\n return new CostValidator(assertion.name, assertion.max_usd ?? 0, assertion.description).validate(context);\n case 'latency':\n return new LatencyValidator(assertion.name, assertion.max_ms ?? 0, assertion.description).validate(context);\n case 'llm':\n return new LLMValidator(assertion.name, assertion.description || assertion.name, 'assert', assertion.prompt, assertion.pass_when ?? 'NO', assertion.model).validate(context);\n default:\n return { passed: false, clauseName: assertion.name, clauseText: assertion.description || assertion.name, clauseType: 'assert', judge: 'deterministic', details: `Unsupported assertion type: ${assertion.type}` };\n }\n }\n\n private async _evaluateClause(text: string, clauseType: string, judge: string, context: RunContext): Promise<ValidationResult> {\n if (judge === 'llm') {\n return new LLMValidator(`${clauseType}:${text.slice(0, 30)}`, text, clauseType).validate(context);\n }\n // Deterministic natural language: pass by default (no handler registered)\n return { passed: true, clauseName: `${clauseType}:${text.slice(0, 30)}`, clauseText: text, clauseType, judge: 'deterministic', details: '' };\n }\n}\n","/** Regex pattern validator. */\n\nimport type { RunContext, ValidationResult, Validator } from './base.js';\n\nexport class PatternValidator implements Validator {\n constructor(\n private name: string,\n private mustNotMatch?: string,\n private mustMatch?: string,\n private description = '',\n ) {}\n\n validate(context: RunContext): ValidationResult {\n const output = context.output;\n\n if (this.mustNotMatch) {\n const re = new RegExp(this.mustNotMatch);\n const match = re.exec(output);\n if (match) {\n return {\n passed: false,\n clauseName: this.name,\n clauseText: this.description || `must_not_match: ${this.mustNotMatch}`,\n clauseType: 'assert',\n judge: 'deterministic',\n details: `Forbidden pattern found: '${match[0].slice(0, 50)}'`,\n };\n }\n }\n\n if (this.mustMatch) {\n const re = new RegExp(this.mustMatch);\n if (!re.test(output)) {\n return {\n passed: false,\n clauseName: this.name,\n clauseText: this.description || `must_match: ${this.mustMatch}`,\n clauseType: 'assert',\n judge: 'deterministic',\n details: 'Required pattern not found in output.',\n };\n }\n }\n\n return {\n passed: true,\n clauseName: this.name,\n clauseText: this.description || this.name,\n clauseType: 'assert',\n judge: 'deterministic',\n details: '',\n };\n }\n}\n","/** Cost validator. */\n\nimport type { RunContext, ValidationResult, Validator } from './base.js';\n\nexport class CostValidator implements Validator {\n constructor(\n private name: string,\n private maxUsd: number,\n private description = '',\n ) {}\n\n validate(context: RunContext): ValidationResult {\n const passed = context.costUsd <= this.maxUsd;\n return {\n passed,\n clauseName: this.name,\n clauseText: this.description || `cost must not exceed $${this.maxUsd.toFixed(4)} USD`,\n clauseType: 'assert',\n judge: 'deterministic',\n details: passed\n ? ''\n : `Run cost $${context.costUsd.toFixed(4)} exceeded limit $${this.maxUsd.toFixed(4)}`,\n };\n }\n}\n","/** Latency validator. */\n\nimport type { RunContext, ValidationResult, Validator } from './base.js';\n\nexport class LatencyValidator implements Validator {\n constructor(\n private name: string,\n private maxMs: number,\n private description = '',\n ) {}\n\n validate(context: RunContext): ValidationResult {\n const passed = context.durationMs <= this.maxMs;\n return {\n passed,\n clauseName: this.name,\n clauseText: this.description || `latency must not exceed ${this.maxMs}ms`,\n clauseType: 'assert',\n judge: 'deterministic',\n details: passed\n ? ''\n : `Run took ${Math.round(context.durationMs)}ms, exceeded limit of ${this.maxMs}ms`,\n };\n }\n}\n","/** LLM judge validator. */\n\nimport type { RunContext, ValidationResult, Validator } from './base.js';\n\nconst DEFAULT_JUDGE_MODEL = 'claude-haiku-4-5-20251001';\n\nconst JUDGE_SYSTEM_PROMPT =\n 'You are an impartial compliance judge evaluating an AI agent\\'s behavior against a specific ' +\n 'contract clause. Evaluate objectively based only on the evidence provided. ' +\n 'Your response must be a single word: YES or NO, followed optionally by one sentence of reasoning.';\n\nexport class LLMValidator implements Validator {\n constructor(\n private name: string,\n private clauseText: string,\n private clauseType: string,\n private prompt?: string,\n private passWhen = 'NO',\n private model = DEFAULT_JUDGE_MODEL,\n private description = '',\n ) {}\n\n async validate(context: RunContext): Promise<ValidationResult> {\n let Anthropic: typeof import('@anthropic-ai/sdk').default;\n try {\n const mod = await import('@anthropic-ai/sdk');\n Anthropic = mod.default;\n } catch {\n return {\n passed: false,\n clauseName: this.name,\n clauseText: this.clauseText,\n clauseType: this.clauseType,\n judge: 'llm',\n details: '@anthropic-ai/sdk not installed. Run: npm install @anthropic-ai/sdk',\n };\n }\n\n const client = new Anthropic();\n const userPrompt = this.prompt\n ? `${this.prompt}\\n\\n--- AGENT INPUT ---\\n${context.input}\\n\\n--- AGENT OUTPUT ---\\n${context.output}`\n : `Contract clause: \"${this.clauseText}\"\\n\\n--- AGENT INPUT ---\\n${context.input}\\n\\n--- AGENT OUTPUT ---\\n${context.output}\\n\\nDoes the agent's output satisfy the contract clause? Answer YES if satisfied, NO if violated.`;\n\n try {\n const response = await client.messages.create({\n model: this.model,\n max_tokens: 64,\n system: JUDGE_SYSTEM_PROMPT,\n messages: [{ role: 'user', content: userPrompt }],\n });\n\n const raw = response.content[0].type === 'text' ? response.content[0].text.trim() : '';\n const firstWord = raw.split(/\\s+/)[0]?.toUpperCase().replace(/[.,;:]$/, '') ?? '';\n const passed = firstWord === this.passWhen.toUpperCase();\n const reasoning = raw.slice(firstWord.length).trim();\n\n return {\n passed,\n clauseName: this.name,\n clauseText: this.clauseText,\n clauseType: this.clauseType,\n judge: 'llm',\n details: reasoning,\n };\n } catch (e) {\n return {\n passed: false,\n clauseName: this.name,\n clauseText: this.clauseText,\n clauseType: this.clauseType,\n judge: 'llm',\n details: `Judge model error: ${e}`,\n };\n }\n }\n}\n","/** Base validator types. */\n\nexport interface RunContext {\n input: string;\n output: string;\n durationMs: number;\n costUsd: number;\n toolCalls: unknown[];\n steps: number;\n metadata: Record<string, unknown>;\n}\n\nexport function makeContext(partial: Partial<RunContext> & { input: string; output: string }): RunContext {\n return {\n durationMs: 0,\n costUsd: 0,\n toolCalls: [],\n steps: 0,\n metadata: {},\n ...partial,\n };\n}\n\nexport interface ValidationResult {\n passed: boolean;\n clauseName: string;\n clauseText: string;\n clauseType: string;\n judge: 'deterministic' | 'llm';\n details: string;\n}\n\nexport interface Validator {\n validate(context: RunContext): ValidationResult | Promise<ValidationResult>;\n}\n","/** enforce() — wraps any agent function with contract validation. */\n\nimport { Contract, getViolationAction, PreconditionClause } from './models.js';\nimport { ContractPreconditionError, ContractViolation } from './exceptions.js';\nimport { ContractRunner } from './runner.js';\nimport { makeContext } from './validators/base.js';\nimport { LLMValidator } from './validators/llm.js';\n\nexport interface EnforceOptions {\n audit?: boolean;\n auditPath?: string;\n costFn?: (result: unknown) => number;\n}\n\ntype AgentFn<T extends string | Promise<string>> = (input: string) => T;\n\nexport function enforce<T extends string | Promise<string>>(\n contract: Contract,\n fn: AgentFn<T>,\n options: EnforceOptions = {},\n): AgentFn<Promise<string>> {\n const { audit = true, auditPath = 'agentcontract-audit.jsonl', costFn } = options;\n const runner = new ContractRunner(contract);\n\n return async (input: string): Promise<string> => {\n // Preconditions\n await checkPreconditions(contract, input);\n\n // Run agent with timing\n const start = performance.now();\n const result = await Promise.resolve(fn(input));\n const durationMs = performance.now() - start;\n\n const output = String(result ?? '');\n const costUsd = costFn ? costFn(result) : 0;\n\n const ctx = makeContext({ input, output, durationMs, costUsd });\n const runResult = await runner.run(ctx);\n\n if (audit) {\n const { AuditWriter } = await import('./audit.js');\n new AuditWriter(auditPath).write(runResult);\n }\n\n // Warn violations → stderr\n const warnViolations = runResult.violations.filter((v) => v.actionTaken === 'warn');\n for (const v of warnViolations) {\n process.stderr.write(\n `[AgentContract WARN] ${v.clauseType.toUpperCase()}: \"${v.clauseText}\" — ${v.details}\\n`\n );\n }\n\n // Blocking violations → throw\n const blocking = runResult.violations.filter((v) =>\n ['block', 'rollback', 'halt_and_alert'].includes(v.actionTaken)\n );\n if (blocking.length > 0) {\n throw new ContractViolation(\n blocking.map((v) => ({\n clause_type: v.clauseType,\n clause_text: v.clauseText,\n action_taken: v.actionTaken,\n }))\n );\n }\n\n return output;\n };\n}\n\nasync function checkPreconditions(contract: Contract, input: string): Promise<void> {\n for (const precondition of contract.requires) {\n let text: string;\n let judge: string;\n let onFail: string;\n\n if (typeof precondition === 'string') {\n text = precondition;\n judge = 'deterministic';\n onFail = 'block';\n } else {\n text = precondition.text;\n judge = precondition.judge;\n onFail = precondition.on_fail;\n }\n\n let passed = true;\n let details = '';\n\n if (judge === 'deterministic') {\n if (/non-empty|not empty/i.test(text)) {\n passed = input.trim().length > 0;\n details = passed ? '' : 'Input is empty.';\n }\n } else if (judge === 'llm') {\n const ctx = makeContext({ input, output: '' });\n const result = await new LLMValidator(`requires:${text.slice(0, 30)}`, text, 'requires').validate(ctx);\n passed = result.passed;\n details = result.details;\n }\n\n if (!passed && onFail === 'block') {\n throw new ContractPreconditionError(text, details);\n }\n }\n}\n","/**\n * @agentcontract/core — Behavioral contracts for AI agents.\n * TypeScript reference implementation of the AgentContract specification.\n * https://github.com/agentcontract/spec\n */\n\nexport const VERSION = '0.1.0';\nexport const SPEC_VERSION = '0.1.0';\n\nexport { loadContract } from './loader.js';\nexport { enforce } from './enforce.js';\nexport { ContractRunner } from './runner.js';\nexport { AuditWriter } from './audit.js';\nexport { makeContext } from './validators/base.js';\n\nexport type { Contract, Clause, Assertion, Limits, OnViolation } from './models.js';\nexport type { RunContext, ValidationResult, Validator } from './validators/base.js';\nexport type { RunResult, ViolationRecord } from './runner.js';\nexport type { EnforceOptions } from './enforce.js';\n\nexport {\n ContractError,\n ContractLoadError,\n ContractPreconditionError,\n ContractViolation,\n} from './exceptions.js';\n"],"mappings":";AAEA,SAAS,oBAAoB;AAC7B,SAAS,eAAe;AACxB,OAAO,UAAU;;;ACFjB,SAAS,SAAS;AAEX,IAAM,YAAY,EAAE,KAAK,CAAC,iBAAiB,KAAK,CAAC,EAAE,QA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