From 9d6587479a7e31428397aff254fb70afa448b250 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 11:12:29 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20dashboard:=20Let=20hive=20de?= =?UTF-8?q?cide=20preview=20is=20one=20clear=20decision,=20not=20a=20wall?= =?UTF-8?q?=20of=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The delegated-decision preview showed the repo#number twice, composed 'Hive would:' twice (the plan API's summary already carried the prefix and stageTrackerDelegatePlanText prepended it again), inlined the consequences into a paragraph, drowned the decision under a rails footer, and offered 'Approve & merge as-is' for a head the preview itself called not mergeable. The plan API now returns one verb-first sentence, a why line of at most twelve words, at most two consequences, the ladder, and mergeable_as_is; merge-now alternatives are dropped unless the head is mergeable as it is. The dashboard renders every plan — PR, issue, adopt/close/return — through one renderer: title, subject line, optional Sentinel chip, 'Hive would' sentence, Why, Then list, and a collapsed Details holding the rails, the ruled-out rungs and the sentinel finding. Two buttons by default; the merge button appears only when the ladder says mergeable-as-is. Fixes #15397 Signed-off-by: Andrew Anderson --- .../fixed-decide-preview-one-decision.md | 1 + src/docs/api-reference/packs-and-acmm.md | 2 +- src/docs/dashboard-sections.md | 9 +- .../api_repo_item_decide_delegated_plan.go | 162 +++++++++++++---- ...pi_repo_item_decide_delegated_plan_test.go | 89 +++++++++- .../stage_tracker_row_actions_test.go | 123 ++++++++++++- src/pkg/dashboard/static-src/css/tracker.css | 26 ++- .../static-src/js/tracker-actions.js | 138 +++++++++++---- src/pkg/dashboard/static/index.html | 164 ++++++++++++++---- 9 files changed, 611 insertions(+), 103 deletions(-) create mode 100644 changelog.d/fixed-decide-preview-one-decision.md diff --git a/changelog.d/fixed-decide-preview-one-decision.md b/changelog.d/fixed-decide-preview-one-decision.md new file mode 100644 index 0000000000..4b26e42f39 --- /dev/null +++ b/changelog.d/fixed-decide-preview-one-decision.md @@ -0,0 +1 @@ +- Dashboard: the *Let hive decide* preview is one clear decision instead of a wall of text — one verb-first sentence (no doubled "Hive would:"), one short why, at most two "then" items, the sentinel finding / rails / ruled-out rungs under a collapsed Details, and **Approve & merge as-is** offered only when the head is mergeable as it is. diff --git a/src/docs/api-reference/packs-and-acmm.md b/src/docs/api-reference/packs-and-acmm.md index d9a10f1ff0..6688d01849 100644 --- a/src/docs/api-reference/packs-and-acmm.md +++ b/src/docs/api-reference/packs-and-acmm.md @@ -19,7 +19,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `POST` | `/api/repos/{owner}/{repo}/items/{number}/hold` | Owner or repo write/maintain/admin | Add or remove a dashboard hold chip for an issue or PR. Body `{"held": true}` adds the hive's exact-match canonical `hive-pause/` label; `{"held": false}` removes exactly the labels causing the hold (`hive-pause/` and/or generic hold labels) and never removes `hive/` provenance. Every toggle writes an audit-log entry; the #8851 upgrade migration writes `/data/hive-hold-migration-.json` with audit-backed, provenance-only, and ambiguous legacy `hive/` classifications. | `pkg/dashboard/api.go:337`, `pkg/dashboard/api_repo_hold.go` | | `POST` | `/api/repos/{owner}/{repo}/items/{number}/decision` | Owner or repo write/maintain/admin, signed-in GitHub user | Record an operator decision from the activity monitor's row menu / selection bar. Body `{"decision": "approve"|"direction"|"close-superseded"|"close-wontfix"|"adopt"|"reroute"|"re-author"|"merge-now"|"queue-merge", "comment": "…", "type": "issue"|"pr", "superseded_by": "#458", "force": true, "to": ""|"any"}` (`force` only with `adopt`, `to` only with `reroute`; an unknown `decision` is a 400). On an issue parked at 045, `approve`/`direction` act exactly as a maintainer's `/hive approve` / `/hive decision ` comment would (labels, `approved-direction`, stage-engine Unparked fact, reply comment naming the operator). On a PR parked at 085 (`type: "pr"`), `approve` posts the `/lgtm` and `/approve` commands as two comments attributed to the operator, records the approval against the head as the human answer to a `requires_human` / decision-requested verdict (the lanes and the stage engine honour it like a trusted merger's Approve review), lifts `needs-human`, clears the sentinel label and acknowledges the bundle's sentinel findings for that head, re-derives the stage and drops the tracker cache — the response adds `released` (`approval-recorded`, `needs-human`, `sentinel-label`, `sentinel-acknowledged`) and `stage`; the merge gate decides from there (no review as the operator, no merge) — and `direction` records the text as a human change request against the head — the `/hive decision` fix lane — on a hive-authored PR, and on a contributor's clanker PR (`author/clanker` / hive attribution markers) where the text is posted to the contributor's hive and the PR moves to `stage/072-returned-to-contributor` (`status: "direction-returned-to-contributor"`); a person's PR, which no hive can carry direction to, answers 409. The close variants post a comment naming the operator (and the superseding PR when `superseded_by` is given) and close the item as not planned. `adopt` and `re-author` require `type: "pr"` and queue adoption via the `adoption/supersede` label (409 unless `governor.labels.stage.adoption` is enabled). `adopt` with `"force": true` is *Adopt now* ([#15038](https://github.com/hivecommons/hive/issues/15038)): it bypasses the author's presence, the grace window and `maintainer_policy`, marks the stage record and nudges the automerge sweep so the adoption engine supersedes the head at once (responds `status: "already-adopted"` when nothing is left to do; 400 on the hive's own PR). `reroute` (`type: "pr"`, `"to": ""|"any"`) hands the PR's follow-up work to another online clanker through the contributor fix queue, posts a `` note and arms a pickup timer that falls back to Adopt now after `governor.reroute.pickup_timeout`; answers `status: "rerouted"`, 409 when no clanker is online or adoption is disabled. On a PR at 090, `merge-now` (*Approve & merge as maintainer*) posts an attributed comment and merges immediately through the hive's GitHub App, returning `status: "merged"`; `queue-merge` (*Approve — let hive merge*) records an approval attributed to the operator and applies the automerge label, returning `status: "queued-for-merge"` for the hive's merge sweep once CI is green and the head has soaked. Both require `type: "pr"` and a verified owner or `merger` role in addition to the route's repo permission check; both refuse closed/merged PRs and the operator's own PR. `merge-now` on a PR whose `mergeable_state` is `dirty`/`behind` instead answers `202` with `status: "rebase-queued"` (approval recorded, rebase kicked, merge follows via the follow-through once the hive's own rebase is green; a head pushed by anyone else fails the follow-through closed; `head-not-pushable` refusal on a fork without maintainer edits). `approve` on such a PR adds `rebase: {attempt, max, exhausted, head, text}` for the rebase episode it opened. Every decision writes an audit-log entry (`repo_item_decision_*`, e.g. `repo_item_decision_adopt_now`, `repo_item_decision_reroute`). | `pkg/dashboard/api.go:338`, `pkg/dashboard/api_repo_item_decision.go` | | `POST` / `GET` | `/api/repos/{owner}/{repo}/items/{number}/decide-delegated` | Same as `…/hold` (owner or repo write), signed-in GitHub user; `decisions.delegate.enabled` (403 when off) | *Let hive decide*: enqueue a delegated-decision job in which the hive decides the parked item itself as the owner's delegate under `pkg/delegatedecision.PolicyText` and records it as a human decision (`/hive decision` comment with the `` marker, park labels off, `triage/accepted`, queue approval on a PR head). Body `{"type": "issue"|"pr", "reason", "caption", "sentinel_reason"}`. `POST` answers 202 with the job (`{id, status: "running"|"done"|"failed", decision: {verdict, rule, text, rationale, actions, keeps_park, ladder?: {decision, reason, ruled_out[]}}, notes, error}`; `ladder` is set on contributor-PR decisions and names the rung that decided — `already-fixed` → `mergeable-as-is` → `rebase-then-merge` → `return-to-contributor` → `contributor-offline` — and why each rung above it did not apply); 409 with the running job while one is in flight; `GET` reads it. Rails: never merges, refuses items wearing `hold`, never grants secrets/permissions (`needs-owner` + `hold` instead), recommends only on hive policy/governance questions (keeps 085). Audited as `repo_item_decision_delegated[_failed]`. See [dashboard-sections.md](../dashboard-sections.md#let-hive-decide). | `pkg/dashboard/api.go:329`, `pkg/dashboard/api_repo_item_decide_delegated.go` | -| `POST` | `/api/repos/{owner}/{repo}/items/{number}/decide-delegated/plan` | Same as `…/decide-delegated` | Preview for *Let hive decide*: runs the same owner-delegate policy with **no side effects** (nothing written, no job) and answers `{would, rule, acting, summary, why, consequences[], alternatives[], writes: false, prior, notes}` — *Hive would: re-author #15029 as a hive PR with the same commits and merge it; #15029 will be closed as superseded. Why: author @Karibhou is untrusted and their clanker is offline.* The confirm popover shows **Let hive do that** / **Approve & merge as-is** / **Cancel**; only then does the SPA post `…/decide-delegated` with `chosen` naming the button. See [dashboard-sections.md](../dashboard-sections.md#let-hive-decide). | `pkg/dashboard/api.go:341`, `pkg/dashboard/api_repo_item_decide_delegated_plan.go` | +| `POST` | `/api/repos/{owner}/{repo}/items/{number}/decide-delegated/plan` | Same as `…/decide-delegated` | Preview for *Let hive decide*: runs the same owner-delegate policy with **no side effects** (nothing written, no job) and answers `{would, rule, acting, title, summary, why, consequences[], ladder, mergeable_as_is, alternatives[], writes: false, prior, notes}` — `summary` is one verb-first sentence with no "Hive would:" prefix (*Send #15332 back to its author with one instruction: make CI green, nothing else.*), `why` one short line (*CI is red.*), `consequences` at most two items, `ladder` the rung that decided with its `ruled_out` list, and `mergeable_as_is` whether an as-is merge is honest (the merge-now alternative is dropped when it is not). The dialog shows **Cancel** / **Let hive do that**, plus **Approve & merge as-is** only when `mergeable_as_is`; only then does the SPA post `…/decide-delegated` with `chosen` naming the button. See [dashboard-sections.md](../dashboard-sections.md#let-hive-decide). | `pkg/dashboard/api.go:341`, `pkg/dashboard/api_repo_item_decide_delegated_plan.go` | | `POST` | `/api/repos/{owner}/{repo}/items/{number}/blocker/recheck` | Same as `…/hold` (owner or repo write), signed-in GitHub user | *Re-check permissions* on an issue parked on a capability blocker (#15099): probes the GitHub App installation's permissions; when the missing permission is granted, clears every ledger entry blocked on it and un-parks the item (`{result: {outcome: "released", …}}`), otherwise `{result: {outcome: "no-effect", reason: "blocker", options: [...]}}`; 404 when the item has no blocker, 409 when the blocker is not a capability gap | `pkg/dashboard/api.go:342` | | `POST` | `/api/repos/{owner}/{repo}/items/{number}/blocker/close-partial` | Same as `…/hold` (owner or repo write), signed-in GitHub user | Option (c) on a capability blocker (#15099): labels the issue `hive/partially-addressed`, posts the operator's `{"comment"}` naming what remains and closes it; the ledger entry is cleared | `pkg/dashboard/api.go:343` | | `POST` | `/api/repos/{owner}/{repo}/items/{number}/accept-triage` | Owner or repo write/maintain/admin | Accept triage on an issue from the activity monitor's row menu — what a maintainer accepting triage on GitHub does by hand: adds the reporter-trust triage label (`triage/accepted`, or the first of `issue_filter.reporter_trust.untrusted_require_labels`; the label is created in the repo if missing) and removes the awaiting label (`needs-triage` / `reporter_trust.awaiting_label`) and a Hive-written `stage/015-triage-needed`. Empty body. Returns `{ok, repo, number, acceptLabel, added, removed, alreadyAccepted, minStatusSeq}`; an issue already carrying the accept label with nothing left to remove is a no-op (`alreadyAccepted: true`, no write, no audit). 404 for a pull request or an unknown item. The status snapshot's labels are patched so the next reconcile reads 010 Actionable before the engine's own 015 → 010 derivation. Every write is audited as `repo_item_accept_triage` under the dashboard user. | `pkg/dashboard/api.go:535`, `pkg/dashboard/api_repo_item_accept_triage.go` | diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 5d480e43b0..90e0ba6efa 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -1304,7 +1304,14 @@ At the same time the hive posts one follow-up comment on the item — *Hive deci The toast and the decision trail lead with the outcome in one line — *Adopted — hive will rebase & merge it next pass (~4m)*; *Adopted: hive opened #15123 with the same commits and will merge it; #15029 will be closed as superseded* — details second, nothing repeated. -**Preview before acting.** *Let hive decide* no longer acts on the click. It first calls `POST …/decide-delegated/plan` , a dry run with no side effects that answers `{would, summary, consequences[], alternatives[]}`, and shows a confirm popover: *Hive would: re-author #15029 as a hive PR with the same commits and merge it; #15029 will be closed as superseded. Why: author @Karibhou is untrusted and their clanker is offline.* Buttons: **Let hive do that** · **Approve & merge as-is** (when the operator has merge rights — the in-tracker maintainer merge when the row exposes it, else an `approve` decision) · **Cancel**. Nothing is written until the operator picks, and the badge tooltip and the trail record which button was pressed (the request's `chosen`). +**Preview before acting.** *Let hive decide* no longer acts on the click. It first calls `POST …/decide-delegated/plan` , a dry run with no side effects that answers `{would, title, summary, why, consequences[], ladder, mergeable_as_is, alternatives[]}`, and shows one decision — built to be read in three seconds (operator feedback on hive's own spoke: the first version was "a wall of text" with a doubled *Hive would: Hive would:*, the PR named twice, three type sizes and a merge button on a head it had just called not mergeable): + +- **Title** *Let hive decide*, then one subject line — `hivecommons/hive#15332 · ci: run crux's Go file-size ratchet…` — with a compact **⚠ Sentinel** chip when the sentinel flagged the head (the full finding is in Details). +- **Eyebrow** *Hive would* → **one verb-first sentence**: *Send #15332 back to its author with one instruction: make CI green, nothing else.* → one muted **Why** line (≤ 12 words: *CI is red.*) → **Then**, at most two short items (*Hive posts that instruction on #15332. · The author pushes a fix; the row updates when it lands.*). +- **Details** (collapsed): the sentinel finding, *Why not the others* — the ladder rungs ruled out above the one that decided (`ladder.ruled_out`) — and the one-line rails (*never merges, never touches held items, never grants secrets; the sentinel label stays with a person*). +- **Buttons**, right-aligned: **Cancel** · **Let hive do that**. **Approve & merge as-is** appears only when the plan says `mergeable_as_is` — the ladder's *mergeable-as-is* rung, or (no ladder) a green, conflict-free, signed-off head — and is greyed with the reason when the operator lacks merge rights; the plan drops the merge-now alternative otherwise, so the dialog cannot contradict itself. + +The same renderer serves issue decisions and every PR verdict (adopt, approve, close as duplicate/superseded, send back, recommend only). The visible text never uses hive's vocabulary (*park*, *audit marker*, *stage*, *ladder*, */hive decision*) and is ≤ 60 words for the #15332 case, which the node harness enforces. Nothing is written until the operator picks, and the badge tooltip and the trail record which button was pressed (the request's `chosen`). **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. diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go b/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go index 976bf85c0e..4531a732b1 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go @@ -6,6 +6,7 @@ import ( "errors" "io" "net/http" + "regexp" "strconv" "strings" "time" @@ -28,20 +29,32 @@ type delegatedDecisionPlan struct { Repo string `json:"repo"` Number int `json:"number"` Type string `json:"type"` + // Title is the item's title, for the dialog's subject line. + Title string `json:"title,omitempty"` // Would is the verdict the hive would record (adopt-supersede, approve, // recommend-only, …); Rule the policy rule behind it; Word the pill / // progress vocabulary for it ("Adopting · opening hive copy…"). Would string `json:"would"` Rule string `json:"rule,omitempty"` Acting string `json:"acting,omitempty"` - // Summary is one line: "Hive would: re-author #15029 as a hive PR with - // the same commits and merge it; #15029 will be closed as superseded." + // Summary is the one decision sentence, verb first and without a + // "Hive would:" prefix (the dialog's eyebrow says that): "Send #15332 + // back to its author with one instruction: make CI green, nothing else." Summary string `json:"summary"` - // Why is the plain reason: "author @Karibhou is untrusted and their - // clanker is offline." + // Why is the one plain reason: "Author @Karibhou is untrusted and + // their clanker is offline." Why string `json:"why,omitempty"` - // Consequences lists what follows, one per line. + // Consequences lists what follows — at most two short items. Consequences []string `json:"consequences"` + // Ladder is the contributor-PR rung the decision landed on, its reason + // and the rungs ruled out above it (hivecommons/hive#15289); the + // dialog shows it under Details. + Ladder *delegatedecision.Ladder `json:"ladder,omitempty"` + // MergeableAsIs is true when "Approve & merge as-is" is an honest + // alternative: the ladder said mergeable-as-is, or (no ladder) the head + // is green, conflict-free and signed off. When false the merge-now + // alternative is left out so the dialog cannot contradict itself. + MergeableAsIs bool `json:"mergeable_as_is"` // Alternatives are the other buttons, in the popover's option shape; // the SPA adds Cancel itself. Alternatives []StageTrackerDecisionOption `json:"alternatives"` @@ -106,7 +119,7 @@ func (s *Server) planDelegatedDecision(ctx context.Context, repoFull string, num if err != nil { return nil, err } - plan := &delegatedDecisionPlan{Repo: repoFull, Number: number, Type: itemType} + plan := &delegatedDecisionPlan{Repo: repoFull, Number: number, Type: itemType, Title: strings.TrimSpace(in.Title)} var d delegatedecision.Decision if out, ok := s.delegatedHumanMergeOutcome(repoFull, number, itemType, "", mergerRole, in, req); ok { // The 090 shortcut: the plan is the shortcut's own answer, with @@ -135,19 +148,31 @@ func (s *Server) planDelegatedDecision(ctx context.Context, repoFull string, num } plan.Summary, plan.Consequences = delegatedPlanWording(in, d) plan.Why = delegatedPlanWhy(in, d) + plan.Ladder = d.Ladder + plan.MergeableAsIs = delegatedPlanMergeableAsIs(in, d) if plan.Alternatives == nil { plan.Alternatives = delegatedPlanAlternatives(in, d, mergerRole) } - for i := range plan.Alternatives { - if plan.Alternatives[i].Action == decisionActionMergeNow { - plan.Alternatives[i].Label = delegatedPlanAlternativeLabel + kept := plan.Alternatives[:0] + for _, alt := range plan.Alternatives { + if alt.Action == decisionActionMergeNow { + if !plan.MergeableAsIs { + continue + } + alt.Label = delegatedPlanAlternativeLabel } + kept = append(kept, alt) } + plan.Alternatives = kept return plan, nil } -// delegatedPlanWording is the summary line and the consequences for the -// decision the hive would record. +// delegatedPlanWording is the one decision sentence and the (at most +// two) "then" items for the decision the hive would record. Operator +// feedback on the preview (hivecommons/hive#15332's dialog: "this needs +// to be exceedingly simple to understand and act on"): verb first, plain +// words, no "Hive would:" prefix — the dialog's eyebrow says that once — +// and nothing a reader has to know hive's vocabulary for. func delegatedPlanWording(in delegatedecision.Input, d delegatedecision.Decision) (string, []string) { ref := "#" + strconv.Itoa(in.Number) target := 0 @@ -158,54 +183,83 @@ func delegatedPlanWording(in delegatedecision.Input, d delegatedecision.Decision } switch { case d.Verdict == delegatedecision.VerdictAdoptSupersede: - return "Hive would: re-author " + ref + " as a hive PR with the same commits and merge it; " + ref + " will be closed as superseded.", + return "Re-open " + ref + " as hive's own PR with the same commits and merge that; close " + ref + " as superseded.", []string{ - "hive opens a hive-authored copy of " + ref + " with the same commits and sign-off", - "the copy rebases, soaks and merges unattended on the adoption pass", - ref + " is closed as superseded once the copy merges; the author keeps commit attribution", + "Hive opens its copy of " + ref + ", lets it soak, and merges it.", + ref + " is closed as superseded; the author keeps the credit.", } case d.Verdict == delegatedecision.VerdictApprove: - return "Hive would: approve " + ref + " at its current head and let the merge gate merge it.", - []string{"hive records approve at the current head", "the merge sweep merges " + ref + " once CI is green and the head has soaked"} + return "Approve " + ref + " as it is and let the merge gate merge it.", + []string{"Hive approves the current commit.", ref + " merges once CI is green and it has soaked."} case d.Verdict == delegatedecision.VerdictCloseDuplicate && target > 0: - return "Hive would: close " + ref + " as a duplicate of #" + strconv.Itoa(target) + ".", []string{ref + " is closed with a comment pointing at #" + strconv.Itoa(target)} + return "Close " + ref + " as a duplicate of #" + strconv.Itoa(target) + ".", []string{ref + " is closed with a comment pointing at #" + strconv.Itoa(target) + "."} case d.Verdict == delegatedecision.VerdictCloseSuperseded && target > 0: - return "Hive would: close " + ref + " as superseded by #" + strconv.Itoa(target) + ".", []string{ref + " is closed with a comment pointing at #" + strconv.Itoa(target)} + return "Close " + ref + " as superseded by #" + strconv.Itoa(target) + ".", []string{ref + " is closed with a comment pointing at #" + strconv.Itoa(target) + "."} case d.Verdict == delegatedecision.VerdictCloseDuplicate, d.Verdict == delegatedecision.VerdictCloseSuperseded: - return "Hive would: close " + ref + ".", []string{ref + " is closed with a comment saying why"} + return "Close " + ref + ".", []string{ref + " is closed with a comment saying why."} case d.Verdict == delegatedecision.VerdictDirection: - return "Hive would: send " + ref + " back with direction: " + strings.TrimSuffix(strings.TrimSpace(d.Text), ".") + ".", - []string{"hive posts the direction on " + ref, "the author's clanker pushes a new commit; the row moves when it lands"} + return "Send " + ref + " back to its author with one instruction: " + delegatedPlanInstruction(in, d) + ".", + []string{"Hive posts that instruction on " + ref + ".", "The author pushes a fix; the row updates when it lands."} case d.Verdict == delegatedecision.VerdictRefused: - return "Hive would: refuse — " + strings.TrimSuffix(strings.TrimSpace(d.Rationale), ".") + ".", []string{"nothing changes; the item stays parked for you"} + return "Do nothing: " + delegatedPlanPlain(d.Rationale) + ".", []string{"Nothing changes; " + ref + " stays waiting for you."} case d.Verdict == delegatedecision.VerdictOwnerOnly: - return "Hive would: leave this to the owner.", []string{"hive labels it needs-owner and holds it", "only the owner can grant this"} + return "Leave this to the owner.", []string{"Hive labels " + ref + " needs-owner and holds it.", "Only the owner can grant this."} default: - text := strings.TrimSuffix(strings.TrimSpace(d.Text), ".") + text := delegatedPlanPlain(d.Text) if text == "" { text = delegatedecision.VerdictPlain(d.Verdict) } - return "Hive would: recommend only — " + text + ".", []string{"nothing is written beyond a comment; the item stays parked until you decide"} + return "Recommend only: " + text + ".", []string{"Hive posts a comment and nothing else.", ref + " waits for you to decide."} + } +} + +// delegatedPlanInstruction is the direction in the author's terms: the +// fix list from the head's facts ("make CI green, nothing else"), or the +// decision's own text when the direction is a reviewer's question. +func delegatedPlanInstruction(in delegatedecision.Input, d delegatedecision.Decision) string { + var fix []string + if in.Conflicting { + fix = append(fix, "rebase onto the base branch") + } + if in.DCOMissing { + fix = append(fix, "add the sign-off") + } + if !in.CIGreen { + fix = append(fix, "make CI green") + } + if len(fix) == 0 || strings.TrimSpace(in.Question) != "" { + if text := delegatedPlanPlain(d.Text); text != "" { + return text + } + } + if len(fix) == 0 { + return "address the review" } + return strings.Join(fix, ", ") + ", nothing else" } -// delegatedPlanWhy is the plain reason behind the plan: "author @Karibhou -// is untrusted and their clanker is offline." +// delegatedPlanWhy is the one plain reason behind the decision, kept +// short enough to read at a glance: the author's standing when that is +// what decided it, otherwise the head's blockers, otherwise the first +// clause of the rule's rationale with its issue references removed. func delegatedPlanWhy(in delegatedecision.Input, d delegatedecision.Decision) string { var parts []string - if in.Kind == delegatedecision.KindPR && !in.TrustedAuthor && !in.HiveAuthored { + if in.Kind == delegatedecision.KindPR && !in.TrustedAuthor && !in.HiveAuthored && d.Verdict != delegatedecision.VerdictDirection { who := "the author" if a := strings.TrimSpace(in.Author); a != "" { who = "author @" + a } parts = append(parts, who+" is untrusted") } - if !in.ContributorOnline { + if !in.ContributorOnline && d.Verdict != delegatedecision.VerdictDirection && in.Kind == delegatedecision.KindPR { parts = append(parts, "their clanker is offline") } why := strings.Join(parts, " and ") + if why == "" && d.Verdict == delegatedecision.VerdictDirection { + why = delegatedPlanBlockers(in) + } if why == "" { - why = strings.TrimSuffix(strings.TrimSpace(d.Rationale), ".") + why = delegatedPlanPlain(d.Rationale) } if why == "" && d.Rule != "" { why = delegatedecision.RulePlain(d.Rule) @@ -216,6 +270,52 @@ func delegatedPlanWhy(in delegatedecision.Input, d delegatedecision.Decision) st return strings.ToUpper(why[:1]) + why[1:] + "." } +// delegatedPlanBlockers names what keeps a head from merging, in plain +// words: "CI is red", "it conflicts with the base branch", "the sign-off +// is missing". +func delegatedPlanBlockers(in delegatedecision.Input) string { + var b []string + if !in.CIGreen { + b = append(b, "CI is red") + } + if in.Conflicting { + b = append(b, "it conflicts with the base branch") + } + if in.DCOMissing { + b = append(b, "the sign-off is missing") + } + return strings.Join(b, " and ") +} + +// delegatedPlanIssueRef strips the "(hivecommons/hive#NNNN)" provenance +// a rule's rationale carries for the log; the preview reads better +// without it. +var delegatedPlanIssueRef = regexp.MustCompile(`\s*\([^()]*#\d+\)`) + +// delegatedPlanPlain is a rationale or decision text reduced to its +// first clause, without issue references or a trailing full stop. +func delegatedPlanPlain(text string) string { + text = delegatedPlanIssueRef.ReplaceAllString(strings.TrimSpace(text), "") + if i := strings.Index(text, "; "); i > 0 { + text = text[:i] + } + return strings.TrimSuffix(strings.TrimSpace(text), ".") +} + +// delegatedPlanMergeableAsIs says whether "Approve & merge as-is" is an +// honest alternative: the ladder's own verdict when it ran, otherwise the +// head's facts. A preview that says the head is not mergeable must not +// offer to merge it (hivecommons/hive#15332's dialog). +func delegatedPlanMergeableAsIs(in delegatedecision.Input, d delegatedecision.Decision) bool { + if in.Kind != delegatedecision.KindPR { + return false + } + if d.Ladder != nil { + return d.Ladder.Decision == delegatedecision.RuleMergeableAsIs + } + return !in.Conflicting && in.CIGreen && !in.DCOMissing +} + // delegatedPlanAlternatives are the other buttons: approve & merge as-is // (merge-now, in-tracker, for a merger) or approve and let hive merge, // send back, close as superseded. diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_plan_test.go b/src/pkg/dashboard/api_repo_item_decide_delegated_plan_test.go index b687e32778..625f323cb9 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated_plan_test.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_plan_test.go @@ -46,7 +46,7 @@ func TestDelegatedDecisionPlanPreviewsAdoptWithoutWrites(t *testing.T) { if plan.Would != string(delegatedecision.VerdictAdoptSupersede) || plan.Writes { t.Fatalf("plan = %+v", plan) } - if plan.Summary != "Hive would: re-author #8 as a hive PR with the same commits and merge it; #8 will be closed as superseded." { + if plan.Summary != "Re-open #8 as hive's own PR with the same commits and merge that; close #8 as superseded." { t.Fatalf("summary %q", plan.Summary) } // The mock grants @someone write, so only the offline half applies here. @@ -60,8 +60,16 @@ func TestDelegatedDecisionPlanPreviewsAdoptWithoutWrites(t *testing.T) { if plan.Acting != "Adopting · opening hive copy…" || len(plan.Consequences) < 2 { t.Fatalf("acting %q consequences %v", plan.Acting, plan.Consequences) } - if len(plan.Alternatives) == 0 || plan.Alternatives[0].Action != decisionActionMergeNow || plan.Alternatives[0].Label != delegatedPlanAlternativeLabel || !plan.Alternatives[0].Enabled { - t.Fatalf("alternatives = %+v", plan.Alternatives) + // The ladder landed on contributor-offline, not mergeable-as-is, so + // the preview must not offer to merge it as it is (#15332's dialog + // said "not mergeable" and offered the merge anyway). + if plan.Ladder == nil || plan.Ladder.Decision != delegatedecision.RuleContributorOffline || plan.MergeableAsIs { + t.Fatalf("ladder=%+v mergeable_as_is=%v", plan.Ladder, plan.MergeableAsIs) + } + for _, alt := range plan.Alternatives { + if alt.Action == decisionActionMergeNow { + t.Fatalf("merge-now offered on a head the ladder ruled not mergeable: %+v", plan.Alternatives) + } } if len(mock.comments) != 0 || len(mock.edits) != 0 || len(mock.added) != 0 || len(mock.removed) != 0 || len(mock.reviews) != 0 || len(mock.merges) != 0 { t.Fatalf("a plan may not write: comments=%v edits=%v added=%v removed=%v reviews=%v merges=%v", mock.comments, mock.edits, mock.added, mock.removed, mock.reviews, mock.merges) @@ -74,7 +82,32 @@ func TestDelegatedDecisionPlanPreviewsAdoptWithoutWrites(t *testing.T) { t.Fatalf("a plan must not reach the ledger: %+v", acts) } } +} +// The mergeable-as-is rung: a green, conflict-free contributor head is +// approved as it is, and "Approve & merge as-is" is offered — greyed with +// the reason when the operator lacks merge rights. +func TestDelegatedDecisionPlanMergeableAsIsOffersMerge(t *testing.T) { + mock := &repoItemDecisionMock{prForeign: true, prLabels: []string{"stage/085-needs-decision", "needs-human"}} + srv := newDelegatedServer(t, mock) + body := `{"type":"pr","reason":"needs-decision","caption":"needs a decision"}` + w := postDelegatedPlan(t, srv, 8, "writer", body, map[string]string{"X-Hive-Role": "merger"}) + if w.Code != http.StatusOK { + t.Fatalf("code=%d body=%s", w.Code, w.Body.String()) + } + var plan delegatedDecisionPlan + if err := json.Unmarshal(w.Body.Bytes(), &plan); err != nil { + t.Fatal(err) + } + if plan.Would != string(delegatedecision.VerdictApprove) || plan.Ladder == nil || plan.Ladder.Decision != delegatedecision.RuleMergeableAsIs || !plan.MergeableAsIs { + t.Fatalf("plan = %+v ladder=%+v", plan, plan.Ladder) + } + if plan.Summary != "Approve #8 as it is and let the merge gate merge it." || strings.Contains(plan.Summary, "Hive would") { + t.Fatalf("summary %q", plan.Summary) + } + if len(plan.Alternatives) == 0 || plan.Alternatives[0].Action != decisionActionMergeNow || plan.Alternatives[0].Label != delegatedPlanAlternativeLabel || !plan.Alternatives[0].Enabled { + t.Fatalf("alternatives = %+v", plan.Alternatives) + } // Without the merger role the as-is merge is greyed with the reason. w = postDelegatedPlan(t, srv, 8, "writer", body, nil) if err := json.Unmarshal(w.Body.Bytes(), &plan); err != nil { @@ -85,6 +118,54 @@ func TestDelegatedDecisionPlanPreviewsAdoptWithoutWrites(t *testing.T) { } } +// hivecommons/hive#15332's preview, as the operator saw it: a direction +// on a red head. The sentence is verb first with no "Hive would:" prefix +// (the dialog composed it twice), the why is one short line, there are at +// most two "then" items and nothing visible uses hive's vocabulary. +func TestDelegatedPlanWordingDirectionIsOneSentence(t *testing.T) { + in := delegatedecision.Input{Kind: delegatedecision.KindPR, Number: 15332, Author: "clubanderson", OwnerAuthor: true, TrustedAuthor: true, CIGreen: false} + d := delegatedecision.Decide(in) + if d.Verdict != delegatedecision.VerdictDirection { + t.Fatalf("verdict %s rule %s", d.Verdict, d.Rule) + } + summary, next := delegatedPlanWording(in, d) + if summary != "Send #15332 back to its author with one instruction: make CI green, nothing else." { + t.Fatalf("summary %q", summary) + } + why := delegatedPlanWhy(in, d) + if why != "CI is red." { + t.Fatalf("why %q", why) + } + if n := len(strings.Fields(why)); n > 12 { + t.Fatalf("why is %d words: %q", n, why) + } + if len(next) != 2 { + t.Fatalf("then items %v", next) + } + for _, text := range append([]string{summary, why}, next...) { + for _, jargon := range []string{"Hive would", "park", "audit marker", "stage", "ladder", "/hive decision"} { + if strings.Contains(strings.ToLower(text), strings.ToLower(jargon)) { + t.Errorf("%q leaks %q", text, jargon) + } + } + } + if delegatedPlanMergeableAsIs(in, d) { + t.Fatal("a red head is not mergeable as it is") + } + // Conflicts and a missing sign-off join the one instruction. + in.Conflicting, in.DCOMissing = true, true + if s, _ := delegatedPlanWording(in, delegatedecision.Decide(in)); s != "Send #15332 back to its author with one instruction: rebase onto the base branch, add the sign-off, make CI green, nothing else." { + t.Fatalf("summary %q", s) + } + // Every verdict's then-list fits the two-item budget. + for _, v := range []delegatedecision.Verdict{delegatedecision.VerdictAdoptSupersede, delegatedecision.VerdictApprove, delegatedecision.VerdictCloseSuperseded, delegatedecision.VerdictRefused, delegatedecision.VerdictOwnerOnly, delegatedecision.VerdictRecommendOnly} { + s, n := delegatedPlanWording(in, delegatedecision.Decision{Verdict: v, Rationale: "because (hivecommons/hive#1); and more", Text: "do the thing (hivecommons/hive#2)"}) + if len(n) > 2 || strings.Contains(s, "Hive would") || strings.Contains(s, "#1)") || strings.Contains(s, "#2)") { + t.Errorf("%s: summary %q then %v", v, s, n) + } + } +} + func TestDelegatedDecisionPlanReadyForHumanMergeUsesShortcut(t *testing.T) { mock := &repoItemDecisionMock{prForeign: true, prLabels: []string{"stage/090-ready-for-human-merge", "role/newcomer"}} srv := newDelegatedServer(t, mock) @@ -97,7 +178,7 @@ func TestDelegatedDecisionPlanReadyForHumanMergeUsesShortcut(t *testing.T) { if err := json.Unmarshal(w.Body.Bytes(), &plan); err != nil { t.Fatal(err) } - if plan.Would != string(delegatedecision.VerdictRecommendOnly) || !strings.HasPrefix(plan.Summary, "Hive would: recommend only") { + if plan.Would != string(delegatedecision.VerdictRecommendOnly) || !strings.HasPrefix(plan.Summary, "Recommend only: ") { t.Fatalf("plan = %+v", plan) } if plan.Alternatives[0].Action != decisionActionMergeNow || plan.Alternatives[0].Label != delegatedPlanAlternativeLabel { diff --git a/src/pkg/dashboard/stage_tracker_row_actions_test.go b/src/pkg/dashboard/stage_tracker_row_actions_test.go index 28f51b9357..a1489304d0 100644 --- a/src/pkg/dashboard/stage_tracker_row_actions_test.go +++ b/src/pkg/dashboard/stage_tracker_row_actions_test.go @@ -810,7 +810,21 @@ func stageTrackerConfirmOptOutJS(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerAsk"), jsFunc(t, html, "stageTrackerDelegateConfirm"), jsFunc(t, html, "stageTrackerDCOCaveat"), - jsFunc(t, html, "stageTrackerDelegatePlanText"), + jsConstLine(t, html, "STAGE_TRACKER_PLAN_BUTTON_DELEGATE"), + jsConstLine(t, html, "STAGE_TRACKER_PLAN_BUTTON_MERGE"), + jsConstLine(t, html, "STAGE_TRACKER_PLAN_TITLE"), + jsConstLine(t, html, "STAGE_TRACKER_PLAN_EYEBROW"), + jsConstLine(t, html, "STAGE_TRACKER_PLAN_NEXT_MAX"), + jsConstLine(t, html, "STAGE_TRACKER_PLAN_TITLE_MAX"), + jsConstLine(t, html, "STAGE_TRACKER_PLAN_RAILS"), + jsConstLine(t, html, "STAGE_TRACKER_PLAN_MERGE_WHY"), + jsFunc(t, html, "hiveDialogEscape"), + jsFunc(t, html, "stageTrackerPlanSentence"), + jsFunc(t, html, "stageTrackerPlanTruncate"), + jsFunc(t, html, "stageTrackerDelegatePlanView"), + jsFunc(t, html, "stageTrackerDelegatePlanHtml"), + jsFunc(t, html, "stageTrackerDelegatePlanVisibleText"), + jsFunc(t, html, "stageTrackerDelegatePlanOffersMerge"), jsFunc(t, html, "stageTrackerDelegatePlanMergeable"), jsFunc(t, html, "stageTrackerDelegatePlanMergeReason"), jsFunc(t, html, "stageTrackerFetchDelegatePlan"), @@ -820,7 +834,7 @@ func stageTrackerConfirmOptOutJS(t *testing.T, html string) string { // The preview dialog is recorded like the confirms; its answer is // the "Let hive do that" button unless a test sets planAnswer. `let planAnswer = null; -function stageTrackerDelegatePlanDialog(plans, sentinel) { dialogs.push({ kind: 'plan', cfg: { title: 'Let hive decide — preview', message: (sentinel ? sentinel + '\n\n' : '') + stageTrackerDelegatePlanText(plans), plans } }); return Promise.resolve(planAnswer === null ? { chosen: 'Let hive do that · previewed ' + plans.map(p => p.would || '?').join('/') } : planAnswer); }`, +function stageTrackerDelegatePlanDialog(plans, sentinel) { const view = stageTrackerDelegatePlanView(plans, sentinel); const html = stageTrackerDelegatePlanHtml(view); dialogs.push({ kind: 'plan', cfg: { title: view.title, message: stageTrackerDelegatePlanVisibleText(html), html, view, plans } }); return Promise.resolve(planAnswer === null ? { chosen: 'Let hive do that · previewed ' + plans.map(p => p.would || '?').join('/') } : planAnswer); }`, `const store = {}; global.localStorage = { getItem: k => (k in store ? store[k] : null), setItem: (k, v) => { store[k] = String(v); }, removeItem: k => { delete store[k]; } }; global.window = { _hiveUser: 'clubanderson' }; const dialogs = []; let dialogAnswer = true; @@ -880,9 +894,10 @@ const plain = { repo: 'o/r', kind: 'pr', number: 4, url: 'u4', stage: 85, modifi const planCalls = []; global.fetch = async (url, init) => { planCalls.push(url); return { ok: true, status: 200, json: async () => ({ would: 'adopt-supersede', summary: 're-author o/r#4 as a hive PR with the same commits and merge it; o/r#4 will be closed as superseded', why: 'Author @k is untrusted and their clanker is offline.', consequences: ['o/r#4 is closed as superseded'], alternatives: [{ action: 'decide:merge-now', label: 'Approve & merge as-is', enabled: false, reason_if_disabled: 'Needs merge rights' }] }) }; }; assert.deepStrictEqual(await stageTrackerActionPayload([plain], 'decide:delegate'), { chosen: 'Let hive do that · previewed adopt-supersede' }); assert.deepStrictEqual(planCalls, ['/api/repos/o/r/items/4/decide-delegated/plan'], 'the preview is the plan route, never the decide route'); - assert.strictEqual(dialogs[0].kind, 'plan'); assert.strictEqual(dialogs[0].cfg.title, 'Let hive decide — preview'); - assert.ok(dialogs[0].cfg.message.includes('o/r#4 — Hive would: re-author o/r#4 as a hive PR') && dialogs[0].cfg.message.includes('Why: Author @k is untrusted and their clanker is offline.'), dialogs[0].cfg.message); + assert.strictEqual(dialogs[0].kind, 'plan'); assert.strictEqual(dialogs[0].cfg.title, 'Let hive decide'); + assert.ok(dialogs[0].cfg.message.includes('Hive would Re-author o/r#4 as a hive PR') && dialogs[0].cfg.message.includes('Why Author @k is untrusted and their clanker is offline.'), dialogs[0].cfg.message); assert.strictEqual(stageTrackerDelegatePlanMergeable(dialogs[0].cfg.plans), false); assert.strictEqual(stageTrackerDelegatePlanMergeReason(dialogs[0].cfg.plans), 'Needs merge rights'); + assert.ok(!dialogs[0].cfg.html.includes('ham-plan-merge'), 'no merge button when the plan does not say mergeable_as_is'); // Cancel: no payload, so runRowAction never sends the decide request. planAnswer = null; dialogs.length = 0; const cancelled = await (async () => { planAnswer = undefined; const r = await stageTrackerActionPayload([plain], 'decide:delegate'); planAnswer = null; return r; })(); @@ -1509,3 +1524,103 @@ assert.strictEqual(plainApproved.options.length, 0, 'a plain approval has no but assert.notStrictEqual(stageTrackerItemState(pr), stageTrackerItemState({ ...pr, rebase: { attempt: 1, max: 2, text: 'Rebasing · attempt 1/2' } }), 'the fixer attempt moves the row state'); `) } + +// TestStageTrackerDelegatePlanDialogIsOneDecision (operator feedback on +// hivecommons/hive#15332's "Let hive decide — preview": "yikes - this is a +// mess … this needs to be exceedingly simple to understand and act on"). +// The renderer takes one view model for PR and issue decisions alike: +// title + one subject line, ONE verb-first sentence (no doubled "Hive +// would:"), ONE short why, at most two "then" items; the sentinel +// finding, the rails and the ruled-out rungs sit under a collapsed +// Details. The visible text for the #15332 case is ≤ 60 words and free of +// hive vocabulary; "Approve & merge as-is" appears only when the plan says +// the head is mergeable as it is. +func TestStageTrackerDelegatePlanDialogIsOneDecision(t *testing.T) { + html := indexHTML(t) + for _, want := range []string{ + `.ham-plan-sentence {`, `.ham-plan-details {`, `.ham-plan-chip {`, `.ham-plan-eyebrow, .ham-plan-label {`, + `stageTrackerDelegatePlanHtml(view)`, `
Details`, + } { + if !strings.Contains(html, want) { + t.Errorf("index.html missing preview wiring %q", want) + } + } + if strings.Contains(html, "Let hive decide — preview") { + t.Error("the preview title still carries the “— preview” suffix") + } + runStageTrackerRowActionsScript(t, stageTrackerRowActionsPreamble(t, html)+stageTrackerConfirmOptOutJS(t, html)+` +const JARGON = ['hive would:', 'park', 'audit marker', 'stage', 'ladder', '/hive decision', 'recommendation']; +const words = text => text.split(/\s+/).filter(Boolean).length; +const buttons = html => (html.match(/]*>([^<]*)<\/button>/g) || []).map(b => b.replace(/<[^>]+>/g, '').replace(/&/g, '&')); +const visibleOf = html => stageTrackerDelegatePlanVisibleText(html); +const detailsOf = html => (html.match(//) || [''])[0]; + +// 1. hivecommons/hive#15332 as the operator saw it: a direction on a red +// head, sentinel-flagged, head not mergeable. +const pr15332 = { ref: 'hivecommons/hive#15332', number: 15332, type: 'pr', title: "ci: run crux's Go file-size ratchet against src/crux on hive PRs", would: 'direction', rule: 'fix-then-merge', + summary: 'Send #15332 back to its author with one instruction: make CI green, nothing else.', why: 'CI is red.', + consequences: ['Hive posts that instruction on #15332.', 'The author pushes a fix; the row updates when it lands.'], + ladder: { decision: 'return-to-contributor', reason: 'the author is connected; returned with the fix list', ruled_out: ['already-fixed: no merged PR has closed this PR\'s issue', 'mergeable-as-is: CI not green'] }, + mergeable_as_is: false, alternatives: [] }; +const sentinel = '⚠ hivecommons/hive#15332 — Sentinel flagged security-relevant changes at 7af26e9: changes 1 sensitive path(s)'; +let view = stageTrackerDelegatePlanView([pr15332], sentinel); +let html = stageTrackerDelegatePlanHtml(view); +let visible = visibleOf(html); +assert.strictEqual(view.title, 'Let hive decide'); +assert.strictEqual(view.subject, "hivecommons/hive#15332 · ci: run crux's Go file-size ratchet against…"); +assert.strictEqual((visible.match(/Hive would/g) || []).length, 1, 'the eyebrow says Hive would exactly once: ' + visible); +assert.ok(!/Hive would:\s*Hive would:/i.test(html), 'no doubled prefix'); +assert.strictEqual((visible.match(/hivecommons\/hive#15332/g) || []).length, 1, 'repo#number appears once: ' + visible); +assert.ok(visible.includes('Send #15332 back to its author with one instruction: make CI green, nothing else.'), visible); +assert.ok(visible.includes('Why CI is red.'), visible); +assert.ok(html.includes('
  1. Hive posts that instruction on #15332.
  2. The author pushes a fix; the row updates when it lands.
'), html); +assert.ok(words(visible) <= 60, 'visible text is ' + words(visible) + ' words: ' + visible); +for (const j of JARGON) assert.ok(!visible.toLowerCase().includes(j), 'visible text leaks ' + JSON.stringify(j) + ': ' + visible); +const details = detailsOf(html); +assert.ok(details.includes('Sentinel flagged security-relevant changes at 7af26e9') && details.includes('mergeable-as-is: CI not green') && details.includes('Rails: never merges'), 'finding, ruled-out rungs and rails live under Details: ' + details); +assert.ok(!visible.includes('Rails'), 'the rails are not visible by default'); +assert.ok(html.includes('⚠ Sentinel'), 'a compact chip flags the sentinel finding'); +assert.deepStrictEqual(buttons(html), ['Cancel', 'Let hive do that'], 'exactly two buttons when the head is not mergeable'); +assert.ok(html.includes('btn-danger hive-dialog-btn primary" data-initial-focus'), 'the sentinel case keeps the danger primary'); +assert.ok(html.indexOf('hive-dialog-btn cancel') < html.indexOf('hive-dialog-btn primary'), 'Cancel first, primary last'); + +// 2. A stale "Hive would:" prefix in the payload is still rendered once. +view = stageTrackerDelegatePlanView([Object.assign({}, pr15332, { summary: 'Hive would: Hive would: send #15332 back' })], ''); +assert.strictEqual(view.decisions[0].sentence, 'Send #15332 back.'); + +// 3. Mergeable as-is: the ladder's approve rung offers the merge button. +const green = { ref: 'o/r#8', number: 8, type: 'pr', title: 'fix typo', would: 'approve', rule: 'mergeable-as-is', + summary: 'Approve #8 as it is and let the merge gate merge it.', why: 'Mergeable and green.', consequences: ['Hive approves the current commit.', '#8 merges once CI is green and it has soaked.'], + ladder: { decision: 'mergeable-as-is', reason: 'mergeable and green; handed to the merge gate', ruled_out: ['already-fixed: no merged PR has closed this PR\'s issue'] }, + mergeable_as_is: true, alternatives: [{ action: 'decide:merge-now', label: 'Approve & merge as-is', enabled: true }] }; +html = stageTrackerDelegatePlanHtml(stageTrackerDelegatePlanView([green], '')); +assert.deepStrictEqual(buttons(html), ['Cancel', 'Approve & merge as-is', 'Let hive do that']); +assert.ok(!html.includes('ham-plan-chip') && html.includes('btn-primary hive-dialog-btn primary'), 'no sentinel: plain primary, no chip'); +assert.ok(!html.includes('aria-disabled'), 'enabled with merge rights'); +// …greyed with the reason without merge rights… +html = stageTrackerDelegatePlanHtml(stageTrackerDelegatePlanView([Object.assign({}, green, { alternatives: [{ action: 'decide:merge-now', enabled: false, reason_if_disabled: 'Needs merge rights' }] })], '')); +assert.ok(html.includes('ham-plan-merge" aria-disabled="true" disabled title="Needs merge rights"'), html); +// …and absent when the plan says the head is not mergeable, whatever the alternatives list. +html = stageTrackerDelegatePlanHtml(stageTrackerDelegatePlanView([Object.assign({}, green, { mergeable_as_is: false })], '')); +assert.deepStrictEqual(buttons(html), ['Cancel', 'Let hive do that']); + +// 4. An issue decision renders through the same model: no merge button, +// no ladder, the direction option is not a button. +const issue = { ref: 'o/r#42', number: 42, type: 'issue', title: 'Flaky test in CI', would: 'recommend-only', summary: 'Recommend only: close #42 as already fixed.', why: 'The question is hive\'s own policy.', consequences: ['Hive posts a comment and nothing else.', '#42 waits for you to decide.'], alternatives: [{ action: 'decide:direction', label: 'Give direction', enabled: true }] }; +view = stageTrackerDelegatePlanView([issue], ''); +html = stageTrackerDelegatePlanHtml(view); +visible = visibleOf(html); +assert.strictEqual(view.subject, 'o/r#42 · Flaky test in CI'); +assert.deepStrictEqual(buttons(html), ['Cancel', 'Let hive do that']); +assert.ok(visible.includes('Recommend only: close #42 as already fixed.') && !html.includes('ham-plan-ruled-out'), visible); +assert.ok(words(visible) <= 60, visible); + +// 5. A batch names each item on its own block, once. +html = stageTrackerDelegatePlanHtml(stageTrackerDelegatePlanView([green, Object.assign({}, green, { ref: 'o/r#9', number: 9 })], '')); +visible = visibleOf(html); +assert.strictEqual((visible.match(/o\/r#8/g) || []).length, 1, visible); +assert.ok(visible.startsWith('Let hive decide 2 items'), visible); +// Three "then" items are cut to two. +assert.strictEqual(stageTrackerDelegatePlanView([Object.assign({}, green, { consequences: ['a', 'b', 'c'] })], '').decisions[0].next.length, 2); +`) +} diff --git a/src/pkg/dashboard/static-src/css/tracker.css b/src/pkg/dashboard/static-src/css/tracker.css index 5502a79944..0645ca79f0 100644 --- a/src/pkg/dashboard/static-src/css/tracker.css +++ b/src/pkg/dashboard/static-src/css/tracker.css @@ -346,8 +346,30 @@ .ham-sub-superseded .ham-row-head { min-height: 0; } .ham-superseded-note { color: var(--muted); font-size: var(--fs-xs); } .ham-adopted-from { color: var(--muted); text-decoration: none; } - .ham-plan-body, .ham-plan-note { white-space: pre-wrap; } - .ham-plan-note { color: var(--muted); font-size: var(--fs-xs); } + /* The Let hive decide preview. One decision, readable in three seconds + (operator feedback on hivecommons/hive#15332's dialog): subject line, + eyebrow, one bold sentence, one muted why, a short "then" list; the + rest lives under a collapsed Details. */ + .ham-plan-dialog .hive-dialog-title { margin-bottom: var(--sp-2); } + .ham-plan-subject { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--sp-6); } + .ham-plan-chip { display: inline-flex; align-items: center; padding: var(--sp-1) var(--sp-4); border: var(--line-width) solid color-mix(in srgb, var(--status-error) 45%, transparent); border-radius: var(--r-pill); background: color-mix(in srgb, var(--status-error) 12%, transparent); color: var(--status-error); font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; } + .ham-plan-body { white-space: normal; font-size: var(--fs-base); color: var(--text); margin-bottom: var(--sp-5); } + .ham-plan-decision + .ham-plan-decision { margin-top: var(--sp-6); padding-top: var(--sp-5); border-top: var(--line-width) solid var(--line-subtle); } + .ham-plan-ref { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--sp-2); } + .ham-plan-eyebrow, .ham-plan-label { color: var(--text-faint); font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .04em; text-transform: uppercase; } + .ham-plan-sentence { margin: var(--sp-1) 0 var(--sp-4); font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: 1.4; color: var(--text); } + .ham-plan-why { margin: 0 0 var(--sp-4); color: var(--muted); } + .ham-plan-why .ham-plan-label { margin-right: var(--sp-2); } + .ham-plan-next { margin: var(--sp-1) 0 0; padding-left: 1.4em; color: var(--muted); } + .ham-plan-next li + li { margin-top: var(--sp-1); } + .ham-plan-details { margin-bottom: var(--sp-6); font-size: var(--fs-sm); color: var(--muted); } + .ham-plan-details > summary { cursor: pointer; color: var(--text-faint); font-size: var(--fs-sm); } + .ham-plan-details > summary:hover { color: var(--text); } + .ham-plan-details > :not(summary) { margin: var(--sp-3) 0 0; } + .ham-plan-details .ham-plan-label { margin-top: var(--sp-4); } + .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-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 d5d1ad8e78..2658cd2f7a 100644 --- a/src/pkg/dashboard/static-src/js/tracker-actions.js +++ b/src/pkg/dashboard/static-src/js/tracker-actions.js @@ -1196,23 +1196,113 @@ const sentinel = stageTrackerSentinelPreface(items); return { title: 'Let hive decide', message: (sentinel ? sentinel + '\n\n' : '') + 'Let the hive decide ' + refs + ' as the owner\'s delegate, under the owner-delegate policy? ' + STAGE_TRACKER_DELEGATE_EXPLANATION, confirmLabel: 'Let hive decide', danger: !!sentinel }; } - // Pure: the preview dialog's text from the plan route's answers — - // "Hive would: … Why: …", one block per PR. + // The "Let hive decide" preview (hivecommons/hive#15126), redesigned on + // operator feedback from hive's own spoke (the dialog for + // hivecommons/hive#15332: "yikes - this is a mess … this needs to be + // exceedingly simple to understand and act on"). Budget: title + one + // subject line; ONE decision sentence; ONE why line; at most two + // "then" items; everything else — the sentinel finding, the rails, the + // rungs ruled out — behind a single collapsed Details. Two buttons, + // [Cancel] [Let hive do that]; "Approve & merge as-is" only when the + // plan says the head is mergeable as it is. const STAGE_TRACKER_PLAN_BUTTON_DELEGATE = 'Let hive do that'; const STAGE_TRACKER_PLAN_BUTTON_MERGE = 'Approve & merge as-is'; - function stageTrackerDelegatePlanText(plans) { - return (plans || []).map(pl => { - const ref = pl.ref || ('#' + pl.number); - const lines = [ref + ' — Hive would: ' + (pl.summary || pl.would || 'decide it')]; - if (pl.why) lines.push('Why: ' + pl.why); - (pl.consequences || []).forEach(c => lines.push('• ' + c)); - return lines.join('\n'); - }).join('\n\n'); - } - // Pure: can "Approve & merge as-is" run — every plan lists merge-now as - // an enabled alternative. + const STAGE_TRACKER_PLAN_TITLE = 'Let hive decide'; + const STAGE_TRACKER_PLAN_EYEBROW = 'Hive would'; + const STAGE_TRACKER_PLAN_NEXT_MAX = 2; + const STAGE_TRACKER_PLAN_TITLE_MAX = 48; + const STAGE_TRACKER_PLAN_RAILS = 'Rails: never merges, never touches held items, never grants secrets; the sentinel label stays with a person.'; + const STAGE_TRACKER_PLAN_MERGE_WHY = 'Not mergeable as it is'; + // Pure: the decision sentence without a stale "Hive would:" prefix — + // the eyebrow says it once (the duplicated prefix of #15332's dialog). + function stageTrackerPlanSentence(pl) { + let text = String(pl.summary || pl.would || 'decide it').trim().replace(/^(hive would:\s*)+/i, ''); + if (!text) text = 'decide it'; + text = text.charAt(0).toUpperCase() + text.slice(1); + return /[.!?]$/.test(text) ? text : text + '.'; + } + function stageTrackerPlanTruncate(text, max) { + text = String(text || '').trim(); + return text.length > max ? text.slice(0, max - 1).replace(/\s+\S*$/, '') + '…' : text; + } + // Pure: one view model for every decision the preview can show — a + // PR or an issue; direction, adopt, close, approve, recommend-only. + // { title, subject, finding, decisions: [{ ref, sentence, why, next[] }], + // ruledOut[], rails, mergeable, mergeWhy, danger } + function stageTrackerDelegatePlanView(plans, sentinel) { + plans = plans || []; + // One item: "repo#N · title"; a batch names each item on its own + // block instead, so no reference is printed twice. + let subject = plans.length + ' items'; + if (plans.length === 1) { + subject = plans[0].ref || ('#' + plans[0].number); + if (plans[0].title) subject += ' · ' + stageTrackerPlanTruncate(plans[0].title, STAGE_TRACKER_PLAN_TITLE_MAX); + } + const decisions = plans.map(pl => ({ + ref: pl.ref || ('#' + pl.number), + sentence: stageTrackerPlanSentence(pl), + why: pl.why ? String(pl.why).trim() : '', + next: (pl.consequences || []).slice(0, STAGE_TRACKER_PLAN_NEXT_MAX).map(String), + })); + const ruledOut = [].concat(...plans.map(pl => (pl.ladder && pl.ladder.ruled_out) || [])); + const mergeable = stageTrackerDelegatePlanMergeable(plans); + return { + title: STAGE_TRACKER_PLAN_TITLE, + subject, + finding: sentinel || '', + decisions, + ruledOut, + rails: STAGE_TRACKER_PLAN_RAILS, + mergeable, + mergeWhy: mergeable ? '' : (stageTrackerDelegatePlanMergeReason(plans) || STAGE_TRACKER_PLAN_MERGE_WHY), + showMerge: stageTrackerDelegatePlanOffersMerge(plans), + danger: !!sentinel, + }; + } + // Pure: the dialog's inner HTML from the view model. The Details + // disclosure is the only place the finding, the rails and the ruled-out + // rungs appear; it is collapsed by default. + function stageTrackerDelegatePlanHtml(view) { + const esc = hiveDialogEscape; + const blocks = view.decisions.map(d => { + const multi = view.decisions.length > 1; + return '
' + + (multi ? '
' + esc(d.ref) + '
' : '') + + '
' + esc(STAGE_TRACKER_PLAN_EYEBROW) + '
' + + '

' + esc(d.sentence) + '

' + + (d.why ? '

Why ' + esc(d.why) + '

' : '') + + (d.next.length ? '
Then
    ' + d.next.map(n => '
  1. ' + esc(n) + '
  2. ').join('') + '
' : '') + + '
'; + }).join(''); + const details = [] + .concat(view.finding ? ['

' + esc(view.finding) + '

'] : []) + .concat(view.ruledOut.length ? ['
Why not the others
    ' + view.ruledOut.map(r => '
  • ' + esc(r) + '
  • ').join('') + '
'] : []) + .concat(['

' + esc(view.rails) + '

']); + return '
' + esc(view.title) + '
' + + '
' + esc(view.subject) + (view.finding ? ' ⚠ Sentinel' : '') + '
' + + '
' + blocks + '
' + + '
Details' + details.join('') + '
' + + '
' + + '' + + (view.showMerge ? '' : '') + + '' + + '
'; + } + // Pure: the preview's visible words — everything outside Details and + // the buttons. Kept for the three-second budget test. + function stageTrackerDelegatePlanVisibleText(html) { + return String(html).replace(//g, ' ').replace(/
[\s\S]*$/, ' ').replace(/<[^>]+>/g, ' ').replace(/&[a-z]+;/g, ' ').replace(/\s+/g, ' ').trim(); + } + // Pure: does the dialog offer "Approve & merge as-is" at all — only + // when every plan says the head is mergeable as it is (the ladder's + // mergeable-as-is rung, or green and conflict-free without a ladder). + function stageTrackerDelegatePlanOffersMerge(plans) { + return (plans || []).length > 0 && plans.every(pl => pl.mergeable_as_is === true && (pl.alternatives || []).some(a => a.action === 'decide:merge-now')); + } + // Pure: can "Approve & merge as-is" run — offered, and every plan lists + // merge-now as an enabled alternative (merge rights). function stageTrackerDelegatePlanMergeable(plans) { - return (plans || []).length > 0 && plans.every(pl => (pl.alternatives || []).some(a => a.action === 'decide:merge-now' && a.enabled !== false)); + return stageTrackerDelegatePlanOffersMerge(plans) && plans.every(pl => (pl.alternatives || []).some(a => a.action === 'decide:merge-now' && a.enabled !== false)); } function stageTrackerDelegatePlanMergeReason(plans) { for (const pl of plans || []) for (const a of pl.alternatives || []) if (a.action === 'decide:merge-now' && a.enabled === false && a.reason_if_disabled) return a.reason_if_disabled; @@ -1228,30 +1318,20 @@ return Object.assign({ ref: stageTrackerRefOf(item) }, data); } catch (e) { return { ref: stageTrackerRefOf(item), number: item.number, error: String(e && e.message || e) }; } } - // The three-button preview: resolves { chosen } for Let hive do that, - // { chosen, mergeNow: true } for Approve & merge as-is, null on Cancel. + // The preview: resolves { chosen } for Let hive do that, { chosen, + // mergeNow: true } for Approve & merge as-is, null on Cancel. function stageTrackerDelegatePlanDialog(plans, sentinel) { - const text = (sentinel ? sentinel + '\n\n' : '') + stageTrackerDelegatePlanText(plans); - const mergeable = stageTrackerDelegatePlanMergeable(plans); - const mergeWhy = mergeable ? '' : (stageTrackerDelegatePlanMergeReason(plans) || 'Needs merge rights on this repo'); + const view = stageTrackerDelegatePlanView(plans, sentinel); return new Promise(resolve => { const overlay = document.createElement('div'); overlay.className = 'hive-dialog-overlay'; hiveRememberModalOpen(overlay); - overlay.innerHTML = ``; + overlay.innerHTML = ''; document.body.appendChild(overlay); const would = plans.map(pl => pl.would || '?').filter((v, i, a) => a.indexOf(v) === i).join('/'); hiveWireDialog(overlay, resolve, null, '.primary', '.cancel', close => close({ chosen: STAGE_TRACKER_PLAN_BUTTON_DELEGATE + ' · previewed ' + would })); const merge = overlay.querySelector('.ham-plan-merge'); - if (merge && mergeable) merge.addEventListener('click', () => { overlay.hiveDialogClose = null; overlay.remove(); resolve({ chosen: STAGE_TRACKER_PLAN_BUTTON_MERGE + ' · previewed ' + would, mergeNow: true }); }); + if (merge && view.mergeable) merge.addEventListener('click', () => { overlay.hiveDialogClose = null; overlay.remove(); resolve({ chosen: STAGE_TRACKER_PLAN_BUTTON_MERGE + ' · previewed ' + would, mergeNow: true }); }); }); } // Let hive decide → plan → preview → act. Returns the delegate payload, diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 9037adea45..87cde67573 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1669,8 +1669,30 @@ .ham-sub-superseded .ham-row-head { min-height: 0; } .ham-superseded-note { color: var(--muted); font-size: var(--fs-xs); } .ham-adopted-from { color: var(--muted); text-decoration: none; } - .ham-plan-body, .ham-plan-note { white-space: pre-wrap; } - .ham-plan-note { color: var(--muted); font-size: var(--fs-xs); } + /* The Let hive decide preview. One decision, readable in three seconds + (operator feedback on hivecommons/hive#15332's dialog): subject line, + eyebrow, one bold sentence, one muted why, a short "then" list; the + rest lives under a collapsed Details. */ + .ham-plan-dialog .hive-dialog-title { margin-bottom: var(--sp-2); } + .ham-plan-subject { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--sp-6); } + .ham-plan-chip { display: inline-flex; align-items: center; padding: var(--sp-1) var(--sp-4); border: var(--line-width) solid color-mix(in srgb, var(--status-error) 45%, transparent); border-radius: var(--r-pill); background: color-mix(in srgb, var(--status-error) 12%, transparent); color: var(--status-error); font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; } + .ham-plan-body { white-space: normal; font-size: var(--fs-base); color: var(--text); margin-bottom: var(--sp-5); } + .ham-plan-decision + .ham-plan-decision { margin-top: var(--sp-6); padding-top: var(--sp-5); border-top: var(--line-width) solid var(--line-subtle); } + .ham-plan-ref { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--sp-2); } + .ham-plan-eyebrow, .ham-plan-label { color: var(--text-faint); font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .04em; text-transform: uppercase; } + .ham-plan-sentence { margin: var(--sp-1) 0 var(--sp-4); font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: 1.4; color: var(--text); } + .ham-plan-why { margin: 0 0 var(--sp-4); color: var(--muted); } + .ham-plan-why .ham-plan-label { margin-right: var(--sp-2); } + .ham-plan-next { margin: var(--sp-1) 0 0; padding-left: 1.4em; color: var(--muted); } + .ham-plan-next li + li { margin-top: var(--sp-1); } + .ham-plan-details { margin-bottom: var(--sp-6); font-size: var(--fs-sm); color: var(--muted); } + .ham-plan-details > summary { cursor: pointer; color: var(--text-faint); font-size: var(--fs-sm); } + .ham-plan-details > summary:hover { color: var(--text); } + .ham-plan-details > :not(summary) { margin: var(--sp-3) 0 0; } + .ham-plan-details .ham-plan-label { margin-top: var(--sp-4); } + .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-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; } @@ -18997,23 +19019,113 @@

