feat(7836): a lesson arrives at the situation confirmed for it, once per session
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 2m8s
CI & Build / Build & push image (push) Skipped

Each lesson can carry its situation: a moment of work (work.deliver,
work.finish, ...) or a typed trigger on the act (path, command, tool,
keyword, matched as rule triggers are). A pass proposes, a person judges:

- lesson_situations (migration 0137): one row per lesson, kind and value,
  suggested / confirmed / rejected; `none` records that no situation fits;
- MCP: lessons_to_situate, propose_lesson_situations,
  lesson_situation_proposals, judge_lesson_situations;
- Settings > Moments lists waiting proposals with Apply / Not this /
  Apply all; a lesson page lists its situations and lets a writer add one
  or take one off (kept as rejected, never proposed again).

Delivery: the moment doors (the plugin catch-all hook and MCP replies) add
the lessons whose confirmed moment the act reached or whose trigger it
matches. The plugin door shows each once per session, using the record
ledger, and records it as pushed (source lesson_situation); the tool filter
now includes the tools a lesson trigger listens on.

The edit door no longer finds lessons by meaning: lesson leaves the
work.change default kinds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 06:10:23 -05:00
co-authored by Claude Opus 5.5
parent ff3fca6a94
commit c22e8e1844
24 changed files with 1506 additions and 8 deletions
@@ -91,6 +91,30 @@ def flush(kept: set[int] | None = None) -> None:
spawn(_insert(rows), site="record_delivery_write")
async def delivered_this_session(user_id: int, note_ids) -> set[int]:
"""Which of these records the bound session was already shown or pointed
at, so a door that shows a record once per session can leave them out.
Empty outside a plugin request, where there is no session to ask about."""
sid = rule_deliveries.current_session()
ids = {int(n) for n in note_ids or []}
if not sid or not user_id or not ids:
return set()
try:
async with async_session() as session:
rows = (await session.execute(
select(RecordDelivery.note_id).where(
RecordDelivery.user_id == int(user_id),
RecordDelivery.session_id == sid,
RecordDelivery.note_id.in_(ids),
RecordDelivery.way.in_((PUSHED, POINTED)),
).distinct()
)).scalars().all()
except Exception: # noqa: BLE001 - a repeat is better than a lost line
logger.debug("session record ledger unreadable", exc_info=True)
return set()
return {int(r) for r in rows}
async def _kinds(session, user_id: int, ids) -> dict[int, str]:
"""`{note_id: kind}` for the ids this user may read; any other id is left
out, so the ledger never records a record its reader could not open."""