a tool row with no cmd no longer execs the utterance (V-581)
An enabled row whose Cmd is empty built argv from the spoken args alone. So args[0] became the program name, and free text picked the binary. A proposal is drafted with no cmd. /tools can enable one before anybody fills it in, so reaching this took no compromise. Exec now refuses such a row with ErrNotEnabled before it builds argv. TestExecEmptyCmdRefuses pins it. Three smaller reads in the same sweep. CapabilityOf parsed a Home Assistant entity id by hand where smarthome.DomainOf already does it. The fallback for an id with no dot is unchanged. GroupByDomain built its map key twice per row. The zenmoney and Home Assistant HTTP clients read an error body before checking the status that discards it. The status check moved ahead of the read in both. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -62,9 +62,10 @@ func capSegment(s string) string {
|
||||
// the tool name when the argv carries no second word.
|
||||
func CapabilityOf(t ipc.Tool) Capability {
|
||||
if entityID, service, ok := smarthome.ParseCmd(t.Cmd); ok {
|
||||
domain := entityID
|
||||
if i := strings.Index(entityID, "."); i > 0 {
|
||||
domain = entityID[:i]
|
||||
// One parse of an entity id, in the package that owns the format.
|
||||
domain := smarthome.DomainOf(entityID)
|
||||
if domain == "" {
|
||||
domain = entityID
|
||||
}
|
||||
return Capability{Scope: "house", Domain: domain, Action: service}
|
||||
}
|
||||
@@ -122,7 +123,8 @@ func GroupByDomain(tools []ipc.Tool) []CapabilityGroup {
|
||||
byKey := map[string][]ipc.Tool{}
|
||||
for _, t := range tools {
|
||||
c := CapabilityOf(t)
|
||||
byKey[capSegment(c.Scope)+"."+capSegment(c.Domain)] = append(byKey[capSegment(c.Scope)+"."+capSegment(c.Domain)], t)
|
||||
key := capSegment(c.Scope) + "." + capSegment(c.Domain)
|
||||
byKey[key] = append(byKey[key], t)
|
||||
}
|
||||
out := make([]CapabilityGroup, 0, len(byKey))
|
||||
for k, v := range byKey {
|
||||
|
||||
Reference in New Issue
Block a user