From a591b2acfe706b9d76bd4726e5b7195ecaa25eff Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Fri, 30 Oct 2026 12:23:01 -0400 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Activity=20Monitor=20settings:?= =?UTF-8?q?=20configurable=20toast=20durations=20and=20pre-merge=20soak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a "Toasts & timing" section to the stage tracker settings modal: info/error toast durations (dashboard.stage_tracker.toast_info_s / toast_error_s, 3–120 s, persisted per hive via PUT /api/config/dashboard and served in the /api/stage-tracker payload, localStorage fallback only when the write is refused) and the contributor lane pre-merge soak (auto_merge.contributor_lane.soak_minutes via PUT /api/config/auto-merge). The merge banner follows 2× the info toast duration. Closes #15813 Signed-off-by: Andrew Anderson --- ...added-15813-tracker-toast-soak-settings.md | 1 + dashboard/openapi.json | 13 +- src/docs/hive-merge.md | 5 +- src/docs/operator-reference.md | 4 +- src/pkg/config/config.go | 45 ++++++ src/pkg/dashboard/api_dashboard_config.go | 51 ++++--- src/pkg/dashboard/stage_tracker.go | 14 ++ src/pkg/dashboard/stage_tracker_build.go | 1 + src/pkg/dashboard/stage_tracker_cues_test.go | 1 + .../stage_tracker_row_actions_test.go | 35 ++++- src/pkg/dashboard/stage_tracker_settings.go | 67 ++++++++ .../dashboard/stage_tracker_settings_test.go | 128 ++++++++++++++++ .../stage_tracker_timing_settings_test.go | 117 ++++++++++++++ src/pkg/dashboard/static-src/css/tracker.css | 2 + .../static-src/js/tracker-actions.js | 56 +++++-- .../dashboard/static-src/js/tracker-merged.js | 5 +- .../dashboard/static-src/js/tracker-sound.js | 78 +++++++++- .../static-src/js/tracker-waiting.js | 3 +- src/pkg/dashboard/static/index.html | 144 ++++++++++++++++-- src/pkg/dashboard/toast_countdown_bar_test.go | 14 +- 20 files changed, 722 insertions(+), 62 deletions(-) create mode 100644 changelog.d/added-15813-tracker-toast-soak-settings.md create mode 100644 src/pkg/dashboard/stage_tracker_settings.go create mode 100644 src/pkg/dashboard/stage_tracker_settings_test.go create mode 100644 src/pkg/dashboard/stage_tracker_timing_settings_test.go diff --git a/changelog.d/added-15813-tracker-toast-soak-settings.md b/changelog.d/added-15813-tracker-toast-soak-settings.md new file mode 100644 index 0000000000..80808b8776 --- /dev/null +++ b/changelog.d/added-15813-tracker-toast-soak-settings.md @@ -0,0 +1 @@ +- The Activity Monitor's ⚙ settings gain a "Toasts & timing" section: info and error toast durations (`dashboard.stage_tracker.toast_info_s` / `toast_error_s`, 3–120 s, saved per hive through `PUT /api/config/dashboard` and served in the `/api/stage-tracker` payload, with a localStorage fallback only when the write is refused) and the contributor lane's pre-merge soak (`auto_merge.contributor_lane.soak_minutes`), live without a restart ([#15813](https://github.com/hivecommons/hive/issues/15813)). diff --git a/dashboard/openapi.json b/dashboard/openapi.json index 75e9a4ee36..8d1a272193 100644 --- a/dashboard/openapi.json +++ b/dashboard/openapi.json @@ -32160,7 +32160,7 @@ "System" ], "summary": "Update dashboard settings", - "description": "Owner-only update for dashboard.port, dashboard.agent_poll_interval_s, dashboard.strategy_lab, dashboard.auth_token, dashboard.authorized_users, dashboard.authorized_user_names, dashboard.hub_proxied, and dashboard.issue_bands.", + "description": "Owner-only update for dashboard.port, dashboard.agent_poll_interval_s, dashboard.strategy_lab, dashboard.auth_token, dashboard.authorized_users, dashboard.authorized_user_names, dashboard.hub_proxied, dashboard.issue_bands, and dashboard.stage_tracker (toast_info_s / toast_error_s, 3-120 seconds, 0 resets the default).", "requestBody": { "required": true, "content": { @@ -32197,6 +32197,17 @@ }, "issue_bands": { "type": "object" + }, + "stage_tracker": { + "type": "object", + "properties": { + "toast_info_s": { + "type": "integer" + }, + "toast_error_s": { + "type": "integer" + } + } } } } diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index e0831daf13..0465c896ba 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -622,7 +622,10 @@ A PR merges through this tier only when all of the following hold: the soak. The skip reason is the stable `contributor-lane:soaking`; the soak head, start and window are recorded once on the stage record, so the stage tracker computes "N left" from that deadline at request time instead - of the hive re-stamping its note every pass. + of the hive re-stamping its note every pass. The window is also editable + from the Activity Monitor's ⚙ → Toasts & timing ("Pre-merge soak"), which + writes `soak_minutes` through `PUT /api/config/auto-merge`; the lane reads + the knob on every pass, so a running soak follows the new window. Merges squash through the same effect-claimed `MergePR` path as the other tiers, log `automerge merged tier=contributor-lane admitted_by=`, record the diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 9451ab9c4d..00d0cd8815 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -454,7 +454,7 @@ advanced into the merge path. | `auto_merge.trusted_authors.require_github_permission` | `true` | Also require GitHub to report author write access; API errors fail closed. Fork PRs still need this check even if the setting is false. | | `auto_merge.trusted_authors.exclude_labels` | `hold`, `do-not-merge`, `needs-human` | Labels that keep a PR out of trusted-author auto-merge. | | `auto_merge.contributor_lane.enabled` | `true` | Enables the contributor-lane tier: Hive merges a green, soaked, reviewer-approved PR whose author holds a `require_tiers` tier in the contributor registry (`registry_tiers_sufficient`), or whose linked issue carries this hive's App-authored `hive:claim kind=contributor` marker naming the PR author with a `tier=` in `require_tiers` and `verified=true`. Grants unattended merge only to contributors an operator granted such a tier and whose GitHub login was proven; set `false` to make every contributor PR wait for a human `/lgtm` + `/approve`. See [hive-merge.md](hive-merge.md#contributor-lane-auto-merge). | -| `auto_merge.contributor_lane.soak_minutes` | `30` | How long the current head must stay green before the tier merges it; a new push restarts the soak. `0`/unset means the default (30); the shortest real soak is `1`. | +| `auto_merge.contributor_lane.soak_minutes` | `30` | How long the current head must stay green before the tier merges it; a new push restarts the soak. `0`/unset means the default (30); the shortest real soak is `1`. Also editable from the Activity Monitor's ⚙ → Toasts & timing ("Pre-merge soak"), which writes through `PUT /api/config/auto-merge`; the lane re-reads it on every pass, so a running soak follows the new window. | | `auto_merge.contributor_lane.require_reviewer_verdict` | `true` | Require an approving aggregate reviewer verdict for the current head. Independently of this key, a hive with no reviewer agent never merges through the tier (`contributor-lane:no-reviewer`). | | `auto_merge.contributor_lane.require_tiers` | `trusted`, `merger` | Contributor trust tiers whose verified claims the tier may merge. Only operator-granted tiers (`trusted`, `merger`, `advisor`) are accepted; `newcomer` and `contributor` are rejected at validation. | | `auto_merge.contributor_lane.registry_tiers_sufficient` | `true` | Admit a PR whose author's contributor-registry profile carries a `require_tiers` tier without a linked issue or `hive:claim` marker (logged as `contributor-lane:registry-trusted`). All other gates still apply. `false` requires the claim marker for every contributor. | @@ -2016,6 +2016,8 @@ dashboard: webhook_refresh_replay_window_s: 1800 # re-apply re-reads to snapshots published meanwhile closed_sweep_interval_s: 300 # list items closed since the last look and evict rows still shown; -1 disables waiting_push_stale_h: 4 # hours without a push on a CI / Review row before the pill's age turns muted-amber + toast_info_s: 15 # how long the tracker's result / waiting-on-you toasts stay (3-120 s); the merge banner stays twice as long + toast_error_s: 30 # how long a failed row action's toast stays (3-120 s); editable from the Activity Monitor's ⚙ → Toasts & timing ``` ## `HIVE_GITHUB_TOKEN` permissions diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index 8bf32c7127..da59c81a46 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -4966,6 +4966,51 @@ type DashboardStageTrackerConfig struct { // age takes the muted-stale tone (hivecommons/hive#15784). 0 means the // default (4); a negative value never marks the wait stale. WaitingPushStaleH int `yaml:"waiting_push_stale_h,omitempty" json:"waiting_push_stale_h,omitempty"` + // ToastInfoS is how many seconds the activity monitor's informational + // toasts (action results, waiting-on-human nudges, the merge banner) + // stay up before dismissing themselves (hivecommons/hive#15813). + // 0 means the default (15); values are clamped to 3..120. + ToastInfoS int `yaml:"toast_info_s,omitempty" json:"toast_info_s,omitempty"` + // ToastErrorS is the same for error toasts. 0 means the default (30); + // values are clamped to 3..120. + ToastErrorS int `yaml:"toast_error_s,omitempty" json:"toast_error_s,omitempty"` +} + +// Defaults and bounds for dashboard.stage_tracker.toast_info_s and +// toast_error_s. The bounds are shared with the settings modal's number +// fields and the PUT validation so every path agrees on what is legal. +const ( + DefaultStageTrackerToastInfoS = 15 + DefaultStageTrackerToastErrorS = 30 + MinStageTrackerToastS = 3 + MaxStageTrackerToastS = 120 +) + +// stageTrackerToastSeconds applies the shared default/clamp rule for a +// toast duration knob. +func stageTrackerToastSeconds(configured, def int) int { + if configured == 0 { + return def + } + return min(max(configured, MinStageTrackerToastS), MaxStageTrackerToastS) +} + +// StageTrackerToastInfo is the effective dashboard.stage_tracker.toast_info_s +// as a duration. +func (c *Config) StageTrackerToastInfo() time.Duration { + if c == nil { + return DefaultStageTrackerToastInfoS * time.Second + } + return time.Duration(stageTrackerToastSeconds(c.Dashboard.StageTracker.ToastInfoS, DefaultStageTrackerToastInfoS)) * time.Second +} + +// StageTrackerToastError is the effective +// dashboard.stage_tracker.toast_error_s as a duration. +func (c *Config) StageTrackerToastError() time.Duration { + if c == nil { + return DefaultStageTrackerToastErrorS * time.Second + } + return time.Duration(stageTrackerToastSeconds(c.Dashboard.StageTracker.ToastErrorS, DefaultStageTrackerToastErrorS)) * time.Second } // defaultStageTrackerWaitingPushStale is the default diff --git a/src/pkg/dashboard/api_dashboard_config.go b/src/pkg/dashboard/api_dashboard_config.go index 40a3dad8df..b6bcf1c4bf 100644 --- a/src/pkg/dashboard/api_dashboard_config.go +++ b/src/pkg/dashboard/api_dashboard_config.go @@ -3,20 +3,22 @@ package dashboard import ( "net/http" "strings" + "time" "github.com/hivecommons/hive/pkg/config" ) type dashboardSettingsPayload struct { - Port int `json:"port"` - AgentPollIntervalS int `json:"agent_poll_interval_s"` - ExperimentLab bool `json:"experiment_lab"` - StrategyLab bool `json:"strategy_lab"` - AuthTokenConfigured bool `json:"auth_token_configured"` - AuthorizedUsers []string `json:"authorized_users"` - AuthorizedUserNames map[string]string `json:"authorized_user_names"` - HubProxied bool `json:"hub_proxied"` - IssueBands dashboardIssueBandsPayload `json:"issue_bands"` + Port int `json:"port"` + AgentPollIntervalS int `json:"agent_poll_interval_s"` + ExperimentLab bool `json:"experiment_lab"` + StrategyLab bool `json:"strategy_lab"` + AuthTokenConfigured bool `json:"auth_token_configured"` + AuthorizedUsers []string `json:"authorized_users"` + AuthorizedUserNames map[string]string `json:"authorized_user_names"` + HubProxied bool `json:"hub_proxied"` + IssueBands dashboardIssueBandsPayload `json:"issue_bands"` + StageTracker dashboardStageTrackerPayload `json:"stage_tracker"` } type dashboardIssueBandsPayload struct { @@ -34,6 +36,8 @@ func dashboardSettingsResponse(cfg *config.Config) dashboardSettingsPayload { for k, v := range d.AuthorizedUserNames { names[k] = v } + toastInfo := int(cfg.StageTrackerToastInfo() / time.Second) + toastError := int(cfg.StageTrackerToastError() / time.Second) return dashboardSettingsPayload{ Port: d.Port, AgentPollIntervalS: d.AgentPollIntervalS, @@ -48,6 +52,7 @@ func dashboardSettingsResponse(cfg *config.Config) dashboardSettingsPayload { DoneLabels: append([]string{}, d.IssueBands.DoneLabels...), StaleDays: d.IssueBands.StaleDays, }, + StageTracker: dashboardStageTrackerPayload{ToastInfoS: &toastInfo, ToastErrorS: &toastError}, } } @@ -63,15 +68,16 @@ func (s *Server) handleDashboardSettingsPut(w http.ResponseWriter, r *http.Reque return } var body struct { - Port *int `json:"port"` - AgentPollIntervalS *int `json:"agent_poll_interval_s"` - ExperimentLab *bool `json:"experiment_lab"` - StrategyLab *bool `json:"strategy_lab"` - AuthToken *string `json:"auth_token"` - AuthorizedUsers []string `json:"authorized_users"` - AuthorizedUserNames map[string]string `json:"authorized_user_names"` - HubProxied *bool `json:"hub_proxied"` - IssueBands *dashboardIssueBandsPayload `json:"issue_bands"` + Port *int `json:"port"` + AgentPollIntervalS *int `json:"agent_poll_interval_s"` + ExperimentLab *bool `json:"experiment_lab"` + StrategyLab *bool `json:"strategy_lab"` + AuthToken *string `json:"auth_token"` + AuthorizedUsers []string `json:"authorized_users"` + AuthorizedUserNames map[string]string `json:"authorized_user_names"` + HubProxied *bool `json:"hub_proxied"` + IssueBands *dashboardIssueBandsPayload `json:"issue_bands"` + StageTracker *dashboardStageTrackerPayload `json:"stage_tracker"` } if err := decodeBody(r, &body); err != nil { jsonError(w, "invalid body", http.StatusBadRequest) @@ -132,6 +138,10 @@ func (s *Server) handleDashboardSettingsPut(w http.ResponseWriter, r *http.Reque } next.IssueBands.StaleDays = body.IssueBands.StaleDays } + if err := applyStageTrackerSettings(&next, body.StageTracker); err != nil { + jsonError(w, err.Error(), http.StatusBadRequest) + return + } cfg.Dashboard = next if err := s.saveConfig(); err != nil { s.logger.Error("failed to persist config after dashboard settings update", "error", err) @@ -139,5 +149,10 @@ func (s *Server) handleDashboardSettingsPut(w http.ResponseWriter, r *http.Reque return } s.auditFromRequest(r, "config_dashboard_settings", auditDetail("section", "dashboard"), "") + if body.StageTracker != nil { + // The tracker payload carries the toast knobs; drop the memoised + // body so the next poll sees the new durations. + s.invalidateStageTrackerCache() + } jsonResponse(w, dashboardSettingsResponse(cfg)) } diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 5ce05339a6..63101fb6a2 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -91,6 +91,20 @@ type StageTrackerResponse struct { // the last few merges. Unlike RecentlyMerged it survives a roll, so it // is what the "Merged" chip shows. Merged StageTrackerMergedSummary `json:"merged"` + // Settings carries the operator-tunable timings the tracker's settings + // modal edits (hivecommons/hive#15813), so every viewer — not only the + // owner who may read /api/config/dashboard — sees the live values. + Settings StageTrackerSettings `json:"settings"` +} + +// StageTrackerSettings is the live value of the timing knobs the Activity +// Monitor settings modal edits: dashboard.stage_tracker.toast_info_s, +// dashboard.stage_tracker.toast_error_s and +// auto_merge.contributor_lane.soak_minutes. +type StageTrackerSettings struct { + ToastInfoS int `json:"toast_info_s"` + ToastErrorS int `json:"toast_error_s"` + SoakMinutes int `json:"soak_minutes"` } // StageTrackerMerged is one recently merged pull request. diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go index e35072aa5c..09a8ca5bf6 100644 --- a/src/pkg/dashboard/stage_tracker_build.go +++ b/src/pkg/dashboard/stage_tracker_build.go @@ -824,6 +824,7 @@ func (s *Server) encodeStageTracker(status *StatusPayload, now time.Time, ttl ti resp := build(status, s.stageStoreOrShared(), now) s.stageTrackerEnrichSoftLinks(resp.Items, stageTrackerRepoQualifier(status), now) resp.CacheTTLSeconds = int64(ttl / time.Second) + resp.Settings = s.stageTrackerSettings() // The encoded body carries source=cache: that is what every later hit // serves verbatim, and what the ETag validates. The building request // alone rewrites the marker to fresh on its way out (handleStageTracker). diff --git a/src/pkg/dashboard/stage_tracker_cues_test.go b/src/pkg/dashboard/stage_tracker_cues_test.go index c6cb02f00f..11a91c2943 100644 --- a/src/pkg/dashboard/stage_tracker_cues_test.go +++ b/src/pkg/dashboard/stage_tracker_cues_test.go @@ -316,6 +316,7 @@ func stageTrackerCelebrateJS(t *testing.T, html string) string { jsConstLine(t, html, "STAGE_TRACKER_CELEBRATE_MAX_FLIGHTS"), jsConstLine(t, html, "STAGE_TRACKER_CELEBRATE_EXIT_PAD"), jsConstLine(t, html, "STAGE_TRACKER_MERGE_BANNER_MS"), + "function stageTrackerMergeBannerMs() { return STAGE_TRACKER_MERGE_BANNER_MS; }", jsConstLine(t, html, "STAGE_TRACKER_MERGE_BANNER_MAX"), jsConstLine(t, html, "STAGE_TRACKER_SOUND_MAX_PLAYS"), jsFunc(t, html, "stageTrackerCelebrateSetting"), diff --git a/src/pkg/dashboard/stage_tracker_row_actions_test.go b/src/pkg/dashboard/stage_tracker_row_actions_test.go index 64f5d0d02c..06606693e2 100644 --- a/src/pkg/dashboard/stage_tracker_row_actions_test.go +++ b/src/pkg/dashboard/stage_tracker_row_actions_test.go @@ -121,7 +121,14 @@ func stageTrackerRowActionsPreamble(t *testing.T, html string) string { jsConstLine(t, html, "STAGE_TRACKER_ACTION_NOOP"), jsConstLine(t, html, "STAGE_TRACKER_ACTION_NO_EFFECT"), jsConstLine(t, html, "STAGE_TRACKER_RESULT_TOAST_MAX"), - jsConstLine(t, html, "STAGE_TRACKER_RESULT_TOAST_MS"), + jsConstLine(t, html, "STAGE_TRACKER_TOAST_DEFAULT_S"), + jsConstLine(t, html, "STAGE_TRACKER_TOAST_MIN_S"), + jsConstLine(t, html, "STAGE_TRACKER_TOAST_MAX_S"), + jsConstLine(t, html, "STAGE_TRACKER_TOAST_KEY"), + jsFunc(t, html, "stageTrackerToastSecondsValid"), + jsFunc(t, html, "stageTrackerToastSeconds"), + jsFunc(t, html, "stageTrackerToastLocal"), + jsFunc(t, html, "stageTrackerToastMs"), jsConstLine(t, html, "STAGE_TRACKER_ACTING_MAX_MS"), jsConstBlock(t, html, "STAGE_TRACKER_ACTING_CAPTIONS"), jsConstLine(t, html, "STAGE_TRACKER_REBASE_MERGE_LABEL"), @@ -1131,10 +1138,11 @@ const tst = stageTrackerResultToast(decided, issue, { id: 'decide:delegate' }); assert.strictEqual(hamToastContainer.children.length, 1); assert.ok(tst.el.className.includes('toast success ham-result-toast sticky'), tst.el.className); assert.ok(tst.el.children.some(c => c.className === 'toast-close'), 'has ✕'); -// An informational result closes itself after STAGE_TRACKER_RESULT_TOAST_MS +// An informational result closes itself after the info toast duration +// (15 s unless the hive's settings say otherwise — hivecommons/hive#15813) // through the sticky guard; × and a state change still close it earlier. -assert.strictEqual(STAGE_TRACKER_RESULT_TOAST_MS, 15000); -assert.strictEqual(tst.el._countdown.ms, STAGE_TRACKER_RESULT_TOAST_MS, 'the countdown runs for the result TTL'); +assert.strictEqual(stageTrackerToastMs('info'), 15000); +assert.strictEqual(tst.el._countdown.ms, 15000, 'the countdown runs for the result TTL'); { const timed = stageTrackerResultToast(decided, issue, { id: 'decide:delegate' }); assert.strictEqual(hamToastContainer.children.length, 2); @@ -1183,11 +1191,26 @@ const rerunReq = stageTrackerActionRequest(prRow, 'decide:delegate:rerun', {}); assert.strictEqual(rerunReq.body.force, true); assert.strictEqual(rerunReq.body.reason, 'contributor-lane:changes-requested'); assert.ok(rerunReq.poll); assert.ok(rerunReq.url.endsWith('/items/14947/decide-delegated')); assert.strictEqual(stageTrackerActionRequest(prRow, 'decide:delegate', {}).body.force, undefined, 'a first click never forces'); assert.strictEqual(stageTrackerActionLabel('decide:delegate:rerun'), 'Re-run decision'); -// Error toasts are sticky but not tied to a row state. +// Error toasts are sticky (×) but not tied to a row state; they close +// after the error toast duration, 30 s by default, and both durations +// follow the tracker payload's settings block live. const bad = stageTrackerResultToast(stageTrackerErrorResult('hold', held, 'boom'), held, { id: 'hold' }); assert.ok(bad.el.className.includes('error')); assert.deepStrictEqual(_stageTrackerResultToasts, []); -assert.strictEqual(bad.el._countdown, undefined, 'an error waits to be acknowledged: no countdown'); +assert.strictEqual(bad.el._countdown.ms, 30000, 'an error closes after the error toast duration'); bad.el.remove(); +_stageTracker = { items: [issue, held], settings: { toast_info_s: 7, toast_error_s: 45 } }; +{ + const tuned = stageTrackerResultToast(decided, issue, { id: 'decide:delegate' }); + assert.strictEqual(tuned.el._countdown.ms, 7000, 'info duration from the hive'); + tuned.el.remove(); _stageTrackerResultToasts = _stageTrackerResultToasts.filter(e => e !== tuned); + const tunedErr = stageTrackerResultToast(stageTrackerErrorResult('hold', held, 'boom'), held, { id: 'hold' }); + assert.strictEqual(tunedErr.el._countdown.ms, 45000, 'error duration from the hive'); + tunedErr.el.remove(); + assert.strictEqual(stageTrackerToastSeconds('info', { toast_info_s: 500 }, null), 120, 'server values clamp to the 3..120 s range'); + assert.strictEqual(stageTrackerToastSeconds('info', { toast_info_s: 7 }, { info: 20, fallback: true }), 20, 'the browser fallback (write refused) wins over the payload'); + assert.strictEqual(stageTrackerToastSeconds('error', { toast_error_s: 'x' }, { info: 20 }), 30, 'garbage falls back to the default'); +} +_stageTracker = { items: [issue, held] }; // Acting state: the clicked issue row and its nested PR both act from the click. const keys = stageTrackerPendingKeys({ repo: 'o/r', kind: 'pr', number: 14947 }, [issue]); diff --git a/src/pkg/dashboard/stage_tracker_settings.go b/src/pkg/dashboard/stage_tracker_settings.go new file mode 100644 index 0000000000..a9affd89cb --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_settings.go @@ -0,0 +1,67 @@ +package dashboard + +import ( + "fmt" + "time" + + "github.com/hivecommons/hive/pkg/config" +) + +// stageTrackerSettings is the live timing block the tracker payload carries +// for the settings modal (hivecommons/hive#15813): the config defaults when +// no config is wired. +func (s *Server) stageTrackerSettings() StageTrackerSettings { + var cfg *config.Config + if s != nil && s.deps != nil { + cfg = s.deps.Config + } + soak := config.DefaultContributorLaneSoakMinutes + if cfg != nil { + soak = cfg.AutoMerge.ContributorLane.EffectiveSoakMinutes() + } + return StageTrackerSettings{ + ToastInfoS: int(cfg.StageTrackerToastInfo() / time.Second), + ToastErrorS: int(cfg.StageTrackerToastError() / time.Second), + SoakMinutes: soak, + } +} + +// dashboardStageTrackerPayload is the dashboard.stage_tracker block +// GET/PUT /api/config/dashboard exchange. Only the toast knobs are editable +// here; the cache and webhook knobs stay YAML-only. +type dashboardStageTrackerPayload struct { + ToastInfoS *int `json:"toast_info_s,omitempty"` + ToastErrorS *int `json:"toast_error_s,omitempty"` +} + +// applyStageTrackerSettings validates and copies the toast knobs from a PUT +// body onto next. A value of 0 resets the knob to its default; anything else +// must sit within the shared 3..120 s bounds. +func applyStageTrackerSettings(next *config.DashboardConfig, body *dashboardStageTrackerPayload) error { + if body == nil { + return nil + } + check := func(name string, v *int) error { + if v == nil || *v == 0 { + return nil + } + if *v < config.MinStageTrackerToastS || *v > config.MaxStageTrackerToastS { + return fmt.Errorf("dashboard.stage_tracker.%s must be between %d and %d seconds (0 resets to the default)", + name, config.MinStageTrackerToastS, config.MaxStageTrackerToastS) + } + return nil + } + if err := check("toast_info_s", body.ToastInfoS); err != nil { + return err + } + if err := check("toast_error_s", body.ToastErrorS); err != nil { + return err + } + if body.ToastInfoS != nil { + next.StageTracker.ToastInfoS = *body.ToastInfoS + } + if body.ToastErrorS != nil { + next.StageTracker.ToastErrorS = *body.ToastErrorS + } + return nil +} diff --git a/src/pkg/dashboard/stage_tracker_settings_test.go b/src/pkg/dashboard/stage_tracker_settings_test.go new file mode 100644 index 0000000000..1a1eefcd87 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_settings_test.go @@ -0,0 +1,128 @@ +package dashboard + +import ( + "encoding/json" + "net/http" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" +) + +// TestStageTrackerToastKnobs pins the default, clamp and reset semantics of +// dashboard.stage_tracker.toast_info_s / toast_error_s (hivecommons/hive#15813). +func TestStageTrackerToastKnobs(t *testing.T) { + var nilCfg *config.Config + if nilCfg.StageTrackerToastInfo() != 15*time.Second || nilCfg.StageTrackerToastError() != 30*time.Second { + t.Fatal("nil config falls back to 15 s info / 30 s error") + } + cfg := &config.Config{} + if cfg.StageTrackerToastInfo() != 15*time.Second || cfg.StageTrackerToastError() != 30*time.Second { + t.Fatal("zero knobs mean the defaults") + } + cfg.Dashboard.StageTracker.ToastInfoS = 45 + cfg.Dashboard.StageTracker.ToastErrorS = 90 + if cfg.StageTrackerToastInfo() != 45*time.Second || cfg.StageTrackerToastError() != 90*time.Second { + t.Fatal("knobs are read in seconds") + } + cfg.Dashboard.StageTracker.ToastInfoS = 1 + cfg.Dashboard.StageTracker.ToastErrorS = 999 + if cfg.StageTrackerToastInfo() != 3*time.Second || cfg.StageTrackerToastError() != 120*time.Second { + t.Fatalf("out-of-range values clamp to 3..120 s, got %v / %v", cfg.StageTrackerToastInfo(), cfg.StageTrackerToastError()) + } + s := newTestServer() + got := s.stageTrackerSettings() + if got.ToastInfoS != 15 || got.ToastErrorS != 30 || got.SoakMinutes != config.DefaultContributorLaneSoakMinutes { + t.Fatalf("server without config reports the defaults, got %+v", got) + } +} + +// TestDashboardSettingsAPIStageTrackerToasts proves the toast knobs round +// trip through PUT /api/config/dashboard, land in the dashboard overlay the +// config watcher merges at boot, reject out-of-range values, and surface in +// the stage-tracker payload every viewer polls. +func TestDashboardSettingsAPIStageTrackerToasts(t *testing.T) { + t.Setenv("KUBERNETES_SERVICE_HOST", "10.96.0.1") // IsKubernetesPod() → true: the overlay is written + s := govServer(t) + dir := t.TempDir() + s.deps.Config.SourcePath = filepath.Join(dir, "hive.yaml") + oldOverlay, oldRuntime := config.DashboardOverlayFile, config.RuntimeConfigFile + config.DashboardOverlayFile = filepath.Join(dir, "hive.yaml.dashboard") + config.RuntimeConfigFile = filepath.Join(dir, "hive.yaml.runtime") + t.Cleanup(func() { config.DashboardOverlayFile, config.RuntimeConfigFile = oldOverlay, oldRuntime }) + s.deps.Config.AutoMerge.ContributorLane.SoakMinutes = 12 + + for _, body := range []map[string]any{ + {"stage_tracker": map[string]any{"toast_info_s": 2}}, + {"stage_tracker": map[string]any{"toast_error_s": 121}}, + {"stage_tracker": map[string]any{"toast_info_s": -5}}, + } { + rec := doPut(s, "/api/config/dashboard", body) + if rec.Code != http.StatusBadRequest { + t.Fatalf("body %#v => %d, want 400 (%s)", body, rec.Code, rec.Body.String()) + } + } + if st := s.deps.Config.Dashboard.StageTracker; st.ToastInfoS != 0 || st.ToastErrorS != 0 { + t.Fatalf("rejected PUT mutated knobs: %+v", st) + } + + rec := doPut(s, "/api/config/dashboard", map[string]any{ + "stage_tracker": map[string]any{"toast_info_s": 20, "toast_error_s": 60}, + }) + if rec.Code != http.StatusOK { + t.Fatalf("PUT = %d: %s", rec.Code, rec.Body.String()) + } + var resp struct { + StageTracker struct { + ToastInfoS int `json:"toast_info_s"` + ToastErrorS int `json:"toast_error_s"` + } `json:"stage_tracker"` + } + if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil { + t.Fatalf("decode: %v", err) + } + if resp.StageTracker.ToastInfoS != 20 || resp.StageTracker.ToastErrorS != 60 { + t.Fatalf("response did not echo the knobs: %s", rec.Body.String()) + } + overlay, err := os.ReadFile(config.DashboardOverlayFile) + if err != nil { + t.Fatalf("overlay not written: %v", err) + } + if !strings.Contains(string(overlay), "toast_info_s: 20") || !strings.Contains(string(overlay), "toast_error_s: 60") { + t.Fatalf("overlay lacks the toast knobs:\n%s", overlay) + } + + got := s.stageTrackerSettings() + if got.ToastInfoS != 20 || got.ToastErrorS != 60 || got.SoakMinutes != 12 { + t.Fatalf("tracker settings block = %+v", got) + } + + // A 0 resets a knob to its default without touching the other. + rec = doPut(s, "/api/config/dashboard", map[string]any{"stage_tracker": map[string]any{"toast_info_s": 0}}) + if rec.Code != http.StatusOK { + t.Fatalf("reset PUT = %d: %s", rec.Code, rec.Body.String()) + } + got = s.stageTrackerSettings() + if got.ToastInfoS != 15 || got.ToastErrorS != 60 { + t.Fatalf("after reset: %+v", got) + } + + // The memoised tracker payload carries the live block. + s.deps.Config.SourcePath = "" + s.statusMu.Lock() + s.status = minimalPayload() + s.statusMu.Unlock() + body, _, _, _ := s.stageTrackerPayload(s.status, time.Now().UTC()) + var tracker struct { + Settings StageTrackerSettings `json:"settings"` + } + if err := json.Unmarshal(body, &tracker); err != nil { + t.Fatalf("decode tracker: %v", err) + } + if tracker.Settings != got { + t.Fatalf("tracker payload settings = %+v, want %+v", tracker.Settings, got) + } +} diff --git a/src/pkg/dashboard/stage_tracker_timing_settings_test.go b/src/pkg/dashboard/stage_tracker_timing_settings_test.go new file mode 100644 index 0000000000..e5c8c6d309 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_timing_settings_test.go @@ -0,0 +1,117 @@ +package dashboard + +import ( + "os/exec" + "strings" + "testing" +) + +// TestStageTrackerTimingSettingsNode runs the Activity Monitor settings +// modal's "Toasts & timing" section under node (hivecommons/hive#15813): +// the fields show the hive's values from the tracker payload, a change +// PUTs the knob to /api/config/dashboard (soak to /api/config/auto-merge) +// and the new duration applies to the next toast, a refused write falls +// back to this browser's localStorage and says so, and the merge banner +// follows the info duration. +func TestStageTrackerTimingSettingsNode(t *testing.T) { + node, err := exec.LookPath("node") + if err != nil { + t.Skip("node not on PATH — timing settings were NOT executed by this run") + } + html := indexHTML(t) + script := strings.Join([]string{ + "const assert = require('assert');", + "function esc(s) { if (typeof s !== 'string') return ''; return s.replace(/&/g, '&').replace(/ (k in store ? store[k] : null), setItem(k, v) { store[k] = String(v); }, removeItem(k) { delete store[k]; } };", + "global.window = {}; const toasts = []; function showToast(msg, type) { toasts.push({ msg, type }); }", + "let renders = 0; function stageTrackerRenderSettings() { renders++; }", + "const puts = []; let nextOk = true; global.fetch = async (url, init) => { puts.push({ url, body: JSON.parse(init.body), method: init.method }); return { ok: nextOk, json: async () => ({ error: 'owner access required' }) }; };", + "var _stageTracker = null;", + jsConstLine(t, html, "STAGE_TRACKER_TOAST_DEFAULT_S"), + jsConstLine(t, html, "STAGE_TRACKER_TOAST_MIN_S"), + jsConstLine(t, html, "STAGE_TRACKER_TOAST_MAX_S"), + jsConstLine(t, html, "STAGE_TRACKER_TOAST_KEY"), + jsConstLine(t, html, "STAGE_TRACKER_MERGE_BANNER_FACTOR"), + jsConstLine(t, html, "STAGE_TRACKER_SOAK_DEFAULT_MIN"), + jsFunc(t, html, "stageTrackerToastSecondsValid"), + jsFunc(t, html, "stageTrackerToastSeconds"), + jsFunc(t, html, "stageTrackerToastLocal"), + jsFunc(t, html, "stageTrackerToastMs"), + jsFunc(t, html, "stageTrackerMergeBannerMs"), + jsFunc(t, html, "stageTrackerTimingSectionHtml"), + jsFunc(t, html, "stageTrackerTimingState"), + jsFunc(t, html, "stageTrackerTimingHeaders"), + jsFunc(t, html, "stageTrackerSaveToastSeconds"), + jsFunc(t, html, "stageTrackerToastInfoChange"), + jsFunc(t, html, "stageTrackerToastErrorChange"), + jsFunc(t, html, "stageTrackerSoakChange"), + ` +(async () => { +// Defaults with no payload: 15 s / 30 s, banner 30 s, soak 30 min. +assert.strictEqual(stageTrackerToastMs('info'), 15000); assert.strictEqual(stageTrackerToastMs('error'), 30000); +assert.strictEqual(stageTrackerMergeBannerMs(), 30000, 'the banner is twice the info toast'); +let h = stageTrackerTimingSectionHtml(stageTrackerTimingState()); +assert.ok(h.includes('id="sts-timing"') && h.includes('Toasts & timing'), h); +assert.ok(h.includes('id="sts-toast-info" min="3" max="120" step="1" value="15"'), h); +assert.ok(h.includes('id="sts-toast-error" min="3" max="120" step="1" value="30"'), h); +assert.ok(h.includes('id="sts-soak" min="1"') && h.includes('value="30"'), h); +assert.ok(h.includes('data-change-action="stageTrackerToastInfoChange"') && h.includes('data-change-action="stageTrackerSoakChange"'), 'fields dispatch change actions'); +assert.ok(h.includes('re-reads it on every pass'), 'the soak hint says how a running soak behaves'); + +// The payload's settings block drives the fields and every toast. +_stageTracker = { items: [], settings: { toast_info_s: 8, toast_error_s: 40, soak_minutes: 12 } }; +assert.strictEqual(stageTrackerToastMs('info'), 8000); assert.strictEqual(stageTrackerToastMs('error'), 40000); assert.strictEqual(stageTrackerMergeBannerMs(), 16000); +h = stageTrackerTimingSectionHtml(stageTrackerTimingState()); +assert.ok(h.includes('id="sts-toast-info" min="3" max="120" step="1" value="8"') && h.includes('value="40"') && h.includes('id="sts-soak" min="1" max="100000" step="1" value="12"'), h); + +// A change writes the hive's knob and applies at once. +const info = { value: '25' }; +assert.strictEqual(await stageTrackerToastInfoChange(info), true); +assert.deepStrictEqual(puts.pop(), { url: '/api/config/dashboard', method: 'PUT', body: { stage_tracker: { toast_info_s: 25 } } }); +assert.strictEqual(stageTrackerToastMs('info'), 25000, 'applies to the next toast without waiting for a poll'); +assert.strictEqual(stageTrackerMergeBannerMs(), 50000); +assert.strictEqual(renders, 1); assert.strictEqual(toasts.pop().type, 'success'); +assert.strictEqual(store[STAGE_TRACKER_TOAST_KEY], undefined, 'a saved value leaves nothing in localStorage'); +const bad = { value: 'abc' }; +assert.strictEqual(await stageTrackerToastErrorChange(bad), false, 'not a number: not sent'); +assert.strictEqual(bad.value, '40', 'the field snaps back to the live value'); assert.strictEqual(puts.length, 0); +const low = { value: '1' }; +await stageTrackerToastErrorChange(low); +assert.strictEqual(low.value, '3', 'clamped to the minimum before the write'); assert.deepStrictEqual(puts.pop().body, { stage_tracker: { toast_error_s: 3 } }); +const high = { value: '500' }; +await stageTrackerToastErrorChange(high); +assert.strictEqual(high.value, '120', 'clamped to the maximum before the write'); assert.deepStrictEqual(puts.pop().body, { stage_tracker: { toast_error_s: 120 } }); + +// A refused write (viewer, hub proxy) keeps the value in this browser only. +nextOk = false; +assert.strictEqual(await stageTrackerToastInfoChange({ value: '5' }), false); +assert.deepStrictEqual(JSON.parse(store[STAGE_TRACKER_TOAST_KEY]), { info: 5, fallback: true }); +assert.strictEqual(stageTrackerToastMs('info'), 5000, 'the fallback applies here'); +assert.strictEqual(stageTrackerToastMs('error'), 120000, 'the other knob still reads the hive'); +assert.strictEqual(toasts.pop().type, 'warning'); +assert.ok(stageTrackerTimingSectionHtml(stageTrackerTimingState()).includes('Saved in this browser only'), 'the modal says the write was refused'); +window.hiveKioskMode = () => true; delete store[STAGE_TRACKER_TOAST_KEY]; +await stageTrackerToastInfoChange({ value: '6' }); +assert.strictEqual(store[STAGE_TRACKER_TOAST_KEY], undefined, 'a kiosk never writes localStorage'); window.hiveKioskMode = () => false; +nextOk = true; +await stageTrackerToastInfoChange({ value: '9' }); +assert.strictEqual(store[STAGE_TRACKER_TOAST_KEY], undefined, 'a later successful write clears the fallback'); assert.strictEqual(stageTrackerToastMs('info'), 9000); + +// The soak writes through the auto-merge config endpoint; < 1 is refused. +puts.length = 0; +assert.strictEqual(await stageTrackerSoakChange({ value: '45' }), true); +assert.deepStrictEqual(puts.pop(), { url: '/api/config/auto-merge', method: 'PUT', body: { contributor_lane: { soak_minutes: 45 } } }); +assert.strictEqual(_stageTracker.settings.soak_minutes, 45); assert.ok(toasts.pop().msg.includes('45 min')); +const zero = { value: '0' }; +assert.strictEqual(await stageTrackerSoakChange(zero), false); assert.strictEqual(zero.value, '45'); assert.strictEqual(puts.length, 0); +nextOk = false; +assert.strictEqual(await stageTrackerSoakChange({ value: '50' }), false); +assert.strictEqual(_stageTracker.settings.soak_minutes, 45, 'a refused soak write changes nothing'); assert.ok(toasts.pop().msg.includes('owner access required')); +console.log('ok'); +})().catch(e => { console.error(e); process.exit(1); }); +`}, "\n") + out, err := runNodeStdin(node, script) + if err != nil || !strings.Contains(string(out), "ok") { + t.Fatalf("node timing settings fixture failed: %v\n%s", err, out) + } +} diff --git a/src/pkg/dashboard/static-src/css/tracker.css b/src/pkg/dashboard/static-src/css/tracker.css index 4579caa97d..e84ef59082 100644 --- a/src/pkg/dashboard/static-src/css/tracker.css +++ b/src/pkg/dashboard/static-src/css/tracker.css @@ -808,6 +808,8 @@ list with one Preview button each plus a sample row the previews play on. */ .sts-hint { color: var(--muted); font-size: var(--fs-xs); margin: 0; } .sts-row { display: flex; align-items: center; gap: var(--sp-3); color: var(--muted); font-size: var(--fs-xs); flex-wrap: wrap; } + .sts-timing-input { width: 6em; } + .sts-timing-unit { color: var(--muted); } .sts-motion-list { display: grid; gap: var(--sp-2); margin: 0; padding: 0; list-style: none; } .sts-motion-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border: var(--line-width) solid var(--line-subtle); border-radius: var(--r-sm); color: var(--muted); font-size: var(--fs-sm); } .sts-motion-item:has(input:checked) { border-color: var(--line-strong); background: var(--panel-strong); color: var(--text); } diff --git a/src/pkg/dashboard/static-src/js/tracker-actions.js b/src/pkg/dashboard/static-src/js/tracker-actions.js index 36d27ba1f3..5221430a6d 100644 --- a/src/pkg/dashboard/static-src/js/tracker-actions.js +++ b/src/pkg/dashboard/static-src/js/tracker-actions.js @@ -1709,12 +1709,48 @@ // toast says why in plain words and carries the next actions. const STAGE_TRACKER_ACTION_NO_EFFECT = 'no-effect'; const STAGE_TRACKER_RESULT_TOAST_MAX = 5; - // An informational result toast ("adopted", "/lgtm posted", a no-op) - // closes itself after this long, with the countdown bar and hover / - // focus pause every timed toast gets; it still leaves earlier on × or - // when the tracker reports the target in a new state. Errors and - // toasts carrying next-action buttons wait for the operator instead. - const STAGE_TRACKER_RESULT_TOAST_MS = 15000; + // Tracker toast lifetimes (hivecommons/hive#15813). An informational + // result toast ("adopted", "/lgtm posted", a no-op) and the waiting-on-you + // nudge close after the info duration; an + // error result closes after the error duration (it keeps its × for an + // earlier dismissal); a toast carrying next-action buttons is a prompt + // and waits for the operator. Both durations are the hive's + // dashboard.stage_tracker.toast_info_s / toast_error_s, read from the + // tracker payload's settings block; this browser's localStorage copy + // is only the fallback for when the server write was refused. + const STAGE_TRACKER_TOAST_DEFAULT_S = Object.freeze({ info: 15, error: 30 }); + const STAGE_TRACKER_TOAST_MIN_S = 3; + const STAGE_TRACKER_TOAST_MAX_S = 120; + const STAGE_TRACKER_TOAST_KEY = 'hive.tracker.toastS'; + // The merge banner stays this many times longer than an info toast + // (30 s at the default), so the two move together. + const STAGE_TRACKER_MERGE_BANNER_FACTOR = 2; + // Pure: a toast duration in seconds, or 0 when the value is not a + // usable number (0 itself means "the default"). + function stageTrackerToastSecondsValid(v) { + const n = Number(v); + if (!isFinite(n) || n <= 0) return 0; + return Math.max(STAGE_TRACKER_TOAST_MIN_S, Math.min(Math.round(n), STAGE_TRACKER_TOAST_MAX_S)); + } + // Pure: the effective duration in seconds for kind ('info' | 'error'). + // This browser's fallback copy wins when present — it only exists when + // the hive refused the write, so the payload still carries the old + // value — then the server's settings block, then the default. + function stageTrackerToastSeconds(kind, settings, local) { + kind = kind === 'error' ? 'error' : 'info'; + const fromLocal = stageTrackerToastSecondsValid(local && local[kind]); + if (fromLocal) return fromLocal; + const fromServer = stageTrackerToastSecondsValid(settings && settings['toast_' + kind + '_s']); + if (fromServer) return fromServer; + return STAGE_TRACKER_TOAST_DEFAULT_S[kind]; + } + function stageTrackerToastLocal() { + try { const v = JSON.parse(localStorage.getItem(STAGE_TRACKER_TOAST_KEY) || 'null'); return v && typeof v === 'object' ? v : null; } catch { return null; } + } + function stageTrackerToastMs(kind) { + return stageTrackerToastSeconds(kind, _stageTracker && _stageTracker.settings, stageTrackerToastLocal()) * 1000; + } + function stageTrackerMergeBannerMs() { return stageTrackerToastMs('info') * STAGE_TRACKER_MERGE_BANNER_FACTOR; } const STAGE_TRACKER_ACTING_MAX_MS = 180000; const STAGE_TRACKER_ACTING_CAPTIONS = { 'hold': 'Holding…', 'release': 'Releasing hold…', 'retry': 'Re-evaluating…', 'needs-human': 'Marking needs-human…', 'accept-triage': 'Accepting triage…', @@ -1849,8 +1885,9 @@ let _stageTrackerResultToasts = []; // Build and show the result toast; it leaves on ×, when the tracker // reports the target in a new state (see stageTrackerResultToastsSync) - // or, for a plain informational result, after - // STAGE_TRACKER_RESULT_TOAST_MS (see stageTrackerResultToastTimed). + // or, for a plain informational result, after the info toast duration + // (see stageTrackerResultToastTimed); an error leaves after the error + // toast duration. function stageTrackerResultToast(result, item, ctx) { const text = stageTrackerResultText(result, item, ctx); const container = document.getElementById('toast-container'); @@ -1888,7 +1925,8 @@ } if (container) container.appendChild(el); makeToastSticky(el); - if (stageTrackerResultToastTimed(text)) toastCountdownBar(el, STAGE_TRACKER_RESULT_TOAST_MS, () => dismissToast(el, null, null, true)); + if (text.type === 'error') toastCountdownBar(el, stageTrackerToastMs('error'), () => dismissToast(el, null, null, true)); + else if (stageTrackerResultToastTimed(text)) toastCountdownBar(el, stageTrackerToastMs('info'), () => dismissToast(el, null, null, true)); const key = stageTrackerTargetKey(result.target) || stageTrackerItemKey(item); const entry = { el, key, state: stageTrackerItemState(stageTrackerItemByKey(_stageTracker, key)), result, text }; if (text.type !== 'error') _stageTrackerResultToasts.push(entry); diff --git a/src/pkg/dashboard/static-src/js/tracker-merged.js b/src/pkg/dashboard/static-src/js/tracker-merged.js index b7b6c30ae0..2732784dd9 100644 --- a/src/pkg/dashboard/static-src/js/tracker-merged.js +++ b/src/pkg/dashboard/static-src/js/tracker-merged.js @@ -840,7 +840,8 @@ return { number: num, head: `${num ? '#' + num + ' ' : ''}merged${b.preview ? ' (test)' : ''}`, text: `${b.title || b.repo || ''}${paren ? ' (' + paren + ')' : ''}`.trim() }; } // Stateful: a persistent banner, bottom right, for one merge — stays - // until dismissed or STAGE_TRACKER_MERGE_BANNER_MS, stacked when + // until dismissed or stageTrackerMergeBannerMs() (twice the info toast + // duration, STAGE_TRACKER_MERGE_BANNER_MS at the default), stacked when // several, with a "show row" link while the row is on the board. function stageTrackerMergeBanner(b) { if (!document.body) return null; @@ -859,7 +860,7 @@ el.innerHTML = `
${num ? `#${esc(num)} ` : ''}merged${info.preview ? ' (test)' : ''}
${esc(t.text)}
`; box.appendChild(el); while (box.children.length > STAGE_TRACKER_MERGE_BANNER_MAX) box.children[0].remove(); - el._timer = setTimeout(() => stageTrackerMergeBannerDismiss(el), STAGE_TRACKER_MERGE_BANNER_MS); + el._timer = setTimeout(() => stageTrackerMergeBannerDismiss(el), stageTrackerMergeBannerMs()); return el; } function stageTrackerMergeBannerDismiss(el) { diff --git a/src/pkg/dashboard/static-src/js/tracker-sound.js b/src/pkg/dashboard/static-src/js/tracker-sound.js index 5deeaccaf7..ec4034fad3 100644 --- a/src/pkg/dashboard/static-src/js/tracker-sound.js +++ b/src/pkg/dashboard/static-src/js/tracker-sound.js @@ -407,15 +407,89 @@ + stageTrackerConfirmSectionHtml(state.skippedConfirms) + stageTrackerCelebrateSectionHtml(state.celebrate !== false, state.celebrateGlyph) + stageTrackerNoteTuckSectionHtml(state.noteTuck !== false) + + stageTrackerTimingSectionHtml(state.timing || {}) + stageTrackerMotionSectionHtml(state.motion, state.stages || []); } + // Pure: the Toasts & timing section (hivecommons/hive#15813) — the info + // and error toast durations and the contributor lane's pre-merge soak. + // Values are the hive's (every browser sees the same), written through + // the dashboard's config overlay so they survive a reload and a roll. + function stageTrackerTimingSectionHtml(t) { + const num = (id, action, value, min, max, unit, label) => ``; + const info = stageTrackerToastSecondsValid(t.toastInfoS) || STAGE_TRACKER_TOAST_DEFAULT_S.info; + const error = stageTrackerToastSecondsValid(t.toastErrorS) || STAGE_TRACKER_TOAST_DEFAULT_S.error; + const soak = Number(t.soakMinutes) >= 1 ? Math.round(Number(t.soakMinutes)) : STAGE_TRACKER_SOAK_DEFAULT_MIN; + return `
+
Toasts & timing
+

