From 331e7b4b2d86f5d4fb1ba905e904511787e37234 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 11:24:45 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20tracker:=20show=20where=20an=20adop?= =?UTF-8?q?ted=20PR=20came=20from?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #15396 Signed-off-by: Andrew Anderson --- changelog.d/added-tracker-lineage-chip.md | 1 + src/docs/api-reference/dashboard-misc.md | 2 +- src/docs/dashboard-sections.md | 2 + src/pkg/dashboard/stage_tracker.go | 11 + src/pkg/dashboard/stage_tracker_lineage.go | 191 ++++++++++++++++++ .../dashboard/stage_tracker_lineage_test.go | 127 ++++++++++++ src/pkg/dashboard/static-src/css/tracker.css | 4 + .../static-src/js/tracker-actions.js | 2 +- .../dashboard/static-src/js/tracker-row.js | 67 +++++- src/pkg/dashboard/static/index.html | 73 ++++++- 10 files changed, 467 insertions(+), 13 deletions(-) create mode 100644 changelog.d/added-tracker-lineage-chip.md create mode 100644 src/pkg/dashboard/stage_tracker_lineage.go create mode 100644 src/pkg/dashboard/stage_tracker_lineage_test.go diff --git a/changelog.d/added-tracker-lineage-chip.md b/changelog.d/added-tracker-lineage-chip.md new file mode 100644 index 0000000000..1ad4870873 --- /dev/null +++ b/changelog.d/added-tracker-lineage-chip.md @@ -0,0 +1 @@ +- The activity monitor's tracker now says where an adopted PR came from: the hive's copy wears a compact `adopted from @author's #N · 6h` chip beside its number, linked to the original, with a plain-words hover on why the hive took it over (CI red and the contributor's agent silent, a maintainer's request, a DCO / rebase re-home); a still-open original reads `superseded by #M`. The `lineage` field behind it is also what the *Let hive decide* preview and the row hover use to add *(adopted from #N)* after the PR number, so an issue covered by an adopted PR no longer looks like the hive took a contributor's PR for no reason. diff --git a/src/docs/api-reference/dashboard-misc.md b/src/docs/api-reference/dashboard-misc.md index 4c10107398..de90bd05ce 100644 --- a/src/docs/api-reference/dashboard-misc.md +++ b/src/docs/api-reference/dashboard-misc.md @@ -38,7 +38,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `GET` | `/api/budget-ignore` | Dashboard auth/session | Budget Ignore Get | `pkg/dashboard/api.go:172` | | `POST` | `/api/budget-ignore` | Owner only | Budget Ignore Set | `pkg/dashboard/api.go:173` | | `GET` | `/api/summaries` | Dashboard auth/session | Summaries | `pkg/dashboard/api.go:185` | -| `GET` | `/api/stage-tracker` | Dashboard auth/session | Stage Tracker: every open issue and pull request of the watched repos for the Hive activity monitor — actionable, held, claimed, in-progress, covered-by-PR, filtered (`needs-*`), draft and exempt-labelled items alike, each with `stage`, `stage_since`, `labels`, `created_at`, `author_kind`, `modifiers`, (PRs) `sentinel_alert` / `sentinel_findings` / `sentinel_reason` when the sentinel flagged the PR, `decision_needed` on a row parked on a person (085 / 045 / 015, the needs-human pill; mirrored onto the issue's `linked_prs[]` entry): `{question, asked_by, since, blocker, blocker_reason, options: [{action, label, enabled, reason_if_disabled}]}` — the reviewer's own decision question when the verdict record has one, the blocker in plain words, and the applicable actions under the row context menu's action ids (`decide:delegate` first), and (issues) `linked_prs`; items with no stage yet report stage `0` "Open"; `needs_human_labels` is the "a person must act" label set behind the monitor's Needs human facet (the same list as `/api/status.labelPresets[needs-human]`); `recently_merged` lists the PRs (`repo`, `number`, `merged_at`) whose `pr_merged` audit entry is under 30 minutes old, so a client diffing two payloads can tell a merge from a close. Served from a server-side cache rebuilt at most every `dashboard.stage_tracker.cache_ttl_s` (default `governor.eval_interval_s`) from the spoke's existing snapshot — a request never calls GitHub. Carries `generated_at`, `source` (`cache` or `fresh`), `cache_ttl_s`, an `ETag` and `Cache-Control: private, max-age=`; `If-None-Match` yields 304. Each hit is recorded under REST caller `dashboard:stage-tracker` so `/api/gh-rate-limits` shows it charged nothing. | `pkg/dashboard/api.go:186` | +| `GET` | `/api/stage-tracker` | Dashboard auth/session | Stage Tracker: every open issue and pull request of the watched repos for the Hive activity monitor — actionable, held, claimed, in-progress, covered-by-PR, filtered (`needs-*`), draft and exempt-labelled items alike, each with `stage`, `stage_since`, `labels`, `created_at`, `author_kind`, `modifiers`, (PRs) `sentinel_alert` / `sentinel_findings` / `sentinel_reason` when the sentinel flagged the PR, `decision_needed` on a row parked on a person (085 / 045 / 015, the needs-human pill; mirrored onto the issue's `linked_prs[]` entry): `{question, asked_by, since, blocker, blocker_reason, options: [{action, label, enabled, reason_if_disabled}]}` — the reviewer's own decision question when the verdict record has one, the blocker in plain words, and the applicable actions under the row context menu's action ids (`decide:delegate` first), (PRs) `lineage` on the hive's copy of an adopted PR — `{kind: adopted|superseded|rebased-by-hive, from_number, from_url, from_author, from_author_kind, to_number, to_url, at, reason}`, derived from the stage store's adoption record or the `hive/adopt-` head branch, mirrored onto the issue's `linked_prs[]` entry; absent on every other row — and (issues) `linked_prs`; items with no stage yet report stage `0` "Open"; `needs_human_labels` is the "a person must act" label set behind the monitor's Needs human facet (the same list as `/api/status.labelPresets[needs-human]`); `recently_merged` lists the PRs (`repo`, `number`, `merged_at`) whose `pr_merged` audit entry is under 30 minutes old, so a client diffing two payloads can tell a merge from a close. Served from a server-side cache rebuilt at most every `dashboard.stage_tracker.cache_ttl_s` (default `governor.eval_interval_s`) from the spoke's existing snapshot — a request never calls GitHub. Carries `generated_at`, `source` (`cache` or `fresh`), `cache_ttl_s`, an `ETag` and `Cache-Control: private, max-age=`; `If-None-Match` yields 304. Each hit is recorded under REST caller `dashboard:stage-tracker` so `/api/gh-rate-limits` shows it charged nothing. | `pkg/dashboard/api.go:186` | | `POST` | `/api/prs/{owner}/{repo}/{number}/queue-automerge` | Merger/owner role | Queue PRAuto Merge | `pkg/dashboard/api.go:187` | | `GET` | `/api/inference/models/{backend}` | Dashboard auth/session | Inference Models | `pkg/dashboard/api.go:363` | | `GET` | `/api/hive-id` | Dashboard auth/session | Hive IDGet | `pkg/dashboard/api.go:425` | diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 90e0ba6efa..1af96d284d 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -1315,6 +1315,8 @@ The same renderer serves issue decisions and every PR verdict (adopt, approve, c **Adoption pairs.** When the delegate adopts in supersede mode and hive opens its copy, the tracker shows the pair explicitly rather than two unrelated PR sub-rows: the original is dimmed — *Adopted → #15123 · superseded (hive re-authored with sign-off)* — with no action chevron and no needs-human styling; the new PR carries the single active chevron and a chip *↳ adopted from #15029 · you approved 17:51*; the issue row's pill follows the new PR. Once the original is closed it drops out of the open-PR projection, so it renders as one dimmed line from the adoption record — *#15029 · closed · superseded by #15123* — with no chevron track; never a blank numbered row. +**Lineage chip (where an adopted PR came from).** Whenever a PR row is the hive's copy of a contributor PR it adopted — whether the operator decided it or the contributor lane adopted on its own after CI went red and the contributor's agent stayed silent — the PR number carries a compact chip, *adopted from @thatguywob's #15226 · 6h*, linked to the original; the original author's kind (human / clanker / hive) is drawn as the usual author icon, never as a word. Its hover says why in plain words: *Hive took this PR over after CI went red and @thatguywob's agent didn't respond. Original commits kept.* (other reasons: at a maintainer's request, DCO / sign-off / rebase / push re-home). Issue #15198 once showed its covering PR #15308 as *Fixing* with nothing saying #15308 was adopted, so routing the fix to a hive agent read as the hive taking a clanker's PR for no reason. The chip is drawn on a top-level PR row, on an issue row's single covering PR and on each sub-row; a still-open original (close-first off) wears the reverse, *superseded by #15308 · 6h*. Behind it is the optional `lineage` field of the payload — `{kind: adopted|superseded|rebased-by-hive, from_number, from_url, from_author, from_author_kind, to_number, to_url, at, reason}` — derived from the stage store's adoption record or the `hive/adopt-` head branch, never a GitHub call; the SPA helper `stageTrackerLineageClause(item)` yields the one clause *(adopted from #15226)* any caption or preview adds after the PR number (the *Let hive decide* preview and the row hover's *Covering PR* line already do). + **A decision wins over a stale label.** Recording any decision (approve, direction, adopt, delegate-resolved) removes `needs-human` and the 045/085 *needs-decision* stage labels in the same write (`liftDelegatedParkLabels`; `pr_decision_operator.go`), and the projection never places a row in 085 while a decision exists for the current head — the row sits where hive actually is, and the popover leads with *You chose Let hive decide · hive decided: fix then merge*, not with the stale ask. **One vocabulary.** Every operator-facing string — event lines, popovers, toasts, pills — uses the chevron's stage vocabulary through one shared mapping (`stage_tracker_vocabulary.go`; `STAGE_TRACKER_STAGE_PHRASE` in the page): *its PR is review passed · waiting for merge admission*, never *PR at 060 reviewed* or *moved to stage/085-needs-decision*. A guard test scans rendered event-line fixtures for raw stage codes and fails on any. diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 174fdabbe8..2f6177f702 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -460,6 +460,11 @@ type StageTrackerItem struct { // closed, unmerged, and never a tracker row; this is the only trace of // it the tracker draws — a small chip on the live PR. Supersedes *StageTrackerSupersedes `json:"supersedes,omitempty"` + // Lineage is, on the hive's copy of an adopted PR, where it came from + // (adopted from @x's #N, when, why) and, on a still-open original, + // which copy superseded it (stage_tracker_lineage.go). Optional; a + // row with no adoption history carries none. + Lineage *StageTrackerLineage `json:"lineage,omitempty"` // Adoption is, on a nudged PR at stage/072, whether adoption is due, // what holds it, and the author's live presence, with the plain-words // line the row shows instead of a bare "Returned to contributor" @@ -620,6 +625,8 @@ type StageTrackerLinkedPR struct { AdoptedBy int `json:"adopted_by,omitempty"` AdoptedByState string `json:"adopted_by_state,omitempty"` AdoptedFrom *StageTrackerAdoptedFrom `json:"adopted_from,omitempty"` + // Lineage mirrors the nested PR's own row field. + Lineage *StageTrackerLineage `json:"lineage,omitempty"` // State is "closed" for an adopted original the hive (or a person) // closed once its copy existed (hivecommons/hive#15126): the sub-row // is one dimmed line "#N · closed · superseded by #M" with no @@ -2082,6 +2089,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto prState := s.stageTrackerPRStateResolver(status, resp.RecentlyMerged) prOpen := func(repo string, number int) bool { return prState(repo, number) == blockedOnPRStateOpen } supersedes := stageTrackerSupersedesIndex(store, status.GitHubBaseURL) + lineage := stageTrackerLineageIndex(store, status.GitHubBaseURL) issueFilter := s.issueFilterConfig() addIssue := func(repoName string, issue github.Issue, bucket, bucketReason string, progress *github.IssueChildren) { // A closed issue has no stage; a stage label it closed wearing is @@ -2200,6 +2208,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto if sup, ok := supersedes[stagelabels.Key(repoName, pr.Number)]; ok { it.Supersedes = &sup } + it.Lineage = stageTrackerLineageFor(lineage, repoName, pr.Number, pr.HeadRef, status.GitHubBaseURL) info, found := superseded[github.ReviewQueueKey(qualifyRepo(repoName), pr.Number)] if !found { info, found = superseded[github.ReviewQueueKey(repoName, pr.Number)] @@ -2258,6 +2267,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto } resp.OpenIssues, resp.OpenPRs = stageTrackerOpenCounts(resp.Items) stageTrackerMergeTrainPostPass(resp.Items) + stageTrackerLineageFillAuthors(resp.Items) s.applyOperatorActions(resp.Items, now) s.applyDecidedProjection(resp.Items, now) applyRebaseAttempts(resp.Items) @@ -3005,6 +3015,7 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem, open func(repo strin lp.Rework = pr.Rework lp.Takeover = pr.Takeover lp.Supersedes = pr.Supersedes + lp.Lineage = pr.Lineage lp.HumanApprover, lp.ManualMerge = pr.HumanApprover, pr.ManualMerge lp.HumanMergeReason, lp.HumanMergeReasonText = pr.HumanMergeReason, pr.HumanMergeReasonText lp.AdmittedBy, lp.DCOUnsigned, lp.DCOTotal = pr.AdmittedBy, pr.DCOUnsigned, pr.DCOTotal diff --git a/src/pkg/dashboard/stage_tracker_lineage.go b/src/pkg/dashboard/stage_tracker_lineage.go new file mode 100644 index 0000000000..b78a939aec --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_lineage.go @@ -0,0 +1,191 @@ +package dashboard + +import ( + "strconv" + "strings" + "time" + + "github.com/hivecommons/hive/pkg/github/automerge" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// Lineage on a tracker row (hivecommons/hive: issue #15198 showed PR +// #15308 "Fixing" with nothing saying #15308 was the hive's copy of +// @thatguywob's #15226, adopted after CI went red and the contributor's +// agent stayed silent — so routing the fix to a hive agent read as the +// hive taking over a clanker's PR for no reason). The superseding PR's +// row now carries `lineage`: where it came from, whose it was, when and +// why; the closed original (when it is still rendered, close_first off) +// carries the reverse. Everything is read from the stage store's adoption +// record (MarkAdopted / MarkSupersededClosedFirst — the same facts the +// "Supersedes #N" body line was written from) or, with no record, from the +// hive/adopt-<n> head branch. Nothing is fetched from GitHub. + +// Lineage kinds. +const ( + lineageAdopted = "adopted" + lineageSuperseded = "superseded" + lineageRebasedByHive = "rebased-by-hive" +) + +// Lineage reason slugs the SPA words its hover from. +const ( + lineageReasonCIRedOffline = "ci-red-contributor-offline" + lineageReasonCIRedUnregistered = "ci-red-contributor-unregistered" + lineageReasonOperatorAsked = "operator-asked" +) + +// StageTrackerLineage is the optional `lineage` field of a PR row: on the +// hive's copy, kind adopted / rebased-by-hive with the original in +// from_*; on the original, kind superseded with the copy in to_*. +type StageTrackerLineage struct { + Kind string `json:"kind"` + // FromNumber / FromURL / FromAuthor / FromAuthorKind name the original + // PR on the hive's copy (author kind human / clanker / hive, "" when + // unknown). + FromNumber int `json:"from_number,omitempty"` + FromURL string `json:"from_url,omitempty"` + FromAuthor string `json:"from_author,omitempty"` + FromAuthorKind string `json:"from_author_kind,omitempty"` + // ToNumber / ToURL name the hive's copy on the original. + ToNumber int `json:"to_number,omitempty"` + ToURL string `json:"to_url,omitempty"` + // At is when the hive adopted; Reason a short slug + // (ci-red-contributor-offline, operator-asked, dco-rehome, …). + At *time.Time `json:"at,omitempty"` + Reason string `json:"reason,omitempty"` +} + +// stageTrackerLineageReason folds the adoption record's AdoptReason into +// the lineage slug. An empty reason is the oldest path: CI red, nudged, +// contributor offline. +func stageTrackerLineageReason(adoptReason string) string { + switch adoptReason { + case "", automerge.AdoptReasonOffline, automerge.AdoptReasonGrace: + return lineageReasonCIRedOffline + case automerge.AdoptReasonUnregistered: + return lineageReasonCIRedUnregistered + case automerge.AdoptReasonOperator, automerge.AdoptReasonOperatorForced: + return lineageReasonOperatorAsked + } + return adoptReason +} + +// stageTrackerLineageAuthorKind guesses the original author's kind when +// the original is not a row any more: an adoption after a relay went +// offline means a registered relay existed (clanker); an unregistered +// author has no agent here (human). "" when the reason says nothing. +func stageTrackerLineageAuthorKind(adoptReason string) string { + switch adoptReason { + case "", automerge.AdoptReasonOffline, automerge.AdoptReasonGrace: + return authorKindClanker + case automerge.AdoptReasonUnregistered: + return authorKindHuman + } + return "" +} + +// stageTrackerLineageIndex maps store keys to lineage: the hive's copy +// (adopted / rebased-by-hive, from the original's AdoptedBy or +// SupersededBy) and the original (superseded). In-place adoptions name no +// second PR and get no lineage. When several originals name the same copy +// the lowest-numbered one wins. +func stageTrackerLineageIndex(store *stagelabels.Store, baseURL string) map[string]StageTrackerLineage { + out := map[string]StageTrackerLineage{} + if store == nil { + return out + } + for _, key := range store.Keys() { + rec, ok := store.Get(key) + if !ok { + continue + } + by := rec.SupersededBy + if by <= 0 { + if rec.AdoptMode == stagelabels.AdoptModeInPlace { + continue + } + by = rec.AdoptedBy + } + if by <= 0 { + continue + } + repo, numText, found := strings.Cut(key, "#") + number, err := strconv.Atoi(numText) + if !found || err != nil || number <= 0 || repo == "" { + continue + } + copyKey := stagelabels.Key(repo, by) + if prev, dup := out[copyKey]; dup && prev.FromNumber > 0 && prev.FromNumber <= number { + continue + } + kind := lineageAdopted + if rec.AdoptReason == automerge.AdoptReasonRebaseRehome { + kind = lineageRebasedByHive + } + var at *time.Time + for _, t := range []time.Time{rec.AdoptedAt, rec.SupersededAt} { + if !t.IsZero() { + tt := t + at = &tt + break + } + } + reason := stageTrackerLineageReason(rec.AdoptReason) + out[copyKey] = StageTrackerLineage{Kind: kind, FromNumber: number, FromURL: overviewItemURL("", repo, number, "pr", baseURL), + FromAuthor: rec.Author, FromAuthorKind: stageTrackerLineageAuthorKind(rec.AdoptReason), At: at, Reason: reason} + out[key] = StageTrackerLineage{Kind: lineageSuperseded, ToNumber: by, ToURL: overviewItemURL("", repo, by, "pr", baseURL), At: at, Reason: reason} + } + return out +} + +// stageTrackerLineageFromHead reads the original's number off a +// hive/adopt-<n> head branch, for a copy whose store record is gone. +func stageTrackerLineageFromHead(repo, headRef, baseURL string) *StageTrackerLineage { + rest, ok := strings.CutPrefix(headRef, "hive/adopt-") + if !ok { + return nil + } + n, err := strconv.Atoi(rest) + if err != nil || n <= 0 { + return nil + } + return &StageTrackerLineage{Kind: lineageAdopted, FromNumber: n, FromURL: overviewItemURL("", repo, n, "pr", baseURL), Reason: lineageReasonCIRedOffline} +} + +// stageTrackerLineageFor is the lineage of repo#number from the index, +// else from its head branch; nil when it has none. +func stageTrackerLineageFor(idx map[string]StageTrackerLineage, repo string, number int, headRef, baseURL string) *StageTrackerLineage { + if l, ok := idx[stagelabels.Key(repo, number)]; ok { + return &l + } + return stageTrackerLineageFromHead(repo, headRef, baseURL) +} + +// stageTrackerLineageFillAuthors completes from_author / from_author_kind +// on each copy whose original is itself a row (close_first off): the +// row's own author fields beat the record's guess. +func stageTrackerLineageFillAuthors(items []StageTrackerItem) { + prs := map[string]*StageTrackerItem{} + for i := range items { + if items[i].Kind == "pr" { + prs[stagelabels.Key(items[i].Repo, items[i].Number)] = &items[i] + } + } + for i := range items { + l := items[i].Lineage + if l == nil || l.FromNumber <= 0 { + continue + } + orig := prs[stagelabels.Key(items[i].Repo, l.FromNumber)] + if orig == nil { + continue + } + if orig.Author != "" { + l.FromAuthor = orig.Author + } + if orig.AuthorKind != "" { + l.FromAuthorKind = orig.AuthorKind + } + } +} diff --git a/src/pkg/dashboard/stage_tracker_lineage_test.go b/src/pkg/dashboard/stage_tracker_lineage_test.go new file mode 100644 index 0000000000..b8d6287ea6 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_lineage_test.go @@ -0,0 +1,127 @@ +package dashboard + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github/automerge" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// #15226 (@thatguywob, via a clanker relay) went red, the contributor +// stayed silent, the hive adopted it as #15308 and closed it. The copy's +// row must say so; the original (when rendered) must point at the copy. +func TestStageTrackerLineageIndex(t *testing.T) { + adoptedAt := time.Date(2026, 10, 29, 4, 56, 0, 0, time.UTC) + store := stagelabels.NewStore("", func() time.Time { return adoptedAt }) + orig := stagelabels.Key("hivecommons/hive", 15226) + store.Observe(orig, stagelabels.ReturnedToContributor, "contributor-lane:ci-red") + store.NoteAuthor(orig, "thatguywob") + store.MarkAdopted(orig, "0a1b2c3", 15308, adoptedAt) + store.MarkSupersededClosedFirst(orig, 15308, false, adoptedAt) + // An in-place adoption names no second PR: no lineage. + inPlace := stagelabels.Key("hivecommons/hive", 15400) + store.Observe(inPlace, stagelabels.AdoptedByHive, "contributor-lane:adopted") + store.MarkAdoptedInPlace(inPlace, "ffff000", automerge.AdoptReasonOffline, adoptedAt) + + idx := stageTrackerLineageIndex(store, "") + if len(idx) != 2 { + t.Fatalf("index = %+v", idx) + } + copyL, ok := idx[stagelabels.Key("hivecommons/hive", 15308)] + if !ok || copyL.Kind != lineageAdopted || copyL.FromNumber != 15226 || copyL.FromAuthor != "thatguywob" || copyL.FromAuthorKind != authorKindClanker || + copyL.Reason != lineageReasonCIRedOffline || copyL.At == nil || !copyL.At.Equal(adoptedAt) || copyL.FromURL != "https://github.com/hivecommons/hive/pull/15226" { + t.Fatalf("copy lineage = %+v", copyL) + } + origL, ok := idx[orig] + if !ok || origL.Kind != lineageSuperseded || origL.ToNumber != 15308 || origL.ToURL != "https://github.com/hivecommons/hive/pull/15308" || origL.FromNumber != 0 { + t.Fatalf("original lineage = %+v", origL) + } + if got := stageTrackerLineageIndex(nil, ""); len(got) != 0 { + t.Fatalf("nil store = %+v", got) + } +} + +func TestStageTrackerLineageReasonsAndHead(t *testing.T) { + for in, want := range map[string]string{ + "": lineageReasonCIRedOffline, automerge.AdoptReasonOffline: lineageReasonCIRedOffline, automerge.AdoptReasonGrace: lineageReasonCIRedOffline, + automerge.AdoptReasonUnregistered: lineageReasonCIRedUnregistered, automerge.AdoptReasonOperator: lineageReasonOperatorAsked, + automerge.AdoptReasonOperatorForced: lineageReasonOperatorAsked, automerge.AdoptReasonDCORehome: automerge.AdoptReasonDCORehome, + } { + if got := stageTrackerLineageReason(in); got != want { + t.Errorf("reason(%q) = %q, want %q", in, got, want) + } + } + // A copy whose record is gone still names its original off the branch. + l := stageTrackerLineageFor(map[string]StageTrackerLineage{}, "hivecommons/hive", 15308, "hive/adopt-15226", "") + if l == nil || l.Kind != lineageAdopted || l.FromNumber != 15226 || l.FromAuthor != "" { + t.Fatalf("head lineage = %+v", l) + } + if stageTrackerLineageFor(map[string]StageTrackerLineage{}, "hivecommons/hive", 1, "feat/x", "") != nil { + t.Fatal("plain branch must carry no lineage") + } + // With the original still a row, its author fields win over the guess. + items := []StageTrackerItem{ + {Kind: "pr", Repo: "hivecommons/hive", Number: 15308, Lineage: &StageTrackerLineage{Kind: lineageAdopted, FromNumber: 15226}}, + {Kind: "pr", Repo: "hivecommons/hive", Number: 15226, Author: "thatguywob", AuthorKind: authorKindHuman}, + } + stageTrackerLineageFillAuthors(items) + if got := items[0].Lineage; got.FromAuthor != "thatguywob" || got.FromAuthorKind != authorKindHuman { + t.Fatalf("filled = %+v", got) + } +} + +// The chip beside the PR number: "adopted from @thatguywob's #15226 · 6h", +// linked to the original, the author's kind as the icon only; the clause +// a caption or the Let-hive-decide preview adds after the PR number. +func TestStageTrackerLineageChipJS(t *testing.T) { + html := indexHTML(t) + for _, want := range []string{ + ".ham-lineage {", + "lineage: lp.lineage || null", + "stageTrackerLineageChipHtml(item, nowMs)", + "stageTrackerLineageChipHtml(lp, nowMs)", + "stageTrackerLineageChipHtml(pr, nowMs) : '') ||", + "stageTrackerRefOf(item) + (typeof stageTrackerLineageClause === 'function' ? stageTrackerLineageClause(item) : '')", + } { + if !strings.Contains(html, want) { + t.Errorf("index.html lacks %q", want) + } + } + script := strings.Join([]string{ + "const assert = require('assert');", + jsFunc(t, html, "esc"), + jsFunc(t, html, "stageTrackerAgoText"), + jsConstBlock(t, html, "STAGE_TRACKER_LINEAGE_REASON_TIP"), + jsFunc(t, html, "stageTrackerLineageText"), + jsFunc(t, html, "stageTrackerLineageTip"), + jsFunc(t, html, "stageTrackerLineageChipHtml"), + jsFunc(t, html, "stageTrackerLineageClause"), + "function stageTrackerIcon(key, cls) { return '<svg class=\"' + cls + '\"></svg>'; }", + ` +const nowMs = Date.parse('2026-10-29T10:56:00Z'); +const lineage = { kind: 'adopted', from_number: 15226, from_url: 'https://github.com/hivecommons/hive/pull/15226', from_author: 'thatguywob', from_author_kind: 'clanker', at: '2026-10-29T04:56:00Z', reason: 'ci-red-contributor-offline' }; +const copy = { kind: 'pr', repo: 'hivecommons/hive', number: 15308, author_kind: 'hive', lineage }; +assert.strictEqual(stageTrackerLineageText(copy, nowMs), "adopted from @thatguywob's #15226 · 6h"); +assert.ok(stageTrackerLineageText(copy, nowMs).split(/\s+/).length <= 12); +const chip = stageTrackerLineageChipHtml(copy, nowMs); +assert.ok(chip.includes('href="https://github.com/hivecommons/hive/pull/15226"'), chip); +assert.ok(chip.includes('ham-lineage'), chip); +assert.ok(chip.includes('ham-author-clanker'), chip); +assert.ok(!/>[^<]*clanker[^<]*</.test(chip), 'author kind must be an icon, not a word: ' + chip); +assert.ok(chip.includes("title=\"Hive took this PR over after CI went red and @thatguywob's agent didn't respond. Original commits kept.\"") || chip.includes("title=\"Hive took this PR over after CI went red and @thatguywob's agent didn't respond. Original commits kept.\""), chip); +assert.strictEqual(stageTrackerLineageClause(copy), ' (adopted from #15226)'); +assert.strictEqual(stageTrackerLineageClause({ kind: 'issue', number: 15198, linked_prs: [{ number: 15308, lineage }] }), ' (adopted from #15226)'); +assert.strictEqual(stageTrackerLineageClause({ kind: 'pr', number: 1 }), ''); +assert.strictEqual(stageTrackerLineageChipHtml({ kind: 'pr', number: 1 }, nowMs), ''); +const orig = { kind: 'pr', number: 15226, lineage: { kind: 'superseded', to_number: 15308, to_url: 'https://github.com/hivecommons/hive/pull/15308', at: '2026-10-29T04:56:00Z' } }; +assert.strictEqual(stageTrackerLineageText(orig, nowMs), 'superseded by #15308 · 6h'); +assert.ok(stageTrackerLineageChipHtml(orig, nowMs).includes('href="https://github.com/hivecommons/hive/pull/15308"')); +assert.strictEqual(stageTrackerLineageClause(orig), ''); +assert.strictEqual(stageTrackerLineageText({ lineage: { kind: 'adopted', from_number: 7 } }, nowMs), 'adopted from #7'); +assert.ok(stageTrackerLineageTip({ lineage: { kind: 'adopted', from_number: 7, reason: 'operator-asked' } }).includes("maintainer's request")); +`, + }, "\n") + runStageTrackerRowActionsScript(t, script) +} diff --git a/src/pkg/dashboard/static-src/css/tracker.css b/src/pkg/dashboard/static-src/css/tracker.css index 6ca7264716..a6238af026 100644 --- a/src/pkg/dashboard/static-src/css/tracker.css +++ b/src/pkg/dashboard/static-src/css/tracker.css @@ -375,6 +375,10 @@ .ham-plan-finding { color: var(--status-error); } .ham-plan-ruled-out { padding-left: 1.4em; } .ham-plan-rails { font-size: var(--fs-xs); color: var(--text-faint); } + .ham-lineage { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; gap: var(--sp-1); } + .ham-lineage:hover { color: var(--text); } + .ham-plan-body, .ham-plan-note { white-space: pre-wrap; } + .ham-plan-note { color: var(--muted); font-size: var(--fs-xs); } .ham-seg.active .cue-acting-cap { margin-left: var(--sp-2); } .cue-acting-cap { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; } .cue-acting-spin { width: 10px; height: 10px; margin-right: 0; } diff --git a/src/pkg/dashboard/static-src/js/tracker-actions.js b/src/pkg/dashboard/static-src/js/tracker-actions.js index 2658cd2f7a..38b0049da7 100644 --- a/src/pkg/dashboard/static-src/js/tracker-actions.js +++ b/src/pkg/dashboard/static-src/js/tracker-actions.js @@ -1315,7 +1315,7 @@ const r = await fetch(req.url + '/plan', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(req.body) }); const data = await r.json().catch(() => ({})); if (!r.ok) return { ref: stageTrackerRefOf(item), number: item.number, error: data.error || ('HTTP ' + r.status) }; - return Object.assign({ ref: stageTrackerRefOf(item) }, data); + return Object.assign({ ref: stageTrackerRefOf(item) + (typeof stageTrackerLineageClause === 'function' ? stageTrackerLineageClause(item) : '') }, data); } catch (e) { return { ref: stageTrackerRefOf(item), number: item.number, error: String(e && e.message || e) }; } } // The preview: resolves { chosen } for Let hive do that, { chosen, diff --git a/src/pkg/dashboard/static-src/js/tracker-row.js b/src/pkg/dashboard/static-src/js/tracker-row.js index 13332357a7..d96ec91d09 100644 --- a/src/pkg/dashboard/static-src/js/tracker-row.js +++ b/src/pkg/dashboard/static-src/js/tracker-row.js @@ -412,7 +412,7 @@ if (item.author || ak) lines.push('Author: ' + (item.author ? '@' + item.author : '') + (ak ? ' (author/' + ak + (item.author_kind_source === 'inferred' ? ', inferred' : '') + ')' : '') + (item.tier ? ' · ' + item.tier : '')); if (item.origin) lines.push('Origin: origin/' + item.origin); if (item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length) lines.push('Covering PR: ' + item.linked_prs.map(lp => Number(lp.number) || 0).sort((x, y) => x - y).map(n => '#' + n).join(', ')); - else if (item.kind === 'issue' && item.linked_pr) lines.push('Covering PR: #' + item.linked_pr); + else if (item.kind === 'issue' && item.linked_pr) lines.push('Covering PR: #' + item.linked_pr + (typeof stageTrackerLineageClause === 'function' ? stageTrackerLineageClause(item) : '')); const actorLine = stageTrackerActorTip(item); if (actorLine) lines.push(actorLine.replace(/^ · /, '')); if (typeof stageTrackerNewLines === 'function') lines.push(...stageTrackerNewLines(item, nowMs)); @@ -823,7 +823,7 @@ human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', base_ref: lp.base_ref || '', decision_needed: lp.decision_needed || null, adoption: lp.adoption || null, takeover: lp.takeover || null, superseded: !!lp.superseded, supersedes: lp.supersedes || null, parent: Number(issue.number) || 0, siblings: open.map(x => Number(x.number) || 0), last_operator_action: lp.last_operator_action || null, operator_action_count: lp.operator_action_count || 0, hold: lp.hold || null, stage_actor: lp.stage_actor || null, presence: lp.presence || null, rework: lp.rework || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, - decided: lp.decided || null, adopted_by: Number(lp.adopted_by) || 0, adopted_by_state: lp.adopted_by_state || '', adopted_from: lp.adopted_from || null, state: lp.state || '', superseded_by: Number(lp.superseded_by) || 0 }; + decided: lp.decided || null, adopted_by: Number(lp.adopted_by) || 0, adopted_by_state: lp.adopted_by_state || '', adopted_from: lp.adopted_from || null, lineage: lp.lineage || null, state: lp.state || '', superseded_by: Number(lp.superseded_by) || 0 }; } // Pure: whether a linked PR is still open (not merged / closed / superseded). function stageTrackerLinkedPROpen(lp) { @@ -834,6 +834,63 @@ if (!issue || issue.kind === 'pr') return []; return (Array.isArray(issue.linked_prs) ? issue.linked_prs : []).filter(stageTrackerLinkedPROpen).map(lp => stageTrackerLinkedPRItem(issue, lp)); } + // Lineage: where an adopted PR came from (`lineage`: {kind, from_number, + // from_url, from_author, from_author_kind, to_number, to_url, at, + // reason}; optional, nothing without it). #15198 showed the hive's copy + // #15308 "Fixing" with no trace of @thatguywob's #15226 it was adopted + // from, so sending the fix to a hive agent read as a mistake. The chip + // sits beside the PR number on every PR mention (top-level row, single + // covering PR, sub-row) and links to the other PR; the author's kind is + // the icon only, never a word. + const STAGE_TRACKER_LINEAGE_REASON_TIP = { + 'ci-red-contributor-offline': "Hive took this PR over after CI went red and @AUTHOR's agent didn't respond. Original commits kept.", + 'ci-red-contributor-unregistered': "Hive took this PR over after CI went red and @AUTHOR has no agent registered here. Original commits kept.", + 'operator-asked': 'Hive took this PR over at a maintainer\'s request. Original commits kept.', + 'dco-rehome': 'Hive re-homed this PR to repair its DCO sign-off. Original commits kept.', + 'signoff-rehome': 'Hive re-homed this PR so its sign-off survives a squash. Original commits kept.', + 'rebase-rehome': 'Hive re-homed this PR onto its own branch to finish the rebase. Original commits kept.', + 'push-rehome': "Hive re-homed this PR because @AUTHOR's branch could no longer be pushed. Original commits kept.", + 'in-place-stalled': 'Hive re-homed this PR after a review finding sat unaddressed. Original commits kept.' + }; + // Pure: the chip's visible words — "adopted from @thatguywob's #15226 · 6h". + function stageTrackerLineageText(item, nowMs) { + const l = item && item.lineage; + if (!l || !l.kind) return ''; + const ago = stageTrackerAgoText(Date.parse(l.at || ''), nowMs).replace(/ ago$/, ''); + const tail = ago ? ' · ' + ago : ''; + if (l.kind === 'superseded') return Number(l.to_number) > 0 ? 'superseded by #' + Number(l.to_number) + tail : ''; + if (!(Number(l.from_number) > 0)) return ''; + const whose = l.from_author ? '@' + l.from_author + "'s " : ''; + return (l.kind === 'rebased-by-hive' ? 'rebased by hive from ' : 'adopted from ') + whose + '#' + Number(l.from_number) + tail; + } + // Pure: the hover — why the hive took it over, in plain words. + function stageTrackerLineageTip(item) { + const l = item && item.lineage; + if (!l || !l.kind) return ''; + if (l.kind === 'superseded') return 'Hive took this PR over as #' + Number(l.to_number) + '; this original is closed when that merges.'; + const who = l.from_author ? '@' + l.from_author : 'the contributor'; + const tip = STAGE_TRACKER_LINEAGE_REASON_TIP[l.reason] || STAGE_TRACKER_LINEAGE_REASON_TIP['ci-red-contributor-offline']; + return tip.split('@AUTHOR').join(who); + } + function stageTrackerLineageChipHtml(item, nowMs) { + const text = stageTrackerLineageText(item, nowMs); + if (!text) return ''; + const l = item.lineage; + const tip = stageTrackerLineageTip(item); + const icon = l.kind !== 'superseded' && l.from_author_kind ? stageTrackerIcon(l.from_author_kind, 'ham-author-ico ham-author-' + esc(l.from_author_kind), l.from_author_kind) : ''; + const href = l.kind === 'superseded' ? l.to_url : l.from_url; + const attrs = `class="ham-badge ham-lineage" title="${esc(tip)}" aria-label="${esc(text + ' — ' + tip)}"`; + return href ? `<a ${attrs} href="${esc(href)}" target="_blank" rel="noopener">${icon}${esc(text)}</a>` : `<span ${attrs}>${icon}${esc(text)}</span>`; + } + // Pure: the one clause a caption or preview adds after the PR number — + // " (adopted from #15226)"; '' without lineage. An issue row reads its + // single covering PR's lineage. + function stageTrackerLineageClause(item) { + let l = item && item.lineage; + if (!l && item && item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length === 1) l = item.linked_prs[0].lineage; + if (!l || !(Number(l.from_number) > 0) || l.kind === 'superseded') return ''; + return ' (adopted from #' + Number(l.from_number) + ')'; + } // Pure: the "↳ adopted from #N · you let hive decide 17:51" chip on the // hive's copy of an adopted PR (hivecommons/hive#15126). function stageTrackerAdoptedFromChipHtml(pr, nowMs) { @@ -867,7 +924,7 @@ return `<div class="ham-sub${typeof stageTrackerCueClasses === 'function' ? stageTrackerCueClasses(pr, ctx) : ''}" data-ham-kind="pr" data-ham-stage="${pr.stage}" data-ham-sub-key="${esc(stageTrackerItemKey(pr))}"> ${typeof stageTrackerRowToolsHtml === 'function' ? stageTrackerRowToolsHtml(pr) : ''} <div class="ham-row-head"> - ${stageTrackerHeadColsHtml([ref], '', stageTrackerActedBadgeHtml(pr, nowMs) + (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(pr, nowMs) : '') + stageTrackerChipsHtml(pr))} + ${stageTrackerHeadColsHtml([ref], '', stageTrackerActedBadgeHtml(pr, nowMs) + ((typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(pr, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(pr, nowMs) : '')) + stageTrackerChipsHtml(pr))} </div> <div class="ham-strip-row"> <ol class="ham-strip" aria-label="Pipeline progress"${stageTrackerMoveAttrs(stageTrackerItemKey(pr), ctx)}>${stageTrackerStripItems(pr, stages, { from: STAGE_TRACKER_PR_COLUMN }, nowMs, ctx)}</ol> @@ -1076,7 +1133,7 @@ // One covering PR: a single entry whose strip the PR's stage drives. const lp = linked[0]; const who = (lp.author_kind || 'hive') + (lp.author ? ' · @' + lp.author : ''); - prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)) + (lp.base_ref ? ` <span class="ham-badge">${esc(lp.base_ref)}</span>` : '')]; + prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)) + (lp.base_ref ? ` <span class="ham-badge">${esc(lp.base_ref)}</span>` : '') + (lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? ' ' + stageTrackerLineageChipHtml(lp, nowMs) : '')]; shown = Object.assign({}, item, { via_pr: true, stage: lp.stage || 40, stage_since: lp.stage_since || item.stage_since, modifiers: lp.modifiers || item.modifiers, deferred_modifiers: lp.deferred_modifiers || item.deferred_modifiers || [], caption: lp.caption || item.caption, reason: lp.reason || item.reason, human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', decision_needed: lp.decision_needed || null, hold: lp.hold || null, adoption: lp.adoption || null, stage_actor: lp.stage_actor || item.stage_actor || null, presence: lp.presence || null, rework: lp.rework || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, decided: lp.decided || item.decided || null }); } else if (linked.length) { @@ -1113,7 +1170,7 @@ </div>`; } else { const li = stageTrackerPRIssueSlot(item); - prRefs = [stageTrackerPRRef(item.number, item.url, item.author_kind || '', item.author, title, (title ? title + ' · ' : '') + stageTrackerTooltip(shown, nowMs))]; + prRefs = [stageTrackerPRRef(item.number, item.url, item.author_kind || '', item.author, title, (title ? title + ' · ' : '') + stageTrackerTooltip(shown, nowMs)) + (item.lineage && typeof stageTrackerLineageChipHtml === 'function' ? ' ' + stageTrackerLineageChipHtml(item, nowMs) : '')]; leadHtml = li.number ? `<div class="ham-head-main${li.closed ? ' ham-issue-closed' : ''}"> ${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 4242f1fbed..f4372e0130 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1698,6 +1698,10 @@ .ham-plan-finding { color: var(--status-error); } .ham-plan-ruled-out { padding-left: 1.4em; } .ham-plan-rails { font-size: var(--fs-xs); color: var(--text-faint); } + .ham-lineage { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; gap: var(--sp-1); } + .ham-lineage:hover { color: var(--text); } + .ham-plan-body, .ham-plan-note { white-space: pre-wrap; } + .ham-plan-note { color: var(--muted); font-size: var(--fs-xs); } .ham-seg.active .cue-acting-cap { margin-left: var(--sp-2); } .cue-acting-cap { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; } .cue-acting-spin { width: 10px; height: 10px; margin-right: 0; } @@ -15642,7 +15646,7 @@ <h3 class="faq-group-title">Where to get help</h3> if (item.author || ak) lines.push('Author: ' + (item.author ? '@' + item.author : '') + (ak ? ' (author/' + ak + (item.author_kind_source === 'inferred' ? ', inferred' : '') + ')' : '') + (item.tier ? ' · ' + item.tier : '')); if (item.origin) lines.push('Origin: origin/' + item.origin); if (item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length) lines.push('Covering PR: ' + item.linked_prs.map(lp => Number(lp.number) || 0).sort((x, y) => x - y).map(n => '#' + n).join(', ')); - else if (item.kind === 'issue' && item.linked_pr) lines.push('Covering PR: #' + item.linked_pr); + else if (item.kind === 'issue' && item.linked_pr) lines.push('Covering PR: #' + item.linked_pr + (typeof stageTrackerLineageClause === 'function' ? stageTrackerLineageClause(item) : '')); const actorLine = stageTrackerActorTip(item); if (actorLine) lines.push(actorLine.replace(/^ · /, '')); if (typeof stageTrackerNewLines === 'function') lines.push(...stageTrackerNewLines(item, nowMs)); @@ -16053,7 +16057,7 @@ <h3 class="faq-group-title">Where to get help</h3> human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', base_ref: lp.base_ref || '', decision_needed: lp.decision_needed || null, adoption: lp.adoption || null, takeover: lp.takeover || null, superseded: !!lp.superseded, supersedes: lp.supersedes || null, parent: Number(issue.number) || 0, siblings: open.map(x => Number(x.number) || 0), last_operator_action: lp.last_operator_action || null, operator_action_count: lp.operator_action_count || 0, hold: lp.hold || null, stage_actor: lp.stage_actor || null, presence: lp.presence || null, rework: lp.rework || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, - decided: lp.decided || null, adopted_by: Number(lp.adopted_by) || 0, adopted_by_state: lp.adopted_by_state || '', adopted_from: lp.adopted_from || null, state: lp.state || '', superseded_by: Number(lp.superseded_by) || 0 }; + decided: lp.decided || null, adopted_by: Number(lp.adopted_by) || 0, adopted_by_state: lp.adopted_by_state || '', adopted_from: lp.adopted_from || null, lineage: lp.lineage || null, state: lp.state || '', superseded_by: Number(lp.superseded_by) || 0 }; } // Pure: whether a linked PR is still open (not merged / closed / superseded). function stageTrackerLinkedPROpen(lp) { @@ -16064,6 +16068,63 @@ <h3 class="faq-group-title">Where to get help</h3> if (!issue || issue.kind === 'pr') return []; return (Array.isArray(issue.linked_prs) ? issue.linked_prs : []).filter(stageTrackerLinkedPROpen).map(lp => stageTrackerLinkedPRItem(issue, lp)); } + // Lineage: where an adopted PR came from (`lineage`: {kind, from_number, + // from_url, from_author, from_author_kind, to_number, to_url, at, + // reason}; optional, nothing without it). #15198 showed the hive's copy + // #15308 "Fixing" with no trace of @thatguywob's #15226 it was adopted + // from, so sending the fix to a hive agent read as a mistake. The chip + // sits beside the PR number on every PR mention (top-level row, single + // covering PR, sub-row) and links to the other PR; the author's kind is + // the icon only, never a word. + const STAGE_TRACKER_LINEAGE_REASON_TIP = { + 'ci-red-contributor-offline': "Hive took this PR over after CI went red and @AUTHOR's agent didn't respond. Original commits kept.", + 'ci-red-contributor-unregistered': "Hive took this PR over after CI went red and @AUTHOR has no agent registered here. Original commits kept.", + 'operator-asked': 'Hive took this PR over at a maintainer\'s request. Original commits kept.', + 'dco-rehome': 'Hive re-homed this PR to repair its DCO sign-off. Original commits kept.', + 'signoff-rehome': 'Hive re-homed this PR so its sign-off survives a squash. Original commits kept.', + 'rebase-rehome': 'Hive re-homed this PR onto its own branch to finish the rebase. Original commits kept.', + 'push-rehome': "Hive re-homed this PR because @AUTHOR's branch could no longer be pushed. Original commits kept.", + 'in-place-stalled': 'Hive re-homed this PR after a review finding sat unaddressed. Original commits kept.' + }; + // Pure: the chip's visible words — "adopted from @thatguywob's #15226 · 6h". + function stageTrackerLineageText(item, nowMs) { + const l = item && item.lineage; + if (!l || !l.kind) return ''; + const ago = stageTrackerAgoText(Date.parse(l.at || ''), nowMs).replace(/ ago$/, ''); + const tail = ago ? ' · ' + ago : ''; + if (l.kind === 'superseded') return Number(l.to_number) > 0 ? 'superseded by #' + Number(l.to_number) + tail : ''; + if (!(Number(l.from_number) > 0)) return ''; + const whose = l.from_author ? '@' + l.from_author + "'s " : ''; + return (l.kind === 'rebased-by-hive' ? 'rebased by hive from ' : 'adopted from ') + whose + '#' + Number(l.from_number) + tail; + } + // Pure: the hover — why the hive took it over, in plain words. + function stageTrackerLineageTip(item) { + const l = item && item.lineage; + if (!l || !l.kind) return ''; + if (l.kind === 'superseded') return 'Hive took this PR over as #' + Number(l.to_number) + '; this original is closed when that merges.'; + const who = l.from_author ? '@' + l.from_author : 'the contributor'; + const tip = STAGE_TRACKER_LINEAGE_REASON_TIP[l.reason] || STAGE_TRACKER_LINEAGE_REASON_TIP['ci-red-contributor-offline']; + return tip.split('@AUTHOR').join(who); + } + function stageTrackerLineageChipHtml(item, nowMs) { + const text = stageTrackerLineageText(item, nowMs); + if (!text) return ''; + const l = item.lineage; + const tip = stageTrackerLineageTip(item); + const icon = l.kind !== 'superseded' && l.from_author_kind ? stageTrackerIcon(l.from_author_kind, 'ham-author-ico ham-author-' + esc(l.from_author_kind), l.from_author_kind) : ''; + const href = l.kind === 'superseded' ? l.to_url : l.from_url; + const attrs = `class="ham-badge ham-lineage" title="${esc(tip)}" aria-label="${esc(text + ' — ' + tip)}"`; + return href ? `<a ${attrs} href="${esc(href)}" target="_blank" rel="noopener">${icon}${esc(text)}</a>` : `<span ${attrs}>${icon}${esc(text)}</span>`; + } + // Pure: the one clause a caption or preview adds after the PR number — + // " (adopted from #15226)"; '' without lineage. An issue row reads its + // single covering PR's lineage. + function stageTrackerLineageClause(item) { + let l = item && item.lineage; + if (!l && item && item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length === 1) l = item.linked_prs[0].lineage; + if (!l || !(Number(l.from_number) > 0) || l.kind === 'superseded') return ''; + return ' (adopted from #' + Number(l.from_number) + ')'; + } // Pure: the "↳ adopted from #N · you let hive decide 17:51" chip on the // hive's copy of an adopted PR (hivecommons/hive#15126). function stageTrackerAdoptedFromChipHtml(pr, nowMs) { @@ -16097,7 +16158,7 @@ <h3 class="faq-group-title">Where to get help</h3> return `<div class="ham-sub${typeof stageTrackerCueClasses === 'function' ? stageTrackerCueClasses(pr, ctx) : ''}" data-ham-kind="pr" data-ham-stage="${pr.stage}" data-ham-sub-key="${esc(stageTrackerItemKey(pr))}"> ${typeof stageTrackerRowToolsHtml === 'function' ? stageTrackerRowToolsHtml(pr) : ''} <div class="ham-row-head"> - ${stageTrackerHeadColsHtml([ref], '', stageTrackerActedBadgeHtml(pr, nowMs) + (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(pr, nowMs) : '') + stageTrackerChipsHtml(pr))} + ${stageTrackerHeadColsHtml([ref], '', stageTrackerActedBadgeHtml(pr, nowMs) + ((typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(pr, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(pr, nowMs) : '')) + stageTrackerChipsHtml(pr))} </div> <div class="ham-strip-row"> <ol class="ham-strip" aria-label="Pipeline progress"${stageTrackerMoveAttrs(stageTrackerItemKey(pr), ctx)}>${stageTrackerStripItems(pr, stages, { from: STAGE_TRACKER_PR_COLUMN }, nowMs, ctx)}</ol> @@ -16306,7 +16367,7 @@ <h3 class="faq-group-title">Where to get help</h3> // One covering PR: a single entry whose strip the PR's stage drives. const lp = linked[0]; const who = (lp.author_kind || 'hive') + (lp.author ? ' · @' + lp.author : ''); - prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)) + (lp.base_ref ? ` <span class="ham-badge">${esc(lp.base_ref)}</span>` : '')]; + prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)) + (lp.base_ref ? ` <span class="ham-badge">${esc(lp.base_ref)}</span>` : '') + (lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? ' ' + stageTrackerLineageChipHtml(lp, nowMs) : '')]; shown = Object.assign({}, item, { via_pr: true, stage: lp.stage || 40, stage_since: lp.stage_since || item.stage_since, modifiers: lp.modifiers || item.modifiers, deferred_modifiers: lp.deferred_modifiers || item.deferred_modifiers || [], caption: lp.caption || item.caption, reason: lp.reason || item.reason, human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', decision_needed: lp.decision_needed || null, hold: lp.hold || null, adoption: lp.adoption || null, stage_actor: lp.stage_actor || item.stage_actor || null, presence: lp.presence || null, rework: lp.rework || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, decided: lp.decided || item.decided || null }); } else if (linked.length) { @@ -16343,7 +16404,7 @@ <h3 class="faq-group-title">Where to get help</h3> </div>`; } else { const li = stageTrackerPRIssueSlot(item); - prRefs = [stageTrackerPRRef(item.number, item.url, item.author_kind || '', item.author, title, (title ? title + ' · ' : '') + stageTrackerTooltip(shown, nowMs))]; + prRefs = [stageTrackerPRRef(item.number, item.url, item.author_kind || '', item.author, title, (title ? title + ' · ' : '') + stageTrackerTooltip(shown, nowMs)) + (item.lineage && typeof stageTrackerLineageChipHtml === 'function' ? ' ' + stageTrackerLineageChipHtml(item, nowMs) : '')]; leadHtml = li.number ? `<div class="ham-head-main${li.closed ? ' ham-issue-closed' : ''}"> ${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} @@ -19150,7 +19211,7 @@ <h2 class="config-title" id="activity-monitor-labels-title">All labels</h2> const r = await fetch(req.url + '/plan', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(req.body) }); const data = await r.json().catch(() => ({})); if (!r.ok) return { ref: stageTrackerRefOf(item), number: item.number, error: data.error || ('HTTP ' + r.status) }; - return Object.assign({ ref: stageTrackerRefOf(item) }, data); + return Object.assign({ ref: stageTrackerRefOf(item) + (typeof stageTrackerLineageClause === 'function' ? stageTrackerLineageClause(item) : '') }, data); } catch (e) { return { ref: stageTrackerRefOf(item), number: item.number, error: String(e && e.message || e) }; } } // The preview: resolves { chosen } for Let hive do that, { chosen,