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
@@ -0,0 +1,58 @@
"""lesson_situations — when a lesson applies, as moments and triggers
Revision ID: 0137
Revises: 0136
Create Date: 2026-11-25
One row per (lesson, kind, value). `kind` is `moment` (a catalog moment
key), `trigger` (a typed predicate on the act, in rule_field_judgments'
trigger_value form) or `none` (no situation fits; value ''). `state` is
`suggested` while a pass's proposal waits, `confirmed` or `rejected` once a
person judges it; only confirmed rows deliver. CASCADE on the lesson: a
situation of a record that no longer exists says nothing. No backfill: no
lesson had a situation before this table.
"""
import sqlalchemy as sa
from alembic import op
revision = "0137"
down_revision = "0136"
branch_labels = None
depends_on = None
# One place each, so the CHECKs and the model's tuples cannot drift (a new
# value later means DROP + ADD CONSTRAINT in the same migration).
_KINDS = ("moment", "trigger", "none")
_STATES = ("suggested", "confirmed", "rejected")
_SOURCES = ("pass", "edit")
def _in(values) -> str:
return "(" + ", ".join(f"'{v}'" for v in values) + ")"
def upgrade() -> None:
op.create_table(
"lesson_situations",
sa.Column("id", sa.BigInteger(), primary_key=True),
sa.Column("lesson_id", sa.BigInteger(), sa.ForeignKey("notes.id", ondelete="CASCADE"), nullable=False),
sa.Column("kind", sa.Text(), nullable=False),
sa.Column("value", sa.Text(), nullable=False, server_default=""),
sa.Column("state", sa.Text(), nullable=False, server_default="suggested"),
sa.Column("source", sa.Text(), nullable=False, server_default="pass"),
sa.Column("note", sa.Text(), nullable=True),
sa.Column("judged_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
sa.UniqueConstraint("lesson_id", "kind", "value", name="uq_lesson_situations_value"),
)
op.create_check_constraint("ck_lesson_situations_kind", "lesson_situations", "kind IN " + _in(_KINDS))
op.create_check_constraint("ck_lesson_situations_state", "lesson_situations", "state IN " + _in(_STATES))
op.create_check_constraint("ck_lesson_situations_source", "lesson_situations", "source IN " + _in(_SOURCES))
op.create_index("ix_lesson_situations_lesson_id", "lesson_situations", ["lesson_id"])
def downgrade() -> None:
op.drop_index("ix_lesson_situations_lesson_id", table_name="lesson_situations")
for name in ("source", "state", "kind"):
op.drop_constraint(f"ck_lesson_situations_{name}", "lesson_situations", type_="check")
op.drop_table("lesson_situations")