Phase 6: fix the live Home Assistant write (Local Calendar, no event id)
The first live run against the new calendar.school entity failed loudly twice, and both causes are fixed here. - The Local Calendar rejects `return_response` on calendar.create_event. The client retries the call without it and ignores the changed-states array that Home Assistant returns instead. - Home Assistant then reports no event id. The item keeps the description marker ([compass-nhs:<id>]) as its reference, so it leaves the candidate set and is never written twice. The live retry proved it: both events already in the calendar were adopted by their markers, with no duplicate. - calendar.get_events reports `start` / `end` (a date-time or a bare date), not `start_date_time`; the reader now accepts all three shapes. A model must no longer classify events. The calendar write depends on the school-event rule, and the LLM labelled every event "normal"; events now keep the deterministic rule under both classifiers. Also fix the Phase 5 screenshot script: the calendar banner shares the `.scan` class, so select each banner by its labelled section. Docs record the accepted decision: Sam chose a Home Assistant Local Calendar, so the target is calendar.school. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -80,10 +80,17 @@ func eventIsSchoolEvent(title string) bool {
|
||||
// fails, loudly, on a model error or an unparseable answer; it never silently
|
||||
// leaves a wrong label. Items are updated in place. now lets the model judge
|
||||
// whether a due date is overdue.
|
||||
//
|
||||
// Calendar events keep the deterministic rule. A model must not decide whether
|
||||
// a class period is a "school event": the calendar write depends on that call
|
||||
// (FR-8), and a wrong label there either spams the family calendar with every
|
||||
// lesson or silently drops the notice they needed.
|
||||
func ClassifyModel(ctx context.Context, c Completer, items []Item, model string, now time.Time) error {
|
||||
if c == nil {
|
||||
return fmt.Errorf("classify: no model client configured")
|
||||
}
|
||||
ClassifyDeterministic(items, now)
|
||||
|
||||
const system = "You classify school items for a parent's morning brief. " +
|
||||
"Reply with JSON only. No prose, no code fences."
|
||||
|
||||
@@ -107,6 +114,9 @@ func ClassifyModel(ctx context.Context, c Completer, items []Item, model string,
|
||||
if i >= len(batch) {
|
||||
return fmt.Errorf("classify: items %d-%d: model returned %d labels for %d items", start, end-1, len(labels), len(batch))
|
||||
}
|
||||
if batch[i].Type == TypeEvent {
|
||||
continue // events keep the deterministic rule
|
||||
}
|
||||
switch label {
|
||||
case importanceHigh, importanceNormal, importanceLow:
|
||||
batch[i].Importance = label
|
||||
|
||||
@@ -302,6 +302,35 @@ func TestClassifyDeterministic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestClassifyModelLeavesEventsDeterministic proves a model cannot label a
|
||||
// school event: the calendar write depends on that call (FR-8).
|
||||
func TestClassifyModelLeavesEventsDeterministic(t *testing.T) {
|
||||
at := time.Date(2026, 10, 15, 18, 0, 0, 0, time.UTC)
|
||||
items := []Item{
|
||||
{Type: TypeEvent, Title: "End of Year Senior Music Concert - HALL - KSH", DueAt: &at},
|
||||
{Type: TypeEvent, Title: "5 - 11HLEGB5 - D8 - LHT", DueAt: &at},
|
||||
{Type: TypeTask, Title: "Essay", DueAt: &at},
|
||||
}
|
||||
reply, _ := json.Marshal([]map[string]any{
|
||||
{"i": 0, "importance": "low"},
|
||||
{"i": 1, "importance": "high"},
|
||||
{"i": 2, "importance": "low"},
|
||||
})
|
||||
c := &stubCompleter{reply: string(reply)}
|
||||
if err := ClassifyModel(context.Background(), c, items, "test-model", at); err != nil {
|
||||
t.Fatalf("ClassifyModel: %v", err)
|
||||
}
|
||||
if items[0].Importance != importanceHigh {
|
||||
t.Errorf("school event = %q, want %q", items[0].Importance, importanceHigh)
|
||||
}
|
||||
if items[1].Importance != importanceNormal {
|
||||
t.Errorf("class period = %q, want %q", items[1].Importance, importanceNormal)
|
||||
}
|
||||
if items[2].Importance != importanceLow {
|
||||
t.Errorf("task = %q, want the model's %q", items[2].Importance, importanceLow)
|
||||
}
|
||||
}
|
||||
|
||||
func ptr(t time.Time) *time.Time { return &t }
|
||||
|
||||
// TestClassifyDeterministicEvents proves the Phase 6 importance rule: a school
|
||||
|
||||
Reference in New Issue
Block a user