How long the tracker's toasts stay: result and waiting-on-you toasts use the info duration, failed actions the error duration, and the merge banner twice the info duration. ${STAGE_TRACKER_TOAST_MIN_S}–${STAGE_TRACKER_TOAST_MAX_S} s; every toast keeps its × and pauses while hovered. Saved for the whole hive (dashboard.stage_tracker.toast_info_s / toast_error_s).

+
${num('sts-toast-info', 'stageTrackerToastInfoChange', info, STAGE_TRACKER_TOAST_MIN_S, STAGE_TRACKER_TOAST_MAX_S, 's', 'Info toast')}${num('sts-toast-error', 'stageTrackerToastErrorChange', error, STAGE_TRACKER_TOAST_MIN_S, STAGE_TRACKER_TOAST_MAX_S, 's', 'Error toast')}${t.fallback ? 'Saved in this browser only — the hive refused the write.' : 'Defaults ' + STAGE_TRACKER_TOAST_DEFAULT_S.info + ' s / ' + STAGE_TRACKER_TOAST_DEFAULT_S.error + ' s.'}
+

The contributor lane holds a green head this long before it merges (auto_merge.contributor_lane.soak_minutes, default ${STAGE_TRACKER_SOAK_DEFAULT_MIN}). The lane re-reads it on every pass, so a running soak follows the new window too — a head counts as soaked once it has been green for this long.

