From d3139063ad1c760ddacc042aa6db3bdd7393fbd9 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Mon, 2 Nov 2026 10:19:11 -0500 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20feat:=20kiosk=20'Request=20a=20?= =?UTF-8?q?Hive'=20call-to-action=20badge,=20Twitch=20channel=20metadata?= =?UTF-8?q?=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrew Anderson --- changelog.d/added-16236-kiosk-cta.md | 1 + src/docs/env-vars.md | 2 + src/docs/streaming-the-activity-monitor.md | 49 ++++++ src/pkg/config/config.go | 6 + src/pkg/dashboard/kiosk_cta.go | 17 ++ src/pkg/dashboard/kiosk_cta.test.js | 35 ++++ src/pkg/dashboard/kiosk_cta_test.go | 30 ++++ src/pkg/dashboard/server.go | 4 + src/pkg/dashboard/static-src/css/kiosk.css | 25 +++ src/pkg/dashboard/static-src/css/matrix.css | 4 + src/pkg/dashboard/static-src/html/faq.html | 5 + src/pkg/dashboard/static-src/js/boot.js | 7 + src/pkg/dashboard/static/index.html | 41 +++++ src/pkg/hub/activity_kiosk_cta.go | 33 ++++ src/pkg/hub/activity_kiosk_cta_test.go | 60 +++++++ src/pkg/hub/activity_page.go | 1 + src/pkg/hub/static/activity.css | 20 +++ src/pkg/hub/static/activity.html | 4 + src/pkg/hub/static/activity.js | 12 ++ src/pkg/webassets/kioskcta/kioskcta.go | 111 +++++++++++++ src/pkg/webassets/kioskcta/kioskcta_test.go | 40 +++++ src/scripts/twitch-channel-cta.sh | 167 ++++++++++++++++++++ 22 files changed, 674 insertions(+) create mode 100644 changelog.d/added-16236-kiosk-cta.md create mode 100644 src/pkg/dashboard/kiosk_cta.go create mode 100644 src/pkg/dashboard/kiosk_cta.test.js create mode 100644 src/pkg/dashboard/kiosk_cta_test.go create mode 100644 src/pkg/hub/activity_kiosk_cta.go create mode 100644 src/pkg/hub/activity_kiosk_cta_test.go create mode 100644 src/pkg/webassets/kioskcta/kioskcta.go create mode 100644 src/pkg/webassets/kioskcta/kioskcta_test.go create mode 100755 src/scripts/twitch-channel-cta.sh diff --git a/changelog.d/added-16236-kiosk-cta.md b/changelog.d/added-16236-kiosk-cta.md new file mode 100644 index 0000000000..8c0957cf44 --- /dev/null +++ b/changelog.d/added-16236-kiosk-cta.md @@ -0,0 +1 @@ +- Every `?kiosk=1` view โ€” the spoke Activity Monitor, the Matrix view and the hub's public Fleet activity page, i.e. the three Twitch streams โ€” shows a small "Request a Hive" call-to-action pill bottom-right with `hive.hivecommons.dev/get-started` and a QR code of it ([#16236](https://github.com/hivecommons/hive/issues/16236)). It never appears in the operator dashboard, `&cta=off` removes it, and the text is `dashboard.kiosk_cta_url` / `dashboard.kiosk_cta_text` on a spoke or `HIVE_HUB_KIOSK_CTA_URL` / `HIVE_HUB_KIOSK_CTA_TEXT` on the hub. `src/scripts/twitch-channel-cta.sh` sets the matching title, category and tags on the channels (`--dry-run`, idempotent, per-channel `channel:manage:broadcast` token). diff --git a/src/docs/env-vars.md b/src/docs/env-vars.md index 842849e5e5..007c20d120 100644 --- a/src/docs/env-vars.md +++ b/src/docs/env-vars.md @@ -77,6 +77,8 @@ behavior. [Maintenance limitations](#keeping-this-reference-current) still apply | `HIVE_HUB_TASK_STATUS_PUSH` | No | `hub.task_status_push`, default `true` | Enable the separate spoke task-status push loop. Accepts `1/true/yes/on` or `0/false/no/off` (case-insensitive); empty/invalid values fall back to config. Read at startup; restart after changing. Core heartbeat and hub-managed upgrade/config delivery remain enabled. | | `HIVE_HUB_PUBLIC_URL` | No | compiled fallback `https://hive.hivecommons.dev` (`defaultHubPublicURL`, `src/pkg/hub/saas_auth.go`) | Hub canonical public origin used to derive OAuth/OIDC callback URLs, hub Open Graph/notification links, same-origin checks, and the registrable-domain scope for hub SSO cookies. Public hub operators should set this to `https://hive.hivecommons.dev` for the cutover; leave the legacy value only while deliberately serving the redirect hostname. **Changing the registrable domain here signs users out of every first-party sibling product left on the old one** โ€” the `hive_hub_user` cookie is scoped to this URL's registrable domain and a browser will not send it anywhere else. See [Moving a public hostname](hivecommons-migration.md#moving-a-public-hostname). | | `HIVE_HUB_SPOKE_DOMAIN` | No | compiled fallback `hive.hivecommons.dev` (`defaultHubSpokeDomain`, `src/pkg/hub/saas_auth.go`) | Parent domain used for hub-provisioned spoke ingress hostnames (for example `.`). Kept separate from `HIVE_HUB_PUBLIC_URL` because the wildcard spoke domain may differ from the hub's own hostname. | +| `HIVE_HUB_KIOSK_CTA_URL` | No | `https://hive.hivecommons.dev/get-started` (`kioskcta.DefaultURL`, `src/pkg/webassets/kioskcta`) | Destination of the call-to-action badge the hub Fleet activity page shows bottom-right when loaded with `?kiosk=1` (the fleet Twitch stream). Rendered as text and as a QR code. | +| `HIVE_HUB_KIOSK_CTA_TEXT` | No | `๐Ÿ Want this for your repos?` (`kioskcta.DefaultText`) | Copy line above the URL on that badge. | | `HIVE_HUB_LEGACY_COOKIE_DOMAIN` | No | none | Optional transition-only hub SSO cookie domain to expire alongside the active cookie domain while accepting any carried `hive_hub_user` cookie value during a host migration. Writes still target the domain derived from `HIVE_HUB_PUBLIC_URL`; unset disables the extra legacy-domain cleanup. | | `HIVE_HUB_SECRET` | Required for spokes registered to a protected hub; optional for a standalone hub with `/data/saas/hub-secret.key` | `/data/saas/hub-secret.key` on the hub when present; no fallback for spoke heartbeat auth | Bearer secret for spoke heartbeats and hub/spoke SaaS APIs. | | `HIVE_HUB_AGENT_RESTART_PROBLEM_THRESHOLD` | No | `5` | Hosted hub threshold for surfacing agent restart storms on `/fleet`. When an agent reports at least this many restarts in the last 24 hours (or since the hub-side reset marker), the hive gets a restart problem chip and drift signal. | diff --git a/src/docs/streaming-the-activity-monitor.md b/src/docs/streaming-the-activity-monitor.md index 8436b4c041..dfb21a73de 100644 --- a/src/docs/streaming-the-activity-monitor.md +++ b/src/docs/streaming-the-activity-monitor.md @@ -38,6 +38,55 @@ monitor. Two knobs: Nothing here touches Twitch or the cluster until **you** create the Secrets and apply the overlay โ€” the steps below are all yours to run. +### Call-to-action overlay + +Every kiosk view โ€” this stream's Activity Monitor, the [Matrix](#matrix-mode-separate-channel) +and the hub's [public fleet page](#the-hivecommonsfleet-broadcast) โ€” carries a +small pill bottom-right: "๐Ÿ Want this for your repos?", the URL +`hive.hivecommons.dev/get-started` in 24px amber, and a 110px QR code of it, so +a viewer on a phone or a 720p transcode can get to **Request a Hive** without +typing. It appears only with `?kiosk=1` (never in the operator dashboard, +pop-out or display mode) and `&cta=off` in `DASHBOARD_PATH` removes it. On a +spoke the destination and the copy are `dashboard.kiosk_cta_url` and +`dashboard.kiosk_cta_text` in `hive.yaml` (read at start-up); on the hub they +are `HIVE_HUB_KIOSK_CTA_URL` and `HIVE_HUB_KIOSK_CTA_TEXT`. The QR code is +rendered server-side (`src/pkg/webassets/kioskcta`) as an inline `data:` PNG, so +nothing external is loaded and the pages' Content-Security-Policy is unchanged. +In Matrix mode the pill sits above the canvas at 85 % opacity so it does not +fight the effect. + +### Channel title, category, tags + +[`src/scripts/twitch-channel-cta.sh`](../scripts/twitch-channel-cta.sh) sets +the title, category and tags of `hivecommons`, `hivecommonsfleet` and +`hivecommonsmatrix` through Helix `PATCH /channels` so each channel page +carries the same call to action as the overlay; `--dry-run` shows the diff +without writing, and a channel that already matches is skipped. Twitch needs a +**user** access token per channel with the `channel:manage:broadcast` scope โ€” +an app token cannot edit channel info โ€” obtained once with the +[device-code grant](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#device-code-grant-flow): + +1. In the [Twitch developer console](https://dev.twitch.tv/console/apps) register + an application (category "Broadcasting Suite", OAuth redirect + `http://localhost`) and note its **Client ID** (`TWITCH_CLIENT_ID`). +2. For each channel, while logged in to Twitch as that channel: request a device + code โ€” `curl -sX POST https://id.twitch.tv/oauth2/device -d client_id=$TWITCH_CLIENT_ID -d scopes=channel:manage:broadcast` โ€” + open the returned `verification_uri`, enter the `user_code`, then exchange it: + `curl -sX POST https://id.twitch.tv/oauth2/token -d client_id=$TWITCH_CLIENT_ID -d device_code= -d grant_type=urn:ietf:params:oauth:grant-type:device_code`. + Keep the `access_token` (and `refresh_token`) out of the shell history, for + example in a password manager. +3. Export the tokens as `TWITCH_TOKEN_HIVECOMMONS`, `TWITCH_TOKEN_HIVECOMMONSFLEET` + and `TWITCH_TOKEN_HIVECOMMONSMATRIX`, then run + `src/scripts/twitch-channel-cta.sh --dry-run` and, when the diff is right, + without the flag. The script verifies that category id `1469308723` is + "Software and Game Development" against `/search/categories` before it writes + and never prints a token. + +Panels (the About tab under the player) have no API: upload the three images +produced for #16236 โ€” "Request a Hive" โ†’ `hive.hivecommons.dev/get-started`, +"What is Hive?" โ†’ the docs, "Discord" โ†’ the invite โ€” by hand on each channel's +**About โ†’ Edit panels**. + ## 1. Twitch side (once) Open the Creator Dashboard at `dashboard.twitch.tv` while logged in as diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index 1f939970c3..7b455118c2 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -4988,6 +4988,12 @@ type DashboardConfig struct { // "redirect_uri is invalid". Validated at load time by // ValidateDashboardPublicURL. PublicURL string `yaml:"public_url,omitempty" json:"public_url,omitempty"` + // KioskCTAURL and KioskCTAText are the destination and copy of the + // call-to-action badge every `?kiosk=1` view shows bottom-right (#16236, + // pkg/webassets/kioskcta). Empty takes the hosted-hive request page and + // its default line. Read once at dashboard start-up, like branding. + KioskCTAURL string `yaml:"kiosk_cta_url,omitempty" json:"kiosk_cta_url,omitempty"` + KioskCTAText string `yaml:"kiosk_cta_text,omitempty" json:"kiosk_cta_text,omitempty"` // Theme names the built-in dashboard theme id ("hive" by default) or // "custom" when theme_overrides supplies the complete operator palette. Theme string `yaml:"theme,omitempty" json:"theme,omitempty"` diff --git a/src/pkg/dashboard/kiosk_cta.go b/src/pkg/dashboard/kiosk_cta.go new file mode 100644 index 0000000000..639ced1000 --- /dev/null +++ b/src/pkg/dashboard/kiosk_cta.go @@ -0,0 +1,17 @@ +package dashboard + +import "github.com/hivecommons/hive/pkg/webassets/kioskcta" + +// kioskCTAOptions is what the kiosk call-to-action badge (#16236) says on +// this spoke: dashboard.kiosk_cta_url / dashboard.kiosk_cta_text, or the +// package defaults (the hub's get-started page) when unset or when the +// server runs without a config, as in tests. +func (s *Server) kioskCTAOptions() kioskcta.Options { + if s.deps == nil || s.deps.Config == nil { + return kioskcta.Options{} + } + return kioskcta.Options{ + URL: s.deps.Config.Dashboard.KioskCTAURL, + Text: s.deps.Config.Dashboard.KioskCTAText, + } +} diff --git a/src/pkg/dashboard/kiosk_cta.test.js b/src/pkg/dashboard/kiosk_cta.test.js new file mode 100644 index 0000000000..7fbcef84f2 --- /dev/null +++ b/src/pkg/dashboard/kiosk_cta.test.js @@ -0,0 +1,35 @@ +// Kiosk call-to-action badge (hivecommons/hive#16236): boot.js turns the +// badge on for `?kiosk=1` only, `&cta=off` opts out, and the stylesheet keeps +// #kiosk-cta hidden without body.kiosk-cta-on so the operator dashboard never +// shows it. Runs against the shipped index.html. +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); + +test('hiveKioskCTAOn: kiosk=1 only, cta=off opts out', () => { + const m = html.match(/window\.hiveKioskCTAOn=function\(href\)\{[\s\S]*?\n \};\n/); + assert.ok(m, 'hiveKioskCTAOn not found in index.html'); + const window = {}; + new Function('window', m[0])(window); + const on = window.hiveKioskCTAOn; + assert.strictEqual(on('https://hive.example/?kiosk=1#section-activity-monitor-section'), true); + assert.strictEqual(on('https://hive.example/?kiosk=1&view=matrix&sound=off'), true); + assert.strictEqual(on('https://hive.example/?kiosk=1&cta=off'), false); + assert.strictEqual(on('https://hive.example/'), false); + assert.strictEqual(on('https://hive.example/?display=1'), false); + assert.strictEqual(on('https://hive.example/?popout=1'), false); + assert.strictEqual(on('not a url'), false); +}); + +test('badge wiring: placeholder outside the root, hidden without the body class, lifted and dimmed in matrix', () => { + assert.ok(html.includes("if(window.hiveKioskCTAOn(window.location.href)) document.body.classList.add('kiosk-cta-on');")); + const root = html.indexOf(''); + const ph = html.indexOf(''); + assert.ok(root > 0 && ph > root, 'placeholder must follow the dashboard root'); + assert.ok(html.includes('#kiosk-cta { display: none; }')); + assert.ok(html.includes('body.kiosk-cta-on #kiosk-cta {')); + assert.ok(html.includes('body.matrix-mode #kiosk-cta { z-index: 100001; opacity: .85; }')); +}); diff --git a/src/pkg/dashboard/kiosk_cta_test.go b/src/pkg/dashboard/kiosk_cta_test.go new file mode 100644 index 0000000000..1c646fcac1 --- /dev/null +++ b/src/pkg/dashboard/kiosk_cta_test.go @@ -0,0 +1,30 @@ +package dashboard + +import ( + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/webassets/kioskcta" +) + +// The served index carries the kiosk call-to-action badge (#16236) where the +// shipped document leaves its placeholder, with dashboard.kiosk_cta_* text. +func TestKioskCTAInjectedIntoIndex(t *testing.T) { + raw := indexHTML(t) + if !strings.Contains(raw, kioskcta.Placeholder) { + t.Fatal("static/index.html has no kiosk CTA placeholder") + } + s := &Server{deps: &Dependencies{Config: &config.Config{}}} + s.deps.Config.Dashboard.KioskCTAURL = "https://hive.example/go" + s.deps.Config.Dashboard.KioskCTAText = "Ask us" + out := string(kioskcta.Inject([]byte(raw), s.kioskCTAOptions())) + for _, want := range []string{`