make sure the tools from the All iterator are sorted (#1238) · sourcegraph/src-cli@fcce499

Original file line numberDiff line numberDiff line change

@@ -4,6 +4,8 @@ import (

44

"context"

55

"encoding/json"

66

"iter"

7+

"maps"

8+

"slices"

79
810

"github.com/sourcegraph/src-cli/internal/api"

911

@@ -71,9 +73,10 @@ func (r *ToolRegistry) CallTool(ctx context.Context, client api.Client, name str

7173
7274

// All returns an iterator that yields the name and Tool definition of all registered tools

7375

func (r *ToolRegistry) All() iter.Seq2[string, *ToolDef] {

76+

keys := slices.Sorted(maps.Keys(r.tools))

7477

return func(yield func(string, *ToolDef) bool) {

75-

for name, def := range r.tools {

76-

if !yield(name, def) {

78+

for _, key := range keys {

79+

if !yield(key, r.tools[key]) {

7780

return

7881

}

7982

}