@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 @@
|
|
|
1
|
+
{"version":3,"sources":["../node_modules/tsup/assets/cjs_shims.js","../src/audit.ts","../src/index.ts","../src/loader.ts","../src/models.ts","../src/exceptions.ts","../src/enforce.ts","../src/runner.ts","../src/validators/pattern.ts","../src/validators/cost.ts","../src/validators/latency.ts","../src/validators/llm.ts","../src/validators/base.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","/** Audit trail — tamper-evident JSONL entries for every run. */\n\nimport { createHash, createHmac } from 'crypto';\nimport { appendFileSync } from 'fs';\nimport type { RunResult } from './runner.js';\n\nexport class AuditWriter {\n constructor(private logPath = 'agentcontract-audit.jsonl') {}\n\n write(result: RunResult, contractPath = ''): Record<string, unknown> {\n const entry = this._buildEntry(result, contractPath);\n appendFileSync(this.logPath, JSON.stringify(entry) + '\\n', 'utf-8');\n return entry;\n }\n\n private _buildEntry(result: RunResult, contractPath: string): Record<string, unknown> {\n const ctx = result.context;\n const inputHash = createHash('sha256').update(ctx.input).digest('hex');\n const outputHash = createHash('sha256').update(ctx.output).digest('hex');\n\n const entry: Record<string, unknown> = {\n run_id: result.runId,\n agent: result.agent,\n contract: contractPath,\n contract_version: result.contractVersion,\n timestamp: new Date().toISOString(),\n input_hash: inputHash,\n output_hash: outputHash,\n duration_ms: Math.round(ctx.durationMs * 100) / 100,\n cost_usd: Math.round(ctx.costUsd * 1_000_000) / 1_000_000,\n violations: result.violations.map((v) => ({\n clause_type: v.clauseType,\n clause_name: v.clauseName,\n clause_text: v.clauseText,\n severity: v.severity,\n action_taken: v.actionTaken,\n judge: v.judge,\n details: v.details,\n })),\n outcome: result.outcome,\n };\n\n const auditKey = process.env['AGENTCONTRACT_AUDIT_KEY'];\n if (auditKey) {\n const payload = JSON.stringify(entry, Object.keys(entry).sort());\n entry['signature'] = createHmac('sha256', auditKey).update(payload).digest('hex');\n }\n\n return entry;\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","/** 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","/** 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","/** 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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Q;AACR,eAAS;AAAA,IACX,OAAO;AACL,aAAO,aAAa;AACpB,cAAQ,aAAa;AACrB,eAAS,aAAa;AAAA,IACxB;AAEA,QAAI,SAAS;AACb,QAAI,UAAU;AAEd,QAAI,UAAU,iBAAiB;AAC7B,UAAI,uBAAuB,KAAK,IAAI,GAAG;AACrC,iBAAS,MAAM,KAAK,EAAE,SAAS;AAC/B,kBAAU,SAAS,KAAK;AAAA,MAC1B;AAAA,IACF,WAAW,UAAU,OAAO;AAC1B,YAAM,MAAM,YAAY,EAAE,OAAO,QAAQ,GAAG,CAAC;AAC7C,YAAM,SAAS,MAAM,IAAI,aAAa,YAAY,KAAK,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM,UAAU,EAAE,SAAS,GAAG;AACrG,eAAS,OAAO;AAChB,gBAAU,OAAO;AAAA,IACnB;AAEA,QAAI,CAAC,UAAU,WAAW,SAAS;AACjC,YAAM,IAAI,0BAA0B,MAAM,OAAO;AAAA,IACnD;AAAA,EACF;AACF;;;AJ7FA;AANO,IAAM,UAAU;AAChB,IAAM,eAAe;","names":["import_crypto","import_fs","yaml","AuditWriter"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContractError,
|
|
3
|
+
ContractLoadError,
|
|
4
|
+
ContractPreconditionError,
|
|
5
|
+
ContractRunner,
|
|
6
|
+
ContractViolation,
|
|
7
|
+
SPEC_VERSION,
|
|
8
|
+
VERSION,
|
|
9
|
+
enforce,
|
|
10
|
+
loadContract,
|
|
11
|
+
makeContext
|
|
12
|
+
} from "./chunk-UHNX2RBZ.mjs";
|
|
13
|
+
import {
|
|
14
|
+
AuditWriter
|
|
15
|
+
} from "./chunk-BVUHPJDU.mjs";
|
|
16
|
+
export {
|
|
17
|
+
AuditWriter,
|
|
18
|
+
ContractError,
|
|
19
|
+
ContractLoadError,
|
|
20
|
+
ContractPreconditionError,
|
|
21
|
+
ContractRunner,
|
|
22
|
+
ContractViolation,
|
|
23
|
+
SPEC_VERSION,
|
|
24
|
+
VERSION,
|
|
25
|
+
enforce,
|
|
26
|
+
loadContract,
|
|
27
|
+
makeContext
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentcontract/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Behavioral contracts for AI agents — TypeScript implementation of the AgentContract specification",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"agentcontract": "dist/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": ["dist"],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"test:watch": "vitest",
|
|
23
|
+
"lint": "tsc --noEmit",
|
|
24
|
+
"prepublishOnly": "npm run build && npm test"
|
|
25
|
+
},
|
|
26
|
+
"keywords": ["ai", "agents", "contracts", "llm", "safety", "compliance", "validation", "agentcontract"],
|
|
27
|
+
"author": "Mauro Moro",
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/agentcontract/agentcontract-ts.git"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/agentcontract/spec",
|
|
34
|
+
"bugs": { "url": "https://github.com/agentcontract/agentcontract-ts/issues" },
|
|
35
|
+
"engines": { "node": ">=18" },
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"commander": "^13.0.0",
|
|
38
|
+
"js-yaml": "^4.1.0",
|
|
39
|
+
"zod": "^3.22.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/js-yaml": "^4.0.9",
|
|
43
|
+
"@types/node": "^22.0.0",
|
|
44
|
+
"tsup": "^8.0.0",
|
|
45
|
+
"typescript": "^5.4.0",
|
|
46
|
+
"vitest": "^2.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@anthropic-ai/sdk": ">=0.20.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"@anthropic-ai/sdk": { "optional": true }
|
|
53
|
+
}
|
|
54
|
+
}
|