UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

41 lines (40 loc) • 3.18 kB
/** * The conservative value-sameness proof the park mint reads when it decides whether a fidelity projection * moved a value, and whether a policy's rewrite names the very value about to be filed. A leaf: no imports. */ /** * CONSERVATIVE "these two are provably the same value" for deciding whether a * {@link import("./checkpoint-store.js").encodeAtFidelity} projection moved anything, and whether a policy's * rewrite names the very value about to be filed. * * Deliberately NOT the binding hash, which is the wrong instrument for this question in two directions: * it folds `-0` onto `0` (a real projection change the policy may care about, invisible to the hash), and * it is a digest, so a collision would read as sameness. `Object.is` at the leaves keeps the `-0` * distinction; comparing own-key SETS keeps the dropped `undefined`-valued key visible. * * Conservative on purpose — the answer it must never give wrongly is TRUE, because both callers read * TRUE as "nothing moved / the policy named this very value" and act by filing. So sameness has to be * PROVED, not merely un-disproved: * - the PROTOTYPES must match and be the plain-object or array one. `[object Object]` is not proof of * a plain object — a class instance and a null-prototype object both report it, and a tool executing * the arguments can observe inherited behaviour. (Neither input to the projection comparison can be * such a value: `structuredClone` and `JSON.parse` both produce plain data. A policy's rewrite can.) * - own keys are compared with `Reflect.ownKeys` and POSITIONALLY, so a SYMBOL key or a non-enumerable * property on one side is a difference rather than an invisible extra, and so is a different order * (which `Object.keys`, `JSON.stringify` and any tool iterating its arguments can see). * - properties are compared through their DESCRIPTORS — every flag, so a frozen object is not the * mutable value a JSON decode produces — and an accessor on either side answers FALSE without being * read: an approval decision must not be made by running deployment code, and what a getter returns * need not be the same twice. * - reference TOPOLOGY counts: two properties that share one object are not two properties holding * equal objects, and a JSON round trip is precisely what turns the first into the second. * - what it CANNOT prove on its own is that the value it inspected answers ordinary reads the way its * descriptors did — a Proxy reports the target's descriptors and can return anything from a `get`. * A caller comparing a value it did not construct must first establish that it is an inert data * graph (the capture clone does exactly that, and refuses a Proxy outright). * - any brand outside plain object/array that is not already reference-identical answers FALSE (a Date * is never the string a JSON codec leaves behind, a Map is never the `{}`), and so does any * inspection that throws. * An uncertain answer therefore costs a policy consultation or a park, never a silently filed value. */ export declare function samePlainValue(a: unknown, b: unknown): boolean;