# neferax07/unloop architecture

> Architecture diagram of the GitHub repository neferax07/unloop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/neferax07/unloop
- Repository: https://github.com/neferax07/unloop

## Overview

unloop is a small, dependency-free repetition-loop governor for greedy LLM decoding. Its main workflow profiles a prompt, initializes a preset governor, then reviews each token step using history and logits; it passes, minimally demotes the continuation logit, escalates with a deterministic phase schedule, or stops. The same core is available through a C ABI, while the CLI replays fixture files and prints a trace. The source excerpts show the core review path and adapters; other documented behavior is represented only where the README supports it.

Main entry points: [`src/lib.rs`](https://github.com/neferax07/unloop/blob/main/src/lib.rs) (Governor Review), [`src/main.rs`](https://github.com/neferax07/unloop/blob/main/src/main.rs) (CLI Replay), [`src/ffi.rs`](https://github.com/neferax07/unloop/blob/main/src/ffi.rs) (C ABI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Governor Core"]
  node_preset["Preset Policy<br/>[lib.rs]"]
  node_governor["Governor Review<br/>[lib.rs]"]
  node_top_two["Top-Two Scan<br/>[lib.rs]"]
  node_step_result["Step Verdict<br/>[lib.rs]"]
end

subgraph group_analysis["Prompt And Detection"]
  node_profile["Prompt Profile<br/>[lib.rs]"]
  node_period["Period Detector<br/>[lib.rs]"]
  node_echo["Echo Detector<br/>[lib.rs]"]
end

subgraph group_interfaces["Runtime Interfaces"]
  node_cli["CLI Replay<br/>[main.rs]"]
  node_c_abi["C ABI<br/>[ffi.rs]"]
end

subgraph group_schedule["Intervention"]
  node_phase["Phase Schedule<br/>[lib.rs]"]
  node_demotion["Logit Demotion<br/>[lib.rs]"]
end

node_cli_user(("CLI User"))
node_decoder_host(("Decoder Host"))

node_cli_user -->|"runs replay"| node_cli
node_cli -->|"profiles prompt"| node_profile
node_cli -->|"reviews steps"| node_governor
node_cli -->|"prints trace"| node_step_result
node_decoder_host -->|"calls ABI"| node_c_abi
node_c_abi -->|"delegates review"| node_governor
node_profile -->|"seeds state"| node_governor
node_governor -->|"checks period"| node_period
node_governor -->|"checks echo"| node_echo
node_governor -->|"scans logits"| node_top_two
node_preset -->|"configures policy"| node_governor
node_governor -->|"advances phase"| node_phase
node_governor -->|"demotes continuation"| node_demotion
node_governor -->|"returns verdict"| node_step_result
node_step_result -->|"guides sampling"| node_decoder_host

click node_cli "https://github.com/neferax07/unloop/blob/main/src/main.rs"
click node_c_abi "https://github.com/neferax07/unloop/blob/main/src/ffi.rs"
click node_profile "https://github.com/neferax07/unloop/blob/main/src/lib.rs"
click node_preset "https://github.com/neferax07/unloop/blob/main/src/lib.rs"
click node_governor "https://github.com/neferax07/unloop/blob/main/src/lib.rs"
click node_period "https://github.com/neferax07/unloop/blob/main/src/lib.rs"
click node_echo "https://github.com/neferax07/unloop/blob/main/src/lib.rs"
click node_top_two "https://github.com/neferax07/unloop/blob/main/src/lib.rs"
click node_phase "https://github.com/neferax07/unloop/blob/main/src/lib.rs"
click node_demotion "https://github.com/neferax07/unloop/blob/main/src/lib.rs"
click node_step_result "https://github.com/neferax07/unloop/blob/main/src/lib.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_preset,node_governor,node_top_two,node_step_result,node_cli_user toneBlue
class node_profile,node_period,node_echo toneAmber
class node_cli,node_c_abi toneMint
class node_phase,node_demotion toneRose
class node_decoder_host toneIndigo
```

## Components

### Governor Core

- [Preset Policy](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`
- [Governor Review](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`
- [Top-Two Scan](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`
- [Step Verdict](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`

### Prompt And Detection

- [Prompt Profile](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`
- [Period Detector](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`
- [Echo Detector](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`

### Runtime Interfaces

- [CLI Replay](https://github.com/neferax07/unloop/blob/main/src/main.rs): `src/main.rs`
- [C ABI](https://github.com/neferax07/unloop/blob/main/src/ffi.rs): `src/ffi.rs`

### Intervention

- [Phase Schedule](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`
- [Logit Demotion](https://github.com/neferax07/unloop/blob/main/src/lib.rs): `src/lib.rs`

### Other components

- **CLI User**
- **Decoder Host**

## Connections

- CLI User → CLI Replay: runs replay (evidence: `README.md`)
- CLI Replay → Prompt Profile: profiles prompt (evidence: `src/main.rs`)
- CLI Replay → Governor Review: reviews steps (evidence: `src/main.rs`)
- CLI Replay → Step Verdict: prints trace (evidence: `src/main.rs`)
- Decoder Host → C ABI: calls ABI (evidence: `src/ffi.rs`)
- C ABI → Governor Review: delegates review (evidence: `src/ffi.rs`)
- Prompt Profile → Governor Review: seeds state (evidence: `README.md`)
- Governor Review → Period Detector: checks period (evidence: `src/lib.rs`)
- Governor Review → Echo Detector: checks echo (evidence: `src/lib.rs`)
- Governor Review → Top-Two Scan: scans logits (evidence: `src/lib.rs`)
- Preset Policy → Governor Review: configures policy (evidence: `README.md`)
- Governor Review → Phase Schedule: advances phase (evidence: `README.md`)
- Governor Review → Logit Demotion: demotes continuation (evidence: `README.md`)
- Governor Review → Step Verdict: returns verdict (evidence: `src/lib.rs`)
- Step Verdict → Decoder Host: guides sampling (evidence: `README.md`)
