Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- name: Tests
run: pnpm test

- name: Verify Assay documentation examples against the public release
run: node scripts/verify-assay-examples.mjs

- name: Build
run: pnpm build

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ jobs:
- name: Tests
run: pnpm test

- name: Verify Assay documentation examples against the public release
run: node scripts/verify-assay-examples.mjs

- name: Build selected Cloudflare environment
env:
TARGET: ${{ inputs.target }}
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ Fumadocs MDX uses `async: true`, so individual documents are compiled into page-
## Design system

The shared tokens, fonts and base styles in `src/app.css` are synchronized from [the platform design system](https://github.com/0xbuffdev/platform/blob/16241087830ddd0c96ae7dd7ba81023cd8892365/packages/ui/src/styles/app.css). Keep the Fumadocs adapter, local source detection and documentation-specific rules when updating that snapshot. The documentation application does not import the platform's private workspace packages.

## Assay documentation

The Assay collection documents the public release [v0.0.1](https://github.com/0xbuffdev/assay/tree/v0.0.1). Use its package exports, contract types, tests and versioned guides as the technical source of truth. Do not document unreleased behavior as available.

Keep the Assay sidebar compact: installation is the index, evaluation covers criteria and composition, observations covers execution and reviews, integrity covers protected references and disclosure, and two reference pages cover the API and contracts. Use headings within those pages for related topics; add a page only for a distinct reader need. Use sentence-case titles, direct language, explicit prerequisites and expected results. Keep code fragments distinct from complete examples. Use Mermaid for data flows and trust boundaries, not decorative diagrams.

The editorial approach draws on [Vercel's writing guidelines](https://github.com/vercel-labs/writing-guidelines), [Cloudflare's style guide](https://developers.cloudflare.com/style-guide/), [Mintlify's developer documentation checklist](https://www.mintlify.com/library/developer-documentation-best-practices) and [Diátaxis](https://diataxis.fr/). Apply the Content repository's humanizer skill when editing prose.

Run `pnpm test` for the documentation structure and internal-link checks. Run `node scripts/verify-assay-examples.mjs` to install the pinned public release in a temporary directory, execute the marked examples, and compare the documented API and limits with the installed package. This requires registry access and Node 24; it does not add Assay to the documentation application's dependency graph. CI and the release workflow run both checks. Update the example verification and all affected version references when adopting a new Assay release.
94 changes: 94 additions & 0 deletions content/docs/assay/api.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: "API reference"
description: "Look up the public functions, constants and return contracts exported by Assay."
---

Import from `@0xbuff/assay`. The package root is the supported import path. All functions except `collectObservations` are synchronous. Inputs to validation and integrity functions are accepted as unknown and checked at runtime.

## Evaluation

| Function | Return | Behavior |
| --- | --- | --- |
| `evaluate(definition, evidence, references?)` | EvaluationResponse | Verify inputs, compare criteria and compose required outcomes. |
| `inspectEvidenceCoverage(definition, evidence)` | ValidationResult of EvidenceCoverage | List missing and incomplete required criteria without evaluating them. |
| `projectPublicResult(definition, result)` | PublicProjectionResponse | Validate a full result and create its public projection. |

`EvaluationResponse` is either a complete result or an invalid-input failure. Inspect `outcome` before accessing findings. See [outcomes](/docs/assay/contracts#outcomes-and-errors).

## Definition integrity

| Function | Return | Behavior |
| --- | --- | --- |
| `computeDefinitionDigest(draft)` | ValidationResult of string | Validate an unsigned draft and compute its digest. |
| `createAssessmentDefinition(draft)` | ValidationResult of AssessmentDefinition | Validate, derive the digest and seal the definition. |
| `verifyAssessmentDefinition(definition)` | ValidationResult of AssessmentDefinition | Verify structure and content digest. |

## Evidence and reference integrity

| Function | Return | Behavior |
| --- | --- | --- |
| `createEvidenceBundle(definition, draft)` | ValidationResult of EvidenceBundle | Verify the definition, bind observations and derive the evidence digest. |
| `verifyEvidenceBundle(definition, evidence)` | ValidationResult of EvidenceBundle | Verify evidence digest, coverage and definition lineage. |
| `createReferenceRecord(draft)` | ValidationResult of ReferenceRecord | Validate and seal a typed reference value. |
| `verifyReferenceBundle(definition, bundle)` | ValidationResult of ReferenceBundle | Verify every supplied record against its authorized definition. |

## Structural parsing

These functions check closed record shapes and resource limits. Structural parsing does not recompute the record's digest or authenticate its source.

| Function | Successful value |
| --- | --- |
| `parseAssessmentDefinitionDraft(input)` | AssessmentDefinitionDraft |
| `parseAssessmentDefinition(input)` | AssessmentDefinition |
| `parseEvidenceBundle(input)` | EvidenceBundle |
| `parseObservationPortReport(input)` | ObservationPortReport |
| `parseEvaluationResult(input)` | EvaluationResult |
| `decodeSerializedRecord(input)` | Bounded immutable JSON object; duplicate keys rejected |

The first five return ValidationResult of their corresponding type. The decoder returns SerializedRecordResult.

## Observation collection

`collectObservations(definition, evidence, port, options?)` returns a Promise of ObservationCollectionResult. Supply an optional signal in `options.signal`. The host implements the port. See [collection guide](/docs/assay/observations#observation-ports).

## Constants

| Export | Value or purpose |
| --- | --- |
| ASSAY_SCHEMA_VERSION | 4 |
| ASSAY_EVALUATOR_VERSION | v0.0.5 |
| CONTRACT_LIMITS | Frozen object containing the bounds listed in [limits](/docs/assay/contracts#resource-limits). |

## Return wrappers


```ts
type ValidationResult<T> =
| Readonly<{ ok: true; value: T }>
| Readonly<{
ok: false;
domain: ValidationDomain;
diagnostics: readonly ValidationDiagnostic[];
}>;
```

The serialized decoder uses the same success shape but its failure has diagnostics without a domain. Projection returns an opaque failure with `reasonCode` instead of diagnostics. Collection returns evidence and receipt directly on success and has distinct failure variants.

Always check `ok` before reading `value` or `evidence`.

## Public types

The installed declarations are the exact type reference. The following groups cover the package's public type exports.

| Area | Types |
| --- | --- |
| Common | Completeness, ExecutionFact, ExecutionTermination, JsonValue, NumericRange, SetItemType, SetScalar |
| Definition | AssessmentDefinition, AssessmentDefinitionDraft, CompositionChild, Criterion, CriterionBase, CriterionComposition, CriterionGroup, CriterionMode, DefinitionReference, Expected, PolicyVersion, ReferenceVisibility, TextNormalization |
| Evidence | EvidenceBundle, EvidenceBundleDraft, Observation, ObservationBase, ObservationFact, ObservationOrigin, ObservationPortProvenance, QualitativeObservation, QualitativeReviewer, ReviewCitation |
| References | ReferenceBundle, ReferenceRecord, ReferenceRecordDraft |
| Collection | ObservationAbortSignal, ObservationCollectionOptions, ObservationCollectionResult, ObservationPort, ObservationPortCriterion, ObservationPortKind, ObservationPortReceipt, ObservationPortReport, ObservationPortRequest |
| Evaluation | CriterionFinding, EvaluationFailure, EvaluationResponse, EvaluationResult, FindingOutcome, ReasonCode, TechnicalOutcome, WarningCode |
| Projection | PublicCriterionFinding, PublicProjectionResponse, PublicReason, PublicTechnicalOutcome, PublicTechnicalResult |
| Validation | DiagnosticCode, EvidenceCoverage, SerializedRecordResult, ValidationDiagnostic, ValidationDomain, ValidationResult |

See the [public entry point](https://github.com/0xbuffdev/assay/blob/v0.0.1/src/index.ts) and [record reference](/docs/assay/contracts) for exact shapes.
221 changes: 221 additions & 0 deletions content/docs/assay/contracts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
---
title: "Contracts and errors"
description: "Record shapes, outcomes, diagnostics and resource limits."
---

All versioned public records use schema version 4. Record fields are closed: unknown fields, unsupported versions and invalid values are rejected. The TypeScript declarations in the released package define the exact unions.

## AssessmentDefinition

| Field | Type | Required |
| --- | --- | --- |
| schemaVersion | 4 | Yes |
| assessmentId | string | Yes |
| revision | string | Yes |
| revisionDigest | SHA-256 digest | Sealed record only |
| policyVersion | composed-required-v1 | Yes |
| criteria | Criterion array | Yes |
| composition | CriterionComposition | Yes |

A draft omits revisionDigest. Criterion IDs are unique. Revision must identify a stable revision, not latest.

### Criterion

All criteria have `id: string`, `kind`, `mode: "required" | "advisory"`, `visibility: "public" | "restricted"` and `parameters`. Only supported objective kinds accept a top-level executionFact.

| Kind | Parameter fields |
| --- | --- |
| exact_text | expected |
| normalized_text | expected, normalization |
| number_with_tolerance | expected, tolerance, optional unit |
| number_range | expected, optional unit |
| set_equivalence | expected, itemType, order, duplicates |
| boolean_equality | expected |
| json_equality | expected |
| observed_execution | assertions (array of id/referenceId pairs) |
| manual_evidence | review: required |
| qualitative_review | reviewPolicyId, reviewPolicyVersion |

An expected value is either a literal with type and value, or a reference with type, referenceId and referenceDigest. Restricted objective criteria require the reference form. See [criteria](/docs/assay/evaluation#criteria) for value types and rules.

Composition contains rootGroupId and groups. A group has id, operator (all or any), and children, each with kind (criterion or group) and id. See [composition](/docs/assay/evaluation#composition).

## EvidenceBundle

| Field | Type | Required |
| --- | --- | --- |
| schemaVersion | 4 | Yes |
| definition | DefinitionReference | Sealed record only |
| evidenceDigest | SHA-256 digest | Sealed record only |
| artifactDigest | SHA-256 digest | No |
| observations | Observation array | Yes |

DefinitionReference contains assessmentId, revision and revisionDigest. The draft omits definition and evidenceDigest.

### Observation

Common fields are criterionId, evidenceRef, kind and completeness (complete or truncated). Criterion IDs must refer to declared criteria and observation/evidence reference IDs cannot repeat.

| Kind | Additional fields |
| --- | --- |
| text | value: string |
| number | value: finite number; optional unit |
| set | items: scalar array; itemType |
| boolean | value: boolean |
| json | value: JSON |
| execution | runRef; assertions with assertionId and state (confirmed, refuted, unknown) |
| manual | artifactRefs: string array |
| qualitative_review | origin, reviewPolicyId, reviewPolicyVersion, reviewer, uncertainty, feedback, citations |

Objective selected facts also carry executionFact and an origin with runRef and termination. Other observations may have an origin as permitted by the scope rules. See [evidence](/docs/assay/evaluation#evidence), [execution facts](/docs/assay/observations#execution-facts) and [qualitative reviews](/docs/assay/observations#qualitative-reviews).

## ReferenceRecord and ReferenceBundle

A reference draft has schemaVersion, referenceId, kind and value. Numeric/range records accept an optional unit; set records require itemType. A sealed reference adds referenceDigest.

Reference kinds are text, number, range, set, boolean and json. The bundle has schemaVersion, definition and references, an array of sealed records. It does not have its own digest.

## EvaluationResponse

A complete result has schemaVersion, definition, evidenceDigest, optional artifactDigest, outcome, policyVersion, findings, evaluator and warnings. The evaluator has id and version. Each finding has criterionId, outcome, reasonCode, evidenceRefs, evaluatorId and evaluatorVersion.

An invalid-input failure has outcome and diagnostics only. Do not assume that definition or findings exist on a failure.

## Observation port

Request fields: schemaVersion, definition, optional artifactDigest, criteria and limits.maxCapturedBytes. Each requested criterion includes criterionId, kind and applicable unit, itemType, assertionIds or executionFact.

Report fields: schemaVersion, definition, optional artifactDigest, provenance, observations and termination where required. A receipt contains definition, evidenceDigest, evidenceRefs, optional termination/artifactDigest and provenance. See [report requirements](/docs/assay/observations#observation-ports).

## PublicTechnicalResult

| Field | Type |
| --- | --- |
| schemaVersion | 4 |
| outcome | pass, fail, inconclusive, evaluation_error or withheld |
| findings | Array of criterionId, outcome and reason |

No evidence references or private warnings are included. See [projection](/docs/assay/integrity#public-projection).

The [contract source](https://github.com/0xbuffdev/assay/tree/v0.0.1/src/contracts) defines the complete field unions and types.

## Outcomes and errors

### Evaluation outcomes

| Outcome | Meaning |
| --- | --- |
| pass | The required composition is satisfied. |
| fail | The required composition has a decisive mismatch. |
| inconclusive | The required composition cannot be resolved. |
| evaluation_error | A comparison error determines the required composition. |
| invalid_definition | The definition is malformed or fails integrity checks. |
| invalid_reference | Supplied reference material is invalid or does not match. |
| invalid_evidence | Evidence is malformed, incompatible or fails integrity checks. |

The first four return complete findings; the last three return only diagnostics. The required aggregate uses the precedence in [composition](/docs/assay/evaluation#composition).

### Criterion findings

| Finding outcome | Reason code | Meaning |
| --- | --- | --- |
| pass | MATCH | Observed value matches. |
| fail | VALUE_MISMATCH | Observed value does not match. |
| inconclusive | REFERENCE_UNAVAILABLE | Required reference value unavailable. |
| inconclusive | EVIDENCE_MISSING | Observation absent. |
| inconclusive | EVIDENCE_TRUNCATED | Observation incomplete. |
| inconclusive | ASSERTION_INCOMPLETE | Execution assertion incomplete. |
| inconclusive | EXECUTION_UNVERIFIED | Assertion claim cannot establish correctness. |
| inconclusive | EXECUTION_INCOMPLETE | Selected run did not complete. |
| inconclusive | ARTIFACT_MISSING | Required manual artifact absent. |
| inconclusive | REVIEW_REQUIRED | Manual or qualitative review needed. |
| error | COMPARATOR_ERROR | Comparison could not complete. |
| error | NUMERIC_OVERFLOW | Relative tolerance bound overflowed. |

`ADVISORY_UNRESOLVED` is the sole warning code; unresolved advisory findings do not determine the binding outcome.

### Public reasons

| Public reason | Technical codes |
| --- | --- |
| match | MATCH |
| mismatch | VALUE_MISMATCH |
| missing_evidence | EVIDENCE_MISSING, ARTIFACT_MISSING |
| incomplete_evidence | EVIDENCE_TRUNCATED, ASSERTION_INCOMPLETE, EXECUTION_INCOMPLETE |
| review_needed | REVIEW_REQUIRED |
| unavailable | REFERENCE_UNAVAILABLE, EXECUTION_UNVERIFIED |
| evaluation_error | COMPARATOR_ERROR, NUMERIC_OVERFLOW |

Public aggregate `withheld` means the definition contains restricted criteria. It does not indicate their outcomes.

### Validation diagnostics

Diagnostics contain a safe schema path and a closed code, without submitted values. ValidationResult domains are invalid_definition, invalid_evidence, invalid_reference and invalid_result.

| Category | Codes |
| --- | --- |
| Serialized input | INVALID_JSON, DUPLICATE_KEY |
| Resource bounds | INPUT_TOO_DEEP, INPUT_TOO_LARGE, TOO_MANY_ITEMS, TOO_MANY_DIAGNOSTICS |
| Unsafe input | UNSUPPORTED_INPUT, UNSAFE_OBJECT, UNSAFE_KEY, UNSAFE_NUMBER |
| Shape | UNEXPECTED_FIELD, MISSING_FIELD, INVALID_TYPE, INVALID_VALUE, UNSUPPORTED_VERSION |
| Definition | DUPLICATE_ID, EMPTY_REQUIRED_CRITERIA, RESTRICTED_LITERAL |
| Integrity | DEFINITION_DIGEST_MISMATCH, REFERENCE_DIGEST_MISMATCH, EVIDENCE_DIGEST_MISMATCH |
| Correspondence | MISMATCHED_DEFINITION, MISMATCHED_ORIGIN, UNKNOWN_REFERENCE, MISMATCHED_REFERENCE, UNKNOWN_CRITERION, MISMATCHED_OBSERVATION |

Collection errors use OBSERVATION_PORT_ERROR or OBSERVATION_CANCELLED. Projection failures return PUBLIC_PROJECTION_REJECTED without diagnostic details.



## Resource limits

The exported `CONTRACT_LIMITS` object defines these bounds. Limits apply to the complete validated record, including nested values.

| Constant | Maximum |
| --- | ---: |
| maxDepth | 12 |
| maxNodes | 4,096 |
| maxInputBytes | 262,144 |
| maxSerializedBytes | 262,144 |
| maxCombinedSerializedBytes | 786,432 |
| maxStringLength | 16,384 |
| maxIdentifierLength | 96 |
| maxObjectKeys | 32 |
| maxArrayLength | 128 |
| maxCriteria | 64 |
| maxGroups | 64 |
| maxGroupChildren | 64 |
| maxGroupDepth | 8 |
| maxCompositionEdges | 127 |
| maxReviewFeedbackBytes | 4,096 |
| maxReviewFeedbackLength | 4,096 |
| maxReviewCitations | 8 |
| maxObservations | 128 |
| maxSetItems | 128 |
| maxEvidenceRefs | 32 |
| maxDiagnostics | 32 |
| maxCapturedBytes | 65,536 |

Byte counts are UTF-8. Length limits on individual strings and review feedback are UTF-16 code units. The combined serialized budget applies to the complete multi-record input. A record that fits a particular field limit can still exceed a total budget.

### Input restrictions

The bounded snapshot rejects unknown keys, functions, accessors, unsupported prototypes, cycles, unsafe numbers and unsupported values. Numeric values must be finite; counts and offsets that require integers must be safe integers. Serialized input must be a JSON object and cannot contain duplicate keys.

The decoder does not replace transport limits. Cap bytes before buffering and reject adversarial live Proxy objects. See [security and trust](/docs/assay/integrity#host-responsibilities).

The [release constants](https://github.com/0xbuffdev/assay/blob/v0.0.1/src/contracts/common.ts) are the source for this table.

## Troubleshooting

| Symptom | Check |
| --- | --- |
| invalid_definition | Schema, revision, criterion IDs, composition and definition digest |
| invalid_evidence | Definition lineage, observation kinds, exact units, origin and evidence digest |
| invalid_reference | Reference ID, digest, kind, unit or item type and bundle lineage |
| inconclusive | Missing or truncated facts, unavailable references, interrupted runs or pending review |
| evaluation_error | Comparator errors or numeric overflow; inspect private finding reasons |
| Collection error | Adapter logs, request/report scope and cancellation signal |
| withheld | Expected when any criterion is restricted |
| PUBLIC_PROJECTION_REJECTED | Use the exact authorized definition and an unmodified complete evaluation result |

Keep diagnostics private. Report reproducible problems with synthetic data to the [issue tracker](https://github.com/0xbuffdev/assay/issues).
Loading
Loading