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
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:
@@ -0,0 +1,77 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, ForeignKey, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from grimoire.models import Base
|
||||
from grimoire.models.base import CreatedAtMixin, iso
|
||||
from grimoire.models.lesson_rule_link import CONFIRMED, LINK_STATES, REJECTED, SUGGESTED
|
||||
|
||||
__all__ = [
|
||||
"CONFIRMED", "KINDS", "MOMENT", "NONE", "REJECTED", "SITUATION_STATES", "SOURCES",
|
||||
"SUGGESTED", "TRIGGER", "LessonSituation",
|
||||
]
|
||||
|
||||
# The same three states as a lesson's link to a rule. CHECK
|
||||
# ck_lesson_situations_state (migration 0137).
|
||||
SITUATION_STATES = LINK_STATES
|
||||
|
||||
# What a row names. `moment` — a catalog moment key: the lesson arrives when
|
||||
# the work reaches it. `trigger` — a typed predicate on the act (tool, path,
|
||||
# command, keyword), stored as `rule_field_judgments.trigger_value` writes it,
|
||||
# so it is matched exactly as a rule's trigger is. `none` — the lesson was
|
||||
# read and no situation fits it; it is reached by meaning alone, and the row
|
||||
# keeps it out of the next pass's queue. CHECK ck_lesson_situations_kind.
|
||||
MOMENT, TRIGGER, NONE = "moment", "trigger", "none"
|
||||
KINDS = (MOMENT, TRIGGER, NONE)
|
||||
|
||||
# `pass` — an agent read the lesson and proposed; `edit` — a person set the
|
||||
# lesson's situations directly. CHECK ck_lesson_situations_source.
|
||||
SOURCES = ("pass", "edit")
|
||||
|
||||
|
||||
class LessonSituation(Base, CreatedAtMixin):
|
||||
"""When a lesson applies, as something the work can be checked against.
|
||||
|
||||
One row per (lesson, kind, value):
|
||||
|
||||
- ``suggested`` — proposed by a pass. Delivers nothing until judged.
|
||||
- ``confirmed`` — the lesson arrives when this moment is reached or this
|
||||
trigger matches the act, once per session.
|
||||
- ``rejected`` — judged not to be when it applies, kept with the reason
|
||||
so the same value is never proposed again.
|
||||
"""
|
||||
|
||||
__tablename__ = "lesson_situations"
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
lesson_id: Mapped[int] = mapped_column(
|
||||
BigInteger, ForeignKey("notes.id", ondelete="CASCADE"), index=True,
|
||||
)
|
||||
kind: Mapped[str] = mapped_column(Text)
|
||||
value: Mapped[str] = mapped_column(Text, default="", server_default="")
|
||||
state: Mapped[str] = mapped_column(Text, default=SUGGESTED, server_default=SUGGESTED)
|
||||
source: Mapped[str] = mapped_column(Text, default="pass", server_default="pass")
|
||||
# For a suggestion, what the proposer read in the lesson; for a judgment,
|
||||
# why it was confirmed or rejected.
|
||||
note: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
judged_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True,
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("lesson_id", "kind", "value", name="uq_lesson_situations_value"),
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"id": self.id,
|
||||
"lesson_id": self.lesson_id,
|
||||
"kind": self.kind,
|
||||
"value": self.value,
|
||||
"state": self.state,
|
||||
"source": self.source,
|
||||
"note": self.note or "",
|
||||
"judged_at": iso(self.judged_at),
|
||||
"created_at": iso(self.created_at),
|
||||
}
|
||||
Reference in New Issue
Block a user