+
${num('sts-soak', 'stageTrackerSoakChange', soak, 1, 100000, 'minutes', 'Pre-merge soak')}
+
`; + } + const STAGE_TRACKER_SOAK_DEFAULT_MIN = 30; + // The settings the Timing section shows: the tracker payload's block + // (the hive's values), with the browser fallback when a write failed. + function stageTrackerTimingState() { + const st = (_stageTracker && _stageTracker.settings) || {}; + const local = stageTrackerToastLocal(); + return { + toastInfoS: stageTrackerToastSeconds('info', st, local), + toastErrorS: stageTrackerToastSeconds('error', st, local), + soakMinutes: st.soak_minutes, + fallback: !!(local && local.fallback), + }; + } + function stageTrackerTimingHeaders() { + return Object.assign({ 'Content-Type': 'application/json' }, typeof _inceptionAuthHeaders === 'function' ? _inceptionAuthHeaders() : {}); + } + // Save one toast duration: the hive first (PUT /api/config/dashboard), + // this browser's localStorage only when that write is refused. + async function stageTrackerSaveToastSeconds(kind, input) { + const secs = stageTrackerToastSecondsValid(input && input.value); + if (!secs) { if (input) input.value = String(stageTrackerToastSeconds(kind, _stageTracker && _stageTracker.settings, stageTrackerToastLocal())); return false; } + if (input) input.value = String(secs); + const field = 'toast_' + kind + '_s'; + let saved = false; + try { + const r = await fetch('/api/config/dashboard', { method: 'PUT', headers: stageTrackerTimingHeaders(), body: JSON.stringify({ stage_tracker: { [field]: secs } }) }); + saved = !!(r && r.ok); + } catch { saved = false; } + if (saved) { + if (_stageTracker) { _stageTracker.settings = Object.assign({}, _stageTracker.settings, { [field]: secs }); } + try { localStorage.removeItem(STAGE_TRACKER_TOAST_KEY); } catch {} + } else if (!(window.hiveKioskMode && window.hiveKioskMode())) { + try { localStorage.setItem(STAGE_TRACKER_TOAST_KEY, JSON.stringify(Object.assign({}, stageTrackerToastLocal() || {}, { [kind]: secs, fallback: true }))); } catch {} + } + stageTrackerRenderSettings(); + if (typeof showToast === 'function') showToast(saved ? (kind === 'error' ? 'Error' : 'Info') + ' toasts now stay ' + secs + ' s' : 'Could not save to the hive — ' + secs + ' s applies in this browser only', saved ? 'success' : 'warning'); + return saved; + } + function stageTrackerToastInfoChange(input) { return stageTrackerSaveToastSeconds('info', input); } + function stageTrackerToastErrorChange(input) { return stageTrackerSaveToastSeconds('error', input); } + // Save the contributor lane's soak through the auto-merge config + // endpoint (the same write the Settings page makes). + async function stageTrackerSoakChange(input) { + const mins = Math.round(Number(input && input.value)); + if (!isFinite(mins) || mins < 1) { if (input) input.value = String(stageTrackerTimingState().soakMinutes || STAGE_TRACKER_SOAK_DEFAULT_MIN); return false; } + let ok = false, msg = ''; + try { + const r = await fetch('/api/config/auto-merge', { method: 'PUT', headers: stageTrackerTimingHeaders(), body: JSON.stringify({ contributor_lane: { soak_minutes: mins } }) }); + ok = !!(r && r.ok); + if (!ok && r) { try { const j = await r.json(); msg = j && j.error ? j.error : ''; } catch {} } + } catch (e) { msg = e && e.message ? e.message : ''; } + if (ok && _stageTracker) _stageTracker.settings = Object.assign({}, _stageTracker.settings, { soak_minutes: mins }); + stageTrackerRenderSettings(); + if (typeof showToast === 'function') showToast(ok ? 'Pre-merge soak is now ' + mins + ' min — applies on the lane\'s next pass' : 'Could not save the soak' + (msg ? ': ' + msg : ''), ok ? 'success' : 'error'); + return ok; + } // Pure: the Merges section — the "Celebrate merges" toggle, the glyph. function stageTrackerCelebrateSectionHtml(on, glyph) { const glyphId = stageTrackerCelebrateGlyphId(glyph); const opts = Object.keys(STAGE_TRACKER_CELEBRATE_GLYPHS).map(id => ``).join(''); return `
Merges
-

