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
+75 -1
View File
@@ -1,7 +1,7 @@
import type { RecordUsage } from "@/types/usage";
import { apiGet, apiPost, apiPut, apiPatch, apiDelete } from "@/api/client";
import type { RuleKind } from "@/api/rulebooks";
import type { RuleKind, RuleTrigger } from "@/api/rulebooks";
/** Where a lesson stands on "which rule is this an instance of?"
* (`services/lesson_rules.py`: LINKED / NO_RULE / UNJUDGED). Three answers,
@@ -229,3 +229,77 @@ export function lessonsTaughtBy(
`/api/lessons/taught-by/${recordId}`,
);
}
// ── when a lesson applies (services/lesson_situations.py) ────────────────
/** `moment` — a catalog moment; `trigger` — a typed predicate on the act. */
export type SituationKind = "moment" | "trigger";
/** One situation of a lesson: live (`confirmed`) or waiting on a person
* (`suggested`). `describes` is how it reads in the line a session sees. */
export interface LessonSituation {
id: number;
lesson_id: number;
kind: SituationKind;
value: string;
state: "suggested" | "confirmed";
source: "pass" | "edit";
note: string;
describes: string;
trigger?: RuleTrigger;
}
export interface LessonSituationProposals {
lessons: {
lesson_id: number;
title: string;
when_to_apply: string;
proposals: LessonSituation[];
}[];
total: number;
/** Readable lessons by where they stand: arriving at a situation, read
* and found to have none, waiting on a judgment, or not yet read. */
counts: { situated: number; none_fits: number; waiting: number; unsituated: number };
}
export interface LessonSituationsPayload {
situations: LessonSituation[];
catalog: { name: string; means: string }[];
trigger_kinds: RuleTrigger["kind"][];
}
export interface SituationJudgment {
id: number;
verdict: "confirm" | "reject";
note?: string;
}
export function getLessonSituationProposals(): Promise<LessonSituationProposals> {
return apiGet("/api/lessons/situations/proposals");
}
/** A confirm makes the lesson arrive at that situation, once per session; a
* reject stops the value being proposed again. */
export function judgeLessonSituations(
judgments: SituationJudgment[],
): Promise<{ judged: LessonSituation[] }> {
return apiPost("/api/lessons/situations/judge", { judgments });
}
export function getLessonSituations(lessonId: number): Promise<LessonSituationsPayload> {
return apiGet(`/api/lessons/${lessonId}/situations`);
}
/** Make one situation live: a moment, or a trigger. */
export function addLessonSituation(
lessonId: number,
body: { moment: string } | { trigger: RuleTrigger },
): Promise<LessonSituation> {
return apiPost(`/api/lessons/${lessonId}/situations`, body);
}
/** Take a situation off its lesson; kept as rejected so it is not proposed
* again. `apiDelete` discards the body. */
export function removeLessonSituation(situationId: number): Promise<void> {
return apiDelete(`/api/lessons/situations/${situationId}`);
}