UNPKG

agentfootprint

Version:

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

42 lines • 2.3 kB
/** * coverage — what a run's records are served under, as a typed value with * THREE states. `undefined` is never "no policy". * * Pattern: a closed discriminated union, decided where the library positively * knows the answer and switched on wherever a record is served. * Role: the one vocabulary every serving door resolves to * (`runRedaction.ts` · `coverageOfExecutor`, `declared.ts` · * `declarationOf`, `EventDispatcher` · `served`): * * - `covered` — the run was opened with a policy: serve under it. * - `declared-none` — POSITIVELY known to have none: the run was opened by * this library with no policy, or the runner declared * none when it was built. Served unchanged. * - `unknown` — the executor, the run, the scope or the runner is not * one this library recorded: nothing says what its * records may show. FAIL CLOSED, whatever the instance * declares — a placeholder for an event, a refusal for * a snapshot or a record. * * A lookup that misses is `unknown`, never `declared-none`: the difference * between "this run had no policy" and "this run is not one we know" is the * difference between serving a record and serving another run's raw values. */ /** Positively no policy. */ export const DECLARED_NONE = Object.freeze({ state: 'declared-none' }); /** Not recorded by this library — fail closed. */ export const UNKNOWN_COVERAGE = Object.freeze({ state: 'unknown' }); /** * The coverage of a run THIS library opened, from the policy it computed for * the run — the union of typed declarations and the policies handed to the * run. Here, and only here, an absent policy is a positive fact: every input * of the union was itself known. */ export function coverageOfOpenedRun(policy) { return policy === undefined ? DECLARED_NONE : Object.freeze({ state: 'covered', policy }); } /** The policy a coverage serves under — `undefined` for `declared-none` only; `unknown` has none to give. */ export function policyOfCoverage(coverage) { return coverage.state === 'covered' ? coverage.policy : undefined; } //# sourceMappingURL=coverage.js.map