# Typed judgments

> jev ships the `jev` CLI, which sends a state and typed questions to the Jev service and prints each answer with its full probability distribution. Every call is written to a local spool and can be mirrored to S3-compatible storage.
>
> Your agent asks a fast classifier before it reasons.

This feature is the `jev` plugin. `jev` is opt-in: no workspace loads it until you add it. It needs no other plugin.

Once it is loaded, Claude Code uses it when the task calls for it, so you do not have to call it by name. To load it for one launch, or to leave it out of one launch once a manifest names it:

```sh
sc <project> <agent> --with jev
sc <project> <agent> --without jev
```

To keep it, add `"$SC_PLUGINS/jev"` to the `plugins` list in the agent's manifest (`.claude/superclaude.toml`), and delete that line to remove it. Or run `sc <project> <agent> --sc-agent "add jev to this agent"`.

| Without it | With it |
|---|---|
| You spend a reasoning-model turn on a question a person answers in a second. | The agent asks jev first and reads how close the runner-up was. |
| A classifier hands back a bare label you can only branch on. | Every answer carries its full probability distribution. |
| You cannot say later why a call came out the way it did. | Every call is appended to a local spool before the answer prints. |

jev puts the `jev` command on the session's `PATH` and adds a prompt section that tells the agent it exists. `jev` sends a piece of text and typed questions to the Jev service and prints each answer with its probability distribution; the `/jev:jev` skill covers question design and thresholds.

## Using it

Write the config file once, then put your API key in its `api_key` line:

```sh
jev init
```

`jev init` writes `~/.config/jev/config.toml` with a placeholder `api_key` and the defaults for every other setting, each section explained in comments, and never overwrites an existing file. Ask one question:

```sh
jev judge --state "Help! My payouts have been failing for 3 days." --question '{"type":"noul","instructions":"Does this convey urgency?"}'
```

`jev` prints one JSON object: an answer for each question, with the probabilities behind it. A `noul` question answers with a probability from 0 to 1.

With the prompt section loaded, the agent reaches for `jev` on its own. To design questions and thresholds with it, load the skill and say what you need: `/jev:jev route these support tickets to billing, technical or account, and escalate anything the model is unsure about`.

Do not use `jev` for reasoning, generation, exact lookup or arithmetic.

**Which question type do I use?**

Jev is not a chat model. You send a **state** and typed **questions**; it returns one answer per question with the distribution behind it.

| Question type | Use it for | The answer |
|---|---|---|
| `choice` | one of a defined set | the option, a `confidence`, and `probabilities` over every option |
| `noul` | whether something is true | a probability from 0 to 1, with no separate confidence |
| `score` | how far along a scale of 2 to 10 levels | a probability-weighted position, which can fall between levels |

A `noul` near `0.5` means both outcomes are equally likely. It does not mean "somewhat yes". `billing` at 0.55 is a different finding from `billing` at 0.98, and only the distribution shows it.

**When should the agent reach for jev?**

