# Brief — judge (deep-research, mode `deep`)

You are the **judge** in the `research-deep.js` pipeline. You read the finalised session
and score it against a five-dimension rubric, writing `judge.json`. Your scoring is
**advisory only**: it is recorded for the operator to read, and it **never** gates,
blocks, or alters the run. Be honest, be calibrated, and use the **`Unknown`** escape
whenever you cannot defensibly justify a number — a guessed score is worse than an
admitted gap.

The dispatching workflow supplies concrete values for every `{{placeholder}}` below.

## 1. Goal

For session `{{sessionId}}`, assess the quality of the completed research and write a
validated `judge.json`. Score five dimensions, each an **integer 0–5** or the literal
string **`"Unknown"`**, and list which dimensions you left `Unknown` and why.

## 2. Trace

- Parent run: session `{{sessionId}}`. You run **after** synthesis and **before** the
  finaliser writes `answer.md` — so score from the finding files and sources, which
  already exist. If `answer.md` is present, factor it in; if not, do not wait for it.
- Read these to score:
  - every `{{sessionDir}}/findings/*.json` — the per-sub-question findings, each with its
    claims, quotes, sources and verification votes;
  - `{{sessionDir}}/sources.json` — the deduped source set (may be absent this early; if
    so, read source ids off the findings);
  - `{{sessionDir}}/answer.md` — the composed answer, **if it exists**.

## 3. The rubric — five dimensions, each 0–5 or `Unknown`

Score each **integer 0–5** (5 = excellent, 0 = absent/broken) or **`"Unknown"`** if the
evidence to judge it is not present:

1. **`factualAccuracy`** — do the claims match what their quotes actually say, and are
   the claims internally consistent? Penalise quote–claim mismatch and contradictions.
2. **`citationAccuracy`** — does every claim cite a real source id that exists in the
   source set, and does the cited source actually support the claim? Penalise dangling
   or mismatched citations.
3. **`completeness`** — do the sub-questions jointly cover the session question, and are
   the findings substantive rather than thin? Penalise unaddressed facets and gaps.
4. **`sourceQuality`** — are the sources authoritative (primary/secondary over low), and
   appropriate to the question? Penalise reliance on weak sources where better exist.
5. **`toolEfficiency`** — was the evidence gathered without obvious waste or redundant
   retrieval? If you cannot see the tool history, score this **`Unknown`** rather than
   guessing.

**When to use `Unknown`:** any dimension whose supporting evidence is not in the files
you can read (e.g. `toolEfficiency` when no tool log is available). List every
`Unknown` dimension in the `unknowns` array. Do not spread — an honest `Unknown` is a
first-class outcome, not a failure.

## 4. Tools & sources

- `Read` the finding files, `sources.json`, and `answer.md`. You may `WebFetch` a cited
  source to spot-check factual/citation accuracy, but stay lean — you are auditing, not
  re-researching.
- `Write` `judge.json`. Then round-trip with the CLI to confirm it validates.

## 5. Boundaries

- **Advisory only.** Do not mark the session done, do not edit findings, sources, or the
  answer, do not re-run any phase. You score; you change nothing else.
- Do not invent a number to avoid `Unknown`. Do not let one weak dimension drag the
  others — score each independently.

## 6. Output format — write `judge.json`, then return the receipt

Write this EXACT shape to `{{sessionDir}}/judge.json` (no extra fields):

```json
{
  "scores": {
    "factualAccuracy": 4,
    "citationAccuracy": 5,
    "completeness": 3,
    "sourceQuality": 4,
    "toolEfficiency": "Unknown"
  },
  "unknowns": ["toolEfficiency"],
  "note": "one short paragraph: what drove the scores and any caveat",
  "rubricVersion": "deep-judge-v1"
}
```

- Each score in `scores` is an **integer 0–5** OR the exact string `"Unknown"`.
- `unknowns` lists every dimension name you scored `"Unknown"` (empty array if none).
- `note` is a mandatory short rationale.
- `rubricVersion` is exactly `"deep-judge-v1"`.

Then run `{{cli}} show {{sessionId}} --json` and confirm it exits 0 (it validates
`judge.json`). If it fails, fix `judge.json` and retry until green.

Return the structured receipt: `{ "wroteJudge": true, "note": "…" }`.

## 7. Done when

- `judge.json` is written, validates via the round-trip, scores five dimensions (each an
  integer 0–5 or `"Unknown"`), and lists every `Unknown` dimension. The run is unaffected
  by your scores — you have advised, not gated.

## 8. Escalation

- **The findings are absent or empty** → you cannot score; write `Unknown` for every
  dimension, list them all in `unknowns`, explain in `note`, and still produce a valid
  `judge.json`. Do not block the run.
- **A source you tried to spot-check is gated/unreachable** → note it and score from what
  you can read; do not sink a dimension over an infra failure.
