From e40b024c527c2ac5d2aa0764be216d0282610b51 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Mon, 16 Nov 2026 21:11:47 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Betty=20answers=20questions=20about?= =?UTF-8?q?=20the=20hive=20from=20its=20live=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Betty, how many open issues are there?" went to the research pool, which only reads the public web. The persona now has a hive-status retriever backed by dashboard.Server.HiveStatusBrief, built from the same in-memory status snapshot as the Overview and the grounded chat (chatBuildSnapshot): open/actionable/held/blocked counts, agents, working and blocked agents, recent completions and open PRs. A question about the hive gets that snippet, the prompt says to answer from it, and no deep dive is started. Part of hivecommons/hive#18590 Signed-off-by: Andy Anderson --- changelog.d/added-18590-betty-hive-status.md | 1 + src/cmd/hive/main.go | 2 +- src/cmd/hive/meetings_actions_test.go | 2 +- src/cmd/hive/meetingswire.go | 17 ++- src/cmd/hive/meetingswire_cli_test.go | 4 +- src/cmd/hive/meetingswire_persona_test.go | 10 +- src/cmd/hive/meetingswire_signin_test.go | 2 +- src/cmd/hive/meetingswire_test.go | 4 +- src/docs/meetings.md | 1 + src/pkg/dashboard/meetings_hive_status.go | 113 ++++++++++++++++++ .../dashboard/meetings_hive_status_test.go | 72 +++++++++++ src/pkg/meetings/betty/hivestatus.go | 86 +++++++++++++ src/pkg/meetings/betty/hivestatus_test.go | 77 ++++++++++++ src/pkg/meetings/betty/persona.go | 3 + src/pkg/meetings/betty/queue.go | 5 +- 15 files changed, 382 insertions(+), 17 deletions(-) create mode 100644 changelog.d/added-18590-betty-hive-status.md create mode 100644 src/pkg/dashboard/meetings_hive_status.go create mode 100644 src/pkg/dashboard/meetings_hive_status_test.go create mode 100644 src/pkg/meetings/betty/hivestatus.go create mode 100644 src/pkg/meetings/betty/hivestatus_test.go diff --git a/changelog.d/added-18590-betty-hive-status.md b/changelog.d/added-18590-betty-hive-status.md new file mode 100644 index 0000000000..b770bc437d --- /dev/null +++ b/changelog.d/added-18590-betty-hive-status.md @@ -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)) diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index 8a7967ecf3..712cb79b51 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -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)) diff --git a/src/cmd/hive/meetings_actions_test.go b/src/cmd/hive/meetings_actions_test.go index 14a743b593..e66986d446 100644 --- a/src/cmd/hive/meetings_actions_test.go +++ b/src/cmd/hive/meetings_actions_test.go @@ -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") } diff --git a/src/cmd/hive/meetingswire.go b/src/cmd/hive/meetingswire.go index 9ec7f72c8b..b14aaef683 100644 --- a/src/cmd/hive/meetingswire.go +++ b/src/cmd/hive/meetingswire.go @@ -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 } @@ -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, }) @@ -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}) diff --git a/src/cmd/hive/meetingswire_cli_test.go b/src/cmd/hive/meetingswire_cli_test.go index a0b88bbeb2..e909163ac6 100644 --- a/src/cmd/hive/meetingswire_cli_test.go +++ b/src/cmd/hive/meetingswire_cli_test.go @@ -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") } @@ -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() diff --git a/src/cmd/hive/meetingswire_persona_test.go b/src/cmd/hive/meetingswire_persona_test.go index 793405a164..f8cb0d6aeb 100644 --- a/src/cmd/hive/meetingswire_persona_test.go +++ b/src/cmd/hive/meetingswire_persona_test.go @@ -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") } @@ -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") } diff --git a/src/cmd/hive/meetingswire_signin_test.go b/src/cmd/hive/meetingswire_signin_test.go index c1348f50ec..d9765030e6 100644 --- a/src/cmd/hive/meetingswire_signin_test.go +++ b/src/cmd/hive/meetingswire_signin_test.go @@ -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") } diff --git a/src/cmd/hive/meetingswire_test.go b/src/cmd/hive/meetingswire_test.go index 4ebac9866c..2dd9b7980e 100644 --- a/src/cmd/hive/meetingswire_test.go +++ b/src/cmd/hive/meetingswire_test.go @@ -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() @@ -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") } diff --git a/src/docs/meetings.md b/src/docs/meetings.md index adfca57afe..621dc8e5fd 100644 --- a/src/docs/meetings.md +++ b/src/docs/meetings.md @@ -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. diff --git a/src/pkg/dashboard/meetings_hive_status.go b/src/pkg/dashboard/meetings_hive_status.go new file mode 100644 index 0000000000..384e238b15 --- /dev/null +++ b/src/pkg/dashboard/meetings_hive_status.go @@ -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 { + 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 "