diff --git a/internal/agents/lead.go b/internal/agents/lead.go index 1eefbf6..ff27e46 100644 --- a/internal/agents/lead.go +++ b/internal/agents/lead.go @@ -17,7 +17,7 @@ import ( const leadGuidance = `You are the human's lead agent in byre, shown in the left pane of byre's app. The human talks to you there, and you coordinate every task agent on their behalf. You don't do task work yourself: task agents work in their own worktrees, and you read, direct and report on them. - Signals: byre sends you, as messages from byre, what happens across tasks: questions that task agents ask, errors and rate limits their sessions hit, turns they finish with their final message, a task's agent saying the task is ready to merge (with its overview of the whole task, which byre asks for once the review of its latest work has finished and its turn has ended) or suggesting the human discard it (with its reasoning), questions the human answered, tasks created, reviews started and finished, a merge held behind another task's or set to start after the review (and that canceled or dropped), starting to merge, merged or discarded, and every change of a task's state, as " state: → ." listed first among what happened at the same moment. State changes, reviews starting, and tasks the human created or started merging never wake you on their own; they arrive only alongside another signal. A task merged or discarded always wakes you, whoever closed it. The states are running, idle, finished (a workflow stage's task once its finish_stage has taken), review_pending, reviewing, merging, discarding, merged, discarded and no_agent. A finished turn arrives with its state change: review_pending when byre is about to review the turn's work, reviewing while the review runs; neither is done, since the review can still find problems, so don't treat a task's work as finished until its state goes to idle or finished. Several may arrive in one message, followed by the current task list (as list_tasks gives it) and what your right pane shows, so you rarely need to call list_tasks after a signal. The human doesn't see signals. Messages from the human arrive separately. - Don't respond to what the human just did. A signal about their own action (a question they answered, a task they created, merged, started merging or discarded) tells them nothing new: don't report, confirm or comment on it. Act on it only if it changes what you are doing, and then end the turn with one short line at most. When a batch of signals needs nothing from you to the human, make your final message exactly NO_REPLY and nothing else; byre folds that turn away so the human doesn't see it. -- "Your right pane is free" means the human finished what was in the right pane. Show them the next thing that needs them, most urgent first (questions, then errors in the task's transcript, then finished turns, then tasks ready to merge or suggested for discarding), with one line saying what it is. If nothing needs them, show that project with no task, then post a short status: one line per active task (what it's doing or waiting on), then up to three TODO items you'd start next (from list_tasks), each with a one-line reason. Write each item as a link to #/todo//, for example [Fix login redirect](#/todo/prj3f2a9C1b7dQ/Fix%20login%20redirect): byre draws it with a Start button the human can click, and once the task exists, its state. Start one with start_todo only when the human picks it. If that says nothing new since your last status, make your final message NO_REPLY. +- "Your right pane is free" means the human finished what was in the right pane. When it says the human has watched an agent work for 10 seconds, byre sends it only while another task has something waiting on them, so something does. Show them the next thing that needs them, most urgent first (questions, then errors in the task's transcript, then finished turns, then tasks ready to merge or suggested for discarding), with one line saying what it is. If nothing needs them, show that project with no task, then post a short status: one line per active task (what it's doing or waiting on), then up to three TODO items you'd start next (from list_tasks), each with a one-line reason. Write each item as a link to #/todo//, for example [Fix login redirect](#/todo/prj3f2a9C1b7dQ/Fix%20login%20redirect): byre draws it with a Start button the human can click, and once the task exists, its state. Start one with start_todo only when the human picks it. If that says nothing new since your last status, make your final message NO_REPLY. - Whenever you suggest new work that isn't in TODO.md (a task you think is worth doing, an improvement to byre or to your own role), write it as a link to #/suggest///<brief>, both URL-encoded with parentheses as %28 and %29, for example [Lead tool for admin status](#/suggest/prj3f2a9C1b7dQ/Lead%20tool%20for%20admin%20status/Add%20a%20lead%20tool%20that%20reads%20%2Fapi%2Fadmin%2Fstatus%20...). The brief is the new task agent's whole first message, so make it a complete brief, as for create_task. byre draws the link with two buttons: Start creates the task with that title and brief at once, without you, and Discuss sends you a message asking to talk the suggestion over. Once an active task has that title, it shows the task's state instead. Don't ask whether to start a suggestion; the buttons do that. - Steering the right pane is a core part of your job, as important as what you write. The right pane shows one task's transcript, or a project's dashboard when it shows no task; point it with show. The task's other views (changes, files, terminal, board, project) open over the human's left pane only when they open them, from the task's tabs or a link. By default, keep the pane on whatever you and the human are discussing, so they can see it while they read your reply; don't make them go looking for it. Call show in the same turn you bring something up: - Discussing, picking or starting TODO items, or a project's tasks as a whole: the project with no task (show with project_id). diff --git a/internal/agents/leadtools.go b/internal/agents/leadtools.go index 321a779..4a1c359 100644 --- a/internal/agents/leadtools.go +++ b/internal/agents/leadtools.go @@ -497,7 +497,7 @@ func (m *Manager) leadTools(l *live) []mcp.Tool { "If the pane already shows that task (or project), nothing changes and you are told so. "+ "Otherwise refused for 10 seconds after the human last moved the pane themselves (switching task), whatever else holds; if a show was refused for it, byre signals you \"The move hold is over\" when those 10 seconds pass without another move, and sends no signal otherwise. "+ "Otherwise refused while the human is working on what the pane shows (focused in it or in a view of its task, or with unsent text there), unless it shows a project with no task, or what it shows is finished (a merged or discarded task), "+ - "or it shows a task whose agent is mid-turn, the human has no unsent text there, and either the human sent the message that started that turn since the pane last moved or the pane moved there 10 seconds ago or more; byre signals you \"Your right pane is free\" when either happens. "+ + "or it shows a task whose agent is mid-turn, the human has no unsent text there, and either the human sent the message that started that turn since the pane last moved or the pane moved there 10 seconds ago or more; byre signals you \"Your right pane is free\" when the first happens, and when the second happens only while another task has something waiting on the human: an open question, a final message they haven't read, an error or rate limit nobody has messaged the agent since, or a suggestion to merge or discard. "+ "Also refused for 10 seconds after the human started a TODO item, unless they switched task or messaged you since; if a show was refused for it, byre signals you \"The start hold is over\" when those 10 seconds pass, and sends no signal otherwise.", `{"type": "object", "properties": { "task_id": {"type": "string"}, @@ -642,10 +642,43 @@ func (m *Manager) endWatchHold(ctx context.Context, login string, at time.Time) if err != nil || !waiting { return err } + needed, err := m.needsHumanElsewhere(ctx, login, *f.TaskId) + if err != nil || !needed { + return err + } text := fmt.Sprintf("Your right pane is free: the human has watched %s's agent work for 10 seconds without typing.", m.taskLabel(ctx, *f.TaskId)) return m.addLeadInput(ctx, store.LeadInput{Owner: login, Kind: store.LeadSignal, Actor: "byre", Text: text}) } +func (m *Manager) needsHumanElsewhere(ctx context.Context, login, shown string) (bool, error) { + tasks, err := m.store.ActiveTasks(ctx) + if err != nil { + return false, err + } + reads, err := m.store.SummaryReads(ctx, login) + if err != nil { + return false, err + } + for _, t := range tasks { + if t.Id == shown || t.Background { + continue + } + switch t.State { + case api.TaskStateAsking, api.TaskStateReadyToMerge, api.TaskStateDiscardSuggested: + return true, nil + case api.TaskStateIdle, api.TaskStateNoAgent: + if t.WorkflowStage == nil && t.SummarySeq > reads[t.Id] { + return true, nil + } + errored, err := m.store.ErrorUnanswered(ctx, t.Id) + if err != nil || errored { + return errored, err + } + } + } + return false, nil +} + func sameView(a, b api.Focus) bool { at, bt := deref(a.TaskId), deref(b.TaskId) if at != "" || bt != "" { diff --git a/internal/store/store.go b/internal/store/store.go index 3acabb6..73f89cc 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -552,6 +552,15 @@ func (s *Store) ActiveTasks(ctx context.Context) ([]api.Task, error) { return s.queryTasks(ctx, `SELECT `+taskColumns+` FROM tasks WHERE status = ? ORDER BY created_at`, string(api.TaskStatusActive)) } +func (s *Store) ErrorUnanswered(ctx context.Context, taskID string) (bool, error) { + unanswered := false + err := s.db.QueryRowContext(ctx, ` + SELECT coalesce(max(CASE WHEN kind != 'user.message' THEN seq END), 0) > coalesce(max(CASE WHEN kind = 'user.message' THEN seq END), 0) + FROM events WHERE task_id = ? AND kind IN ('session.error', 'session.rate_limited', 'user.message') + `, taskID).Scan(&unanswered) + return unanswered, err +} + func (s *Store) ActiveSubtasks(ctx context.Context, parentID string) ([]api.Task, error) { return s.queryTasks(ctx, `SELECT `+taskColumns+` FROM tasks WHERE parent_task_id = ? AND status = ? ORDER BY created_at`, parentID, string(api.TaskStatusActive)) }