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
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:
@@ -169,6 +169,8 @@ _READ_ONLY_TOOLS = frozenset({
|
||||
# rules, as list_rules is.
|
||||
"rules_to_mount", "rule_moment_proposals",
|
||||
"rules_to_weigh", "rule_weight_proposals",
|
||||
# Adherence: the readout, and the queue a transcript review works from.
|
||||
"rule_adherence", "adherence_to_judge",
|
||||
})
|
||||
|
||||
# Every tool that WRITES, by name. Nothing reads this set at runtime — a tool
|
||||
@@ -236,6 +238,8 @@ _WRITE_TOOLS = frozenset({
|
||||
# A misfire report writes a counted row that can become an unmount
|
||||
# proposal.
|
||||
"rule_misfired",
|
||||
# A transcript review's adherence verdicts, with the evidence it wrote.
|
||||
"judge_adherence",
|
||||
# A reviewer's verdicts on logged menu lines — rows carrying free
|
||||
# prose the agent authored, `rule_outcome`'s reason for being a write.
|
||||
"judge_menu",
|
||||
|
||||
@@ -16,6 +16,7 @@ from grimoire.mcp._context import current_user_id
|
||||
from grimoire.services import moment_actions as 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
|
||||
|
||||
@@ -317,6 +318,66 @@ async def judge_rule_weights(judgments: list[dict]) -> dict:
|
||||
return await weights_svc.judge(current_user_id(), judgments)
|
||||
|
||||
|
||||
async def rule_adherence(days: int = 30, rule_id: int = 0) -> dict:
|
||||
"""Whether the rules in force at each moment were followed there — per rule and per moment.
|
||||
|
||||
A rule is in force at a moment of a session when it was delivered there.
|
||||
For each rule at each place (a moment such as `work.deliver`, or an arm
|
||||
such as `pre_tool_rule`) over the last `days`: `in_force` (sessions it
|
||||
was delivered there in), `opened` (sessions that opened it), and one
|
||||
count per verdict — `followed`, `departed` (read and deliberately not
|
||||
followed, with a reason), `broken` (the work went against it),
|
||||
`not_applicable` (it did not bear on the work there) — and `unjudged`.
|
||||
|
||||
Verdicts come from an `enforce` refusal (the act did not happen), from
|
||||
the session's own `rule_outcome` and `rule_misfired` calls, and from a
|
||||
review of the transcript (`adherence_to_judge` / `judge_adherence`).
|
||||
Returns `by_rule` (each with its places), `by_moment` (each with its
|
||||
rules) and `totals`. `rule_id` narrows to one rule.
|
||||
"""
|
||||
return await adherence_svc.summary(current_user_id(), days=days, rule_id=rule_id or None)
|
||||
|
||||
|
||||
async def adherence_to_judge(session_id: str = "", sessions: int = 3, per_session: int = 40) -> dict:
|
||||
"""The rules that were in force at a moment of a session and have no verdict yet — for a transcript review.
|
||||
|
||||
Grouped by session, most recent first. Each item is one rule at one place
|
||||
in that session: the rule's `statement` and `when_to_apply`, where it
|
||||
arrived (`at`), how often and when (`delivered`, `first_at`, `last_at`),
|
||||
and whether the session `opened` it. `how` says where the session's
|
||||
transcript is kept.
|
||||
|
||||
To review a session: read its transcript around each item's times, see
|
||||
what the work was at that moment, and decide whether it kept the rule.
|
||||
Record the verdicts with `judge_adherence`, quoting or describing what in
|
||||
the transcript shows each one. An item that did not bear on the work
|
||||
there is `not_applicable`; that is a finding about where the rule is
|
||||
delivered, and is as useful as the rest. `unjudged` is the total waiting.
|
||||
`session_id` narrows to one session.
|
||||
"""
|
||||
return await adherence_svc.to_judge(
|
||||
current_user_id(), session_id, sessions=sessions, per_session=per_session,
|
||||
)
|
||||
|
||||
|
||||
async def judge_adherence(verdicts: list[dict]) -> dict:
|
||||
"""Record a transcript review's verdicts on rules in force at a moment of a session.
|
||||
|
||||
Each item is `{"session_id": "…", "rule_id": N, "at": "work.deliver",
|
||||
"verdict": "followed"|"broken"|"departed"|"not_applicable",
|
||||
"evidence": "…"}`, the `session_id`, `rule_id` and `at` as
|
||||
`adherence_to_judge` listed them. `evidence` is required: what the
|
||||
transcript shows — the act, the reply, or the passage — so a later reader
|
||||
can check the verdict. `departed` is for a session that said why it did
|
||||
not follow the rule; `broken` for work that went against it without one.
|
||||
|
||||
A review replaces the session's own account (a later, closer reading
|
||||
wins), except where an `enforce` rule refused the act, which stands.
|
||||
Returns `judged` and `refused`, each refused item with why.
|
||||
"""
|
||||
return await adherence_svc.judge(current_user_id(), verdicts)
|
||||
|
||||
|
||||
def register(mcp) -> None:
|
||||
mcp.tool(name="list_moments")(list_moments)
|
||||
mcp.tool(name="list_reply_shapes")(list_reply_shapes)
|
||||
@@ -331,3 +392,6 @@ def register(mcp) -> None:
|
||||
mcp.tool(name="propose_rule_weights")(propose_rule_weights)
|
||||
mcp.tool(name="rule_weight_proposals")(rule_weight_proposals)
|
||||
mcp.tool(name="judge_rule_weights")(judge_rule_weights)
|
||||
mcp.tool(name="rule_adherence")(rule_adherence)
|
||||
mcp.tool(name="adherence_to_judge")(adherence_to_judge)
|
||||
mcp.tool(name="judge_adherence")(judge_adherence)
|
||||
|
||||
Reference in New Issue
Block a user