feat(7733): adherence is measured per rule and per moment, and shown
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 16s
CI & Build / TypeScript typecheck (push) Successful in 36s
CI & Build / Python tests (push) Failing after 1m48s
CI & Build / integration (push) Successful in 2m26s
CI & Build / Build & push image (push) Skipped

A rule is in force at a moment of a session when it was delivered there.
Each (session, rule, place) now carries at most one verdict (rule_adherence,
migration 0134): followed, departed, broken or not applicable, with where it
came from:

- an enforce rule refusing the act: followed, recorded by the moment arm, and
  never replaced;
- the session's own rule_outcome (applied, departed) and rule_misfired calls,
  which the plugin's outcome hook now also posts with the session id
  (/api/plugin/rule-verdict) onto the delivery being answered;
- a transcript review: adherence_to_judge lists what has no verdict yet, by
  session, and judge_adherence records verdicts with their evidence.

rule_adherence (MCP) and /api/retrieval/adherence give the readout: sessions
in force, opened and each verdict per rule and per place. Settings > Moments
shows it in a "Were they followed" panel, beside each moment's delivered and
opened counts, and per rule inside each moment.

Verdicts are pruned with their deliveries and left out of backups like them.
Plugin 2026.11.23.2227.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 17:28:23 -05:00
co-authored by Claude Opus 5.5
parent e70b2c2c00
commit b4bdd7798c
25 changed files with 1114 additions and 25 deletions
+38
View File
@@ -246,6 +246,44 @@ export interface WeightJudgeResult {
refused: { rule_id: number; field?: string; error: string }[];
}
/** One rule at one place, or a sum of them: how many sessions it was in
* force in, opened in, and what each was judged. */
export interface AdherenceCounts {
in_force: number;
opened: number;
followed: number;
/** Read and deliberately not followed, with a stated reason. */
departed: number;
broken: number;
not_applicable: number;
unjudged: number;
}
export interface RuleAdherenceRow extends AdherenceCounts {
rule_id: number;
/** Null for a rule deleted since. */
title: string | null;
by_moment: (AdherenceCounts & { at: string })[];
}
export interface MomentAdherenceRow extends AdherenceCounts {
/** A moment (`work.deliver`) or an arm (`pre_tool_rule`). */
at: string;
by_rule: (AdherenceCounts & { rule_id: number; title: string | null })[];
}
export interface AdherencePayload {
days: number;
totals: AdherenceCounts;
by_rule: RuleAdherenceRow[];
by_moment: MomentAdherenceRow[];
}
/** Whether the rules in force at each moment were followed there. */
export function getAdherence(days = 30): Promise<AdherencePayload> {
return apiGet(`/api/retrieval/adherence?days=${days}`);
}
export function getWeightProposals(ruleId?: number): Promise<WeightProposalsPayload> {
return apiGet(`/api/retrieval/weights/proposals${ruleId ? `?rule_id=${ruleId}` : ""}`);
}
+20 -5
View File
@@ -1,12 +1,26 @@
<script setup lang="ts">
import type { MomentRuleUsage } from "@/api/moments";
import type { AdherenceCounts, MomentRuleUsage } from "@/api/moments";
/**
* Which rules a moment delivered, and whether an agent went on to read each.
* The moment's own counts cannot say this once two rules are mounted there.
* Closed by default: the counts in the row above are what most visits want.
* Which rules a moment delivered, whether an agent went on to read each, and
* — where a verdict exists — whether it was followed there. The moment's own
* counts cannot say this once two rules are mounted there. Closed by default:
* the counts in the row above are what most visits want.
*/
defineProps<{ rules: MomentRuleUsage[] }>();
withDefaults(defineProps<{
rules: MomentRuleUsage[];
/** This moment's adherence per rule id, from the adherence readout. */
adherence?: Record<number, AdherenceCounts>;
}>(), { adherence: () => ({}) });
function verdicts(c: AdherenceCounts | undefined): string {
if (!c) return "";
const parts = [`followed ${c.followed} of ${c.in_force}`];
if (c.broken) parts.push(`broken ${c.broken}`);
if (c.departed) parts.push(`departed ${c.departed}`);
if (c.not_applicable) parts.push(`not applicable ${c.not_applicable}`);
return parts.join(" · ");
}
</script>
<template>
@@ -19,6 +33,7 @@ defineProps<{ rules: MomentRuleUsage[] }>();
<span :class="r.opened ? 'delivered-opened' : 'delivered-unopened'">
{{ r.opened ? "opened" : "not opened" }}
</span>
<span v-if="adherence[r.rule_id]" class="delivered-count">{{ verdicts(adherence[r.rule_id]) }}</span>
</li>
</ul>
</details>
+42 -4
View File
@@ -4,7 +4,9 @@ import { useMomentsStore } from "@/stores/moments";
import MomentProposals from "@/components/MomentProposals.vue";
import MomentRuleUsage from "@/components/MomentRuleUsage.vue";
import WeightProposals from "@/components/WeightProposals.vue";
import type { MomentAction, MomentUsage } from "@/api/moments";
import RuleAdherence from "@/components/RuleAdherence.vue";
import { getAdherence } from "@/api/moments";
import type { AdherencePayload, MomentAction, MomentAdherenceRow, MomentUsage } from "@/api/moments";
import { fmtDate } from "@/utils/dateFormat";
/**
@@ -32,6 +34,28 @@ function usage(moment: string): MomentUsage | null {
return data.value?.usage.by_moment[moment] ?? null;
}
// Adherence is read on its own, so a failure there leaves the catalog and the
// delivery counts standing and says so in its own panel.
const adherence = ref<AdherencePayload | null>(null);
const adherenceFailed = ref(false);
async function loadAdherence() {
try {
adherence.value = await getAdherence(days.value);
adherenceFailed.value = false;
} catch {
adherenceFailed.value = true;
}
}
function followed(moment: string): MomentAdherenceRow | null {
return adherence.value?.by_moment.find((m) => m.at === moment) ?? null;
}
function verdictsByRule(moment: string): Record<number, MomentAdherenceRow["by_rule"][number]> {
return Object.fromEntries((followed(moment)?.by_rule ?? []).map((r) => [r.rule_id, r]));
}
// A named procedure is its own moment (`skill.<name>`), so it appears here
// only once something is mounted on it or has been delivered at it — the
// catalog cannot list procedures it has never heard of.
@@ -102,7 +126,10 @@ async function addMapping() {
}
}
onMounted(() => store.load(true));
onMounted(async () => {
await store.load(true);
await loadAdherence();
});
</script>
<template>
@@ -128,6 +155,7 @@ onMounted(() => store.load(true));
<MomentProposals />
<WeightProposals />
<RuleAdherence :data="adherence" :failed="adherenceFailed" @retry="loadAdherence" />
<ul class="moment-list">
<li v-for="m in catalog" :key="m.name" class="moment-row">
@@ -144,6 +172,9 @@ onMounted(() => store.load(true));
last {{ fmtDate(usage(m.name)!.last_delivered_at!) }}
</span>
</template>
<span v-if="followed(m.name)">
followed {{ followed(m.name)!.followed }} of {{ followed(m.name)!.in_force }} in force
</span>
</span>
</div>
<p class="moment-desc">{{ m.means }}</p>
@@ -170,7 +201,9 @@ onMounted(() => store.load(true));
>×</button>
</span>
</div>
<MomentRuleUsage v-if="usage(m.name)" :rules="usage(m.name)!.by_rule" />
<MomentRuleUsage
v-if="usage(m.name)" :rules="usage(m.name)!.by_rule" :adherence="verdictsByRule(m.name)"
/>
</li>
</ul>
@@ -188,9 +221,14 @@ onMounted(() => store.load(true));
<span>delivered {{ usage(name)!.delivered }}</span>
<span>opened {{ usage(name)!.opened }} of {{ usage(name)!.rules }}</span>
</template>
<span v-if="followed(name)">
followed {{ followed(name)!.followed }} of {{ followed(name)!.in_force }} in force
</span>
</span>
</div>
<MomentRuleUsage v-if="usage(name)" :rules="usage(name)!.by_rule" />
<MomentRuleUsage
v-if="usage(name)" :rules="usage(name)!.by_rule" :adherence="verdictsByRule(name)"
/>
</li>
</ul>
</template>
+107
View File
@@ -0,0 +1,107 @@
<script setup lang="ts">
import { computed } from "vue";
import type { AdherenceCounts, AdherencePayload } from "@/api/moments";
/**
* Whether the rules in force at each moment were followed there. A rule is in
* force at a moment of a session when it was delivered there; each such case
* is followed, departed from (with a stated reason), broken, not applicable,
* or not judged yet. Verdicts come from a refused act, the session's own
* `rule_outcome` / `rule_misfired`, and transcript reviews
* (`adherence_to_judge`). One row per rule; open a row for its places.
*/
const props = defineProps<{
data: AdherencePayload | null;
failed: boolean;
}>();
const emit = defineEmits<{ retry: [] }>();
const rows = computed(() => props.data?.by_rule ?? []);
// The verdict counts in reading order, each shown only when it is not zero,
// so a row says what happened rather than listing zeros.
const PARTS: [keyof AdherenceCounts, string][] = [
["followed", "followed"],
["departed", "departed"],
["broken", "broken"],
["not_applicable", "not applicable"],
["unjudged", "not judged"],
];
function parts(c: AdherenceCounts): { key: string; text: string }[] {
return PARTS.filter(([k]) => c[k] > 0).map(([k, label]) => ({ key: k, text: `${label} ${c[k]}` }));
}
</script>
<template>
<section class="adherence" aria-labelledby="adherence-title">
<h3 id="adherence-title" class="sub-title">Were they followed</h3>
<p v-if="failed" class="error-msg">
Adherence could not be loaded.
<button type="button" class="btn-text" @click="emit('retry')">Try again</button>
</p>
<p v-else-if="!data" class="empty-msg">Loading adherence…</p>
<p v-else-if="!rows.length" class="empty-msg">
No rule was in force at a moment in the last {{ data.days }} days.
</p>
<template v-else>
<p class="field-hint">
Sessions each rule was in force in over the last {{ data.days }} days, and what each was
judged. A review fills in the rest from transcripts with <code>adherence_to_judge</code>.
</p>
<div class="adherence-totals">
<span>in force {{ data.totals.in_force }}</span>
<span>opened {{ data.totals.opened }}</span>
<span v-for="p in parts(data.totals)" :key="p.key" :class="`v-${p.key}`">{{ p.text }}</span>
</div>
<ul class="adherence-list">
<li v-for="r in rows" :key="r.rule_id" class="adherence-rule">
<details>
<summary class="adherence-row">
<span class="adherence-title">{{ r.title ?? `Rule ${r.rule_id} (deleted)` }}</span>
<span class="adherence-counts">
<span>in force {{ r.in_force }}</span>
<span>opened {{ r.opened }}</span>
<span v-for="p in parts(r)" :key="p.key" :class="`v-${p.key}`">{{ p.text }}</span>
</span>
</summary>
<ul class="adherence-places">
<li v-for="m in r.by_moment" :key="m.at" class="adherence-row">
<code class="moment-name">{{ m.at }}</code>
<span class="adherence-counts">
<span>in force {{ m.in_force }}</span>
<span>opened {{ m.opened }}</span>
<span v-for="p in parts(m)" :key="p.key" :class="`v-${p.key}`">{{ p.text }}</span>
</span>
</li>
</ul>
</details>
</li>
</ul>
</template>
</section>
</template>
<style scoped>
.adherence { display: flex; flex-direction: column; gap: var(--fs-space-2); }
.sub-title { margin: 0; font-size: 0.95rem; color: var(--fs-text-primary); }
.adherence-totals,
.adherence-counts {
display: inline-flex; flex-wrap: wrap; gap: var(--fs-space-2);
font-size: var(--fs-size-tiny); color: var(--fs-text-secondary);
font-variant-numeric: tabular-nums;
}
.adherence-counts { margin-left: auto; justify-content: flex-end; }
.adherence-list,
.adherence-places { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-1); }
.adherence-places { margin: var(--fs-space-1) 0 var(--fs-space-2) var(--fs-space-4); }
.adherence-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--fs-space-2); }
.adherence-rule summary { cursor: pointer; }
.adherence-title { font-size: var(--fs-size-body-sm); color: var(--fs-text-primary); }
/* Broken is the one count a person acts on, so it is the one that stands out;
not judged is a gap in the record, not a fault, and stays quiet. */
.v-broken { color: var(--fs-text-primary); font-weight: var(--fs-weight-medium); }
.v-unjudged { color: var(--fs-text-tertiary); font-style: italic; }
</style>
<style src="@/assets/moments-shared.css" />