# Scoped deterministic checks
Status: M0 contract for the capability compiler; not a claim of released functionality.
## Boundary
A check answers whether a declared predicate holds for the supplied facts and conditions. It does not execute an action, observe the filesystem, grant authority, establish that a caller's evidence is true, or turn a hypothesis into proof. Observation adapters and immutable receipts are separate later milestones.
One pure function must serve CLI, MCP and eventual WASM. Version one is opt-in. Existing banks and hooks are untouched.
## First wire contract
`instinct check validate|run|explain --input FILE|-` reads at most 1 MiB. No bank is opened or created. The first implementation covers the pure kernel below; no network, process launch, arbitrary scripts or host-path facts are interpreted as access grants.
```json
{
"check": {
"schema": "instinct.check/v1",
"id": "artifact-membership",
"revision": 1,
"inputs": {"actual": "set<string>", "allowed": "set<string>"},
"claim": {"op": "subset", "left": {"fact": "actual"}, "right": {"fact": "allowed"}},
"required_conditions": ["complete-inventory", "explicit-policy"],
"scope": {"project": "release-lab"}
},
"facts": {"actual": ["release.bin", "scratch.env"], "allowed": ["release.bin"]},
"conditions": {"complete-inventory": true, "explicit-policy": true},
"scope": {"project": "release-lab"}
}
```
The only top-level keys are `check`, `facts`, `conditions`, `scope`; `check` is required. Omitted facts/conditions/scope mean empty objects. Missing evidence is unknown, never false or globally valid. No null substitutes for absent objects.
Definition keys: `schema`, `id`, `revision`, `inputs`, `claim`, `required_conditions`, `scope`. First five required; conditions defaults empty list and scope defaults empty object. IDs: 1–128 ASCII letters/digits/`._-`, starting with a letter. Revision: JSON integer literal 1..2147483647, no exponent, fraction, sign or float rounding.
Scope keys: `project`, `persona`, `harness`, `version`, `machine`. Values are nonempty strings. A definition's omitted dimension imposes no restriction; an explicitly required dimension must match exactly. A missing required dimension abstains; a different value abstains. Never use environment variables implicitly for this pure API. Empty strings, null, unknown dimensions and wildcard syntax `*` are invalid. Keep names consistent with existing `eligibility::Scope`; do not create a second interpretation of legacy lesson scope.
### Types
- `string`: exact Unicode scalar sequence; no case-folding or normalization.
- `bool`: JSON true/false.
- `int`: canonical decimal **string** within signed i128 range (`0`, `-1`, `123`; no plus, exponent, fraction, leading zeros or negative zero). This avoids the legacy JSON parser's f64 precision loss.
- `set<string>`: array of unique exact strings. Input order is not semantic. Duplicate members are rejected, not silently counted twice.
Rational values and graph-specific operations remain explicit unsupported features of this first vertical increment; they must not be emulated with floats. They are tracked in M1 before its overall completion.
All supplied facts must be declared and correctly typed, even when a short-circuit could avoid reading them. Unknown keys or wrong types are errors. Missing declared facts are permitted and propagate abstention when needed. Conditions are a map of declared required-condition names to booleans. Missing/false required conditions abstain; unknown condition names are rejected. A caller saying true remains caller-reported, not independently observed evidence.
### Expressions
Operands are `{"fact":"declared-name"}` only in the first version. This keeps the meaning and types explicit and avoids implicit literal coercion. Supported predicates:
| Operator | Fields | Types |
|---|---|---|
| `subset`, `disjoint` | `op`, `left`, `right` | both `set<string>` |
| `contains` | `op`, `left`, `right` | `set<string>`, `string` |
| `eq` | `op`, `left`, `right` | identical supported types |
| `lt`, `lte` | `op`, `left`, `right` | both `int` |
| `all`, `any` | `op`, `args` | nonempty array of predicates |
| `not` | `op`, `arg` | one predicate |
Unknown fields/operators/references and mixed types are errors during compilation, even in unreachable branches. `all`/`any` operands are evaluated deterministically in document order within fuel; no external effects occur. `all`: any false => fail; otherwise unknown => abstain; all true => pass. `any`: any true => pass; otherwise unknown => abstain; all false => fail. `not` preserves unknown. A missing required condition or mismatched scope abstains at the check level, regardless of the claim expression.
Witnesses are deterministic and bounded: first lexicographic unexpected member for a failed subset, first common member for disjoint failure, otherwise a concise reason without exposing unrelated fact values. Explain reports the checked predicate/type/required evidence; it does not invent a rationale or expose the whole input.
## Results and errors
Success-shaped results use `schema: instinct.check-result/v1`, `check_id`, `revision`, `verdict` (`pass`, `fail`, `abstain`), `reason`, `witness` (string or null), `missing` (sorted unique names), `scope` (explicit current scope), `steps` and `authorization: not_evaluated`, `evidence_origin: caller_reported`.
`validate` compiles the full definition, validates provided facts/conditions/scope, and returns `schema: instinct.check-validation/v1`, `check_id`, `revision`, `valid: true`, `authorization: not_evaluated`. Missing facts are not a validation error. Validation must not be represented as a predicate PASS.
`explain` produces the same evaluated result plus `explanation` with the declared types, required conditions and scope. No additional inference or automatic action.
Invalid JSON, duplicate keys (including nested/Unicode-equivalent escaped keys), malformed definitions/types, invalid numerics and unknown fields yield structured JSON `schema: instinct.check-error/v1`, `verdict: error`, `reason`, `authorization: not_evaluated`, CLI exit 2. File/input I/O errors use the same shape. Valid fail/abstain exit 0. No logging before the JSON result. CLI argument duplicates/unknowns/extra positionals are errors; `--help` is explicit and side-effect-free.
## Limits and safety
- Wire: 1 MiB bytes; JSON nesting at most 64; reject duplicate keys and raw control characters.
- Claim: depth at most 32, at most 4096 expression nodes.
- Facts: at most 10000 entries and set members in aggregate.
- Evaluation: at most 100000 charged operations; each element visited/comparison is charged, not merely each AST node.
- Witness/explanation output: at most 64 KiB; do not allocate an unbounded error message containing the request.
Resource exhaustion yields a bounded `abstain` result where a valid definition can be identified; malformed or structurally unparseable requests yield error. Never panic/overflow or report partial evaluation as pass. All structural/type errors are found before evaluation. No unsafe Rust, shell, dependencies, I/O or global scope mutation in the pure evaluator. Native CLI input adapter is the only file reader in this increment.
## Compatibility and next milestones
Legacy JSON wire behavior outside `check` must not change accidentally. The current parser stores numbers as f64 and does not reject duplicate keys; the new adapter must strictly preflight its raw input before reusing the existing parser or use the coordinated strict research parser when available. Exact typed integers remain strings.
Policy and pure kernel sources are Helix-authored with generated Rust exports; public Cargo consumers do not need the compiler. Existing handwritten main dispatch can add the smallest integration seam. New modules and tests must be included in the explicit Cargo package allowlist and generated export checks.
M2 adds observations, hashes and receipts without confusing caller assertions with world evidence. M3 adds MCP/hook adapters. M4 reuses the coordinated research matcher; this module must not implement an alternative analogy engine.