When a pull request merges its row stays for a moment, its ✓ cell glows and a glyph (the bee) rises from it towards the top of the window — landing on the "Merged" chip when it is in view, otherwise leaving through the top edge — the count rolls up like an odometer, and a banner at the bottom right names the merge until dismissed (or 30 s). Under reduced motion the glyph fades in place. The chip's number is the hive's all-time count (kept on the server, so it survives a reload); click it for the recent merges.

+

When a pull request merges its row stays for a moment, its ✓ cell glows and a glyph (the bee) rises from it towards the top of the window — landing on the "Merged" chip when it is in view, otherwise leaving through the top edge — the count rolls up like an odometer, and a banner at the bottom right names the merge until dismissed (or twice the info toast duration — see Toasts & timing). Under reduced motion the glyph fades in place. The chip's number is the hive's all-time count (kept on the server, so it survives a reload); click it for the recent merges.

`; } @@ -486,7 +560,7 @@ if (!body) return; const names = {}; for (const kind of Object.keys(STAGE_TRACKER_SOUND_KINDS)) names[kind] = stageTrackerClipStatusText(kind); - setIfChanged(body, stageTrackerSettingsHtml({ on: _stageTrackerSoundOn, volume: _stageTrackerVolume, clips: _stageTrackerClips, names, motion: stageTrackerMotionSetting(), stages: (_stageTracker && _stageTracker.stages) || [], celebrate: stageTrackerCelebrateSetting(), noteTuck: stageTrackerNoteTuckSetting(), celebrateGlyph: stageTrackerCelebrateGlyphId((() => { try { return localStorage.getItem(STAGE_TRACKER_CELEBRATE_GLYPH_KEY); } catch { return null; } })()), skippedConfirms: stageTrackerSkippedConfirms(), repoChip: stageTrackerRepoChipSetting(), group: _stageTrackerGroup })); + setIfChanged(body, stageTrackerSettingsHtml({ on: _stageTrackerSoundOn, volume: _stageTrackerVolume, clips: _stageTrackerClips, names, motion: stageTrackerMotionSetting(), stages: (_stageTracker && _stageTracker.stages) || [], celebrate: stageTrackerCelebrateSetting(), noteTuck: stageTrackerNoteTuckSetting(), celebrateGlyph: stageTrackerCelebrateGlyphId((() => { try { return localStorage.getItem(STAGE_TRACKER_CELEBRATE_GLYPH_KEY); } catch { return null; } })()), skippedConfirms: stageTrackerSkippedConfirms(), timing: stageTrackerTimingState(), repoChip: stageTrackerRepoChipSetting(), group: _stageTrackerGroup })); const rm = document.getElementById('sts-rm-preview'); if (rm) rm.checked = document.body.classList.contains('ham-rm-preview'); } diff --git a/src/pkg/dashboard/static-src/js/tracker-waiting.js b/src/pkg/dashboard/static-src/js/tracker-waiting.js index 4b1ba4a5db..cd12e36ba6 100644 --- a/src/pkg/dashboard/static-src/js/tracker-waiting.js +++ b/src/pkg/dashboard/static-src/js/tracker-waiting.js @@ -10,7 +10,6 @@ rises. All three land on the Activity Monitor with the Waiting on you filter (?filter=waiting-on-you deep-links to the same view). */ const STAGE_TRACKER_WAITING_TOAST_GAP_MS = 10 * 60 * 1000; - const STAGE_TRACKER_WAITING_TOAST_MS = 12000; const STAGE_TRACKER_WAITING_TOOLTIP_MAX = 5; const STAGE_TRACKER_WAITING_TOAST_NUMBERS = 3; const STAGE_TRACKER_WAITING_TOAST_KEY = 'hive-waiting-on-you-toast-at'; @@ -86,7 +85,7 @@ if (nowMs - last < STAGE_TRACKER_WAITING_TOAST_GAP_MS) return; try { localStorage.setItem(STAGE_TRACKER_WAITING_TOAST_KEY, String(nowMs)); } catch {} if (typeof showToast !== 'function') return; - showToast(stageTrackerWaitingToastText(w), 'warning', { actionLabel: 'Show', onAction: showWaitingOnYou, autoDismissMs: STAGE_TRACKER_WAITING_TOAST_MS }); + showToast(stageTrackerWaitingToastText(w), 'warning', { actionLabel: 'Show', onAction: showWaitingOnYou, autoDismissMs: stageTrackerToastMs('info') }); } function stageTrackerWaitingToastText(w) { diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index c14ecd8ad1..521ed201f7 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -2137,6 +2137,8 @@ list with one Preview button each plus a sample row the previews play on. */ .sts-hint { color: var(--muted); font-size: var(--fs-xs); margin: 0; } .sts-row { display: flex; align-items: center; gap: var(--sp-3); color: var(--muted); font-size: var(--fs-xs); flex-wrap: wrap; } + .sts-timing-input { width: 6em; } + .sts-timing-unit { color: var(--muted); } .sts-motion-list { display: grid; gap: var(--sp-2); margin: 0; padding: 0; list-style: none; } .sts-motion-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border: var(--line-width) solid var(--line-subtle); border-radius: var(--r-sm); color: var(--muted); font-size: var(--fs-sm); } .sts-motion-item:has(input:checked) { border-color: var(--line-strong); background: var(--panel-strong); color: var(--text); } @@ -21182,12 +21184,48 @@

All labels

// toast says why in plain words and carries the next actions. const STAGE_TRACKER_ACTION_NO_EFFECT = 'no-effect'; const STAGE_TRACKER_RESULT_TOAST_MAX = 5; - // An informational result toast ("adopted", "/lgtm posted", a no-op) - // closes itself after this long, with the countdown bar and hover / - // focus pause every timed toast gets; it still leaves earlier on × or - // when the tracker reports the target in a new state. Errors and - // toasts carrying next-action buttons wait for the operator instead. - const STAGE_TRACKER_RESULT_TOAST_MS = 15000; + // Tracker toast lifetimes (hivecommons/hive#15813). An informational + // result toast ("adopted", "/lgtm posted", a no-op) and the waiting-on-you + // nudge close after the info duration; an + // error result closes after the error duration (it keeps its × for an + // earlier dismissal); a toast carrying next-action buttons is a prompt + // and waits for the operator. Both durations are the hive's + // dashboard.stage_tracker.toast_info_s / toast_error_s, read from the + // tracker payload's settings block; this browser's localStorage copy + // is only the fallback for when the server write was refused. + const STAGE_TRACKER_TOAST_DEFAULT_S = Object.freeze({ info: 15, error: 30 }); + const STAGE_TRACKER_TOAST_MIN_S = 3; + const STAGE_TRACKER_TOAST_MAX_S = 120; + const STAGE_TRACKER_TOAST_KEY = 'hive.tracker.toastS'; + // The merge banner stays this many times longer than an info toast + // (30 s at the default), so the two move together. + const STAGE_TRACKER_MERGE_BANNER_FACTOR = 2; + // Pure: a toast duration in seconds, or 0 when the value is not a + // usable number (0 itself means "the default"). + function stageTrackerToastSecondsValid(v) { + const n = Number(v); + if (!isFinite(n) || n <= 0) return 0; + return Math.max(STAGE_TRACKER_TOAST_MIN_S, Math.min(Math.round(n), STAGE_TRACKER_TOAST_MAX_S)); + } + // Pure: the effective duration in seconds for kind ('info' | 'error'). + // This browser's fallback copy wins when present — it only exists when + // the hive refused the write, so the payload still carries the old + // value — then the server's settings block, then the default. + function stageTrackerToastSeconds(kind, settings, local) { + kind = kind === 'error' ? 'error' : 'info'; + const fromLocal = stageTrackerToastSecondsValid(local && local[kind]); + if (fromLocal) return fromLocal; + const fromServer = stageTrackerToastSecondsValid(settings && settings['toast_' + kind + '_s']); + if (fromServer) return fromServer; + return STAGE_TRACKER_TOAST_DEFAULT_S[kind]; + } + function stageTrackerToastLocal() { + try { const v = JSON.parse(localStorage.getItem(STAGE_TRACKER_TOAST_KEY) || 'null'); return v && typeof v === 'object' ? v : null; } catch { return null; } + } + function stageTrackerToastMs(kind) { + return stageTrackerToastSeconds(kind, _stageTracker && _stageTracker.settings, stageTrackerToastLocal()) * 1000; + } + function stageTrackerMergeBannerMs() { return stageTrackerToastMs('info') * STAGE_TRACKER_MERGE_BANNER_FACTOR; } const STAGE_TRACKER_ACTING_MAX_MS = 180000; const STAGE_TRACKER_ACTING_CAPTIONS = { 'hold': 'Holding…', 'release': 'Releasing hold…', 'retry': 'Re-evaluating…', 'needs-human': 'Marking needs-human…', 'accept-triage': 'Accepting triage…', @@ -21322,8 +21360,9 @@

All labels

let _stageTrackerResultToasts = []; // Build and show the result toast; it leaves on ×, when the tracker // reports the target in a new state (see stageTrackerResultToastsSync) - // or, for a plain informational result, after - // STAGE_TRACKER_RESULT_TOAST_MS (see stageTrackerResultToastTimed). + // or, for a plain informational result, after the info toast duration + // (see stageTrackerResultToastTimed); an error leaves after the error + // toast duration. function stageTrackerResultToast(result, item, ctx) { const text = stageTrackerResultText(result, item, ctx); const container = document.getElementById('toast-container'); @@ -21361,7 +21400,8 @@

All labels

} if (container) container.appendChild(el); makeToastSticky(el); - if (stageTrackerResultToastTimed(text)) toastCountdownBar(el, STAGE_TRACKER_RESULT_TOAST_MS, () => dismissToast(el, null, null, true)); + if (text.type === 'error') toastCountdownBar(el, stageTrackerToastMs('error'), () => dismissToast(el, null, null, true)); + else if (stageTrackerResultToastTimed(text)) toastCountdownBar(el, stageTrackerToastMs('info'), () => dismissToast(el, null, null, true)); const key = stageTrackerTargetKey(result.target) || stageTrackerItemKey(item); const entry = { el, key, state: stageTrackerItemState(stageTrackerItemByKey(_stageTracker, key)), result, text }; if (text.type !== 'error') _stageTrackerResultToasts.push(entry); @@ -22520,7 +22560,8 @@

All labels

return { number: num, head: `${num ? '#' + num + ' ' : ''}merged${b.preview ? ' (test)' : ''}`, text: `${b.title || b.repo || ''}${paren ? ' (' + paren + ')' : ''}`.trim() }; } // Stateful: a persistent banner, bottom right, for one merge — stays - // until dismissed or STAGE_TRACKER_MERGE_BANNER_MS, stacked when + // until dismissed or stageTrackerMergeBannerMs() (twice the info toast + // duration, STAGE_TRACKER_MERGE_BANNER_MS at the default), stacked when // several, with a "show row" link while the row is on the board. function stageTrackerMergeBanner(b) { if (!document.body) return null; @@ -22539,7 +22580,7 @@

All labels

el.innerHTML = `
${num ? `#${esc(num)} ` : ''}merged${info.preview ? ' (test)' : ''}
${esc(t.text)}
`; box.appendChild(el); while (box.children.length > STAGE_TRACKER_MERGE_BANNER_MAX) box.children[0].remove(); - el._timer = setTimeout(() => stageTrackerMergeBannerDismiss(el), STAGE_TRACKER_MERGE_BANNER_MS); + el._timer = setTimeout(() => stageTrackerMergeBannerDismiss(el), stageTrackerMergeBannerMs()); return el; } function stageTrackerMergeBannerDismiss(el) { @@ -23095,15 +23136,89 @@

All labels

+ stageTrackerConfirmSectionHtml(state.skippedConfirms) + stageTrackerCelebrateSectionHtml(state.celebrate !== false, state.celebrateGlyph) + stageTrackerNoteTuckSectionHtml(state.noteTuck !== false) + + stageTrackerTimingSectionHtml(state.timing || {}) + stageTrackerMotionSectionHtml(state.motion, state.stages || []); } + // Pure: the Toasts & timing section (hivecommons/hive#15813) — the info + // and error toast durations and the contributor lane's pre-merge soak. + // Values are the hive's (every browser sees the same), written through + // the dashboard's config overlay so they survive a reload and a roll. + function stageTrackerTimingSectionHtml(t) { + const num = (id, action, value, min, max, unit, label) => ``; + const info = stageTrackerToastSecondsValid(t.toastInfoS) || STAGE_TRACKER_TOAST_DEFAULT_S.info; + const error = stageTrackerToastSecondsValid(t.toastErrorS) || STAGE_TRACKER_TOAST_DEFAULT_S.error; + const soak = Number(t.soakMinutes) >= 1 ? Math.round(Number(t.soakMinutes)) : STAGE_TRACKER_SOAK_DEFAULT_MIN; + return `
+
Toasts & timing
+

