# AgentFork Protocol v1

Status: private pre-release draft

## 1. Purpose

AgentFork represents an unresolved question as multiple concurrent candidate
possibilities. It records externally inspectable evidence, deterministic
weight updates, and the basis for a terminal resolution. It does not represent
private chain-of-thought and makes no claim of quantum computation.

The key words **MUST**, **MUST NOT**, **REQUIRED**, **SHOULD**, **SHOULD NOT**,
and **MAY** are normative requirements in this document.

## 2. Event stream

A fork is the reduction of an ordered stream of event envelopes. An envelope
contains:

- `protocol_version`: integer protocol version; v1 is `1`.
- `fork_id`: validated identifier shared by every event in the stream.
- `sequence`: contiguous integer beginning at `1` and not exceeding
  `9_007_199_254_740_991`.
- `event`: exactly one transition payload.

The first event MUST be `fork_opened`. A reducer MUST reject a missing,
duplicated, skipped, reordered, cross-fork, or unsupported-version event. A
rejected event MUST NOT partially mutate materialized state.

## 3. Identifiers and text

Identifiers MUST contain 1 through 128 ASCII bytes from letters, digits, `-`,
`_`, `.`, and `:`. Candidate and evidence identifiers MUST be unique within
their respective fork scope.

Questions, propositions, observations, reasons, sources, and authority
references are public protocol text. Callers MUST NOT place hidden reasoning or
secrets in these fields. A reducer cannot determine semantic sensitivity; it
MUST reject empty or whitespace-only text and enforce the byte limits defined
by the v1 reference implementation.

## 4. Candidate weights

Weights are unsigned fixed-point integers in `[0, 1_000_000_000]`. Candidate
weights in `fork_opened` MUST total exactly `1_000_000_000`.

For selected weight `w`, evidence strength `s`, and scale `S`:

```text
supports: selected_raw = w*S + s*(S-w)
opposes:  selected_raw = w*(S-s)
other:    candidate_raw = w*S
```

Raw scores are normalized to scale `S` using integer division. Remaining parts
are assigned in descending fractional-remainder order. Ties are broken by
candidate identifier in ascending byte order. An update producing zero total
raw score MUST be rejected.

## 5. Evidence

An `evidence_applied` event contains a unique evidence identifier, candidate
identifier, direction, fixed-point strength, provenance source, and concise
observation. It MUST target an existing candidate in an active fork. Reusing an
evidence identifier MUST be rejected.

## 6. Resolution

A `fork_resolved` event selects an existing candidate and records a public
reason plus one of two bases:

- `threshold`: the candidate MUST be the deterministic leader and satisfy the
  declared minimum weight, minimum leader margin, and minimum evidence count.
- `authorized_override`: the event MUST name a non-empty external authority
  reference. Authorization itself is verified outside the pure reducer.

The deterministic leader is the highest-weight candidate, with ascending
candidate identifier breaking equal-weight ties.

## 7. Lifecycle

The v1 lifecycle is:

```text
ACTIVE -> RESOLVED | EXPIRED | VETOED
```

All terminal states are immutable. A reducer MUST reject evidence, a second
terminal event, or any attempt to return a terminal fork to active state.

## 8. Conformance

An implementation conforms to v1 when it:

1. Accepts every valid vector under `conformance/v1`.
2. Produces the exact expected materialized JSON bytes.
3. Rejects every invalid vector with no partial state mutation.
4. Passes cross-language replay when additional implementations are present.

The canonical wire representation is AgentFork Canonical JSON v1, the
restricted [RFC 8785](https://www.rfc-editor.org/rfc/rfc8785.html) profile in
`spec/AGENTFORK_CANONICAL_JSON.md`. Decoders reject unknown fields and unsafe
integer sequences. Accepted noncanonical member order or whitespace MUST be
re-encoded before byte comparison, hashing, or signing.
