From 375ffa15ce3cca3350191f9e4b7471792b38732a Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Wed, 28 Oct 2026 12:25:10 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Activity=20Monitor:=20needs-hum?= =?UTF-8?q?an=20popover=20says=20what=20to=20decide=20and=20offers=20the?= =?UTF-8?q?=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hovering or focusing the 'Needs human decision' chevron word or a lead needs-human / triage-needed pill opens an in-app popover: what the row waits on (the reviewer's own question when the verdict record has one, else the park reason in plain words, plus the blocker), the applicable actions as buttons (Let hive decide first) down the row context menu's code path, and who asked, when. GET /api/stage-tracker rows carry decision_needed {question, asked_by, since, blocker, blocker_reason, options[]} under the context menu's action ids; mirrored onto linked_prs[]. Requested by @clubanderson. Fixes #14994 Signed-off-by: Andrew Anderson --- .../added-needs-human-decision-popover.md | 1 + src/docs/api-reference.md | 2 +- src/docs/dashboard-sections.md | 4 + src/pkg/dashboard/stage_tracker.go | 26 ++ src/pkg/dashboard/stage_tracker_decision.go | 412 ++++++++++++++++++ .../stage_tracker_decision_popover_test.go | 144 ++++++ .../dashboard/stage_tracker_decision_test.go | 249 +++++++++++ src/pkg/dashboard/static/index.html | 240 +++++++++- 8 files changed, 1071 insertions(+), 7 deletions(-) create mode 100644 changelog.d/added-needs-human-decision-popover.md create mode 100644 src/pkg/dashboard/stage_tracker_decision.go create mode 100644 src/pkg/dashboard/stage_tracker_decision_popover_test.go create mode 100644 src/pkg/dashboard/stage_tracker_decision_test.go diff --git a/changelog.d/added-needs-human-decision-popover.md b/changelog.d/added-needs-human-decision-popover.md new file mode 100644 index 0000000000..4af91449c2 --- /dev/null +++ b/changelog.d/added-needs-human-decision-popover.md @@ -0,0 +1 @@ +- Activity Monitor: hovering or focusing the *Needs human decision* chevron word or a lead *needs-human* / *triage needed* pill opens an in-app popover that says what the row is waiting on (the reviewer's own question when the hive has one, else the park reason in plain words, plus the blocker — "A reviewer requested changes on b0f5f80 — needs a new commit. Approving cannot override that."), offers the applicable actions as buttons (*Let hive decide* first, then Approve / Give direction / Close as superseded / Close as won't fix / Hold or Release; disabled ones grey with their reason) down the row context menu's code path, and names who asked and when; `GET /api/stage-tracker` rows carry the new `decision_needed` (`question`, `asked_by`, `since`, `blocker`, `blocker_reason`, `options[]`). Requested by @clubanderson ([#14994](https://github.com/hivecommons/hive/issues/14994)). diff --git a/src/docs/api-reference.md b/src/docs/api-reference.md index 7db055579d..8015fe2abd 100644 --- a/src/docs/api-reference.md +++ b/src/docs/api-reference.md @@ -570,7 +570,7 @@ always resolved server-side from the validated token. | `GET` | `/api/budget-ignore` | Dashboard auth/session | Budget Ignore Get | `pkg/dashboard/api.go:171` | | `POST` | `/api/budget-ignore` | Owner only | Budget Ignore Set | `pkg/dashboard/api.go:172` | | `GET` | `/api/summaries` | Dashboard auth/session | Summaries | `pkg/dashboard/api.go:184` | -| `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, 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: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:185` | | `POST` | `/api/prs/{owner}/{repo}/{number}/queue-automerge` | Merger/owner role | Queue PRAuto Merge | `pkg/dashboard/api.go:186` | | `GET` | `/api/inference/models/{backend}` | Dashboard auth/session | Inference Models | `pkg/dashboard/api.go:356` | | `GET` | `/api/hive-id` | Dashboard auth/session | Hive IDGet | `pkg/dashboard/api.go:418` | diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 7ae4480db8..9c803064e2 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -687,6 +687,10 @@ Fed by `GET /api/stage-tracker`. Every issue and pull request follows the same p **Multi-select.** The checkbox in a row's left gutter selects the row; **Shift+click** selects the range from the last clicked row, **Cmd/Ctrl+click** toggles, **Cmd/Ctrl+Shift+click** adds a range to what is selected; with a row focused, **Space** toggles it (Shift+Space extends). Cmd/Ctrl- or Shift-clicking the row itself, away from its links, selects it too. A selection bar appears above the list with the count, **Clear**, and the same actions for the whole selection — *Decide…* (opens the group as a menu, *Let hive decide* first — each selected row gets its own delegated-decision job, see below), *Hold*, *Release hold*, *Re-evaluate now*, *Mark needs-human…*, *Copy links* — each enabled only when it is valid for every selected row and otherwise greyed with the first reason ("Not applicable to acme/console#12", "Sign in with write access…"). Right-clicking a selected row acts on the whole selection. Bulk actions run one request per row, in list order, under a progress toast ("Hold 2/5 — acme/console#12…"); the result toast lists each failure by row and the successes stand, after which the list and the status snapshot refresh (a hive-wide rescan is sent once per batch). Selection is keyed on the row's item (repository, kind, number), not its node, so the live re-render keeps it; a row that leaves the list — merged, closed, filtered or paged out — leaves the selection. +**Needs-human decision popover.** Hovering — or, by keyboard, focusing — the *Needs human decision* chevron word on a row (an issue at 045, a PR at 085, an issue whose nested PR is parked there) or a lead *needs-human* / *triage needed* pill opens an in-app popover (no native tooltip on that element) that says, in this order: **what the row is waiting on** — the reviewer's own question when the hive has one (the text the hive's "Needs a decision" comment on the PR prints after *reviewer question:*, read from the same verdict record), else a plain-words sentence for the park reason, plus the blocker in plain words ("A reviewer requested changes on b0f5f80 — needs a new commit. Approving cannot override that."); **what you can do** — one button per applicable action, *Let hive decide* first, then Approve / Give direction / Close as superseded / Close as won't fix / Hold or Release hold (an issue at 015: Accept triage, Hold, Mark needs-human), each disabled with its reason when the row's state or your role rules it out; **who asked and when** ("Asked by a reviewer · 2 hours ago"); then the chevron's stage line. The buttons run the row context menu's code path, so the same result toast and in-flight chevron apply. The popover stays open while the pointer is over it or its trigger, pins on click or focus, and closes on Esc (focus returns to the trigger), click-away, scroll or resize. The text comes from the tracker payload's `decision_needed` (`question`, `asked_by`, `since`, `blocker`, `blocker_reason`, `options[] {action, label, enabled, reason_if_disabled}`), whose `action` ids are the context menu's own (`decide:delegate`, `decide:approve`, …). + +**Cue tokens.** The three cues of the legend above (state pill, working spin, decision badge) share one `tracker-cues` CSS block on `.ham-row`: `--cue-state` (what the row waits on — the pill and this popover), `--cue-work` (the hive is working right now — the chevron spin), `--cue-decision` (what people and the hive decided — the ✓ badge). Nothing else blinks; motion stays in the 150–300 ms range. + ### Let hive decide **What it is.** *Let hive decide* is the first entry under *Decide…* on a row parked at *Needs human decision* (an issue at 045, a PR at 085, or an issue whose nested PR is parked there), and under *Decide…* in the selection bar for a bulk run. It asks the hive to make the decision itself, as the owner's delegate, under the owner's standing operating rules — and to record it exactly as a human decision is recorded: a `/hive decision ` comment on the item (plus the queue approval on a PR head when the decision is to release the PR), the parking labels lifted, `triage/accepted` added where it applies, and the stage engine's un-park logged with the requesting operator named. The item leaves 085/045 and proceeds without the owner. The action is audited as `repo_item_decision_delegated` (or `repo_item_decision_delegated_failed`) and the **Decisions log** shows those rows with a *delegated* badge so delegated and human decisions can be told apart and counted. diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 2b3007c6e4..61a06eed59 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -19,6 +19,7 @@ import ( "github.com/hivecommons/hive/pkg/dashboard/collect" "github.com/hivecommons/hive/pkg/dashboard/webstatic" "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/review" "github.com/hivecommons/hive/pkg/stageengine" stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" @@ -330,6 +331,12 @@ type StageTrackerItem struct { // (hivecommons/hive#14589). UnauthorizedStep string `json:"unauthorized_step,omitempty"` Unauthorized string `json:"unauthorized,omitempty"` + // DecisionNeeded is set on a row parked on a person (085 / 045 / 015, + // the needs-human or needs-decision pill): what the person must + // decide, who asked, the plain-words blocker and the actions that + // advance it, under the row context menu's action ids. See + // stage_tracker_decision.go. + DecisionNeeded *StageTrackerDecision `json:"decision_needed,omitempty"` // StaleLabels are control labels the row still wears that its stage // has outrun, so they are not read as modifiers: `needs-triage` on an // issue at 020 or later (015 is not a gate; the reconciler removes the @@ -432,6 +439,9 @@ type StageTrackerLinkedPR struct { HumanMergeReason string `json:"human_merge_reason,omitempty"` HumanMergeReasonText string `json:"human_merge_reason_text,omitempty"` Head string `json:"head,omitempty"` + // DecisionNeeded mirrors the nested PR's own row field so the issue's + // sub-row can open the same "Needs human" popover. + DecisionNeeded *StageTrackerDecision `json:"decision_needed,omitempty"` } // Stage numbers the tracker lays out by. Pinned to stagelabels.Table in @@ -1458,6 +1468,15 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto if verifierErr == nil { evidenceVerifier = &verifier } + // The reviewer's decision question for a parked PR comes from the + // local verdict artifact; a missing or unreadable artifact just means + // the popover falls back to the reason-derived question. + var verdictArtifact *review.Artifact + if art, err := review.LoadArtifact(""); err == nil { + verdictArtifact = &art + } + verdictFor := stageTrackerVerdictLookup(verdictArtifact) + sentinelLabel := s.sentinelLabel() lookup := func(repo string, number int) (stagelabels.Record, bool) { if store == nil { return stagelabels.Record{}, false @@ -1604,6 +1623,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto it.LinkedPRs = append(it.LinkedPRs, StageTrackerLinkedPR{Number: lp.Number, URL: lp.URL}) } } + it.DecisionNeeded = stageTrackerDecisionNeeded(it, nil, sentinelLabel) add(it) } addPR := func(repoName string, pr github.PullRequest, verdict *github.MergeVerdict, bucket, bucketReason string) { @@ -1654,6 +1674,11 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto } it.Actor = "maintainer" } + var agg *review.Aggregate + if a, ok := verdictFor(repoName, pr.Number, pr.HeadSHA); ok { + agg = &a + } + it.DecisionNeeded = stageTrackerDecisionNeeded(it, agg, sentinelLabel) add(it) } for _, repo := range status.Repos { @@ -2352,6 +2377,7 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) { lp.HumanApprover, lp.ManualMerge = pr.HumanApprover, pr.ManualMerge lp.HumanMergeReason, lp.HumanMergeReasonText = pr.HumanMergeReason, pr.HumanMergeReasonText lp.BaseRef = pr.BaseRef + lp.DecisionNeeded = pr.DecisionNeeded if len(pr.Modifiers) > 0 { lp.Modifiers = append([]string(nil), pr.Modifiers...) } diff --git a/src/pkg/dashboard/stage_tracker_decision.go b/src/pkg/dashboard/stage_tracker_decision.go new file mode 100644 index 0000000000..677397a0e2 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_decision.go @@ -0,0 +1,412 @@ +package dashboard + +import ( + "slices" + "strings" + "time" + + "github.com/hivecommons/hive/pkg/review" + "github.com/hivecommons/hive/pkg/stageengine" + stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// The "Needs human" popover (hivecommons/hive#14994, owner request +// 2026-10-28): hovering the +// *Needs human decision* pill or the needs-human chip must say WHAT the +// person is being asked to decide, who asked, and which of the row's +// actions advance it. The tracker payload carries that as +// `decision_needed` on every row parked on a person: the reviewer's +// actual question (the `decision_question` the verdict relay recorded in +// review-verdicts.json for the PR's current head — the same text the 085 +// stage comment prints after "reviewer question:"), the blocking reason in +// plain words, and the applicable actions under the SAME ids the row +// context menu uses, so the popover's buttons and the menu share one code +// path in the SPA. + +// StageTrackerDecision is the decision a person owes on a tracker row. +type StageTrackerDecision struct { + // Question is what the person must decide, in the asker's own words + // when the hive has them (the reviewer's decision question), else a + // sentence derived from the park reason. + Question string `json:"question"` + // AskedBy names who parked the item: "reviewer swarm", "sentinel", + // "lane rule", "GitHub App permissions", "triage gate", "hive agent", + // "escalation ledger". + AskedBy string `json:"asked_by"` + // Since is when the question was asked: the verdict's recorded time + // for a reviewer question, else when the item entered its stage. + Since *time.Time `json:"since,omitempty"` + // Blocker says in plain words what stops the hive from proceeding on + // its own (and, where it applies, what a human approval cannot do); + // BlockerReason is the lane token behind it + // ("contributor-lane:changes-requested", "sentinel-alert", …). + Blocker string `json:"blocker,omitempty"` + BlockerReason string `json:"blocker_reason,omitempty"` + // Options are the actions that can advance the item, first the one the + // owner asked to lead ("Let hive decide"), under the row context menu's + // action ids. A disabled option says why; the SPA further greys out + // what the signed-in viewer's role does not allow. + Options []StageTrackerDecisionOption `json:"options"` +} + +// StageTrackerDecisionOption is one action the popover offers. +type StageTrackerDecisionOption struct { + Action string `json:"action"` + Label string `json:"label"` + Enabled bool `json:"enabled"` + ReasonIfDisabled string `json:"reason_if_disabled,omitempty"` +} + +// Action ids shared with the SPA's row context menu +// (STAGE_TRACKER_ACTION_LABELS in index.html). +const ( + decisionActionDelegate = "decide:delegate" + decisionActionApprove = "decide:approve" + decisionActionDirection = "decide:direction" + decisionActionCloseSuperseded = "decide:close-superseded" + decisionActionCloseWontfix = "decide:close-wontfix" + decisionActionAcceptTriage = "accept-triage" + decisionActionHold = "hold" + decisionActionRelease = "release" + decisionActionNeedsHuman = "needs-human" +) + +// Who asked, in the plain words the popover prints (owner, 2026-10-28: +// "exceedingly clear, easy to read, and concise" — no hive jargon). +const ( + decisionAskedByReviewer = "a reviewer" + decisionAskedBySentinel = "the security check" + decisionAskedByLane = "the hive" + decisionAskedByApp = "GitHub permissions" + decisionAskedByTriage = "triage" + decisionAskedByHiveAgent = "the hive" + decisionAskedByEscalation = "the needs-human label" +) + +// Blocker reason tokens the tracker coins when the lane left none. The +// token is for machines (filters, tests); the popover prints Blocker. +const ( + decisionBlockerSentinel = "sentinel-alert" + decisionBlockerHold = "hold" +) + +const ( + decisionWhyHeld = "On hold — release the hold first" + decisionWhyNoPermission = "Only a person with the permission can do this" + decisionWhyApproveNoGrant = "Approving does not grant the missing permission" + decisionHeldBlocker = "On hold — the hive does nothing until the hold is released." +) + +// stageTrackerVerdictLookup returns a lookup over review-verdicts.json for +// the newest aggregate recorded for repo#number at head, mirroring the +// contributor lane's own match (cmd/hive contributorLaneVerdictFromArtifact) +// so the popover quotes the question the lane acted on. nil artifact → a +// lookup that never matches. +func stageTrackerVerdictLookup(artifact *review.Artifact) func(repo string, number int, head string) (review.Aggregate, bool) { + return func(repo string, number int, head string) (review.Aggregate, bool) { + if artifact == nil || number == 0 || strings.TrimSpace(head) == "" { + return review.Aggregate{}, false + } + var match review.Aggregate + var ok bool + for _, item := range artifact.Items { + item = item.Normalize() + if item.Number != number || !strings.EqualFold(strings.TrimSpace(item.Repo), strings.TrimSpace(repo)) || !review.SameHeadSHA(item.HeadSHA, head) { + continue + } + if !ok || item.RecordedAt.After(match.RecordedAt) { + match, ok = item, true + } + } + return match, ok + } +} + +// stageTrackerDecisionNeeded derives the decision a row asks of a person, +// or nil when nothing on the row waits on one. verdict is the review +// aggregate for the PR's current head when the artifact has one; +// sentinelLabel is the configured sentinel alert label. +func stageTrackerDecisionNeeded(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel string) *StageTrackerDecision { + held := slices.Contains(it.Modifiers, modHold) + switch { + case it.Kind == "pr" && (it.Stage == stagelabels.NeedsDecision.Number() || slices.Contains(it.Modifiers, modNeedsDecision)): + return decisionForPR(it, verdict, sentinelLabel, held) + case it.Kind == "issue" && it.Mirrored: + // The issue rides its covering PR; the PR's own row (nested under + // the issue) carries the decision. + return nil + case it.Kind == "issue" && (it.Stage == stagelabels.IssueNeedsDecision.Number() || slices.Contains(it.Modifiers, modNeedsDecision)): + return decisionForIssue(it, held) + case it.Kind == "issue" && (it.Stage == stagelabels.TriageNeeded.Number() || slices.Contains(it.Modifiers, modNeedsTriage)): + return decisionForTriage(it, held) + case slices.Contains(it.Modifiers, modNeedsHuman): + return decisionForNeedsHuman(it, held) + } + return nil +} + +func decisionHoldOption(held bool) StageTrackerDecisionOption { + if held { + return StageTrackerDecisionOption{Action: decisionActionRelease, Label: "Release hold", Enabled: true} + } + return StageTrackerDecisionOption{Action: decisionActionHold, Label: "Hold", Enabled: true} +} + +func decisionOption(action, label string, enabled bool, why string) StageTrackerDecisionOption { + if enabled { + why = "" + } + return StageTrackerDecisionOption{Action: action, Label: label, Enabled: enabled, ReasonIfDisabled: why} +} + +// decisionChangesRequested reports whether the base reason says a swarm +// reviewer asked for changes — directly, or as the lane reason an adoption +// stalled on. +func decisionChangesRequested(base string) bool { + lower := strings.ToLower(strings.TrimSpace(base)) + lower = strings.TrimPrefix(lower, stagelabels.LaneReasonAdoptionStalledPrefix) + switch lower { + case stageengineprstage.ContributorLaneReasonChangesRequested, stagelabels.LaneReasonChangesRequested, + "reviewer-verdict:request_changes", "changes-requested", stageengineprstage.AutoMergeReasonHumanChangesRequested: + return true + } + return false +} + +// decisionLaneRule reports whether the base reason is a lane rule that +// never merges unattended whoever approves (workflow files, removed tests, +// human-merge paths, no reviewer, refused merges, …). +func decisionLaneRule(base string) bool { + lower := strings.ToLower(strings.TrimSpace(base)) + switch lower { + case stageengineprstage.ContributorLaneReasonWorkflowPath, stageengineprstage.ContributorLaneReasonTestsRemoved, + stageengineprstage.ContributorLaneReasonNoReviewer, stageengineprstage.ContributorLaneReasonReporterTrustHold, + stageengineprstage.ContributorLaneReasonNoAppBotLogin, stageengineprstage.ContributorLaneReasonFilesEvidence, + stageengineprstage.AutoMergeReasonHumanMergePath, stageengineprstage.AutoMergeReasonHumanMergePathEvidence, + stageengineprstage.AutoMergeReasonIntentUnauthorized, stageengineprstage.AutoMergeReasonIntentEvidence, + stageengineprstage.AutoMergeReasonMergeRefusedReview, stageengineprstage.AutoMergeReasonMergeRefusedMethod, + stageengineprstage.AutoMergeReasonNoAppBotLogin: + return true + } + return false +} + +// decisionPlainReason renders a lane rule in plain words for the popover +// (the owner's bar: no reason slugs, no stage codes, no hive jargon). +func decisionPlainReason(base string) string { + switch strings.ToLower(strings.TrimSpace(base)) { + case stageengineprstage.ContributorLaneReasonWorkflowPath: + return "it edits CI workflow files" + case stageengineprstage.ContributorLaneReasonTestsRemoved: + return "it removes tests" + case stageengineprstage.ContributorLaneReasonNoReviewer: + return "no reviewer is configured for this repo" + case stageengineprstage.ContributorLaneReasonReporterTrustHold: + return "the author's trust level is not yet known" + case stageengineprstage.ContributorLaneReasonNoAppBotLogin, stageengineprstage.AutoMergeReasonNoAppBotLogin: + return "the hive's GitHub App login is not known" + case stageengineprstage.ContributorLaneReasonFilesEvidence: + return "the hive could not read its changed files" + case stageengineprstage.AutoMergeReasonHumanMergePath, stageengineprstage.AutoMergeReasonHumanMergePathEvidence: + return "it touches files a person must merge" + case stageengineprstage.AutoMergeReasonIntentUnauthorized, stageengineprstage.AutoMergeReasonIntentEvidence: + return "the hive could not confirm the author's merge intent" + case stageengineprstage.AutoMergeReasonMergeRefusedReview: + return "GitHub requires a review the hive cannot give" + case stageengineprstage.AutoMergeReasonMergeRefusedMethod: + return "GitHub refused the hive's merge method" + } + if text := humanizeStageReason(base); text != "" { + return text + } + return "the hive parked it" +} + +func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel string, held bool) *StageTrackerDecision { + base, _ := stagelabels.HumanApprovedReason(it.Reason) + base = strings.TrimSpace(base) + lower := strings.ToLower(base) + sha := shortHead(it.Head) + at := "" + if sha != "" { + at = " on " + sha + } + d := &StageTrackerDecision{Since: it.StageSince, AskedBy: decisionAskedByLane, BlockerReason: base} + approveOK, approveWhy := true, "" + delegateOK, delegateWhy := !held, decisionWhyHeld + + sentinel := it.SentinelAlert || lower == "sentinel" || lower == stageengineprstage.ContributorLaneReasonSentinelBlocked + changes := decisionChangesRequested(base) + laneRule := decisionLaneRule(base) + adoptionLane, adoptionStalled := strings.CutPrefix(base, stagelabels.LaneReasonAdoptionStalledPrefix) + forkGuard, forkGuarded := strings.CutPrefix(base, stageengineprstage.StageReasonForkGuard) + reviewerDeferred := lower == stageengine.StageReasonVerdictRequiresHuman || lower == stageengine.StageReasonDecisionRequested + + // WHAT it is waiting on: the question, most specific source first. A + // reviewer's own question is quoted verbatim — it is the text the + // hive's "Needs a decision" comment on the PR prints after "reviewer + // question:", read from the same verdict record. + switch { + case it.UnauthorizedStep != "": + d.AskedBy = decisionAskedByApp + d.Question = "The hive's GitHub App may not " + unauthorizedStepWords(it.UnauthorizedStep) + " here. A maintainer has to do that step on GitHub." + d.Blocker = strings.TrimSpace(it.Unauthorized) + delegateOK, delegateWhy = false, decisionWhyNoPermission + approveOK, approveWhy = false, decisionWhyApproveNoGrant + case verdict != nil && strings.TrimSpace(verdict.DecisionQuestion) != "": + d.AskedBy = decisionAskedByReviewer + d.Question = strings.TrimSpace(verdict.DecisionQuestion) + if !verdict.RecordedAt.IsZero() { + t := verdict.RecordedAt + d.Since = &t + } + case verdict != nil && decisionFirstNonEmpty(verdict.HumanSummaries) != "": + d.AskedBy = decisionAskedByReviewer + d.Question = "A reviewer handed this to a person: " + decisionFirstNonEmpty(verdict.HumanSummaries) + if !verdict.RecordedAt.IsZero() { + t := verdict.RecordedAt + d.Since = &t + } + case reviewerDeferred: + d.AskedBy = decisionAskedByReviewer + d.Question = "A reviewer handed this PR to a person without a specific question. Merge it as is, give direction, or close it?" + case sentinel: + d.AskedBy = decisionAskedBySentinel + reason := strings.TrimSpace(it.SentinelReason) + if reason == "" { + reason = "security-relevant changes" + } + d.Question = "The security check flagged " + reason + at + ". Accept it as is, give direction, or close it?" + case adoptionStalled: + d.Question = "The hive took this PR over but could not move it (" + decisionPlainReason(adoptionLane) + "). Give direction, or close it?" + case forkGuarded: + d.Question = "CI will not run for this fork PR (" + strings.ReplaceAll(forkGuard, ",", ", ") + "). A maintainer must push the branch to this repo — or close it?" + case changes: + d.AskedBy = decisionAskedByReviewer + d.Question = "A reviewer requested changes" + at + ". Give direction for a new commit, or close it?" + case laneRule: + d.Question = "The hive never merges this by itself (" + decisionPlainReason(base) + "). Approve it for a maintainer to merge, give direction, or close it?" + default: + clause := decisionPlainReason(base) + if base == "" { + clause = strings.TrimSpace(it.Caption) + } + if clause == "" { + clause = "the hive parked it" + } + d.Question = "A person must decide (" + clause + "). Approve, give direction, or close?" + } + + // The blocker in plain words, and what it disables. + switch { + case it.UnauthorizedStep != "": + // set above + case changes: + d.Blocker = "A reviewer requested changes" + at + " — needs a new commit. Approving cannot override that." + approveOK, approveWhy = false, d.Blocker + case sentinel: + d.Blocker = "The security check has an open alert. The hive will not merge until a person removes the `" + sentinelLabel + "` label." + if base == "" { + d.BlockerReason = decisionBlockerSentinel + } + case laneRule: + d.Blocker = "The hive never merges this by itself. After approval, a maintainer merges." + case forkGuarded: + d.Blocker = "Neither the author nor the hive can make CI run for this fork PR." + case reviewerDeferred: + d.Blocker = "The hive will not merge until a person decides." + } + if held { + if d.Blocker != "" { + d.Blocker += " " + } + d.Blocker += decisionHeldBlocker + if d.BlockerReason == "" { + d.BlockerReason = decisionBlockerHold + } + } + + d.Options = []StageTrackerDecisionOption{ + decisionOption(decisionActionDelegate, "Let hive decide", delegateOK, delegateWhy), + decisionOption(decisionActionApprove, "Approve", approveOK, approveWhy), + decisionOption(decisionActionDirection, "Give direction", true, ""), + decisionOption(decisionActionCloseSuperseded, "Close as superseded", true, ""), + decisionOption(decisionActionCloseWontfix, "Close as won't fix", true, ""), + decisionHoldOption(held), + } + return d +} + +func decisionForIssue(it StageTrackerItem, held bool) *StageTrackerDecision { + d := &StageTrackerDecision{Since: it.StageSince, AskedBy: decisionAskedByHiveAgent, BlockerReason: strings.TrimSpace(it.Reason)} + d.Question = "The hive parked this issue for a person. Approve the direction, send it back with direction, or close it?" + d.Blocker = "No agent picks this up until a person answers. The hive's question is in its latest comment on the issue." + if held { + d.Blocker += " " + decisionHeldBlocker + if d.BlockerReason == "" { + d.BlockerReason = decisionBlockerHold + } + } + d.Options = []StageTrackerDecisionOption{ + decisionOption(decisionActionDelegate, "Let hive decide", !held, decisionWhyHeld), + decisionOption(decisionActionApprove, "Approve direction", true, ""), + decisionOption(decisionActionDirection, "Send back", true, ""), + decisionOption(decisionActionCloseSuperseded, "Close as superseded", true, ""), + decisionOption(decisionActionCloseWontfix, "Close as won't fix", true, ""), + decisionHoldOption(held), + } + return d +} + +func decisionForTriage(it StageTrackerItem, held bool) *StageTrackerDecision { + d := &StageTrackerDecision{Since: it.StageSince, AskedBy: decisionAskedByTriage, BlockerReason: strings.TrimSpace(it.Reason)} + d.Question = "Should the hive work on this issue? Accept triage so an agent can take it, hold it, or mark it needs-human." + d.Blocker = "No agent picks up an issue until a maintainer accepts triage." + if held { + d.Blocker += " " + decisionHeldBlocker + } + d.Options = []StageTrackerDecisionOption{ + decisionOption(decisionActionAcceptTriage, "Accept triage", true, ""), + decisionHoldOption(held), + } + if !slices.Contains(it.Modifiers, modNeedsHuman) { + d.Options = append(d.Options, decisionOption(decisionActionNeedsHuman, "Mark needs-human", true, "")) + } + return d +} + +func decisionForNeedsHuman(it StageTrackerItem, held bool) *StageTrackerDecision { + d := &StageTrackerDecision{Since: it.StageSince, AskedBy: decisionAskedByEscalation, BlockerReason: "label:" + modNeedsHuman} + what := "issue" + if it.Kind == "pr" { + what = "PR" + } + d.Question = "This " + what + " is marked needs-human: automated fixes ran out, or a person flagged it. Review it on GitHub and remove the label when the hive may continue." + d.Blocker = "The hive does nothing with a needs-human item until a person removes the label." + if held { + d.Blocker += " " + decisionHeldBlocker + } + d.Options = []StageTrackerDecisionOption{decisionHoldOption(held)} + return d +} + +// decisionParkLabel pulls the label out of a 045 reason ("held for a +// person: needs-human", "parked on a person: needs-decision"); "" otherwise. +func decisionParkLabel(reason string) string { + for _, prefix := range []string{"held for a person:", "parked on a person:"} { + if rest, ok := strings.CutPrefix(strings.TrimSpace(reason), prefix); ok { + return strings.TrimSpace(rest) + } + } + return "" +} + +func decisionFirstNonEmpty(ss []string) string { + for _, s := range ss { + if t := strings.TrimSpace(s); t != "" { + return t + } + } + return "" +} diff --git a/src/pkg/dashboard/stage_tracker_decision_popover_test.go b/src/pkg/dashboard/stage_tracker_decision_popover_test.go new file mode 100644 index 0000000000..487c33b70a --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_decision_popover_test.go @@ -0,0 +1,144 @@ +package dashboard + +import ( + "strings" + "testing" +) + +// The "Needs human" decision popover (owner request, 2026-10-28): hovering +// or focusing the "Needs human decision" chevron word / needs-human pill +// shows WHAT to decide, who asked and when, the blocker in plain words, +// and the applicable actions — "Let hive decide" first — down the row +// context menu's code path. The pure helpers run under node the way +// stage_tracker_row_actions_test.go does. + +func stageTrackerDecisionPopPreamble(t *testing.T, html string) string { + t.Helper() + return strings.Join([]string{ + stageTrackerRowActionsPreamble(t, html), + jsConstLine(t, html, "STAGE_TRACKER_DECISION_LEAVE_MS"), + "var _stageTrackerDecisionPop = null;", + jsFunc(t, html, "agentNowAgo"), + jsFunc(t, html, "stageTrackerDecisionOf"), + jsFunc(t, html, "stageTrackerDecisionTriggerHtml"), + jsFunc(t, html, "stageTrackerDecisionOptions"), + jsFunc(t, html, "stageTrackerDecisionPopHtml"), + jsFunc(t, html, "stageTrackerDecisionRun"), + }, "\n") +} + +const stageTrackerDecisionPopFixture = ` +const decision = { question: 'Should the retry budget go to 5?', asked_by: 'a reviewer', since: '2026-10-27T10:30:00Z', + blocker: 'A reviewer requested changes on b0f5f80 — needs a new commit. Approving cannot override that.', blocker_reason: 'contributor-lane:changes-requested', + options: [ + { action: 'decide:approve', label: 'Approve', enabled: false, reason_if_disabled: 'A reviewer requested changes on b0f5f80 — needs a new commit. Approving cannot override that.' }, + { action: 'decide:delegate', label: 'Let hive decide', enabled: true }, + { action: 'decide:direction', label: 'Give direction', enabled: true }, + { action: 'decide:close-superseded', label: 'Close as superseded', enabled: true }, + { action: 'decide:close-wontfix', label: "Close as won't fix", enabled: true }, + { action: 'hold', label: 'Hold', enabled: true }, + ] }; +const pr = { repo: 'o/r', kind: 'pr', number: 7, title: 'Raise retries', url: 'https://github.com/o/r/pull/7', stage: 85, stage_since: '2026-10-27T09:00:00Z', modifiers: ['needs-decision'], decision_needed: decision }; +const issue = { repo: 'o/r', kind: 'issue', number: 3, title: 'Flaky retries', stage: 40, mirrored: true, modifiers: [], linked_prs: [ { number: 7, title: 'Raise retries', url: 'https://github.com/o/r/pull/7', stage: 85, modifiers: ['needs-decision'], decision_needed: decision } ] }; +const plain = { repo: 'o/r', kind: 'pr', number: 8, title: 'Plain', stage: 60, modifiers: [] }; +const ctx = { user: true, canHold: true, canHuman: true }; +` + +func TestStageTrackerDecisionPopoverContent(t *testing.T) { + html := indexHTML(t) + runStageTrackerRowActionsScript(t, stageTrackerDecisionPopPreamble(t, html)+stageTrackerDecisionPopFixture+` +// The row's decision: the PR's own; an issue's is its parked nested PR's; a plain row has none. +assert.strictEqual(stageTrackerDecisionOf(pr).key, 'o/r/pr#7'); +const viaIssue = stageTrackerDecisionOf(issue); +assert.strictEqual(viaIssue.key, 'o/r/pr#7'); +assert.strictEqual(viaIssue.item.kind, 'pr'); +assert.strictEqual(viaIssue.item.decision_needed.question, decision.question); +assert.strictEqual(stageTrackerDecisionOf(plain), null); +assert.strictEqual(stageTrackerDecisionOf(null), null); + +// Options: server narrowed by the viewer's role; "Let hive decide" leads; disabled carry their reason. +let opts = stageTrackerDecisionOptions(pr, ctx); +assert.deepStrictEqual(opts.map(o => o.id), ['decide:delegate', 'decide:approve', 'decide:direction', 'decide:close-superseded', 'decide:close-wontfix', 'hold']); +assert.strictEqual(opts[0].enabled, true); +assert.strictEqual(opts[1].enabled, false); +assert.ok(opts[1].why.indexOf('requested changes') >= 0, opts[1].why); +assert.strictEqual(opts.find(o => o.id === 'decide:close-wontfix').danger, true); +// A read-only viewer sees every option greyed with the sign-in reason. +opts = stageTrackerDecisionOptions(pr, { user: false, canHold: false, canHuman: false }); +assert.ok(opts.every(o => !o.enabled), JSON.stringify(opts)); +assert.strictEqual(opts[0].why, STAGE_TRACKER_WHY_WRITE); + +// Trigger: a button, no native title (the popover is the hover text), aria for the dialog. +const trig = stageTrackerDecisionTriggerHtml(stageTrackerDecisionOf(pr), 'Needs human decision', 'Merge gate — tip'); +assert.ok(/^`; + } + // Pure: the popover's options — the server's (what the row's state + // allows) narrowed by the client's (what this viewer may do): enabled + // only when both agree, the first reason wins. "Let hive decide" leads. + function stageTrackerDecisionOptions(item, ctx) { + const d = item && item.decision_needed; + const server = d && Array.isArray(d.options) ? d.options : []; + const flat = stageTrackerFlatActions(stageTrackerRowActions(item, ctx || { user: false, canHold: false, canHuman: false })); + const out = server.map(o => { + const c = flat[o.action]; + const enabled = !!o.enabled && !!(c && c.enabled); + const why = enabled ? '' : (o.reason_if_disabled || (c ? c.why : 'Not available on this row') || ''); + return { id: o.action, label: o.label || STAGE_TRACKER_ACTION_LABELS[o.action] || o.action, enabled, why, danger: !!(c && c.danger) || /^decide:close-/.test(o.action) }; + }); + const lead = out.findIndex(o => o.id === 'decide:delegate'); + if (lead > 0) out.unshift(out.splice(lead, 1)[0]); + return out; + } + // Pure: the popover markup. + function stageTrackerDecisionPopHtml(item, options, nowMs, tip) { + const d = item.decision_needed || {}; + const ref = stageTrackerRefOf(item); + const sinceMs = Date.parse(d.since || item.stage_since || ''); + const meta = ['Asked by ' + (d.asked_by || 'the hive'), sinceMs ? agentNowAgo(nowMs - sinceMs) : ''].filter(Boolean).join(' · '); + const buttons = options.map(o => ``).join(''); + // Order (owner): WHAT it is waiting on → WHAT you can do → WHO asked, when. + return ``; + } + // Run a popover action down the row context menu's path. + function stageTrackerDecisionRun(item, act) { + if (typeof runRowAction === 'function') return runRowAction(act, item); + return stageTrackerDoAction([item], act); + } + function stageTrackerCloseDecisionPop(refocus) { + const p = _stageTrackerDecisionPop; + if (!p) return; + _stageTrackerDecisionPop = null; + clearTimeout(p.timer); + document.removeEventListener('pointerdown', p.onAway, true); + document.removeEventListener('keydown', p.onKey, true); + window.removeEventListener('resize', p.onAway); + window.removeEventListener('scroll', p.onAway, true); + if (p.el.parentNode) p.el.parentNode.removeChild(p.el); + const trig = stageTrackerDecisionTrigger(p.key); + if (trig) trig.setAttribute('aria-expanded', 'false'); + if (refocus && trig && typeof trig.focus === 'function') trig.focus(); + } + function stageTrackerDecisionTrigger(key) { + const el = document.getElementById('activity-monitor-panel'); + if (!el || !key) return null; + for (const b of el.querySelectorAll('.ham-decision-trigger')) if (b.dataset.hamDecision === key) return b; + return null; + } + // Open (or pin) the popover for a trigger. Hover opens it unpinned: it + // closes once neither the trigger nor the popover is hovered. Click or + // focus pins it: it then closes on Esc, click-away, scroll or resize. + function stageTrackerOpenDecisionPop(trigger, pin) { + const key = trigger && trigger.dataset ? trigger.dataset.hamDecision : ''; + if (!key) return; + if (_stageTrackerDecisionPop && _stageTrackerDecisionPop.key === key) { + if (pin) _stageTrackerDecisionPop.pinned = true; + clearTimeout(_stageTrackerDecisionPop.timer); + return; + } + stageTrackerCloseDecisionPop(false); + stageTrackerCloseMenu(false); + const item = stageTrackerItemByKey(_stageTracker, key); + if (!item || !item.decision_needed) return; + const options = stageTrackerDecisionOptions(item, stageTrackerActionCtx(item.repo)); + const tpl = document.createElement('template'); + tpl.innerHTML = stageTrackerDecisionPopHtml(item, options, Date.now(), trigger.dataset.hamTip || ''); + const el = tpl.content.firstElementChild; + document.body.appendChild(el); + const r = trigger.getBoundingClientRect(); + const pos = stageTrackerMenuPosition(r.left, r.bottom, el.offsetWidth, el.offsetHeight, window.innerWidth, window.innerHeight); + el.style.setProperty('left', pos.left + 'px'); + el.style.setProperty('top', pos.top + 'px'); + trigger.setAttribute('aria-expanded', 'true'); + const p = { el, key, item, pinned: !!pin, timer: 0 }; + p.onAway = e => { if (e.type !== 'pointerdown' || !(el.contains(e.target) || (e.target.closest && e.target.closest('.ham-decision-trigger') === stageTrackerDecisionTrigger(key)))) stageTrackerCloseDecisionPop(false); }; + p.onKey = e => { + if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); stageTrackerCloseDecisionPop(true); return; } + if (e.key === 'Tab' && el.contains(e.target)) { + const acts = Array.from(el.querySelectorAll('.ham-decision-act')); + const last = acts[acts.length - 1], first = acts[0]; + if ((!e.shiftKey && e.target === last) || (e.shiftKey && (e.target === first || e.target === el))) stageTrackerCloseDecisionPop(true); + } + }; + el.addEventListener('pointerenter', () => clearTimeout(p.timer)); + el.addEventListener('pointerleave', () => stageTrackerDecisionPopLeave()); + el.addEventListener('focusin', () => { p.pinned = true; clearTimeout(p.timer); }); + el.addEventListener('click', e => { + const b = e.target.closest('[data-ham-act]'); + if (!b || b.getAttribute('aria-disabled') === 'true') return; + e.preventDefault(); e.stopPropagation(); + const act = b.dataset.hamAct; + stageTrackerCloseDecisionPop(true); + stageTrackerDecisionRun(p.item, act); + }); + document.addEventListener('pointerdown', p.onAway, true); + document.addEventListener('keydown', p.onKey, true); + window.addEventListener('resize', p.onAway); + window.addEventListener('scroll', p.onAway, true); + _stageTrackerDecisionPop = p; + if (pin && pin.focus) { const first = el.querySelector('.ham-decision-act:not([aria-disabled="true"])'); (first || el).focus(); } + } + // The pointer left the trigger or the popover: close after a beat unless + // it is pinned or the pointer is back over either (rows re-render, so + // the trigger is looked up afresh by key). + function stageTrackerDecisionPopLeave() { + const p = _stageTrackerDecisionPop; + if (!p || p.pinned) return; + clearTimeout(p.timer); + p.timer = setTimeout(() => { + const q = _stageTrackerDecisionPop; + if (!q || q.pinned) return; + const trig = stageTrackerDecisionTrigger(q.key); + if (q.el.matches(':hover') || (trig && trig.matches(':hover'))) { stageTrackerDecisionPopLeave(); return; } + stageTrackerCloseDecisionPop(false); + }, STAGE_TRACKER_DECISION_LEAVE_MS); + } + function stageTrackerWireDecisionPop(el) { + el.addEventListener('pointerover', e => { + const b = e.target.closest ? e.target.closest('.ham-decision-trigger') : null; + if (b && el.contains(b) && e.pointerType !== 'touch') stageTrackerOpenDecisionPop(b, false); + }); + el.addEventListener('pointerout', e => { + const b = e.target.closest ? e.target.closest('.ham-decision-trigger') : null; + if (b) stageTrackerDecisionPopLeave(); + }); + el.addEventListener('focusin', e => { + const b = e.target.closest ? e.target.closest('.ham-decision-trigger') : null; + if (b) stageTrackerOpenDecisionPop(b, true); + }); + el.addEventListener('click', e => { + const b = e.target.closest ? e.target.closest('.ham-decision-trigger') : null; + if (!b || e.metaKey || e.ctrlKey || e.shiftKey) return; + e.preventDefault(); e.stopPropagation(); + if (_stageTrackerDecisionPop && _stageTrackerDecisionPop.key === b.dataset.hamDecision && _stageTrackerDecisionPop.pinned) { stageTrackerCloseDecisionPop(false); return; } + stageTrackerOpenDecisionPop(b, { focus: true }); + }); + el.addEventListener('keydown', e => { + const b = e.target.closest ? e.target.closest('.ham-decision-trigger') : null; + if (b && (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); stageTrackerOpenDecisionPop(b, { focus: true }); } + }); } function stageTrackerSelect(key, mods) { const el = document.getElementById('activity-monitor-panel'); From cf65b6b2fc10df5c1ad2fa2b08da1b0faf56d998 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Wed, 28 Oct 2026 12:40:05 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8C=B1=20Drop=20unused=20decisionPark?= =?UTF-8?q?Label=20helper=20(golangci-lint=20unused)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrew Anderson --- src/pkg/dashboard/stage_tracker_decision.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/pkg/dashboard/stage_tracker_decision.go b/src/pkg/dashboard/stage_tracker_decision.go index 677397a0e2..d7f03072c8 100644 --- a/src/pkg/dashboard/stage_tracker_decision.go +++ b/src/pkg/dashboard/stage_tracker_decision.go @@ -391,17 +391,6 @@ func decisionForNeedsHuman(it StageTrackerItem, held bool) *StageTrackerDecision return d } -// decisionParkLabel pulls the label out of a 045 reason ("held for a -// person: needs-human", "parked on a person: needs-decision"); "" otherwise. -func decisionParkLabel(reason string) string { - for _, prefix := range []string{"held for a person:", "parked on a person:"} { - if rest, ok := strings.CutPrefix(strings.TrimSpace(reason), prefix); ok { - return strings.TrimSpace(rest) - } - } - return "" -} - func decisionFirstNonEmpty(ss []string) string { for _, s := range ss { if t := strings.TrimSpace(s); t != "" {