How long the tracker's toasts stay: result and waiting-on-you toasts use the info duration, failed actions the error duration, and the merge banner twice the info duration. ${STAGE_TRACKER_TOAST_MIN_S}–${STAGE_TRACKER_TOAST_MAX_S} s; every toast keeps its × and pauses while hovered. Saved for the whole hive (dashboard.stage_tracker.toast_info_s / toast_error_s).

+
${num('sts-toast-info', 'stageTrackerToastInfoChange', info, STAGE_TRACKER_TOAST_MIN_S, STAGE_TRACKER_TOAST_MAX_S, 's', 'Info toast')}${num('sts-toast-error', 'stageTrackerToastErrorChange', error, STAGE_TRACKER_TOAST_MIN_S, STAGE_TRACKER_TOAST_MAX_S, 's', 'Error toast')}${t.fallback ? 'Saved in this browser only — the hive refused the write.' : 'Defaults ' + STAGE_TRACKER_TOAST_DEFAULT_S.info + ' s / ' + STAGE_TRACKER_TOAST_DEFAULT_S.error + ' s.'}
+

The contributor lane holds a green head this long before it merges (auto_merge.contributor_lane.soak_minutes, default ${STAGE_TRACKER_SOAK_DEFAULT_MIN}). The lane re-reads it on every pass, so a running soak follows the new window too — a head counts as soaked once it has been green for this long.

