# Gate an agent claiming it is done

<!-- BEGIN GENERATED: usage -->

Did an agent finish task, judging report against evidence, with unproven claims, quietly narrowed scope, open questions, and unresolved errors flagged in the same call?

Use when: A coding agent says it is finished and you must decide, before accepting or before letting it stop, whether the work is actually complete.

Install `jev-recipes` and set `TYPESAFE_API_KEY` in your server environment. See the [quick start](https://github.com/agencyenterprise/jev-recipes/blob/main/README.md#use-a-recipe).

```ts
import { completionGate } from 'jev-recipes/completion-gate';

const result = await completionGate({
  task: 'Add input validation to the signup endpoint, write unit tests for the new validation, and make sure the full test suite passes.',
  report:
    'I added validation for email and password fields in signup.ts and wrote three unit tests covering the new checks. All tests pass. Let me know if you want me to also validate the username field.',
  evidence:
    '$ npm test\n\nTest Files  12 passed (12)\n     Tests  87 passed (87)\n\n$ git diff --stat\n src/signup.ts          | 18 ++++++++++++\n tests/signup.test.ts   | 41 +++++++++++++++++++++++++',
  minConfidence: 0.8,
});
console.log(result);
```

Try the saved example without an API key: `npx jev-recipes demo completion-gate`.

<details>
<summary>Illustrative result from the offline fixture</summary>

```json
{
  "model": "demo-fixture",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  },
  "status": "ready",
  "verdict": "complete",
  "confidence": 0.9,
  "probabilities": {
    "complete": 0.9,
    "incomplete": 0.05,
    "unverified": 0.03,
    "unclear": 0.02
  },
  "signals": {
    "claimsWithoutEvidence": {
      "status": "ready",
      "verdict": "absent",
      "probability": 0.06,
      "confidence": 0.94
    },
    "scopeNarrowed": {
      "status": "ready",
      "verdict": "absent",
      "probability": 0.08,
      "confidence": 0.92
    },
    "openQuestions": {
      "status": "ready",
      "verdict": "absent",
      "probability": 0.12,
      "confidence": 0.88
    },
    "unresolvedErrors": {
      "status": "ready",
      "verdict": "absent",
      "probability": 0.03,
      "confidence": 0.97
    }
  },
  "detected": []
}
```

This saved response illustrates behavior; it is not a model accuracy measurement.

</details>

Related recipes:

- [`step-complete`](https://jev-recipes.com/recipes/step-complete/): Use step-complete to check one explicit completion condition against evidence.
- [`goal-drift`](https://jev-recipes.com/recipes/goal-drift/): Use goal-drift while the agent is still working to catch a step that wanders from the goal.
- [`result-plausibility`](https://jev-recipes.com/recipes/result-plausibility/): Use result-plausibility to check whether a single tool result is a real answer.

<!-- END GENERATED: usage -->

## Input

<!-- BEGIN GENERATED: input -->

| Field           | Required | Shape                        |
| --------------- | -------- | ---------------------------- |
| `task`          | Yes      | string                       |
| `report`        | Yes      | string                       |
| `evidence`      | No       | string                       |
| `minConfidence` | No       | number; minimum 0; maximum 1 |

This table is generated from the input schema. Additional text, uniqueness, and policy checks are described below and in the shared options.

<!-- END GENERATED: input -->

See [shared options and behavior](https://github.com/agencyenterprise/jev-recipes/blob/main/recipes/README.md#shared-options-and-behavior) for client configuration, validation, and errors. Types are inferred from this folder's Zod 4 schemas.

`task` is the original assignment. `report` is the agent's final message. `evidence` is the record that can prove the report: test output, a diff summary, command results, or the tail of the transcript. Without `evidence`, the recipe judges the report alone and treats its bare assertions as unverified.

## Result

`verdict` is `complete`, `incomplete`, `unverified`, or `unclear`, with `confidence` and `probabilities`. Only `complete` should let the agent stop without a second look.

`signals` carries four independent checks made in the same request: `claimsWithoutEvidence`, `scopeNarrowed`, `openQuestions`, and `unresolvedErrors`, each with its own `verdict`, `probability`, `confidence`, and `status`. `detected` lists the signals judged present. Use them to decide what to send back to the agent: an `openQuestions` signal usually means the agent should make the decision itself, while `unresolvedErrors` means it should keep working.

A result is `ready` when the decision confidence meets `minConfidence` and the verdict is not `unclear`. Otherwise it is `review`.

## Measured accuracy

<!-- BEGIN GENERATED: accuracy -->

**Current mixed-source measurement; experimental.**

Measured on 144 golden cases against `jev-1.13.0`: **98% accurate** overall (contested cases 100%, adversarial cases 100%).

Recorded 2026-10-04 with package 0.9.12, on the **development** split. Recipe fingerprint: `07af7ca742bf9c8de291687ddb75cb999d01c4ce643a10ac88459553127d4644`.

Scoring revision: 2.

141/144 cases correct; 91 ready, 53 review, 0 failed. Accuracy among ready cases: 100%.

Latency: p50 99.77 ms, p95 177.67 ms. Usage: 148543 input tokens and 19626 output tokens across 144 logical requests.

Labels: unspecified (44 cases): Existing repository labels; independent review and original authorship were not recorded. author-synthetic (100 cases): AI-authored synthetic boundary cases for jev-recipes; labels have not had independent human review.

These authored cases are not independent human validation. Related variants are correlated; case-level confidence intervals can overstate independent evidence.

95% case-level accuracy interval: 94% to 99%.

| `minConfidence` | Deferred to review | Accuracy of ready results |
| --------------- | ------------------ | ------------------------- |
| 0.5             | 25%                | 100%                      |
| 0.6             | 31%                | 100%                      |
| 0.7             | 33%                | 100%                      |
| 0.8             | 37%                | 100%                      |
| 0.9             | 48%                | 100%                      |
| 0.95            | 56%                | 100%                      |

The lowest threshold reaching 95% accuracy on ready results is 0.5.

Run `npm run eval -- completion-gate` to save new results and update this guide. The full report, including misses, is in [evals/results/completion-gate.json](https://github.com/agencyenterprise/jev-recipes/blob/main/evals/results/completion-gate.json). Accuracy on your own data may differ.

<!-- END GENERATED: accuracy -->

## Reuse and calls

Uses the shared choice-with-labels fan-out helper. One live invocation makes one Jev request carrying five questions. This folder owns the completion instruction, the verdict criteria, and the signal definitions.

## Limits

Supply real evidence. A report that says "all tests pass" with no test output is `unverified` by design. When the transcript is long, pass its final portion plus any command output that bears on the task.

The recipe does not judge code quality or correctness beyond what the evidence shows. Pair it with a review step for that.

## Example input

[demo.json](https://github.com/agencyenterprise/jev-recipes/blob/main/recipes/completion-gate/demo.json) contains editable input and a hand-authored response. After installing `jev-recipes`, `npx jev-recipes demo completion-gate` shows an offline illustration, not an accuracy measurement. Use `npx jev-recipes describe completion-gate` to inspect the input and result schemas.

## Decision boundary

Use `unclear` when the required scope cannot be established, `incomplete` when a known requirement remains unfinished, and `unverified` when completion is claimed without supporting evidence. The caller decides what evidence is sufficient for its workflow.

Canonical guide: https://jev-recipes.com/recipes/completion-gate/
Evidence: Current mixed-source measurement. Last updated 2026-10-04.
