UNPKG

agentfootprint

Version:

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

76 lines • 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.projectCauseBasis = void 0; const cause_1 = require("foottrace/cause"); const causeCapture_js_1 = require("./causeCapture.js"); const causeControl_js_1 = require("./causeControl.js"); /** A snapshot projection, not another dependence walker. The public reader owns all graph reasoning. */ function projectCauseBasis(snapshot, nodes, controlDeps, extras) { // A snapshot-local namespace is not a storage address or a service-correlation claim. const recordedAddress = (0, causeCapture_js_1.captureOwn)(snapshot, 'logAddress'); const runId = (0, causeCapture_js_1.captureOwn)(snapshot, 'runId'); const address = recordedAddress ?? (typeof runId === 'string' ? { logRunId: `snapshot:${runId}`, drillPath: [] } : undefined); if (address === undefined) return undefined; const log = (0, causeCapture_js_1.captureOwn)(snapshot, 'commitLog'); if (!Array.isArray(log)) return undefined; if (log.length > 4096) return 'truncated'; let capture = extras?.sources ? (0, causeCapture_js_1.assessSourceCapture)(snapshot, log.length, extras.sources.status) : (0, causeCapture_js_1.assessCapture)(snapshot, log.length); const nativeControl = capture.status === 'admitted' ? (0, causeControl_js_1.capturedControl)(snapshot) : undefined; if (capture.status === 'admitted' && nativeControl === undefined) capture = (0, causeCapture_js_1.captureAssessment)('control-not-retained', capture.readSources); const reads = Object.create(null); const marks = Object.create(null); const control = Object.create(null); let visited = 0; for (const [id, stage] of nodes) { if (visited++ >= 4096) return 'truncated'; const capturedReads = (0, causeCapture_js_1.captureOwn)(stage, 'stageReads'); if (capturedReads !== null && typeof capturedReads === 'object') reads[id] = Object.keys(capturedReads); else if (capture.status === 'admitted') reads[id] = []; const omitted = extras?.readKeys?.get(id); if (omitted) reads[id] = [...new Set([...(reads[id] ?? []), ...omitted])]; const attention = (0, causeCapture_js_1.captureOwn)(stage, 'attention'); if (attention !== undefined) marks[id] = attention; const parent = nativeControl === undefined ? controlDeps?.()?.(id) : nativeControl[id]; if (parent !== undefined) control[id] = { deciderId: parent.deciderId }; } if (capture.status === 'admitted' && log.some((bundle) => !nodes.has((0, causeCapture_js_1.captureOwn)(bundle, 'runtimeStageId')))) capture = (0, causeCapture_js_1.captureAssessment)('projection-incomplete', capture.readSources); const complete = capture.status === 'admitted'; const scopeAddress = (complete && (0, causeCapture_js_1.captureAddress)((0, causeCapture_js_1.captureOwn)(snapshot, 'logAddress'))) || address; const scope = { address: scopeAddress, commitLog: log, reads, ...(complete || Object.keys(marks).length ? { attention: marks } : {}), ...(nativeControl === undefined && controlDeps?.() === undefined ? {} : { controlDeps: control }), complete, ...(extras?.initialState === undefined ? {} : { initialState: extras.initialState }), ...(extras?.sources === undefined ? {} : { readSources: extras.sources.scope }), }; const graph = (0, cause_1.createRecordGraph)([scope], { maxCommits: 4096 }); // The public scope reader admits untrusted commits and creates its own official IDs. return { graph: { ...graph, roots: (context) => graph.openScope(scopeAddress, context) }, capture, }; } exports.projectCauseBasis = projectCauseBasis; //# sourceMappingURL=causeProjection.js.map