# internal/app/finalize

Package finalize owns the host-facing accountability finalization use case.

## Run

```go
func Run(ctx context.Context, snapshotter Snapshotter, acceptanceRunner AcceptanceRunner, signer Signer, input Input) (Output, error)
```

Run executes deterministic snapshot and acceptance checks, then calibrates the accepted review evidence and mints a receipt. The model review itself is deliberately outside this use case and must already be present in input.

## AcceptanceRunner

```go
type AcceptanceRunner interface {
	Evaluate(context.Context, acceptance.EvaluateInput) (acceptance.EvaluateOutput, error)
}
```

AcceptanceRunner evaluates declared acceptance criteria.

- `Evaluate: func(context.Context, acceptance.EvaluateInput) (acceptance.EvaluateOutput, error)`: 

## FileFact

```go
type FileFact struct {
	Path   string
	Status string
	SHA256 string
}
```

FileFact carries the per-file snapshot facts the reviewer evidence reuses, so review does not re-list and re-hash the tree the snapshot already walked.

- `Path: string`: 
- `Status: string`: 
- `SHA256: string`: 

## Input

```go
type Input struct {
	TaskID          string
	SessionID       string
	Scope           []string
	BaseRef         string
	Review          ReviewEvidence
	SpecFingerprint string
	HostUnderReview receipt.HostUnderReview
	Independence    receipt.Independence
	Criteria        []acceptance.Criterion
	WorkDir         string
	Env             []string
	Timeout         time.Duration
	IdleTimeout     time.Duration
	PriorLedgerHead string
	MintedAt        time.Time
}
```

Input configures one gate run.

- `TaskID: string`: 
- `SessionID: string`: 
- `Scope: []string`: 
- `BaseRef: string`: 
- `Review: ReviewEvidence`: 
- `SpecFingerprint: string`: 
- `HostUnderReview: receipt.HostUnderReview`: 
- `Independence: receipt.Independence`: 
- `Criteria: []acceptance.Criterion`: 
- `WorkDir: string`: 
- `Env: []string`: 
- `Timeout: time.Duration`: 
- `IdleTimeout: time.Duration`: 
- `PriorLedgerHead: string`: 
- `MintedAt: time.Time`: 

## Output

```go
type Output struct {
	Verdict      string
	Acceptance   acceptance.EvaluateOutput
	Findings     []review.Finding
	Receipt      *receipt.Envelope
	Independence receipt.Independence
	Reason       string
}
```

Output is the structured gate result.

- `Verdict: string`: 
- `Acceptance: acceptance.EvaluateOutput`: 
- `Findings: []review.Finding`: 
- `Receipt: *receipt.Envelope`: 
- `Independence: receipt.Independence`: 
- `Reason: string`: 

## ReviewEvidence

```go
type ReviewEvidence struct {
	Dossier    review.Dossier
	Provenance []receipt.Provenance
	Ignored    []string
	Reviewer   receipt.Reviewer
}
```

ReviewEvidence is the accepted result of the independent review already recorded in the session ledger. Finalization consumes this evidence; it never invokes a provider or re-runs a model review.

- `Dossier: review.Dossier`: 
- `Provenance: []receipt.Provenance`: 
- `Ignored: []string`: 
- `Reviewer: receipt.Reviewer`: 

## Signer

```go
type Signer interface {
	Sign(receipt.Body) (receipt.DetachedSignature, error)
}
```

Signer signs the canonical receipt body.

- `Sign: func(receipt.Body) (receipt.DetachedSignature, error)`: 

## Snapshot

```go
type Snapshot struct {
	TreeSHA           string
	BaseCommit        string
	HeadCommit        string
	FileDigests       map[string]string
	Files             []FileFact
	IgnoredUnreviewed []string
	Deleted           []string
}
```

Snapshot captures the deterministic tree facts included in the receipt.

- `TreeSHA: string`: 
- `BaseCommit: string`: 
- `HeadCommit: string`: 
- `FileDigests: map[string]string`: 
- `Files: []FileFact`: 
- `IgnoredUnreviewed: []string`: 
- `Deleted: []string`: 

## SnapshotInput

```go
type SnapshotInput struct {
	Scope   []string
	BaseRef string
}
```

SnapshotInput scopes the tree fingerprint.

- `Scope: []string`: 
- `BaseRef: string`: 

## Snapshotter

```go
type Snapshotter interface {
	Snapshot(context.Context, SnapshotInput) (Snapshot, error)
}
```

Snapshotter computes the commit-free tree facts reviewed by finalization.

- `Snapshot: func(context.Context, SnapshotInput) (Snapshot, error)`:
