diff --git a/changelog.d/changed-15771.md b/changelog.d/changed-15771.md new file mode 100644 index 0000000000..cd72f2a7f3 --- /dev/null +++ b/changelog.d/changed-15771.md @@ -0,0 +1 @@ +- refactor: split tracker row source (#15771) diff --git a/src/pkg/dashboard/static-src/js/tracker-row-acted.js b/src/pkg/dashboard/static-src/js/tracker-row-acted.js new file mode 100644 index 0000000000..8552166546 --- /dev/null +++ b/src/pkg/dashboard/static-src/js/tracker-row-acted.js @@ -0,0 +1,184 @@ + const STAGE_TRACKER_ACTED_STATES = ['waiting', 'addressed', 'stuck', 'pending', 'failed', 'executing', 'blocked']; + const STAGE_TRACKER_ACTED_FILTERS = ['any', 'awaiting', 'acted', 'stuck']; + const STAGE_TRACKER_ACTED_STUCK_DEFAULT_S = 30 * 60; + // Every state wears the same history mark (the clock-and-arrow the + // column header uses): the badge is an audit affordance, never a "done" + // tick. Colour and border carry the state; the aria-label says it in words. + const STAGE_TRACKER_HISTORY_ICON = ''; + const STAGE_TRACKER_ACTED_GLYPH = { waiting: STAGE_TRACKER_HISTORY_ICON, addressed: STAGE_TRACKER_HISTORY_ICON, stuck: STAGE_TRACKER_HISTORY_ICON, pending: STAGE_TRACKER_HISTORY_ICON, failed: STAGE_TRACKER_HISTORY_ICON, executing: STAGE_TRACKER_HISTORY_ICON, blocked: STAGE_TRACKER_HISTORY_ICON }; + function stageTrackerActedLabel(action) { return STAGE_TRACKER_ACTED_LABELS[action] || String(action || '').replace(/-/g, ' '); } + // Pure: the record a row's badge reads — the item's own, else (an issue + // row drawn over its single covering PR) that PR's; null when none. + function stageTrackerActedSource(item) { + if (!item) return null; + // A failure this client just saw outranks an older server record + // (hivecommons/hive#15436): the badge goes red at once. + const failed = typeof stageTrackerActionFailureOf === 'function' ? stageTrackerActionFailureOf(item) : null; + if (failed) return { item, action: failed, count: (Number(item.operator_action_count) || 0) + 1 }; + if (item.last_operator_action) return { item, action: item.last_operator_action, count: Number(item.operator_action_count) || 1 }; + const linked = Array.isArray(item.linked_prs) ? item.linked_prs : []; + if (item.kind === 'issue' && linked.length === 1 && linked[0].last_operator_action) { + return { item: { repo: item.repo, number: linked[0].number, kind: 'pr', stage: linked[0].stage || 0, modifiers: linked[0].modifiers || [], reason: linked[0].reason || '', caption: linked[0].caption || '', decision_needed: linked[0].decision_needed || null, decided: linked[0].decided || null }, action: linked[0].last_operator_action, count: Number(linked[0].operator_action_count) || 1 }; + } + return null; + } + // Pure: the badge state as of nowMs. The server judges `stuck` when it + // builds the payload; a row still `waiting` ages into `stuck` here once + // the window passes, so the badge turns amber between refreshes too. + function stageTrackerActedState(action, nowMs) { + if (!action) return ''; + let state = STAGE_TRACKER_ACTED_STATES.indexOf(action.state) >= 0 ? action.state : 'waiting'; + if (state === 'waiting') { + const at = Date.parse(action.at || ''); + const windowMs = (Number(action.stuck_after_seconds) || STAGE_TRACKER_ACTED_STUCK_DEFAULT_S) * 1000; + if (at && (Number(nowMs) || Date.now()) - at >= windowMs) state = 'stuck'; + } + return state; + } + // Pure: minutes/hours/days in words for the badge tooltip. + function stageTrackerActedAgo(ms) { + const min = Math.max(0, Math.floor((Number(ms) || 0) / 60000)); + if (min < 1) return 'just now'; + if (min < 60) return min + ' min ago'; + const h = Math.floor(min / 60); + if (h < 48) return h + ' h ago'; + return Math.floor(h / 24) + ' d ago'; + } + function stageTrackerActedOutcomeWords(action) { + switch (action.outcome) { + case 'applied': return 'done' + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); + case 'no-op': return 'nothing changed' + (action.detail ? ': ' + stageTrackerActedPlain(action.detail) : ''); + case 'failed': return 'failed' + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); + case 'pending': return action.action === 'merge-now' ? 'rebasing, then merging…' : (action.action === 'queue-merge' ? 'approved — hive will merge on the next tick once CI is green' : 'the hive is deciding…'); + case 'executing': return (action.detail ? stageTrackerActedPlain(action.detail) : 'decided — the hive is carrying it out…'); + case 'no-effect': return "hasn't taken effect" + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); + case 'blocked': return 'blocked' + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); + case 'superseded-by-state-change': return 'the item moved on by itself'; + } + return action.outcome || ''; + } + // Pure: the stage in plain words, never a code ("Merge gate", not 085). + function stageTrackerActedStageName(n) { + const num = Number(n) || 0; + const st = ((_stageTracker && _stageTracker.stages) || []).find(s => Number(s.number) === num); + return st && (st.short || st.label) ? (st.short || st.label) : (num ? 'stage ' + num : 'an unknown stage'); + } + // Pure: operator-facing gloss for the slugs the hive writes into stage + // reasons and endpoint status words. Unknown input is returned with its + // dashes and colons spelled as words so nothing reads like a code. + const STAGE_TRACKER_ACTED_PLAIN = { + 'contributor-lane:changes-requested': 'a reviewer requested changes; needs a new commit', + 'contributor-lane:approved': 'a reviewer approved it', + 'contributor-lane:ci-failed': 'CI failed on the latest commit', + 'needs-rebase': 'needs a rebase onto the base branch', + 'needs-human': 'waiting on a person', + 'needs-decision': 'waiting on your decision', + unparked: 'released to the hive', + 'approval-commented': 'your approval was posted as a comment', + closed: 'closed on GitHub', + held: 'put on hold', + released: 'hold released', + 'already accepted': 'it was already accepted', + 'approval-recorded': 'recorded your approval', 'rebase-kicked': 'started the rebase', rebased: 'rebased it onto the base branch', 'ci-green': 'saw CI go green', merged: 'merged it', + 'rebase-conflict': 'the rebase conflicts', 'ci-red': 'CI went red on the rebased head', 'rebase-timeout': 'the rebase did not land in time', 'head-not-pushable': 'the hive cannot push to this fork', 'foreign-head': 'the head moved after your approval, pushed by someone other than the hive', + }; + function stageTrackerActedPlain(text) { + const t = String(text || '').trim(); + if (!t) return ''; + if (STAGE_TRACKER_ACTED_PLAIN[t]) return STAGE_TRACKER_ACTED_PLAIN[t]; + if (/^hive decided: /.test(t)) return t.replace(/^hive decided: /, 'the hive decided: ').replace(/ \(([^)]+)\)/, (m, r) => ' (rule: ' + r.replace(/[-_:]/g, ' ') + ')'); + if (/^decided: /.test(t)) return t.replace(/^decided: /, 'the hive decided: ').replace(/ \(([^)]+)\)/, (m, r) => ' (rule: ' + r.replace(/[-_:]/g, ' ') + ')'); + if (/^[a-z0-9]+([-_:][a-z0-9]+)+$/.test(t)) return t.replace(/[-_:]/g, ' '); + // Slugs inside a sentence ("… — contributor-lane:changes-requested blocks it"). + return t.replace(/\b[a-z0-9]+(?:[-_:][a-z0-9]+)+\b/g, m => STAGE_TRACKER_ACTED_PLAIN[m] || (/[a-z]/.test(m) ? m.replace(/[-_:]/g, ' ') : m)); + } + // Row-menu action id each ledger action was submitted under, so the + // option the owner just took is not offered back to them. + const STAGE_TRACKER_ACTED_OPTION_ID = { 'let-hive-decide': 'decide:delegate', approve: 'decide:approve', 'give-direction': 'decide:direction', 'close-superseded': 'decide:close-superseded', wontfix: 'decide:close-wontfix', 'close-read': 'decide:close-read', 'accept-triage': 'accept-triage', hold: 'hold', 'merge-now': 'decide:merge-now', 'queue-merge': 'decide:queue-merge', 're-author': 'decide:re-author', adopt: 'decide:adopt', 'adopt-now': 'decide:adopt-now', reroute: 'decide:reroute' }; + // Pure: what the owner can still do when their action changed nothing + // (no-op) or the item has not moved (stuck): the enabled options from + // the row's decision_needed payload, minus the one just taken. + function stageTrackerActedOptions(item, action, state) { + if (!(action.outcome === 'no-op' || state === 'stuck' || state === 'failed' || state === 'blocked')) return ''; + const dn = item && item.decision_needed; + const opts = dn && Array.isArray(dn.options) ? dn.options : []; + const taken = STAGE_TRACKER_ACTED_OPTION_ID[action.action] || ''; + return opts.filter(o => o && o.enabled && o.action !== taken && o.label).map(o => o.label).join(' · '); + } + // Pure: the tooltip — the decision trail in plain words, in the order + // every cue on the row uses: what it is waiting on → what you chose → + // what the hive did next (who, when). ≤ 2 short lines per fact. + function stageTrackerActedTip(item, nowMs) { + const src = stageTrackerActedSource(item); + if (!src) return ''; + const a = src.action; + nowMs = Number(nowMs) || Date.now(); + const state = stageTrackerActedState(a, nowMs); + const atMs = Date.parse(a.at || '') || nowMs; + const me = !a.actor || (window._hiveUser && a.actor.toLowerCase() === String(window._hiveUser).toLowerCase()); + const who = me ? 'You' : '@' + a.actor; + const label = stageTrackerActedLabel(a.action) + (a.target ? ' ' + a.target : ''); + const ago = stageTrackerActedAgo(nowMs - atMs); + const stageNow = stageTrackerActedStageName(src.item.stage); + const waitingOn = stageTrackerActedPlain(src.item.caption || src.item.reason); + const lines = []; + const dec = src.item.decided || (item && item.decided); + if (dec && typeof stageTrackerDecidedLead === 'function') lines.push(stageTrackerDecidedLead(dec, a, nowMs)); + else if (state === 'addressed') lines.push('Addressed — now at ' + stageNow + '.'); + else if (state === 'stuck') lines.push('Still at ' + stageNow + ' ' + ago.replace(/ ago$/, '') + ' after you asked' + (waitingOn ? ' — hive says: ' + waitingOn : '') + '.'); + else if (state === 'pending') lines.push('At ' + stageNow + ' while the hive decides.'); + else if (state === 'failed') lines.push('Still at ' + stageNow + (a.progress ? ' — ' + stageTrackerActedPlain(a.progress) : ' — try again, or act on GitHub') + '.'); + else if (state === 'executing') lines.push('At ' + stageNow + ' — the hive is carrying it out' + (a.progress ? ': ' + stageTrackerActedPlain(a.progress) : '') + '.'); + else if (state === 'blocked') lines.push('Blocked at ' + stageNow + (a.progress ? ' — ' + stageTrackerActedPlain(a.progress) : ' — the hive lacks a permission it needs') + '.'); + else lines.push('At ' + stageNow + (waitingOn ? ' — ' + waitingOn : '') + '.'); + lines.push(who + ' chose ' + label + ' · ' + agentNowClockTime(atMs, nowMs) + ' (' + ago + ') · ' + stageTrackerActedOutcomeWords(a) + '.'); + if (a.progress && state !== 'executing' && state !== 'blocked' && state !== 'failed') lines.push('Hive now: ' + stageTrackerActedPlain(a.progress) + '.'); + if (a.human) lines.push('You can: ' + a.human); + else if (state === 'executing') lines.push('Nothing for you to do — the badge updates when the adoption lands.'); + if (a.note) lines.push('Your note: ' + a.note); + const options = stageTrackerActedOptions(src.item, a, state); + if (options) lines.push('Options: ' + options + '.'); + const followed = Array.isArray(a.followed) ? a.followed : []; + followed.slice(-3).forEach(h => { + const hopMs = Date.parse(h.at || '') || nowMs; + if (!(Number(h.number) > 0) && h.slug) lines.push('Then the hive ' + stageTrackerActedPlain(h.slug) + (h.reason ? ' — ' + h.reason : '') + ' · ' + stageTrackerActedAgo(nowMs - hopMs) + '.'); + else lines.push('Then the hive ' + (h.regressed ? 'sent it back to ' : 'moved it to ') + stageTrackerActedStageName(h.number) + (h.reason ? ' — ' + stageTrackerActedPlain(h.reason) : '') + ' · ' + stageTrackerActedAgo(nowMs - hopMs) + '.'); + }); + if (src.count > 1) lines.push((src.count - 1) + ' earlier action' + (src.count > 2 ? 's' : '') + ' on this item.'); + return lines.join('\n'); + } + // Pure: the badge HTML ('' when the row has no recorded action). An + // in-app tooltip (the shared .config-info portal: hover or focus), + // never a native title. + function stageTrackerActedBadgeHtml(item, nowMs) { + const src = stageTrackerActedSource(item); + if (!src) return ''; + // While this client is still waiting on its own decision the pill's + // "Hive deciding…" caption is the one cue (#15126); a server-side + // pending action still wears the dotted history badge (#15200). + if (typeof stageTrackerRowDeciding === 'function' && (stageTrackerRowDeciding(stageTrackerItemKey(src.item)) || stageTrackerRowDeciding(stageTrackerItemKey(item)))) return ''; + let state = stageTrackerActedState(src.action, nowMs); + const dec = src.item.decided || item.decided; + if (dec) state = dec.effect === 'timed-out' ? 'stuck' : (dec.effect === 'landed' ? 'addressed' : 'waiting'); + const id = 'ham-acted-tip-' + String((src.item.repo || '') + '-' + (Number(src.item.number) || 0)).replace(/[^A-Za-z0-9_-]/g, '-'); + const tip = stageTrackerActedTip(item, nowMs); + const short = dec ? (dec.word || stageTrackerActedLabel(src.action.action)) + ' — ' + (dec.verdict || '') : stageTrackerActedLabel(src.action.action); + const n = Math.max(1, Number(src.count) || 1); + const label = 'History: ' + n + ' action' + (n === 1 ? '' : 's') + ' — ' + short + ' — ' + state; + return `${STAGE_TRACKER_ACTED_GLYPH[state] || STAGE_TRACKER_HISTORY_ICON}${esc(tip).replace(/\n/g, '
')}
`; + } + // Pure: the Decisions filter. awaiting = parked on a person with no + // action recorded yet (or the last one failed / was overtaken without + // moving it); acted = any action recorded; stuck = acted and still at + // the same stage past the window. + function stageTrackerActedMatches(item, mode, nowMs) { + if (!mode || mode === 'any') return true; + const src = stageTrackerActedSource(item); + const state = src ? stageTrackerActedState(src.action, nowMs) : ''; + switch (mode) { + case 'acted': return !!src; + case 'stuck': return state === 'stuck'; + case 'awaiting': return !!stageTrackerDecisionTarget(item) && (!src || state === 'failed'); + } + return true; + } diff --git a/src/pkg/dashboard/static-src/js/tracker-row-layout.js b/src/pkg/dashboard/static-src/js/tracker-row-layout.js new file mode 100644 index 0000000000..2942d75c6c --- /dev/null +++ b/src/pkg/dashboard/static-src/js/tracker-row-layout.js @@ -0,0 +1,556 @@ + + // Ghost strip for a title line: the lead cell (Open..Claimed) carries + // the item's own number + title, the PR cell (PR in progress..Merge gate) + // the given refs, and the cap cell the modifier chip, bottom-aligned so + // it sits on the last title line, directly over the strip's right end. + // The since column is an empty spacer here (same width as the strip + // row's, which carries the time on step): a wrapped title must not float + // the age away from the chevrons it describes. + function stageTrackerHeadColsHtml(prRefs, leadHtml, chipsHtml) { + const wide = !(prRefs && prRefs.length); + return `
  1. ${leadHtml || ''}
  2. ${wide ? '' : `
  3. ${prRefs.join('')}
  4. `}
  5. ${chipsHtml || ''}
`; + } + + function stageTrackerSinceHtml(item, nowMs) { + const mods = Array.isArray(item.modifiers) ? item.modifiers : []; + let sinceMs = Date.parse(item.stage_since || ''); + // A blocked row without stage_since still shows its age, from created_at. + if (!sinceMs && mods.indexOf('blocked') >= 0) sinceMs = stageTrackerOpenSince(item).ms; + const stalled = mods.indexOf('stalled') >= 0; + return `${esc(sinceMs ? stageTrackerShortAgo(nowMs - sinceMs) : '')}`; + } + + const STAGE_TRACKER_LINKED_TIP = "linked PR, shown on its issue's row"; + // Issue numbers that list each covering PR, by "repo#pr", for the PRs + // listed by more than one open issue (so a row can say "also under #N"). + function stageTrackerSharedPRs(items) { + const by = {}; + (items || []).forEach(it => { + if (!it || it.kind !== 'issue') return; + (Array.isArray(it.linked_prs) ? it.linked_prs : []).forEach(lp => { + const k = (it.repo || '') + '#' + (Number(lp.number) || 0); + (by[k] = by[k] || []).push(Number(it.number) || 0); + }); + }); + const out = {}; + Object.keys(by).forEach(k => { if (by[k].length > 1) out[k] = by[k].slice().sort((a, b) => a - b); }); + return out; + } + // Hover text for a PR drawn on its issue's row (it rides the PR link: + // the row's hover budget allows no other titled element). Every row but + // the lowest-numbered issue listing the PR also names where else it shows. + function stageTrackerLinkedTip(issue, prNumber, ctx) { + const all = (ctx && ctx.sharedPRs && ctx.sharedPRs[(issue.repo || '') + '#' + (Number(prNumber) || 0)]) || []; + const others = all.filter(n => n !== Number(issue.number)); + const also = others.length && all[0] !== Number(issue.number) ? ' · also under #' + others.join(', #') : ''; + return STAGE_TRACKER_LINKED_TIP + also; + } + // "↳" ahead of such a PR, so the shared row is recognisable as the PR's + // place in the list (aria-label only; no title of its own). + const STAGE_TRACKER_LINKED_GLYPH = '↳'; + + // A covering PR nested under its issue: "[author icon] #N title" at the + // PR column, then the PR's own strip from PR in progress onwards. The + // PR's full tooltip rides its link; the sub-row container has none. + // Pure: a nested PR as a row item of its own — the object every row + // action receives (runRowAction(action, row)), so a ⋯ menu or popover + // on a sub-row acts on THAT PR: its number, repo and head, never the + // parent issue's. `parent` names the issue; `siblings` the other open + // PRs under it (the superseded-by prompt pre-fills the one sibling). + function stageTrackerLinkedPRItem(issue, lp) { + const open = Array.isArray(issue.linked_prs) ? issue.linked_prs.filter(x => x && x.number !== lp.number && stageTrackerLinkedPROpen(x, issue)) : []; + return { repo: issue.repo, number: lp.number, kind: 'pr', title: lp.title || '', url: lp.url || '', author: lp.author || '', author_kind: lp.author_kind || '', + stage: lp.stage || 0, stage_since: lp.stage_since || '', stage_slug: lp.stage_slug || '', modifiers: lp.modifiers || [], deferred_modifiers: lp.deferred_modifiers || [], caption: lp.caption || '', reason: lp.reason || '', + human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', base_ref: lp.base_ref || '', decision_needed: lp.decision_needed || null, + adoption: lp.adoption || null, takeover: lp.takeover || null, superseded: !!lp.superseded, supersedes: lp.supersedes || null, parent: Number(issue.number) || 0, siblings: open.map(x => Number(x.number) || 0), + last_operator_action: lp.last_operator_action || null, operator_action_count: lp.operator_action_count || 0, hold: lp.hold || null, stage_actor: lp.stage_actor || null, claimant: lp.claimant || null, presence: lp.presence || null, rework: lp.rework || null, push: lp.push || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, left_train: lp.left_train || null, overlap: lp.overlap || null, + decided: lp.decided || null, adopted_by: Number(lp.adopted_by) || 0, adopted_by_state: lp.adopted_by_state || '', adopted_from: lp.adopted_from || null, lineage: lp.lineage || null, state: lp.state || '', superseded_by: Number(lp.superseded_by) || 0 }; + } + // Pure: whether a linked PR is still open (not merged / closed / + // superseded). With `issue`, an adopted original whose hive copy is + // listed under the same issue counts as superseded even while GitHub + // still has it open (the write-back gate kept it at 072): the pair + // {original, copy} is one logical PR, so #15495 never reads as "2 + // PRs" needing a human to pick (hivecommons/hive#15495). + function stageTrackerLinkedPROpen(lp, issue) { + if (!lp || lp.superseded || String(lp.state || '') === 'closed' || (Number(lp.stage) || 0) >= STAGE_TRACKER_TERMINAL || (Array.isArray(lp.modifiers) ? lp.modifiers : []).indexOf('merged') >= 0) return false; + const by = Number(lp.superseded_by || lp.adopted_by) || 0; + if (by > 0 && issue && lp.adopted_by_state !== 'closed' && lp.adopted_by_state !== 'closed-twice' && lp.adopted_by_state !== 'copy-failed') { + const linked = Array.isArray(issue.linked_prs) ? issue.linked_prs : []; + if (linked.some(x => x && Number(x.number) === by && String(x.state || '') !== 'closed')) return false; + } + return true; + } + // Pure: an issue's open nested PRs as row items. + function stageTrackerNestedOpenPRs(issue) { + if (!issue || issue.kind === 'pr') return []; + return (Array.isArray(issue.linked_prs) ? issue.linked_prs : []).filter(lp => stageTrackerLinkedPROpen(lp, issue)).map(lp => stageTrackerLinkedPRItem(issue, lp)); + } + // Lineage: where an adopted PR came from (`lineage`: {kind, from_number, + // from_url, from_author, from_author_kind, to_number, to_url, at, + // reason}; optional, nothing without it). #15198 showed the hive's copy + // #15308 "Fixing" with no trace of @thatguywob's #15226 it was adopted + // from, so sending the fix to a hive agent read as a mistake. The chip + // sits beside the PR number on every PR mention (top-level row, single + // covering PR, sub-row) and links to the other PR; the author's kind is + // the icon only, never a word. + const STAGE_TRACKER_LINEAGE_REASON_TIP = { + 'ci-red-contributor-offline': "Hive took this PR over after CI went red and @AUTHOR's agent didn't respond. Original commits kept.", + 'ci-red-contributor-unregistered': "Hive took this PR over after CI went red and @AUTHOR has no agent registered here. Original commits kept.", + 'operator-asked': 'Hive took this PR over at a maintainer\'s request. Original commits kept.', + 'dco-rehome': 'Hive re-homed this PR to repair its DCO sign-off. Original commits kept.', + 'signoff-rehome': 'Hive re-homed this PR so its sign-off survives a squash. Original commits kept.', + 'rebase-rehome': 'Hive re-homed this PR onto its own branch to finish the rebase. Original commits kept.', + 'push-rehome': "Hive re-homed this PR because @AUTHOR's branch could no longer be pushed. Original commits kept.", + 'in-place-stalled': 'Hive re-homed this PR after a review finding sat unaddressed. Original commits kept.' + }; + // Pure: the chip's visible words — "adopted from @thatguywob's #15226 · 6h". + function stageTrackerLineageText(item, nowMs) { + const l = item && item.lineage; + if (!l || !l.kind) return ''; + const ago = stageTrackerAgoText(Date.parse(l.at || ''), nowMs).replace(/ ago$/, ''); + // Once the head moves the chip says so instead of the adoption's age: + // "adopted from @x's #N · pushed 2m ago" (hivecommons/hive#15784). + const pushed = typeof stageTrackerPushLineageSuffix === 'function' ? stageTrackerPushLineageSuffix(item, nowMs) : ''; + const tail = pushed || (ago ? ' · ' + ago : ''); + if (l.kind === 'superseded') return Number(l.to_number) > 0 ? 'superseded by #' + Number(l.to_number) + tail : ''; + if (!(Number(l.from_number) > 0)) return ''; + const whose = l.from_author ? '@' + l.from_author + "'s " : ''; + return (l.kind === 'rebased-by-hive' ? 'rebased by hive from ' : 'adopted from ') + whose + '#' + Number(l.from_number) + tail; + } + // Pure: the hover — why the hive took it over, in plain words. + function stageTrackerLineageTip(item) { + const l = item && item.lineage; + if (!l || !l.kind) return ''; + if (l.kind === 'superseded') return 'Hive took this PR over as #' + Number(l.to_number) + '; this original is closed when that merges.'; + const who = l.from_author ? '@' + l.from_author : 'the contributor'; + const tip = STAGE_TRACKER_LINEAGE_REASON_TIP[l.reason] || STAGE_TRACKER_LINEAGE_REASON_TIP['ci-red-contributor-offline']; + return tip.split('@AUTHOR').join(who) + stageTrackerSupersededOriginalClause(Number(l.from_number), l.from_state); + } + // Pure: the hover clause that says what became of the superseded + // original the chip stands in for — closed, or still open and closing + // when the copy merges; '' when the server does not say. + function stageTrackerSupersededOriginalClause(number, state) { + if (!(number > 0)) return ''; + if (state === 'closed') return ' #' + number + ' is closed as superseded.'; + if (state === 'open') return ' #' + number + ' is superseded and still open; it closes when this merges.'; + return ''; + } + function stageTrackerLineageChipHtml(item, nowMs) { + const text = stageTrackerLineageText(item, nowMs); + if (!text) return ''; + const l = item.lineage; + const tip = stageTrackerLineageTip(item); + const icon = l.kind !== 'superseded' && l.from_author_kind ? stageTrackerIcon(l.from_author_kind, 'ham-author-ico ham-author-' + esc(l.from_author_kind), l.from_author_kind) : ''; + const href = l.kind === 'superseded' ? l.to_url : l.from_url; + const attrs = `class="ham-badge ham-lineage" title="${esc(tip)}" aria-label="${esc(text + ' — ' + tip)}"`; + return href ? `${icon}${esc(text)}` : `${icon}${esc(text)}`; + } + // Pure: the one clause a caption or preview adds after the PR number — + // " (adopted from #15226)"; '' without lineage. An issue row reads its + // single covering PR's lineage. + function stageTrackerLineageClause(item) { + let l = item && item.lineage; + if (!l && item && item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length === 1) l = item.linked_prs[0].lineage; + if (!l || !(Number(l.from_number) > 0) || l.kind === 'superseded') return ''; + return ' (adopted from #' + Number(l.from_number) + ')'; + } + // Pure: the "↳ adopted from #N · you let hive decide 17:51" chip on the + // hive's copy of an adopted PR (hivecommons/hive#15126). + function stageTrackerAdoptedFromChipHtml(pr, nowMs) { + const af = pr && pr.adopted_from; + if (!af || !af.number) return ''; + let text = '↳ adopted from #' + af.number; + if (af.decided_at) { + const what = af.decided_action === 'let-hive-decide' ? 'you let hive decide' : 'you approved'; + text += ' · ' + what + ' ' + agentNowClockTime(Date.parse(af.decided_at), typeof nowMs === 'number' ? nowMs : Date.now()); + } + const tip = 'Hive re-authored #' + af.number + (af.author ? ' (by @' + af.author + ')' : '') + ' as this PR with the same commits and sign-off' + (af.decided_by ? '; the decision on #' + af.number + ' was ' + (af.decided_action || 'yours') + ' by @' + af.decided_by : '') + '.' + (stageTrackerSupersededOriginalClause(Number(af.number), af.state) || ' #' + af.number + ' is closed as superseded when this merges.'); + return `${esc(text)}`; + } + // Pure: the reciprocal of the "↳ #N · under #M" chip (hivecommons/ + // hive#15806) — on the PR drawn here, "also closes #A, #B" naming the + // other listed open issues it resolves, every number a link; past + // three it reads "#A, #B, #C +N" and the hover names every title. + function stageTrackerAlsoClosesChipHtml(lp) { + const list = Array.isArray(lp && lp.also_closes) ? lp.also_closes.filter(li => li && Number(li.number) > 0) : []; + if (!list.length) return ''; + const shown = list.slice(0, 3); + const links = shown.map(li => `#${Number(li.number)}`).join(', '); + const more = list.length > shown.length ? ' +' + (list.length - shown.length) : ''; + const tip = 'this PR also resolves ' + list.map(li => '#' + Number(li.number) + (li.title ? ' (' + li.title + ')' : '')).join(', '); + return `also closes ${links}${more}`; + } + // Pure: the lineage-style chips of a covering PR drawn under an issue — + // its lineage / adopted-from chip, then the also-closes chip; null = none. + function stageTrackerLinkedChipsHtml(lp, lineage) { + const also = typeof stageTrackerAlsoClosesChipHtml === 'function' ? stageTrackerAlsoClosesChipHtml(lp) : ''; + const out = [lineage || '', also].filter(Boolean).join(' '); + return out || null; + } + // The row's inline lead action (tracker-actions.js + // stageTrackerLeadActionHtml), computed against the viewer's own + // permissions on the item's repo; '' where the actions module or a + // viewer context is absent (the node harness lifts this file alone). + // subRows: the linked PRs drawn as sub-rows under an issue row — a lead + // that acts on one of them renders there, never on both rows. + function stageTrackerLeadButtonHtml(item, nowMs, subRows) { + if (typeof stageTrackerLeadActionHtml !== 'function' || typeof stageTrackerActionCtx !== 'function' || !item) return ''; + const ctx = stageTrackerActionCtx(item.repo); + if (!ctx) return ''; + ctx.nowMs = typeof nowMs === 'number' ? nowMs : Date.now(); + return stageTrackerLeadActionHtml(item, ctx, subRows); + } + // PR link, then the lineage chip (null = none), then the base pill. + function stageTrackerPRPillsHtml(ref, lineage, baseRef) { + return ref + (lineage == null ? '' : ' ' + lineage) + (baseRef ? ` ${esc(baseRef)}` : ''); + } + function stageTrackerSubRowHtml(lp, issue, stages, nowMs, ctx) { + const pr = stageTrackerLinkedPRItem(issue, lp); + const superseded = typeof stageTrackerLinkedSupersededText === 'function' ? stageTrackerLinkedSupersededText(lp, issue) : ''; + let ref = stageTrackerPRRef(pr.number, pr.url, pr.author_kind, pr.author, pr.title, (pr.title ? pr.title + ' · ' : '') + (superseded ? superseded + ' · ' + stageTrackerLinkedSupersededTip(lp) : stageTrackerTooltip(pr, nowMs)) + ' · ' + stageTrackerLinkedTip(issue, pr.number, ctx)); + // One line (hivecommons/hive: "consolidate from 3 lines of text to + // 1"): connector, repo chip, author icon + #N + title, the lineage / + // adopted-from chip, then the base pill — all siblings of the flex-row + // PR cell; the title ellipsizes, the pills never shrink. A superseded + // original wears neither pill — it closes as superseded, not as the + // closer of anything. + const lineage = superseded ? '' : ((typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(pr, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(pr, nowMs) : '')); + const chip = ctx && ctx.repoChips ? stageTrackerRepoChipHtml(pr.repo, ctx) : ''; + if (chip) ref = `${chip}${ref}`; + ref = stageTrackerPRPillsHtml(ref, !superseded && typeof stageTrackerLinkedChipsHtml === 'function' ? stageTrackerLinkedChipsHtml(lp, lineage) : (lineage || null), lp.base_ref); + ref = STAGE_TRACKER_LINKED_GLYPH + ref; + if (superseded) { + // The adopted original: one muted line, no chevron track, no row + // tools, no needs-human styling — the copy carries the chevron. The + // trailing note never wraps; the title ellipsizes first (owner, + // hivecommons/hive#15511: "superseded · hive adopted → #15574"). + return `
+
+ ${stageTrackerHeadColsHtml([ref + ` ${esc(superseded)}`], '', stageTrackerActedBadgeHtml(pr, nowMs))} +
+
`; + } + return `
+ ${typeof stageTrackerRowToolsHtml === 'function' ? stageTrackerRowToolsHtml(pr) : ''} +
+ ${stageTrackerHeadColsHtml([ref], '', stageTrackerActedBadgeHtml(pr, nowMs) + stageTrackerChipsHtml(pr) + (typeof stageTrackerLeadButtonHtml === 'function' ? stageTrackerLeadButtonHtml(pr, nowMs) : ''))} +
+
+
    ${stageTrackerStripItems(pr, stages, { from: STAGE_TRACKER_PR_COLUMN }, nowMs, ctx)}
+ ${stageTrackerSinceHtml(pr, nowMs)} +
+ ${stageTrackerCurrentStageHtml(pr, stages, { from: STAGE_TRACKER_PR_COLUMN })}${typeof stageTrackerEventHtml === 'function' ? stageTrackerEventHtml(stageTrackerItemKey(pr), ctx) : ''} +
`; + } + + // Covering PRs of an issue, furthest along first, attention-first + // within a stage (stageTrackerAttentionTier), then longest on step. + // A PR that closes several open issues is drawn once: the server names + // the issue whose row carries it (drawn_under); the other issues list it + // as a compact "under #M" chip instead of a second identical strip + // (hivecommons/hive#14921 under #14910 and #14911). + function stageTrackerLinkedDrawnHere(lp, item) { + const under = Number(lp && lp.drawn_under) || 0; + return !under || under === (Number(item && item.number) || 0); + } + function stageTrackerLinkedElsewhere(item) { + const linked = Array.isArray(item.linked_prs) ? item.linked_prs : []; + return linked.filter(lp => !stageTrackerLinkedDrawnHere(lp, item)).sort((x, y) => (x.number || 0) - (y.number || 0)); + } + function stageTrackerLinkedElsewhereHtml(item) { + return stageTrackerLinkedElsewhere(item).map(lp => `↳ #${Number(lp.number) || 0} · under #${Number(lp.drawn_under)}`).join(' '); + } + function stageTrackerLinkedSorted(item, stages) { + const linked = Array.isArray(item.linked_prs) ? item.linked_prs.filter(lp => stageTrackerLinkedDrawnHere(lp, item) && !stageTrackerLinkedSupersededGone(lp, item)) : (item.linked_pr ? [{ number: item.linked_pr }] : []); + const sinceOf = lp => Date.parse(lp.stage_since || '') || Infinity; + return linked.sort((x, y) => (stageTrackerAnchor(y.stage, stages, 'pr', y) - stageTrackerAnchor(x.stage, stages, 'pr', x)) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0))); + } + + // Pure: a PR whose drawn_under issue is not a row of this page (filtered + // out or on another page) would otherwise be drawn nowhere. The first + // listed issue that covers it draws it instead; later ones chip to that + // row. Returns the rows (same length, nulls kept), copying only changed ones. + function stageTrackerAdoptOrphanPRs(rows) { + const listed = new Set(); + for (const it of rows) if (it && it.kind === 'issue') listed.add(it.repo + '#' + it.number); + const claimedBy = {}; + return rows.map(it => { + if (!it || it.kind !== 'issue' || !Array.isArray(it.linked_prs)) return it; + let changed = false; + const linked = it.linked_prs.map(lp => { + const under = Number(lp && lp.drawn_under) || 0; + if (!under || under === (Number(it.number) || 0) || listed.has(it.repo + '#' + under)) return lp; + const key = it.repo + '#' + lp.number; + if (!(key in claimedBy)) claimedBy[key] = Number(it.number) || 0; + if (claimedBy[key] === (Number(it.number) || 0)) { changed = true; return Object.assign({}, lp, { drawn_under: 0 }); } + changed = true; + return Object.assign({}, lp, { drawn_under: claimedBy[key] }); + }); + return changed ? Object.assign({}, it, { linked_prs: linked }) : it; + }); + } + + // The stage a covering PR drives its issue's strip at: its own, or 040 + // covered-by-PR while it has none yet (an open PR filed seconds ago, + // still waiting for the stage-label pass). One rule for the strip and + // the list order — hive's own #15654 (000 New, nested #15655 drawn as + // "PR in progress") sat at the bottom among the New rows because the + // sort key fell back to the parent's unlabelled stage while the strip + // did not. + const STAGE_TRACKER_COVERED_BY_PR = 40; + function stageTrackerLeadStage(lp) { + return Number(lp && lp.stage) || STAGE_TRACKER_COVERED_BY_PR; + } + // Pure: the row whose live work drives an issue's strip and list place + // — its furthest covering PR, else the issue itself. + function stageTrackerLead(item, stages) { + const linked = item.kind === 'issue' ? stageTrackerLinkedSorted(item, stages) : []; + if (!linked.length) return { lead: item, kind: item.kind, stage: Number(item.stage) || 0, since: item.stage_since || '' }; + const lp = linked[0]; + return { lead: lp, kind: 'pr', stage: stageTrackerLeadStage(lp), since: lp.stage_since || item.stage_since || '' }; + } + // List order: furthest along the strip first — a covered issue counts as + // far along as its furthest covering PR — then longest-waiting first. + function stageTrackerSortKey(item, stages) { + const l = stageTrackerLead(item, stages); + return { anchor: stageTrackerAnchor(l.stage, stages, l.kind, l.lead), since: Date.parse(l.since) || Infinity }; + } + + /* ---- Repo chip and group-by-repo (pure; run under node by + stage_tracker_repo_grouping_test.go) ------------------------------- */ + // Deterministic palette slot for a repo: the string hash the contributor + // tint fallback uses (contribTintFallback), bucketed onto the + // --ham-repo-tint-N tokens so the chip CSS names no literal colour. + function stageTrackerRepoTint(repo) { + const text = String(repo || ''); + let hash = 0; + for (let i = 0; i < text.length; i++) hash = ((hash << 5) - hash + text.charCodeAt(i)) | 0; + return Math.abs(hash) % STAGE_TRACKER_REPO_TINTS; + } + function stageTrackerRepoShort(repo) { + const s = String(repo || ''); + const i = s.indexOf('/'); + return i >= 0 ? s.slice(i + 1) : s; + } + // The configured primary repo may arrive as owner/repo or as the bare + // name; an item's repo is owner/repo. + function stageTrackerIsPrimary(repo, primary) { + if (!repo || !primary) return false; + if (repo === primary) return true; + return String(primary).indexOf('/') < 0 && stageTrackerRepoShort(repo) === primary; + } + // Whether rows carry the chip under a setting, given how many repos the + // payload spans. + function stageTrackerRepoChipOn(mode, repoCount) { + if (mode === 'never') return false; + if (mode === 'always') return true; + return (Number(repoCount) || 0) > 1; + } + // The chip. ctx.repoChips = { primary, active } turns it on + // (renderStageTracker sets it from the setting); absent → ''. The + // primary repo's chip is muted; click filters the list to the repo, or + // clears the filter when it already is that repo. + function stageTrackerRepoChipHtml(repo, ctx) { + if (!ctx || !ctx.repoChips || !repo) return ''; + const primary = stageTrackerIsPrimary(repo, ctx.repoChips.primary); + const active = ctx.repoChips.active === repo; + const tip = repo + (primary ? ' (primary repo)' : '') + (active ? ' — showing only this repo; click to show all repos' : ' — click to show only this repo'); + return ``; + } + // Every hive-filed issue title leads with its filing agent in brackets + // (`[scanner] …`, `[reviewer] Review backlog (security): …`). The tag is + // drawn once, as a chip ahead of the title, and the title text that + // follows no longer repeats it; the full title stays in the tooltip. A + // bracket that is not an agent slug (`[ACMM L0]`, `[Tests]`) is part of + // the subject and is left in the title. + function stageTrackerSplitTitleTag(title) { + const m = /^\s*\[([a-z0-9][a-z0-9_.-]*)\]\s*(.*)$/s.exec(String(title || '')); + if (!m || !m[2]) return { tag: '', text: String(title || '') }; + return { tag: m[1], text: m[2] }; + } + function stageTrackerTitleHtml(title, extraClass) { + const full = String(title || ''); + const { tag, text } = stageTrackerSplitTitleTag(full); + const cls = 'ham-title' + (extraClass ? ' ' + extraClass : ''); + const chip = tag ? `${esc(tag)} ` : ''; + return `${chip}${esc(text)}`; + } + // Column name for a group header's distribution tooltip (as the column header draws it). + function stageTrackerColName(idx, stages) { + if (idx >= STAGE_TRACKER_PATH.length) return 'Merged'; + const n = STAGE_TRACKER_PATH[idx]; + const st = (stages || []).find(s => Number(s.number) === n) || {}; + return n === 0 ? 'Open' : (st.short || st.label || String(n)); + } + // Rows grouped by repo: [{ repo, key, rows, count, attention, cols, + // collapsed }], the primary repo first, then by row count (desc), then + // by name. cols is the per-column row count (a covered issue rides its + // furthest PR, as the strip draws it); needs-attention is counted over + // the rows. opts: { primary, collapsed: { repo: true }, stages }. + function stageTrackerGroups(rows, opts) { + opts = opts || {}; + const by = {}; + for (const it of rows || []) { + const r = it.repo || ''; + if (!by[r]) by[r] = { repo: r, key: STAGE_TRACKER_GROUP_KEY_PREFIX + r, rows: [], count: 0, attention: 0, cols: Array.from({ length: STAGE_TRACKER_PATH.length + 1 }, () => 0), collapsed: !!(opts.collapsed && opts.collapsed[r]) }; + const g = by[r]; + g.rows.push(it); + g.count++; + if (stageTrackerNeedsAttention(it)) g.attention++; + const anchor = stageTrackerSortKey(it, opts.stages || []).anchor; + const col = anchor >= STAGE_TRACKER_TERMINAL ? STAGE_TRACKER_PATH.length : STAGE_TRACKER_PATH.indexOf(anchor); + if (col >= 0) g.cols[col]++; + } + const prim = g => stageTrackerIsPrimary(g.repo, opts.primary) ? 0 : 1; + return Object.keys(by).map(r => by[r]).sort((a, b) => (prim(a) - prim(b)) || (b.count - a.count) || a.repo.localeCompare(b.repo)); + } + // One page of grouped entries: { group } headers and { group, item } + // rows. Headers do not count toward the page size; a page that opens + // mid-group repeats that group's header; a collapsed group is its + // header alone. total counts every row (so a collapsed group is not + // reported as filtered out); from/to and the pages run over the rows + // of expanded groups (shown). + function stageTrackerGroupPage(groups, f) { + f = stageTrackerNormalizeFilter(f); + const flat = []; + let total = 0; + for (const g of groups || []) { total += g.count; flat.push({ group: g }); if (!g.collapsed) for (const it of g.rows) flat.push({ group: g, item: it }); } + const shown = flat.filter(e => e.item).length; + const pages = Math.max(1, Math.ceil(shown / f.size)); + const page = Math.min(f.page, pages); + const lo = (page - 1) * f.size, hi = page * f.size; + const rows = []; + let n = 0, lastHeader = null; + for (const e of flat) { + if (!e.item) { + // A header sits at the row position its rows start; one exactly + // at the page end opens the next page unless this is the last. + if (n >= lo && (n < hi || page === pages)) { rows.push(e); lastHeader = e.group; } + continue; + } + if (n >= lo && n < hi) { + if (lastHeader !== e.group) { rows.push({ group: e.group }); lastHeader = e.group; } + rows.push(e); + } + n++; + } + return { rows, page, pages, from: shown ? lo + 1 : 0, to: Math.min(shown, hi), total, shown, size: f.size }; + } + // Group header row: caret toggle, repo chip, owner/repo, row count, + // needs-attention count and a mini per-column distribution. Keyed + // `group:owner/repo` by the render so the reconcile keeps it stable. + function stageTrackerGroupHeaderHtml(g, stages, ctx) { + const max = Math.max(1, ...g.cols); + const dist = g.cols.map((c, i) => ``).join(''); + const attn = g.attention ? `${g.attention} need${g.attention === 1 ? 's' : ''} attention` : ''; + // The header always carries the chip, whatever the row setting. + const chipCtx = { repoChips: Object.assign({}, (ctx && ctx.repoChips) || {}) }; + return `
+ + ${stageTrackerRepoChipHtml(g.repo, chipCtx)}${esc(g.repo)} + ${g.count} ${g.count === 1 ? 'row' : 'rows'}${attn} + ${dist} +
`; + } + + // Row = title line (number, title, chips, since) + thin strip. Non-active + // chevrons carry only a grey icon; the active one carries words. + // Everything else is in the tooltip on the row's own #N link: the issue + // ref on the left for an issue row, the ham-pr-ref in the PR column for a + // PR row (the row container, kind/author icons, chips, the since cell and + // a PR row's issue slot carry none). + // An issue with no PR yet, or exactly one covering PR, is a single entry + // (the PR's stage drives the strip and its "[icon] #N title" sits in the + // PR column). With two or more covering PRs the issue strip stops at + // Claimed and one sub-row per PR continues it. A PR drawn on its own + // row owns the whole strip; its issue slot names the issue it closes or + // the "no linked issue" placeholder, never the PR itself. + function stageTrackerRowHtml(item, stages, ctx) { + ctx = ctx || {}; + const nowMs = Number(ctx.nowMs) || Date.now(); + const isIssue = item.kind === 'issue'; + const title = item.title || ''; + let prRefs = [], shown = item, range = null, subs = '', subRows = null; + if (isIssue) { + const linked = stageTrackerLinkedSorted(item, stages); + if (linked.length === 1) { + // One covering PR: a single entry whose strip the PR's stage drives. + const lp = linked[0]; + const who = (lp.author_kind || 'hive') + (lp.author ? ' · @' + lp.author : ''); + const lineage = (lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(lp, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(lp, nowMs) : ''); + prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRPillsHtml(stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)), typeof stageTrackerLinkedChipsHtml === 'function' ? stageTrackerLinkedChipsHtml(lp, lineage) : (lineage || null), lp.base_ref)]; + shown = Object.assign({}, item, { via_pr: true, stage: stageTrackerLeadStage(lp), stage_since: lp.stage_since || item.stage_since, modifiers: lp.modifiers || item.modifiers, deferred_modifiers: lp.deferred_modifiers || item.deferred_modifiers || [], caption: lp.caption || item.caption, reason: lp.reason || item.reason, + human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', decision_needed: lp.decision_needed || null, hold: lp.hold || null, adoption: lp.adoption || null, stage_actor: lp.stage_actor || item.stage_actor || null, claimant: lp.claimant || null, presence: lp.presence || null, rework: lp.rework || null, push: lp.push || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, left_train: lp.left_train || null, overlap: lp.overlap || null, decided: lp.decided || item.decided || null }); + } else if (linked.length) { + // Several covering PRs: the issue strip ends at Claimed, all passed + // and nothing lit; one sub-row per PR carries the live chevron. + range = { to: 20 }; + if (stageTrackerAnchor(item.stage, stages, item.kind) <= 20) shown = Object.assign({}, item, { stage: 40 }); + subs = linked.map(lp => stageTrackerSubRowHtml(lp, item, stages, nowMs, ctx)).join(''); + subRows = linked; + } + } + // Invariant (owner): the issue slot on the left never holds a PR. A + // PR whose issue is listed is nested under it; a PR seen on its own + // (no issue, or the Pull requests view) puts the issue it closes — or + // a muted "no linked issue" placeholder — on the left and names + // itself in the PR column, exactly where a covering PR sits on an + // issue row. That holds when the issue is already closed too + // (closed_issue set, hivecommons/hive#14655): the issue still leads, + // struck through with a `closed` chip — `closed by #N` when the + // server knows the merged PR that closed it, so a duplicate fix reads + // as one (hivecommons/hive#15232) — and the PR stays in the PR column + // rather than taking the issue slot. A not-planned close adds a chip + // saying the PR may be moot. + // The repo chip (when on) leads the row, before the issue slot's #N. + const chip = ctx.repoChips ? stageTrackerRepoChipHtml(item.repo, ctx) : ''; + let leadHtml; + if (isIssue) { + leadHtml = `
+ ${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} + #${Number(item.number) || 0} + ${stageTrackerTitleHtml(title)} + ${item.claim_reference ? `refs` : ''} + ${typeof stageTrackerLinkedElsewhereHtml === 'function' ? stageTrackerLinkedElsewhereHtml(item) : ''} + ${item.is_tracker ? `tracker${item.children && item.children.total ? ' ' + Number(item.children.completed) + '/' + Number(item.children.total) : ''}` : ''} +
`; + } else { + const li = stageTrackerPRIssueSlot(item); + prRefs = [stageTrackerPRRef(item.number, item.url, item.author_kind || '', item.author, title, (title ? title + ' · ' : '') + stageTrackerTooltip(shown, nowMs)) + (item.lineage && typeof stageTrackerLineageChipHtml === 'function' ? ' ' + stageTrackerLineageChipHtml(item, nowMs) : '')]; + leadHtml = li.number + ? `
+ ${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} + #${li.number} + ${li.title ? stageTrackerTitleHtml(li.title) : `${esc(li.placeholder)}`}${li.soft ? ` refs` : ''}${li.closed ? ' ' + stageTrackerClosedChipHtml(item, li) : ''} +
` + : `
+ ${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} + ${esc(li.text)} +
`; + } + const prs = typeof stageTrackerRowPRKeys === 'function' ? stageTrackerRowPRKeys(item) : ''; + const trainKey = typeof stageTrackerTrainKey === 'function' ? stageTrackerTrainKey(item) : ''; + return `
+ ${stageTrackerRowToolsHtml(item)} +
+ ${stageTrackerHeadColsHtml(prRefs, leadHtml, stageTrackerActedBadgeHtml(item, nowMs) + stageTrackerChipsHtml(shown) + (typeof stageTrackerLeadButtonHtml === 'function' ? stageTrackerLeadButtonHtml(item, nowMs, subRows) : ''))} +
+
+
    ${stageTrackerStripItems(shown, stages, range, nowMs, ctx)}
+ ${stageTrackerSinceHtml(shown, nowMs)} +
${stageTrackerCurrentStageHtml(shown, stages, range, nowMs)}${typeof stageTrackerEventHtml === 'function' ? stageTrackerEventHtml(stageTrackerItemKey(item), ctx) : ''}${typeof stageTrackerReviewNotesHtml === 'function' ? stageTrackerReviewNotesHtml(item, ctx) : ''}${subs} +
`; + } + + /* ---- tracker-cues (JS): working / waiting / event line ---------------- + See the CSS block of the same name. Pure helpers, run under node by + stage_tracker_cues_test.go. */ + // Pure: which open items a hive agent is on right now, from the status + // payload the dashboard already polls: busy agents whose lastAction is + // in their current round. Keyed owner/repo#number (lower-case); an + // action names the item but not its kind, so rows match by number. + const STAGE_TRACKER_WORK_WORDS = { + agent_pr_created: 'opened a pull request', agent_issue_created: 'opened an issue', agent_comment_created: 'commented', agent_issue_claimed: 'claimed it', + agent_label_applied: 'changed labels', agent_review_requested: 'asked for review', agent_issue_closed: 'closed it', pr_closed: 'closed it', agent_pr_reviewed: 'reviewed it', pr_merged: 'merged it', + }; diff --git a/src/pkg/dashboard/static-src/js/tracker-row-strip.js b/src/pkg/dashboard/static-src/js/tracker-row-strip.js new file mode 100644 index 0000000000..6c8c635536 --- /dev/null +++ b/src/pkg/dashboard/static-src/js/tracker-row-strip.js @@ -0,0 +1,383 @@ + + // Column header: the stage names once, aligned with the chevrons below. + // It is sticky under the Merged bar (tracker-cues CSS), so the names + // and the chip stay in view while the list scrolls. + function stageTrackerHeaderHtml(stages) { + const byNum = {}; + (stages || []).forEach(st => { byNum[st.number] = st; }); + const cols = STAGE_TRACKER_PATH.map(n => { + const name = n === 0 ? 'Open' : ((byNum[n] || {}).short || (byNum[n] || {}).label || String(n)); + // The Merge queue column wears the same train as the train header chip. + const ico = n === 80 && typeof stageTrackerTrainIconHtml === 'function' ? stageTrackerTrainIconHtml('ham-ico ham-train-icon ham-col-ico') : ''; + return `
  • ${ico}${esc(name)}
  • `; + }).join(''); + return ``; + } + + // Chevrons for one item. range bounds the columns the item owns (an + // issue row stops at PR in progress, a nested PR row starts there); + // columns outside it are invisible spacers that keep the grid aligned. + // Only the active chevron carries hover text (stage name, description, + // whose move it is); passed and upcoming chevrons have none. + function stageTrackerStripItems(item, stages, range, nowMs, ctx) { + const segs = stageTrackerSegments(item, stages, nowMs, ctx); + const trains = ctx && ctx.trains; + const curStage = Number(item.stage) || 0; + const from = range && range.from != null ? range.from : -Infinity; + const to = range && range.to != null ? range.to : Infinity; + const actorKind = stageTrackerActorKind(item); + const actorIco = actorKind ? stageTrackerIcon(actorKind, 'ham-ico ham-actor-ico', 'Next move: ' + actorKind) : ''; + const actorTip = stageTrackerActorTip(item); + const claimant = typeof stageTrackerClaimant === 'function' ? stageTrackerClaimant(item) : null; + const holderShort = claimant ? stageTrackerClaimantShort(claimant) : ''; + // "· @odttlnt's clanker · ■ offline 3h": the holder's live state + // rides after the holder when the row's presence is theirs. + const holderPresence = holderShort && typeof stageTrackerHolderPresenceHtml === 'function' ? stageTrackerHolderPresenceHtml(item, claimant, nowMs) : ''; + const holderHtml = holderShort ? ` · ${esc(holderShort)}${holderPresence}` : ''; + // A row whose next mover is nobody (an unclassified PR under its + // issue reads "PR in progress") still shows WHO holds it: the + // holder's own kind icon stands where the actor icon would + // (hivecommons/hive#15541). + const holderIco = holderShort && !actorIco ? stageTrackerIcon(stageTrackerClaimantIconKind(claimant), 'ham-ico ham-actor-ico', stageTrackerClaimantLine(claimant, nowMs)) : ''; + // Static chevrons carry no data-motion: the CSS only animates the two + // moving buckets. The hive-acting pulse needs an agent actually on + // the item (tracker-cues: working); a hive stage with nobody on it is + // waiting, and its tooltip says so. + // tracker-cues helpers are optional here so a lifted copy of this + // function (tests, previews) renders without them. + const worker = typeof stageTrackerWorkingOn === 'function' ? stageTrackerWorkingOn(item, ctx && ctx.workers) : null; + let motion = stageTrackerMotion(item); + if (motion === STAGE_TRACKER_MOTION_ACTIVE && !worker) motion = STAGE_TRACKER_MOTION_STATIC; + const motionAttr = motion === STAGE_TRACKER_MOTION_STATIC ? '' : ` data-motion="${motion}"`; + return segs.map(sg => { + if (sg.number < from || sg.number > to) return ``; + const sentinel = !!(sg.detour && sg.detour.sentinel); + const sentinelSuffix = !!(sg.detour && sg.detour.sentinelSuffix); + const cls = ['ham-seg', sg.state, sg.cap ? 'cap' : '', sg.cap && sg.terminal ? 'merged' : '', sg.detour ? 'detoured' : '', sg.hold ? 'ham-open-hold' : '', sg.blocked ? 'ham-open-blocked' : '', sg.draft ? 'ham-open-draft' : '', sg.isNew ? 'ham-open-new' : '', sg.advisory ? 'ham-open-advisory' : '', sg.openSince && sg.openSince.stale ? 'ham-open-stale' : '', sentinel || sentinelSuffix ? 'ham-sentinel' : ''].filter(Boolean).join(' '); + const active = sg.state === 'active'; + let tip = ''; + if (active) { + tip = sg.label + (sg.description ? ' — ' + sg.description : ''); + if (sg.blocked) tip += ' — ' + stageTrackerBlockedTip(item); + if (sg.draft) tip += ' — ' + STAGE_TRACKER_DRAFT_TIP; + if (sg.isNew && typeof stageTrackerNewLines === 'function') tip = (typeof stageTrackerOpenTriageNeeded === 'function' && stageTrackerOpenTriageNeeded(item) ? 'Triage needed — ' : 'New — ') + stageTrackerNewLines(item, nowMs).join(' — '); + if (sg.advisory) tip = (item.advisory && item.advisory.caption) || 'Advisory for maintainers · read, then close'; + if (sg.openSince) tip += ' — open since ' + new Date(sg.openSince.ms).toISOString() + (sg.openSince.fromCreated ? ' (opened)' : ''); + // The shared Merge gate word hides 080 vs 095 vs 100; the chevron tooltip carries it. + // With merge_gate in the payload the sentence is the gate's own + // (what holds it, next sweep, soak left — #15073). + const gateInfo = !sg.detour && typeof stageTrackerMergeGateInfo === 'function' ? stageTrackerMergeGateInfo(item, nowMs, trains) : null; + if (gateInfo) tip = sg.label + ' — ' + gateInfo.tip; + else if (!sg.detour && (curStage === 60 || curStage === 80)) tip = sg.label + ' — not yet admitted' + (item.caption || item.reason ? ' — ' + (item.caption || item.reason) : ''); + else if (curStage === STAGE_TRACKER_PRE_MERGE_SOAK) tip = sg.label + ' — admitted, soaking' + stageTrackerSoakLeft(item); + else if (curStage === 100) tip = sg.label + ' — admitted, merging'; + // Why a person merges a 090 PR leads its tooltip (hivecommons/hive#14658). + // The reason is the whole story; the stage description would only repeat it (hivecommons/hive#15394). + else if (curStage === STAGE_TRACKER_READY_FOR_HUMAN_MERGE && item.human_merge_reason_text) tip = ((sg.detour && sg.detour.text) || sg.label) + ' — ' + String(item.human_merge_reason_text).trim(); + // A refusal on an earlier head is history, not the word: the + // chevron reads the live stage and the hover keeps "merge attempt + // on previous head failed: branch protection". + const priorNote = !sg.cap && typeof stageTrackerPriorHeadMergeFailedNote === 'function' ? stageTrackerPriorHeadMergeFailedNote(item) : ''; + if (priorNote) tip += ' — ' + priorNote; + if (actorTip && !sg.cap) tip += actorTip; + if (claimant && !sg.cap) tip += ' · ' + stageTrackerClaimantLine(claimant, nowMs); + // The sentinel's reason leads the lane tooltip so the security + // implication is read before the stage mechanics. + if (sentinel) tip = stageTrackerSentinelTip(item) + ' — ' + tip; + else if (sentinelSuffix) tip = tip + ' — ' + stageTrackerSentinelTip(item); + // Working or waiting leads: what happens now, or what it waits on. + if (!sg.cap && typeof stageTrackerCueLead === 'function') tip = stageTrackerCueLead(item, worker, nowMs) + tip; + } + let inner; + // A lit chevron on a row parked on a person ("Needs human decision", + // "Triage needed") is the trigger of the decision popover: the word + // becomes a button and the chevron drops its native title so the + // popover (which repeats the stage line) is its one hover text. + const decision = active && !sg.cap && typeof stageTrackerDecisionOf === 'function' ? stageTrackerDecisionOf(item) : null; + // On the merge gate the word carries its live detail and the + // leading glyph says in words what hive is doing (#15073). + const gateWord = active && !sg.cap && !sg.detour && typeof stageTrackerMergeGateWordHtml === 'function' ? stageTrackerMergeGateWordHtml(item, nowMs, trains) : ''; + // A detour word that already names the holder ("Returned to + // @bob's clanker") does not repeat them after the dot. + const detourHolder = sg.detour && holderShort && sg.detour.text.indexOf(holderShort) >= 0 ? '' : holderHtml; + const word = sg.detour ? `${esc(sg.detour.text)}${detourHolder}` : (gateWord || `${esc(sg.short)}${holderHtml}`); + const gateCue = gateWord && typeof stageTrackerGateCueHtml === 'function' ? stageTrackerGateCueHtml(item, nowMs, trains) : ''; + // The agent-working spinner (tracker-cues) names the agent and what + // it did, so a spinning glyph is never unexplained. + const workTip = worker && typeof stageTrackerCueLead === 'function' ? stageTrackerCueLead(item, worker, nowMs).replace(/ — $/, '') : ''; + const workIco = workTip ? `${stageTrackerIcon(sg.number, 'ham-ico ham-active-ico')}` : stageTrackerIcon(sg.number, 'ham-ico ham-active-ico'); + // The cap chevron is the ✓ only once the PR is merged; until then + // the column is the row's history and wears the history mark. + if (sg.cap) inner = sg.terminal ? stageTrackerIcon(sg.number, 'ham-ico') : stageTrackerIcon('history', 'ham-ico ham-history-ico', 'History — no decisions or actions recorded yet'); + else if (active) inner = gateCue + workIco + (decision ? stageTrackerDecisionTriggerHtml(decision, word, tip) : word) + (actorIco || holderIco); + else inner = stageTrackerIcon(sg.number, 'ham-ico'); + return `
  • ${inner}
  • `; + }).join(''); + } + + // Compact strips retain their column alignment; the current step gets a + // full-width caption so detours and the next actor never need a hover. + function stageTrackerCurrentStageHtml(item, stages, range, nowMs) { + if (item.superseded && item.superseded.closer_pr) return `

    ${esc(stageTrackerHeadline(item) + (item.superseded.keep_reason ? " · " + item.superseded.keep_reason : ""))}

    `; + const active = stageTrackerSegments(item, stages, nowMs).find(sg => sg.state === 'active' + && (!range || range.from == null || sg.number >= range.from) + && (!range || range.to == null || sg.number <= range.to)); + if (!active) return ''; + const actor = active.cap ? '' : stageTrackerActorTip(item); + const regressed = stageTrackerRegressionText(item, Date.now()); + const text = active.short + (active.detour && active.detour.text !== active.short ? ' · ' + active.detour.text : '') + actor + (regressed ? ' · ' + regressed : ''); + return `

    ${esc(text)}

    `; + } + + // "040 Covered by PR" — the stage code plus the strip word the payload + // names for it (the code alone when the stage table is not loaded yet). + function stageTrackerStageWord(n) { + const num = Number(n) || 0; + const st = ((_stageTracker && _stageTracker.stages) || []).find(s => Number(s.number) === num); + const code = String(num).padStart(3, '0'); + return st && (st.short || st.label) ? code + ' ' + (st.short || st.label) : code; + } + + // Modifiers that park an item on a person. A regression on a row that + // carries none of these and sits on a hive-driven stage is the hive's + // to work through, so the dashboard must not dress it as a human call. + const STAGE_TRACKER_HUMAN_MODS = ['hold', 'unauthorized', 'needs-human', 'needs-decision', 'needs-rebase', 'blocked', 'stalled']; + const STAGE_TRACKER_HANDLED_TEXT = 'stage ↓'; + const STAGE_TRACKER_HANDLED_NOTE = 'the hive is handling it — no action needed; clears on the next forward step'; + + // True when the item is regressed but nothing about it waits on a + // person: no human-gate modifier and not on a human-gated stage. Such a + // row gets a muted "stage ↓" pill and stays out of "Needs attention". + function stageTrackerRegressionHandled(item) { + const mods = Array.isArray(item.modifiers) ? item.modifiers : []; + if (mods.indexOf('regressed') < 0) return false; + if (mods.some(m => STAGE_TRACKER_HUMAN_MODS.indexOf(m) >= 0)) return false; + return STAGE_TRACKER_ATTENTION_STAGES.indexOf(Number(item.stage) || 0) < 0; + } + + // The regressed pill's explanation: which stage the item fell from and + // to, when, and the reason recorded with the fall — so "regressed" never + // needs a trip to the store to read. '' when the item is not regressed. + // A hive-handled regression adds the note that nobody needs to act. + function stageTrackerRegressionText(item, nowMs) { + const mods = Array.isArray(item.modifiers) ? item.modifiers : []; + const from = Number(item.regressed_from) || 0; + if (mods.indexOf('regressed') < 0 || !from) return ''; + const cur = Number(item.stage) || 0; + const to = Number(item.regressed_to) || cur; + const atMs = Date.parse(item.regressed_at || ''); + let text = 'regressed: ' + stageTrackerStageWord(from) + ' → ' + stageTrackerStageWord(to); + if (!isNaN(atMs)) text += ' at ' + agentNowClockTime(atMs, nowMs || Date.now()); + if (item.regressed_reason) text += ' because ' + String(item.regressed_reason); + if (cur && cur !== to) text += ' · now ' + stageTrackerStageWord(cur); + if (stageTrackerRegressionHandled(item)) text += ' · ' + STAGE_TRACKER_HANDLED_NOTE; + return text; + } + + // The name of one trail hop. The payload's history entries carry + // {number, slug, at, ...} (StageTrackerHop); the strip word for the + // number wins, the slug stands in before the stage table is loaded, and + // '' means the hop cannot be named and is left out of the trail. + function stageTrackerHopName(h) { + if (!h || typeof h !== 'object') return ''; + const raw = h.number !== undefined ? h.number : h.stage; + const num = Number(raw); + if (raw !== undefined && raw !== null && raw !== '' && !isNaN(num)) { + if (num === 0) return 'Open'; + const st = ((_stageTracker && _stageTracker.stages) || []).find(s => Number(s.number) === num); + if (st && (st.short || st.label)) return st.short || st.label; + } + return h.slug ? String(h.slug) : ''; + } + + // "Trail: CI / Review → Needs human decision" — the last few hops of the + // item's history by stage name; '' when fewer than two hops can be named. + function stageTrackerTrailText(item) { + const hist = Array.isArray(item && item.history) ? item.history : []; + const names = hist.slice(-STAGE_TRACKER_TRAIL_HOPS).map(stageTrackerHopName).filter(Boolean); + return names.length > 1 ? names.join(' → ') : ''; + } + + // Row tooltip: headline, reason, repo, author, flags, since, recent hops. + function stageTrackerTooltip(item, nowMs) { + const ak = item.author_kind || ''; + // Plain words for author_kind in hover text (hivecommons/hive#15394). + const akPlain = { human: 'person', clanker: 'agent', hive: 'hive', bot: 'bot' }; + const mods = Array.isArray(item.modifiers) ? item.modifiers : []; + const sinceMs = Date.parse(item.stage_since || ''); + const trail = stageTrackerTrailText(item); + const openHeld = (Number(item.stage) || 0) === 0 && mods.indexOf('hold') >= 0; + const lines = openHeld + ? [stageTrackerHeadline(item) + (item.caption || item.reason ? ' · ' + (item.caption || item.reason) : '') + (item.repo ? ' · ' + item.repo : '')] + : [stageTrackerHeadline(item), item.caption || item.reason || '', item.repo || '']; + if (item.author || ak) lines.push('Author: ' + (item.author ? '@' + item.author : '') + (ak ? ' (' + (akPlain[ak] || ak) + (item.author_kind_source === 'inferred' ? ', inferred' : '') + ')' : '') + (item.tier ? ' · ' + item.tier : '')); + if (item.origin) lines.push('Origin: origin/' + item.origin); + if (item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length) lines.push('Covering PR: ' + item.linked_prs.map(lp => Number(lp.number) || 0).sort((x, y) => x - y).map(n => '#' + n).join(', ')); + else if (item.kind === 'issue' && item.linked_pr) lines.push('Covering PR: #' + item.linked_pr + (typeof stageTrackerLineageClause === 'function' ? stageTrackerLineageClause(item) : '')); + const actorLine = stageTrackerActorTip(item); + if (actorLine) lines.push(actorLine.replace(/^ · /, '')); + if (typeof stageTrackerNewLines === 'function') lines.push(...stageTrackerNewLines(item, nowMs)); + const blockedPR = mods.indexOf('blocked') >= 0 ? stageTrackerBlockedOnPR(item) : null; + if (blockedPR) lines.push(blockedPR.tip); + if (typeof stageTrackerTrainLines === 'function') lines.push(...stageTrackerTrainLines(item)); + // Guarded: the test harnesses load helpers by name, and this one is additive. + const adoption = typeof stageTrackerAdoptionTip === 'function' ? stageTrackerAdoptionTip(item) : ''; + if (adoption) lines.push('Adoption: ' + adoption + (typeof stageTrackerAdoptOffered === 'function' && stageTrackerAdoptOffered(item) ? ' (row menu → Adopt)' : '')); + const presence = typeof stageTrackerPresenceTip === 'function' ? stageTrackerPresenceTip(item, nowMs) : ''; + if (presence) lines.push('Presence: ' + presence); + const rework = typeof stageTrackerReworkTip === 'function' ? stageTrackerReworkTip(item, nowMs) : ''; + if (rework) lines.push('Rework: ' + rework); + const push = typeof stageTrackerPushTip === 'function' ? stageTrackerPushTip(item, nowMs) : ''; + if (push) lines.push('Push: ' + push); + if (mods.length) lines.push('Flags: ' + mods.map(m => STAGE_TRACKER_MOD_TEXT[m] || m).join(', ')); + const stale = stageTrackerStaleLabelsText(item); + if (stale) lines.push(stale); + const deferred = stageTrackerDeferredMods(item); + if (deferred.length) lines.push(STAGE_TRACKER_DEFERRED_NOTE + deferred.map(m => STAGE_TRACKER_MOD_TEXT[m] || m).join(', ')); + if (item.sentinel_alert && deferred.indexOf(STAGE_TRACKER_SENTINEL_CHIP) < 0) lines.push(stageTrackerSentinelTip(item)); + const regressed = stageTrackerRegressionText(item, nowMs); + if (regressed) lines.push(regressed.charAt(0).toUpperCase() + regressed.slice(1)); + if (mods.indexOf('unauthorized') >= 0 && item.unauthorized) lines.push('Unauthorized: ' + item.unauthorized); + if (mods.indexOf('hold') >= 0 && typeof stageTrackerHoldPill === 'function' && stageTrackerHoldPill(item)) lines.push(stageTrackerHoldPill(item)); + if (sinceMs) lines.push('Since ' + agentNowClockTime(sinceMs, nowMs) + ' · ' + agentNowAgo(nowMs - sinceMs)); + if (trail) lines.push('Trail: ' + trail); + // Say it once: a line the caption already said is not repeated (hivecommons/hive#15394). + return lines.filter((l, i) => l && lines.indexOf(l) === i).join('\n'); + } + + // The sentinel chip: drawn in the chip area (beside needs rebase / + // regressed) on every lane but the one whose word already says it. + // Pure: the "supersedes #N" chip on a live PR that replaced a closed + // original (`supersedes`: {number, url, closed_at, open} — the hive's + // close-first supersession, hivecommons/hive#15135). The closed PR is + // never a row; this chip is its only trace. '' without one. + function stageTrackerSupersedesTip(item, nowMs) { + const sp = item && item.supersedes; + if (!sp || !(Number(sp.number) > 0)) return ''; + const ago = stageTrackerAgoText(Date.parse(sp.closed_at || ''), nowMs); + if (sp.open) return 'Replaces #' + Number(sp.number) + ' (left open with the note' + (ago ? ', ' + ago : '') + ')'; + return 'Replaces #' + Number(sp.number) + ' (closed' + (ago ? ' ' + ago : '') + ')'; + } + function stageTrackerSupersedesChipHtml(item, nowMs) { + const tip = stageTrackerSupersedesTip(item, nowMs); + if (!tip) return ''; + const sp = item.supersedes; + const text = 'supersedes #' + Number(sp.number); + const attrs = `class="ham-badge ham-badge-supersedes" title="${esc(tip)}" aria-label="${esc(tip)}"`; + if (sp.url) return `${esc(text)}`; + return `${esc(text)}`; + } + function stageTrackerSentinelChipHtml(item) { + if (!item || !item.sentinel_alert || stageTrackerSentinelInLane(item) || stageTrackerSentinelAsSuffix(item) || stageTrackerDeferredMods(item).indexOf(STAGE_TRACKER_SENTINEL_CHIP) >= 0) return ''; + return `${esc(STAGE_TRACKER_SENTINEL_CHIP)}`; + } + + // Pure: the hold pill text from the row's `hold` provenance ('' when the + // pass could not attribute the hold, so the plain "hold" word stays). + function stageTrackerHoldPill(item) { + const h = item && item.hold; + if (!h || !h.by) return ''; + if (h.pill) return h.pill; + const who = h.by === 'hive' ? 'hive' : '@' + h.by; + return 'Held by ' + who + (h.reason ? ' · ' + h.reason : ''); + } + // Pure: the hold pill's hover text — who, why, since when. + function stageTrackerHoldTip(item, nowMs) { + const h = item && item.hold; + if (!h || !h.by) return ''; + const sinceMs = Date.parse(h.since || ''); + const lines = [stageTrackerHoldPill(item)]; + if (h.by === 'hive') lines.push(h.source === 'reporter-trust' ? 'The hive set this hold itself: the linked issue\'s reporter is below the trust the gate requires. Release it to let the lane merge, or keep it until a maintainer has reviewed the reporter.' : 'The hive set this hold itself.'); + if (sinceMs) lines.push('Since ' + agentNowClockTime(sinceMs, nowMs) + ' · ' + agentNowAgo(nowMs - sinceMs)); + return lines.join('\n'); + } + + function stageTrackerChipsHtml(item) { + const sentinel = stageTrackerSentinelChipHtml(item) + (typeof stageTrackerAdoptionChipHtml === 'function' ? stageTrackerAdoptionChipHtml(item) : '') + (typeof stageTrackerPresenceChipHtml === 'function' ? stageTrackerPresenceChipHtml(item) : '') + (typeof stageTrackerPushChipHtml === 'function' ? stageTrackerPushChipHtml(item, Date.now()) : '') + (typeof stageTrackerReroutePillHtml === 'function' ? stageTrackerReroutePillHtml(item) : '') + (typeof stageTrackerSupersedesChipHtml === 'function' ? stageTrackerSupersedesChipHtml(item, Date.now()) : '') + (typeof stageTrackerOverlapBadgeHtml === 'function' ? stageTrackerOverlapBadgeHtml(item) : ''); + const mods = (Array.isArray(item.modifiers) ? item.modifiers.slice() : []) + .sort((x, y) => STAGE_TRACKER_MOD_PRIORITY.indexOf(x) - STAGE_TRACKER_MOD_PRIORITY.indexOf(y)); + if (!mods.length) return sentinel; + // A regression the hive is working through yields the lead pill to any + // other modifier and, alone, draws muted as "stage ↓" rather than red. + const handled = stageTrackerRegressionHandled(item); + if (handled && mods.length > 1) mods.push(mods.shift()); + let text = handled && mods[0] === 'regressed' ? STAGE_TRACKER_HANDLED_TEXT : (STAGE_TRACKER_MOD_TEXT[mods[0]] || mods[0].replace(/-/g, ' ')); + // A hold the stage-label pass could attribute names who set it and why + // ("Held by hive · reporter trust (issue #N by @X, contributor)"), so the + // operator is not left reading "hold +1" (hivecommons/hive#15020). + // Guarded: the test harnesses load helpers by name, and this one is additive. + const holdPill = mods[0] === 'hold' && typeof stageTrackerHoldPill === 'function' ? stageTrackerHoldPill(item) : ''; + if (holdPill) text = holdPill; + // A row the scheduler withholds for open GitHub "blocked by" dependencies names them (hivecommons/hive#14765); + // one blocked on a PR (hive:blocked-on marker) names it and links to it (hivecommons/hive#14952). + const blockedPR = mods[0] === 'blocked' ? stageTrackerBlockedOnPR(item) : null; + if (mods[0] === 'blocked' && Array.isArray(item.blocked_on) && item.blocked_on.length) text = stageTrackerBlockedTip(item); + else if (blockedPR) text = 'blocked on ' + blockedPR.short; + // A blocked row with a hive:recheck-after deadline ("blocked until ") names when the sweep re-checks it. + const recheck = mods[0] === 'blocked' ? /^blocked until (\S+)/i.exec(String(item.bucket_reason || '')) : null; + const recheckMs = recheck ? Date.parse(recheck[1]) : NaN; + if (!isNaN(recheckMs)) text += ' · re-check at ' + agentNowClockTime(recheckMs, Date.now()); + // The regressed pill (lead or folded into "+1") explains itself on + // hover; failing that, a draft pill (lead or folded) does. + const regressed = stageTrackerRegressionText(item, Date.now()); + // An unauthorized pill names the missing App permission and the human step; + // the regressed pill explains itself; a blocked pill names what it waits on; + // failing all three, a draft pill does. + const anyBlockedPR = mods.indexOf('blocked') >= 0 ? stageTrackerBlockedOnPR(item) : null; + const tip = (mods.indexOf('unauthorized') >= 0 && String(item.unauthorized || '').trim()) || regressed + || (holdPill && typeof stageTrackerHoldTip === 'function' ? stageTrackerHoldTip(item, Date.now()) : '') + || (mods.indexOf('blocked') >= 0 && Array.isArray(item.blocked_on) && item.blocked_on.length ? 'Withheld from the scanner until ' + item.blocked_on.join(', ') + (item.blocked_on.length > 1 ? ' close' : ' closes') : '') + || (anyBlockedPR ? anyBlockedPR.tip : '') + || (mods.indexOf('draft') >= 0 ? STAGE_TRACKER_DRAFT_TIP : ''); + const cls = 'ham-mod-' + mods[0] + (handled && mods[0] === 'regressed' ? ' ham-mod-handled' : ''); + const inner = `${esc(text)}${mods.length > 1 ? ' +' + (mods.length - 1) : ''}`; + // The lead pill of a row blocked on a PR is the link to that PR. + if (blockedPR && blockedPR.url) return sentinel + `${inner}`; + // A lead needs-human / needs human decision pill opens the decision + // popover (what to decide, who asked, the applicable actions) instead + // of a native tooltip. + // A hive-set hold is a decision too (release or keep): its pill opens the same popover. + const decision = (mods[0] === 'needs-human' || mods[0] === 'needs-decision' || (holdPill && item.hold && item.hold.by === 'hive')) && typeof stageTrackerDecisionOf === 'function' ? stageTrackerDecisionOf(item) : null; + if (decision) return sentinel + stageTrackerDecisionTriggerHtml(decision, inner, tip, 'ham-badge ham-badge-mod ' + cls); + return sentinel + `${inner}`; + } + + /* ---- "Did I act on this?" badge ------------------------------------ + Owner (2026-10-28): "I need a way to see if I selected an action on + an item so I can keep track of whether or not I addressed it. + Hovering over the indicator should show me what action I requested." + The server keeps a ledger of every row action submitted from the + dashboard (operator_actions.go) and the tracker payload carries the + newest one per item as `last_operator_action` with a derived state: + waiting (same stage, recent), addressed (the item moved on, or the + control asked for is in effect), stuck (same stage past the window), + pending (Let hive decide still running), failed. The row wears a + history badge (clock + arrow, with the action count) in the cap cell + — neutral at rest, amber when stuck, red when failed, dotted while + pending — whose in-app tooltip names the action, + when, the outcome and what hive did next. The in-flight spinner (the + request still on the wire) is a different thing drawn on the chevron; + this badge appears once the server has recorded the action. */ + const STAGE_TRACKER_ACTED_LABELS = { + approve: 'Approve', 'give-direction': 'Give direction', 'close-superseded': 'Close as superseded', wontfix: "Close as won't-fix", 'close-read': 'Closed', + 'let-hive-decide': 'Let hive decide', hold: 'Hold', release: 'Release hold', 'accept-triage': 'Accept triage', 'mark-needs-human': 'Mark needs-human', + 'queue-merge': 'Approve and let hive merge', 'merge-now': 'Merge now as maintainer', + adopt: 'Adopt', 'adopt-now': 'Adopt now', reroute: 'Reroute to another clanker', + }; + // "Rebase, then merge as maintainer" is merge-now on a row that needs a + // rebase (hivecommons/hive#14822): the server relabels the option and + // answers 202 rebase-queued; the follow-through's steps come back in + // last_operator_action.followed[] as hops without a stage number. + const STAGE_TRACKER_REBASE_MERGE_LABEL = 'Rebase, then merge as maintainer'; + const STAGE_TRACKER_ACTION_REBASE_QUEUED = 'rebase-queued'; + function stageTrackerNeedsRebase(item) { + if (!item) return false; + if ((Array.isArray(item.modifiers) ? item.modifiers : []).indexOf('needs-rebase') >= 0) return true; + if ((Array.isArray(item.labels) ? item.labels : []).some(l => String(l).toLowerCase() === 'needs-rebase')) return true; + const rm = item.rebase_merge; + return !!(rm && rm.state && rm.state !== 'merged' && rm.state !== 'failed'); + } + function stageTrackerRebaseMergeLive(item) { + const rm = item && item.rebase_merge; + return !!(rm && (rm.state === 'approved' || rm.state === 'rebasing' || rm.state === 'ci-pending')); + } diff --git a/src/pkg/dashboard/static-src/js/tracker-row.js b/src/pkg/dashboard/static-src/js/tracker-row.js index a5633b61c5..3b1372a566 100644 --- a/src/pkg/dashboard/static-src/js/tracker-row.js +++ b/src/pkg/dashboard/static-src/js/tracker-row.js @@ -327,1126 +327,3 @@ if (hours < 48) return hours + 'h'; return Math.floor(hours / 24) + 'd'; } - - // Column header: the stage names once, aligned with the chevrons below. - // It is sticky under the Merged bar (tracker-cues CSS), so the names - // and the chip stay in view while the list scrolls. - function stageTrackerHeaderHtml(stages) { - const byNum = {}; - (stages || []).forEach(st => { byNum[st.number] = st; }); - const cols = STAGE_TRACKER_PATH.map(n => { - const name = n === 0 ? 'Open' : ((byNum[n] || {}).short || (byNum[n] || {}).label || String(n)); - // The Merge queue column wears the same train as the train header chip. - const ico = n === 80 && typeof stageTrackerTrainIconHtml === 'function' ? stageTrackerTrainIconHtml('ham-ico ham-train-icon ham-col-ico') : ''; - return `
  • ${ico}${esc(name)}
  • `; - }).join(''); - return ``; - } - - // Chevrons for one item. range bounds the columns the item owns (an - // issue row stops at PR in progress, a nested PR row starts there); - // columns outside it are invisible spacers that keep the grid aligned. - // Only the active chevron carries hover text (stage name, description, - // whose move it is); passed and upcoming chevrons have none. - function stageTrackerStripItems(item, stages, range, nowMs, ctx) { - const segs = stageTrackerSegments(item, stages, nowMs, ctx); - const trains = ctx && ctx.trains; - const curStage = Number(item.stage) || 0; - const from = range && range.from != null ? range.from : -Infinity; - const to = range && range.to != null ? range.to : Infinity; - const actorKind = stageTrackerActorKind(item); - const actorIco = actorKind ? stageTrackerIcon(actorKind, 'ham-ico ham-actor-ico', 'Next move: ' + actorKind) : ''; - const actorTip = stageTrackerActorTip(item); - const claimant = typeof stageTrackerClaimant === 'function' ? stageTrackerClaimant(item) : null; - const holderShort = claimant ? stageTrackerClaimantShort(claimant) : ''; - // "· @odttlnt's clanker · ■ offline 3h": the holder's live state - // rides after the holder when the row's presence is theirs. - const holderPresence = holderShort && typeof stageTrackerHolderPresenceHtml === 'function' ? stageTrackerHolderPresenceHtml(item, claimant, nowMs) : ''; - const holderHtml = holderShort ? ` · ${esc(holderShort)}${holderPresence}` : ''; - // A row whose next mover is nobody (an unclassified PR under its - // issue reads "PR in progress") still shows WHO holds it: the - // holder's own kind icon stands where the actor icon would - // (hivecommons/hive#15541). - const holderIco = holderShort && !actorIco ? stageTrackerIcon(stageTrackerClaimantIconKind(claimant), 'ham-ico ham-actor-ico', stageTrackerClaimantLine(claimant, nowMs)) : ''; - // Static chevrons carry no data-motion: the CSS only animates the two - // moving buckets. The hive-acting pulse needs an agent actually on - // the item (tracker-cues: working); a hive stage with nobody on it is - // waiting, and its tooltip says so. - // tracker-cues helpers are optional here so a lifted copy of this - // function (tests, previews) renders without them. - const worker = typeof stageTrackerWorkingOn === 'function' ? stageTrackerWorkingOn(item, ctx && ctx.workers) : null; - let motion = stageTrackerMotion(item); - if (motion === STAGE_TRACKER_MOTION_ACTIVE && !worker) motion = STAGE_TRACKER_MOTION_STATIC; - const motionAttr = motion === STAGE_TRACKER_MOTION_STATIC ? '' : ` data-motion="${motion}"`; - return segs.map(sg => { - if (sg.number < from || sg.number > to) return ``; - const sentinel = !!(sg.detour && sg.detour.sentinel); - const sentinelSuffix = !!(sg.detour && sg.detour.sentinelSuffix); - const cls = ['ham-seg', sg.state, sg.cap ? 'cap' : '', sg.cap && sg.terminal ? 'merged' : '', sg.detour ? 'detoured' : '', sg.hold ? 'ham-open-hold' : '', sg.blocked ? 'ham-open-blocked' : '', sg.draft ? 'ham-open-draft' : '', sg.isNew ? 'ham-open-new' : '', sg.advisory ? 'ham-open-advisory' : '', sg.openSince && sg.openSince.stale ? 'ham-open-stale' : '', sentinel || sentinelSuffix ? 'ham-sentinel' : ''].filter(Boolean).join(' '); - const active = sg.state === 'active'; - let tip = ''; - if (active) { - tip = sg.label + (sg.description ? ' — ' + sg.description : ''); - if (sg.blocked) tip += ' — ' + stageTrackerBlockedTip(item); - if (sg.draft) tip += ' — ' + STAGE_TRACKER_DRAFT_TIP; - if (sg.isNew && typeof stageTrackerNewLines === 'function') tip = (typeof stageTrackerOpenTriageNeeded === 'function' && stageTrackerOpenTriageNeeded(item) ? 'Triage needed — ' : 'New — ') + stageTrackerNewLines(item, nowMs).join(' — '); - if (sg.advisory) tip = (item.advisory && item.advisory.caption) || 'Advisory for maintainers · read, then close'; - if (sg.openSince) tip += ' — open since ' + new Date(sg.openSince.ms).toISOString() + (sg.openSince.fromCreated ? ' (opened)' : ''); - // The shared Merge gate word hides 080 vs 095 vs 100; the chevron tooltip carries it. - // With merge_gate in the payload the sentence is the gate's own - // (what holds it, next sweep, soak left — #15073). - const gateInfo = !sg.detour && typeof stageTrackerMergeGateInfo === 'function' ? stageTrackerMergeGateInfo(item, nowMs, trains) : null; - if (gateInfo) tip = sg.label + ' — ' + gateInfo.tip; - else if (!sg.detour && (curStage === 60 || curStage === 80)) tip = sg.label + ' — not yet admitted' + (item.caption || item.reason ? ' — ' + (item.caption || item.reason) : ''); - else if (curStage === STAGE_TRACKER_PRE_MERGE_SOAK) tip = sg.label + ' — admitted, soaking' + stageTrackerSoakLeft(item); - else if (curStage === 100) tip = sg.label + ' — admitted, merging'; - // Why a person merges a 090 PR leads its tooltip (hivecommons/hive#14658). - // The reason is the whole story; the stage description would only repeat it (hivecommons/hive#15394). - else if (curStage === STAGE_TRACKER_READY_FOR_HUMAN_MERGE && item.human_merge_reason_text) tip = ((sg.detour && sg.detour.text) || sg.label) + ' — ' + String(item.human_merge_reason_text).trim(); - // A refusal on an earlier head is history, not the word: the - // chevron reads the live stage and the hover keeps "merge attempt - // on previous head failed: branch protection". - const priorNote = !sg.cap && typeof stageTrackerPriorHeadMergeFailedNote === 'function' ? stageTrackerPriorHeadMergeFailedNote(item) : ''; - if (priorNote) tip += ' — ' + priorNote; - if (actorTip && !sg.cap) tip += actorTip; - if (claimant && !sg.cap) tip += ' · ' + stageTrackerClaimantLine(claimant, nowMs); - // The sentinel's reason leads the lane tooltip so the security - // implication is read before the stage mechanics. - if (sentinel) tip = stageTrackerSentinelTip(item) + ' — ' + tip; - else if (sentinelSuffix) tip = tip + ' — ' + stageTrackerSentinelTip(item); - // Working or waiting leads: what happens now, or what it waits on. - if (!sg.cap && typeof stageTrackerCueLead === 'function') tip = stageTrackerCueLead(item, worker, nowMs) + tip; - } - let inner; - // A lit chevron on a row parked on a person ("Needs human decision", - // "Triage needed") is the trigger of the decision popover: the word - // becomes a button and the chevron drops its native title so the - // popover (which repeats the stage line) is its one hover text. - const decision = active && !sg.cap && typeof stageTrackerDecisionOf === 'function' ? stageTrackerDecisionOf(item) : null; - // On the merge gate the word carries its live detail and the - // leading glyph says in words what hive is doing (#15073). - const gateWord = active && !sg.cap && !sg.detour && typeof stageTrackerMergeGateWordHtml === 'function' ? stageTrackerMergeGateWordHtml(item, nowMs, trains) : ''; - // A detour word that already names the holder ("Returned to - // @bob's clanker") does not repeat them after the dot. - const detourHolder = sg.detour && holderShort && sg.detour.text.indexOf(holderShort) >= 0 ? '' : holderHtml; - const word = sg.detour ? `${esc(sg.detour.text)}${detourHolder}` : (gateWord || `${esc(sg.short)}${holderHtml}`); - const gateCue = gateWord && typeof stageTrackerGateCueHtml === 'function' ? stageTrackerGateCueHtml(item, nowMs, trains) : ''; - // The agent-working spinner (tracker-cues) names the agent and what - // it did, so a spinning glyph is never unexplained. - const workTip = worker && typeof stageTrackerCueLead === 'function' ? stageTrackerCueLead(item, worker, nowMs).replace(/ — $/, '') : ''; - const workIco = workTip ? `${stageTrackerIcon(sg.number, 'ham-ico ham-active-ico')}` : stageTrackerIcon(sg.number, 'ham-ico ham-active-ico'); - // The cap chevron is the ✓ only once the PR is merged; until then - // the column is the row's history and wears the history mark. - if (sg.cap) inner = sg.terminal ? stageTrackerIcon(sg.number, 'ham-ico') : stageTrackerIcon('history', 'ham-ico ham-history-ico', 'History — no decisions or actions recorded yet'); - else if (active) inner = gateCue + workIco + (decision ? stageTrackerDecisionTriggerHtml(decision, word, tip) : word) + (actorIco || holderIco); - else inner = stageTrackerIcon(sg.number, 'ham-ico'); - return `
  • ${inner}
  • `; - }).join(''); - } - - // Compact strips retain their column alignment; the current step gets a - // full-width caption so detours and the next actor never need a hover. - function stageTrackerCurrentStageHtml(item, stages, range, nowMs) { - if (item.superseded && item.superseded.closer_pr) return `

    ${esc(stageTrackerHeadline(item) + (item.superseded.keep_reason ? " · " + item.superseded.keep_reason : ""))}

    `; - const active = stageTrackerSegments(item, stages, nowMs).find(sg => sg.state === 'active' - && (!range || range.from == null || sg.number >= range.from) - && (!range || range.to == null || sg.number <= range.to)); - if (!active) return ''; - const actor = active.cap ? '' : stageTrackerActorTip(item); - const regressed = stageTrackerRegressionText(item, Date.now()); - const text = active.short + (active.detour && active.detour.text !== active.short ? ' · ' + active.detour.text : '') + actor + (regressed ? ' · ' + regressed : ''); - return `

    ${esc(text)}

    `; - } - - // "040 Covered by PR" — the stage code plus the strip word the payload - // names for it (the code alone when the stage table is not loaded yet). - function stageTrackerStageWord(n) { - const num = Number(n) || 0; - const st = ((_stageTracker && _stageTracker.stages) || []).find(s => Number(s.number) === num); - const code = String(num).padStart(3, '0'); - return st && (st.short || st.label) ? code + ' ' + (st.short || st.label) : code; - } - - // Modifiers that park an item on a person. A regression on a row that - // carries none of these and sits on a hive-driven stage is the hive's - // to work through, so the dashboard must not dress it as a human call. - const STAGE_TRACKER_HUMAN_MODS = ['hold', 'unauthorized', 'needs-human', 'needs-decision', 'needs-rebase', 'blocked', 'stalled']; - const STAGE_TRACKER_HANDLED_TEXT = 'stage ↓'; - const STAGE_TRACKER_HANDLED_NOTE = 'the hive is handling it — no action needed; clears on the next forward step'; - - // True when the item is regressed but nothing about it waits on a - // person: no human-gate modifier and not on a human-gated stage. Such a - // row gets a muted "stage ↓" pill and stays out of "Needs attention". - function stageTrackerRegressionHandled(item) { - const mods = Array.isArray(item.modifiers) ? item.modifiers : []; - if (mods.indexOf('regressed') < 0) return false; - if (mods.some(m => STAGE_TRACKER_HUMAN_MODS.indexOf(m) >= 0)) return false; - return STAGE_TRACKER_ATTENTION_STAGES.indexOf(Number(item.stage) || 0) < 0; - } - - // The regressed pill's explanation: which stage the item fell from and - // to, when, and the reason recorded with the fall — so "regressed" never - // needs a trip to the store to read. '' when the item is not regressed. - // A hive-handled regression adds the note that nobody needs to act. - function stageTrackerRegressionText(item, nowMs) { - const mods = Array.isArray(item.modifiers) ? item.modifiers : []; - const from = Number(item.regressed_from) || 0; - if (mods.indexOf('regressed') < 0 || !from) return ''; - const cur = Number(item.stage) || 0; - const to = Number(item.regressed_to) || cur; - const atMs = Date.parse(item.regressed_at || ''); - let text = 'regressed: ' + stageTrackerStageWord(from) + ' → ' + stageTrackerStageWord(to); - if (!isNaN(atMs)) text += ' at ' + agentNowClockTime(atMs, nowMs || Date.now()); - if (item.regressed_reason) text += ' because ' + String(item.regressed_reason); - if (cur && cur !== to) text += ' · now ' + stageTrackerStageWord(cur); - if (stageTrackerRegressionHandled(item)) text += ' · ' + STAGE_TRACKER_HANDLED_NOTE; - return text; - } - - // The name of one trail hop. The payload's history entries carry - // {number, slug, at, ...} (StageTrackerHop); the strip word for the - // number wins, the slug stands in before the stage table is loaded, and - // '' means the hop cannot be named and is left out of the trail. - function stageTrackerHopName(h) { - if (!h || typeof h !== 'object') return ''; - const raw = h.number !== undefined ? h.number : h.stage; - const num = Number(raw); - if (raw !== undefined && raw !== null && raw !== '' && !isNaN(num)) { - if (num === 0) return 'Open'; - const st = ((_stageTracker && _stageTracker.stages) || []).find(s => Number(s.number) === num); - if (st && (st.short || st.label)) return st.short || st.label; - } - return h.slug ? String(h.slug) : ''; - } - - // "Trail: CI / Review → Needs human decision" — the last few hops of the - // item's history by stage name; '' when fewer than two hops can be named. - function stageTrackerTrailText(item) { - const hist = Array.isArray(item && item.history) ? item.history : []; - const names = hist.slice(-STAGE_TRACKER_TRAIL_HOPS).map(stageTrackerHopName).filter(Boolean); - return names.length > 1 ? names.join(' → ') : ''; - } - - // Row tooltip: headline, reason, repo, author, flags, since, recent hops. - function stageTrackerTooltip(item, nowMs) { - const ak = item.author_kind || ''; - // Plain words for author_kind in hover text (hivecommons/hive#15394). - const akPlain = { human: 'person', clanker: 'agent', hive: 'hive', bot: 'bot' }; - const mods = Array.isArray(item.modifiers) ? item.modifiers : []; - const sinceMs = Date.parse(item.stage_since || ''); - const trail = stageTrackerTrailText(item); - const openHeld = (Number(item.stage) || 0) === 0 && mods.indexOf('hold') >= 0; - const lines = openHeld - ? [stageTrackerHeadline(item) + (item.caption || item.reason ? ' · ' + (item.caption || item.reason) : '') + (item.repo ? ' · ' + item.repo : '')] - : [stageTrackerHeadline(item), item.caption || item.reason || '', item.repo || '']; - if (item.author || ak) lines.push('Author: ' + (item.author ? '@' + item.author : '') + (ak ? ' (' + (akPlain[ak] || ak) + (item.author_kind_source === 'inferred' ? ', inferred' : '') + ')' : '') + (item.tier ? ' · ' + item.tier : '')); - if (item.origin) lines.push('Origin: origin/' + item.origin); - if (item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length) lines.push('Covering PR: ' + item.linked_prs.map(lp => Number(lp.number) || 0).sort((x, y) => x - y).map(n => '#' + n).join(', ')); - else if (item.kind === 'issue' && item.linked_pr) lines.push('Covering PR: #' + item.linked_pr + (typeof stageTrackerLineageClause === 'function' ? stageTrackerLineageClause(item) : '')); - const actorLine = stageTrackerActorTip(item); - if (actorLine) lines.push(actorLine.replace(/^ · /, '')); - if (typeof stageTrackerNewLines === 'function') lines.push(...stageTrackerNewLines(item, nowMs)); - const blockedPR = mods.indexOf('blocked') >= 0 ? stageTrackerBlockedOnPR(item) : null; - if (blockedPR) lines.push(blockedPR.tip); - if (typeof stageTrackerTrainLines === 'function') lines.push(...stageTrackerTrainLines(item)); - // Guarded: the test harnesses load helpers by name, and this one is additive. - const adoption = typeof stageTrackerAdoptionTip === 'function' ? stageTrackerAdoptionTip(item) : ''; - if (adoption) lines.push('Adoption: ' + adoption + (typeof stageTrackerAdoptOffered === 'function' && stageTrackerAdoptOffered(item) ? ' (row menu → Adopt)' : '')); - const presence = typeof stageTrackerPresenceTip === 'function' ? stageTrackerPresenceTip(item, nowMs) : ''; - if (presence) lines.push('Presence: ' + presence); - const rework = typeof stageTrackerReworkTip === 'function' ? stageTrackerReworkTip(item, nowMs) : ''; - if (rework) lines.push('Rework: ' + rework); - const push = typeof stageTrackerPushTip === 'function' ? stageTrackerPushTip(item, nowMs) : ''; - if (push) lines.push('Push: ' + push); - if (mods.length) lines.push('Flags: ' + mods.map(m => STAGE_TRACKER_MOD_TEXT[m] || m).join(', ')); - const stale = stageTrackerStaleLabelsText(item); - if (stale) lines.push(stale); - const deferred = stageTrackerDeferredMods(item); - if (deferred.length) lines.push(STAGE_TRACKER_DEFERRED_NOTE + deferred.map(m => STAGE_TRACKER_MOD_TEXT[m] || m).join(', ')); - if (item.sentinel_alert && deferred.indexOf(STAGE_TRACKER_SENTINEL_CHIP) < 0) lines.push(stageTrackerSentinelTip(item)); - const regressed = stageTrackerRegressionText(item, nowMs); - if (regressed) lines.push(regressed.charAt(0).toUpperCase() + regressed.slice(1)); - if (mods.indexOf('unauthorized') >= 0 && item.unauthorized) lines.push('Unauthorized: ' + item.unauthorized); - if (mods.indexOf('hold') >= 0 && typeof stageTrackerHoldPill === 'function' && stageTrackerHoldPill(item)) lines.push(stageTrackerHoldPill(item)); - if (sinceMs) lines.push('Since ' + agentNowClockTime(sinceMs, nowMs) + ' · ' + agentNowAgo(nowMs - sinceMs)); - if (trail) lines.push('Trail: ' + trail); - // Say it once: a line the caption already said is not repeated (hivecommons/hive#15394). - return lines.filter((l, i) => l && lines.indexOf(l) === i).join('\n'); - } - - // The sentinel chip: drawn in the chip area (beside needs rebase / - // regressed) on every lane but the one whose word already says it. - // Pure: the "supersedes #N" chip on a live PR that replaced a closed - // original (`supersedes`: {number, url, closed_at, open} — the hive's - // close-first supersession, hivecommons/hive#15135). The closed PR is - // never a row; this chip is its only trace. '' without one. - function stageTrackerSupersedesTip(item, nowMs) { - const sp = item && item.supersedes; - if (!sp || !(Number(sp.number) > 0)) return ''; - const ago = stageTrackerAgoText(Date.parse(sp.closed_at || ''), nowMs); - if (sp.open) return 'Replaces #' + Number(sp.number) + ' (left open with the note' + (ago ? ', ' + ago : '') + ')'; - return 'Replaces #' + Number(sp.number) + ' (closed' + (ago ? ' ' + ago : '') + ')'; - } - function stageTrackerSupersedesChipHtml(item, nowMs) { - const tip = stageTrackerSupersedesTip(item, nowMs); - if (!tip) return ''; - const sp = item.supersedes; - const text = 'supersedes #' + Number(sp.number); - const attrs = `class="ham-badge ham-badge-supersedes" title="${esc(tip)}" aria-label="${esc(tip)}"`; - if (sp.url) return `${esc(text)}`; - return `${esc(text)}`; - } - function stageTrackerSentinelChipHtml(item) { - if (!item || !item.sentinel_alert || stageTrackerSentinelInLane(item) || stageTrackerSentinelAsSuffix(item) || stageTrackerDeferredMods(item).indexOf(STAGE_TRACKER_SENTINEL_CHIP) >= 0) return ''; - return `${esc(STAGE_TRACKER_SENTINEL_CHIP)}`; - } - - // Pure: the hold pill text from the row's `hold` provenance ('' when the - // pass could not attribute the hold, so the plain "hold" word stays). - function stageTrackerHoldPill(item) { - const h = item && item.hold; - if (!h || !h.by) return ''; - if (h.pill) return h.pill; - const who = h.by === 'hive' ? 'hive' : '@' + h.by; - return 'Held by ' + who + (h.reason ? ' · ' + h.reason : ''); - } - // Pure: the hold pill's hover text — who, why, since when. - function stageTrackerHoldTip(item, nowMs) { - const h = item && item.hold; - if (!h || !h.by) return ''; - const sinceMs = Date.parse(h.since || ''); - const lines = [stageTrackerHoldPill(item)]; - if (h.by === 'hive') lines.push(h.source === 'reporter-trust' ? 'The hive set this hold itself: the linked issue\'s reporter is below the trust the gate requires. Release it to let the lane merge, or keep it until a maintainer has reviewed the reporter.' : 'The hive set this hold itself.'); - if (sinceMs) lines.push('Since ' + agentNowClockTime(sinceMs, nowMs) + ' · ' + agentNowAgo(nowMs - sinceMs)); - return lines.join('\n'); - } - - function stageTrackerChipsHtml(item) { - const sentinel = stageTrackerSentinelChipHtml(item) + (typeof stageTrackerAdoptionChipHtml === 'function' ? stageTrackerAdoptionChipHtml(item) : '') + (typeof stageTrackerPresenceChipHtml === 'function' ? stageTrackerPresenceChipHtml(item) : '') + (typeof stageTrackerPushChipHtml === 'function' ? stageTrackerPushChipHtml(item, Date.now()) : '') + (typeof stageTrackerReroutePillHtml === 'function' ? stageTrackerReroutePillHtml(item) : '') + (typeof stageTrackerSupersedesChipHtml === 'function' ? stageTrackerSupersedesChipHtml(item, Date.now()) : '') + (typeof stageTrackerOverlapBadgeHtml === 'function' ? stageTrackerOverlapBadgeHtml(item) : ''); - const mods = (Array.isArray(item.modifiers) ? item.modifiers.slice() : []) - .sort((x, y) => STAGE_TRACKER_MOD_PRIORITY.indexOf(x) - STAGE_TRACKER_MOD_PRIORITY.indexOf(y)); - if (!mods.length) return sentinel; - // A regression the hive is working through yields the lead pill to any - // other modifier and, alone, draws muted as "stage ↓" rather than red. - const handled = stageTrackerRegressionHandled(item); - if (handled && mods.length > 1) mods.push(mods.shift()); - let text = handled && mods[0] === 'regressed' ? STAGE_TRACKER_HANDLED_TEXT : (STAGE_TRACKER_MOD_TEXT[mods[0]] || mods[0].replace(/-/g, ' ')); - // A hold the stage-label pass could attribute names who set it and why - // ("Held by hive · reporter trust (issue #N by @X, contributor)"), so the - // operator is not left reading "hold +1" (hivecommons/hive#15020). - // Guarded: the test harnesses load helpers by name, and this one is additive. - const holdPill = mods[0] === 'hold' && typeof stageTrackerHoldPill === 'function' ? stageTrackerHoldPill(item) : ''; - if (holdPill) text = holdPill; - // A row the scheduler withholds for open GitHub "blocked by" dependencies names them (hivecommons/hive#14765); - // one blocked on a PR (hive:blocked-on marker) names it and links to it (hivecommons/hive#14952). - const blockedPR = mods[0] === 'blocked' ? stageTrackerBlockedOnPR(item) : null; - if (mods[0] === 'blocked' && Array.isArray(item.blocked_on) && item.blocked_on.length) text = stageTrackerBlockedTip(item); - else if (blockedPR) text = 'blocked on ' + blockedPR.short; - // A blocked row with a hive:recheck-after deadline ("blocked until ") names when the sweep re-checks it. - const recheck = mods[0] === 'blocked' ? /^blocked until (\S+)/i.exec(String(item.bucket_reason || '')) : null; - const recheckMs = recheck ? Date.parse(recheck[1]) : NaN; - if (!isNaN(recheckMs)) text += ' · re-check at ' + agentNowClockTime(recheckMs, Date.now()); - // The regressed pill (lead or folded into "+1") explains itself on - // hover; failing that, a draft pill (lead or folded) does. - const regressed = stageTrackerRegressionText(item, Date.now()); - // An unauthorized pill names the missing App permission and the human step; - // the regressed pill explains itself; a blocked pill names what it waits on; - // failing all three, a draft pill does. - const anyBlockedPR = mods.indexOf('blocked') >= 0 ? stageTrackerBlockedOnPR(item) : null; - const tip = (mods.indexOf('unauthorized') >= 0 && String(item.unauthorized || '').trim()) || regressed - || (holdPill && typeof stageTrackerHoldTip === 'function' ? stageTrackerHoldTip(item, Date.now()) : '') - || (mods.indexOf('blocked') >= 0 && Array.isArray(item.blocked_on) && item.blocked_on.length ? 'Withheld from the scanner until ' + item.blocked_on.join(', ') + (item.blocked_on.length > 1 ? ' close' : ' closes') : '') - || (anyBlockedPR ? anyBlockedPR.tip : '') - || (mods.indexOf('draft') >= 0 ? STAGE_TRACKER_DRAFT_TIP : ''); - const cls = 'ham-mod-' + mods[0] + (handled && mods[0] === 'regressed' ? ' ham-mod-handled' : ''); - const inner = `${esc(text)}${mods.length > 1 ? ' +' + (mods.length - 1) : ''}`; - // The lead pill of a row blocked on a PR is the link to that PR. - if (blockedPR && blockedPR.url) return sentinel + `${inner}`; - // A lead needs-human / needs human decision pill opens the decision - // popover (what to decide, who asked, the applicable actions) instead - // of a native tooltip. - // A hive-set hold is a decision too (release or keep): its pill opens the same popover. - const decision = (mods[0] === 'needs-human' || mods[0] === 'needs-decision' || (holdPill && item.hold && item.hold.by === 'hive')) && typeof stageTrackerDecisionOf === 'function' ? stageTrackerDecisionOf(item) : null; - if (decision) return sentinel + stageTrackerDecisionTriggerHtml(decision, inner, tip, 'ham-badge ham-badge-mod ' + cls); - return sentinel + `${inner}`; - } - - /* ---- "Did I act on this?" badge ------------------------------------ - Owner (2026-10-28): "I need a way to see if I selected an action on - an item so I can keep track of whether or not I addressed it. - Hovering over the indicator should show me what action I requested." - The server keeps a ledger of every row action submitted from the - dashboard (operator_actions.go) and the tracker payload carries the - newest one per item as `last_operator_action` with a derived state: - waiting (same stage, recent), addressed (the item moved on, or the - control asked for is in effect), stuck (same stage past the window), - pending (Let hive decide still running), failed. The row wears a - history badge (clock + arrow, with the action count) in the cap cell - — neutral at rest, amber when stuck, red when failed, dotted while - pending — whose in-app tooltip names the action, - when, the outcome and what hive did next. The in-flight spinner (the - request still on the wire) is a different thing drawn on the chevron; - this badge appears once the server has recorded the action. */ - const STAGE_TRACKER_ACTED_LABELS = { - approve: 'Approve', 'give-direction': 'Give direction', 'close-superseded': 'Close as superseded', wontfix: "Close as won't-fix", 'close-read': 'Closed', - 'let-hive-decide': 'Let hive decide', hold: 'Hold', release: 'Release hold', 'accept-triage': 'Accept triage', 'mark-needs-human': 'Mark needs-human', - 'queue-merge': 'Approve and let hive merge', 'merge-now': 'Merge now as maintainer', - adopt: 'Adopt', 'adopt-now': 'Adopt now', reroute: 'Reroute to another clanker', - }; - // "Rebase, then merge as maintainer" is merge-now on a row that needs a - // rebase (hivecommons/hive#14822): the server relabels the option and - // answers 202 rebase-queued; the follow-through's steps come back in - // last_operator_action.followed[] as hops without a stage number. - const STAGE_TRACKER_REBASE_MERGE_LABEL = 'Rebase, then merge as maintainer'; - const STAGE_TRACKER_ACTION_REBASE_QUEUED = 'rebase-queued'; - function stageTrackerNeedsRebase(item) { - if (!item) return false; - if ((Array.isArray(item.modifiers) ? item.modifiers : []).indexOf('needs-rebase') >= 0) return true; - if ((Array.isArray(item.labels) ? item.labels : []).some(l => String(l).toLowerCase() === 'needs-rebase')) return true; - const rm = item.rebase_merge; - return !!(rm && rm.state && rm.state !== 'merged' && rm.state !== 'failed'); - } - function stageTrackerRebaseMergeLive(item) { - const rm = item && item.rebase_merge; - return !!(rm && (rm.state === 'approved' || rm.state === 'rebasing' || rm.state === 'ci-pending')); - } - const STAGE_TRACKER_ACTED_STATES = ['waiting', 'addressed', 'stuck', 'pending', 'failed', 'executing', 'blocked']; - const STAGE_TRACKER_ACTED_FILTERS = ['any', 'awaiting', 'acted', 'stuck']; - const STAGE_TRACKER_ACTED_STUCK_DEFAULT_S = 30 * 60; - // Every state wears the same history mark (the clock-and-arrow the - // column header uses): the badge is an audit affordance, never a "done" - // tick. Colour and border carry the state; the aria-label says it in words. - const STAGE_TRACKER_HISTORY_ICON = ''; - const STAGE_TRACKER_ACTED_GLYPH = { waiting: STAGE_TRACKER_HISTORY_ICON, addressed: STAGE_TRACKER_HISTORY_ICON, stuck: STAGE_TRACKER_HISTORY_ICON, pending: STAGE_TRACKER_HISTORY_ICON, failed: STAGE_TRACKER_HISTORY_ICON, executing: STAGE_TRACKER_HISTORY_ICON, blocked: STAGE_TRACKER_HISTORY_ICON }; - function stageTrackerActedLabel(action) { return STAGE_TRACKER_ACTED_LABELS[action] || String(action || '').replace(/-/g, ' '); } - // Pure: the record a row's badge reads — the item's own, else (an issue - // row drawn over its single covering PR) that PR's; null when none. - function stageTrackerActedSource(item) { - if (!item) return null; - // A failure this client just saw outranks an older server record - // (hivecommons/hive#15436): the badge goes red at once. - const failed = typeof stageTrackerActionFailureOf === 'function' ? stageTrackerActionFailureOf(item) : null; - if (failed) return { item, action: failed, count: (Number(item.operator_action_count) || 0) + 1 }; - if (item.last_operator_action) return { item, action: item.last_operator_action, count: Number(item.operator_action_count) || 1 }; - const linked = Array.isArray(item.linked_prs) ? item.linked_prs : []; - if (item.kind === 'issue' && linked.length === 1 && linked[0].last_operator_action) { - return { item: { repo: item.repo, number: linked[0].number, kind: 'pr', stage: linked[0].stage || 0, modifiers: linked[0].modifiers || [], reason: linked[0].reason || '', caption: linked[0].caption || '', decision_needed: linked[0].decision_needed || null, decided: linked[0].decided || null }, action: linked[0].last_operator_action, count: Number(linked[0].operator_action_count) || 1 }; - } - return null; - } - // Pure: the badge state as of nowMs. The server judges `stuck` when it - // builds the payload; a row still `waiting` ages into `stuck` here once - // the window passes, so the badge turns amber between refreshes too. - function stageTrackerActedState(action, nowMs) { - if (!action) return ''; - let state = STAGE_TRACKER_ACTED_STATES.indexOf(action.state) >= 0 ? action.state : 'waiting'; - if (state === 'waiting') { - const at = Date.parse(action.at || ''); - const windowMs = (Number(action.stuck_after_seconds) || STAGE_TRACKER_ACTED_STUCK_DEFAULT_S) * 1000; - if (at && (Number(nowMs) || Date.now()) - at >= windowMs) state = 'stuck'; - } - return state; - } - // Pure: minutes/hours/days in words for the badge tooltip. - function stageTrackerActedAgo(ms) { - const min = Math.max(0, Math.floor((Number(ms) || 0) / 60000)); - if (min < 1) return 'just now'; - if (min < 60) return min + ' min ago'; - const h = Math.floor(min / 60); - if (h < 48) return h + ' h ago'; - return Math.floor(h / 24) + ' d ago'; - } - function stageTrackerActedOutcomeWords(action) { - switch (action.outcome) { - case 'applied': return 'done' + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); - case 'no-op': return 'nothing changed' + (action.detail ? ': ' + stageTrackerActedPlain(action.detail) : ''); - case 'failed': return 'failed' + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); - case 'pending': return action.action === 'merge-now' ? 'rebasing, then merging…' : (action.action === 'queue-merge' ? 'approved — hive will merge on the next tick once CI is green' : 'the hive is deciding…'); - case 'executing': return (action.detail ? stageTrackerActedPlain(action.detail) : 'decided — the hive is carrying it out…'); - case 'no-effect': return "hasn't taken effect" + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); - case 'blocked': return 'blocked' + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); - case 'superseded-by-state-change': return 'the item moved on by itself'; - } - return action.outcome || ''; - } - // Pure: the stage in plain words, never a code ("Merge gate", not 085). - function stageTrackerActedStageName(n) { - const num = Number(n) || 0; - const st = ((_stageTracker && _stageTracker.stages) || []).find(s => Number(s.number) === num); - return st && (st.short || st.label) ? (st.short || st.label) : (num ? 'stage ' + num : 'an unknown stage'); - } - // Pure: operator-facing gloss for the slugs the hive writes into stage - // reasons and endpoint status words. Unknown input is returned with its - // dashes and colons spelled as words so nothing reads like a code. - const STAGE_TRACKER_ACTED_PLAIN = { - 'contributor-lane:changes-requested': 'a reviewer requested changes; needs a new commit', - 'contributor-lane:approved': 'a reviewer approved it', - 'contributor-lane:ci-failed': 'CI failed on the latest commit', - 'needs-rebase': 'needs a rebase onto the base branch', - 'needs-human': 'waiting on a person', - 'needs-decision': 'waiting on your decision', - unparked: 'released to the hive', - 'approval-commented': 'your approval was posted as a comment', - closed: 'closed on GitHub', - held: 'put on hold', - released: 'hold released', - 'already accepted': 'it was already accepted', - 'approval-recorded': 'recorded your approval', 'rebase-kicked': 'started the rebase', rebased: 'rebased it onto the base branch', 'ci-green': 'saw CI go green', merged: 'merged it', - 'rebase-conflict': 'the rebase conflicts', 'ci-red': 'CI went red on the rebased head', 'rebase-timeout': 'the rebase did not land in time', 'head-not-pushable': 'the hive cannot push to this fork', 'foreign-head': 'the head moved after your approval, pushed by someone other than the hive', - }; - function stageTrackerActedPlain(text) { - const t = String(text || '').trim(); - if (!t) return ''; - if (STAGE_TRACKER_ACTED_PLAIN[t]) return STAGE_TRACKER_ACTED_PLAIN[t]; - if (/^hive decided: /.test(t)) return t.replace(/^hive decided: /, 'the hive decided: ').replace(/ \(([^)]+)\)/, (m, r) => ' (rule: ' + r.replace(/[-_:]/g, ' ') + ')'); - if (/^decided: /.test(t)) return t.replace(/^decided: /, 'the hive decided: ').replace(/ \(([^)]+)\)/, (m, r) => ' (rule: ' + r.replace(/[-_:]/g, ' ') + ')'); - if (/^[a-z0-9]+([-_:][a-z0-9]+)+$/.test(t)) return t.replace(/[-_:]/g, ' '); - // Slugs inside a sentence ("… — contributor-lane:changes-requested blocks it"). - return t.replace(/\b[a-z0-9]+(?:[-_:][a-z0-9]+)+\b/g, m => STAGE_TRACKER_ACTED_PLAIN[m] || (/[a-z]/.test(m) ? m.replace(/[-_:]/g, ' ') : m)); - } - // Row-menu action id each ledger action was submitted under, so the - // option the owner just took is not offered back to them. - const STAGE_TRACKER_ACTED_OPTION_ID = { 'let-hive-decide': 'decide:delegate', approve: 'decide:approve', 'give-direction': 'decide:direction', 'close-superseded': 'decide:close-superseded', wontfix: 'decide:close-wontfix', 'close-read': 'decide:close-read', 'accept-triage': 'accept-triage', hold: 'hold', 'merge-now': 'decide:merge-now', 'queue-merge': 'decide:queue-merge', 're-author': 'decide:re-author', adopt: 'decide:adopt', 'adopt-now': 'decide:adopt-now', reroute: 'decide:reroute' }; - // Pure: what the owner can still do when their action changed nothing - // (no-op) or the item has not moved (stuck): the enabled options from - // the row's decision_needed payload, minus the one just taken. - function stageTrackerActedOptions(item, action, state) { - if (!(action.outcome === 'no-op' || state === 'stuck' || state === 'failed' || state === 'blocked')) return ''; - const dn = item && item.decision_needed; - const opts = dn && Array.isArray(dn.options) ? dn.options : []; - const taken = STAGE_TRACKER_ACTED_OPTION_ID[action.action] || ''; - return opts.filter(o => o && o.enabled && o.action !== taken && o.label).map(o => o.label).join(' · '); - } - // Pure: the tooltip — the decision trail in plain words, in the order - // every cue on the row uses: what it is waiting on → what you chose → - // what the hive did next (who, when). ≤ 2 short lines per fact. - function stageTrackerActedTip(item, nowMs) { - const src = stageTrackerActedSource(item); - if (!src) return ''; - const a = src.action; - nowMs = Number(nowMs) || Date.now(); - const state = stageTrackerActedState(a, nowMs); - const atMs = Date.parse(a.at || '') || nowMs; - const me = !a.actor || (window._hiveUser && a.actor.toLowerCase() === String(window._hiveUser).toLowerCase()); - const who = me ? 'You' : '@' + a.actor; - const label = stageTrackerActedLabel(a.action) + (a.target ? ' ' + a.target : ''); - const ago = stageTrackerActedAgo(nowMs - atMs); - const stageNow = stageTrackerActedStageName(src.item.stage); - const waitingOn = stageTrackerActedPlain(src.item.caption || src.item.reason); - const lines = []; - const dec = src.item.decided || (item && item.decided); - if (dec && typeof stageTrackerDecidedLead === 'function') lines.push(stageTrackerDecidedLead(dec, a, nowMs)); - else if (state === 'addressed') lines.push('Addressed — now at ' + stageNow + '.'); - else if (state === 'stuck') lines.push('Still at ' + stageNow + ' ' + ago.replace(/ ago$/, '') + ' after you asked' + (waitingOn ? ' — hive says: ' + waitingOn : '') + '.'); - else if (state === 'pending') lines.push('At ' + stageNow + ' while the hive decides.'); - else if (state === 'failed') lines.push('Still at ' + stageNow + (a.progress ? ' — ' + stageTrackerActedPlain(a.progress) : ' — try again, or act on GitHub') + '.'); - else if (state === 'executing') lines.push('At ' + stageNow + ' — the hive is carrying it out' + (a.progress ? ': ' + stageTrackerActedPlain(a.progress) : '') + '.'); - else if (state === 'blocked') lines.push('Blocked at ' + stageNow + (a.progress ? ' — ' + stageTrackerActedPlain(a.progress) : ' — the hive lacks a permission it needs') + '.'); - else lines.push('At ' + stageNow + (waitingOn ? ' — ' + waitingOn : '') + '.'); - lines.push(who + ' chose ' + label + ' · ' + agentNowClockTime(atMs, nowMs) + ' (' + ago + ') · ' + stageTrackerActedOutcomeWords(a) + '.'); - if (a.progress && state !== 'executing' && state !== 'blocked' && state !== 'failed') lines.push('Hive now: ' + stageTrackerActedPlain(a.progress) + '.'); - if (a.human) lines.push('You can: ' + a.human); - else if (state === 'executing') lines.push('Nothing for you to do — the badge updates when the adoption lands.'); - if (a.note) lines.push('Your note: ' + a.note); - const options = stageTrackerActedOptions(src.item, a, state); - if (options) lines.push('Options: ' + options + '.'); - const followed = Array.isArray(a.followed) ? a.followed : []; - followed.slice(-3).forEach(h => { - const hopMs = Date.parse(h.at || '') || nowMs; - if (!(Number(h.number) > 0) && h.slug) lines.push('Then the hive ' + stageTrackerActedPlain(h.slug) + (h.reason ? ' — ' + h.reason : '') + ' · ' + stageTrackerActedAgo(nowMs - hopMs) + '.'); - else lines.push('Then the hive ' + (h.regressed ? 'sent it back to ' : 'moved it to ') + stageTrackerActedStageName(h.number) + (h.reason ? ' — ' + stageTrackerActedPlain(h.reason) : '') + ' · ' + stageTrackerActedAgo(nowMs - hopMs) + '.'); - }); - if (src.count > 1) lines.push((src.count - 1) + ' earlier action' + (src.count > 2 ? 's' : '') + ' on this item.'); - return lines.join('\n'); - } - // Pure: the badge HTML ('' when the row has no recorded action). An - // in-app tooltip (the shared .config-info portal: hover or focus), - // never a native title. - function stageTrackerActedBadgeHtml(item, nowMs) { - const src = stageTrackerActedSource(item); - if (!src) return ''; - // While this client is still waiting on its own decision the pill's - // "Hive deciding…" caption is the one cue (#15126); a server-side - // pending action still wears the dotted history badge (#15200). - if (typeof stageTrackerRowDeciding === 'function' && (stageTrackerRowDeciding(stageTrackerItemKey(src.item)) || stageTrackerRowDeciding(stageTrackerItemKey(item)))) return ''; - let state = stageTrackerActedState(src.action, nowMs); - const dec = src.item.decided || item.decided; - if (dec) state = dec.effect === 'timed-out' ? 'stuck' : (dec.effect === 'landed' ? 'addressed' : 'waiting'); - const id = 'ham-acted-tip-' + String((src.item.repo || '') + '-' + (Number(src.item.number) || 0)).replace(/[^A-Za-z0-9_-]/g, '-'); - const tip = stageTrackerActedTip(item, nowMs); - const short = dec ? (dec.word || stageTrackerActedLabel(src.action.action)) + ' — ' + (dec.verdict || '') : stageTrackerActedLabel(src.action.action); - const n = Math.max(1, Number(src.count) || 1); - const label = 'History: ' + n + ' action' + (n === 1 ? '' : 's') + ' — ' + short + ' — ' + state; - return `${STAGE_TRACKER_ACTED_GLYPH[state] || STAGE_TRACKER_HISTORY_ICON}${esc(tip).replace(/\n/g, '
    ')}
    `; - } - // Pure: the Decisions filter. awaiting = parked on a person with no - // action recorded yet (or the last one failed / was overtaken without - // moving it); acted = any action recorded; stuck = acted and still at - // the same stage past the window. - function stageTrackerActedMatches(item, mode, nowMs) { - if (!mode || mode === 'any') return true; - const src = stageTrackerActedSource(item); - const state = src ? stageTrackerActedState(src.action, nowMs) : ''; - switch (mode) { - case 'acted': return !!src; - case 'stuck': return state === 'stuck'; - case 'awaiting': return !!stageTrackerDecisionTarget(item) && (!src || state === 'failed'); - } - return true; - } - - // Ghost strip for a title line: the lead cell (Open..Claimed) carries - // the item's own number + title, the PR cell (PR in progress..Merge gate) - // the given refs, and the cap cell the modifier chip, bottom-aligned so - // it sits on the last title line, directly over the strip's right end. - // The since column is an empty spacer here (same width as the strip - // row's, which carries the time on step): a wrapped title must not float - // the age away from the chevrons it describes. - function stageTrackerHeadColsHtml(prRefs, leadHtml, chipsHtml) { - const wide = !(prRefs && prRefs.length); - return `
    1. ${leadHtml || ''}
    2. ${wide ? '' : `
    3. ${prRefs.join('')}
    4. `}
    5. ${chipsHtml || ''}
    `; - } - - function stageTrackerSinceHtml(item, nowMs) { - const mods = Array.isArray(item.modifiers) ? item.modifiers : []; - let sinceMs = Date.parse(item.stage_since || ''); - // A blocked row without stage_since still shows its age, from created_at. - if (!sinceMs && mods.indexOf('blocked') >= 0) sinceMs = stageTrackerOpenSince(item).ms; - const stalled = mods.indexOf('stalled') >= 0; - return `${esc(sinceMs ? stageTrackerShortAgo(nowMs - sinceMs) : '')}`; - } - - const STAGE_TRACKER_LINKED_TIP = "linked PR, shown on its issue's row"; - // Issue numbers that list each covering PR, by "repo#pr", for the PRs - // listed by more than one open issue (so a row can say "also under #N"). - function stageTrackerSharedPRs(items) { - const by = {}; - (items || []).forEach(it => { - if (!it || it.kind !== 'issue') return; - (Array.isArray(it.linked_prs) ? it.linked_prs : []).forEach(lp => { - const k = (it.repo || '') + '#' + (Number(lp.number) || 0); - (by[k] = by[k] || []).push(Number(it.number) || 0); - }); - }); - const out = {}; - Object.keys(by).forEach(k => { if (by[k].length > 1) out[k] = by[k].slice().sort((a, b) => a - b); }); - return out; - } - // Hover text for a PR drawn on its issue's row (it rides the PR link: - // the row's hover budget allows no other titled element). Every row but - // the lowest-numbered issue listing the PR also names where else it shows. - function stageTrackerLinkedTip(issue, prNumber, ctx) { - const all = (ctx && ctx.sharedPRs && ctx.sharedPRs[(issue.repo || '') + '#' + (Number(prNumber) || 0)]) || []; - const others = all.filter(n => n !== Number(issue.number)); - const also = others.length && all[0] !== Number(issue.number) ? ' · also under #' + others.join(', #') : ''; - return STAGE_TRACKER_LINKED_TIP + also; - } - // "↳" ahead of such a PR, so the shared row is recognisable as the PR's - // place in the list (aria-label only; no title of its own). - const STAGE_TRACKER_LINKED_GLYPH = '↳'; - - // A covering PR nested under its issue: "[author icon] #N title" at the - // PR column, then the PR's own strip from PR in progress onwards. The - // PR's full tooltip rides its link; the sub-row container has none. - // Pure: a nested PR as a row item of its own — the object every row - // action receives (runRowAction(action, row)), so a ⋯ menu or popover - // on a sub-row acts on THAT PR: its number, repo and head, never the - // parent issue's. `parent` names the issue; `siblings` the other open - // PRs under it (the superseded-by prompt pre-fills the one sibling). - function stageTrackerLinkedPRItem(issue, lp) { - const open = Array.isArray(issue.linked_prs) ? issue.linked_prs.filter(x => x && x.number !== lp.number && stageTrackerLinkedPROpen(x, issue)) : []; - return { repo: issue.repo, number: lp.number, kind: 'pr', title: lp.title || '', url: lp.url || '', author: lp.author || '', author_kind: lp.author_kind || '', - stage: lp.stage || 0, stage_since: lp.stage_since || '', stage_slug: lp.stage_slug || '', modifiers: lp.modifiers || [], deferred_modifiers: lp.deferred_modifiers || [], caption: lp.caption || '', reason: lp.reason || '', - human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', base_ref: lp.base_ref || '', decision_needed: lp.decision_needed || null, - adoption: lp.adoption || null, takeover: lp.takeover || null, superseded: !!lp.superseded, supersedes: lp.supersedes || null, parent: Number(issue.number) || 0, siblings: open.map(x => Number(x.number) || 0), - last_operator_action: lp.last_operator_action || null, operator_action_count: lp.operator_action_count || 0, hold: lp.hold || null, stage_actor: lp.stage_actor || null, claimant: lp.claimant || null, presence: lp.presence || null, rework: lp.rework || null, push: lp.push || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, left_train: lp.left_train || null, overlap: lp.overlap || null, - decided: lp.decided || null, adopted_by: Number(lp.adopted_by) || 0, adopted_by_state: lp.adopted_by_state || '', adopted_from: lp.adopted_from || null, lineage: lp.lineage || null, state: lp.state || '', superseded_by: Number(lp.superseded_by) || 0 }; - } - // Pure: whether a linked PR is still open (not merged / closed / - // superseded). With `issue`, an adopted original whose hive copy is - // listed under the same issue counts as superseded even while GitHub - // still has it open (the write-back gate kept it at 072): the pair - // {original, copy} is one logical PR, so #15495 never reads as "2 - // PRs" needing a human to pick (hivecommons/hive#15495). - function stageTrackerLinkedPROpen(lp, issue) { - if (!lp || lp.superseded || String(lp.state || '') === 'closed' || (Number(lp.stage) || 0) >= STAGE_TRACKER_TERMINAL || (Array.isArray(lp.modifiers) ? lp.modifiers : []).indexOf('merged') >= 0) return false; - const by = Number(lp.superseded_by || lp.adopted_by) || 0; - if (by > 0 && issue && lp.adopted_by_state !== 'closed' && lp.adopted_by_state !== 'closed-twice' && lp.adopted_by_state !== 'copy-failed') { - const linked = Array.isArray(issue.linked_prs) ? issue.linked_prs : []; - if (linked.some(x => x && Number(x.number) === by && String(x.state || '') !== 'closed')) return false; - } - return true; - } - // Pure: an issue's open nested PRs as row items. - function stageTrackerNestedOpenPRs(issue) { - if (!issue || issue.kind === 'pr') return []; - return (Array.isArray(issue.linked_prs) ? issue.linked_prs : []).filter(lp => stageTrackerLinkedPROpen(lp, issue)).map(lp => stageTrackerLinkedPRItem(issue, lp)); - } - // Lineage: where an adopted PR came from (`lineage`: {kind, from_number, - // from_url, from_author, from_author_kind, to_number, to_url, at, - // reason}; optional, nothing without it). #15198 showed the hive's copy - // #15308 "Fixing" with no trace of @thatguywob's #15226 it was adopted - // from, so sending the fix to a hive agent read as a mistake. The chip - // sits beside the PR number on every PR mention (top-level row, single - // covering PR, sub-row) and links to the other PR; the author's kind is - // the icon only, never a word. - const STAGE_TRACKER_LINEAGE_REASON_TIP = { - 'ci-red-contributor-offline': "Hive took this PR over after CI went red and @AUTHOR's agent didn't respond. Original commits kept.", - 'ci-red-contributor-unregistered': "Hive took this PR over after CI went red and @AUTHOR has no agent registered here. Original commits kept.", - 'operator-asked': 'Hive took this PR over at a maintainer\'s request. Original commits kept.', - 'dco-rehome': 'Hive re-homed this PR to repair its DCO sign-off. Original commits kept.', - 'signoff-rehome': 'Hive re-homed this PR so its sign-off survives a squash. Original commits kept.', - 'rebase-rehome': 'Hive re-homed this PR onto its own branch to finish the rebase. Original commits kept.', - 'push-rehome': "Hive re-homed this PR because @AUTHOR's branch could no longer be pushed. Original commits kept.", - 'in-place-stalled': 'Hive re-homed this PR after a review finding sat unaddressed. Original commits kept.' - }; - // Pure: the chip's visible words — "adopted from @thatguywob's #15226 · 6h". - function stageTrackerLineageText(item, nowMs) { - const l = item && item.lineage; - if (!l || !l.kind) return ''; - const ago = stageTrackerAgoText(Date.parse(l.at || ''), nowMs).replace(/ ago$/, ''); - // Once the head moves the chip says so instead of the adoption's age: - // "adopted from @x's #N · pushed 2m ago" (hivecommons/hive#15784). - const pushed = typeof stageTrackerPushLineageSuffix === 'function' ? stageTrackerPushLineageSuffix(item, nowMs) : ''; - const tail = pushed || (ago ? ' · ' + ago : ''); - if (l.kind === 'superseded') return Number(l.to_number) > 0 ? 'superseded by #' + Number(l.to_number) + tail : ''; - if (!(Number(l.from_number) > 0)) return ''; - const whose = l.from_author ? '@' + l.from_author + "'s " : ''; - return (l.kind === 'rebased-by-hive' ? 'rebased by hive from ' : 'adopted from ') + whose + '#' + Number(l.from_number) + tail; - } - // Pure: the hover — why the hive took it over, in plain words. - function stageTrackerLineageTip(item) { - const l = item && item.lineage; - if (!l || !l.kind) return ''; - if (l.kind === 'superseded') return 'Hive took this PR over as #' + Number(l.to_number) + '; this original is closed when that merges.'; - const who = l.from_author ? '@' + l.from_author : 'the contributor'; - const tip = STAGE_TRACKER_LINEAGE_REASON_TIP[l.reason] || STAGE_TRACKER_LINEAGE_REASON_TIP['ci-red-contributor-offline']; - return tip.split('@AUTHOR').join(who) + stageTrackerSupersededOriginalClause(Number(l.from_number), l.from_state); - } - // Pure: the hover clause that says what became of the superseded - // original the chip stands in for — closed, or still open and closing - // when the copy merges; '' when the server does not say. - function stageTrackerSupersededOriginalClause(number, state) { - if (!(number > 0)) return ''; - if (state === 'closed') return ' #' + number + ' is closed as superseded.'; - if (state === 'open') return ' #' + number + ' is superseded and still open; it closes when this merges.'; - return ''; - } - function stageTrackerLineageChipHtml(item, nowMs) { - const text = stageTrackerLineageText(item, nowMs); - if (!text) return ''; - const l = item.lineage; - const tip = stageTrackerLineageTip(item); - const icon = l.kind !== 'superseded' && l.from_author_kind ? stageTrackerIcon(l.from_author_kind, 'ham-author-ico ham-author-' + esc(l.from_author_kind), l.from_author_kind) : ''; - const href = l.kind === 'superseded' ? l.to_url : l.from_url; - const attrs = `class="ham-badge ham-lineage" title="${esc(tip)}" aria-label="${esc(text + ' — ' + tip)}"`; - return href ? `${icon}${esc(text)}` : `${icon}${esc(text)}`; - } - // Pure: the one clause a caption or preview adds after the PR number — - // " (adopted from #15226)"; '' without lineage. An issue row reads its - // single covering PR's lineage. - function stageTrackerLineageClause(item) { - let l = item && item.lineage; - if (!l && item && item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length === 1) l = item.linked_prs[0].lineage; - if (!l || !(Number(l.from_number) > 0) || l.kind === 'superseded') return ''; - return ' (adopted from #' + Number(l.from_number) + ')'; - } - // Pure: the "↳ adopted from #N · you let hive decide 17:51" chip on the - // hive's copy of an adopted PR (hivecommons/hive#15126). - function stageTrackerAdoptedFromChipHtml(pr, nowMs) { - const af = pr && pr.adopted_from; - if (!af || !af.number) return ''; - let text = '↳ adopted from #' + af.number; - if (af.decided_at) { - const what = af.decided_action === 'let-hive-decide' ? 'you let hive decide' : 'you approved'; - text += ' · ' + what + ' ' + agentNowClockTime(Date.parse(af.decided_at), typeof nowMs === 'number' ? nowMs : Date.now()); - } - const tip = 'Hive re-authored #' + af.number + (af.author ? ' (by @' + af.author + ')' : '') + ' as this PR with the same commits and sign-off' + (af.decided_by ? '; the decision on #' + af.number + ' was ' + (af.decided_action || 'yours') + ' by @' + af.decided_by : '') + '.' + (stageTrackerSupersededOriginalClause(Number(af.number), af.state) || ' #' + af.number + ' is closed as superseded when this merges.'); - return `${esc(text)}`; - } - // Pure: the reciprocal of the "↳ #N · under #M" chip (hivecommons/ - // hive#15806) — on the PR drawn here, "also closes #A, #B" naming the - // other listed open issues it resolves, every number a link; past - // three it reads "#A, #B, #C +N" and the hover names every title. - function stageTrackerAlsoClosesChipHtml(lp) { - const list = Array.isArray(lp && lp.also_closes) ? lp.also_closes.filter(li => li && Number(li.number) > 0) : []; - if (!list.length) return ''; - const shown = list.slice(0, 3); - const links = shown.map(li => `#${Number(li.number)}`).join(', '); - const more = list.length > shown.length ? ' +' + (list.length - shown.length) : ''; - const tip = 'this PR also resolves ' + list.map(li => '#' + Number(li.number) + (li.title ? ' (' + li.title + ')' : '')).join(', '); - return `also closes ${links}${more}`; - } - // Pure: the lineage-style chips of a covering PR drawn under an issue — - // its lineage / adopted-from chip, then the also-closes chip; null = none. - function stageTrackerLinkedChipsHtml(lp, lineage) { - const also = typeof stageTrackerAlsoClosesChipHtml === 'function' ? stageTrackerAlsoClosesChipHtml(lp) : ''; - const out = [lineage || '', also].filter(Boolean).join(' '); - return out || null; - } - // The row's inline lead action (tracker-actions.js - // stageTrackerLeadActionHtml), computed against the viewer's own - // permissions on the item's repo; '' where the actions module or a - // viewer context is absent (the node harness lifts this file alone). - // subRows: the linked PRs drawn as sub-rows under an issue row — a lead - // that acts on one of them renders there, never on both rows. - function stageTrackerLeadButtonHtml(item, nowMs, subRows) { - if (typeof stageTrackerLeadActionHtml !== 'function' || typeof stageTrackerActionCtx !== 'function' || !item) return ''; - const ctx = stageTrackerActionCtx(item.repo); - if (!ctx) return ''; - ctx.nowMs = typeof nowMs === 'number' ? nowMs : Date.now(); - return stageTrackerLeadActionHtml(item, ctx, subRows); - } - // PR link, then the lineage chip (null = none), then the base pill. - function stageTrackerPRPillsHtml(ref, lineage, baseRef) { - return ref + (lineage == null ? '' : ' ' + lineage) + (baseRef ? ` ${esc(baseRef)}` : ''); - } - function stageTrackerSubRowHtml(lp, issue, stages, nowMs, ctx) { - const pr = stageTrackerLinkedPRItem(issue, lp); - const superseded = typeof stageTrackerLinkedSupersededText === 'function' ? stageTrackerLinkedSupersededText(lp, issue) : ''; - let ref = stageTrackerPRRef(pr.number, pr.url, pr.author_kind, pr.author, pr.title, (pr.title ? pr.title + ' · ' : '') + (superseded ? superseded + ' · ' + stageTrackerLinkedSupersededTip(lp) : stageTrackerTooltip(pr, nowMs)) + ' · ' + stageTrackerLinkedTip(issue, pr.number, ctx)); - // One line (hivecommons/hive: "consolidate from 3 lines of text to - // 1"): connector, repo chip, author icon + #N + title, the lineage / - // adopted-from chip, then the base pill — all siblings of the flex-row - // PR cell; the title ellipsizes, the pills never shrink. A superseded - // original wears neither pill — it closes as superseded, not as the - // closer of anything. - const lineage = superseded ? '' : ((typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(pr, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(pr, nowMs) : '')); - const chip = ctx && ctx.repoChips ? stageTrackerRepoChipHtml(pr.repo, ctx) : ''; - if (chip) ref = `${chip}${ref}`; - ref = stageTrackerPRPillsHtml(ref, !superseded && typeof stageTrackerLinkedChipsHtml === 'function' ? stageTrackerLinkedChipsHtml(lp, lineage) : (lineage || null), lp.base_ref); - ref = STAGE_TRACKER_LINKED_GLYPH + ref; - if (superseded) { - // The adopted original: one muted line, no chevron track, no row - // tools, no needs-human styling — the copy carries the chevron. The - // trailing note never wraps; the title ellipsizes first (owner, - // hivecommons/hive#15511: "superseded · hive adopted → #15574"). - return `
    -
    - ${stageTrackerHeadColsHtml([ref + ` ${esc(superseded)}`], '', stageTrackerActedBadgeHtml(pr, nowMs))} -
    -
    `; - } - return `
    - ${typeof stageTrackerRowToolsHtml === 'function' ? stageTrackerRowToolsHtml(pr) : ''} -
    - ${stageTrackerHeadColsHtml([ref], '', stageTrackerActedBadgeHtml(pr, nowMs) + stageTrackerChipsHtml(pr) + (typeof stageTrackerLeadButtonHtml === 'function' ? stageTrackerLeadButtonHtml(pr, nowMs) : ''))} -
    -
    -
      ${stageTrackerStripItems(pr, stages, { from: STAGE_TRACKER_PR_COLUMN }, nowMs, ctx)}
    - ${stageTrackerSinceHtml(pr, nowMs)} -
    - ${stageTrackerCurrentStageHtml(pr, stages, { from: STAGE_TRACKER_PR_COLUMN })}${typeof stageTrackerEventHtml === 'function' ? stageTrackerEventHtml(stageTrackerItemKey(pr), ctx) : ''} -
    `; - } - - // Covering PRs of an issue, furthest along first, attention-first - // within a stage (stageTrackerAttentionTier), then longest on step. - // A PR that closes several open issues is drawn once: the server names - // the issue whose row carries it (drawn_under); the other issues list it - // as a compact "under #M" chip instead of a second identical strip - // (hivecommons/hive#14921 under #14910 and #14911). - function stageTrackerLinkedDrawnHere(lp, item) { - const under = Number(lp && lp.drawn_under) || 0; - return !under || under === (Number(item && item.number) || 0); - } - function stageTrackerLinkedElsewhere(item) { - const linked = Array.isArray(item.linked_prs) ? item.linked_prs : []; - return linked.filter(lp => !stageTrackerLinkedDrawnHere(lp, item)).sort((x, y) => (x.number || 0) - (y.number || 0)); - } - function stageTrackerLinkedElsewhereHtml(item) { - return stageTrackerLinkedElsewhere(item).map(lp => `↳ #${Number(lp.number) || 0} · under #${Number(lp.drawn_under)}`).join(' '); - } - function stageTrackerLinkedSorted(item, stages) { - const linked = Array.isArray(item.linked_prs) ? item.linked_prs.filter(lp => stageTrackerLinkedDrawnHere(lp, item) && !stageTrackerLinkedSupersededGone(lp, item)) : (item.linked_pr ? [{ number: item.linked_pr }] : []); - const sinceOf = lp => Date.parse(lp.stage_since || '') || Infinity; - return linked.sort((x, y) => (stageTrackerAnchor(y.stage, stages, 'pr', y) - stageTrackerAnchor(x.stage, stages, 'pr', x)) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0))); - } - - // Pure: a PR whose drawn_under issue is not a row of this page (filtered - // out or on another page) would otherwise be drawn nowhere. The first - // listed issue that covers it draws it instead; later ones chip to that - // row. Returns the rows (same length, nulls kept), copying only changed ones. - function stageTrackerAdoptOrphanPRs(rows) { - const listed = new Set(); - for (const it of rows) if (it && it.kind === 'issue') listed.add(it.repo + '#' + it.number); - const claimedBy = {}; - return rows.map(it => { - if (!it || it.kind !== 'issue' || !Array.isArray(it.linked_prs)) return it; - let changed = false; - const linked = it.linked_prs.map(lp => { - const under = Number(lp && lp.drawn_under) || 0; - if (!under || under === (Number(it.number) || 0) || listed.has(it.repo + '#' + under)) return lp; - const key = it.repo + '#' + lp.number; - if (!(key in claimedBy)) claimedBy[key] = Number(it.number) || 0; - if (claimedBy[key] === (Number(it.number) || 0)) { changed = true; return Object.assign({}, lp, { drawn_under: 0 }); } - changed = true; - return Object.assign({}, lp, { drawn_under: claimedBy[key] }); - }); - return changed ? Object.assign({}, it, { linked_prs: linked }) : it; - }); - } - - // The stage a covering PR drives its issue's strip at: its own, or 040 - // covered-by-PR while it has none yet (an open PR filed seconds ago, - // still waiting for the stage-label pass). One rule for the strip and - // the list order — hive's own #15654 (000 New, nested #15655 drawn as - // "PR in progress") sat at the bottom among the New rows because the - // sort key fell back to the parent's unlabelled stage while the strip - // did not. - const STAGE_TRACKER_COVERED_BY_PR = 40; - function stageTrackerLeadStage(lp) { - return Number(lp && lp.stage) || STAGE_TRACKER_COVERED_BY_PR; - } - // Pure: the row whose live work drives an issue's strip and list place - // — its furthest covering PR, else the issue itself. - function stageTrackerLead(item, stages) { - const linked = item.kind === 'issue' ? stageTrackerLinkedSorted(item, stages) : []; - if (!linked.length) return { lead: item, kind: item.kind, stage: Number(item.stage) || 0, since: item.stage_since || '' }; - const lp = linked[0]; - return { lead: lp, kind: 'pr', stage: stageTrackerLeadStage(lp), since: lp.stage_since || item.stage_since || '' }; - } - // List order: furthest along the strip first — a covered issue counts as - // far along as its furthest covering PR — then longest-waiting first. - function stageTrackerSortKey(item, stages) { - const l = stageTrackerLead(item, stages); - return { anchor: stageTrackerAnchor(l.stage, stages, l.kind, l.lead), since: Date.parse(l.since) || Infinity }; - } - - /* ---- Repo chip and group-by-repo (pure; run under node by - stage_tracker_repo_grouping_test.go) ------------------------------- */ - // Deterministic palette slot for a repo: the string hash the contributor - // tint fallback uses (contribTintFallback), bucketed onto the - // --ham-repo-tint-N tokens so the chip CSS names no literal colour. - function stageTrackerRepoTint(repo) { - const text = String(repo || ''); - let hash = 0; - for (let i = 0; i < text.length; i++) hash = ((hash << 5) - hash + text.charCodeAt(i)) | 0; - return Math.abs(hash) % STAGE_TRACKER_REPO_TINTS; - } - function stageTrackerRepoShort(repo) { - const s = String(repo || ''); - const i = s.indexOf('/'); - return i >= 0 ? s.slice(i + 1) : s; - } - // The configured primary repo may arrive as owner/repo or as the bare - // name; an item's repo is owner/repo. - function stageTrackerIsPrimary(repo, primary) { - if (!repo || !primary) return false; - if (repo === primary) return true; - return String(primary).indexOf('/') < 0 && stageTrackerRepoShort(repo) === primary; - } - // Whether rows carry the chip under a setting, given how many repos the - // payload spans. - function stageTrackerRepoChipOn(mode, repoCount) { - if (mode === 'never') return false; - if (mode === 'always') return true; - return (Number(repoCount) || 0) > 1; - } - // The chip. ctx.repoChips = { primary, active } turns it on - // (renderStageTracker sets it from the setting); absent → ''. The - // primary repo's chip is muted; click filters the list to the repo, or - // clears the filter when it already is that repo. - function stageTrackerRepoChipHtml(repo, ctx) { - if (!ctx || !ctx.repoChips || !repo) return ''; - const primary = stageTrackerIsPrimary(repo, ctx.repoChips.primary); - const active = ctx.repoChips.active === repo; - const tip = repo + (primary ? ' (primary repo)' : '') + (active ? ' — showing only this repo; click to show all repos' : ' — click to show only this repo'); - return ``; - } - // Every hive-filed issue title leads with its filing agent in brackets - // (`[scanner] …`, `[reviewer] Review backlog (security): …`). The tag is - // drawn once, as a chip ahead of the title, and the title text that - // follows no longer repeats it; the full title stays in the tooltip. A - // bracket that is not an agent slug (`[ACMM L0]`, `[Tests]`) is part of - // the subject and is left in the title. - function stageTrackerSplitTitleTag(title) { - const m = /^\s*\[([a-z0-9][a-z0-9_.-]*)\]\s*(.*)$/s.exec(String(title || '')); - if (!m || !m[2]) return { tag: '', text: String(title || '') }; - return { tag: m[1], text: m[2] }; - } - function stageTrackerTitleHtml(title, extraClass) { - const full = String(title || ''); - const { tag, text } = stageTrackerSplitTitleTag(full); - const cls = 'ham-title' + (extraClass ? ' ' + extraClass : ''); - const chip = tag ? `${esc(tag)} ` : ''; - return `${chip}${esc(text)}`; - } - // Column name for a group header's distribution tooltip (as the column header draws it). - function stageTrackerColName(idx, stages) { - if (idx >= STAGE_TRACKER_PATH.length) return 'Merged'; - const n = STAGE_TRACKER_PATH[idx]; - const st = (stages || []).find(s => Number(s.number) === n) || {}; - return n === 0 ? 'Open' : (st.short || st.label || String(n)); - } - // Rows grouped by repo: [{ repo, key, rows, count, attention, cols, - // collapsed }], the primary repo first, then by row count (desc), then - // by name. cols is the per-column row count (a covered issue rides its - // furthest PR, as the strip draws it); needs-attention is counted over - // the rows. opts: { primary, collapsed: { repo: true }, stages }. - function stageTrackerGroups(rows, opts) { - opts = opts || {}; - const by = {}; - for (const it of rows || []) { - const r = it.repo || ''; - if (!by[r]) by[r] = { repo: r, key: STAGE_TRACKER_GROUP_KEY_PREFIX + r, rows: [], count: 0, attention: 0, cols: Array.from({ length: STAGE_TRACKER_PATH.length + 1 }, () => 0), collapsed: !!(opts.collapsed && opts.collapsed[r]) }; - const g = by[r]; - g.rows.push(it); - g.count++; - if (stageTrackerNeedsAttention(it)) g.attention++; - const anchor = stageTrackerSortKey(it, opts.stages || []).anchor; - const col = anchor >= STAGE_TRACKER_TERMINAL ? STAGE_TRACKER_PATH.length : STAGE_TRACKER_PATH.indexOf(anchor); - if (col >= 0) g.cols[col]++; - } - const prim = g => stageTrackerIsPrimary(g.repo, opts.primary) ? 0 : 1; - return Object.keys(by).map(r => by[r]).sort((a, b) => (prim(a) - prim(b)) || (b.count - a.count) || a.repo.localeCompare(b.repo)); - } - // One page of grouped entries: { group } headers and { group, item } - // rows. Headers do not count toward the page size; a page that opens - // mid-group repeats that group's header; a collapsed group is its - // header alone. total counts every row (so a collapsed group is not - // reported as filtered out); from/to and the pages run over the rows - // of expanded groups (shown). - function stageTrackerGroupPage(groups, f) { - f = stageTrackerNormalizeFilter(f); - const flat = []; - let total = 0; - for (const g of groups || []) { total += g.count; flat.push({ group: g }); if (!g.collapsed) for (const it of g.rows) flat.push({ group: g, item: it }); } - const shown = flat.filter(e => e.item).length; - const pages = Math.max(1, Math.ceil(shown / f.size)); - const page = Math.min(f.page, pages); - const lo = (page - 1) * f.size, hi = page * f.size; - const rows = []; - let n = 0, lastHeader = null; - for (const e of flat) { - if (!e.item) { - // A header sits at the row position its rows start; one exactly - // at the page end opens the next page unless this is the last. - if (n >= lo && (n < hi || page === pages)) { rows.push(e); lastHeader = e.group; } - continue; - } - if (n >= lo && n < hi) { - if (lastHeader !== e.group) { rows.push({ group: e.group }); lastHeader = e.group; } - rows.push(e); - } - n++; - } - return { rows, page, pages, from: shown ? lo + 1 : 0, to: Math.min(shown, hi), total, shown, size: f.size }; - } - // Group header row: caret toggle, repo chip, owner/repo, row count, - // needs-attention count and a mini per-column distribution. Keyed - // `group:owner/repo` by the render so the reconcile keeps it stable. - function stageTrackerGroupHeaderHtml(g, stages, ctx) { - const max = Math.max(1, ...g.cols); - const dist = g.cols.map((c, i) => ``).join(''); - const attn = g.attention ? `${g.attention} need${g.attention === 1 ? 's' : ''} attention` : ''; - // The header always carries the chip, whatever the row setting. - const chipCtx = { repoChips: Object.assign({}, (ctx && ctx.repoChips) || {}) }; - return `
    - - ${stageTrackerRepoChipHtml(g.repo, chipCtx)}${esc(g.repo)} - ${g.count} ${g.count === 1 ? 'row' : 'rows'}${attn} - ${dist} -
    `; - } - - // Row = title line (number, title, chips, since) + thin strip. Non-active - // chevrons carry only a grey icon; the active one carries words. - // Everything else is in the tooltip on the row's own #N link: the issue - // ref on the left for an issue row, the ham-pr-ref in the PR column for a - // PR row (the row container, kind/author icons, chips, the since cell and - // a PR row's issue slot carry none). - // An issue with no PR yet, or exactly one covering PR, is a single entry - // (the PR's stage drives the strip and its "[icon] #N title" sits in the - // PR column). With two or more covering PRs the issue strip stops at - // Claimed and one sub-row per PR continues it. A PR drawn on its own - // row owns the whole strip; its issue slot names the issue it closes or - // the "no linked issue" placeholder, never the PR itself. - function stageTrackerRowHtml(item, stages, ctx) { - ctx = ctx || {}; - const nowMs = Number(ctx.nowMs) || Date.now(); - const isIssue = item.kind === 'issue'; - const title = item.title || ''; - let prRefs = [], shown = item, range = null, subs = '', subRows = null; - if (isIssue) { - const linked = stageTrackerLinkedSorted(item, stages); - if (linked.length === 1) { - // One covering PR: a single entry whose strip the PR's stage drives. - const lp = linked[0]; - const who = (lp.author_kind || 'hive') + (lp.author ? ' · @' + lp.author : ''); - const lineage = (lp.lineage && typeof stageTrackerLineageChipHtml === 'function' ? stageTrackerLineageChipHtml(lp, nowMs) : '') || (typeof stageTrackerAdoptedFromChipHtml === 'function' ? stageTrackerAdoptedFromChipHtml(lp, nowMs) : ''); - prRefs = [STAGE_TRACKER_LINKED_GLYPH + stageTrackerPRPillsHtml(stageTrackerPRRef(lp.number, lp.url, lp.author_kind || '', lp.author, lp.title, (lp.title ? lp.title + '\n' : '') + 'Author: ' + who + ' · ' + stageTrackerLinkedTip(item, lp.number, ctx)), typeof stageTrackerLinkedChipsHtml === 'function' ? stageTrackerLinkedChipsHtml(lp, lineage) : (lineage || null), lp.base_ref)]; - shown = Object.assign({}, item, { via_pr: true, stage: stageTrackerLeadStage(lp), stage_since: lp.stage_since || item.stage_since, modifiers: lp.modifiers || item.modifiers, deferred_modifiers: lp.deferred_modifiers || item.deferred_modifiers || [], caption: lp.caption || item.caption, reason: lp.reason || item.reason, - human_approver: lp.human_approver || '', manual_merge: !!lp.manual_merge, human_merge_reason: lp.human_merge_reason || '', human_merge_reason_text: lp.human_merge_reason_text || '', sentinel_alert: !!lp.sentinel_alert, sentinel_reason: lp.sentinel_reason || '', head: lp.head || '', decision_needed: lp.decision_needed || null, hold: lp.hold || null, adoption: lp.adoption || null, stage_actor: lp.stage_actor || item.stage_actor || null, claimant: lp.claimant || null, presence: lp.presence || null, rework: lp.rework || null, push: lp.push || null, merge_gate: lp.merge_gate || null, merge_train: lp.merge_train || null, left_train: lp.left_train || null, overlap: lp.overlap || null, decided: lp.decided || item.decided || null }); - } else if (linked.length) { - // Several covering PRs: the issue strip ends at Claimed, all passed - // and nothing lit; one sub-row per PR carries the live chevron. - range = { to: 20 }; - if (stageTrackerAnchor(item.stage, stages, item.kind) <= 20) shown = Object.assign({}, item, { stage: 40 }); - subs = linked.map(lp => stageTrackerSubRowHtml(lp, item, stages, nowMs, ctx)).join(''); - subRows = linked; - } - } - // Invariant (owner): the issue slot on the left never holds a PR. A - // PR whose issue is listed is nested under it; a PR seen on its own - // (no issue, or the Pull requests view) puts the issue it closes — or - // a muted "no linked issue" placeholder — on the left and names - // itself in the PR column, exactly where a covering PR sits on an - // issue row. That holds when the issue is already closed too - // (closed_issue set, hivecommons/hive#14655): the issue still leads, - // struck through with a `closed` chip — `closed by #N` when the - // server knows the merged PR that closed it, so a duplicate fix reads - // as one (hivecommons/hive#15232) — and the PR stays in the PR column - // rather than taking the issue slot. A not-planned close adds a chip - // saying the PR may be moot. - // The repo chip (when on) leads the row, before the issue slot's #N. - const chip = ctx.repoChips ? stageTrackerRepoChipHtml(item.repo, ctx) : ''; - let leadHtml; - if (isIssue) { - leadHtml = `
    - ${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} - #${Number(item.number) || 0} - ${stageTrackerTitleHtml(title)} - ${item.claim_reference ? `refs` : ''} - ${typeof stageTrackerLinkedElsewhereHtml === 'function' ? stageTrackerLinkedElsewhereHtml(item) : ''} - ${item.is_tracker ? `tracker${item.children && item.children.total ? ' ' + Number(item.children.completed) + '/' + Number(item.children.total) : ''}` : ''} -
    `; - } else { - const li = stageTrackerPRIssueSlot(item); - prRefs = [stageTrackerPRRef(item.number, item.url, item.author_kind || '', item.author, title, (title ? title + ' · ' : '') + stageTrackerTooltip(shown, nowMs)) + (item.lineage && typeof stageTrackerLineageChipHtml === 'function' ? ' ' + stageTrackerLineageChipHtml(item, nowMs) : '')]; - leadHtml = li.number - ? `
    - ${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} - #${li.number} - ${li.title ? stageTrackerTitleHtml(li.title) : `${esc(li.placeholder)}`}${li.soft ? ` refs` : ''}${li.closed ? ' ' + stageTrackerClosedChipHtml(item, li) : ''} -
    ` - : `
    - ${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} - ${esc(li.text)} -
    `; - } - const prs = typeof stageTrackerRowPRKeys === 'function' ? stageTrackerRowPRKeys(item) : ''; - const trainKey = typeof stageTrackerTrainKey === 'function' ? stageTrackerTrainKey(item) : ''; - return `
    - ${stageTrackerRowToolsHtml(item)} -
    - ${stageTrackerHeadColsHtml(prRefs, leadHtml, stageTrackerActedBadgeHtml(item, nowMs) + stageTrackerChipsHtml(shown) + (typeof stageTrackerLeadButtonHtml === 'function' ? stageTrackerLeadButtonHtml(item, nowMs, subRows) : ''))} -
    -
    -
      ${stageTrackerStripItems(shown, stages, range, nowMs, ctx)}
    - ${stageTrackerSinceHtml(shown, nowMs)} -
    ${stageTrackerCurrentStageHtml(shown, stages, range, nowMs)}${typeof stageTrackerEventHtml === 'function' ? stageTrackerEventHtml(stageTrackerItemKey(item), ctx) : ''}${typeof stageTrackerReviewNotesHtml === 'function' ? stageTrackerReviewNotesHtml(item, ctx) : ''}${subs} -
    `; - } - - /* ---- tracker-cues (JS): working / waiting / event line ---------------- - See the CSS block of the same name. Pure helpers, run under node by - stage_tracker_cues_test.go. */ - // Pure: which open items a hive agent is on right now, from the status - // payload the dashboard already polls: busy agents whose lastAction is - // in their current round. Keyed owner/repo#number (lower-case); an - // action names the item but not its kind, so rows match by number. - const STAGE_TRACKER_WORK_WORDS = { - agent_pr_created: 'opened a pull request', agent_issue_created: 'opened an issue', agent_comment_created: 'commented', agent_issue_claimed: 'claimed it', - agent_label_applied: 'changed labels', agent_review_requested: 'asked for review', agent_issue_closed: 'closed it', pr_closed: 'closed it', agent_pr_reviewed: 'reviewed it', pr_merged: 'merged it', - }; diff --git a/src/pkg/dashboard/static-src/manifest.txt b/src/pkg/dashboard/static-src/manifest.txt index 53ea46d019..201936629f 100644 --- a/src/pkg/dashboard/static-src/manifest.txt +++ b/src/pkg/dashboard/static-src/manifest.txt @@ -69,6 +69,9 @@ js/tracker-words-stage.js js/tracker-words-gate.js js/tracker-words.js js/tracker-row.js +js/tracker-row-strip.js +js/tracker-row-acted.js +js/tracker-row-layout.js js/tracker-motion.js js/tracker-filter.js js/tracker-filter-state.js