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:
@@ -168,6 +168,7 @@ _READ_ONLY_TOOLS = frozenset({
|
||||
# rules are unjudged and which proposals wait. Reads of the caller's own
|
||||
# rules, as list_rules is.
|
||||
"rules_to_mount", "rule_moment_proposals",
|
||||
"lessons_to_situate", "lesson_situation_proposals",
|
||||
"rules_to_weigh", "rule_weight_proposals",
|
||||
# Adherence: the readout, and the queue a transcript review works from.
|
||||
"rule_adherence", "adherence_to_judge",
|
||||
@@ -183,6 +184,7 @@ _WRITE_TOOLS = frozenset({
|
||||
# notes, tasks, planning
|
||||
"create_note", "update_note", "delete_note",
|
||||
"create_lesson", "update_lesson", "delete_lesson", "judge_lesson_link",
|
||||
"propose_lesson_situations", "judge_lesson_situations",
|
||||
"create_task", "update_task", "delete_task", "add_task_log",
|
||||
"create_records", "start_planning",
|
||||
"create_milestone", "update_milestone", "delete_milestone",
|
||||
|
||||
@@ -14,6 +14,7 @@ from grimoire.services import access as access_svc
|
||||
from grimoire.services import dedup as dedup_svc
|
||||
from grimoire.services import knowledge as knowledge_svc
|
||||
from grimoire.services import lesson_rules as lesson_rules_svc
|
||||
from grimoire.services import lesson_situations as lesson_situations_svc
|
||||
from grimoire.services import lessons as lessons_svc
|
||||
from grimoire.services import systems as systems_svc
|
||||
from grimoire.services import trash as trash_svc
|
||||
@@ -451,7 +452,71 @@ async def delete_lesson(lesson_id: int) -> dict:
|
||||
}
|
||||
|
||||
|
||||
async def lessons_to_situate(limit: int = 25, offset: int = 0) -> dict:
|
||||
"""The lessons with no situation yet — the pass over the corpus, a page at a time.
|
||||
|
||||
A lesson with no situation arrives only when a prompt's words resemble
|
||||
it. Read each one here and decide WHEN it applies: a moment of work it
|
||||
belongs to, a trigger on the act (a `path` glob, a `command` prefix, a
|
||||
`tool`, a `keyword`), or that none fits. Record the answer with
|
||||
`propose_lesson_situations`. A lesson leaves this list once any answer is
|
||||
recorded, so the next call returns the next unread lessons.
|
||||
|
||||
Each lesson carries its title, its stated `when_to_apply`, the `rules` it
|
||||
is a confirmed instance of with their own moments and triggers (the
|
||||
strongest hint at its situation), and values already `rejected` for it.
|
||||
The page carries the moment `catalog` and the `trigger_kinds`.
|
||||
"""
|
||||
return await lesson_situations_svc.to_situate(current_user_id(), limit=limit, offset=offset)
|
||||
|
||||
|
||||
async def propose_lesson_situations(proposals: list[dict]) -> dict:
|
||||
"""Propose when lessons apply — for the operator to confirm; nothing is delivered by this call.
|
||||
|
||||
Each item is `{"lesson_id": N, "moments": ["work.deliver"], "triggers":
|
||||
[{"kind": "path", "pattern": "alembic/versions/*.py"}], "why": "…"}`.
|
||||
Empty `moments` and `triggers` say no situation fits: the lesson stays
|
||||
reachable by meaning, and leaves the pass's list.
|
||||
|
||||
Propose a moment when the lesson is about that point in the work whatever
|
||||
the work is about; a trigger when it is about a kind of file, command or
|
||||
tool. Keep it to the few points where the lesson changes what is done —
|
||||
a lesson that matches every edit is noise there. `why` is shown to the
|
||||
operator beside the proposal; write it so they can say yes or no without
|
||||
opening the lesson.
|
||||
|
||||
Returns `written`, `skipped` (already recorded, in any state) and
|
||||
`refused` (a bad item, refused alone). Then show the operator what waits
|
||||
(`lesson_situation_proposals`); they judge it in Settings › Moments or
|
||||
through `judge_lesson_situations`.
|
||||
"""
|
||||
return await lesson_situations_svc.propose(current_user_id(), proposals)
|
||||
|
||||
|
||||
async def lesson_situation_proposals(lesson_id: int = 0) -> dict:
|
||||
"""The lesson situations waiting on the operator, grouped by lesson.
|
||||
|
||||
Each proposal has its `id` (what `judge_lesson_situations` takes), its
|
||||
`kind` (`moment` or `trigger`), what it `describes`, and the proposer's
|
||||
`note`. `lesson_id` narrows to one lesson.
|
||||
"""
|
||||
return await lesson_situations_svc.pending(current_user_id(), lesson_id=lesson_id or None)
|
||||
|
||||
|
||||
async def judge_lesson_situations(judgments: list[dict]) -> dict:
|
||||
"""Confirm or reject lesson situations — on the operator's word, since a confirm changes what reaches their sessions.
|
||||
|
||||
Each item is `{"id": N, "verdict": "confirm" | "reject", "note": "why"}`,
|
||||
with the id from `lesson_situation_proposals`. A confirmed situation
|
||||
delivers its lesson when the work reaches it, once per session; a
|
||||
rejected one is never proposed again. Put the operator's reason in `note`.
|
||||
"""
|
||||
return await lesson_situations_svc.judge(current_user_id(), judgments)
|
||||
|
||||
|
||||
def register(mcp) -> None:
|
||||
for fn in (list_lessons, create_lesson, get_lesson, update_lesson,
|
||||
delete_lesson, judge_lesson_link):
|
||||
delete_lesson, judge_lesson_link, lessons_to_situate,
|
||||
propose_lesson_situations, lesson_situation_proposals,
|
||||
judge_lesson_situations):
|
||||
mcp.tool(name=fn.__name__)(fn)
|
||||
|
||||
Reference in New Issue
Block a user