Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ tool = "get_transactions"
args = { account_id = "acct-001" }
```

`covenant snapshot` runs each probe and stores its response **fingerprint** — the type shape of what actually came back, never the values, which legitimately change — in the lock. `covenant check` re-runs the probes and classifies shape drift with the same severity model, at location `behavior`:
`covenant snapshot` runs each probe and stores its response **fingerprint** — the type shape of what actually came back — in the lock, alongside one **sample** response so the optional `--judge` pass has a baseline to compare meaning against. Shape drift is judged on the fingerprint alone; values legitimately change between runs. `covenant check` re-runs the probes and classifies shape drift with the same severity model, at location `behavior`:

```bash
$ COVENANT_BEHAVIOR_DRIFT=1 covenant check # response body renames a field; schema untouched
Expand Down
10 changes: 6 additions & 4 deletions covenant/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ def _check_probes(
from .judge import judge_probe # the [judge] extra is optional; import on use

descriptions = {t["name"]: t.get("description") for t in base_tools}
shape_drifted = {c.tool for c in changes}
# A probe is identified by tool + args, so judge each live probe on its own
# merits: skip only the probes that themselves errored or shape-drifted, never
# a clean probe that happens to share a tool name with a drifted sibling.
for r in live:
if r["is_error"] or r["tool"] in shape_drifted:
base = base_by[probe_key(r["tool"], r["args"])] # every live key is baselined (see above)
if r["is_error"] or diff_probes([base], [r]):
continue # errors and shape drift are already reported; judge only clean shapes
sample = base_by[probe_key(r["tool"], r["args"])].get("sample")
verdict = judge_probe(
r["tool"], descriptions.get(r["tool"]), r["args"],
sample, r["response"], model=cfg.judge_model,
base.get("sample"), r["response"], model=cfg.judge_model,
)
if verdict.drift:
changes.append(Change(
Expand Down
5 changes: 4 additions & 1 deletion covenant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def load_config(path: str | Path = "covenant.toml", server_override: str | None
if not command and not url:
raise ConfigError("no server configured: set [server].command or .url, or pass --server")

judge_model = (data.get("judge") or {}).get("model")
judge = data.get("judge") or {}
if not isinstance(judge, dict):
raise ConfigError("[judge] must be a table")
judge_model = judge.get("model")
if judge_model is not None and not isinstance(judge_model, str):
raise ConfigError("[judge].model must be a string")

Expand Down
3 changes: 2 additions & 1 deletion covenant/fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import json

from ._types import JsonDict
from .errors import CovenantError


def fingerprint(value: object) -> JsonDict:
Expand All @@ -33,7 +34,7 @@ def fingerprint(value: object) -> JsonDict:
if shapes and all(s == shapes[0] for s in shapes):
return {"type": "array", "items": shapes[0]}
return {"type": "array"}
raise ValueError(f"cannot fingerprint non-JSON value of type {type(value).__name__}")
raise CovenantError(f"cannot fingerprint non-JSON value of type {type(value).__name__}")


def probe_key(tool: str, args: JsonDict | None) -> str:
Expand Down
5 changes: 4 additions & 1 deletion covenant/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ async def _run_probes(config: Config, probes: list[Probe]) -> list[JsonDict]:
records: list[JsonDict] = []
async with _session(config) as session:
for probe in probes:
result = await session.call_tool(probe.tool, probe.args)
try:
result = await session.call_tool(probe.tool, probe.args)
except Exception as e: # noqa: BLE001 - name the probe so a config typo isn't a "connection" error
raise CovenantError(f"probe {probe.tool} failed: {e}") from e
response, is_error, error = _resolve_result(result)
records.append({
"tool": probe.tool,
Expand Down
5 changes: 4 additions & 1 deletion covenant/judge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def judge_probe(
raw = raw.strip("`").removeprefix("json").strip()
try:
data = json.loads(raw)
return Verdict(drift=bool(data["drift"]), reason=str(data["reason"]))
drift = data["drift"]
if not isinstance(drift, bool):
raise TypeError(f"drift must be a boolean, got {type(drift).__name__}")
return Verdict(drift=drift, reason=str(data["reason"]))
except (json.JSONDecodeError, KeyError, TypeError) as e:
raise CovenantError(f"judge returned an unparseable verdict: {raw!r}") from e
3 changes: 2 additions & 1 deletion tests/test_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from covenant.errors import CovenantError
from covenant.fingerprint import fingerprint, probe_key


Expand Down Expand Up @@ -30,7 +31,7 @@ def test_arrays_keep_items_only_when_uniform():


def test_non_json_value_is_loud():
with pytest.raises(ValueError):
with pytest.raises(CovenantError):
fingerprint({1, 2})


Expand Down
Loading