fix(7883): a lesson recorded for reply.report reaches the turn before the reply, and reply.ask is not offered to a lesson
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / integration (push) Successful in 2m0s
CI & Build / Python tests (push) Successful in 3m48s
CI & Build / Build & push image (push) Successful in 20s

Situated lessons arrived only at tool acts and in MCP replies, so a lesson
given a reply moment was accepted and never shown. The per-turn delivery now
carries lessons confirmed on reply.report, once per session, between the
turn's rules and its reply shape. reply.ask is known only after the reply is
written, so lesson_situations refuses it and leaves it out of the catalog the
pass and the lesson page offer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:48:12 -05:00
co-authored by Claude Opus 5.5
parent 5bde619511
commit 07c4a716bd
7 changed files with 114 additions and 23 deletions
+28 -4
View File
@@ -21,8 +21,10 @@ THE STATES (models/lesson_situation.py):
a lesson's situation directly (`add` / `remove`), which is a judgment too.
A rejected value is never proposed again.
- DELIVERY. `for_act` returns the lessons whose confirmed moment this act
reached or whose confirmed trigger it matches. The plugin's door shows each
once per session.
reached or whose confirmed trigger it matches. The plugin's doors show each
once per session: the act door for tool calls, and the turn's delivery for
`reply.report`, before the reply is written. `reply.ask` has no door
(`NO_LESSON_DOOR`) and is refused.
ACL (services/access.py). Proposing, judging and editing change what a
lesson says about itself, so they need WRITE on the lesson
@@ -58,6 +60,28 @@ SITUATIONS_MAX = 8
_NOTE_CHARS = 600
_REMOVED_NOTE = "removed by an edit"
# Moments no door can bring a lesson to. Whether a reply asks something is
# known only once it is written, at the Stop hook, which can hold a reply for
# a rule but cannot inform it; a lesson about asking belongs on
# `reply.report`, which arrives before every reply.
NO_LESSON_DOOR = {
"reply.ask": "a lesson cannot arrive at reply.ask: whether a reply asks is known only "
"after it is written. Use reply.report, which arrives before every reply.",
}
def lesson_moments() -> list[dict]:
"""The moments a lesson can be recorded for, as `{name, means}`."""
return [{"name": m["name"], "means": m["means"]}
for m in moments.catalog()["moments"] if m["name"] not in NO_LESSON_DOOR]
def _require_lesson_moment(name: str) -> str:
clean = moments.require_moment(name)
if clean in NO_LESSON_DOOR:
raise ValueError(NO_LESSON_DOOR[clean])
return clean
def trigger_value(trigger: triggers_svc.Trigger) -> str:
"""A trigger as one stored string, the form rule_field_judgments uses."""
@@ -108,7 +132,7 @@ def _values(moment_names, trigger_raw) -> list[tuple[str, str]]:
"""(kind, value) pairs, validated and de-duplicated, or the first refusal."""
out: list[tuple[str, str]] = []
for name in moment_names or []:
out.append((MOMENT, moments.require_moment(name)))
out.append((MOMENT, _require_lesson_moment(name)))
for raw in trigger_raw or []:
out.append((TRIGGER, trigger_value(triggers_svc.require_trigger(raw))))
out = list(dict.fromkeys(out))
@@ -179,7 +203,7 @@ async def to_situate(user_id: int, limit: int = PASS_PAGE, offset: int = 0) -> d
"lessons": lessons,
"total": int(total),
"offset": int(offset or 0),
"catalog": [{"name": m["name"], "means": m["means"]} for m in moments.catalog()["moments"]],
"catalog": lesson_moments(),
"trigger_kinds": list(triggers_svc.KINDS),
}