Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/conch/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ func runAgent(args []string) error {
return agentQuestion(args[1:])
case len(args) >= 1 && args[0] == "answer":
return agentAnswer(args[1:])
case len(args) >= 1 && args[0] == "team":
return agentTeam(args[1:])
case len(args) != 2 || args[0] != "explain":
return errors.New("usage: conch agent explain ID | status | install NAME | prompt [-wait] ID TEXT | question ID | answer [-question QID] ID CHOICE | skill [-remove] [-apply] | setup [-agent NAME] [-copy] [DIR] | add NAME -command BINARY | " +
return errors.New("usage: conch agent explain ID | status | install NAME | prompt [-wait] ID TEXT | question ID | answer [-question QID] ID CHOICE | team ID [TEAM | - | -clear] | skill [-remove] [-apply] | setup [-agent NAME] [-copy] [DIR] | add NAME -command BINARY | " +
"sync [-from NAME] [-to NAMES] [-apply] [-undo [STAMP]] [DIR] | library [list | add | skill | on | off | rm | import | plan | apply | undo]")
}
c, err := connect(false)
Expand Down
11 changes: 8 additions & 3 deletions cmd/conch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ Usage:
conch server run the server in the foreground
conch server stop stop the server and every pane it owns
conch server reload run a new conch build without stopping panes
conch status [-wide] [-json] show server and pane status, with the host a terminal is on with ssh;
conch status [-wide] [-json] [-team NAME]
show server and pane status, with the host a terminal is on with ssh;
fitted to the terminal (-wide: every column, as piped); BACKGROUND
is what an idle agent left running (-json: agent.background, agent.jobs)
is what an idle agent left running (-json: agent.background, agent.jobs);
-team: only that team's agents
conch new [-cwd DIR] [-name N] -- CMD [ARGS...]
start a pane (with -m, default: that machine's home)
conch send ID TEXT type TEXT into a pane (-keys to send key names); from an agent's
Expand Down Expand Up @@ -119,6 +121,9 @@ Usage:
conch agent question ID what a waiting agent asks, and its choices, as JSON (null when not waiting)
conch agent answer [-question QID] ID CHOICE
pick a choice of a waiting agent's menu without opening its pane
conch agent team ID [TEAM | - | -clear]
which team an agent is in, or put it in one: - keeps it out of
every team, -clear leaves it to [[teams]]' rules in config.toml
conch agent prompt [-wait] [-until done,idle,waiting] [-timeout 30m] [-at TIME] ID TEXT
send an agent its next message, refused (exit 3) while it
waits on a question; -wait blocks until that work ends;
Expand Down Expand Up @@ -172,7 +177,7 @@ Usage:
| merge [-order P,P] [-remove] [-stop] NAME BRANCH
projects kept together because they change together (an API, its
web app, their specs), each still a project of its own
conch task [-cwd DIR] [-branch B] [-base B] [-agent A,B] [-n N] [-name N] [-at TIME] [-every SPAN] [-queue [-wip N]] [-after REF] [-issue N | -ticket KEY] [-account NAME] [-sandbox PROVIDER] PROMPT
conch task [-cwd DIR] [-branch B] [-base B] [-agent A,B] [-n N] [-name N] [-at TIME] [-every SPAN] [-queue [-wip N]] [-after REF] [-issue N | -ticket KEY] [-account NAME] [-team NAME] [-sandbox PROVIDER] PROMPT
new branch + worktree + Claude with PROMPT; in a folder that isn't a
git repository the agent works there instead (with -m and no -cwd:
that machine's home);
Expand Down
22 changes: 21 additions & 1 deletion cmd/conch/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,19 @@ func runTask(args []string) error {
wip := fs.Int("wip", 0, "with -queue, how many agents the project runs before it waits (default 3)")
account := fs.String("account", "", "the agents' account (conch account list); default: the folder's pin, else each agent's own")
after := fs.String("after", "", "start it once this has finished, on top of its branch: a branch, a pane, or a task on the schedule (its ID or -branch)")
team := fs.String("team", "", "put the agents in this team, as the app's Team menu does ([[teams]] in config.toml)")
if err := fs.Parse(args); err != nil {
return err
}
*team = strings.TrimSpace(*team)
// A team is put on a pane, and these start none now.
if *team != "" && (*at != "" || *every != "" || *queue || *after != "" || *inSandbox != "") {
return errors.New("-team puts agents that start now in a team; -at, -every, -queue, -after and -sandbox start them later or elsewhere")
}
prompt := strings.Join(fs.Args(), " ")
*ticket = strings.TrimSpace(*ticket)
if prompt == "" && *issue <= 0 && *ticket == "" {
return errors.New("usage: conch task [-cwd DIR] [-branch B] [-base B] [-agent NAME[,NAME...]] [-n N] [-name N] [-at TIME] [-every SPAN] [-queue [-wip N]] [-after REF] [-issue N | -ticket KEY] [-account NAME] [-sandbox PROVIDER] PROMPT")
return errors.New("usage: conch task [-cwd DIR] [-branch B] [-base B] [-agent NAME[,NAME...]] [-n N] [-name N] [-at TIME] [-every SPAN] [-queue [-wip N]] [-after REF] [-issue N | -ticket KEY] [-account NAME] [-team NAME] [-sandbox PROVIDER] PROMPT")
}
if *issue < 0 {
return errors.New("-issue takes an issue's number")
Expand Down Expand Up @@ -308,6 +314,9 @@ func runTask(args []string) error {
case onRemoteMachine() && dir == "":
// Nothing here says where on that machine: the agent starts in its
// home, as a machine-level pane, like conch -m M new -agent.
if *team != "" {
return errors.New("-team works in a project: give -cwd")
}
return runPlainTask(nil, "", agents, *n, *branch, *base, *name, *account, prompt)
case onRemoteMachine():
if err := remoteDir(dir); err != nil {
Expand Down Expand Up @@ -347,6 +356,9 @@ func runTask(args []string) error {
return errors.New("-at, -every, -queue and -after start a task on a branch of its own, so they need a git repository")
}
// No repository to branch: the agent works in the folder itself.
if *team != "" {
return errors.New("-team works in a git project: put the agent in a team after with conch agent team")
}
return runPlainTask(c, dir, agents, *n, *branch, *base, *name, *account, prompt)
}
branchFrom := prompt
Expand Down Expand Up @@ -403,6 +415,9 @@ func runTask(args []string) error {
}
}
}
if *team != "" && len(c.MissingCapabilities([]string{proto.CapPaneTeam})) > 0 {
return fmt.Errorf("the conch server (pid %d) is from an older build without teams; reload it with `conch server reload`", c.Server.PID)
}
var failed int
for _, at := range attempts {
var info proto.PaneInfo
Expand All @@ -426,6 +441,11 @@ func runTask(args []string) error {
return fmt.Errorf("%s started, but naming it failed: %v", info.ID, err)
}
}
if *team != "" {
if err := call(c, proto.MethodPaneTeam, proto.PaneTeamParams{ID: info.ID, Team: *team}, &info); err != nil {
return fmt.Errorf("%s started, but putting it in %s failed: %v", info.ID, *team, err)
}
}
fmt.Printf("%s %s %s\n", info.ID, info.Cwd, info.Branch)
}
if failed > 0 {
Expand Down
10 changes: 9 additions & 1 deletion cmd/conch/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// running and how it stands first, the folder from ~, the command in
// whatever room is left, and a line saying how many agents are working.

const statusUsage = "usage: conch status [-wide] [-json]"
const statusUsage = "usage: conch status [-wide] [-json] [-team NAME]"

// terminalWidth is the width of the terminal stdout is, or 0 when it is
// not one; tests replace it.
Expand All @@ -44,6 +44,7 @@ func runStatus(args []string) error {
fs := flag.NewFlagSet("status", flag.ContinueOnError)
wide := fs.Bool("wide", false, "every column, as it is printed to a pipe")
asJSON := fs.Bool("json", false, "the server and its panes as JSON")
team := fs.String("team", "", "only the agents in this team ([[teams]] in config.toml, or put there by hand)")
if err := fs.Parse(args); err != nil {
return err
}
Expand Down Expand Up @@ -71,6 +72,9 @@ func runStatus(args []string) error {
defer c.Close()
var list proto.PaneList
listErr := call(c, proto.MethodPaneList, nil, &list)
if listErr == nil && *team != "" {
list.Panes = onlyTeam(c, list.Panes, *team)
}
if *asJSON {
if listErr != nil {
return listErr
Expand All @@ -87,6 +91,10 @@ func runStatus(args []string) error {
if listErr != nil {
return listErr
}
if len(list.Panes) == 0 && *team != "" {
fmt.Printf("no agents in %s\n", *team)
return nil
}
if len(list.Panes) == 0 {
fmt.Println("no panes")
return nil
Expand Down
109 changes: 109 additions & 0 deletions cmd/conch/team.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"errors"
"fmt"
"strings"

"github.com/Amitgb14/conch/internal/client"
"github.com/Amitgb14/conch/internal/config"
"github.com/Amitgb14/conch/internal/proto"
)

const agentTeamUsage = "usage: conch agent team ID [TEAM | - | -clear]"

// agentTeam says which team a pane is in, or puts it in one: a name, "-"
// for no team whatever the rules say, or -clear to leave it to the rules.
func agentTeam(args []string) error {
if len(args) < 1 || len(args) > 2 {
return errors.New(agentTeamUsage)
}
ref, team := args[0], ""
set := len(args) == 2
if set {
team = strings.TrimSpace(args[1])
switch team {
case "-clear":
team = ""
case "":
return errors.New(agentTeamUsage)
}
}
c, err := connect(false)
if err != nil {
return err
}
defer c.Close()
if missing := c.MissingCapabilities([]string{proto.CapPaneTeam}); len(missing) > 0 {
return fmt.Errorf("the conch server (pid %d) is from an older build without teams; reload it with `conch server reload`", c.Server.PID)
}
id, err := resolvePane(c, ref)
if err != nil {
return err
}
var info proto.PaneInfo
if set {
if err := call(c, proto.MethodPaneTeam, proto.PaneTeamParams{ID: id, Team: team}, &info); err != nil {
return err
}
} else {
var list proto.PaneList
if err := call(c, proto.MethodPaneList, nil, &list); err != nil {
return err
}
for _, p := range list.Panes {
if p.ID == id {
info = p
}
}
}
teams := paneTeams(c, []proto.PaneInfo{info})
switch {
case teams[info.ID] != "":
how := "by hand"
if info.Team == "" {
how = "by its rule in config.toml"
}
fmt.Printf("%s is in %s (%s)\n", info.ID, teams[info.ID], how)
case info.Team == config.NoTeam:
fmt.Printf("%s is kept out of every team\n", info.ID)
default:
fmt.Printf("%s is in no team\n", info.ID)
}
return nil
}

// paneTeams is each pane's team, by hand or by config.toml's rules (an
// agent's project and branch); "" for none.
func paneTeams(c *client.Client, panes []proto.PaneInfo) map[string]string {
var teams []config.Team
if cfg, err := config.Load(); err == nil {
teams = cfg.Teams
}
names := map[string]string{}
if len(teams) > 0 {
var projects proto.ProjectList
if call(c, proto.MethodProjectList, nil, &projects) == nil {
for _, p := range projects.Projects {
names[p.ID] = p.Name
}
}
}
out := map[string]string{}
for _, p := range panes {
out[p.ID] = config.TeamFor(teams, p.Team, names[p.ProjectID], p.Branch)
}
return out
}

// onlyTeam keeps the panes in team (any case).
func onlyTeam(c *client.Client, panes []proto.PaneInfo, team string) []proto.PaneInfo {
teams := paneTeams(c, panes)
var out []proto.PaneInfo
for _, p := range panes {
if strings.EqualFold(teams[p.ID], team) {
out = append(out, p)
}
}
return out
}
122 changes: 122 additions & 0 deletions cmd/conch/team_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package main

import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"

"github.com/Amitgb14/conch/internal/config"
"github.com/Amitgb14/conch/internal/proto"
)

// teamServer is a fake server with three agents in two projects; pane.team
// is recorded and answered with the pane in that team.
func teamServer(t *testing.T) *a4Var[[]proto.PaneTeamParams] {
t.Helper()
a4Env(t)
os.WriteFile(filepath.Join(config.Dir(), "config.toml"), []byte(`
[[teams]]
name = "Backend"
projects = ["api"]

[[teams]]
name = "UI"
branches = ["ui/*"]
`), 0o644)
srv := startA4Server(t, config.SocketPath())
seen := newA4Var([]proto.PaneTeamParams(nil))
panes := []proto.PaneInfo{
{ID: "p1", Name: "claude", State: proto.PaneRunning, ProjectID: "r1", Branch: "retry", Agent: &proto.AgentStatus{Name: "claude"}},
{ID: "p2", Name: "codex", State: proto.PaneRunning, ProjectID: "r2", Branch: "ui/nav", Agent: &proto.AgentStatus{Name: "codex"}},
{ID: "p3", Name: "gemini", State: proto.PaneRunning, ProjectID: "r2", Branch: "docs", Team: "Report", Agent: &proto.AgentStatus{Name: "gemini"}},
{ID: "p4", Name: "out", State: proto.PaneRunning, ProjectID: "r1", Branch: "x", Team: config.NoTeam, Agent: &proto.AgentStatus{Name: "claude"}},
}
srv.setHandle(func(msg proto.Message, _ *proto.Conn) (any, *proto.Error) {
switch msg.Method {
case proto.MethodPaneList:
return proto.PaneList{Panes: panes}, nil
case proto.MethodProjectList:
return proto.ProjectList{Projects: []proto.ProjectInfo{{ID: "r1", Name: "api"}, {ID: "r2", Name: "web"}}}, nil
case proto.MethodPaneTeam:
var p proto.PaneTeamParams
json.Unmarshal(msg.Params, &p)
seen.Set(append(seen.Get(), p))
for _, q := range panes {
if q.ID == p.ID {
q.Team = p.Team
return q, nil
}
}
return nil, proto.Errorf(proto.ErrNotFound, "no pane %s", p.ID)
}
return nil, nil
})
return seen
}

func TestAgentTeam(t *testing.T) {
seen := teamServer(t)
run := func(args ...string) (string, error) {
var err error
out, _ := a4Capture(t, "", func() { err = runAgent(append([]string{"team"}, args...)) })
return out, err
}
for ref, want := range map[string]string{
"p1": "p1 is in Backend (by its rule in config.toml)",
"codex": "p2 is in UI (by its rule in config.toml)",
"p3": "p3 is in Report (by hand)",
"p4": "p4 is kept out of every team",
"gemini": "p3 is in Report (by hand)",
} {
if out, err := run(ref); err != nil || !strings.Contains(out, want) {
t.Errorf("%s: %q %v, want %q", ref, out, err, want)
}
}
if out, err := run("p1", "UX"); err != nil || !strings.Contains(out, "p1 is in UX (by hand)") {
t.Fatalf("set: %q %v", out, err)
}
run("p1", "-")
run("p1", "-clear")
got := seen.Get()
if len(got) != 3 || got[0] != (proto.PaneTeamParams{ID: "p1", Team: "UX"}) || got[1].Team != "-" || got[2].Team != "" {
t.Fatalf("sent %+v", got)
}
for _, bad := range [][]string{{}, {"p1", "a", "b"}, {"p1", " "}} {
if _, err := run(bad...); err == nil || !strings.Contains(err.Error(), "usage") {
t.Errorf("%q: %v", bad, err)
}
}
if _, err := run("nope"); err == nil {
t.Fatal("an unknown pane should fail")
}
}

func TestStatusTeam(t *testing.T) {
teamServer(t)
var err error
out, _ := a4Capture(t, "", func() { err = runStatus([]string{"-wide", "-team", "backend"}) })
if err != nil {
t.Fatal(err)
}
if !strings.Contains(out, "p1") || strings.Contains(out, "p2") || strings.Contains(out, "p4") {
t.Fatalf("backend: %s", out)
}
out, _ = a4Capture(t, "", func() { err = runStatus([]string{"-team", "Nobody"}) })
if err != nil || !strings.Contains(out, "no agents in Nobody") {
t.Fatalf("empty: %q %v", out, err)
}
}

// -team is for agents that start now: a task kept for later has no pane
// to put in a team.
func TestTaskTeamOnlyNow(t *testing.T) {
a4Env(t)
for _, extra := range [][]string{{"-at", "+30m"}, {"-every", "1h"}, {"-queue"}, {"-after", "main"}, {"-sandbox", "daytona"}} {
args := append(append([]string{"-team", "UI"}, extra...), "do it")
if err := runTask(args); err == nil || !strings.Contains(err.Error(), "start them later or elsewhere") {
t.Errorf("%v: %v", extra, err)
}
}
}
1 change: 1 addition & 0 deletions docs/testing/end-to-end.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ What it carries, and what is left over in each row:
| 9.180 🖥 | ▶ Run on a real Xcode project | Conch.app on this Mac with Xcode, a real iOS app project (an `.xcodeproj`, or a workspace with CocoaPods) whose folder holds a package with a scheme of its own: open its Mobile Preview (or the Mobile workbench) on an iPhone simulator, press **▶ Run**; change a screen and press it again; try it with the simulator shut down, and in a folder with two projects | `conch preview run` builds the app's scheme (not the package's) for that simulator with the build shown in the terminal, installs it and opens it in the phone pane with no Simulator window; the second Run shows the change; a shut simulator is started first; two projects are named and nothing is built | ☐ |
| 9.181 🖥 | Mobile options only for mobile projects | Conch.app on this Mac with three local projects: an iOS app, a plain Go service, and one whose app exists only on an agent's branch (worktree); then have an agent create an Expo app in the Go project | Right-click: **Mobile Preview** on the iOS project and the branch-only one, not on the Go service; a workbench on the Go service has no phone button and no Mobile layout; once the agent writes the Expo app's package.json, Mobile Preview appears there within seconds; in the branch-only project, ▶ Run builds in the checkout that has the app | ☐ |
| 9.182 | Pruning merged branches against GitHub | In a real repository: merge one branch's pull request on GitHub with a squash, another with a merge commit, and merge a third locally; push a fourth unmerged; commit once more on a fifth after its merge. Run `conch branch prune -merged`, then Settings → Git → Old branches → Merged in Conch.app, and delete. | All three merged ones are listed (the squashed one once GitHub says it merged), ticked, and deleted; the pushed one and the one with a later commit are not listed; a branch checked out in a worktree is listed and kept. Against a server from before this, both say to reload it and delete nothing. | ☐ |
| 9.183 🖥 | Agent teams in Conch.app with real agents | With `[[teams]]` Backend (a project) and UI (a branch pattern) and a dozen agents across two projects: watch Agents split; right-click one → Team → UI; drag another onto Backend and onto No team; New Task with a team; Show Side by Side and Broadcast to This Team… on a team's row; `conch server reload`; `conch status -team UI`. | Each project's Agents shows Backend, UI, then No team, with counts; a project with no team keeps its list. A move by menu or drag lands at once, in every window and the TUI's `conch status -team`; a reload keeps it. Side by Side puts the team's agents in one tab; the broadcast reaches only them. | ☐ |

Everything else marked 💳 wants a model: the brain's providers (1.x), an
agent's own state hooks and usage (2.1-2.5, 9.1, 9.21, 9.22, 9.70), saved
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Config struct {
// that matches deciding (permissions.go). After Actions for the same
// reason.
Permissions []PermissionRule `toml:"permissions,omitempty"`
// Teams group agents by what they work on — backend, UI, a report —
// across projects and branches (teams.go). After the plain tables too.
Teams []Team `toml:"teams,omitempty"`
}

// WebCfg is the phone gateway, conch web. URL is the address phones open —
Expand Down
Loading
Loading