All labels

const sentinel = stageTrackerSentinelPreface(items); return { title: 'Let hive decide', message: (sentinel ? sentinel + '\n\n' : '') + 'Let the hive decide ' + refs + ' as the owner\'s delegate, under the owner-delegate policy? ' + STAGE_TRACKER_DELEGATE_EXPLANATION, confirmLabel: 'Let hive decide', danger: !!sentinel }; } - // Pure: the preview dialog's text from the plan route's answers — - // "Hive would: … Why: …", one block per PR. + // The "Let hive decide" preview (hivecommons/hive#15126), redesigned on + // operator feedback from hive's own spoke (the dialog for + // hivecommons/hive#15332: "yikes - this is a mess … this needs to be + // exceedingly simple to understand and act on"). Budget: title + one + // subject line; ONE decision sentence; ONE why line; at most two + // "then" items; everything else — the sentinel finding, the rails, the + // rungs ruled out — behind a single collapsed Details. Two buttons, + // [Cancel] [Let hive do that]; "Approve & merge as-is" only when the + // plan says the head is mergeable as it is. const STAGE_TRACKER_PLAN_BUTTON_DELEGATE = 'Let hive do that'; const STAGE_TRACKER_PLAN_BUTTON_MERGE = 'Approve & merge as-is'; - function stageTrackerDelegatePlanText(plans) { - return (plans || []).map(pl => { - const ref = pl.ref || ('#' + pl.number); - const lines = [ref + ' — Hive would: ' + (pl.summary || pl.would || 'decide it')]; - if (pl.why) lines.push('Why: ' + pl.why); - (pl.consequences || []).forEach(c => lines.push('• ' + c)); - return lines.join('\n'); - }).join('\n\n'); - } - // Pure: can "Approve & merge as-is" run — every plan lists merge-now as - // an enabled alternative. + const STAGE_TRACKER_PLAN_TITLE = 'Let hive decide'; + const STAGE_TRACKER_PLAN_EYEBROW = 'Hive would'; + const STAGE_TRACKER_PLAN_NEXT_MAX = 2; + const STAGE_TRACKER_PLAN_TITLE_MAX = 48; + const STAGE_TRACKER_PLAN_RAILS = 'Rails: never merges, never touches held items, never grants secrets; the sentinel label stays with a person.'; + const STAGE_TRACKER_PLAN_MERGE_WHY = 'Not mergeable as it is'; + // Pure: the decision sentence without a stale "Hive would:" prefix — + // the eyebrow says it once (the duplicated prefix of #15332's dialog). + function stageTrackerPlanSentence(pl) { + let text = String(pl.summary || pl.would || 'decide it').trim().replace(/^(hive would:\s*)+/i, ''); + if (!text) text = 'decide it'; + text = text.charAt(0).toUpperCase() + text.slice(1); + return /[.!?]$/.test(text) ? text : text + '.'; + } + function stageTrackerPlanTruncate(text, max) { + text = String(text || '').trim(); + return text.length > max ? text.slice(0, max - 1).replace(/\s+\S*$/, '') + '…' : text; + } + // Pure: one view model for every decision the preview can show — a + // PR or an issue; direction, adopt, close, approve, recommend-only. + // { title, subject, finding, decisions: [{ ref, sentence, why, next[] }], + // ruledOut[], rails, mergeable, mergeWhy, danger } + function stageTrackerDelegatePlanView(plans, sentinel) { + plans = plans || []; + // One item: "repo#N · title"; a batch names each item on its own + // block instead, so no reference is printed twice. + let subject = plans.length + ' items'; + if (plans.length === 1) { + subject = plans[0].ref || ('#' + plans[0].number); + if (plans[0].title) subject += ' · ' + stageTrackerPlanTruncate(plans[0].title, STAGE_TRACKER_PLAN_TITLE_MAX); + } + const decisions = plans.map(pl => ({ + ref: pl.ref || ('#' + pl.number), + sentence: stageTrackerPlanSentence(pl), + why: pl.why ? String(pl.why).trim() : '', + next: (pl.consequences || []).slice(0, STAGE_TRACKER_PLAN_NEXT_MAX).map(String), + })); + const ruledOut = [].concat(...plans.map(pl => (pl.ladder && pl.ladder.ruled_out) || [])); + const mergeable = stageTrackerDelegatePlanMergeable(plans); + return { + title: STAGE_TRACKER_PLAN_TITLE, + subject, + finding: sentinel || '', + decisions, + ruledOut, + rails: STAGE_TRACKER_PLAN_RAILS, + mergeable, + mergeWhy: mergeable ? '' : (stageTrackerDelegatePlanMergeReason(plans) || STAGE_TRACKER_PLAN_MERGE_WHY), + showMerge: stageTrackerDelegatePlanOffersMerge(plans), + danger: !!sentinel, + }; + } + // Pure: the dialog's inner HTML from the view model. The Details + // disclosure is the only place the finding, the rails and the ruled-out + // rungs appear; it is collapsed by default. + function stageTrackerDelegatePlanHtml(view) { + const esc = hiveDialogEscape; + const blocks = view.decisions.map(d => { + const multi = view.decisions.length > 1; + return '
' + + (multi ? '
' + esc(d.ref) + '
' : '') + + '
' + esc(STAGE_TRACKER_PLAN_EYEBROW) + '
' + + '

' + esc(d.sentence) + '

' + + (d.why ? '

Why ' + esc(d.why) + '

' : '') + + (d.next.length ? '
Then
    ' + d.next.map(n => '
  1. ' + esc(n) + '
  2. ').join('') + '
' : '') + + '
'; + }).join(''); + const details = [] + .concat(view.finding ? ['

' + esc(view.finding) + '

'] : []) + .concat(view.ruledOut.length ? ['
Why not the others
    ' + view.ruledOut.map(r => '
  • ' + esc(r) + '
  • ').join('') + '
'] : []) + .concat(['

' + esc(view.rails) + '

']); + return '
' + esc(view.title) + '
' + + '
' + esc(view.subject) + (view.finding ? ' ⚠ Sentinel' : '') + '
' + + '
' + blocks + '
' + + '
Details' + details.join('') + '
' + + '
' + + '' + + (view.showMerge ? '' : '') + + '' + + '
'; + } + // Pure: the preview's visible words — everything outside Details and + // the buttons. Kept for the three-second budget test. + function stageTrackerDelegatePlanVisibleText(html) { + return String(html).replace(//g, ' ').replace(/
[\s\S]*$/, ' ').replace(/<[^>]+>/g, ' ').replace(/&[a-z]+;/g, ' ').replace(/\s+/g, ' ').trim(); + } + // Pure: does the dialog offer "Approve & merge as-is" at all — only + // when every plan says the head is mergeable as it is (the ladder's + // mergeable-as-is rung, or green and conflict-free without a ladder). + function stageTrackerDelegatePlanOffersMerge(plans) { + return (plans || []).length > 0 && plans.every(pl => pl.mergeable_as_is === true && (pl.alternatives || []).some(a => a.action === 'decide:merge-now')); + } + // Pure: can "Approve & merge as-is" run — offered, and every plan lists + // merge-now as an enabled alternative (merge rights). function stageTrackerDelegatePlanMergeable(plans) { - return (plans || []).length > 0 && plans.every(pl => (pl.alternatives || []).some(a => a.action === 'decide:merge-now' && a.enabled !== false)); + return stageTrackerDelegatePlanOffersMerge(plans) && plans.every(pl => (pl.alternatives || []).some(a => a.action === 'decide:merge-now' && a.enabled !== false)); } function stageTrackerDelegatePlanMergeReason(plans) { for (const pl of plans || []) for (const a of pl.alternatives || []) if (a.action === 'decide:merge-now' && a.enabled === false && a.reason_if_disabled) return a.reason_if_disabled; @@ -19029,30 +19141,20 @@

