import { LocalBoard } from "@consensus-tools/core";
// --- Initialize the board ---
const board = new LocalBoard({
mode: "local",
local: {
storage: { kind: "json", path: "./contract-review-state.json" },
jobDefaults: {
reward: 20,
stakeRequired: 5,
maxParticipants: 6,
expiresSeconds: 7200,
consensusPolicy: { type: "APPROVAL_VOTE", quorum: 4, threshold: 0.6 },
},
},
});
await board.init();
// --- The contract under review ---
const contract = {
vendor: "CloudScale Infrastructure Inc.",
annualValue: 2_400_000,
term: "3 years with auto-renewal",
effectiveDate: "2026-04-01",
aiRiskRating: "MODERATE",
aiRecommendation: "Sign with minor revisions to SLA section",
sections: {
liability: "Section 14.3(c): Provider's aggregate liability shall not be limited under this Agreement.",
ipRights: "Section 8.2: Client grants Provider a perpetual, irrevocable license to all data models, algorithms, and derivative works created using the Services.",
dataProcessing: "No Data Processing Addendum attached. Section 12 references 'standard security practices' without specifics.",
termination: "Section 22.1: Agreement auto-renews for successive 1-year terms. Cancellation requires 180 calendar days written notice prior to renewal date.",
},
jurisdictions: ["US-NY", "EU-DE", "EU-FR"],
};
console.log("CONTRACT REVIEW: " + contract.vendor);
console.log("Annual value: $" + contract.annualValue.toLocaleString());
console.log("AI recommendation: " + contract.aiRecommendation);
console.log("AI risk rating: " + contract.aiRiskRating);
console.log("");
// --- Post the guard job ---
const job = await board.engine.postJob("contract-review-system", {
title: `Guard review: ${contract.vendor} ($${(contract.annualValue / 1_000_000).toFixed(1)}M/yr)`,
reward: 20,
stakeRequired: 5,
});
console.log("Job posted: " + job.id);
console.log("Awaiting guard evaluations...");
console.log("");
// --- 4 specialist guards evaluate independently ---
const guards = [
{
id: "liability-reviewer",
verdict: "BLOCK",
confidence: 0.97,
findings: {
severity: "CRITICAL",
clause: "Section 14.3(c)",
issue: "Unlimited liability clause",
detail: "Provider's liability is explicitly unlimited. Standard cloud contracts cap liability at 12-24 months of fees. Unlimited liability on a $2.4M/yr contract exposes the firm to uncapped damages claims. This single clause could cost more than the entire contract value.",
recommendation: "Require liability cap at 12 months of fees paid ($2.4M). Add mutual limitation. Carve out only for IP infringement and confidentiality breach.",
},
},
{
id: "ip-counsel",
verdict: "BLOCK",
confidence: 0.94,
findings: {
severity: "CRITICAL",
clause: "Section 8.2",
issue: "Overbroad IP assignment — client data models at risk",
detail: "The 'perpetual, irrevocable license to all data models and derivative works' is extraordinarily broad. This could transfer ownership of the firm's proprietary client data models, ML training artifacts, and analytical frameworks to the vendor. For a law firm, this may include privileged work product.",
recommendation: "Replace with limited license scoped to service delivery only. Add explicit carve-out for client data, privileged materials, and firm IP. Require return/destruction of all data upon termination.",
},
},
{
id: "data-privacy-analyst",
verdict: "BLOCK",
confidence: 0.92,
findings: {
severity: "CRITICAL",
clause: "Missing DPA",
issue: "No Data Processing Addendum despite GDPR applicability",
detail: "Contract covers EU jurisdictions (DE, FR) but contains no DPA, no Standard Contractual Clauses, no specification of data controller/processor roles, and no breach notification timeline. Section 12 references 'standard security practices' — this is legally meaningless under GDPR Art. 28. Processing EU personal data without a DPA exposes the firm to fines up to 4% of annual turnover.",
recommendation: "Require GDPR-compliant DPA as mandatory exhibit. Include SCCs for cross-border transfers. Specify 72-hour breach notification. Define data retention and deletion obligations.",
},
},
{
id: "commercial-terms-reviewer",
verdict: "ESCALATE",
confidence: 0.85,
findings: {
severity: "HIGH",
clause: "Section 22.1",
issue: "Auto-renewal with 180-day cancellation notice is a trap",
detail: "180-day cancellation notice is 3-6x the industry standard (30-60 days). On a 3-year term, the firm must decide whether to renew 6 months before expiration — likely before they have enough performance data to evaluate. Combined with no SLA enforcement mechanism, the firm is locked in with no leverage.",
recommendation: "Negotiate to 60-day notice period. Add SLA credits with teeth (15-25% of monthly fees). Include termination-for-convenience clause with 90-day wind-down.",
},
},
];
for (const guard of guards) {
await board.engine.claimJob(guard.id, job.id, {
stakeAmount: 5,
leaseSeconds: 600,
});
await board.engine.submitJob(guard.id, job.id, {
summary: guard.verdict,
confidence: guard.confidence,
artifacts: {
severity: guard.findings.severity,
clause: guard.findings.clause,
issue: guard.findings.issue,
detail: guard.findings.detail,
recommendation: guard.findings.recommendation,
},
});
console.log(`[${guard.id}] ${guard.verdict} (confidence: ${guard.confidence})`);
console.log(` Severity: ${guard.findings.severity}`);
console.log(` Clause: ${guard.findings.clause}`);
console.log(` Issue: ${guard.findings.issue}`);
console.log(` Detail: ${guard.findings.detail}`);
console.log("");
}
// --- Resolve the consensus ---
const resolution = await board.engine.resolveJob("contract-review-system", job.id);
console.log("=".repeat(60));
console.log("CONSENSUS RESOLUTION");
console.log("=".repeat(60));
console.log("");
// --- Tally the verdicts ---
const verdicts = guards.map((g) => g.verdict);
const blockCount = verdicts.filter((v) => v === "BLOCK").length;
const escalateCount = verdicts.filter((v) => v === "ESCALATE").length;
const finalDecision = blockCount >= 2 ? "BLOCK" : escalateCount >= 2 ? "ESCALATE" : "ALLOW";
console.log("Final decision: " + finalDecision);
console.log("Block votes: " + blockCount + " of " + guards.length);
console.log("Escalate votes: " + escalateCount + " of " + guards.length);
console.log("Policy: " + resolution.policyType);
console.log("Winners: " + JSON.stringify(resolution.winners));
console.log("");
// --- Overrides the AI's original recommendation ---
console.log("AI recommended: " + contract.aiRecommendation);
console.log("Guard overrode AI: YES — 3 of 4 guards flagged critical issues");
console.log("");
// --- Summary of required actions before signing ---
console.log("REQUIRED ACTIONS BEFORE SIGNING:");
console.log("-".repeat(40));
for (const guard of guards) {
console.log(`[${guard.findings.severity}] ${guard.findings.issue}`);
console.log(` -> ${guard.findings.recommendation}`);
console.log("");
}
// --- What would have happened without the guard ---
console.log("=".repeat(60));
console.log("WITHOUT THIS GUARD:");
console.log("=".repeat(60));
console.log("");
console.log("The firm signs a $2.4M/year contract with:");
console.log(" - Unlimited liability exposure (no cap on damages)");
console.log(" - Vendor owns the firm's data models and derivative works");
console.log(" - No GDPR compliance (up to 4% of turnover in fines)");
console.log(" - 180-day cancellation trap (locked in with no leverage)");
console.log("");
console.log("Estimated risk exposure: $5M+ in liability, regulatory fines,");
console.log("and IP loss over the 3-year term.");
// --- Audit trail ---
console.log("");
console.log("=".repeat(60));
console.log("AUDIT TRAIL");
console.log("=".repeat(60));
console.log("");
console.log("All guard evaluations, votes, and the final resolution are");
console.log("stored in contract-review-state.json for regulatory and");
console.log("malpractice defense purposes.");
console.log("");
console.log("Job ID: " + job.id);
console.log("Timestamp: " + new Date().toISOString());
console.log("Contract: " + contract.vendor);
console.log("Annual value: $" + contract.annualValue.toLocaleString());
console.log("Guard count: " + guards.length);
console.log("Decision: " + finalDecision);