Reconnect the app's command channel after sleep; list clients from it
This commit is contained in:
+15
-28
@@ -35,7 +35,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
||||
{
|
||||
Name: "list_clients",
|
||||
Description: "List the Macs with byre's app open: the human's own machines, not the one byre (and your worktree) runs on. " +
|
||||
"Each has its name, which the other client tools take as client, the human using it, and when the human last did something in byre from it. " +
|
||||
"Each has its name, which the other client tools take as client, the id of that running app (pass it as client instead when two apps are open on one Mac), the human using it, and when the human last did something in byre from it. " +
|
||||
"The most recently active one is listed first; it is usually the Mac the human sits at.",
|
||||
InputSchema: json.RawMessage(`{"type": "object", "properties": {}}`),
|
||||
Handler: func(ctx context.Context, raw json.RawMessage) (string, error) {
|
||||
@@ -50,7 +50,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client": {"type": "string", "description": "The client's name from list_clients."},
|
||||
"client": {"type": "string", "description": "The client's name from list_clients, or its id when several are connected from that Mac."},
|
||||
"command": {"type": "string"},
|
||||
"timeout_ms": {"type": "integer", "description": "Kill the command after this long (default 120000, at most 600000)."}
|
||||
},
|
||||
@@ -67,7 +67,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client": {"type": "string", "description": "The client's name from list_clients."},
|
||||
"client": {"type": "string", "description": "The client's name from list_clients, or its id when several are connected from that Mac."},
|
||||
"path": {"type": "string", "description": "The file or directory, relative to your worktree."},
|
||||
"dest": {"type": "string", "description": "Its new path on the client, absolute or starting with ~/, e.g. ~/Applications/byre.app."}
|
||||
},
|
||||
@@ -84,7 +84,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client": {"type": "string", "description": "The client's name from list_clients."},
|
||||
"client": {"type": "string", "description": "The client's name from list_clients, or its id when several are connected from that Mac."},
|
||||
"path": {"type": "string", "description": "The file or directory on the client, absolute or starting with ~/."},
|
||||
"dest": {"type": "string", "description": "Its new path, relative to your worktree; parent directories are created."}
|
||||
},
|
||||
@@ -101,7 +101,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client": {"type": "string", "description": "The client's name from list_clients."},
|
||||
"client": {"type": "string", "description": "The client's name from list_clients, or its id when several are connected from that Mac."},
|
||||
"path": {"type": "string", "description": "The file, absolute or starting with ~/."},
|
||||
"offset": {"type": "integer", "description": "The line number to start from (default 1)."},
|
||||
"limit": {"type": "integer", "description": "The most lines to return (default 2000)."}
|
||||
@@ -118,7 +118,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client": {"type": "string", "description": "The client's name from list_clients."},
|
||||
"client": {"type": "string", "description": "The client's name from list_clients, or its id when several are connected from that Mac."},
|
||||
"path": {"type": "string", "description": "The file, absolute or starting with ~/."},
|
||||
"content": {"type": "string"}
|
||||
},
|
||||
@@ -135,7 +135,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client": {"type": "string", "description": "The client's name from list_clients."},
|
||||
"client": {"type": "string", "description": "The client's name from list_clients, or its id when several are connected from that Mac."},
|
||||
"path": {"type": "string", "description": "The file, absolute or starting with ~/."},
|
||||
"old_string": {"type": "string"},
|
||||
"new_string": {"type": "string"}
|
||||
@@ -156,7 +156,7 @@ func (m *Manager) clientTools(l *live) []mcp.Tool {
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client": {"type": "string", "description": "The client's name from list_clients."},
|
||||
"client": {"type": "string", "description": "The client's name from list_clients, or its id when several are connected from that Mac."},
|
||||
"tool": {"type": "string", "enum": ["screen_list", "capture", "ax_tree", "act", "browser", "chrome"]},
|
||||
"arguments": {"type": "object", "description": "The tool's arguments."}
|
||||
},
|
||||
@@ -174,39 +174,26 @@ func (m *Manager) listClients(ctx context.Context) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
type row struct {
|
||||
c clients.Client
|
||||
last *time.Time
|
||||
}
|
||||
rows := []row{}
|
||||
for _, c := range m.clients.List() {
|
||||
r := row{c: c}
|
||||
for _, s := range status.Clients {
|
||||
if s.Login == c.Login && s.Host == c.Host && s.Commit == c.Commit {
|
||||
r.last = s.LastActionAt
|
||||
}
|
||||
}
|
||||
rows = append(rows, r)
|
||||
}
|
||||
rows := status.Clients
|
||||
if len(rows) == 0 {
|
||||
return "No client Macs are connected.", nil
|
||||
}
|
||||
sort.SliceStable(rows, func(i, j int) bool {
|
||||
a, b := rows[i].last, rows[j].last
|
||||
a, b := rows[i].LastActionAt, rows[j].LastActionAt
|
||||
return a != nil && (b == nil || a.After(*b))
|
||||
})
|
||||
|
||||
now := time.Now()
|
||||
b := &strings.Builder{}
|
||||
for i, r := range rows {
|
||||
fmt.Fprintf(b, "- %s (%s): ", r.c.Host, r.c.Login)
|
||||
if r.last == nil {
|
||||
fmt.Fprintf(b, "- %s (%s, id %s): ", r.Host, r.Login, r.Id)
|
||||
if r.LastActionAt == nil {
|
||||
b.WriteString("no action since byre started")
|
||||
} else {
|
||||
fmt.Fprintf(b, "last action %s ago", now.Sub(*r.last).Round(time.Second))
|
||||
fmt.Fprintf(b, "last action %s ago", now.Sub(*r.LastActionAt).Round(time.Second))
|
||||
}
|
||||
fmt.Fprintf(b, ", connected %s ago, app built from %s", now.Sub(r.c.ConnectedAt).Round(time.Second), r.c.Commit)
|
||||
if i == 0 && r.last != nil {
|
||||
fmt.Fprintf(b, ", connected %s ago, app built from %s", now.Sub(r.ConnectedAt).Round(time.Second), r.Commit)
|
||||
if i == 0 && r.LastActionAt != nil {
|
||||
b.WriteString(" (most recently active)")
|
||||
}
|
||||
b.WriteString("\n")
|
||||
|
||||
Reference in New Issue
Block a user