Files
rea/experiments/atomic-codemode/native-projection-contract.mjs
T
8114bd675e feat(experiment): expose bounded call-rooted definition facts
Share native membership and operand ownership across full and projected facts. Preserve exact phi bindings and definition frontiers when the full graph is unavailable, keep CFG/use coverage explicit, and expose selected reads through the same CLI/SDK/MCP contracts. Verify real SQLite/zlib fidelity, encoded fallback, bounded metadata, and cache reuse; pin the next real-model question and oracle.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 11:16:26 +00:00

69 lines
2.0 KiB
JavaScript

// Sparse facts retain their own resource, root and frontier contract.
import { z } from "zod";
import {
operationId,
value,
rowParser,
requireFact,
readNativeFacet,
} from "./native-contract.mjs";
import { operation, parseOperation } from "./native-operation-contract.mjs";
const frontier = z.strictObject({
definition: operationId,
reason: z.enum(["operation-budget", "outside-recovered-membership"]),
});
const coverage = z.strictObject({
scope: z.string(),
operation_budget: z.literal(4096),
frontier: z.array(frontier).max(12288),
issues: z.array(z.string()).max(4096),
machine_semantic_equivalence: z.literal("unknown"),
});
const schema = z.strictObject({
schema_version: z.literal(1),
roots: z.array(operationId).max(4096),
operations: z.array(operation).max(4096),
values: z.array(value).max(12288),
coverage,
});
const parseCoverage = rowParser(coverage, {
frontier: (row) => frontier.parse(row),
issues: (row) => z.string().parse(row),
});
const parseProjection = rowParser(
schema,
{
roots: (row) => operationId.parse(row),
operations: parseOperation,
values: (row) => value.parse(row),
},
{ coverage: parseCoverage },
);
export const readProjectionFacet = (fn) =>
readNativeFacet(fn, "atomic_projection", "operation projection", (raw) => {
requireFact(
raw?.schema_version === 1,
"Unsupported native projection schema",
);
for (const [rows, limit] of [
[raw.roots, 4096],
[raw.operations, 4096],
[raw.values, 12288],
[raw.coverage?.frontier, 12288],
[raw.coverage?.issues, 4096],
])
requireFact(
Array.isArray(rows) && rows.length <= limit,
"Native projection exceeds capacity or has invalid shape",
);
requireFact(
raw.operations.reduce(
(n, op) => n + (Array.isArray(op?.inputs) ? op.inputs.length : 0),
0,
) <= 16384,
"Native projection input capacity exceeded",
);
return parseProjection(raw);
});