+
${num('sts-soak', 'stageTrackerSoakChange', soak, 1, 100000, 'minutes', 'Pre-merge soak')}
+
`; + } + const STAGE_TRACKER_SOAK_DEFAULT_MIN = 30; + // The settings the Timing section shows: the tracker payload's block + // (the hive's values), with the browser fallback when a write failed. + function stageTrackerTimingState() { + const st = (_stageTracker && _stageTracker.settings) || {}; + const local = stageTrackerToastLocal(); + return { + toastInfoS: stageTrackerToastSeconds('info', st, local), + toastErrorS: stageTrackerToastSeconds('error', st, local), + soakMinutes: st.soak_minutes, + fallback: !!(local && local.fallback), + }; + } + function stageTrackerTimingHeaders() { + return Object.assign({ 'Content-Type': 'application/json' }, typeof _inceptionAuthHeaders === 'function' ? _inceptionAuthHeaders() : {}); + } + // Save one toast duration: the hive first (PUT /api/config/dashboard), + // this browser's localStorage only when that write is refused. + async function stageTrackerSaveToastSeconds(kind, input) { + const secs = stageTrackerToastSecondsValid(input && input.value); + if (!secs) { if (input) input.value = String(stageTrackerToastSeconds(kind, _stageTracker && _stageTracker.settings, stageTrackerToastLocal())); return false; } + if (input) input.value = String(secs); + const field = 'toast_' + kind + '_s'; + let saved = false; + try { + const r = await fetch('/api/config/dashboard', { method: 'PUT', headers: stageTrackerTimingHeaders(), body: JSON.stringify({ stage_tracker: { [field]: secs } }) }); + saved = !!(r && r.ok); + } catch { saved = false; } + if (saved) { + if (_stageTracker) { _stageTracker.settings = Object.assign({}, _stageTracker.settings, { [field]: secs }); } + try { localStorage.removeItem(STAGE_TRACKER_TOAST_KEY); } catch {} + } else if (!(window.hiveKioskMode && window.hiveKioskMode())) { + try { localStorage.setItem(STAGE_TRACKER_TOAST_KEY, JSON.stringify(Object.assign({}, stageTrackerToastLocal() || {}, { [kind]: secs, fallback: true }))); } catch {} + } + stageTrackerRenderSettings(); + if (typeof showToast === 'function') showToast(saved ? (kind === 'error' ? 'Error' : 'Info') + ' toasts now stay ' + secs + ' s' : 'Could not save to the hive — ' + secs + ' s applies in this browser only', saved ? 'success' : 'warning'); + return saved; + } + function stageTrackerToastInfoChange(input) { return stageTrackerSaveToastSeconds('info', input); } + function stageTrackerToastErrorChange(input) { return stageTrackerSaveToastSeconds('error', input); } + // Save the contributor lane's soak through the auto-merge config + // endpoint (the same write the Settings page makes). + async function stageTrackerSoakChange(input) { + const mins = Math.round(Number(input && input.value)); + if (!isFinite(mins) || mins < 1) { if (input) input.value = String(stageTrackerTimingState().soakMinutes || STAGE_TRACKER_SOAK_DEFAULT_MIN); return false; } + let ok = false, msg = ''; + try { + const r = await fetch('/api/config/auto-merge', { method: 'PUT', headers: stageTrackerTimingHeaders(), body: JSON.stringify({ contributor_lane: { soak_minutes: mins } }) }); + ok = !!(r && r.ok); + if (!ok && r) { try { const j = await r.json(); msg = j && j.error ? j.error : ''; } catch {} } + } catch (e) { msg = e && e.message ? e.message : ''; } + if (ok && _stageTracker) _stageTracker.settings = Object.assign({}, _stageTracker.settings, { soak_minutes: mins }); + stageTrackerRenderSettings(); + if (typeof showToast === 'function') showToast(ok ? 'Pre-merge soak is now ' + mins + ' min — applies on the lane\'s next pass' : 'Could not save the soak' + (msg ? ': ' + msg : ''), ok ? 'success' : 'error'); + return ok; + } // Pure: the Merges section — the "Celebrate merges" toggle, the glyph. function stageTrackerCelebrateSectionHtml(on, glyph) { const glyphId = stageTrackerCelebrateGlyphId(glyph); const opts = Object.keys(STAGE_TRACKER_CELEBRATE_GLYPHS).map(id => ``).join(''); return `
Merges
-

