Audit of 3560327
This commit is contained in:
+13
-12
@@ -39,7 +39,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
|||||||
"The most recently active one is listed first; it is usually the Mac the human sits at.",
|
"The most recently active one is listed first; it is usually the Mac the human sits at.",
|
||||||
InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`),
|
InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`),
|
||||||
Handler: func(ctx context.Context, raw json.RawMessage) (string, error) {
|
Handler: func(ctx context.Context, raw json.RawMessage) (string, error) {
|
||||||
return m.listClients(ctx)
|
return m.listClients(), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -219,24 +219,25 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) listClients(ctx context.Context) (string, error) {
|
func (m *Manager) recentClients() []clients.Client {
|
||||||
status, err := m.status(ctx)
|
rows := m.clients.List()
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
rows := status.Clients
|
|
||||||
if len(rows) == 0 {
|
|
||||||
return "No client Macs are connected.", nil
|
|
||||||
}
|
|
||||||
sort.SliceStable(rows, func(i, j int) bool {
|
sort.SliceStable(rows, func(i, j int) bool {
|
||||||
a, b := rows[i].LastActionAt, rows[j].LastActionAt
|
a, b := rows[i].LastActionAt, rows[j].LastActionAt
|
||||||
return a != nil && (b == nil || a.After(*b))
|
return a != nil && (b == nil || a.After(*b))
|
||||||
})
|
})
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) listClients() string {
|
||||||
|
rows := m.recentClients()
|
||||||
|
if len(rows) == 0 {
|
||||||
|
return "No client Macs are connected."
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
b := &strings.Builder{}
|
b := &strings.Builder{}
|
||||||
for i, r := range rows {
|
for i, r := range rows {
|
||||||
fmt.Fprintf(b, "- %s (%s, id %s): ", r.Host, r.Login, r.Id)
|
fmt.Fprintf(b, "- %s (%s, id %s): ", r.Host, r.Login, r.ID)
|
||||||
if r.LastActionAt == nil {
|
if r.LastActionAt == nil {
|
||||||
b.WriteString("no action since byre started")
|
b.WriteString("no action since byre started")
|
||||||
} else {
|
} else {
|
||||||
@@ -251,7 +252,7 @@ func (m *Manager) listClients(ctx context.Context) (string, error) {
|
|||||||
}
|
}
|
||||||
b.WriteString("\n")
|
b.WriteString("\n")
|
||||||
}
|
}
|
||||||
return b.String(), nil
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientBashArgs struct {
|
type clientBashArgs struct {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package agents
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ const signTimeout = 2 * time.Minute
|
|||||||
func (m *Manager) signer(ctx context.Context, user api.User) func(payload []byte) ([]byte, error) {
|
func (m *Manager) signer(ctx context.Context, user api.User) func(payload []byte) ([]byte, error) {
|
||||||
return func(payload []byte) ([]byte, error) {
|
return func(payload []byte) ([]byte, error) {
|
||||||
mine := []clients.Client{}
|
mine := []clients.Client{}
|
||||||
for _, c := range m.clients.List() {
|
for _, c := range m.recentClients() {
|
||||||
if c.Login == user.Login {
|
if c.Login == user.Login {
|
||||||
mine = append(mine, c)
|
mine = append(mine, c)
|
||||||
}
|
}
|
||||||
@@ -24,10 +23,7 @@ func (m *Manager) signer(ctx context.Context, user api.User) func(payload []byte
|
|||||||
if len(mine) == 0 {
|
if len(mine) == 0 {
|
||||||
return nil, fmt.Errorf("commits are signed on %s's Mac, and none of theirs is connected", user.Login)
|
return nil, fmt.Errorf("commits are signed on %s's Mac, and none of theirs is connected", user.Login)
|
||||||
}
|
}
|
||||||
sort.SliceStable(mine, func(i, j int) bool {
|
|
||||||
a, b := mine[i].LastActionAt, mine[j].LastActionAt
|
|
||||||
return a != nil && (b == nil || a.After(*b))
|
|
||||||
})
|
|
||||||
client := mine[0]
|
client := mine[0]
|
||||||
|
|
||||||
ident := fmt.Sprintf("%s <%s>", user.GitName, user.GitEmail)
|
ident := fmt.Sprintf("%s <%s>", user.GitName, user.GitEmail)
|
||||||
|
|||||||
Reference in New Issue
Block a user