UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

99 lines • 4.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkFindingClaim = void 0; /** * Pure opt-in findings adapter. Role: bind one literal declaration to an exact * authorized result, then ask the shared evaluator; return a row for the EXISTING * findings writer. No ledger, evidence discovery, callbacks on restore or I/O. */ const boundedJson_js_1 = require("../../../lib/boundedJson.js"); const bindEvidence_js_1 = require("../../../integrity/claim-binding/bindEvidence.js"); const scope_js_1 = require("../../../integrity/claim-binding/scope.js"); const evaluate_js_1 = require("../../../integrity/unsupported-claim/evaluate.js"); const verificationRow_js_1 = require("./verificationRow.js"); /** * Invalid/missing JSON value throws explicitly: replacing it with null would * misrecord the declaration. A malformed optional check is a recorded refusal. * `supported` is possible only after bindClaim establishes an eligible pair; * the standalone evaluator's no-conflict result is never sufficient. */ function checkFindingClaim(input) { const request = (0, boundedJson_js_1.ownData)(input.request); if (!Object.hasOwn(request, 'value')) throw new TypeError('Finding claim has no declared value.'); const declaredValue = (0, boundedJson_js_1.copyJson)(request.value, verificationRow_js_1.VERIFICATION_LIMITS.valueBytes, true); let declaredRule; let checkProblem; if (!Object.hasOwn(request, 'check')) checkProblem = 'missing-check'; else { try { const check = (0, boundedJson_js_1.ownData)(request.check); if ((0, scope_js_1.boundedText)(check.rule)) declaredRule = check.rule; if (Object.keys(check).some((key) => key !== 'rule') || declaredRule === undefined) checkProblem = 'malformed-check'; } catch { checkProblem = 'malformed-check'; } } if (Object.keys(request).some((key) => !['value', 'check', 'subject', 'predicate'].includes(key))) checkProblem = 'malformed-check'; const base = { kind: 'claim-verification', claimId: (0, verificationRow_js_1.claimIdentityOf)(input.identity), declaredOn: input.declaredOn, standing: input.standing, iteration: input.iteration, ...(input.turn !== undefined && { turn: input.turn }), checker: { id: 'claim-pair', version: 1 }, ...(input.parentResult !== undefined && { declaredResult: input.parentResult }), ...(declaredRule !== undefined && { declaredRule }), declaredValue, }; const unverified = (reason) => (0, verificationRow_js_1.readClaimVerificationRow)({ ...base, outcome: 'unverified', reason }); if (input.standing === 'noise') return unverified('ineligible-noise'); if (checkProblem !== undefined) return unverified(checkProblem); if (input.parentResult === undefined) return unverified('missing-result'); const bound = (0, bindEvidence_js_1.bindClaim)({ result: input.parentResult, value: declaredValue, rule: declaredRule }, input.snapshot, input.rules, input.intendedScope); if (bound.kind === 'unverified') return unverified(bound.reason === 'missing-result' && input.retentionLimited === true ? 'retention-limit' : bound.reason); if (Object.hasOwn(request, 'subject') || Object.hasOwn(request, 'predicate')) { try { const subject = (0, boundedJson_js_1.ownData)(request.subject, ['kind', 'id']); if (subject.kind !== bound.claim.subject.kind || subject.id !== bound.claim.subject.id || request.predicate !== bound.claim.predicate) return unverified('assertion-mismatch'); } catch { return unverified('assertion-mismatch'); } } const reason = (0, evaluate_js_1.evaluateClaimPair)(bound.evidence, bound.claim); if (reason !== 'no-conflict' && reason !== 'numeric-leniency' && reason !== 'conflict') return unverified(reason); const resolved = { resultId: bound.resultId, rule: bound.rule, scope: bound.scope, coverage: bound.coverage, ...(bound.period !== undefined && { period: bound.period }), evidence: bound.evidence, claim: bound.claim, }; return (0, verificationRow_js_1.readClaimVerificationRow)({ ...base, outcome: reason === 'conflict' ? 'contradicted' : 'supported', reason, resolved, }); } exports.checkFindingClaim = checkFindingClaim; //# sourceMappingURL=verificationCheck.js.map