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
+32
View File
@@ -20,6 +20,7 @@ from grimoire.services import moment_delivery as moment_delivery_svc
from grimoire.services import plugin_context as plugin_ctx_svc
from grimoire.services import reply_shapes as reply_shapes_svc
from grimoire.services import repo_bindings as repo_bindings_svc
from grimoire.services import rule_adherence as rule_adherence_svc
from grimoire.services import report_check as report_check_svc
from grimoire.services import rule_deliveries as rule_deliveries_svc
from grimoire.services import rule_moment_judgments as judgments_svc
@@ -458,6 +459,37 @@ async def rule_opened():
))
@plugin_bp.post("/rule-verdict")
@login_required
async def rule_verdict():
"""A session said what a rule it was delivered did there.
Body: `{"session_id", "rule_id", "outcome"?, "moment"?, "why"?}`, posted
by the plugin after a `rule_outcome` call (`outcome`: applied or
departed) or a `rule_misfired` call (`moment`: where it arrived and did
not apply). The verdict lands on this session's latest delivery of the
rule — at that moment, for a misfire — and is the adherence readout's
evidence that the rule was followed, departed from, or did not bear on
the work. A rule the session was never delivered records nothing.
Returns `{"recorded", "at"}`.
"""
data = await request.get_json(silent=True) or {}
if not isinstance(data, dict):
return jsonify({"recorded": False, "at": ""})
try:
rule_id = int(data.get("rule_id") or 0)
except (TypeError, ValueError):
rule_id = 0
if rule_id <= 0:
return jsonify({"recorded": False, "at": ""})
return jsonify(await rule_adherence_svc.from_session(
g.user.id, str(data.get("session_id") or ""), rule_id,
outcome=str(data.get("outcome") or ""),
misfired_at=str(data.get("moment") or ""),
why=str(data.get("why") or ""),
))
@plugin_bp.post("/reply-rules")
@login_required
@memoized_query_embeddings
+17
View File
@@ -21,6 +21,7 @@ from grimoire.auth import get_current_user_id, login_required
from grimoire.services import moment_actions as moment_actions_svc
from grimoire.services import moments as moments_svc
from grimoire.services import reply_shapes as shapes_svc
from grimoire.services import rule_adherence as adherence_svc
from grimoire.services import rule_field_judgments as weights_svc
from grimoire.services import rule_moment_judgments as judgments_svc
from grimoire.services import rulebooks as rulebooks_svc
@@ -241,6 +242,22 @@ async def judge_moment_proposals_route():
return jsonify(await judgments_svc.judge(get_current_user_id(), data["judgments"]))
@retrieval_bp.route("/adherence", methods=["GET"])
@login_required
async def adherence_route():
"""Whether the rules in force at each moment were followed there —
`rule_adherence`'s payload, from the same service. `?days=` sets the
window (default 30); `?rule_id=` narrows to one rule."""
try:
days = int(request.args.get("days") or adherence_svc.SUMMARY_DAYS)
rule_id = int(request.args.get("rule_id") or 0)
except ValueError:
return jsonify({"error": "days and rule_id must be whole numbers"}), 400
return jsonify(await adherence_svc.summary(
get_current_user_id(), days=days, rule_id=rule_id or None,
))
@retrieval_bp.route("/weights/proposals", methods=["GET"])
@login_required
async def weight_proposals_route():