When a pull request merges its row stays for a moment, its ✓ cell glows and a glyph (the bee) rises from it towards the top of the window — landing on the "Merged" chip when it is in view, otherwise leaving through the top edge — the count rolls up like an odometer, and a banner at the bottom right names the merge until dismissed (or 30 s). Under reduced motion the glyph fades in place. The chip's number is the hive's all-time count (kept on the server, so it survives a reload); click it for the recent merges.

+

When a pull request merges its row stays for a moment, its ✓ cell glows and a glyph (the bee) rises from it towards the top of the window — landing on the "Merged" chip when it is in view, otherwise leaving through the top edge — the count rolls up like an odometer, and a banner at the bottom right names the merge until dismissed (or twice the info toast duration — see Toasts & timing). Under reduced motion the glyph fades in place. The chip's number is the hive's all-time count (kept on the server, so it survives a reload); click it for the recent merges.

`; } @@ -23174,7 +23289,7 @@

All labels

if (!body) return; const names = {}; for (const kind of Object.keys(STAGE_TRACKER_SOUND_KINDS)) names[kind] = stageTrackerClipStatusText(kind); - setIfChanged(body, stageTrackerSettingsHtml({ on: _stageTrackerSoundOn, volume: _stageTrackerVolume, clips: _stageTrackerClips, names, motion: stageTrackerMotionSetting(), stages: (_stageTracker && _stageTracker.stages) || [], celebrate: stageTrackerCelebrateSetting(), noteTuck: stageTrackerNoteTuckSetting(), celebrateGlyph: stageTrackerCelebrateGlyphId((() => { try { return localStorage.getItem(STAGE_TRACKER_CELEBRATE_GLYPH_KEY); } catch { return null; } })()), skippedConfirms: stageTrackerSkippedConfirms(), repoChip: stageTrackerRepoChipSetting(), group: _stageTrackerGroup })); + setIfChanged(body, stageTrackerSettingsHtml({ on: _stageTrackerSoundOn, volume: _stageTrackerVolume, clips: _stageTrackerClips, names, motion: stageTrackerMotionSetting(), stages: (_stageTracker && _stageTracker.stages) || [], celebrate: stageTrackerCelebrateSetting(), noteTuck: stageTrackerNoteTuckSetting(), celebrateGlyph: stageTrackerCelebrateGlyphId((() => { try { return localStorage.getItem(STAGE_TRACKER_CELEBRATE_GLYPH_KEY); } catch { return null; } })()), skippedConfirms: stageTrackerSkippedConfirms(), timing: stageTrackerTimingState(), repoChip: stageTrackerRepoChipSetting(), group: _stageTrackerGroup })); const rm = document.getElementById('sts-rm-preview'); if (rm) rm.checked = document.body.classList.contains('ham-rm-preview'); } @@ -23395,7 +23510,6 @@

All labels

rises. All three land on the Activity Monitor with the Waiting on you filter (?filter=waiting-on-you deep-links to the same view). */ const STAGE_TRACKER_WAITING_TOAST_GAP_MS = 10 * 60 * 1000; - const STAGE_TRACKER_WAITING_TOAST_MS = 12000; const STAGE_TRACKER_WAITING_TOOLTIP_MAX = 5; const STAGE_TRACKER_WAITING_TOAST_NUMBERS = 3; const STAGE_TRACKER_WAITING_TOAST_KEY = 'hive-waiting-on-you-toast-at'; @@ -23471,7 +23585,7 @@

All labels

if (nowMs - last < STAGE_TRACKER_WAITING_TOAST_GAP_MS) return; try { localStorage.setItem(STAGE_TRACKER_WAITING_TOAST_KEY, String(nowMs)); } catch {} if (typeof showToast !== 'function') return; - showToast(stageTrackerWaitingToastText(w), 'warning', { actionLabel: 'Show', onAction: showWaitingOnYou, autoDismissMs: STAGE_TRACKER_WAITING_TOAST_MS }); + showToast(stageTrackerWaitingToastText(w), 'warning', { actionLabel: 'Show', onAction: showWaitingOnYou, autoDismissMs: stageTrackerToastMs('info') }); } function stageTrackerWaitingToastText(w) { diff --git a/src/pkg/dashboard/toast_countdown_bar_test.go b/src/pkg/dashboard/toast_countdown_bar_test.go index a613d7565c..445673dda9 100644 --- a/src/pkg/dashboard/toast_countdown_bar_test.go +++ b/src/pkg/dashboard/toast_countdown_bar_test.go @@ -87,13 +87,17 @@ func TestToastCountdownBarWiredToDismissTimer(t *testing.T) { } // Stage-tracker action-result toasts: informational ones close after - // STAGE_TRACKER_RESULT_TOAST_MS on the same countdown; errors and - // toasts offering next actions stay sticky. - if !strings.Contains(html, "const STAGE_TRACKER_RESULT_TOAST_MS = 15000;") { - t.Error("result toasts need a named 15s lifetime constant") + // the info toast duration and errors after the error toast duration + // (dashboard.stage_tracker.toast_info_s / toast_error_s, #15813) on + // the same countdown; toasts offering next actions stay sticky. + if !strings.Contains(html, "const STAGE_TRACKER_TOAST_DEFAULT_S = Object.freeze({ info: 15, error: 30 });") { + t.Error("tracker toasts need named 15 s / 30 s default lifetimes") } result := extractJSFunction(t, html, "stageTrackerResultToast") - if !strings.Contains(result, "if (stageTrackerResultToastTimed(text)) toastCountdownBar(el, STAGE_TRACKER_RESULT_TOAST_MS, () => dismissToast(el, null, null, true));") { + if !strings.Contains(result, "if (text.type === 'error') toastCountdownBar(el, stageTrackerToastMs('error'), () => dismissToast(el, null, null, true));") { + t.Error("stageTrackerResultToast must arm the shared countdown for errors with the error toast duration") + } + if !strings.Contains(result, "else if (stageTrackerResultToastTimed(text)) toastCountdownBar(el, stageTrackerToastMs('info'), () => dismissToast(el, null, null, true));") { t.Error("stageTrackerResultToast must arm the shared countdown for timed results, dismissing through the sticky guard") } timed := extractJSFunction(t, html, "stageTrackerResultToastTimed") From 20465b77db1458e758ffe85524db33d5a180529d Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Fri, 30 Oct 2026 12:36:38 -0400 Subject: [PATCH 2/3] test: stub stageTrackerToastMs in waiting node suite Signed-off-by: Andrew Anderson --- src/pkg/dashboard/stage_tracker_waiting.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkg/dashboard/stage_tracker_waiting.test.js b/src/pkg/dashboard/stage_tracker_waiting.test.js index 39914a9d3f..4c89c3274a 100644 --- a/src/pkg/dashboard/stage_tracker_waiting.test.js +++ b/src/pkg/dashboard/stage_tracker_waiting.test.js @@ -29,7 +29,8 @@ function load(env) { 'function stageTrackerSaveFilter() {}', 'var _stageTrackerFilter = {};', pick(/const STAGE_TRACKER_WAITING_TOAST_GAP_MS = [^\n]*\n/, 'GAP'), - pick(/const STAGE_TRACKER_WAITING_TOAST_MS = [^\n]*\n/, 'TOAST_MS'), + // Toast duration comes from the Activity Monitor settings (#15813). + 'function stageTrackerToastMs() { return 15000; }', pick(/const STAGE_TRACKER_WAITING_TOOLTIP_MAX = [^\n]*\n/, 'TOOLTIP_MAX'), pick(/const STAGE_TRACKER_WAITING_TOAST_NUMBERS = [^\n]*\n/, 'TOAST_NUMBERS'), pick(/const STAGE_TRACKER_WAITING_TOAST_KEY = [^\n]*\n/, 'TOAST_KEY'), From bac2b8ca7b7dbb4a0c3bec5cbb1a1331a48bdd28 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Fri, 30 Oct 2026 13:16:18 -0400 Subject: [PATCH 3/3] test: cover stage tracker toast knob accessors in pkg/config Signed-off-by: Andrew Anderson --- src/pkg/config/stage_tracker_toast_test.go | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/pkg/config/stage_tracker_toast_test.go diff --git a/src/pkg/config/stage_tracker_toast_test.go b/src/pkg/config/stage_tracker_toast_test.go new file mode 100644 index 0000000000..958b358826 --- /dev/null +++ b/src/pkg/config/stage_tracker_toast_test.go @@ -0,0 +1,55 @@ +package config + +import ( + "testing" + "time" + + "gopkg.in/yaml.v3" +) + +// Toast duration knobs (hivecommons/hive#15813): defaults when unset or nil, +// clamped to [MinStageTrackerToastS, MaxStageTrackerToastS] otherwise. +func TestStageTrackerToastAccessors(t *testing.T) { + var nilCfg *Config + if got := nilCfg.StageTrackerToastInfo(); got != DefaultStageTrackerToastInfoS*time.Second { + t.Fatalf("nil info = %v", got) + } + if got := nilCfg.StageTrackerToastError(); got != DefaultStageTrackerToastErrorS*time.Second { + t.Fatalf("nil error = %v", got) + } + + cases := []struct { + name string + info, errS int + wantInfo, wantE time.Duration + }{ + {"unset", 0, 0, 15 * time.Second, 30 * time.Second}, + {"configured", 20, 45, 20 * time.Second, 45 * time.Second}, + {"clamped low", 1, -7, 3 * time.Second, 3 * time.Second}, + {"clamped high", 500, 121, 120 * time.Second, 120 * time.Second}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + var c Config + c.Dashboard.StageTracker.ToastInfoS = tc.info + c.Dashboard.StageTracker.ToastErrorS = tc.errS + if got := c.StageTrackerToastInfo(); got != tc.wantInfo { + t.Errorf("info = %v, want %v", got, tc.wantInfo) + } + if got := c.StageTrackerToastError(); got != tc.wantE { + t.Errorf("error = %v, want %v", got, tc.wantE) + } + }) + } +} + +func TestStageTrackerToastYAMLKeys(t *testing.T) { + var c Config + src := "dashboard:\n stage_tracker:\n toast_info_s: 9\n toast_error_s: 60\n" + if err := yaml.Unmarshal([]byte(src), &c); err != nil { + t.Fatal(err) + } + if c.StageTrackerToastInfo() != 9*time.Second || c.StageTrackerToastError() != 60*time.Second { + t.Fatalf("yaml keys not wired: info=%v error=%v", c.StageTrackerToastInfo(), c.StageTrackerToastError()) + } +}