# vitals.v1

Source: https://usecns.dev/contract-vitals/

## Upstream claims in `vitals.v1`

`cns status` compares how many inference requests a hook says it sent to Thalamus with what Thalamus recorded.

|  |  |
| --- | --- |
| Writers | `cns hook` (from the child's `CNS_UPSTREAM_LOG`), Cortex (`src/daemon/vitals.mjs`, System 1 classification rows) |
| Reader | `cns status` section `[6] Telemetry` |
| Location | `.cns/vitals.jsonl` (or `$CNS_VITALS_PATH`), compared with `$CNS_THALAMUS_STATE_DIR/telemetry.db` read through `thalamus replay` |
| Row fields (optional, appended after `nonce`) | `thalamus_calls` (served by Thalamus), `thalamus_refused` (Thalamus refused: no member healthy, so it records no row), `direct_calls` (sent straight to a node) |
| `CNS_UPSTREAM_LOG` | file path exported to a hook child; one line per request: `thalamus`, `refused`, or `direct <addr>` |

Red conditions: `BYPASS` (`direct_calls` > 0 in the window), `MISMATCH` (Thalamus recorded fewer rows than `thalamus_calls` claims; it may record more, since other clients share it), `TELEMETRY_UNREADABLE` (`thalamus replay` failed). `telemetry: absent` (no state dir or no `telemetry.db`) and `thalamus-claims: none` are not passes and not red. No organ other than Cortex's System 1 router emits claims yet, so on a live machine the comparison reads `not evaluated` until Engram, Axon and Soma report theirs.

## Vitals ledger (`.cns/vitals.jsonl`, schema `vitals.v1`)

One JSON object per line. Writer: `cns hook <organ> <event> -- <cmd...>` (always exits 0). Reader: `cns status` section `[5] Vitals`.

`cns hook --harness agy <organ> <event> -- <cmd...>` (Google Antigravity, `harnesses/frontier/agy-hooks.json`) writes the same row. It runs from the Git top level of the stdin payload's `workspacePaths[0]` (else the hook's own directory) and passes the payload to `<cmd>` unchanged. It runs nothing and writes no row when the organ is not mounted there: `axon` needs `.axon/axon.db` and `engram` needs `.engram/ote.toml`. Its stdout is always one JSON object: the child's stdout when it is one (for `pre-tool-use`, one with a non-empty `decision`), otherwise `{"decision":"allow"}` for `pre-tool-use`, `{"decision":"stop"}` for `session-end` and `stop`, and `{}` for every other event. An empty or `{}` PreToolUse answer would deny the tool call in Antigravity.

Fields: `v` (`vitals.v1`), `ts` (UTC ISO-8601, at most 5 minutes in the future), `organ`, `event`, `argv_sha256`, `exit`, `duration_ms`, `stdout_bytes`, `stdout_sha256`, `missing_binary`, `vacuous`, `usage_error`, `nonce`. Rows written by an organ or by cns itself may add `internal_status` (`ok` or other), `degraded` (a reason string) or `recovered` (`true`); `organ` must be a string, `event` a string and `exit` a number or the row is malformed and `cns status` is red.

Contract rules for organs:

1. Organs never write rows on a hook channel (`<organ>/<harness event>`): the wrapper's later exit-0 row would hide the error. Report a swallowed error on `<organ>/internal:<site>` with `internal_status: "error"` and a `degraded` reason, and write one `internal_status: "ok"` row there on recovery. Error rows read FAILED (red); a newest ok row on an `internal:` channel reads RESOLVED (not red, does not age). `recovered` or an ok row on a hook channel is an ordinary PASSED row and ages into STALE after 7 days.
2. `cns` is a reserved organ name. Only cns writes organ `cns` rows (`cns/dead-man-memory`, states RECOVERED and DEGRADED, which do not age). The reader rejects any other organ `cns` row as malformed.

---