Agent: what a day of live use asked for
Build image / build-and-push (push) Successful in 19s
Gadfly review (reusable) / review (pull_request) Successful in 10m2s
Adversarial Review (Gadfly) / review (pull_request) Successful in 10m2s

Twenty-one prompts against the live assistant found one fabricated success,
a model that believed it was 2025, and a describe_garden that was ~450 plop
entries per turn. This is the set of fixes, each traceable to a finding:

- The gardener's LOCAL day travels with the turn (`today` on POST /agent/chat,
  sent by the UI like plantedAt) into the system prompt and every dated tool
  default. Left to guess, the model dated journal entries a year back; left to
  the server, a 9 pm fill landed on UTC's tomorrow.
- describe_garden groups plops by plant — count, where, planted date, days to
  maturity — and lists ids only for groups of ≤ 8; list_plantings spells a big
  group out on demand and remove_plantings acts on one plant in a bed ("take
  the beets out, leave the garlic"), which used to mean 116 single removals.
- New tools: move_planting (keeps the planting date; across beds via the new
  MovePlanting, which is why the store's UPDATE now writes object_id),
  update_plant, read_history, copy_garden (the "<garden> — <year>" plan
  convention). fill_region takes an explicit local rectangle and a seedLotId;
  place_planting's radius defaults to one plant (spacing/2) instead of a guess.
- The system prompt states the date and the gardener's units, forbids claiming
  a change no tool made, says it cannot undo and points at the Undo button,
  asks before clearing beds on an ambiguous sentence, and stops narrating its
  own plantings into the journal.
- A mutation aimed at ANOTHER garden inside a turn is recorded under that
  garden as its own change set, not filed into the open scope.
- UI: the thread scrolls inside the Assistant panel so the composer stays
  put; every tool has a step label; wide tables stay inside the bubble.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
2026-08-23 00:14:41 -04:00
co-authored by Claude Fable 5
parent f0aefb5378
commit bc14bbed0d
18 changed files with 1702 additions and 186 deletions
+257 -4
View File
@@ -3,6 +3,7 @@ package service
import (
"context"
"errors"
"fmt"
"math"
"sort"
"testing"
@@ -471,12 +472,17 @@ func TestFillScenario(t *testing.T) {
t.Fatalf("objects = %d, want 1", len(desc.Objects))
}
// Tally plant → the set of rough locations it appears in.
// Plantings come grouped by plant: a group's Where names the region when the
// whole group sits in one, and a small group also lists its plops.
locs := map[string]map[string]bool{}
for _, p := range desc.Objects[0].Plantings {
if locs[p.Plant] == nil {
locs[p.Plant] = map[string]bool{}
for _, g := range desc.Objects[0].Plantings {
if locs[g.Plant] == nil {
locs[g.Plant] = map[string]bool{}
}
locs[g.Plant][g.Where] = true
for _, p := range g.Each {
locs[g.Plant][p.Location] = true
}
locs[p.Plant][p.Location] = true
}
if len(locs["Garlic"]) == 0 || !locs["Garlic"]["NE corner"] {
t.Errorf("garlic locations = %v, want NE corner", locs["Garlic"])
@@ -538,3 +544,250 @@ func TestFillRegionPlantedAt(t *testing.T) {
t.Errorf("bad date err = %v, want ErrInvalidInput", err)
}
}
// TestDescribeGardenGroupsByPlant — describe_garden is what the assistant reads
// at the start of every turn, and the live one's first describe of a grid-filled
// garden was ~450 plop entries. A group per plant says what a person would say
// ("beans across the north half, sown in May"), spells out its plops only when
// there are few, and carries the dates the model had no way to know before.
func TestDescribeGardenGroupsByPlant(t *testing.T) {
ctx := context.Background()
s := newTestService(t, openConfig())
owner := seedUser(t, s, "[email protected]")
g, err := s.CreateGarden(ctx, owner, GardenInput{Name: "Grouped", WidthCM: 2000, HeightCM: 2000})
if err != nil {
t.Fatalf("garden: %v", err)
}
bed := seedFillBed(t, s, owner, g.ID, 400, 400)
beans := seedNamedPlant(t, s, owner, "Beans", 10)
basil := seedNamedPlant(t, s, owner, "Basil", 25)
may, june := "2026-05-01", "2026-06-01"
// A grid fill of the north half: far more plops than get listed, all May.
if _, err := s.Fill(ctx, owner, bed.ID, FillSpec{RegionName: "north", PlantID: beans.ID, Layout: FillGrid, PlantedAt: &may}); err != nil {
t.Fatalf("fill beans: %v", err)
}
// Three basil plops in the south half, on two dates, one with an explicit count.
three := 3
for _, in := range []PlantingInput{
{PlantID: basil.ID, XCM: -100, YCM: 100, RadiusCM: 20, PlantedAt: &may},
{PlantID: basil.ID, XCM: 0, YCM: 150, RadiusCM: 20, PlantedAt: &june, Count: &three},
{PlantID: basil.ID, XCM: 100, YCM: 100, RadiusCM: 20, PlantedAt: &june},
} {
if _, err := s.CreatePlanting(ctx, owner, bed.ID, in); err != nil {
t.Fatalf("place basil: %v", err)
}
}
desc, err := s.DescribeGarden(ctx, owner, g.ID)
if err != nil {
t.Fatalf("DescribeGarden: %v", err)
}
groups := map[string]DescribeGroup{}
for _, gr := range desc.Objects[0].Plantings {
groups[gr.Plant] = gr
}
if len(groups) != 2 {
t.Fatalf("groups = %d (%+v), want one per plant", len(groups), desc.Objects[0].Plantings)
}
b := groups["Beans"]
if b.Plops <= maxListedPlops {
t.Fatalf("the beans fill made %d plops; the test needs more than %d to exercise the listing cap", b.Plops, maxListedPlops)
}
if b.Each != nil {
t.Errorf("a %d-plop group listed its plops individually", b.Plops)
}
if b.Where != "north half" {
t.Errorf("beans where = %q, want %q", b.Where, "north half")
}
if b.PlantedAt != may {
t.Errorf("beans plantedAt = %q, want %q", b.PlantedAt, may)
}
if b.Plants != b.Plops {
t.Errorf("grid beans: plants %d ≠ plops %d (one plant per grid plop)", b.Plants, b.Plops)
}
ba := groups["Basil"]
if ba.Plops != 3 || len(ba.Each) != 3 {
t.Errorf("basil: plops %d, each %d; want 3 and 3 (a small group lists its plops)", ba.Plops, len(ba.Each))
}
if ba.Where != "south half" {
t.Errorf("basil where = %q, want %q", ba.Where, "south half")
}
if ba.PlantedAt != may+"…"+june {
t.Errorf("basil plantedAt = %q, want the range %q", ba.PlantedAt, may+"…"+june)
}
// Two derived counts (π·20²/25² ≈ 2 each) plus the explicit 3.
if want := 2*derivedCount(20, 25) + 3; ba.Plants != want {
t.Errorf("basil plants = %d, want %d", ba.Plants, want)
}
for _, e := range ba.Each {
if e.PlantedAt == "" || e.Version == 0 || e.ID == 0 {
t.Errorf("listed plop %+v is missing id, version or date", e)
}
}
// The big group's ids are a call away, narrowed to one plant.
listed, err := s.ListObjectPlantings(ctx, owner, bed.ID, &beans.ID)
if err != nil {
t.Fatalf("ListObjectPlantings: %v", err)
}
if len(listed) != b.Plops {
t.Errorf("listed %d beans, want %d", len(listed), b.Plops)
}
for _, p := range listed {
if p.PlantID != beans.ID || p.PlantedAt != may || p.Plant != "Beans" {
t.Errorf("listed plop %+v, want a May bean", p)
break
}
}
// A stranger gets not-found, like everything else behind the garden ACL.
stranger := seedUser(t, s, "[email protected]")
if _, err := s.ListObjectPlantings(ctx, stranger, bed.ID, nil); !errors.Is(err, domain.ErrNotFound) {
t.Errorf("stranger ListObjectPlantings err = %v, want ErrNotFound", err)
}
}
// TestSummarizeWhere pins the words a group's location comes out in: the
// compass names NamedRegion understands when the group fits one, "throughout"
// for a whole-bed fill, a short list for a few scattered plops, and a bounding
// box for anything else — never a column down the middle called a "half".
func TestSummarizeWhere(t *testing.T) {
o := &domain.GardenObject{WidthCM: 200, HeightCM: 100}
at := func(pts ...[2]float64) []domain.Planting {
out := make([]domain.Planting, 0, len(pts))
for _, p := range pts {
out = append(out, domain.Planting{XCM: p[0], YCM: p[1]})
}
return out
}
for _, tc := range []struct {
name string
in []domain.Planting
want string
}{
{"single", at([2]float64{0, -10}), "north"},
{"ne corner", at([2]float64{10, -10}, [2]float64{80, -40}), "NE corner"},
{"south half", at([2]float64{-80, 10}, [2]float64{80, 40}), "south half"},
{"column down the middle", at([2]float64{0, -40}, [2]float64{0, 0}, [2]float64{0, 40}), "north, center, south"},
{"whole bed", at([2]float64{-90, -40}, [2]float64{90, -40}, [2]float64{-90, 40}, [2]float64{90, 40}, [2]float64{0, 0}), "throughout"},
{"middle third", at([2]float64{-30, -40}, [2]float64{30, -40}, [2]float64{-30, 0}, [2]float64{30, 0}, [2]float64{-30, 40}, [2]float64{30, 40}), "x -30…30, y -40…40 cm from the centre"},
} {
if got := summarizeWhere(o, tc.in); got != tc.want {
t.Errorf("%s: summarizeWhere = %q, want %q", tc.name, got, tc.want)
}
}
}
// TestClearPlantingsOnePlantOnTheDayTold — "take the beets out, leave the
// garlic", dated the gardener's day: the whole-bed clear's narrower sibling, and
// what the assistant needed instead of 116 single removals.
func TestClearPlantingsOnePlantOnTheDayTold(t *testing.T) {
ctx := context.Background()
s := newTestService(t, openConfig())
owner := seedUser(t, s, "[email protected]")
g, err := s.CreateGarden(ctx, owner, GardenInput{Name: "Mixed", WidthCM: 2000, HeightCM: 2000})
if err != nil {
t.Fatalf("garden: %v", err)
}
bed := seedFillBed(t, s, owner, g.ID, 400, 200)
garlic := seedNamedPlant(t, s, owner, "Garlic", 15)
beet := seedNamedPlant(t, s, owner, "Beet", 10)
if _, err := s.Fill(ctx, owner, bed.ID, FillSpec{RegionName: "west", PlantID: garlic.ID}); err != nil {
t.Fatalf("fill garlic: %v", err)
}
beets, err := s.Fill(ctx, owner, bed.ID, FillSpec{RegionName: "east", PlantID: beet.ID})
if err != nil {
t.Fatalf("fill beets: %v", err)
}
day := "2026-08-22"
n, err := s.ClearPlantings(ctx, owner, bed.ID, ClearOptions{PlantID: &beet.ID, RemovedAt: &day})
if err != nil {
t.Fatalf("ClearPlantings: %v", err)
}
if n != len(beets) {
t.Errorf("cleared %d, want the %d beets", n, len(beets))
}
rows, err := s.store.ListPlantingsForObject(ctx, bed.ID)
if err != nil {
t.Fatalf("list: %v", err)
}
for _, r := range rows {
switch {
case r.PlantID == beet.ID && (r.RemovedAt == nil || *r.RemovedAt != day):
t.Errorf("beet %d removedAt = %v, want %q", r.ID, r.RemovedAt, day)
case r.PlantID == garlic.ID && r.RemovedAt != nil:
t.Errorf("garlic %d was removed by a clear aimed at the beets", r.ID)
}
}
sets, _, err := s.GardenHistory(ctx, owner, g.ID, 0, 0)
if err != nil {
t.Fatalf("history: %v", err)
}
if want := fmt.Sprintf("Removed Beet from %s (%d plantings)", objectLabel(bed), n); sets[0].Summary != want {
t.Errorf("summary = %q, want %q", sets[0].Summary, want)
}
// Nothing left of that plant clears nothing, cleanly; a bad date is refused
// before anything is touched.
if n, err := s.ClearPlantings(ctx, owner, bed.ID, ClearOptions{PlantID: &beet.ID}); err != nil || n != 0 {
t.Errorf("second clear = (%d, %v), want (0, nil)", n, err)
}
bad := "22/08/2026"
if _, err := s.ClearPlantings(ctx, owner, bed.ID, ClearOptions{RemovedAt: &bad}); !errors.Is(err, domain.ErrInvalidInput) {
t.Errorf("bad date err = %v, want ErrInvalidInput", err)
}
}
// TestFillByRectangleAttributesSeed — a fill can be aimed at any rectangle of the
// object's local frame (the middle third, a strip along one edge), not only a
// compass name, and can charge its plops to a seed lot so the lot's "remaining"
// means something.
func TestFillByRectangleAttributesSeed(t *testing.T) {
ctx := context.Background()
s := newTestService(t, openConfig())
owner := seedUser(t, s, "[email protected]")
g, err := s.CreateGarden(ctx, owner, GardenInput{Name: "Rect", WidthCM: 2000, HeightCM: 2000})
if err != nil {
t.Fatalf("garden: %v", err)
}
bed := seedFillBed(t, s, owner, g.ID, 240, 120)
beet := seedNamedPlant(t, s, owner, "Beet", 10)
lot, err := s.CreateSeedLot(ctx, owner, SeedLotInput{PlantID: beet.ID, Quantity: 500, Unit: "seeds"})
if err != nil {
t.Fatalf("lot: %v", err)
}
created, err := s.Fill(ctx, owner, bed.ID, FillSpec{
Region: Region{MinX: -40, MinY: -60, MaxX: 40, MaxY: 60}, PlantID: beet.ID, Layout: FillGrid, SeedLotID: &lot.ID,
})
if err != nil {
t.Fatalf("Fill: %v", err)
}
if len(created) == 0 {
t.Fatal("the rectangle fill planted nothing")
}
for _, p := range created {
if p.XCM < -40 || p.XCM > 40 || p.YCM < -60 || p.YCM > 60 {
t.Errorf("plop at (%v,%v) is outside the rectangle", p.XCM, p.YCM)
}
if p.SeedLotID == nil || *p.SeedLotID != lot.ID {
t.Errorf("plop %d seedLotId = %v, want the lot", p.ID, p.SeedLotID)
}
}
got, err := s.GetSeedLot(ctx, owner, lot.ID)
if err != nil {
t.Fatalf("GetSeedLot: %v", err)
}
if got.Used != float64(len(created)) || got.Remaining != 500-float64(len(created)) {
t.Errorf("lot used/remaining = %v/%v, want %d/%v", got.Used, got.Remaining, len(created), 500-float64(len(created)))
}
// Someone else's lot, or a lot of another plant, refuses the whole fill.
garlic := seedNamedPlant(t, s, owner, "Garlic", 15)
if _, err := s.Fill(ctx, owner, bed.ID, FillSpec{RegionName: "all", PlantID: garlic.ID, SeedLotID: &lot.ID}); err == nil {
t.Error("a fill charged to a lot of a different plant succeeded")
}
}