Format swarm code

This commit is contained in:
patriceckhart 2026-05-16 14:01:23 +02:00
parent 36f190af31
commit 37526a6286
8 changed files with 32 additions and 32 deletions

View file

@ -948,7 +948,7 @@ func (d *swarmDialog) Render(th tui.Theme, width int) []string {
return d.renderTranscript(th, width)
}
out := []string{frameHeader(th, "swarm (n new · p prompt · R resume · ↑/↓ move · enter view · k kill · r remove · esc close)", width)}
out := []string{frameHeader(th, "swarm (n new, p prompt, R resume, ↑/↓ move, enter view, k kill, r remove, esc close)", width)}
if d.prompting {
return d.renderPromptEditor(th, width, out)
}
@ -960,7 +960,7 @@ func (d *swarmDialog) Render(th tui.Theme, width int) []string {
d.openModelPicker()
}
out = d.modelPicker.Render(th, width)
out = append(out, " "+th.FG256(th.Muted, "select model for next spawn · esc to cancel"))
out = append(out, " "+th.FG256(th.Muted, "select model for next spawn, esc to cancel"))
return out
}
if d.spawning {
@ -998,7 +998,7 @@ func (d *swarmDialog) Render(th tui.Theme, width int) []string {
// Matching blank row below before the hint, mirroring the
// main input's editor breathing room.
out = append(out, "")
out = append(out, " "+th.FG256(th.Muted, "enter spawn · /model pick model · @ file/dir picker · paste/drop paths become [file:] / [dir:] chips · esc cancel"))
out = append(out, " "+th.FG256(th.Muted, "enter spawn, /model pick model, @ file/dir picker, paste/drop paths become [file:] / [dir:] chips, esc cancel"))
out = append(out, frameRule(th, width))
return out
}
@ -1031,11 +1031,11 @@ func (d *swarmDialog) renderTranscript(th tui.Theme, width int) []string {
return d.Render(th, width)
}
header := []string{
frameHeader(th, "swarm: "+a.ID+" (type to send · esc back)", width),
frameHeader(th, "swarm: "+a.ID+" (type to send, esc back)", width),
" " + th.FG256(th.Muted, "task: "+a.Task),
" " + th.FG256(th.Muted, "branch: "+a.Branch),
" " + th.FG256(th.Muted, "dir: "+a.Dir),
" " + th.FG256(th.Muted, fmt.Sprintf("status: %s · %s", a.Status, a.Activity)),
" " + th.FG256(th.Muted, fmt.Sprintf("status: %s, %s", a.Status, a.Activity)),
}
if a.Model != "" {
modelLine := "model: " + a.Model
@ -1135,7 +1135,7 @@ func (d *swarmDialog) appendTranscriptEditor(out []string, th tui.Theme, width i
d.transcriptSpin.Start()
}
out = append(out, "")
prefix := fmt.Sprintf("%s %s · %s",
prefix := fmt.Sprintf("%s %s, %s",
th.FG256(th.Assistant, d.transcriptSpin.Frame()),
th.FG256(th.Assistant, a.Activity),
th.FG256(th.Muted, d.transcriptSpin.Elapsed().String()),
@ -1153,7 +1153,7 @@ func (d *swarmDialog) appendTranscriptEditor(out []string, th tui.Theme, width i
out = append(out, " "+l)
}
out = append(out, "")
out = append(out, " "+th.FG256(th.Muted, "enter send · @ file/dir picker · esc back"))
out = append(out, " "+th.FG256(th.Muted, "enter send, @ file/dir picker, esc back"))
return out
}
@ -1315,7 +1315,7 @@ func (d *swarmDialog) renderPromptEditor(th tui.Theme, width int, out []string)
}
// Matching blank row below before the hint.
out = append(out, "")
out = append(out, " "+th.FG256(th.Muted, "enter send · @ file/dir picker · esc cancel"))
out = append(out, " "+th.FG256(th.Muted, "enter send, @ file/dir picker, esc cancel"))
out = append(out, frameRule(th, width))
return out
}

View file

@ -1074,7 +1074,7 @@ func TestSwarmTranscriptGrowsWithNewMessages(t *testing.T) {
// both the new content AND keep the old content (no clipping).
cur = []swarm.AgentSnapshot{{
ID: "agent-1", Task: "x", Status: swarm.StatusRunning,
Lines: []string{"old line 1", "old line 2", "new reply A", "new reply B"},
Lines: []string{"old line 1", "old line 2", "new reply A", "new reply B"},
Started: cur[0].Started,
}}
out = strings.Join(d.Render(tui.Theme{}, 80), "\n")
@ -1262,7 +1262,7 @@ func TestSwarmTranscriptBusySpinnerRenders(t *testing.T) {
t.Error("spinner stayed live after agent reported idle")
}
// The bare word "thinking" must not appear anymore.
if strings.Contains(out, "· thinking ·") {
if strings.Contains(out, "· thinking, ") {
t.Errorf("busy line still rendered when agent is idle:\n%s", out)
}
}

View file

@ -172,9 +172,9 @@ func (i *Interactive) runSwarm(ctx context.Context, args []string) {
case 0:
i.swarmStatus("", "/swarm resume: no resumable agents (none detached or terminated)")
case 1:
i.swarmStatus("1 resumable agent · press R to resume", "")
i.swarmStatus("1 resumable agent, press R to resume", "")
default:
i.swarmStatus(fmt.Sprintf("%d resumable agents · ↑/↓ to pick · R to resume", count), "")
i.swarmStatus(fmt.Sprintf("%d resumable agents, ↑/↓ to pick, R to resume", count), "")
}
return
}

View file

@ -11,8 +11,8 @@ import (
"github.com/patriceckhart/zot/internal/agent/modes"
"github.com/patriceckhart/zot/internal/core"
"github.com/patriceckhart/zot/internal/swarm"
"github.com/patriceckhart/zot/internal/provider"
"github.com/patriceckhart/zot/internal/swarm"
)
// runSwarmAgentMode is the daemon-mode entry point used by every
@ -85,12 +85,12 @@ func runSwarmAgentMode(ctx context.Context, args Args, version string) error {
// cancel so the "cancel" inbox message can interrupt an
// in-flight turn without tearing down the whole daemon.
var (
mu sync.Mutex
turnCtx context.Context = ctx
cancelFn context.CancelFunc
busyTurn bool
turnNo int
shutdown = make(chan struct{})
mu sync.Mutex
turnCtx context.Context = ctx
cancelFn context.CancelFunc
busyTurn bool
turnNo int
shutdown = make(chan struct{})
)
runOne := func(prompt string) {

View file

@ -28,10 +28,10 @@ import (
// stat the file size and read from their last offset on every
// poll.
type Event struct {
Time time.Time `json:"time"`
Type string `json:"type"`
Data map[string]any `json:"-"`
Raw map[string]any `json:"-"` // includes type+time+data for replay
Time time.Time `json:"time"`
Type string `json:"type"`
Data map[string]any `json:"-"`
Raw map[string]any `json:"-"` // includes type+time+data for replay
}
// MarshalJSON flattens Data into the top-level object so consumers

View file

@ -179,7 +179,7 @@ func TestReloadReplaysTranscriptFromEventLog(t *testing.T) {
m := agentMeta{
ID: id, Task: "do thing", Branch: "swarm/alpha-9",
Dir: filepath.Join(root, "wt", id), Started: time.Now().Add(-time.Hour),
InboxPath: filepath.Join(stateDir, "in.sock"),
InboxPath: filepath.Join(stateDir, "in.sock"),
EventLogPath: filepath.Join(stateDir, "events.jsonl"),
SessionPath: filepath.Join(stateDir, "session.json"),
}
@ -606,11 +606,11 @@ func TestStopOnDetachedAgentIsNoopAndDoesNotPanic(t *testing.T) {
}
m := agentMeta{
ID: id, Task: "t", Branch: "swarm/" + id,
Dir: filepath.Join(root, "wt", id),
Started: time.Now().Add(-time.Hour),
InboxPath: filepath.Join(stateDir, "in.sock"),
Dir: filepath.Join(root, "wt", id),
Started: time.Now().Add(-time.Hour),
InboxPath: filepath.Join(stateDir, "in.sock"),
EventLogPath: filepath.Join(stateDir, "events.jsonl"),
SessionPath: filepath.Join(stateDir, "session.json"),
SessionPath: filepath.Join(stateDir, "session.json"),
}
mb, _ := json.MarshalIndent(m, "", " ")
if err := os.WriteFile(filepath.Join(stateDir, "meta.json"), mb, 0o644); err != nil {

View file

@ -509,7 +509,7 @@ func (f *Swarm) SnapshotAll() []AgentSnapshot {
// agentSink is the Sink the Swarm hands to each Runner.
type agentSink struct{ a *Agent }
func (s agentSink) Activity(msg string) { s.a.setActivity(msg) }
func (s agentSink) Activity(msg string) { s.a.setActivity(msg) }
func (s agentSink) Transcript(chunk string) { s.a.appendTranscript(chunk) }
func truncate(s string, n int) string {

View file

@ -207,9 +207,9 @@ func TestSnapshotIsStableAcrossAccess(t *testing.T) {
func TestTaskSlug(t *testing.T) {
cases := map[string]string{
"fix the login form": "fix-the-login-form",
" weird --- spaces!! ": "weird-spaces",
"": "agent",
"fix the login form": "fix-the-login-form",
" weird --- spaces!! ": "weird-spaces",
"": "agent",
"a-very-long-task-name-that-overflows": "a-very-long-task-name-th",
}
for in, want := range cases {