All labels

return Object.assign({ ref: stageTrackerRefOf(item) }, data); } catch (e) { return { ref: stageTrackerRefOf(item), number: item.number, error: String(e && e.message || e) }; } } - // The three-button preview: resolves { chosen } for Let hive do that, - // { chosen, mergeNow: true } for Approve & merge as-is, null on Cancel. + // The preview: resolves { chosen } for Let hive do that, { chosen, + // mergeNow: true } for Approve & merge as-is, null on Cancel. function stageTrackerDelegatePlanDialog(plans, sentinel) { - const text = (sentinel ? sentinel + '\n\n' : '') + stageTrackerDelegatePlanText(plans); - const mergeable = stageTrackerDelegatePlanMergeable(plans); - const mergeWhy = mergeable ? '' : (stageTrackerDelegatePlanMergeReason(plans) || 'Needs merge rights on this repo'); + const view = stageTrackerDelegatePlanView(plans, sentinel); return new Promise(resolve => { const overlay = document.createElement('div'); overlay.className = 'hive-dialog-overlay'; hiveRememberModalOpen(overlay); - overlay.innerHTML = ``; + overlay.innerHTML = ''; document.body.appendChild(overlay); const would = plans.map(pl => pl.would || '?').filter((v, i, a) => a.indexOf(v) === i).join('/'); hiveWireDialog(overlay, resolve, null, '.primary', '.cancel', close => close({ chosen: STAGE_TRACKER_PLAN_BUTTON_DELEGATE + ' · previewed ' + would })); const merge = overlay.querySelector('.ham-plan-merge'); - if (merge && mergeable) merge.addEventListener('click', () => { overlay.hiveDialogClose = null; overlay.remove(); resolve({ chosen: STAGE_TRACKER_PLAN_BUTTON_MERGE + ' · previewed ' + would, mergeNow: true }); }); + if (merge && view.mergeable) merge.addEventListener('click', () => { overlay.hiveDialogClose = null; overlay.remove(); resolve({ chosen: STAGE_TRACKER_PLAN_BUTTON_MERGE + ' · previewed ' + would, mergeNow: true }); }); }); } // Let hive decide → plan → preview → act. Returns the delegate payload, From 499bb51f974e6b6b86fd8d56d3acd16c055ddaa7 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Thu, 29 Oct 2026 11:17:58 -0400 Subject: [PATCH 2/2] dashboard: keep the preview CSS comment free of hex-like refs TestStageTrackerCuesWiring scans the tracker CSS block for raw colours; '#15332' in a comment tripped its '#1' probe. Signed-off-by: Andrew Anderson --- src/pkg/dashboard/static-src/css/tracker.css | 2 +- src/pkg/dashboard/static/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkg/dashboard/static-src/css/tracker.css b/src/pkg/dashboard/static-src/css/tracker.css index 0645ca79f0..ac5e85cf0a 100644 --- a/src/pkg/dashboard/static-src/css/tracker.css +++ b/src/pkg/dashboard/static-src/css/tracker.css @@ -347,7 +347,7 @@ .ham-superseded-note { color: var(--muted); font-size: var(--fs-xs); } .ham-adopted-from { color: var(--muted); text-decoration: none; } /* The Let hive decide preview. One decision, readable in three seconds - (operator feedback on hivecommons/hive#15332's dialog): subject line, + (operator feedback on the dialog, issue 15397): subject line, eyebrow, one bold sentence, one muted why, a short "then" list; the rest lives under a collapsed Details. */ .ham-plan-dialog .hive-dialog-title { margin-bottom: var(--sp-2); } diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 87cde67573..3eae2157b3 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1670,7 +1670,7 @@ .ham-superseded-note { color: var(--muted); font-size: var(--fs-xs); } .ham-adopted-from { color: var(--muted); text-decoration: none; } /* The Let hive decide preview. One decision, readable in three seconds - (operator feedback on hivecommons/hive#15332's dialog): subject line, + (operator feedback on the dialog, issue 15397): subject line, eyebrow, one bold sentence, one muted why, a short "then" list; the rest lives under a collapsed Details. */ .ham-plan-dialog .hive-dialog-title { margin-bottom: var(--sp-2); }