The rule, published as [when-to-use](/prompts#p-jev-when-to-use), is that a Jev call is the cheap check that decides whether the expensive one is needed. A call typically takes tens to a few hundred milliseconds. Before a reasoning model spends a turn on a question a knowledgeable person could answer in a second, the agent asks `jev` and reads how close the runner-up was. Use it to decide whether to call a reasoning model, and to check that model's result; never for justification.

Every call is recorded so a judgment can be explained later. The `jev-latest` alias moves when the service ships a new model, so the record keeps both the model you asked for and the model that answered.

**Set thresholds in a judgment file**

`--state` takes text, `@<file>` or `-` for stdin, and `--question` is repeatable. Put anything with a policy in a file:

```json
{
  "state": "Help! My payouts have been failing for 3 days.",
  "questions": {
    "category": {
      "type": "choice",
      "instructions": "Which team should handle this?",
      "criteria": { "billing": "Payments, refunds", "technical": "Bugs", "other": "None of the above" }
    },
    "frustration": {
      "type": "score",
      "instructions": "How frustrated is the customer?",
      "criteria": ["calm", "frustrated", "very angry"]
    },
    "urgent": { "type": "noul", "instructions": "Does this convey urgency?" }
  },
  "policy": {
    "floor": 0.6,
    "gate": {
      "category": [
        { "outcome": "billing", "confirm_at": 0.6, "act_at": 0.85 },
        { "outcome": "technical", "act_at": 0.6 }
      ]
    },
    "weights": [{ "id": "frustration", "weight": 1.0 }]
  }
}
```

Validate it first. `--check` sends nothing, and prints the question types and which questions the policy gated and weighted:

```sh
jev judge --check --file judgment.json
jev judge --file judgment.json
```

A judgment file has five top-level fields: `_` (one comment), `state`, `model`, `questions` and `policy`. Any other key is a parse error. Each part of `policy` is optional:

- No policy is a fan-out. You get the answers and read them yourself.
- `gate` is confidence-gated routing. Each `choice` question gets rungs, one per outcome, with an `act_at` and an optional `confirm_at`.
- `weights` is composite scoring. Each `score` is divided by its own `levels - 1` before weighting, so a ten-level scale does not outweigh a three-level one. The output keeps every contribution.
- One `choice` question with a gate is intent routing. The dispatch itself stays in your code.

A gate turns a confidence into one of three dispositions:

| Confidence | Disposition |
|---|---|
| below `floor` | `escalate` |
| at or above `act_at` | `act` |
| at or above `confirm_at`, below `act_at` | `confirm` |
| anything else, or an outcome with no rung | `escalate` |

`act_at` is required on every rung. To never act automatically on an outcome, leave it without a rung. The plugin's `examples/` folder holds a worked judgment file for each pattern, including `01-fan-out.json`, `02-intent-routing.json`, `03-confidence-gating.json` and `04-composite-scoring.json`.

**Judge a whole dataset**

Run a dataset with the same verb. Each line of `rows.jsonl` is one state, and the file supplies the questions and policy:

```sh
jev judge --file questions.json --states rows.jsonl --concurrency 8 > out.jsonl
```

Output is one JSON line per input line, in completion order, each with `i`, the 0-based index of the non-blank input lines. The output does not echo the row, so join on `i`: it is the row's position among the non-blank lines of `rows.jsonl`, counting from 0. Keep the ids in the same order. A malformed row carries its own error and the run continues. Concurrency defaults to 1 and caps at 32. The service's rate limit is per account, so an unbounded fan-out throttles everyone sharing the key.

`--states` takes a file, not a directory. Turn a folder of documents into rows first:

```sh
for f in drafts/*.md; do jq -cn --arg id "$f" --rawfile text "$f" '{id:$id, text:$text}'; done > rows.jsonl
```

Group a run's records by exporting scope variables once. Every descendant process inherits them:

```sh
export JEV_SCOPE_COMPONENT=<caller>
export JEV_SCOPE_RUN=<run-id>
```

At the end of a pipeline, run `jev flush` to upload without waiting for the interval.

**Read the output and the exit codes**

Every command except `help` prints one JSON object on stdout, and a dataset run prints one per line. Diagnostics go to stderr, so a shell, Python or Go caller can pipe the output without filtering it. A gated call, abridged:

```json
{
  "ok": true,
  "data": {
    "model": "jev-1.13.0",
    "answers": {
      "severity": {
        "type": "choice",
        "choice": "critical",
        "confidence": 0.9,
        "probabilities": { "critical": 0.92, "high": 0.08, "low": 0.0, "medium": 0.0 }
      }
    },
    "decision": {
      "gates": { "severity": { "outcome": "critical", "confidence": 0.9, "disposition": "act" } },
      "composite": null
    },
    "policy_error": null,
    "usage": { "input_tokens": 551, "output_tokens": 24 }
  },
  "metadata": { "recorded": true, "scope": { "session": "…" }, "questions": 1 }
}
```

`answers` is what the model said, keyed by your question ids. `decision` is what your policy made of it. `metadata.recorded` says whether the record reached the spool.

| Code | Meaning |
|---|---|
| `0` | ok |
| `1` | the call failed on its first attempt, such as a rejected key or request; or every row of a dataset run failed |
| `2` | bad arguments or a bad judgment file |
| `3` | configuration, usually a missing API key |
| `4` | the retries or the 30-second call budget ran out |
| `6` | the answer came back but the record did not reach the spool |

Wire up exit 6: it is the only signal that an answer has no record. A dataset run uses each line's `recorded` field instead.

**Check the setup and clean up**

The service has one operation: one state and N questions in, one answer each out. So the CLI has one verb for it, `jev judge`. Fan-out, routing, gating and scoring are sections of a judgment file, not separate commands. The other verbs set up and inspect the tool:

| Command | What it does |
|---|---|
| `jev init` | writes `~/.config/jev/config.toml` with a placeholder `api_key` and the defaults for every other setting, explained in comments; never overwrites an existing file |
| `jev status` | prints the resolved configuration and the spool's state; secrets appear only as `set (<n> chars)` |
| `jev models` | lists the models your key may name |
| `jev flush` | seals the open spool segment and uploads now |
| `jev gc` | deletes the oldest uploaded batches beyond the keep count |
| `jev daemon --once` | runs one seal-and-upload pass and exits |

**How it works**

`jev judge` sends one HTTPS request and prints one JSON object. A judgment file can add a policy that turns confidences into `act`, `confirm` or `escalate`. Every call is first appended to a local spool, which a background daemon can mirror to S3-compatible storage.

A failed attempt is retried with jittered backoff, up to 3 attempts by default, inside a 30-second budget for the whole call. A `Retry-After` from the service is honoured up to 120 seconds, and a clamp is recorded rather than applied silently. A `422` is never retried, because the request body is wrong and stays wrong.

Before `jev` prints an answer, it appends the record to the spool and fsyncs it. If the process dies between the two, the record survives and the answer is lost, which is the recoverable direction. The record holds the state, the questions, every probability vector exactly as returned, the requested and served model, token usage, the request id, and every attempt with its status and duration. A state over 64 KiB is stored as its SHA-256 with `state_stored: "hashed"`. The API key is never written to a record.

The first call that finds no daemon starts one, detached from the caller's terminal. The daemon seals the open segment into an immutable batch every 30 minutes, or sooner at 8 MiB. Beside each batch it writes a manifest with the batch's SHA-256, record counts by component, run, session, outcome and served model, summed tokens, and how many records needed a retry. It uploads the batch when storage is configured. A failed upload stays sealed and is retried on the next pass. The daemon exits after four idle intervals, two hours at the default. If it cannot start, the call still succeeds and the record waits on disk.

**What it needs**

| Needs | Required | What for |
|---|---|---|
| A Jev API key | yes | every `judge` and `models` call; set `api_key` in the config file |
| Network access to the Jev API | yes | each judgment is one HTTPS request |
| `bin/jev` | yes | the CLI; the release bundle ships it prebuilt for your platform |
| An S3-compatible bucket and credentials | no | mirrors sealed batches; without one, records stay in the local spool |
| Rust toolchain (`cargo`, 1.85 or later) | no | building from source, or installing `jev` outside the plugin |

`jev` is on the session's `PATH` while the plugin is loaded. To call it from your own scripts outside a session, use `~/.superclaude/plugins/jev/bin/jev`, or build it and install a global copy into `~/.cargo/bin`:

```sh
make -C ~/.superclaude/docs/judgments
```

`make` builds `bin/jev` and runs `cargo install` for the global copy. `make install` builds only the plugin copy.

**Configuration**

The `system` workspace loads jev when the plugin is installed; every other workspace needs it added. Use `--with jev` for one launch, or name it in the manifest to keep it. The API key is the only thing it needs.

Load jev per workspace in the [manifest](/docs/superclaude-toml) (`.claude/superclaude.toml`), and name its prompt section:

```toml
plugins = ["$SC_PLUGINS/jev"]
system_prompt = ["identity", "jev:when-to-use"]
```

The `system` workspace and `--with` render [`jev:when-to-use`](/prompts#p-jev-when-to-use) without being asked. jev is opt-in, so `sc doctor` does not expect every workspace to name it.

The tool reads `$XDG_CONFIG_HOME/jev/config.toml`, else `~/.config/jev/config.toml`. `jev init` creates it with mode 0600. The environment overrides the file. The template's comments say where to create a key, and `jev status` reads `UNSET` until one is set.

The file has four tables. The first holds the service settings: `api_key`, `base_url`, `model` (default `jev-latest`), `timeout_secs` (30) and `max_attempts` (3). Each has an environment override, listed by `jev help`. Pin a versioned model id such as `jev-1.13.0` once you have tuned a threshold against it. The other three:

```toml
[spool]
dir = ""                  # empty means $XDG_STATE_HOME/jev, else ~/.local/state/jev
keep_uploaded = 200       # uploaded batches kept on disk

[upload]
enabled = false           # true, plus bucket and both keys, turns mirroring on
endpoint = "https://<s3-endpoint>"
bucket = "<bucket>"
region = "auto"
prefix = "judgments"      # objects land at <prefix>/<batch-id>.jsonl
access_key_id = "<access-key-id>"
secret_access_key = "<secret-access-key>"
interval_secs = 1800
max_bytes = 8388608

[scope]
component = ""
run = ""
job = ""
parent = ""
```

A half-filled `[upload]` does not fail a call. Mirroring stays off and `jev status` reports `upload` as `DISABLED`. It also lists keys it does not recognise, and warns when the file holds a credential and its mode grants group or other users any access.

| Variable | What it overrides |
|---|---|
| `JEV_SPOOL_DIR` | `[spool] dir` |
| `JEV_SPOOL_KEEP_UPLOADED` | `[spool] keep_uploaded` |
| `JEV_UPLOAD_INTERVAL_SECS`, `JEV_UPLOAD_MAX_BYTES`, `JEV_PREFIX` | the matching `[upload]` keys |
| `AWS_ENDPOINT_URL_S3`, `AWS_REGION`, `BUCKET_NAME`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` | the storage keys; `enabled = true` must still be in the file |
| `JEV_SCOPE_COMPONENT`, `JEV_SCOPE_RUN`, `JEV_SCOPE_JOB`, `JEV_SCOPE_PARENT` | the `[scope]` keys |
| `JEV_SCOPE_SESSION` | the group id; minted per process when unset |
| `JEV_SCOPE_LABEL_<KEY>` | adds a free-form label |
| `JEV_DAEMON=off` | never start the daemon automatically |
| `JEV_RECORD=off` | write no records; a single call then exits `6` |

The daemon reads its environment when it starts, from the call that started it. Storage credentials that exist only in one shell's environment reach it only if that shell started it. Credentials in the file always apply.
