# Requirement identity and evidence ownership

How zelk identifies the requirements a run must meet and who owns their evidence.
Sessions record run-local or scoped verification at creation. Run-local
verification applies model checks within the producing run and host checks
across runs. Scoped verification uses explicit work associations supplied by
the host.

## Identity and ownership

A requirement has a stable opaque ID, a positive revision, a display name and a
fixed check command. The name is not identity. Work acceptance also names a
stable work ID and the revision at which its meaning was introduced.

| Scope | Ownership |
|---|---|
| Host | Configured invariant; model effects cannot create, revise or retire it |
| Work | Acceptance tied to a work identity; changes require a recorded instruction |

Observations are separate. Recording or relabeling an observation cannot declare
a requirement. A work revision change alone does not retire a requirement or
invalidate unchanged acceptance; requirement revision identifies its meaning.

`RequirementDeclared` expects the current revision (zero for creation) and
declares exactly the next revision. Overflow is rejected. `RequirementRetired`
targets an exact revision and records a reason plus instruction reference.
Retirement preserves the definition and its history.

## Attribution and authority

Initial host invariants are attributed to the session configuration. Each later
change names exactly one host command or model tool effect. Work changes
and retirements name their originating instruction. Structural validation checks
identifier shape and required fields. It does not establish that a command was
accepted, an effect is running, the instruction exists or the actor owns the
target. The reducer must establish those facts from the log before admission.

In particular, a record containing a plausible host command ID is not a host
operation. The registry must receive independently established actor authority,
and reject scope/owner changes or stale revisions. Model interpretation may
associate work but cannot authorize removal of host invariants.

## Evidence binding

Run-local evidence has no `EvidenceRecorded.Scope`. Scoped evidence must
match the active workspace, run, work identity and work revision when it folds. A paired requirement ID/revision is
optional: absent means observation only. Never infer workspace identity from a
display path or promote a label into a standing requirement.

Registry evidence lookup matches workspace, stable requirement identity,
requirement revision, work ownership and command. The producing work revision
is provenance; it must not blanket-invalidate unaffected requirements. Passing
an unrelated observation cannot substitute for missing required evidence.

## Registry initialization and bounds

`SessionStarted.Config.Checks` initializes the scoped registry. Each configured
check becomes a host invariant at revision 1. Its stable ID derives from the
host scope, workspace identity and check name. Initialization validates the
definitions, including unique names, before publishing the session state.

Metadata bounds are 1,024 requirements, 256-byte IDs and names, 64 KiB commands,
4 KiB retirement reasons and 1 MiB of encoded initial definitions. Admission
refuses inputs that exceed the limits. Existing identities and obligations are
retained. Log and blob budgets apply independently.

## Registry transition implementation

`internal/requirements.State` is a reducer-owned value. Successful mutations copy
the affected containers; rejected transitions leave acknowledged input intact.
`Clone` isolates retirement pointers. There is no I/O,
goroutine, provider, clock or independent store in this package.

The reducer supplies an independently established `Authority`, including a model
effect's associated work. A forged host command label does not change that actor.
Model effects can change only the work they are associated with.

An identical current declaration or retirement is idempotent. Repeating the
original declaration after retirement cannot revive it. Stale/future revisions,
owner changes and changed retirement decisions conflict. All retained identities,
including retired ones, count toward the registry bound; revisions of an existing
identity remain possible at capacity. No obligation is evicted.

`MatchEvidence` validates binding separately from outcome/freshness. It rejects
wrong namespace, work, requirement revision, command or source and unscoped or
observation-only evidence. Display-label changes do not change identity. A later
work revision can reuse an unaffected requirement; an earlier producing revision
cannot satisfy acceptance introduced later. Actual log-reference validation,
idle authority, writer reconciliation and atomic publication remain the
integrating reducer/driver's responsibility.

## Session integration

`Config.VerificationContract` records the session's verification contract.
`WithScopedVerification(workspaceID)` selects scoped verification for new
sessions. The CLI and isolated children record run-local verification, and a
fork inherits its source's contract. `ConfigChanged` preserves the contract,
workspace identity and scoped host checks.

Hosts change requirements only while the session is idle, through
`SetVerificationWork`, `DeclareRequirement` and `RetireRequirement`. Each change names an accepted originating instruction
(a user message, goal, steering message, skill invocation or child
continuation). The acceptance ID supplies host authority; a command cannot
claim it. Admission previews the exact command batch, so a requirement command
behind a message in the same batch, an unaccepted instruction, a stale
revision is refused with `ErrInvalidCommand` before
anything is appended. A live `Send` while a run is active is refused the same
way and, like any invalid live command, ends that execution.

`SetVerificationWork` sets the verification focus. Changing focus keeps the
other work's requirements registered and retires nothing. Applicable
requirements are the host invariants plus the focused work's active
acceptance. Scoped sessions always require verification of those requirements.
Verify resolves its `check` argument by stable requirement ID, or by a unique
display name, and refuses a replacement command. Evidence then records the
requirement ID and revision. An unmatched check is an observation: it records
the producing workspace, run and work revision, and never enrolls itself.
Without a focus, Verify is refused with a request for host association.
A check run against nothing applicable decides nothing, so creating and then
deleting a file under one work item succeeds on the deletion's own
observation.

The scoped ledger keeps every observation by evidence ID, up to
`MaxScopedEvidence` (4,096). At capacity, Verify is refused before dispatch,
and the run ends incomplete with that limit as its cause. Nothing is evicted.
Evidence folds only while its Verify effect is running and only for the
current run and focus. Host-sourced evidence must bind a host invariant.

Not yet implemented: writer reconciliation for finished children,
conversational finalization, model-attributed association of messages
with work and supersession, and a host status view of requirements.
Hosts read requirement state by folding the log with `loop.State`
(`Requirements`, `ApplicableRequirements` and
`ScopedEvidence`).
