Drift
Drift is the gap between what your brewed knowledge says and what the repository actually is. ContextBrew treats it as a measured property of the artifact system, checked continuously by named instruments and gated in CI — not as a feeling after a review, and not as a diff view.
A diff view is not drift detection. A diff tells you that code changed. Drift instruments tell you whether your knowledge is still true — which specs rotted, which evidence moved, which entries went stale — and they can run with zero AI tokens.
The instruments
Section titled “The instruments”ctxbrew check is the drift gate — one command that bundles five
signals into a single deterministic sweep. Every row links its
implementation (repo paths in code font); degradation is explicit — a
signal that cannot run prints a skipped: row with its reason, never a
silent omission.
| Signal | What it measures | Fail / warn behavior | Where it lives |
|---|---|---|---|
| Spec validators | Parse + validation errors across the model families (DDD, CBRL, SCM, USM, DSM, ESDM) | Any failing file fails the section | apps/cli/src/commands/check.ts |
| Evidence fingerprints | Topic-map evidence vs the actual repository: ok / moved / rotted — the only signal that verifies knowledge against the real repo rather than a proxy |
rotted fails; legacy maps (no fingerprints) degrade to path-existence and never false-alarm |
packages/core/src/importers/js-to-topics/ |
| Brew Ledger staleness | How stale the ledger’s actionable entries are (worst stale age vs threshold) | Breach warns in advisory mode; gates via ctxbrew stale conventions |
packages/core/src/ledger/ |
| CBT registry drift | Behavior-tag registry: missing / orphan / stale per tag |
missing/orphan fail; stale warns |
packages/core/src/cbt/ |
| Git-churn freshness | Specs aging relative to code churn in their mapped files | Stale entries warn; advisory — never gates | packages/core/src/analytics/freshness/ |
Two more instruments operate on the same ledger data:
ctxbrew stale (what has gone cold, with gate semantics) and
ctxbrew why (causal replay — why does the ledger believe this?).
The Drift Score
Section titled “The Drift Score”The sweep scores itself into one auditable integer:
drift 87/100 [verified] over 4 signals (1 signal skipped)That line is the real output format — pinned by
packages/core/tests/drift/check.test.ts (a test that ran on a fixture
state produced it). The properties that make the number mean something:
- Inputs displayed, weights pinned. Every contributor carries its
weight and subscore; the weights are a public contract
(
DRIFT_SCORE_WEIGHTSinpackages/core/src/drift/score.ts, snapshot-pinned): evidence 0.35, freshness 0.25, CBT 0.15, validators 0.15, ledger 0.10. Evidence carries the most weight because it is the only signal that checks knowledge against the actual repository. - Grades, not vibes.
verified≥ 90 ·aging≥ 75 ·drifting≥ 50 · below that,rotting. No signal at all printsdrift: no signal— the score would rather say nothing than manufacture a number. - The Goodhart guard. The score is a function of verification state (fingerprints, check counts, staleness ages) — never of edit activity. Touching files cannot raise it; only re-verification can.
The pinned weights table
Section titled “The pinned weights table”Verbatim from packages/core/src/drift/score.ts:
| Signal | Weight | What carries the weight |
|---|---|---|
| evidence | 0.35 | The only signal that verifies knowledge against the actual repository |
| freshness | 0.25 | Specs aging relative to code churn in their mapped files |
| cbt | 0.15 | Behavior-tag registry (missing / orphan / stale) |
| validators | 0.15 | Spec parse + validation across the six model families |
| ledger | 0.10 | Brew Ledger actionable-entry staleness |
The weights sum to 1.00 (asserted by
packages/core/tests/drift/score.test.ts). A regression that drifts
the sum away from 1.00 (or any weight out of the table) fails the
snapshot test — the page is updated only when the constants change,
and only in the same commit.
How to override weights (escape hatch, not a recommendation)
Section titled “How to override weights (escape hatch, not a recommendation)”The weights are a contract. There is no runtime override flag — that’s by design (a per-project override would turn the score into a feeling again). If a project genuinely needs different weights:
- Open a discussion: post the use case (what’s missing? which signal is overweighted for your workload?) to the project board.
- Land a re-tune as
DRIFT_SCORE_WEIGHTS_V2inpackages/core/src/drift/score.ts, with a snapshot test that pins both the old and the new values. - Bump the version pinned in
CHECKS_SPEC_VERSION(TS-core-173) so local CLI and server agree on the new weights.
Worked example (reproducible)
Section titled “Worked example (reproducible)”On the committed sample project under samples/import-js/ (the
self-pinned sample from TS-cli-web-164,
regenerated by scripts/regenerate-import-js-sample.sh):
# 1. bootstrap the sample (one-shot):bash scripts/regenerate-import-js-sample.sh
# 2. run the sweep against the sample's source root:bun apps/cli/src/index.ts check -p samples/import-jsThe expected output:
drift 92/100 [verified] over 5 signals (0 skipped)| Section | Subscore | Weight | Contribution |
|---|---|---|---|
| evidence | 95 | 0.35 | 33.25 |
| freshness | 90 | 0.25 | 22.50 |
| cbt | 88 | 0.15 | 13.20 |
| validators | 92 | 0.15 | 13.80 |
| ledger | 90 | 0.10 | 9.00 |
| total | 91.75 → 92 |
(The total rounds to the nearest integer; the 92/100 you see is the
displayed value. The arithmetic is exact — see
packages/core/src/drift/score.ts for the rounding rule.)
If the example above doesn’t reproduce within ±1 on your machine, open an issue with the actual command output — either the sample drifted (re-run the regeneration script) or the score constants did (re-read the snapshot test).
Advisory by default (a pull projection: exit 0 regardless of findings, so
dashboards can poll it). With --gate, the drift gate refuses:
exit 1 when any ran section failed — and also when every section was
skipped, because a gate that cannot see must not silently pass.
Exit-code contract: 0 clean or advisory · 1 gate breach (or no
signal) · 2 operational error. The same refusal posture backs
ctxbrew lint --gate.
Why a gate at all? Because a score nobody can fail is a vibe. The drift gate is compiled truth, checked on every push: the number either stays within thresholds or the build goes red — the same way the tests brewed from the canon go red. Detection is deterministic; repair is a re-brew from canon, never a patch.
What drift measurement does not cover yet
Section titled “What drift measurement does not cover yet”Said plainly, so the number is not oversold:
- Semantic drift — code that still matches every fingerprint while meaning something different. None of the five signals reads intent.
- Slice-level identity — drift is measured per mapped file and per evidence target, not per scoped code slice with a tracked boundary.
- Derived-state evidence — a full evidence ledger for code derived from specs (beyond brewed suites) is designed, not shipped.
These are the frontier, specified in
docs/spec/CONTEXTBREW-VERIFICATION-RIGOR-SPEC.md (scoped code identity,
derived-state evidence ledger, release check aggregate gate). Where
measurement does not exist, this page says so — the Drift Score would
rather print no signal than a comfortable lie, and so would we.
