Agent tools: plant lookup, plant creation, journal entries (#55)
"Change the garlic garden bed to instead be cucumbers this year" was nearly executable already — describe_garden resolves "the garlic bed" to an object id because it reports the NAMES of what's planted, clear_object empties it, and fill_region replants it. Step three had no way to get its plantId. The toolbox had no plant tool at all, so the agent could see the string "Garlic" come out of describe_garden and had no route from "cucumbers" to an id. One missing tool blocked the whole flagship interaction. find_plant matches the actor's visible catalog and deliberately returns SEVERAL candidates rather than one guess. "garlic" against a catalog holding both "Garlic" and "German Red Garlic" is genuinely ambiguous, and a caller holding the surrounding conversation is far better placed to disambiguate than a fuzzy-match heuristic here. Results are ranked exact, then prefix, then substring, then category, and ordered stably — a tool whose results reshuffle between calls is one a model can't reason about across turns. Each result also reports how much seed is left of that plant across the actor's lots, so the agent can say "you only have enough for half that bed" instead of confidently planting seed that doesn't exist. Omitted rather than zeroed when there are no lots, and dropped when lots disagree about the unit, since summing seeds and grams would be a lie. create_plant lets a variety be named in conversation without leaving the chat. It's user-scoped, not garden-scoped — someone with no editable garden can still name a plant — which the tests assert deliberately rather than assume. add_journal_entry arrived with #52: "note that the west bed has mildew" is squarely the kind of thing you say out loud while walking around. Also reviewed the descriptions on the existing seven tools, since they are the model's only documentation. fill_region's region vocabulary now says north is the top of the garden, gives a worked example of the replant sequence, and notes that filling twice is safe. The demo sequence is now a test: describe_garden → find_plant("cucumber") → clear_object → fill_region, ending with a bed of cucumbers and no active garlic. go.mod is deliberately untouched — majordomo stays out of the module until #56 drops the build tag, so the default build is unaffected. Closes #55 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01H3zbym8Doka2d7D48maSgZ
This commit is contained in:
@@ -237,3 +237,104 @@ func TestDeletePlantInUseIsBlocked(t *testing.T) {
|
||||
t.Errorf("delete freed plant: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFindPlantsRanksAndDisambiguates — FindPlants deliberately returns several
|
||||
// candidates rather than one guess, because "garlic" against a catalog holding
|
||||
// both "Garlic" and "German Red Garlic" is genuinely ambiguous and a caller with
|
||||
// the surrounding context is better placed to choose than a heuristic here.
|
||||
func TestFindPlantsRanksAndDisambiguates(t *testing.T) {
|
||||
s := newTestService(t, openConfig())
|
||||
owner := seedUser(t, s, "[email protected]")
|
||||
ctx := context.Background()
|
||||
|
||||
custom, err := s.CreatePlant(ctx, owner, PlantInput{
|
||||
Name: "German Red Garlic", Category: domain.CategoryVegetable, SpacingCM: 15,
|
||||
Color: "#8a5a8a", Icon: "🧄",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreatePlant: %v", err)
|
||||
}
|
||||
|
||||
got, err := s.FindPlants(ctx, owner, "garlic")
|
||||
if err != nil {
|
||||
t.Fatalf("FindPlants: %v", err)
|
||||
}
|
||||
names := map[string]bool{}
|
||||
for _, m := range got {
|
||||
names[m.Name] = true
|
||||
}
|
||||
if !names["Garlic"] || !names[custom.Name] {
|
||||
t.Errorf("got %v, want both the built-in and the custom variety", names)
|
||||
}
|
||||
// Exact match first, so a caller taking [0] gets the least surprising one.
|
||||
if got[0].Name != "Garlic" {
|
||||
t.Errorf("first match = %q, want the exact name", got[0].Name)
|
||||
}
|
||||
|
||||
// Prefix beats substring: "german" should surface the custom one first.
|
||||
pre, err := s.FindPlants(ctx, owner, "german")
|
||||
if err != nil {
|
||||
t.Fatalf("FindPlants: %v", err)
|
||||
}
|
||||
if len(pre) == 0 || pre[0].Name != custom.Name {
|
||||
t.Errorf("FindPlants(german) = %+v, want the custom variety first", pre)
|
||||
}
|
||||
|
||||
// Category search works, and a query matching nothing says so plainly.
|
||||
if herbs, _ := s.FindPlants(ctx, owner, "herb"); len(herbs) == 0 {
|
||||
t.Error("category search found nothing")
|
||||
}
|
||||
if none, _ := s.FindPlants(ctx, owner, "zzzzz"); len(none) != 0 {
|
||||
t.Errorf("FindPlants(zzzzz) = %+v, want nothing", none)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFindPlantsReportsSeedRemaining — so a caller can say "you only have enough
|
||||
// for half that bed" instead of confidently planting seed that doesn't exist.
|
||||
func TestFindPlantsReportsSeedRemaining(t *testing.T) {
|
||||
s := newTestService(t, openConfig())
|
||||
owner := seedUser(t, s, "[email protected]")
|
||||
other := seedUser(t, s, "[email protected]")
|
||||
ctx := context.Background()
|
||||
|
||||
plant := seedOwnPlant(t, s, owner, 15)
|
||||
if _, err := s.CreateSeedLot(ctx, owner, SeedLotInput{
|
||||
PlantID: plant.ID, Quantity: 100, Unit: domain.UnitSeeds,
|
||||
}); err != nil {
|
||||
t.Fatalf("CreateSeedLot: %v", err)
|
||||
}
|
||||
|
||||
got, err := s.FindPlants(ctx, owner, plant.Name)
|
||||
if err != nil {
|
||||
t.Fatalf("FindPlants: %v", err)
|
||||
}
|
||||
if len(got) == 0 || got[0].SeedRemaining == nil || *got[0].SeedRemaining != 100 {
|
||||
t.Fatalf("seedRemaining = %+v, want 100", got[0].SeedRemaining)
|
||||
}
|
||||
if got[0].SeedUnit != domain.UnitSeeds {
|
||||
t.Errorf("seedUnit = %q", got[0].SeedUnit)
|
||||
}
|
||||
|
||||
// A plant with no lots reports nothing rather than a misleading zero.
|
||||
builtin, err := s.FindPlants(ctx, owner, "Garlic")
|
||||
if err != nil {
|
||||
t.Fatalf("FindPlants: %v", err)
|
||||
}
|
||||
if len(builtin) > 0 && builtin[0].SeedRemaining != nil {
|
||||
t.Errorf("a plant with no lots reported %v remaining", *builtin[0].SeedRemaining)
|
||||
}
|
||||
|
||||
// And lots are private: another user searching the same plant sees no seed.
|
||||
// (They can't see the custom plant at all, so search a built-in instead.)
|
||||
if _, err := s.CreateSeedLot(ctx, other, SeedLotInput{
|
||||
PlantID: builtinPlantID(t, s, other), Quantity: 50, Unit: domain.UnitSeeds,
|
||||
}); err != nil {
|
||||
t.Fatalf("CreateSeedLot(other): %v", err)
|
||||
}
|
||||
mine, _ := s.FindPlants(ctx, owner, "Garlic")
|
||||
for _, m := range mine {
|
||||
if m.SeedRemaining != nil {
|
||||
t.Errorf("saw another user's seed count on %q", m.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user