Run script/setup in new worktrees and give each task a port block

This commit is contained in:
Ian Gulliver
2026-10-15 11:52:13 -07:00
parent f5e5dd30e3
commit cfa9699f4b
15 changed files with 453 additions and 174 deletions
+26 -14
View File
@@ -62,6 +62,10 @@ type Manager struct {
snapMu sync.Mutex
snaps map[string]*snapState
setupMu sync.Mutex
setups map[string]bool
setupFailures map[string]string
bad *badLines
watchStop chan struct{}
}
@@ -95,18 +99,20 @@ type live struct {
func New(st *store.Store, limits Limits, worktreeRoot, leadRoot string) *Manager {
m := &Manager{
store: st,
limits: limits,
worktreeRoot: worktreeRoot,
leadRoot: leadRoot,
live: map[string]*live{},
rateLimits: map[api.AgentSessionVendor]map[string]any{},
leadAnswered: map[string]bool{},
paneFocused: map[string]bool{},
signals: make(chan api.Event, 1024),
snaps: map[string]*snapState{},
bad: newBadLines(),
watchStop: make(chan struct{}),
store: st,
limits: limits,
worktreeRoot: worktreeRoot,
leadRoot: leadRoot,
live: map[string]*live{},
rateLimits: map[api.AgentSessionVendor]map[string]any{},
leadAnswered: map[string]bool{},
paneFocused: map[string]bool{},
signals: make(chan api.Event, 1024),
snaps: map[string]*snapState{},
setups: map[string]bool{},
setupFailures: map[string]string{},
bad: newBadLines(),
watchStop: make(chan struct{}),
}
go m.signalLoop()
return m
@@ -406,7 +412,7 @@ func (m *Manager) turn(ctx context.Context, sess api.AgentSession, task api.Task
return api.AgentSession{}, err
}
if room {
if room && !m.settingUp(task.Id) {
return m.start(ctx, sess, task, actor, text, images, api.AgentSessionStateIdle)
}
@@ -500,6 +506,9 @@ func (m *Manager) drain(ctx context.Context) error {
}
for _, q := range queued {
if m.settingUp(q.TaskID) {
continue
}
room, err := m.hasRoom(ctx, q.Vendor)
if err != nil {
return err
@@ -652,7 +661,7 @@ func (m *Manager) ensureLive(ctx context.Context, sess api.AgentSession, task ap
}
tools := []mcp.Tool{m.askTool(l), m.cancelQuestionTool(l), m.createTaskTool(l), m.setMergeTitleTool(l)}
hooks := map[string][]claude.HookMatcher{
"UserPromptSubmit": {{Func: remindGuidance(g)}},
"UserPromptSubmit": {{Func: m.remindTaskGuidance(l, g)}},
"Stop": {{Func: m.bounceProseQuestion(l)}},
"PostToolUse": {{Func: m.afterTool(l)}},
}
@@ -677,6 +686,9 @@ func (m *Manager) ensureLive(ctx context.Context, sess api.AgentSession, task ap
Hooks: hooks,
OnBadLine: func(line []byte, reason string) { m.recordBadLine(l, line, reason) },
}
if l.owner == "" {
opts.Env = portEnv(task)
}
started, err := m.store.SessionStarted(ctx, sess.Id)
if err != nil {
return nil, err