diff --git a/changelog.d/added-waiting-on-you.md b/changelog.d/added-waiting-on-you.md new file mode 100644 index 0000000000..43c009b4af --- /dev/null +++ b/changelog.d/added-waiting-on-you.md @@ -0,0 +1 @@ +- The dashboard now tells the operator when work is parked on a human: `/api/stage-tracker` carries `waiting_on_human` (`count`, `items[{repo, number, type, kind, since, who}]`; kinds `needs-decision`, `ready-for-human-merge`, `approve-needed`, `returned-to-contributor-offline`, `other-human-wait`) and each item `waiting_on_you` / `wait_kind`. A second, orange **Hive activity monitor** sidebar badge and a **Waiting on you · N** topbar pill (hidden at zero) show the count; both, `?filter=waiting-on-you` and the new **Waiting on you** toolbar chip narrow the activity monitor to those rows; a debounced in-app toast (one per ten minutes, none in kiosk mode) fires when the count rises. Hold, advisories, decided rows and contributors still inside their grace are not counted. diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 92e642109a..319ac7276a 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -799,6 +799,16 @@ The header reports the filtered row count and how many need attention; paginatio **The counter beside the section name.** The left-menu counter and the header lead (`37 rows (33 issues + 4 PRs on their own row) · 3 need attention`) count *rows* of the default view, not items: every open issue is a row; a pull request is its own row only when it is not drawn under a listed issue. The Overview counter (`33/13`) prints the same open set as issues/PRs, so the two differ by exactly the pull requests that share their issue's row (`9 PRs shown on their issue's row` in the tooltip). The header and tooltip also name the PRs sharing issue rows. Filters and the kind tabs narrow the list and the `showing X–Y of N` line, never the counter. +### How you'll know something is waiting on you + +The hive often parks work on a person: a decision asked at **045** / **085**, a PR at **090** ready for a human merge, an approval the hive's GitHub App cannot give (`needs-human`, `unauthorized`), or a contributor who has gone offline past their grace so the operator is the fallback. Those waits used to look like any other row ("PR in progress"); nothing added them up and nothing said so. Three surfaces now read one server block, `/api/stage-tracker` → `waiting_on_human` (`count`, `items[{repo, number, type, kind, since, who}]`), so a human wait is never silent: + +- **Sidebar.** A second, orange badge on **Hive activity monitor** carries the waiting-on-you count (the grey badge stays the row count). Its tooltip lists the five longest waits with what each needs and how long it has waited. Hidden at zero. +- **Topbar.** A **Waiting on you · N** pill sits beside **Health**, hidden at zero. Click it to land on the activity monitor with the **Waiting on you** filter applied; `?filter=waiting-on-you` on the dashboard URL does the same (for links from chat or a notification). +- **Toast.** When the count rises between two polls, one in-app toast says **N items need your decision — #15312, #15433 …** with a **Show** action that applies the filter. At most one toast per ten minutes; none in kiosk mode. + +`kind` is one of `needs-decision` (045 / 085 or the `needs-decision` modifier), `ready-for-human-merge` (090), `approve-needed` (`needs-human` / `unauthorized`), `returned-to-contributor-offline` (071 / 072 once the author's grace has elapsed — `who` is then the contributor, the operator being their fallback), `other-human-wait` (015 triage). `who` is `operator` for everything the signed-in operator / maintainers must do themselves. Rows on **hold**, advisories, decided rows and PRs nested under a listed issue are not counted: hold is the operator's own choice, an advisory asks for nothing, and a decided row is the hive's to act on next. Each item also carries `waiting_on_you` / `wait_kind`, which is what the **Waiting on you** toolbar chip filters on. + ### Filters, sorting and pagination Filters run on the cached browser payload and persist across reloads, except the page number: @@ -806,6 +816,7 @@ Filters run on the cached browser payload and persist across reloads, except the - Kind, **Repo**, **Author** kind and search (`#number`, number or title substring, including covering PRs). - **Since**: any, over one hour/day/week on the current step, or past that stage's configured dwell. Stalled items always qualify. - **Needs attention**: drawn health modifiers or a human-gated stage. Deferred merge-gate pills do not qualify; a handled regression alone does not qualify. +- **Waiting on you**: only rows the server flagged `waiting_on_you` (see *How you'll know something is waiting on you* above). - Synthetic **Needs human** / **On hold** facets and label chips, described below. Stage labels sort numerically, then other labels alphabetically, case-insensitively. Chips within one family OR; families AND; synthetic facets AND with label chips. **+N more** opens *All labels*, with every label and count, type-to-filter, toggles and **Clear**. Selected labels are promoted into the visible row. **Clear filters** appears whenever the view is narrowed. diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index c3e68d0aea..2c2635b1a7 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -76,6 +76,10 @@ type StageTrackerResponse struct { // filter cannot disagree. NeedsHuman int `json:"needs_human"` OnHold int `json:"on_hold"` + // WaitingOnHuman lists the items parked on the operator / maintainers + // (stage_tracker_waiting.go): the sidebar badge, topbar pill and + // toast read it so a human wait is never silent. + WaitingOnHuman StageTrackerWaitingOnHuman `json:"waiting_on_human"` // Engine is the ADR-0025 central stage engine's mode and counters for // the tracker's status strip; absent when the hive has no engine. Engine *stageengine.Status `json:"engine,omitempty"` @@ -327,6 +331,12 @@ type StageTrackerItem struct { // OnHold is true when the item wears a hold pill: paused on purpose, // waiting on nobody. OnHold bool `json:"on_hold,omitempty"` + // WaitingOnYou is true when the item is parked on the signed-in + // operator / maintainers (stage_tracker_waiting.go); WaitKind names + // why (needs-decision, ready-for-human-merge, approve-needed, + // returned-to-contributor-offline, other-human-wait). + WaitingOnYou bool `json:"waiting_on_you,omitempty"` + WaitKind string `json:"wait_kind,omitempty"` // Hold says who set the `hold` label and why, when the stage-label // pass could read it (hivecommons/hive#15020): the pill then reads // "Held by hive · reporter trust (issue #N by @X, contributor)" or @@ -2441,6 +2451,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto applyRebaseAttempts(resp.Items) s.applyRebaseMergeFollowThrough(resp.Items, now) resp.NeedsHuman, resp.OnHold = stageTrackerHumanCounts(resp.Items) + resp.WaitingOnHuman = stageTrackerWaitingOnHuman(resp.Items) stageTrackerResolveLinkedPRs(resp.Items, prOpen) stageTrackerMarkClosedBy(resp.Items, s.mergedLedger().ClosedBy) stageTrackerResolveActors(resp.Items) diff --git a/src/pkg/dashboard/stage_tracker_ui_test.go b/src/pkg/dashboard/stage_tracker_ui_test.go index 5088befc1c..a8c7850482 100644 --- a/src/pkg/dashboard/stage_tracker_ui_test.go +++ b/src/pkg/dashboard/stage_tracker_ui_test.go @@ -20,6 +20,16 @@ func TestStageTrackerSectionWiring(t *testing.T) { `.ham-select {`, `.ham-repo-filter {`, `id="activity-monitor-sidebar-badge"`, + // Waiting-on-you surfacing (hivecommons/hive#15638): second sidebar + // badge, topbar pill, toolbar chip and the filter key they share. + `id="activity-monitor-waiting-badge" class="badge-count oc-nav-count oc-nav-count--waiting" data-zero`, + `id="oc-waiting-on-you" data-action="showWaitingOnYou"`, + `id="activity-monitor-waiting" data-action="hamFilter" data-arg0="waitingOnYou" data-arg1="toggle"`, + `if (f.waitingOnYou && !item.waiting_on_you) return false;`, + `function stageTrackerRenderWaiting(d, nowMs)`, + `function stageTrackerWaitingToast(w, nowMs)`, + `if (typeof window.hiveKioskMode === 'function' && window.hiveKioskMode()) return;`, + `const STAGE_TRACKER_WAITING_FILTER_PARAM = 'waiting-on-you';`, `'activity-monitor-section': { title: '📍 Hive activity monitor'`, `'activity-monitor-section': { heading: 'Hive activity monitor'`, `'activity-monitor-section', 'agents-section', 'agent-activity-section', 'faq-section'`, diff --git a/src/pkg/dashboard/stage_tracker_waiting.go b/src/pkg/dashboard/stage_tracker_waiting.go new file mode 100644 index 0000000000..94c08da7a0 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_waiting.go @@ -0,0 +1,164 @@ +package dashboard + +import ( + "slices" + "sort" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// Waiting-on-you aggregation (hivecommons/hive#15638): the stage tracker +// payload names every open item that is parked on the signed-in operator +// (or any maintainer) so the SPA can wear a second sidebar badge, a topbar +// pill and fire a toast. Before this the operator learned that a dozen +// PRs had sat at 085 needs-decision for 3–21 hours only by reading each +// row. The aggregation reuses the per-item fields the tracker already +// computes (Stage, Modifiers, DecisionNeeded, Adoption, Takeover, Decided, +// Advisory) and invents no new state. + +// Wait kinds carried in StageTrackerWaitingItem.Kind and +// StageTrackerItem.WaitKind. +const ( + // waitKindNeedsDecision: 085 PR needs-decision / 045 issue + // needs-decision, or the needs-decision modifier. + waitKindNeedsDecision = "needs-decision" + // waitKindReadyForHumanMerge: 090, a trusted human must press merge. + waitKindReadyForHumanMerge = "ready-for-human-merge" + // waitKindReturnedOffline: 071 / 072 with the contributor offline past + // the grace, so the operator is the fallback (adopt / reroute). + waitKindReturnedOffline = "returned-to-contributor-offline" + // waitKindApproveNeeded: needs-human or unauthorized — the hive's App + // lacks the permission or a lane rule wants a human approval. + waitKindApproveNeeded = "approve-needed" + // waitKindOther: any other stage only a person can advance (015 + // triage-needed). + waitKindOther = "other-human-wait" +) + +// waitWhoOperator is the Who value for a wait that falls to the signed-in +// operator / maintainers rather than a named contributor. +const waitWhoOperator = "operator" + +// StageTrackerWaitingOnHuman is the payload header's waiting_on_human block. +type StageTrackerWaitingOnHuman struct { + // Count is len(Items): the number the badges show. + Count int `json:"count"` + // Items lists the waits, longest waiting first. + Items []StageTrackerWaitingItem `json:"items"` +} + +// StageTrackerWaitingItem is one item parked on the operator. +type StageTrackerWaitingItem struct { + Repo string `json:"repo"` + Number int `json:"number"` + // Type is pr or issue. + Type string `json:"type"` + // Kind is one of the waitKind* constants. + Kind string `json:"kind"` + // Since is when the wait began: the decision's asked time when one is + // recorded, else when the item entered its stage. + Since *time.Time `json:"since,omitempty"` + // Who is the login the wait is attributed to: "operator" for the + // signed-in operator / maintainers, else the contributor whose + // offline grace ran out (the operator is their fallback). + Who string `json:"who"` +} + +// stageTrackerReturnedStages are the stages where the row waits on its +// author; the operator only inherits the wait once the author is offline +// past the grace. +var stageTrackerReturnedStages = []int{stagelabels.NeedsAuthor.Number(), stagelabels.ReturnedToContributor.Number()} + +// stageTrackerWaitKind classifies the human wait on it, "" when the item +// waits on nobody the operator is answerable for. Hold, advisories and +// already-decided rows never count: hold is the operator's own choice, +// an advisory asks for nothing, and a decided row is the hive's to act +// on next. +func stageTrackerWaitKind(it StageTrackerItem) (kind, who string) { + if stageTrackerOnHold(it) || it.Advisory != nil || it.Decided != nil { + return "", "" + } + switch { + case it.Stage == stagelabels.NeedsDecision.Number(), it.Stage == stagelabels.IssueNeedsDecision.Number(), slices.Contains(it.Modifiers, modNeedsDecision): + return waitKindNeedsDecision, waitWhoOperator + case it.Stage == stagelabels.ReadyForHumanMerge.Number(): + return waitKindReadyForHumanMerge, waitWhoOperator + case slices.Contains(it.Modifiers, modNeedsHuman), slices.Contains(it.Modifiers, modUnauthorized): + return waitKindApproveNeeded, waitWhoOperator + case slices.Contains(stageTrackerReturnedStages, it.Stage): + if !stageTrackerContributorGraceElapsed(it) { + return "", "" + } + who := it.Author + if it.Adoption != nil && it.Adoption.Author != "" { + who = it.Adoption.Author + } + if who == "" { + who = waitWhoOperator + } + return waitKindReturnedOffline, who + case it.Stage == stagelabels.TriageNeeded.Number(): + return waitKindOther, waitWhoOperator + } + return "", "" +} + +// stageTrackerContributorGraceElapsed reports whether a row returned to +// its contributor has outlived their grace, so the operator is now the +// one the hive waits on (adopt / reroute / nudge by hand). +func stageTrackerContributorGraceElapsed(it StageTrackerItem) bool { + if it.Takeover != nil && (it.Takeover.GraceElapsed || it.Takeover.AdoptNow) { + return true + } + if it.Adoption != nil && it.Adoption.Due { + return true + } + return it.Presence != nil && it.Presence.Next == presenceNextAdopt +} + +// stageTrackerWaitSince is when the wait on it began. +func stageTrackerWaitSince(it StageTrackerItem) *time.Time { + if it.DecisionNeeded != nil && it.DecisionNeeded.Since != nil { + return it.DecisionNeeded.Since + } + if it.Presence != nil && it.Presence.Since != nil { + return it.Presence.Since + } + return it.StageSince +} + +// stageTrackerWaitingOnHuman flags every item parked on the operator +// (WaitingOnYou / WaitKind) and returns the header block, longest wait +// first. Nested rows (an issue's covering PR drawn under it) are skipped +// so one decision is counted once. +func stageTrackerWaitingOnHuman(items []StageTrackerItem) StageTrackerWaitingOnHuman { + out := StageTrackerWaitingOnHuman{Items: []StageTrackerWaitingItem{}} + for i := range items { + it := &items[i] + it.WaitingOnYou, it.WaitKind = false, "" + if it.NestedUnder != 0 { + continue + } + kind, who := stageTrackerWaitKind(*it) + if kind == "" { + continue + } + it.WaitingOnYou, it.WaitKind = true, kind + out.Items = append(out.Items, StageTrackerWaitingItem{Repo: it.Repo, Number: it.Number, Type: it.Kind, Kind: kind, Since: stageTrackerWaitSince(*it), Who: who}) + } + sort.SliceStable(out.Items, func(a, b int) bool { + sa, sb := out.Items[a].Since, out.Items[b].Since + switch { + case sa == nil && sb == nil: + return false + case sa == nil: + return false + case sb == nil: + return true + } + return sa.Before(*sb) + }) + out.Count = len(out.Items) + return out +} diff --git a/src/pkg/dashboard/stage_tracker_waiting.test.js b/src/pkg/dashboard/stage_tracker_waiting.test.js new file mode 100644 index 0000000000..39914a9d3f --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_waiting.test.js @@ -0,0 +1,157 @@ +// Waiting-on-you surfacing (hivecommons/hive#15638): the tracker payload's +// waiting_on_human block feeds a second sidebar badge, a topbar pill and a +// debounced toast; the Waiting on you filter keeps only flagged rows. The +// functions are lifted out of index.html so this runs against the shipped +// source. +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); + +function pick(re, what) { + const m = html.match(re); + assert.ok(m, what + ' not found in index.html'); + return m[0]; +} + +function load(env) { + const src = [ + 'var toasts = [];', + 'var navigated = [];', + 'var filtered = [];', + 'function showToast(msg, type, opts) { toasts.push({ msg, type, opts }); }', + 'function ocNavigate(s) { navigated.push(s); }', + 'function hamFilter(k, v) { filtered.push([k, v]); }', + 'function stageTrackerActedAgo(ms) { return Math.round(ms / 3600000) + "h"; }', + 'function stageTrackerLoadFilter() {}', + 'function stageTrackerSaveFilter() {}', + 'var _stageTrackerFilter = {};', + pick(/const STAGE_TRACKER_WAITING_TOAST_GAP_MS = [^\n]*\n/, 'GAP'), + pick(/const STAGE_TRACKER_WAITING_TOAST_MS = [^\n]*\n/, 'TOAST_MS'), + pick(/const STAGE_TRACKER_WAITING_TOOLTIP_MAX = [^\n]*\n/, 'TOOLTIP_MAX'), + pick(/const STAGE_TRACKER_WAITING_TOAST_NUMBERS = [^\n]*\n/, 'TOAST_NUMBERS'), + pick(/const STAGE_TRACKER_WAITING_TOAST_KEY = [^\n]*\n/, 'TOAST_KEY'), + pick(/const STAGE_TRACKER_WAITING_FILTER_PARAM = [^\n]*\n/, 'FILTER_PARAM'), + pick(/const STAGE_TRACKER_WAIT_KIND_WORDS = \{[\s\S]*?\n \};\n/, 'WAIT_KIND_WORDS'), + 'var _stageTrackerWaitingPrevCount = null;', + pick(/function stageTrackerWaitingOnYou\(d\) \{[\s\S]*?\n \}\n/, 'stageTrackerWaitingOnYou'), + pick(/function stageTrackerWaitKindWords\(kind\) \{[^\n]*\n/, 'stageTrackerWaitKindWords'), + pick(/function stageTrackerWaitingTitle\(w, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerWaitingTitle'), + pick(/function stageTrackerRenderWaiting\(d, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerRenderWaiting'), + pick(/function stageTrackerWaitingToast\(w, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerWaitingToast'), + pick(/function stageTrackerWaitingToastText\(w\) \{[\s\S]*?\n \}\n/, 'stageTrackerWaitingToastText'), + pick(/function showWaitingOnYou\(\) \{[\s\S]*?\n \}\n/, 'showWaitingOnYou'), + pick(/function stageTrackerApplyUrlFilter\(\) \{[\s\S]*?\n \}\n/, 'stageTrackerApplyUrlFilter'), + 'return { stageTrackerWaitingOnYou, stageTrackerWaitingTitle, stageTrackerRenderWaiting, stageTrackerWaitingToast, stageTrackerWaitingToastText, showWaitingOnYou, stageTrackerApplyUrlFilter, toasts, navigated, filtered, filter: () => _stageTrackerFilter };', + ].join('\n'); + const store = {}; + const els = {}; + function el(id) { + const attrs = {}; + const label = { textContent: '' }; + return els[id] = { id, textContent: '', title: '', hidden: false, attrs, + setAttribute(k, v) { attrs[k] = v; }, removeAttribute(k) { delete attrs[k]; }, hasAttribute(k) { return k in attrs; }, + querySelector() { return label; }, label }; + } + ['activity-monitor-waiting-badge', 'oc-waiting-on-you', 'activity-monitor-waiting'].forEach(el); + els['activity-monitor-waiting-badge'].attrs['data-zero'] = ''; + els['oc-waiting-on-you'].hidden = true; + const window = Object.assign({ hiveKioskMode: () => false, location: { href: 'http://h/' } }, env || {}); + const localStorage = { getItem: k => (k in store ? store[k] : null), setItem: (k, v) => { store[k] = String(v); } }; + const history = { replaceState(_, __, u) { window.location.href = u; } }; + const document = { getElementById: id => els[id] || null }; + const api = new Function('window', 'localStorage', 'history', 'document', 'URL', src)(window, localStorage, history, document, URL); + return Object.assign(api, { els, store, window }); +} + +const payload = (items) => ({ waiting_on_human: { count: items.length, items } }); +const T0 = Date.parse('2026-10-20T12:00:00Z'); +const items3 = [ + { repo: 'o/r', number: 15312, type: 'pr', kind: 'needs-decision', since: '2026-10-20T06:00:00Z', who: 'operator' }, + { repo: 'o/r', number: 15433, type: 'pr', kind: 'ready-for-human-merge', since: '2026-10-20T09:00:00Z', who: 'operator' }, + { repo: 'o/r', number: 41, type: 'pr', kind: 'returned-to-contributor-offline', since: '2026-10-20T11:00:00Z', who: 'karibhou' }, +]; + +test('badge, pill and chip read the block; pill hides at zero', () => { + const api = load(); + api.stageTrackerRenderWaiting(payload(items3), T0); + const badge = api.els['activity-monitor-waiting-badge'], pill = api.els['oc-waiting-on-you']; + assert.strictEqual(badge.textContent, '3'); + assert.ok(!badge.hasAttribute('data-zero')); + assert.strictEqual(pill.hidden, false); + assert.strictEqual(pill.label.textContent, 'Waiting on you · 3'); + assert.match(pill.title, /^3 waiting on you/); + assert.match(pill.title, /r#15312 — needs your decision · 6h/); + assert.match(pill.title, /r#41 — contributor offline — adopt or reroute \(@karibhou\)/); + assert.strictEqual(api.els['activity-monitor-waiting'].textContent, 'Waiting on you (3)'); + api.stageTrackerRenderWaiting(payload([]), T0); + assert.strictEqual(badge.textContent, '0'); + assert.ok(badge.hasAttribute('data-zero')); + assert.strictEqual(pill.hidden, true); + assert.strictEqual(pill.title, 'Nothing is waiting on you'); +}); + +test('tooltip lists at most five items and says how many more', () => { + const api = load(); + const many = Array.from({ length: 8 }, (_, i) => ({ repo: 'o/r', number: i + 1, kind: 'needs-decision', who: 'operator' })); + const title = api.stageTrackerWaitingTitle({ count: 8, items: many }, T0); + assert.strictEqual(title.split('\n').length, 7); + assert.match(title, /… and 3 more$/); +}); + +test('older payloads without the block fall back to per-item flags', () => { + const api = load(); + const w = api.stageTrackerWaitingOnYou({ items: [ + { repo: 'o/r', number: 1, kind: 'pr', waiting_on_you: true, wait_kind: 'needs-decision' }, + { repo: 'o/r', number: 2, kind: 'pr', waiting_on_you: true, nested_under: 9 }, + { repo: 'o/r', number: 3, kind: 'pr' }, + ] }); + assert.strictEqual(w.count, 1); + assert.strictEqual(w.items[0].number, 1); +}); + +test('toast fires once when the count rises, debounced ten minutes, with a Show action', () => { + const api = load(); + api.stageTrackerRenderWaiting(payload(items3.slice(0, 1)), T0); + assert.strictEqual(api.toasts.length, 0, 'first payload seeds the baseline, no toast'); + api.stageTrackerRenderWaiting(payload(items3), T0 + 1000); + assert.strictEqual(api.toasts.length, 1); + assert.strictEqual(api.toasts[0].type, 'warning'); + assert.strictEqual(api.toasts[0].msg, '3 items need your decision — #15312, #15433, #41'); + assert.strictEqual(api.toasts[0].opts.actionLabel, 'Show'); + assert.ok(api.toasts[0].opts.autoDismissMs > 0); + api.toasts[0].opts.onAction(); + assert.deepStrictEqual(api.navigated, ['activity-monitor-section']); + assert.deepStrictEqual(api.filtered, [['waitingOnYou', true]]); + // Within the gap: a further rise stays quiet; a drop never toasts. + api.stageTrackerRenderWaiting(payload(items3.concat([{ repo: 'o/r', number: 5, kind: 'needs-decision', who: 'operator' }])), T0 + 60 * 1000); + api.stageTrackerRenderWaiting(payload(items3), T0 + 61 * 1000); + assert.strictEqual(api.toasts.length, 1); + // After the gap a rise toasts again, and the long list is elided. + api.stageTrackerRenderWaiting(payload(items3.concat([{ repo: 'o/r', number: 5, kind: 'needs-decision', who: 'operator' }])), T0 + 11 * 60 * 1000); + assert.strictEqual(api.toasts.length, 2); + assert.strictEqual(api.toasts[1].msg, '4 items need your decision — #15312, #15433, #41 …'); +}); + +test('toast text uses the singular for one item', () => { + const api = load(); + assert.strictEqual(api.stageTrackerWaitingToastText({ count: 1, items: items3.slice(0, 1) }), '1 item needs your decision — #15312'); +}); + +test('kiosk mode never toasts', () => { + const api = load({ hiveKioskMode: () => true }); + api.stageTrackerRenderWaiting(payload([]), T0); + api.stageTrackerRenderWaiting(payload(items3), T0 + 1000); + assert.strictEqual(api.toasts.length, 0); +}); + +test('?filter=waiting-on-you applies the filter once and drops the parameter', () => { + const api = load({ location: { href: 'http://h/?filter=waiting-on-you' } }); + assert.strictEqual(api.stageTrackerApplyUrlFilter(), true); + assert.strictEqual(api.filter().waitingOnYou, true); + assert.strictEqual(api.window.location.href, 'http://h/#section-activity-monitor-section'); + const plain = load({ location: { href: 'http://h/#section-governor' } }); + assert.strictEqual(plain.stageTrackerApplyUrlFilter(), false); +}); diff --git a/src/pkg/dashboard/stage_tracker_waiting_test.go b/src/pkg/dashboard/stage_tracker_waiting_test.go new file mode 100644 index 0000000000..c9a751269d --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_waiting_test.go @@ -0,0 +1,106 @@ +package dashboard + +import ( + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// The waiting_on_human block names every item parked on the operator / +// maintainers so the SPA badges, pill and toast can never stay silent +// while a dozen PRs sit at 085 (hivecommons/hive#15638). +func TestStageTrackerWaitingOnHuman_KindsAndAttribution(t *testing.T) { + asked := time.Date(2026, 10, 20, 8, 0, 0, 0, time.UTC) + older := asked.Add(-6 * time.Hour) + items := []StageTrackerItem{ + // 085 with a recorded decision question: needs-decision, since = asked. + {Repo: "o/r", Number: 15312, Kind: "pr", Stage: stagelabels.NeedsDecision.Number(), DecisionNeeded: &StageTrackerDecision{Since: &asked}}, + // 045 issue: needs-decision too. + {Repo: "o/r", Number: 20, Kind: "issue", Stage: stagelabels.IssueNeedsDecision.Number(), StageSince: &older}, + // 090: a trusted human must press merge. + {Repo: "o/r", Number: 15433, Kind: "pr", Stage: stagelabels.ReadyForHumanMerge.Number()}, + // unauthorized modifier on an ordinary stage: approve-needed. + {Repo: "o/r", Number: 30, Kind: "pr", Stage: 60, Modifiers: []string{modUnauthorized}}, + // 072 with the contributor still inside their grace: not the + // operator's wait. + {Repo: "o/r", Number: 40, Kind: "pr", Stage: stagelabels.ReturnedToContributor.Number(), Author: "karibhou", Presence: &StageTrackerPresence{Login: "karibhou", Next: presenceNextWait}}, + // 071 with the grace elapsed: the operator is the fallback, the + // wait is attributed to the contributor. + {Repo: "o/r", Number: 41, Kind: "pr", Stage: stagelabels.NeedsAuthor.Number(), Author: "karibhou", Takeover: &StageTrackerTakeover{GraceElapsed: true}}, + // 015 triage-needed: other-human-wait. + {Repo: "o/r", Number: 50, Kind: "issue", Stage: stagelabels.TriageNeeded.Number()}, + // hold, advisory and decided rows never count. + {Repo: "o/r", Number: 60, Kind: "pr", Stage: stagelabels.NeedsDecision.Number(), Modifiers: []string{modHold}}, + {Repo: "o/r", Number: 61, Kind: "pr", Stage: stagelabels.NeedsDecision.Number(), Advisory: &StageTrackerAdvisory{}}, + {Repo: "o/r", Number: 62, Kind: "pr", Stage: stagelabels.NeedsDecision.Number(), Decided: &StageTrackerDecided{}}, + // a nested PR is counted once, under its issue. + {Repo: "o/r", Number: 63, Kind: "pr", Stage: stagelabels.NeedsDecision.Number(), NestedUnder: 20}, + // an ordinary in-flight PR waits on nobody. + {Repo: "o/r", Number: 70, Kind: "pr", Stage: 60}, + } + got := stageTrackerWaitingOnHuman(items) + if got.Count != 6 || len(got.Items) != 6 { + t.Fatalf("count = %d (%d items), want 6: %+v", got.Count, len(got.Items), got.Items) + } + want := map[int][2]string{ + 15312: {waitKindNeedsDecision, waitWhoOperator}, + 20: {waitKindNeedsDecision, waitWhoOperator}, + 15433: {waitKindReadyForHumanMerge, waitWhoOperator}, + 30: {waitKindApproveNeeded, waitWhoOperator}, + 41: {waitKindReturnedOffline, "karibhou"}, + 50: {waitKindOther, waitWhoOperator}, + } + for _, w := range got.Items { + exp, ok := want[w.Number] + if !ok { + t.Errorf("unexpected item #%d (%s)", w.Number, w.Kind) + continue + } + if w.Kind != exp[0] || w.Who != exp[1] { + t.Errorf("#%d: kind/who = %s/%s, want %s/%s", w.Number, w.Kind, w.Who, exp[0], exp[1]) + } + if w.Number == 15312 && (w.Type != "pr" || w.Since == nil || !w.Since.Equal(asked)) { + t.Errorf("#15312: type/since = %s/%v, want pr/%v", w.Type, w.Since, asked) + } + } + // Longest wait first; items with no Since sink to the end. + if got.Items[0].Number != 20 || got.Items[1].Number != 15312 { + t.Errorf("order = %d, %d; want 20 then 15312", got.Items[0].Number, got.Items[1].Number) + } + // Per-item flags mirror the block so the SPA filter shares one truth. + for _, it := range items { + _, flagged := want[it.Number] + if it.WaitingOnYou != flagged { + t.Errorf("#%d: waiting_on_you = %v, want %v", it.Number, it.WaitingOnYou, flagged) + } + if flagged && it.WaitKind != want[it.Number][0] { + t.Errorf("#%d: wait_kind = %q, want %q", it.Number, it.WaitKind, want[it.Number][0]) + } + } +} + +func TestStageTrackerWaitingOnHuman_ZeroWhenNone(t *testing.T) { + got := stageTrackerWaitingOnHuman([]StageTrackerItem{{Repo: "o/r", Number: 1, Kind: "pr", Stage: 60}}) + if got.Count != 0 || got.Items == nil || len(got.Items) != 0 { + t.Fatalf("got %+v, want count 0 with an empty (non-nil) list", got) + } + if stageTrackerWaitingOnHuman(nil).Count != 0 { + t.Fatal("nil items must count zero") + } +} + +// Adoption.Due and Presence.Next=adopt are the other two signals that the +// contributor's grace ran out. +func TestStageTrackerWaitingOnHuman_ReturnedOfflineSignals(t *testing.T) { + stage := stagelabels.ReturnedToContributor.Number() + for name, it := range map[string]StageTrackerItem{ + "adoption-due": {Number: 1, Kind: "pr", Stage: stage, Adoption: &StageTrackerAdoption{Author: "zed", Due: true}}, + "presence-adopt": {Number: 2, Kind: "pr", Stage: stage, Author: "zed", Presence: &StageTrackerPresence{Login: "zed", Next: presenceNextAdopt}}, + } { + kind, who := stageTrackerWaitKind(it) + if kind != waitKindReturnedOffline || who != "zed" { + t.Errorf("%s: kind/who = %s/%s, want %s/zed", name, kind, who, waitKindReturnedOffline) + } + } +} diff --git a/src/pkg/dashboard/static-src/css/design-system.css b/src/pkg/dashboard/static-src/css/design-system.css index 888f034069..41957ae967 100644 --- a/src/pkg/dashboard/static-src/css/design-system.css +++ b/src/pkg/dashboard/static-src/css/design-system.css @@ -80,6 +80,10 @@ .oc-nav-count { margin-left: auto; flex: none; order: 1; } /* x/y pills (Overview, Governor) stay hidden until their feed has loaded. */ .oc-nav-count[hidden] { display: none; } + /* second Activity Monitor badge: items waiting on the operator, attention colour until zero. */ + .oc-nav-count--waiting:not([data-zero]) + .oc-nav-count { margin-left: var(--sp-1); } + .oc-nav-count--waiting:not([data-zero]) { --component-status: var(--status-attention); background: color-mix(in srgb, var(--component-status) 16%, transparent); border-color: color-mix(in srgb, var(--component-status) 50%, transparent); color: var(--component-status); } + .oc-nav-count--waiting[data-zero] { display: none; } /* pill size steps */ .token-model-chip { padding: 4px 10px; font-size: var(--fs-sm); } .nous-config-pill { padding: 3px 10px; font-size: var(--fs-sm); } diff --git a/src/pkg/dashboard/static-src/css/topbar.css b/src/pkg/dashboard/static-src/css/topbar.css index db014df0d4..ef84522944 100644 --- a/src/pkg/dashboard/static-src/css/topbar.css +++ b/src/pkg/dashboard/static-src/css/topbar.css @@ -126,6 +126,10 @@ .dashboard-custom-style-note button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: var(--fs-sm); line-height: 1; padding: var(--sp-0); } .oc-topbar-right { position: relative; z-index: 2; justify-self: end; max-width: 100%; display: flex; align-items: center; justify-content: flex-end; gap: var(--nav-chip-gap, 8px); min-width: 0; flex-wrap: nowrap; } .oc-health-badge { --nav-chip-color: var(--status-ok); } + /* Waiting on you pill (hivecommons/hive#15638): attention colour, hidden at zero, clickable. */ + .nav-chip--attention, .oc-waiting-on-you { --nav-chip-color: var(--status-attention); } + .oc-waiting-on-you { flex: 0 0 auto; cursor: pointer; font-weight: 600; } + .oc-waiting-on-you[hidden] { display: none; } #oc-settings-btn { flex: 0 0 auto; } .oc-topbar .git-version { color: var(--muted); } .oc-health-badge, #welcome-topbar-btn, #oc-gh-avatar-wrap { flex: 0 0 auto; } diff --git a/src/pkg/dashboard/static-src/css/tracker.css b/src/pkg/dashboard/static-src/css/tracker.css index f086d2bc65..7130a4da6a 100644 --- a/src/pkg/dashboard/static-src/css/tracker.css +++ b/src/pkg/dashboard/static-src/css/tracker.css @@ -30,6 +30,7 @@ .ham-chips { display: inline-flex; gap: var(--sp-1); } .ham-chip { border: var(--line-width) solid var(--line); background: transparent; color: var(--muted); border-radius: var(--r-pill); padding: var(--sp-1) var(--sp-4); font-size: var(--fs-xs); cursor: pointer; } .ham-chip[aria-pressed="true"] { background: var(--panel-strong); color: var(--text); border-color: var(--line-strong); } + .ham-chip--waiting[aria-pressed="true"] { color: var(--status-attention); border-color: var(--status-attention); } .ham-chip:hover { color: var(--text); border-color: var(--line-strong); } .ham-chip[hidden] { display: none; } .ham-chip .ham-chip-n { color: var(--text-faint); margin-left: var(--sp-1); } diff --git a/src/pkg/dashboard/static-src/html/sidebar.html b/src/pkg/dashboard/static-src/html/sidebar.html index b5f4da751e..2ca4f21c8e 100644 --- a/src/pkg/dashboard/static-src/html/sidebar.html +++ b/src/pkg/dashboard/static-src/html/sidebar.html @@ -11,7 +11,7 @@
Dashboard
🍩Overview - 📍Hive activity monitor0 + 📍Hive activity monitor00 🚦Governor 📈Throughput
diff --git a/src/pkg/dashboard/static-src/html/topbar.html b/src/pkg/dashboard/static-src/html/topbar.html index 2e000de8c9..d6696d7d0f 100644 --- a/src/pkg/dashboard/static-src/html/topbar.html +++ b/src/pkg/dashboard/static-src/html/topbar.html @@ -30,6 +30,7 @@ + Health OK @@ -7227,6 +7236,7 @@

🐝 Getting Started