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
1 change: 1 addition & 0 deletions changelog.d/added-18590-betty-hive-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **Betty answers questions about the hive from its live state.** "Betty, how many open issues are there?" or "what PRs are open in the hive repo?" is answered in seconds from the same in-memory status the Overview and the dashboard chat read (open, actionable, held and blocked counts, agents and what they are doing, recent completions, open PRs), and is no longer sent to the research agents. ([#18590](https://github.com/hivecommons/hive/issues/18590))
2 changes: 1 addition & 1 deletion src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,7 @@ func (b *boot) bootDashboardAPIWith(deps bootDashboardAPIDeps) {
rt = b.agentMgr
}
researchPool := wireMeetingsResearch(b.cfg, rt, b.logger)
if lr := wireMeetingsLive(b.cfg, mgr, store, b.knowledgeAPI, func() map[string]*beads.Store { return b.beadStores }, researchPool, b.logger); lr != nil {
if lr := wireMeetingsLive(b.cfg, mgr, store, b.knowledgeAPI, func() map[string]*beads.Store { return b.beadStores }, researchPool, b.logger, b.dashSrv.HiveStatusBrief); lr != nil {
b.meetingsLive = lr
b.cleanup.push(lr.Close)
b.cleanup.push(routeResearch(researchPool, lr))
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/hive/meetings_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestMeetingsActionsAdapterAndWiring(t *testing.T) {
Dashboard: config.DashboardConfig{PublicURL: "https://hive.example/"},
}
logger := slog.New(slog.DiscardHandler)
runner := wireMeetingsLive(cfg, mgr, store, &knowledge.KnowledgeAPI{}, nil, nil, logger)
runner := wireMeetingsLive(cfg, mgr, store, &knowledge.KnowledgeAPI{}, nil, nil, logger, nil)
if runner == nil {
t.Fatal("want a live runner")
}
Expand Down
17 changes: 13 additions & 4 deletions src/cmd/hive/meetingswire.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ func meetingSpekArgs(m meetings.Meeting, contextDir string) []string {
// in the panel instead of silently. beadStores feeds the persona's work-item
// retrieval and may be nil.
func wireMeetingsLive(cfg *config.Config, mgr *meetings.Manager, store *meetings.Store, kapi *knowledge.KnowledgeAPI,
beadStores func() map[string]*beads.Store, research live.ResearchDispatcher, logger *slog.Logger) *live.Runner {
beadStores func() map[string]*beads.Store, research live.ResearchDispatcher, logger *slog.Logger,
hiveStatus func(context.Context) (string, error)) *live.Runner {
if cfg == nil || mgr == nil || store == nil {
return nil
}
Expand Down Expand Up @@ -227,7 +228,7 @@ func wireMeetingsLive(cfg *config.Config, mgr *meetings.Manager, store *meetings
},
Ledger: live.NewLedger(m.Budget.MaxTokensPerHourOrDefault(), m.Budget.MaxTokensPerDayOrDefault()),
Logger: logger,
Persona: meetingPersonaFactory(cfg, persona, llm, store, kapi, beadStores, slotsDir, maxTokens, research != nil, logger),
Persona: meetingPersonaFactory(cfg, persona, llm, store, kapi, beadStores, slotsDir, maxTokens, research != nil, logger, hiveStatus),
PersonaName: personaName,
IsLeave: meetings.NewLeaveMatcher(persona.LeavePhrases).Match,
})
Expand All @@ -250,14 +251,22 @@ func wireMeetingsLive(cfg *config.Config, mgr *meetings.Manager, store *meetings
// Anthropic Messages API on a hive with only an Anthropic key, both charged
// to the meeting's usage file and budget. With no model she still
// introduces herself but does not answer questions. canResearch lets an
// addressed question she cannot answer well become a deep dive.
// addressed question she cannot answer well become a deep dive. hiveStatus,
// when set, is the dashboard's live hive state (open issues and PRs,
// actionable, held and blocked counts, agents): questions about the hive
// itself are answered from it in-process, never sent to research
// (hivecommons/hive#18590 finding 9).
func meetingPersonaFactory(cfg *config.Config, persona config.ResolvedMeetingsPersona, llm config.ResolvedMeetingsLLM,
store *meetings.Store, kapi *knowledge.KnowledgeAPI, beadStores func() map[string]*beads.Store,
slotsDir string, maxTokens int, canResearch bool, logger *slog.Logger) func(meetings.Meeting) *betty.Engine {
slotsDir string, maxTokens int, canResearch bool, logger *slog.Logger,
hiveStatus func(context.Context) (string, error)) func(meetings.Meeting) *betty.Engine {
if !persona.Enabled {
return nil
}
var retrievers []betty.Retriever
if hiveStatus != nil {
retrievers = append(retrievers, betty.HiveStatusRetriever{Brief: hiveStatus})
}
if kapi != nil {
stores := betty.FileStores(kapi.FileStores)
retrievers = append(retrievers, betty.KnowledgeRetriever{Stores: stores})
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/hive/meetingswire_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestMeetingPersonaFactoryAgentBackend(t *testing.T) {
cfg := &config.Config{}
persona := cfg.Meetings.Persona.Resolve()
logger := slog.New(slog.DiscardHandler)
e := meetingPersonaFactory(cfg, persona, cliLLM(bin, dir), store, nil, nil, t.TempDir(), 100, false, logger)(meetings.Meeting{ID: "m1"})
e := meetingPersonaFactory(cfg, persona, cliLLM(bin, dir), store, nil, nil, t.TempDir(), 100, false, logger, nil)(meetings.Meeting{ID: "m1"})
if e == nil {
t.Fatal("want an engine")
}
Expand All @@ -91,7 +91,7 @@ func TestMeetingPersonaFactoryAgentBackend(t *testing.T) {
e.Close()
bad := cliLLM(bin, dir)
bad.AgentBackend = "codex"
if e := meetingPersonaFactory(cfg, persona, bad, store, nil, nil, "", 0, false, logger)(meetings.Meeting{ID: "m2"}); e == nil {
if e := meetingPersonaFactory(cfg, persona, bad, store, nil, nil, "", 0, false, logger, nil)(meetings.Meeting{ID: "m2"}); e == nil {
t.Fatal("want an engine without a model")
} else {
e.Close()
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/hive/meetingswire_persona_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestMeetingPersonaFactory(t *testing.T) {
persona := cfg.Meetings.Persona.Resolve()
llm := config.ResolvedMeetingsLLM{Backend: config.MeetingsLLMModeOpenAI, Endpoint: "http://127.0.0.1:1", Model: "m", MaxInFlight: 1}
beadStores := func() map[string]*beads.Store { return nil }
fn := meetingPersonaFactory(cfg, persona, llm, store, &knowledge.KnowledgeAPI{}, beadStores, t.TempDir(), 100, true, slog.New(slog.DiscardHandler))
fn := meetingPersonaFactory(cfg, persona, llm, store, &knowledge.KnowledgeAPI{}, beadStores, t.TempDir(), 100, true, slog.New(slog.DiscardHandler), nil)
if fn == nil {
t.Fatal("the persona is on by default")
}
Expand All @@ -35,21 +35,21 @@ func TestMeetingPersonaFactory(t *testing.T) {
web := cfg.Meetings.Persona
web.SearxngURL = "http://searxng.meetings.svc.cluster.local:8080"
anth := config.ResolvedMeetingsLLM{Backend: config.MeetingsLLMModeAnthropic, AnthropicKey: "ak", Model: config.DefaultMeetingsPersonaAnthropicModel, MaxInFlight: 1}
if e := meetingPersonaFactory(cfg, web.Resolve(), anth, store, nil, nil, "", 0, false, nil)(meetings.Meeting{ID: "m3"}); e == nil {
if e := meetingPersonaFactory(cfg, web.Resolve(), anth, store, nil, nil, "", 0, false, nil, nil)(meetings.Meeting{ID: "m3"}); e == nil {
t.Fatal("want an engine on the Anthropic path")
} else {
e.Close()
}
// Without a model Betty still runs (intros only).
if e := meetingPersonaFactory(cfg, persona, config.ResolvedMeetingsLLM{Backend: config.MeetingsLLMModeNone}, store, nil, nil, "", 0, false, nil)(meetings.Meeting{ID: "m2"}); e == nil {
if e := meetingPersonaFactory(cfg, persona, config.ResolvedMeetingsLLM{Backend: config.MeetingsLLMModeNone}, store, nil, nil, "", 0, false, nil, nil)(meetings.Meeting{ID: "m2"}); e == nil {
t.Fatal("want an engine without a model")
}
off := false
cfg.Meetings.Persona.Enabled = &off
if meetingPersonaFactory(cfg, cfg.Meetings.Persona.Resolve(), llm, store, nil, nil, "", 0, false, nil) != nil {
if meetingPersonaFactory(cfg, cfg.Meetings.Persona.Resolve(), llm, store, nil, nil, "", 0, false, nil, nil) != nil {
t.Fatal("persona off means no factory")
}
r := wireMeetingsLive(cfg, mustManager(t, store), store, nil, nil, nil, nil)
r := wireMeetingsLive(cfg, mustManager(t, store), store, nil, nil, nil, nil, nil)
if r == nil {
t.Fatal("live loop without the persona")
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/hive/meetingswire_signin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestMeetingPersonaFactoryBadCABundle(t *testing.T) {
persona.Enabled = true
llm := config.ResolvedMeetingsLLM{Backend: config.MeetingsLLMModeOpenAI, Endpoint: "https://gw", Model: "m", AgentBackend: "corp-gw",
CABundle: filepath.Join(t.TempDir(), "absent.pem"), MaxInFlight: 1}
e := meetingPersonaFactory(cfg, persona, llm, store, nil, nil, "", 0, false, slog.New(slog.DiscardHandler))(meetings.Meeting{ID: "m1"})
e := meetingPersonaFactory(cfg, persona, llm, store, nil, nil, "", 0, false, slog.New(slog.DiscardHandler), nil)(meetings.Meeting{ID: "m1"})
if e == nil {
t.Fatal("want an engine")
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/hive/meetingswire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestWireMeetingsManager(t *testing.T) {
}

func TestWireMeetingsLive(t *testing.T) {
if wireMeetingsLive(nil, nil, nil, nil, nil, nil, nil) != nil {
if wireMeetingsLive(nil, nil, nil, nil, nil, nil, nil, nil) != nil {
t.Fatal("nil inputs must not build a live loop")
}
dir := t.TempDir()
Expand All @@ -213,7 +213,7 @@ func TestWireMeetingsLive(t *testing.T) {
}
defer mgr.Close()
cfg := &config.Config{Meetings: config.MeetingsConfig{Enabled: true}}
r := wireMeetingsLive(cfg, mgr, store, &knowledge.KnowledgeAPI{}, nil, nil, slog.New(slog.DiscardHandler))
r := wireMeetingsLive(cfg, mgr, store, &knowledge.KnowledgeAPI{}, nil, nil, slog.New(slog.DiscardHandler), nil)
if r == nil {
t.Fatal("want a live runner")
}
Expand Down
1 change: 1 addition & 0 deletions src/docs/meetings.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Hive attends meetings as a persona: **Betty** ("Betty Bee from the hive", she/he
- **Intro.** "Betty, introduce yourself", "who are you, Betty?" or "who's the bot?" gets the intro (`meetings.persona.intro_template`), which says what she does and how to send her home.
- **What she answers.** When addressed she answers briefly from the hive's knowledge vaults, its beads (work items), its code maps (when `knowledge.code_maps.enabled` is on) and the web (when `meetings.persona.searxng_url` is set, see [Web answers](#web-answers)), plus the last three minutes of the meeting. If she does not know, she says so. A request that is not a question gets one clarifying question or one or two sentences on the recent discussion.
- **Voice.** She speaks only when the request was spoken (addressed in the meeting's audio) or asks for it ("say it", "out loud"). She first says a short acknowledgement at once ("Let me check on that.", rotating, in the persona's language), then the answer, at most 2 sentences and 200 characters with no links or Markdown. The answer goes through the meeting's voice rules: it is spoken only when the meeting's voice is on and `meetings.voice_on_address` is true, and falls back to chat otherwise or when speaking fails; the acknowledgement is never posted to chat and is not charged to the budget. That gate is hive's, for every platform: Quorum v0.2.0 ignores `voice: false` on Discord, so hive never calls `say` for a meeting whose voice is off. A spoken "Betty?" with no question gets one clarifying question or one or two sentences on the last three minutes.
- **Questions about the hive itself.** "How many open issues are there?", "what PRs are open in the hive repo?", "which agents are working?" are answered from the hive's live dashboard state (the same open, actionable, held and blocked counts, agents and open PRs the Overview and the dashboard chat use), read in-process, so the answer comes in seconds and never goes to research. Such a question names the hive (or "the repo") or asks for open issues, open PRs, actionable items or recent merges.
- **Deep dives.** When an addressed question needs research (the model sets `needs_research`, or its confidence is below `min_confidence`) and the meeting has a research path, she says "I'll dig into that and report back", starts a research item through the same pool, cap and approval as Spek's research (shown in the panel as `betty-N`, dispatched with `betty=1` in its meta), and posts exactly one follow-up in her own voice when it completes (the summary as is if restyling fails).
- **Room questions.** Betty also answers questions people ask the room (a line ending in "?" or starting with "what", "how", "who" and the like, four words or more), but only if nobody answers within `answer_wait_s` (8 seconds), the knowledge sources had a hit, the model is at least `min_confidence` (0.75) sure, and the topic was not already answered. She never posts general commentary.
- **Caps.** Unprompted answers are capped at `per_10m` (2 per ten minutes), at least `min_gap_s` (90 seconds) apart and `per_meeting` (12) per meeting, with one reply per question, at most `queue_depth` (3) questions waiting and none older than `stale_s` (60 seconds). Addressed requests skip these caps but still go through the chat rate limit (`meetings.chat_posts_per_minute`) and the meeting budget. Chat answers are at most 3 sentences and 300 characters.
Expand Down
113 changes: 113 additions & 0 deletions src/pkg/dashboard/meetings_hive_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package dashboard

import (
"context"
"errors"
"fmt"
"strings"
"time"
)

// Hive status for the meeting attendee (hivecommons/hive#18590 finding 9).
// "Betty, how many open issues are there?" is answered from the same
// in-memory status the Overview tiles and the dashboard chat's grounded
// answers read (s.status via chatBuildSnapshot), in-process and in
// milliseconds, instead of going to the research agents. Nothing is
// fetched and nothing is written.

const (
// hiveStatusMaxListed bounds each named list (working agents, recent
// completions, open PRs) in the brief.
hiveStatusMaxListed = 5
// hiveStatusMaxChars bounds the whole brief.
hiveStatusMaxChars = 1500
// hiveStatusTextCap truncates one listed item's free text.
hiveStatusTextCap = 80
)

// errHiveStatusUnavailable means the dashboard has no status snapshot yet.
var errHiveStatusUnavailable = errors.New("hive status is still initializing")

// HiveStatusBrief is the hive's live state as a few plain sentences for
// the meeting attendee: open and actionable issues and PRs, held and
// blocked counts, items awaiting a decision, agents (working, paused,
// blocked) and what they are doing or last finished, and the newest open
// PRs.
func (s *Server) HiveStatusBrief(ctx context.Context) (string, error) {
if err := ctx.Err(); err != nil {
return "", err
}
status := s.chatStatusSnapshot()
if status == nil {
return "", errHiveStatusUnavailable
}
now := time.Now()
snap := chatBuildSnapshot(status, "", now, nil)
return hiveStatusBrief(status, snap), nil
}

func hiveStatusBrief(status *StatusPayload, snap chatSnapshot) string {
var b strings.Builder
t := snap.Totals
if t == nil {
t = &chatSnapshotTotals{}
}
oi := status.OpenItems
fmt.Fprintf(&b, "Open now: %d issues and %d PRs", oi.Issues, oi.PRs)
if oi.IssuesSyncing {
b.WriteString(" (issue count still syncing, at least this many)")
}
fmt.Fprintf(&b, ". Actionable: %d issues, %d PRs. Held: %d issues, %d PRs. Blocked: %d issues, %d PRs. Awaiting a decision: %d.",
oi.Buckets.Actionable.Issues, oi.Buckets.Actionable.PRs, oi.Buckets.Held.Issues, oi.Buckets.Held.PRs,
oi.Buckets.Blocked.Issues, oi.Buckets.Blocked.PRs, t.AwaitingDecision)

var working, blocked, done []string
for _, a := range snap.Agents {
switch {
case a.BlockedReason != "":
blocked = append(blocked, a.Name)
case a.Busy == "working":
w := a.Name
if a.Doing != "" {
w += " (" + chatTruncate(a.Doing, hiveStatusTextCap) + ")"
}
working = append(working, w)
}
if a.LastCompleted != "" {
done = append(done, a.Name+": "+chatTruncate(a.LastCompleted, hiveStatusTextCap))
}
}
fmt.Fprintf(&b, " Agents: %d, %d paused, %d blocked.", t.Agents, t.AgentsPaused, len(blocked))
hiveStatusList(&b, " Working on", working)
hiveStatusList(&b, " Blocked", blocked)
hiveStatusList(&b, " Recently finished", done)
var prs []string
for _, pr := range snap.PRs {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Advisory (low): PR titles, a.Doing and a.LastCompleted go to every meeting participant, including guests in external meetings, with no check on who is asking. Consider limiting the answer to counts unless the meeting is internal.

line := pr.Ref + " " + chatTruncate(pr.Title, hiveStatusTextCap)
if pr.CI != "" {
line += " (CI " + pr.CI + ")"
}
prs = append(prs, line)
}
hiveStatusList(&b, " Open PRs", prs)
if status.StaleSince != "" {
b.WriteString(" Some counts are last-good figures from " + status.StaleSince + ".")
}
return chatTruncate(b.String(), hiveStatusMaxChars)
}

// hiveStatusList appends "<label>: a; b; c (and N more)." when list has items.
func hiveStatusList(b *strings.Builder, label string, list []string) {
if len(list) == 0 {
return
}
more := len(list) - hiveStatusMaxListed
if more > 0 {
list = list[:hiveStatusMaxListed]
}
b.WriteString(label + ": " + strings.Join(list, "; "))
if more > 0 {
fmt.Fprintf(b, " (and %d more)", more)
}
b.WriteString(".")
}
72 changes: 72 additions & 0 deletions src/pkg/dashboard/meetings_hive_status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package dashboard

import (
"context"
"errors"
"strings"
"testing"
"time"
)

// TestHiveStatusBrief pins hivecommons/hive#18590 finding 9: the meeting
// attendee answers hive-state questions from the dashboard's in-memory
// status, the same counts the Overview shows.
func TestHiveStatusBrief(t *testing.T) {
s := &Server{}
if _, err := s.HiveStatusBrief(context.Background()); !errors.Is(err, errHiveStatusUnavailable) {
t.Fatalf("no snapshot: err = %v", err)
}
st := chatEvalStatus(time.Now())
st.OpenItems.Buckets.Actionable = FrontendOpenItemKinds{Issues: 7, PRs: 3}
st.OpenItems.Buckets.Held = FrontendOpenItemKinds{Issues: 4, PRs: 1}
st.OpenItems.Buckets.Blocked = FrontendOpenItemKinds{Issues: 2}
st.Agents = append(st.Agents, FrontendAgent{Name: "coder", State: "running", Busy: "working", Doing: "fixing #13990"})
s.status = st
got, err := s.HiveStatusBrief(context.Background())
if err != nil {
t.Fatal(err)
}
for _, want := range []string{
"Open now: 40 issues and 12 PRs.",
"Actionable: 7 issues, 3 PRs. Held: 4 issues, 1 PRs. Blocked: 2 issues, 0 PRs.",
"Agents: 17, 1 paused, 1 blocked.",
"Working on: coder (fixing #13990).",
"Blocked: reviewer-2.",
"Recently finished: scanner: opened PR hivecommons/hive#14001",
"Open PRs: ",
"14002 fix: other (CI failure)",
} {
if !strings.Contains(got, want) {
t.Errorf("brief lacks %q:\n%s", want, got)
}
}
if len(got) > hiveStatusMaxChars {
t.Fatalf("brief is %d bytes", len(got))
}

st.StaleSince = "2026-11-16T10:00:00Z"
st.OpenItems.IssuesSyncing = true
got, _ = s.HiveStatusBrief(context.Background())
if !strings.Contains(got, "at least this many") || !strings.Contains(got, "last-good figures from 2026-11-16T10:00:00Z") {
t.Fatalf("stale and syncing are said: %s", got)
}

ctx, cancel := context.WithCancel(context.Background())
cancel()
if _, err := s.HiveStatusBrief(ctx); err == nil {
t.Fatal("a cancelled context returns its error")
}
}

func TestHiveStatusListCaps(t *testing.T) {
var b strings.Builder
hiveStatusList(&b, "L", []string{"1", "2", "3", "4", "5", "6", "7"})
if got := b.String(); got != "L: 1; 2; 3; 4; 5 (and 2 more)." {
t.Fatalf("got %q", got)
}
b.Reset()
hiveStatusList(&b, "L", nil)
if b.Len() != 0 {
t.Fatal("an empty list writes nothing")
}
}
Loading
Loading