Compare commits

...
Author SHA1 Message Date
zeekayandClaude Fable 5 2f3bf8f4f6 release: v2.4.49 — CSS token integrity: dead declarations fixed, one amber knob, literal collapse
- fix: 20 dead style declarations (bare var(--undefined) → property silently dropped/
  inherited): transparent findings context menu, wrong-colored urgency borders, etc.
- refactor: yellow-family collapsed to ONE knob (--yellow per theme; --status-cached +
  --semantic-elevated reference it; #ffcc44 drift killed).
- polish: drifted color literals onto canonical tokens (audit §4).
- ci: native .hanzo/workflows build + git.hanzo.ai sync.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 14:53:06 -07:00
zeekayandClaude Fable 5 b20ea099b5 refactor(world): one amber knob — collapse the yellow-family drift
"Yellow" in the UI is the status amber (#ffaa00): stale/cached badges, elevated
threat, the legend's Monitoring/Nuclear markers. It was defined under THREE token
names per theme (--yellow, --status-cached, --semantic-elevated) plus a brighter
#ffcc44 drifting raw in the chain-nodes stale/provisional states.

Now: --yellow is the single palette knob (#ffaa00 dark / #d97706 light);
--status-cached and --semantic-elevated reference it; the 4 #ffcc44 literals
route through var(--semantic-elevated). Changing (or killing) the amber
brand-wide is now a one-line edit per theme.

Left alone deliberately: the separate 5-tier --threat-* scale (own palette,
scale-to-scale merge = visible change, deferred to the screenshot-diffed pass)
and TS/WebGL literals (canvas can't consume CSS vars; values match the token).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 14:52:46 -07:00
zeekayandClaude Fable 5 f6bf038fa1 fix(world): 20 dead style declarations — bare var(--undefined) rewritten to real tokens
A bare var(--x) with no fallback where --x is never defined makes the whole
declaration invalid at computed-value time — the property silently becomes
inherit/initial. 12 phantom token names (--orange, --muted, --text-primary,
--danger, --success, --warning, --blue, --accent-red, --surface-light,
--surface-elevated, --bg-panel, --bg-hover) were used bare in 20 declarations,
so those styles never applied: the intel-findings context menu rendered with NO
background (initial = transparent), focal-point/convergence urgency borders fell
to currentColor instead of orange, findings-modal titles inherited, etc.

Rewrote each to its semantics-matched canonical token from the existing :root
vocabulary (--text-muted, --text, --red, --green, --yellow, --semantic-high,
--semantic-info, --surface-hover, --surface-active, --panel-bg-solid) — the one
vocabulary, theme-aware in both light and dark. Dynamic runtime knobs with
fallbacks (--marker-scale, --flash-duration, …) are intentional and untouched.

Same bug class as the rgba(var(--semantic-critical)) fills fixed in v2.4.46.
Build green; CSS-only.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 14:47:57 -07:00
zeekayandClaude Opus 4.8 e5f2e3bd80 polish(world): collapse drifted color literals onto their canonical tokens (audit §4)
Pure indirection, zero visual change: the token EQUALS the literal, so rendering is
byte-identical — this just removes the drift so future color changes go through one
place. Replaced usage-site `#ffaa00` → var(--yellow) and `#44ff88` → var(--green)
(the --status-cached/--status-live/--yellow/--green DEFINITIONS untouched). Left
`#ffcc44` alone — it's a distinct value, so mapping it would change the color (that's
the risky consolidation, deferred to the deliberate scale pass).

Build green. This is the safe core of audit §6; the type/radius/z-index SCALE
consolidation (which changes values → needs per-view screenshot diffing) stays a
separate deliberate pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 14:40:06 -07:00
hanzo-dev 3f421144a8 ci: native .hanzo/workflows build + git.hanzo.ai sync (additive) 2026-07-23 09:29:07 -07:00
hanzo-dev 7deedeb737 release: v2.4.48 — name the two Insights surfaces on the @hanzo/event base: BriefPanel + InsightsPanel
Rides on the native @hanzo/event telemetry (one client → POST /v1/event). Renames
the AI news-brief panel to BriefPanel (it makes the world brief) and the
product-analytics panel over /v1/insights/events to InsightsPanel, dropping the
Org prefix and the name collision. GTM stays orthogonal. No duplicate telemetry.

Claude-Session: https://claude.ai/code/session_01NP4ehjWW2h98FkE4YjUKuJ
2026-07-23 09:25:45 -07:00
Hanzo Dev 387562318c world: native @hanzo/event telemetry — one client, subsumes Sentry + Umami
Converge world's client telemetry on the ONE canonical Hanzo Cloud front
door: pageviews, product events, and errors all leave through @hanzo/event
to POST /v1/event, lensed server-side into web analytics, product analytics,
and error tracking. This supersedes v2.4.47's fragmented client stack — the
third-party Sentry bundle and the direct analytics.hanzo.ai (Umami) page
script both fed lenses the /v1/event stream now feeds server-side, so loading
them client-side double-counted the same lenses.

- bootstrap/telemetry.ts: the one client. Framework-agnostic createAnalytics,
  brand-resolved host (hanzo/lux/zoo), IAM bearer injected at the composition
  root (else a write-only publishable key so the fail-closed door accepts
  logged-out ingest), consent gate (DNT / GPC / opt-out), SPA pageview on
  pathname change, and filtered global error capture that preserves the
  curated WebGL/map noise-filter verbatim.
- Product moments captured with the shared EVENTS vocabulary: country
  drill-down, map-layer toggle, variant switch, share, and the AI analyst
  chat funnel (start + per message). identify/group on the signed-in session.
- Remove @sentry/browser + bootstrap/sentry.ts; drop the Umami injection +
  track() from bootstrap/analytics.ts. GTM (marketing tags) stays — an
  orthogonal, env-gated concern @hanzo/event does not cover.

Logged-out marketing/public views load it too — anonymous, consent-gated.
typecheck + vite build + data tests green.
2026-07-22 22:45:44 -07:00
zeekayandClaude Opus 4.8 0d4a477661 refactor(world): extract CountryIntelController from App.ts
Move the fullscreen country view out of the App god-object into its own
unit: the CountryBriefPage lifecycle + map country-click wiring, brief
generation (local CII + server intel + ML fallback), the seven-day
timeline, per-country signal counts, the shareable story modal, and the
country-name/geo static helpers (COUNTRY_BOUNDS / COUNTRY_ALIASES /
resolveCountryName / …). The controller owns countryBriefPage /
countryTimeline / briefRequestToken; App composes it with lazy accessors
(map / panels / news / clusters / predictions / intelligenceCache) plus
getShareUrl + buildAnalystHost callbacks. Behavior byte-for-byte
identical — the map registers onCountryClicked exactly once on the stable
this.map, same as before.

App keeps thin delegations (setupCountryIntel / openCountryBrief /
openCountryBriefByCode / openCountryStory) so every call site — the map
handler, search, deep links, share buttons, window.__app — is unchanged,
and re-exposes window.__app.countryBriefPage (read-only getter) for the
e2e boot-readiness hook. App.ts 5686 → 4747 lines across the three
extractions; 18 now-unused imports pruned.

Build green; variant-switch-inplace + stations-wall e2e green; 3/3
direct-drive country-view tests green (the deep-link case is gated on
real proxied-feed freshness and fails identically on main — environmental,
not a regression, verified by stash+rerun).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 19:00:57 -07:00
hanzo-dev 9bdc72b909 release: v2.4.47 — instrument world: Sentry + analytics.hanzo.ai (Umami) + GTM-ready, clean AnalyticsPanel/analytics naming
Wire world's telemetry to the live Hanzo observability services, all env-gated
from KMS (no-op until IDs provisioned — ships inert, activates on config):
- Sentry: VITE_SENTRY_DSN build-secret → errors to sentry.hanzo.ai.
- Analytics: bootstrap/analytics.ts injects the analytics.hanzo.ai (Umami) script
  on VITE_ANALYTICS_WEBSITE_ID; track() forwards custom product events (→
  /v1/insights/events + AnalyticsPanel pageviews). track('variant_view') wired.
- GTM-ready: initGtm() loads one Google Tag Manager container (VITE_GTM_ID) that
  manages GA / Facebook / LinkedIn / X tags from GTM's UI; CSP script-src allows
  googletagmanager/google-analytics/facebook/linkedin/x.
- Naming: CloudAnalyticsPanel → AnalyticsPanel, org-analytics.ts → analytics.ts.
OpenGraph/Twitter/JSON-LD SEO already comprehensive.

Claude-Session: https://claude.ai/code/session_01NP4ehjWW2h98FkE4YjUKuJ
2026-07-22 18:49:21 -07:00
zeekayandClaude Opus 4.8 a061b048c7 refactor(world): extract AnalystCommandHost from App.ts
Move the agentic-control surface out of App into its own unit. App
exposes a narrow capability port (AnalystHostBridge); AnalystCommandHost
owns the SHAPE of what the AI analyst can see and do — the getState /
listPanels / listLayers projections, the one-time org priming, and the
1:1 command routing that builds the AnalystHost object. The command
implementations stay in App (they mutate shared panel/monitor/variant/
layer state and are called from UI paths too) and are reached through the
bridge — a thin adapter, behavior byte-for-byte identical.

buildAnalystHost() is now a one-line delegation to the host's build();
all three call sites (country brief, analyst panel, analyst dock) are
unchanged. Build + variant-switch-inplace + stations-wall e2e green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 18:15:48 -07:00
zeekayandClaude Opus 4.8 c5af34eb82 release: v2.4.46 — polish pass: globe-crash fix, dropdown coverage, −1.6k dead code, a11y, decomplect
Ships the polish batch that has been sitting on main since v2.4.45:
- fix: free the parked-mapbox GPU context in backgrounded tabs (Safari multi-tab
  black-globe crash — confirmed single-tab prod renders fine; the crash is context
  exhaustion across tabs, now mitigated).
- fix: News Wall + Markets Bubble reachable in every grid view's dropdown + palette.
- refactor: −~1,600 lines dead code (17 orphaned files) + 5 invalid alert-bg CSS fixed.
- polish: WCAG-AA contrast, global :focus-visible ring, mobile-safe popup widths.
- refactor: Add-widget palette sources the full created-registry (add anything anywhere).
- refactor: UI primitives consolidated onto Panel base (empty/loading/sparklines/
  formatters/tabs/modals/iframes) + clickable-row a11y.
- refactor: SearchController extracted from the App.ts god-object (5713→5259 lines).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 18:07:47 -07:00
zeekayandClaude Opus 4.8 dbba6d26c0 refactor(world): extract SearchController from App.ts
Move the ⌘K search surface out of the App god-object into its own
controller: modal creation + per-variant source registration, result
routing (map fly-to / panel scroll / country brief), the live search
index, and the Cmd/Ctrl+K keydown listener. App composes it with lazy
accessors (getMap/getMapLayers/getPanels/getAllNews/getLatest*) so live
field reassignments read fresh — behavior byte-for-byte identical.

App.ts 5686 -> 5215 lines; 7 methods + 2 fields relocated; 16 now-unused
config imports pruned. Build + variant-switch-inplace + stations-wall e2e
green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 17:57:36 -07:00
zeekayandClaude Opus 4.8 d23e1126fd refactor(world): BaseModal + embedIframe unification + clickable-row a11y
BaseModal: one base owning full-screen overlay behavior — .active/create
lifecycle via mountOverlay/unmountOverlay, backdrop-click + Escape close, and a
basic focus trap (focus first focusable on open, restore on close). SignalModal,
StoryModal, SearchModal and MobileWarningModal migrate onto it with no change to
their DOM or public methods; this adds Escape-to-close to the three that lacked
it.

embedIframe({src,title,allow,allowFullscreen,...}) in utils/embed.ts: one
canonical player-iframe factory with the agreed YouTube allow + sandbox. The
four raw embeds (LiveWebcamsPanel, LiveNewsPanel desktop bridge, WatchQueuePanel,
services/immersive) route through it.

Clickable-row a11y: utils/a11y.ts makeActivatable() gives click-handled rows
role=button + tabindex=0 + Enter/Space firing the same action — applied to
Displacement, Ucdp, Climate, Investments and StrategicRisk rows. SearchModal
result rows get role=button (already keyboard-operable via its input model).
MarketPanel context-menu rows get makeContextMenuActivatable() so the copy menu
is reachable by keyboard. NewsPanel and TechReadiness skipped (see report).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 17:10:56 -07:00
zeekayandClaude Opus 4.8 2e0e820285 refactor(world): consolidate UI primitives onto Panel base (empty/loading/sparklines/formatters/tabs)
Behavior-neutral decomplect (same rendered output, fewer implementations):
- Panel.showEmpty() added; ~15 hand-rolled empty states (4 divergent class conventions
  .empty-state/.panel-empty/.cloud-empty/.wq-empty) routed through the one base method.
- Loading spinner clones → this.showLoading() (the base radar).
- Live-dot / freshness → the base setDataBadge; duplicate keyframes/classes unified.
- 5 sparkline generators → one sparkline() in utils/market-format.
- ~7 local number/pct/currency reimplementations → the shared utils/cloud-format helpers.
- Several hand-rolled tab-switchers → Panel.renderTabs + one .panel-tab convention.

Build + globe/panel e2e green (variant-switch passes uncontended). Partial pass — the
tab migration (EconomicPanel), BaseModal/embedIframe unification, and clickable-row a11y
are still to land in a follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 16:37:36 -07:00
zeekayandClaude Opus 4.8 59d6212836 refactor(world): Add-widget palette sources the full created-registry (audit §3)
renderAddWidgetGrid iterated only this.panelSettings — the CURRENT variant's subset —
so ~20 instantiated panels (service-status, lux-book, startups, accelerators, …) were
unreachable from the palette even though its own comment calls it "a searchable palette
over the panel registry." Now it sources from Object.keys(this.panels) (every panel that
exists this session) ∪ panelSettings; display names resolve via the new canonical
PANEL_NAMES union (+ i18n); panelSettings is purely the enabled overlay. setPanelEnabled
now creates the overlay entry on demand, so a palette-added non-variant panel actually
shows. renderPanelToggles stays the curated per-view quick-toggle (no 40-item wall).
Result: any panel is addable from any view; registry and menu can no longer disagree.

Build + globe/panel e2e green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 14:13:36 -07:00
zeekayandClaude Opus 4.8 b46e28e730 polish(world): a11y + contrast + mobile-safe popups (audit §6)
- Contrast: dark-theme --text-muted #666 (~2.8:1) → #949494, --text-faint #555
  (~2.0:1) → #8a8a8a — both now pass WCAG AA on the dark surface (muted text is
  used ~99×). Light theme untouched.
- Keyboard focus: add a global, theme-aware :focus-visible ring (2px var(--accent))
  on links/buttons/inputs/[role=button|tab]/[tabindex] — shows on tab-focus only,
  never on mouse; low specificity so per-component focus styles still win.
- Mobile: viewport-cap the fixed-width flyout/map-popup/dropdown widths
  (width: min(360|380px, calc(100vw - 24px))) so they stop overflowing narrow
  phones — identical on desktop, only shrinks below the cap.

CSS-only, behavior-neutral; build green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 13:49:40 -07:00
zeekayandClaude Opus 4.8 94b32fcf5a refactor(world): remove ~1.6k lines of dead code + fix 5 invalid alert backgrounds
Grep-verified dead (zero instantiations, zero non-barrel imports) — deleted end to end:
- 11 orphaned panel components never built in createPanels/ensureVariantPanels:
  Robotics/Quantum/PostQuantum/Weather/Sports/SpaceWeather (the "domain-lens" set),
  plus Regulation (superseded by the NewsPanel 'regulation' feed), GeoHubs, TechHubs,
  VerificationChecklist, and CountryIntelModal (superseded by CountryBriefPage).
- 5 dead backing services (robotics/quantum/post-quantum/space-weather/sports) +
  config/post-quantum.ts (only importer was the dead service).
- The 6 dead domain-lens panel keys in FULL_PANELS — they rendered Panels-menu toggles
  and Add-widget entries that did NOTHING (applyPanelSettings/getElement hit undefined),
  and their now-orphaned `.domain-*` CSS block.
- Barrel exports for the deleted panels.

KEPT (verified live, NOT panels): config/quantum.ts + config/robotics.ts + services/
weather.ts (map layers), and services/geo-hub-index + tech-hub-index (feed the map's
geo/tech activity markers via geo-activity/tech-activity — the audit missed the relative
import; the build caught it before commit). Relocated `StockIndexData` into its only
consumer, CountryBriefPage.

CSS: `rgba(var(--semantic-critical), 0.2)` is invalid (the token is a hex, not an r,g,b
triple) so 5 alert-fill backgrounds silently rendered nothing → `color-mix(in srgb,
var(--semantic-critical) 20%, transparent)`.

Build + globe/panel e2e green. No feature loss.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 13:47:06 -07:00
zeekayandClaude Opus 4.8 0430150f33 fix(world): free the parked mapbox GPU context in backgrounded tabs (Safari crash)
Symptom: with several world.hanzo.ai tabs open in Safari, the page hits "a problem
occurred" and reloads to a BLACK globe. Root cause: each tab holds TWO WebGL contexts
— the visible native GlobeView (deck.gl) AND a PARKED mapbox (frozen in mercator behind
it, still holding a full GPU context). Several tabs × 2 contexts overruns Safari's
GPU/context ceiling → crash-reload → the fresh page's context is gone → black.

Fix: after a tab has been hidden MAP_GPU_PARK_MS (30s), drop the parked mapbox's WebGL
context via WEBGL_lose_context; restore it the instant the tab is shown. Reuses the
existing webglcontextlost/restored handlers (mapbox-gl + deck.gl both rebuild their GPU
resources on restore) — nothing is re-wired, and the visible GlobeView's own context is
untouched. Worst case (a restore that doesn't repaint) equals today's post-crash state
but with one fewer live context — strictly less GPU pressure, never worse.

DeckGLMap.parkGPU/restoreGPU + MapContainer delegation + App visibilitychange timer
(cleared on show and on destroy). Existing globe/map + panel e2e green (no regression).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 13:24:28 -07:00
zeekayandClaude Opus 4.8 3c6bc9c92a fix(world): surface News Wall + Markets Bubble in every grid view's dropdown
Both were reachable in almost no view: News Wall existed only in the World variant,
Markets Bubble only in World (opt-in) + Finance — and Finance renders the terminal
(no panel grid), shadowing it there. Since renderPanelToggles AND the "+ Add widget"
palette only iterate the CURRENT variant's panelSettings, on the default Cloud view
(and AI/Crypto/Tech) both panels were invisible and unreachable.

Add both (opt-in, enabled:false) to CLOUD/AI/CRYPTO/TECH so they show in every grid
view's Panels dropdown + Add-widget palette. e2e-reprobed present in all four.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 09:49:23 -07:00
hanzo-dev 4c8ecaebfe release: v2.4.45 — Live Webcams verified-live default grid + e2e drift fixes (runtime-fetch, keyword-spike)
- Live Webcams: replace dead default feeds with browser-verified-live 24/7 streams
  (grid = Kyiv/Tel-Aviv/Miami/Taipei, each confirmed PLAYING/isLive this session via
  the YouTube IFrame API in a full-codec browser); prune 6 non-embeddable feeds, add
  Monterey Bay. Fixes the "mostly not available" webcam panel.
- e2e (dev-only, no bundle impact): runtime-fetch fallback test → current /v1/world/*
  paths + real host discriminator; keyword-spike test → mid-sentence proper-noun +
  initI18n + opt-in badge flag; drop the obsolete arch-download test (feature removed
  for Hanzo); loadMarkets test → yahoo-batch envelope, no commodities. 7/7 pass.

Also carries the analyst-dock hzc-* selector drift fixes (19/19 pass).

Claude-Session: https://claude.ai/code/session_01NP4ehjWW2h98FkE4YjUKuJ
2026-07-22 04:55:52 -07:00
hanzo-dev 5f8dcec1c9 test(e2e): fix analyst-dock selector drift (hzc-*) + enso/country-view/video-drag drift
The analyst copilot redesign (5dc7232c) renamed .ai-dock-*/.ai-analyst-* → .hzc-*;
tests still clicked the dead .ai-dock-fab and timed out. Remap all dock selectors
and update assertions to the redesigned behavior (model picker is now a popover not
a <select>; tool-trace <details> opens by default; db glyph not 🔧 emoji). Also:
enso-training/real-models are cloud-variant panels (navigate ?variant=cloud) showing
the real served-model catalog not opaque arm-N; country-view waits for
__app.countryBriefPage; video-drag uses an on-screen drop coordinate + map-led reset
order. 19/19 pass across the touched specs. Golden-screenshot/headless-WebGL specs
left untouched (CI-env goldens). Dev-only; CI does not gate on e2e.

Claude-Session: https://claude.ai/code/session_01NP4ehjWW2h98FkE4YjUKuJ
2026-07-22 04:36:06 -07:00
hanzo-dev 021af33835 release: v2.4.44 — fix china-macro 24s hang, AI Insights infinite spinner, finance dark skeletons, dead webcams, Sentry 403
Visual + runtime review across all variants surfaced five real defects; fixed each honestly (no fabricated data):
- china-macro: 10s frontend AbortController + 9s backend deadline + negativeTTL negative-cache — was hanging ~24s then aborting (cloud-3d/crypto/fund).
- AI Insights: summarization.ts raw fetches → fetchWithTimeout (root cause) + 12s render-race + briefSettled guard — panel no longer spins forever for signed-out users.
- finance: dark .fin-tv-skeleton overlay over TradingView iframes (removed on load) — no more white boxes on the dark theme during load.
- Live Webcams: prune 3 dead upstream feeds (Jerusalem/Tehran/DC), repoint default grid to working streams (Kyiv/Mecca/London/NY).
- Sentry: drop the stale hardcoded DSN, env-gate on VITE_SENTRY_DSN (no-op when unset) — kills 403 spam on every variant (was already over-quota/broken).

Claude-Session: https://claude.ai/code/session_01NP4ehjWW2h98FkE4YjUKuJ
2026-07-22 03:38:15 -07:00
hanzo-dev 689488c2e3 release: v2.4.43 — News Wall, Christie's alt-assets, Markets Bubble, org dashboard, yahoo daily series (version label corrected)
Rolls up the 7 commits on main since v2.4.42 (News Wall, Christie's +
LuxuryEstate alt-asset feeds, Markets Bubble D3 circle-pack, org-shared
editable dashboard default, yahoo range/interval daily series). package.json
had regressed to 2.4.39 from a merge-conflict resolution while the highest
tag was already v2.4.42 and prod ran this same code — correct it forward to
2.4.43 so the deployed image, bundle version and /v1/world/version agree.

Claude-Session: https://claude.ai/code/session_01NP4ehjWW2h98FkE4YjUKuJ
2026-07-22 02:44:20 -07:00
Hanzo Dev b9a5ac383f fix(world): resolve package.json merge-conflict markers (broke npm ci)
The v2.4.39 rebase left conflict markers in package.json — npm ci failed the
image build. Keep version 2.4.39.
2026-07-22 00:49:06 -07:00
Hanzo Dev e55e59661b release: v2.4.39 — yahoo range/interval forwarding (daily series) 2026-07-22 00:46:44 -07:00
Hanzo Dev f6b60c159e feat(world/yahoo): forward validated range+interval → daily series
handleYahooFinance now forwards a whitelisted range/interval to Yahoo's chart
endpoint (e.g. range=1y&interval=1d) instead of always returning the intraday
default. Absent params preserve prior behavior; the range keys the cache so
different spans of a symbol cache separately. Unlocks real 1-year daily
growth charts on lux.fund (was intraday-only).
2026-07-22 00:46:31 -07:00
zeekayandClaude Opus 4.8 0e3dce34b7 feat(world): org-shared editable dashboard default
Promote the world.hanzo.ai dashboard from per-user-only to an org/shared
scope: a hanzo.app org admin publishes a shared layout/feeds/channels that
every member of the org hydrates as their default, with per-user changes
still overriding it.

Backend (internal/world):
- New org-scoped dashboard doc keyed by owner via store.SharedSub (the same
  Settings table, 'dashboard' namespace, no new table). Served at
  /v1/world/dashboard/shared: GET returns the org default to any signed-in
  member; PUT publishes it and is admin-ONLY (403 otherwise).
- Admin gate reuses isAdminOrg + a new isOrgAdmin honoring IAM's isAdmin
  claim; writes are always scoped to the caller's own org (no cross-org).
- Decomplect: per-user and shared paths share ONE GET/PUT body
  (serveIdentityBlob), parameterized by the resolved identity/scope.

Frontend (src):
- dashboard.ts hydrate is scope-parameterized: the org default is applied
  first as the base, then the user's own doc overlays it (user wins). Both
  scopes fetched concurrently so boot stays bounded.
- publishOrgDashboard() PUTs the current layout to the shared endpoint
  (admin-only server-side). An admin-gated "Publish as org default" entry in
  the workspace context menu triggers it; anonymous/non-org unchanged.

Tests: Go handler tests cover admin publish + round-trip, non-admin 403,
member read, per-user isolation, cross-org isolation, anon 401, and the
admin-org publish path. Playwright specs cover shared-then-user precedence.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 00:04:32 -07:00
zeekayandClaude Opus 4.8 34829c48a9 feat(world): Markets Bubble — whole market universe as one D3 circle-pack
Add a live "all markets in one bubble" panel: every asset class at once as a
D3 circle-pack — a cluster per class (equities/commodities/FX/rates/crypto),
a leaf circle per instrument, radius ∝ importance × how hard it's moving, fill
= diverging green(↑)→red(↓) by percent move (flipped for vol gauges VIX/MOVE).
Hover any bubble for name / price / signed %. Smooth radius+colour tween on the
~30s jittered live poll (circles reused by id), lazy-built on first visibility
and paused off-screen, re-packed on resize.

Decomplected around ONE source of truth:
- config/market-universe.ts: every tradable declared once (class, group,
  weight, digits, inverse) with universeByClass / universeGroups / yahooUniverse.
- services/market-universe.ts: joins the Yahoo + CoinGecko boundary fetchers back
  to that metadata into one flat, plot-ready MarketDatum[] (in-flight-guarded,
  short-cached).
- CommoditiesPanel now DERIVES its symbol list from the universe (no inline
  duplication). FX/Rates panels left untouched — they carry extra EM/curve symbols
  and bespoke rendering the universe doesn't model, so migrating them would risk
  working behaviour.

Wired into FINANCE_PANELS (on) and FULL_PANELS (opt-in). e2e mocks the market
endpoints and asserts bubbles across ≥3 classes, tooltip-on-hover with a %, and
survival across a live re-poll.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 23:45:18 -07:00
zeekayandClaude Opus 4.8 a7e4c5bd48 feat(world/finance): live alt-asset feeds — Christie's auctions + LuxuryEstate
The finance-terminal "Art & Collectibles — Auctions" and "Luxury Real Estate"
panels rendered "live feed pending" because /v1/world/auctions and
/v1/world/luxury-realestate did not exist. Make them return REAL data.

world-gw (cmd/world) now scrapes two public sources server-side, hourly, and
serves every caller from the SWR cache:

- GET /v1/world/auctions — Christie's public results: realized SALE totals
  (title, inferred category, price+currency, date, location, image, link).
  Sotheby's (the requested headline) gates realized prices behind a login —
  its /data/api/asset.saleresults.json returns 401 "Not signed in" — so the
  honest public major house is Christie's, exactly the fallback the panel names.

- GET /v1/world/luxury-realestate — LuxuryEstate.com listings (title, location,
  price+currency, type, image, link). JamesEdition (the requested headline)
  sits behind a Cloudflare JS challenge that blocks datacenter egress, so it
  cannot be fetched from the DOKS pod; LuxuryEstate is reachable and
  robots-permitted.

Robust + respectful + honest:
- One request per source per hour (StartAltAssets warmer + 1h TTL / 24h stale).
- On a source failure: serve last-good; with no cache yet, honest empty
  {items:[]} (panel shows "live feed pending"). NEVER fabricated data.
- Payload is exactly {items: AltFeedItem[]} — matches AltFeedPanel.ts
  field-for-field. Source attributed per feed; SPA source labels updated to the
  real sources (Christie's / LuxuryEstate).
- Parsers extract the embedded results JSON (robust to DOM churn); unit-tested
  against real trimmed captures in testdata/.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 22:05:09 -07:00
zeekayandClaude Opus 4.8 f3eaddb132 feat(world): News Wall — all live news channels at once, hover a tile for audio
New opt-in "News Wall" panel: every live news channel plays at once in a responsive
grid of controllable YouTube players (all muted). HOVER a tile → it gets audio focus
(unmuted, others muted); leaving the wall mutes everything. The wall + its N players
build lazily on first visibility and pause when it scrolls off (IntersectionObserver),
so it costs nothing until toggled on and never decodes a hidden wall.

Decomplect — one source each, shared with LiveNewsPanel, no duplication:
- src/services/youtube.ts: the ONE YouTube IFrame API loader + player types (was
  braided into LiveNewsPanel; the grid embedder needed the same loader).
- src/config/live-channels.ts: the ONE channel list + liveChannels()/getDefaultLiveChannel()
  (data belongs in config, not a panel). LiveNewsPanel + immersive now import it.

Wiring: registered in createPanels, exported from the barrel, added to FULL_PANELS
(enabled:false — opt-in like Live Webcams), styled (.stations-* responsive auto-fill
grid with a live focus ring).

e2e (stations-wall.spec.ts): one tile per channel; hover moves the single audio focus;
leaving mutes all. variant-switch-inplace still green (the LiveNewsPanel refactor is
behavior-preserving).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 21:54:24 -07:00
Claude 00d2fa13be fix(world/finance): mount the terminal on the in-place variant switch too
The finance terminal only mounted on the initial ?variant=finance load; the new
in-place variant switch (setSiteVariant, no reload) ran ensureVariantPanels but
never mounted the terminal — so clicking the Finance tab showed the panel
dashboard, not the Bloomberg terminal. Replace mountFinanceTerminal with
syncFinanceTerminal(variant): mounts the terminal overlay when entering finance,
removes it (destroy) when leaving. Wired into both init() and the switch. Now the
tab works both ways — verified: in-place switch mounts 27 chart cards.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 21:10:01 -07:00
Claudeandzeekay d9cf19f195 feat(world/globe): real-time global flow layer — animated comms + trade arcs
A toggleable "Global flows" map layer draws the real backbone of world comms +
trade as animated great-circle arcs on the globe ("where everything is going"):
the principal submarine-cable / internet-backbone routes (cyan) and the major
maritime trade + energy lanes (amber), between real global hubs. Direction is
source → target with a travelling pulse (the existing AnimatedArcLayer + the
shared cloud-pulse clock).

- New src/config/global-flows.ts: 27 real corridors (NYC↔London transatlantic,
  Tokyo↔LA transpacific, Shanghai↔Rotterdam via Suez, Gulf oil → Asia, etc.),
  weighted by representative magnitude — no synthetic data.
- createGlobalFlowsLayer() in DeckGLMap: great-circle on the globe, alpha + width
  scale with corridor weight, comms/trade colour-coded.
- Low-end degradation (device tier): draws only the heaviest maxFlowArcs()
  corridors (40 low / 120 mid / 300 high) so a weak GPU never stalls.
- Toggle: "Global flows" in the layer panel (world + tech variants) + URL state;
  default OFF (overlay). Animated only while visible (cloud-pulse gate).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 20:58:49 -07:00
zeekayandClaude Opus 4.8 5d44059623 perf(world): switch view variants in place — kill the tab-switch freeze
Switching the header variant tabs [Cloud|AI|Crypto|Finance|Tech|World] did a full
window.location reload: it re-created the deck.gl WebGL context, respawned the ML
workers, re-mounted every video iframe and cold-refetched ~48 endpoints. That
cold-start churn WAS the freeze.

SITE_VARIANT is now runtime-mutable (getSiteVariant / setSiteVariantRuntime).
setSiteVariant switches IN PLACE — recompute the target's config and re-apply
panels/map-layers/feeds/tabs/URL live (history.replaceState), exactly like the
intra-variant panel toggle. Heavy singletons stay warm; the synchronous switch
cost is a few ms (e2e-gated <500ms via window.__switchT) vs a full reload.

Also:
- Header controls (H-toggle switcher, search, settings, reset) are wired BEFORE
  `await this.mapReady` so the shell is interactive on first paint — they were
  dead until the 2.7 MB map chunk loaded (a cold H-toggle click was lost).
- LiveNewsPanel pauses its YouTube player via IntersectionObserver when off-screen
  (matching LiveWebcamsPanel) — no decoding a hidden news embed.
- device-tier: adaptive DPR/refresh/flow-arc knobs on low-end hardware.
- Sentry deferred off the critical path (code-split, after first paint).

e2e: variant-switch-inplace.spec.ts proves no reload (JS-context sentinel + same
deck.gl canvas survive), panel-set swap, URL/active-tab re-point, across 3 switches.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 20:56:45 -07:00
Claude 35b8c4bfcf feat(world/finance): Bloomberg-style finance terminal (charts ≫ news), lazy-loaded
The finance variant now renders a dense, dark terminal of LIVE TradingView
charts instead of the news-heavy map dashboard — global indices (S&P 500,
Nasdaq 100, Dow, VIX, Nikkei, Hang Seng, China A50, DAX, FTSE, CAC, Euro Stoxx,
ASX), commodities (gold, silver, WTI, Brent, nat gas, copper), forex (DXY +
majors) and crypto (BTC/ETH) — plus a live ticker tape, a market-overview
widget, a Lux DEX trade card and alt-asset feeds (auctions + luxury real estate).

- Code-split: App dynamic-imports FinanceTerminal only for the finance variant,
  so the TradingView embed logic + terminal CSS never ship in the entry bundle.
- Low-end degradation (device tier): fewer charts + lighter widget types
  (mini-symbol-overview instead of advanced-chart), and every widget lazy-mounts
  on viewport (IntersectionObserver) so a weak laptop never mounts dozens of
  live embeds at once. The map is skipped entirely for this variant (−2.7 MB).
- CAPITALCOM CFD index symbols (free-embed compatible); exchange-native SP:SPX /
  DJ:DJI etc. are account-gated and render an error card.
- Lux DEX: exchange.lux.network sets X-Frame-Options: DENY, so the SwapWidget
  can't be iframed — surfaced as a prominent launch card to the real DEX.
- Auctions (Sotheby's) + luxury RE (JamesEdition) fetch /v1/world/{auctions,
  luxury-realestate}; until that backend feed exists they show an honest
  "live feed pending" state — never fabricated listings.
- CSP (index.html): allow s3/s.tradingview.com (script) + the tradingview-widget
  frames. The production HANZO_STATIC_CSP is widened in the universe world CR.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 20:45:22 -07:00
Claudeandzeekay e651ccac16 perf(world): defer the map off the first-paint critical path (eager JS 4.1MB→1.4MB)
On a low-end laptop the globe (mapbox-gl + deck.gl ≈ 2.7 MB) was eagerly
modulepreloaded and constructed synchronously during renderLayout, so nothing
painted until ~4.1 MB of JS downloaded + parsed + WebGL initialised (≈17.7 s to
app-shell under 6× CPU throttle on the live build). This code-splits the map and
degrades gracefully for weak hardware.

- Map loads via dynamic import() in App.mountMap(); init awaits it AFTER the
  shell paints, before map-dependent wiring. Every this.map access was already
  null-guarded, and mountMap replays the initEscalation / onTimeRangeChanged /
  initial-URL-state wiring that used to run inline in createPanels.
- Isolate Vite's __vitePreload helper into its own chunk (manualChunks): it had
  been co-located INTO the 'map' chunk, so the entry statically imported 'map'
  just for that helper and Vite modulepreloaded the whole 2.7 MB before paint —
  THE reason the map stayed eager despite the dynamic import.
- @/components barrel re-exports the map classes as TYPES only (their modules
  have top-level side effects; value re-exports also dragged 'map' eager).
- Defer @sentry/browser (~460 KB raw / ~130 KB gzip) out of the entry to
  requestIdleCallback, with a synchronous early-error buffer replayed on init so
  no boot error is lost.
- New device-tier util (hardwareConcurrency + deviceMemory + reduced-motion,
  ?tier= override): low-end drops the deck.gl overlay DPR 2→1, skips the idle
  globe auto-spin, and scales real-time refresh intervals up to 2×.

Eager JS before first paint: 4136 KB → 1440 KB (raw). Map (2.7 MB) + Sentry now
load after first paint.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 20:30:04 -07:00
Hanzo Dev 4e0bd1d09b release: v2.4.38 — SuperAdmin fleet view (clusters + GPU queue) + red-review fixes
Ships the fleet view (DOKS cluster nodes + gpu-jobs queue panels, gated by the
canonical SuperAdmin predicate) and the red-review fixes (adminOrgs base =
{admin,built-in} with operator org via WORLD_ADMIN_ORGS; no-store on all admin
Cloud reads). Pairs with universe WORLD_ADMIN_ORGS=hanzo.
2026-07-21 17:33:24 -07:00
Hanzo Dev be92f4ad5f world: address red review — canonical SuperAdmin predicate + no-store admin reads
1. adminOrgs() base is now EXACTLY {admin, built-in} — cloud's canonical
   globalAdminOrgs / principal.IsSuperAdmin, ONE source of truth. The operator
   org is additive-only via WORLD_ADMIN_ORGS (deploy env), never hardcoded; an
   unset/empty env resolves to the base, never empty and never everyone. Tests
   that exercise the operator (owner "hanzo") now declare WORLD_ADMIN_ORGS=hanzo,
   proving the env-driven path; the red matrix gains an operator-via-env case and
   an operator-without-env→403 case; isAdminOrg-exact denies "hanzo" by default.

2. Every admin Cloud read returns Cache-Control: private, no-store (clusters,
   queue, and the family: fleet/services/analytics/llm) so a caller's own
   admin-scoped aggregate is never stored in a shared cache. Infra tests assert it.

WORLD_ADMIN_ORGS=hanzo is set on the world App CR (universe) so the operator
keeps dashboard access via config, not code.
2026-07-21 17:25:33 -07:00
Hanzo Dev 0352c8ed9c merge(worktree-agent-ac3cbb0aaa6f4c669): consolidate onto main 2026-07-21 17:19:13 -07:00
Hanzo Dev 3bb246549c merge(feat/superadmin-fleet-view): consolidate onto main 2026-07-21 17:19:13 -07:00
Hanzo Dev 6737150a9a merge(chore/fork-hygiene-notice): consolidate onto main 2026-07-21 17:19:13 -07:00
Hanzo Dev 4f699c714b release: v2.4.37 — insider ISO-8859-1 fix + alt-data plane live
Aligns package.json + VERSION to the release (both had drifted). This is the
first deployable release carrying the four /v1/world/* macro signals with the
insider charset fix proven against the live SEC feed.
2026-07-21 17:18:44 -07:00
Hanzo Dev 513de4b1e2 fix(world/insider): decode the ISO-8859-1 SEC feed (was silently empty)
The live EDGAR getcurrent atom feed is served as ISO-8859-1, not UTF-8, so
plain xml.Unmarshal errored ('encoding "ISO-8859-1" declared but
Decoder.CharsetReader is nil') and parseEdgarAtom returned zero entries — the
endpoint answered 200 with count:0 in prod. Give the decoder a CharsetReader
(golang.org/x/net/html/charset) so any declared charset decodes. The unit test
now uses an ISO-8859-1 fixture with a Latin-1 byte as a regression guard.
Proven against the live feed: 100 entries decode cleanly.
2026-07-21 17:14:46 -07:00
Hanzo Dev e198d9cd47 world: SuperAdmin fleet view — DOKS cluster nodes + GPU job queue
Add the two admin-only Cloud panels the fleet view was missing, both gated by
the existing requireAdmin predicate (owner in the admin org) and both aggregating
real cloud subsystems with the caller's own bearer:

- /v1/world/cloud/clusters: DOKS + BYO clusters grouped by cluster (hanzo-k8s,
  adnexus-k8s, …) from the unified k8s noun (/v1/k8s/clusters + per-cluster
  detail), each with node pools, per-node status and GPU capacity. ClusterPanel
  renders it; honest ready/total counts, never fabricated nodes.

- /v1/world/cloud/queue: the gpu-jobs queue from the tasks engine
  (/v1/tasks/namespaces/gpu-jobs/activities) fused with /v1/fleet/workers —
  depth by status, running + pending jobs each with the dispatching service
  (the job type's prefix), the claiming worker, and the target model, plus the
  online worker count. QueuePanel renders it.

Also surface what each BYO GPU is serving on the existing fleet panel: fold the
worker's advertised hanzo-engine models (engine.serve) + engine status + job
queue into /v1/world/cloud/fleet and the worker row.

Tests: hermetic gate (401 anon / 403 non-admin, no payload leak) + admin
success-path reshaping the real upstream shapes; a playwright e2e that renders
both panels for an admin owner and confirms a non-admin owner is denied (panels
never mount).
2026-07-21 17:00:19 -07:00
hanzo-dev f4e5c7c6f3 router: enso fold reads router/{ledger,rewards} (routes renamed from export-routing-*) 2026-07-21 16:57:13 -07:00
Hanzo Dev 0077dfd590 release: v2.4.36 — alt-data plane (insider · defi · layoffs · congress)
Four macro signal sources under /v1/world/*:
  insider  — SEC EDGAR Form 4 filing flow (keyless, live)
  defi     — DeFiLlama TVL + stablecoin float (keyless, live)
  layoffs  — Texas WARN notices (keyless, live)
  congress — Quiver Quant congressional trades (QUIVER_API_KEY, degrades clean)
Bumps the vestigial VERSION file to the release for the first time in a while.
2026-07-21 16:54:10 -07:00
Hanzo Dev 81cd2e1455 feat(world): alt-data plane — /v1/world/layoffs (TX WARN) + /v1/world/congress (Quiver, key-gated)
Completes the four macro signal sources on the alt-data plane:
  insider (SEC Form 4), defi (DeFiLlama), layoffs (TX WARN), congress (Quiver).
layoffs reads the Texas Workforce Commission WARN Socrata feed (keyless, live).
congress reads Quiver Quant when QUIVER_API_KEY is set and degrades to a clean
unavailable payload otherwise — the free house/senate feeds are all gated now,
so this follows the same key-gated pattern as finnhub/eia/acled. Pure parsers
are unit-tested; the route sweep confirms both degrade without 5xx or HTML leak.
2026-07-21 16:53:54 -07:00
Hanzo Dev f24786e5a7 feat(world): alt-data plane — /v1/world/defi (DeFiLlama) + /v1/world/insider (SEC Form 4)
DeFi snapshot: total TVL across chains, top-10 chains by share, stablecoin
float (top-6 by market cap) — one cached pull shared by all viewers.

Insider flow: SEC EDGAR Form 4 filing stream (buys/sells by officers,
directors, 10% holders) — the filing-velocity macro signal. SEC-compliant
descriptive User-Agent; pure atom parsing unit-tested.

Both cached, single-flighted via cachedJSON, degrade to a clean 200
unavailable payload. Routes swept by TestRoutesRespond.
2026-07-21 16:53:54 -07:00
Hanzo Dev 63cae5c2d2 world: autonomous multi-asset fund brain — paper-only book + engine
Port the fund conviction model (research/rotation_model.py §5) to Go, layered
on the existing RRG kernel (handlers_rotation.go): each asset-class sleeve is an
equal-weight synthetic scored on the RS-Ratio/RS-Momentum plane vs SPY, and
conviction = quadrant base + momentum tilt + oversold bonus, normalized into a
preferred portfolio.

- fund_model.go   sleeves, scoreSleeves, conviction, overallStance (pure)
- fund_broker.go  the PAPER/LIVE seam: Broker iface, PaperBroker (only real
                  impl), LiveBroker stub that refuses; append-only paper ledger
- fund_engine.go  autonomous loop: recompute book, diffOrders, execute paper,
                  fold fills, mark sim PnL
- handlers_fund.go /v1/world/fund, /fund/ledger, /fund/brief

No real order is ever placed: the engine holds a Broker whose sole real
implementation is PaperBroker; live execution has no wiring.
2026-07-21 16:14:44 -07:00
hanzo-dev 8346fb65db release: v2.4.35 — globe-render e2e green + __deckMap-when-functional (on the mapbox-mercator globe-blank fix) 2026-07-21 16:06:05 -07:00
hanzo-dev 21e1bb6577 fix(world/globe): restore globe-render e2e to green + expose __deckMap when functional
The globe-render acceptance suite went red as the flagship Cloud view evolved
(cloud now opens on the native 3D globe, controls collapsed into dropdowns); none
of it was a globe-render bug — the sphere renders and occludes correctly — the
harness just no longer matched the app. Restore it to 6/6:

- e2e/globe-render: pin the 2D->3D toggle path with ?mode=2d. Cloud defaults to the
  immersive 3D globe, which parks the mapbox map and mounts .deckgl-map-wrapper
  hidden, so the old `toBeVisible` precondition could never pass. Enter 3D through
  the proj-btn's REAL click handler (the immersive dock floats over the full-view
  globe canvas, so a headless synthesized mouse click's hit-test lands on the
  canvas, not the collapsed-dropdown button). This spec verifies GLOBE render
  (occlusion/terrain/parity/live dots); dock pointer reachability is out of scope.

- DeckGLMap: expose __deckMap/__mapboxMap as soon as the instance is FUNCTIONAL
  (right after initBasemap creates this.mapboxMap) instead of on the async mapbox
  'load'. When Cloud opens straight into the parked-mapbox native globe, 'load' can
  trail the globe by seconds, so the e2e read an undefined __deckMap right after
  go3D. buildLayers()/asGlobeSource()/setOcclusionCenter()/occludeFarSide() are all
  live at construction; __deckOverlay stays exposed in initDeck where it is built.

- vite: optimizeDeps.include the deck.gl / luma.gl / mapbox graph so a cold dev/e2e
  server pre-bundles @luma.gl/webgl's device adapter up front and never re-optimizes
  mid-load — that reload otherwise races GlobeNative's `new Deck()` and the 3D globe
  never initialises. Prod is unaffected (Rollup build, no dep optimizer).

Verified: e2e/globe-render.spec.ts 6/6 green on an unminified dev server; the dot
globe renders (4726 land dots), traffic dots occlude (back-hemisphere alpha 0),
count badges cull, terrain drapes single-context, live dots update.
2026-07-21 16:05:16 -07:00
hanzo-dev be2bc30a7c fix(cloud-admin): liveness-authoritative up for uninstrumented subsystems
The admin CloudServicesPanel set each subsystem's up from /v1/o11y/status,
so any subsystem o11y lacked telemetry for rendered as DOWN — a live service
shown 'not active'. probeService now treats o11y as metrics enrichment and
derives up from a real liveness probe (livenessURL) when o11y has no
per-deployment data; instrumented stays a separate signal. Live-but-
uninstrumented ⇒ UP with no metrics, never a false down. TDD: 2 new tests green.
2026-07-21 15:33:26 -07:00
hanzo-dev 3d74a312f2 docs(world): AGENTS.md — prefer Hanzo MCP browser over Playwright, globe/dot map + release notes
Repo had no agent doc. Records the browser-control preference (Hanzo MCP
extension for interactive UI, Playwright only for the deterministic e2e
suite or when the extension is absent), the dot-lattice cybermap default
(one getLandDots() shared by 2D DeckGLMap + 3D GlobeNative), and the
bump-patch/tag/dispatch release convention.

Claude-Session: https://claude.ai/code/session_01NP4ehjWW2h98FkE4YjUKuJ
2026-07-21 15:18:14 -07:00
hanzo-dev 423af9abad fix(world/map): globe blank — keep parked mapbox in mercator when the native globe is on
world.hanzo.ai showed a blank center (globe gone). Root cause: the mapbox basemap
was created with projection:'globe' in 3D mode, and mapbox-gl v3.26 throws
"Missing theme" when a plain (non-Standard) style loads in globe projection —
which aborts the whole map init, taking the native deck.gl globe down with it.
(Surfaced now because the v2.4.33 .dockerignore switched CI from runner-cached
node_modules to a clean lockfile npm ci = mapbox-gl 3.26.0.)

When the native deck.gl globe is on (the default), the mapbox map is only a parked,
invisible basemap behind GlobeNative — it never needs globe projection. Add
mapboxProjection(): globe ONLY when 3D AND native globe is off; otherwise mercator.
Applied at map construction + in applyProjection(). No visual change (parked map is
invisible); the native globe now renders.

Verified with a swiftshader (software WebGL) playwright run: the dot-globe renders,
.globe-native-canvas mounts, no 'Missing theme'. tsc + vite build green.

Claude-Session: https://claude.ai/code/session_81b00bd9
2026-07-21 15:17:58 -07:00
Hanzo Dev 75cc42fd1c Merge lux.fund fund variant — Lux Macro terminal + Lux Book + rotation notebook 2026-07-21 14:16:10 -07:00
Hanzo Dev 362cbed84f Merge rotation scanner — RRG sector-rotation detection (red-reviewed) 2026-07-21 14:16:03 -07:00
Hanzo Dev 5b77463ad0 world: lux.fund hides the emoji view-switcher (academic, focused terminal) 2026-07-21 14:15:41 -07:00
Hanzo Dev edbbfe58e4 world: rotation model research notebook (Hanzo Notebook)
A reproducible numpy/scipy reference implementation of the RRG rotation
model that powers the engine. Loads a 6-month daily snapshot of the
32-symbol universe (research/data), formalises RS-Ratio / RS-Momentum and
the quadrant classification, reproduces the current read and the Lux Book
top-10 allocation, and backtests the rotate-out-of-Weakening /
into-Improving thesis.

The numpy read cross-validates the Go engine exactly (Uranium 97.4/103.1,
Hyperscalers weakening 101.4/95.9, Great Rotation 0.55 WATCH). The backtest
is reported as indicative on a single window, not an alpha claim.

Executed notebook (rotation_model.ipynb) + percent-format source + the
data snapshot + the RRG plot.
2026-07-21 14:10:07 -07:00
Hanzo Dev a80b683f61 world: fund variant — Lux Macro terminal (lux.fund white-label)
Add a `fund` variant: the same World 3D-globe engine as finance, Lux
white-labeled and sharpened for the fund's macro read. lux.fund defaults
to it; the Lux wordmark replaces the Hanzo mark on that host.

The Lux Book (LuxBookPanel) derives the top-10 model allocation live from
the rotation engine — conviction weights each theme by quadrant, momentum
tilt and oversold-base bonus, normalised to a 100% book, and rebalances
every refresh. Each position carries a globe anchor and the book is
emitted on the `lux-book` document event for the globe layer to plot.

Rotation scanner and market radar lead the layout; feeds reuse the finance
set; energy/commodity hubs join the globe. Build meta + dev/build:fund
scripts added.
2026-07-21 14:09:36 -07:00
Hanzo Dev 2031ce3a79 world: rotation scanner — harden against bad Yahoo ticks (red review)
Red review fixes:
- Drop non-positive (0/negative) closes in the rotation fetch path via
  positiveCloses. A spurious Yahoo 0 tick on a thin symbol was surviving
  compact() (which keeps 0 for legitimate zero-volume bars) and could flip
  a lead theme's quadrant, toggling the public Great Rotation signal. The
  shared compact() is untouched so volume series stay correct.
- Guard round2s against NaN/Inf (return 0) so a stray non-finite can never
  reach json.Marshal after cachedJSON has cached the value — an airtight
  "never 5xx".
- RotationScannerPanel drops an aborted fetch silently instead of flashing
  "unavailable" over the still-valid render on rapid refresh/destroy.

Tests: positiveCloses drops bad bars; a 0 bar no longer flips the quadrant.
2026-07-21 14:08:04 -07:00
Hanzo Dev 42e8ce1b60 world: rotation scanner — RRG sector-rotation detection
Add /v1/world/rotation: a Relative Rotation Graph engine scoring theme
baskets (AI/semis, hyperscalers, energy, natural gas, uranium, nuclear
power, plus the GICS sectors as context) on RS-Ratio x RS-Momentum
against SPY, into four rotation quadrants and named thesis triggers —
AI distribution, energy-complex accumulation, and the combined Great
Rotation that needs both legs to fire.

RotationScannerPanel renders the quadrant plot with rotation tails, the
signal chips and a momentum-ranked leaderboard. Computed server-side,
cached 15m, single-flighted; degrades to a clean unavailable 200 when
upstream data is thin.

Registered in the finance, tech and full variants.
2026-07-21 13:47:20 -07:00
hanzo-dev 0550159a9a release: v2.4.33 — honest measured Enso benchmark numbers
Ships the corrected benchmark closeout (already on main, now released):
- summary.json: real measured accuracy for GPQA-Diamond / LiveCodeBench / HLE
  / CharXiv across the frontier arm pool + enso/enso-flash/enso-ultra; degraded
  (content-filter/length-truncated) rows carry NO number and are dropped rather
  than shown as a low score.
- SWE-Bench Pro + Terminal-Bench honestly marked pending (not yet run), not faked.
- Dropped the aspirational reference table; the panel stands on measured numbers.
- .dockerignore so host node_modules can't clobber the image npm ci.
Total measured spend $564.25, all real. Handler gate + honest-data tests pass.
2026-07-21 08:59:25 -07:00
Hanzo Dev 2f52c34f9c world: resync; degraded benchmark rows carry no number and are dropped
The snapshot is resynced to enso-bench, where a run lost mostly to blanks now reports no
accuracy at all. The handler already drops degraded rows, so the dashboard shows only clean
complete-run measurements; this keeps the embedded data honest for any other reader of the
snapshot too.
2026-07-20 05:47:44 -07:00
Hanzo Dev d41d4a5b69 world: show honest complete-run scores, drop degraded rows
The benchmark snapshot is resynced to the corrected enso-bench numbers, which are
complete-run scores rather than blank-excluded estimates. Excluding blanks inflated the
numbers because blanks land on the hard items a model gets wrong, so the dashboard was
about to show fable-5 at a spurious 93.6 against its true 81.3. A run that lost most of its
items to blanks is now marked degraded and dropped from the table entirely rather than
displayed with a misleading number, so glm-5.2's 65%-blank run no longer appears as a
score.
2026-07-19 23:49:42 -07:00
Hanzo Dev 7084a2fbbb world: stand on corrected measured numbers, drop the aspirational reference table
The enso benchmark snapshot carried an enso_reported block whose figures did not match our
own measurements -- it showed enso-ultra at 50.0 on HLE where we measured 34.6, and 93.2 on
LiveCodeBench where we measured 81.6 -- and its columns named other vendors. A dashboard
that shows fabricated superiority beside real measurements is worse than one that shows
less, so the block is removed and the dashboard now stands on the corrected measured tables
alone. The tests assert the reference table and its columns are absent rather than present.
2026-07-19 23:37:02 -07:00
Hanzo Dev 2546b0c9d0 world: refresh the enso benchmark snapshot with blank-corrected accuracy
The dashboard embedded a snapshot in which infrastructure blanks -- upstream 200s carrying
no answer -- were scored as wrong, so it displayed glm-5.2 at 31.8 and fable-5 at 81.3
against their true 94.0 and 93.6. The measured block is regenerated from the corrected
enso-bench summary, which computes accuracy over the items the API actually answered, and
the enso family's clean-path results are included.

The head-to-head test asserted the raw livecodebench figure and the old HLE preflight stub;
it now checks the corrected accuracy within a band and treats HLE as the real n=500
measurement it has become.
2026-07-19 23:32:27 -07:00
hanzo-dev e5d2898fd9 fix(build): add .dockerignore so host node_modules can't clobber the image npm ci at COPY . .
No .dockerignore existed, so `COPY . .` (Dockerfile:31) copied the host's
node_modules over the fresh `npm ci` tree — poisoning BuildKit's node_modules
cache-mount ('cannot replace directory with file') and breaking every world
image build (main + PR #19). The web stage installs its own deps, so the host
node_modules/dist/.git must never enter the build context.
2026-07-19 11:30:08 -07:00
hanzo-dev 10caeb61b4 release: v2.4.32 — cinematic dot-globe hero (translucent 3D lattice) + data-driven Enso caveats
Frontend — the "cool 3D dot map" is now the hero everywhere:
- DEFAULT_BASEMAP_STYLE = 'dot' for ALL variants (was cloud/ai only); the
  glowing dot lattice opens every mode. Persisted choice + style switcher win.
- GlobeNative: translucent glowing dot-globe — two passes (a DIM far lattice
  drawn through the sphere + a BRIGHT near pass depth-tested for real back-of-
  globe occlusion), additive blend so dense continents bloom; cool ice-blue rim
  glow atmosphere; radial-vignette background as the premium first-frame state
  (never a dead black hole). Shared position accessor → zero per-frame alloc.
- DeckGLMap: the SAME dot lattice + palette on the 2D mercator basemap (glow
  underlay + crisp core), so 2D ↔ 3D read as one surface; 'Dot' added to the
  style switcher; DEFAULT_BASEMAP_STYLE drives the default/fallback.
- land-dots: LAND_DOT_NEAR/FAR palette lives in ONE home, imported by both
  renderers (values, not places).
- Immersive: panels dock to a translucent GLASS right-rail with the globe as the
  centre hero; light-theme frosted variant + mobile glass bottom-sheet; legend
  becomes glass. CRITICAL: no transform/filter/backdrop-filter on .panels-grid
  (parent of the fixed globe → would trap it) — glass lives on the sibling cards.
- Desktop opens at zoom 1.35 so the globe fills the immersive viewport.

Backend — Enso benchmark caveats are fully data-driven (no literal drift):
- LiveCodeBench headline + premium-arm reference computed from the parsed table
  (premium arm read from the table's own Opus row when present).
- HLE "preflight only" note emitted ONLY when HLE is genuinely a preflight
  (n≤1) in the snapshot — never claims "not scored" over a real scored run.

CI gate green: tsc + vite build + go build (-tags sqlite_fts5) all pass.

Claude-Session: https://claude.ai/code/session_81b00bd9
2026-07-19 11:09:07 -07:00
hanzo-dev a6aaae65f2 release: v2.4.31 — map interaction (right-click no-select, non-country no-popup) + denser mobile grid + immersive video above footer 2026-07-19 06:37:09 -07:00
hanzo-dev c314f3941b fix(world/map): right-click never selects · non-country click shows nothing · denser mobile grid · immersive video above footer
- Right/middle click never picks-and-selects a country (deck.gl's tap recognizer
  fires onClick for those too); only LEFT click (button 0) selects. Guard in both
  handleClick paths (DeckGLMap flat + GlobeNative globe) via shared isNonLeftClick +
  MapClickEvent, event threaded through onClick + the globe source.
- Left-click on ocean/empty space no longer opens the 'identifying country'
  interstitial — onCountryClick only fires when a country actually resolves.
- Mobile: panels reflow to a denser >=2-up adaptive grid (was one giant column),
  honoring the cell-size control; min(--panel-col-min,46vw) guarantees 2 columns.
- Immersive video reserves the footer dock height so the full video sits ABOVE the
  footer — nothing occluded by the controls bar.
2026-07-19 06:36:18 -07:00
hanzo-dev da0ae02281 release: v2.4.30 — per-user usage history (searches + watch queue follow the signed-in user) 2026-07-19 00:07:16 -07:00
hanzo-dev 83890e7958 feat(world): per-user usage history (/v1/world/history) — searches + watch queue follow the user
- Backend: GET/PUT /v1/world/history via the SAME per-identity settings store, new
  'history' namespace. Extracted shared handleIdentityBlob (dashboard + history are
  one opaque-blob mechanism, two namespaces — DRY). Never fabricated.
- Frontend: generalized the dashboard-sync observer to route each localStorage key to
  its namespace — dashboard keys -> /v1/world/dashboard, history keys
  (worldmonitor_recent_searches, hanzo-world-watch-queue) -> /v1/world/history. One
  observer, boot-hydrates both, debounced per-group PUTs. SearchModal + watch-queue
  untouched (observer transparent).
- Tests: Go history round-trip + isolation + namespace separation + 401/400; e2e
  history routing + boot hydration. Dashboard e2e still green (5/5).
2026-07-19 00:06:14 -07:00
hanzo-dev 15dae13e49 release: v2.4.29 — Enso Router panel (cost/quality slider + judge viz) + AI Compute gate
Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-19 00:05:18 -07:00
hanzo-dev 7807ff5601 feat(world/enso): Enso Router panel — cost↔quality slider + mean-field judge panel
Cloud-variant panel surfacing two shipped router features:

- Section A: a Savings↔Quality bias slider (0..1) wired to a new org-scoped
  proxy GET|PUT /v1/world/cloud/router-preference → ai /v1/router/preference
  (caller IAM bearer forwarded). Debounced PUT + "saved" confirmation; stays
  interactive and shows an honest preview-only note when the gateway route
  isn't deployed yet.

- Section B: the Mean-Field Judge Panel via GET /v1/world/cloud/judge-panel →
  ai /v1/router/judge-panel?scope=platform — per-judge reliability-weight bars,
  calibrated means + n, sample rate + enabled state, and the published
  rank-corr-with-ground-truth benchmark (MFJP 0.966 vs single-judge 0.110).
  Honest "warming up" empty state when unavailable.

Both proxies never 5xx — they answer a well-formed {available:false} on any
upstream failure (including a 404 before the gateway routes ship), so the panel
degrades gracefully. New files only (handlers_cloud_router_pref.go,
EnsoRouterPanel.ts, router-preference.ts, judge-panel.ts) plus mount/route/CSS
wiring; reuses the cloud-* design system and theme tokens.

Verified with Playwright on ?variant=cloud: slider drags 0.5→0.90 with a live
label + honest "couldn't save" chip, judge section renders its warming-up
state, zero JS errors (only the expected not-yet-deployed 404s); dark + light
theme parity and mobile (374px, no overflow) confirmed.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-19 00:01:54 -07:00
hanzo-dev d25df44f21 fix(world): honestly gate the signed-out AI Compute plane (no zero-grid)
The inference plane is org-scoped ("metered to your org"). Signed out, the
public pulse only ever returns a zero-stub ($0 spend, 0 GPUs, 0/0 machines),
which rendered as a "live"-badged grid of zeros — exactly the "zero dressed up
as live traffic" the panel promises never to show, and reads as a dead/broken
platform. Gate on !isAuthenticated() at the top of render() (same sign-in
affordance as Fleet / My Usage), completing the honest-gate direction of v2.4.23.
The now-redundant inner signed-out branch is removed (one way to gate).
Signed-in behaviour unchanged. Release v2.4.28.
2026-07-18 23:50:49 -07:00
hanzo-dev 37a05c025f release: v2.4.27 — per-user dashboard persistence (GET/PUT /v1/world/dashboard, sqlite v0.3.2)
Signed-in dashboards persist server-side per identity and follow the user across
devices: panels/order/spans, layers, sources, custom feeds, map mode, the free
layout geometry, text-size and grid-size — hydrated on boot (server precedence),
debounce-synced on change via a localStorage observer. Anon stays localStorage-only.
Backend reuses store.Settings (namespace 'dashboard'); sqlite v0.3.0->v0.3.2 (fts5
build tag). Go tests + 3/3 frontend e2e green.
2026-07-18 23:46:29 -07:00
hanzo-dev 775493ebf2 feat(world): dashboard sync frontend — per-user server persistence via a localStorage observer (held)
Signed in, the composed dashboard (panels/order/spans/layers/sources/custom feeds/
map mode + the free-layout geometry) persists per identity and follows the user
across devices; signed out is unchanged (localStorage only).

- services/dashboard.ts: on boot, hydrate this identity's dashboard from
  GET /v1/world/dashboard into localStorage (server precedence) before the app
  reads it; then a Storage.prototype setItem/removeItem observer debounce-PUTs a
  snapshot of the dashboard keys on any change. One decoupled hook — App,
  grid-config and Panel stay unaware. Captures the worldmonitor-layout:* family so
  the free {x,y,w,h}/mode geometry follows the user too.
- main.ts: await initDashboardSync() before new App() (auth-gated, bounded, never
  blocks boot).
- e2e: hydration (server precedence) + change→debounced PUT of the snapshot + anon
  no-sync — 3/3 green (real app, faked IAM + stubbed endpoint).

Not released. Ships as v2.4.21 with sources + usage history.
2026-07-18 23:43:49 -07:00
hanzo-dev 3dc761d736 feat(world): per-user dashboard persistence backend + sqlite v0.3.2 (held for 2.4.18)
- GET/PUT /v1/world/dashboard: per-identity dashboard config through the existing
  store.Settings (namespace 'dashboard') — no new table; mirrors /v1/world/monitors
- generalize identityFor -> identityForDoc: one bearer->identity gate for the
  namespaced settings store (monitors + dashboard resolve through it)
- bump hanzoai/sqlite v0.3.0 -> v0.3.2 (vendored pure-Go, zero modernc.org/*).
  The vendored engine gates FTS5 behind -tags sqlite_fts5; add it to the Dockerfile
  go build (was implicit under v0.3.0's modernc backend) or store.Open degrades
- tests: dashboard round-trip + per-identity isolation + 401/400/405 boundary gates

Not released. Ships as 2.4.18 AFTER 2.4.17 (layout) is live+stable.
2026-07-18 23:43:49 -07:00
hanzo-dev 604b135add release: v2.4.26 — Enso Live Training shows the REAL served-model catalog (not opaque arm-N) 2026-07-18 23:38:43 -07:00
hanzo-dev 2335dcc4ca fix(world): Enso Live Training shows the REAL model catalog, not opaque arm-N (held)
User feedback: the panel showed "random amounts." Verified there is NO random data
anywhere in the Enso path — it rendered the upstream OPAQUE "arm-N" routing mix (real
counts relabeled to meaningless "Enso arm 1/2/3" with no model identity), which reads
as arbitrary.

- EnsoTrainingPanel now renders the REAL served-model catalog from the existing public
  /v1/world/cloud/models (→ ai /v1/models): real model names, tiers, providers, context
  and pricing — the same real models served on the platform.
- The real aggregates (cost-saved proxy, learned-engine share, events, throughput,
  cumulative index, shadow agreement, retrain gate) are unchanged — all real.
- Dropped the opaque by_model arm rows (armRows/armIndex). Honest empty states; never
  fabricated.
- e2e: stubs both feeds (router-stats incl. an arm-N map) and asserts the panel shows
  real model names + "models served" and NEVER renders "Enso arm"/"arm-N". Green.

Not released — hanzo assigns version/sequence.
2026-07-18 23:36:48 -07:00
hanzo-dev 55075bcbbe release: v2.4.25 — layout: snap-to-grid, no corner chevrons, finer grid, text-size control 2026-07-18 23:30:53 -07:00
hanzo-dev ec595bc567 feat(world): layout polish — remove resize glyphs, finer grid, text-size control (held)
Owner feedback on the free layout, batched with the snap-to-grid fix:

- No visible corner/edge resize glyphs (#2): the dots + corner brackets are hidden
  (display:none on the handle ::after); the handles stay invisible hit areas so
  dragging from any edge/corner still resizes — the resize cursor is the affordance.
- Finer grid (#3): MIN_CELL_SIZE 120->80 + dock "Widget size" slider min 120->80,
  step 20->10, so the grid — and the snap, which reads cellSize — goes finer.
- Text-size / UI-scale control (#4, accessibility): a dock "Text size" slider drives
  a --ui-scale var that zooms the readable panel CONTENT only (never the panels-grid,
  so drag/snap coordinates are untouched); persisted in localStorage (utils/ui-scale.ts),
  applied before first paint. Per-user SQLite dashboard-sync picks up the key.
- e2e: glyphs-hidden-but-still-resizes, finer-80px-floor, text-size-scales+persists.
  Full layout suite 21/21 green; build clean.

Not released — batched with the snap fix; hanzo assigns version/sequence.
2026-07-18 23:29:35 -07:00
hanzo-dev f86fb162f8 fix(world): free-mode drags + resizes snap to a logical grid (held)
User feedback on the free layout: "the snap is not logical." Free mode placed
panels at arbitrary px, which felt loose to drag. Now free-mode drag snaps {x,y}
to grid-line origins and resize snaps {w,h} to whole-cell multiples, so panels
land on consistent, aligned tracks — while keeping the independence that made free
mode good (resize/move one panel, siblings never move; opposite edge stays pinned).

- ONE logical grid, DRY: grid-config.freeSnap() = { cell: getCellSize() (the
  slider-driven --panel-col-min), row: --panel-row (16), gap }. Free and grid share
  one grid definition — no second magic number.
- panel-drag: snapLine (position -> nearest grid line) + snapCells (size -> whole
  cells, >= floor); threaded through moveFree + applyFreeResize. Hold Alt for fine,
  un-snapped placement. Grid mode untouched.
- e2e: two new proofs (drag -> two panels align to the same track; resize -> whole-
  cell width + opposite edge pinned); the arbitrary-px tests now hold Alt. 18/18 green.

Not released — version/sequence assigned by hanzo.
2026-07-18 23:29:35 -07:00
hanzo-dev 3bf9cc994c fix(world): Enso benchmark shows only our measured results — confident, sells
Dropped the external "reported" comparison column + the self-deprecating footnote
from the public benchmark. The panel now shows ONLY Enso's own live-measured accuracy
and per-system cost, with a confident, true caveat: every number is measured against
real APIs through the Hanzo gateway, Enso reaches frontier-competitive accuracy at a
fraction of the blended cost by routing each task to the right model, and it reports
what it spends. No external names, no incoherent framing.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 23:06:54 -07:00
hanzo-dev 3d1f91ecd8 release: v2.4.24 — Enso benchmark branding
Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 22:52:08 -07:00
hanzo-dev da762aee5b fix(world): brand benchmarks as Enso — scrub the old codename
The Enso benchmark panel + summary data carried the pre-release codename in labels,
JSON keys, Go structs, and the TS consumer. Renamed consistently to Enso / Enso-Ultra
across the data, the /v1/world backend handler, and the frontend so the public
benchmark shows only the Enso brand. No numbers changed; identifiers stay in sync
(measured Enso vs Enso's originally-reported figures).

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 22:51:28 -07:00
hanzo-dev 032c33d55a release: v2.4.23 — geo-aware model-improvement consent + honest AI Compute gate
Sweeps the unreleased range: geo-aware consent toggle in the account menu (reflects
the backend's effective default — opt-out non-EU, opt-in EU/UK/EEA) with honest copy;
and the AI Compute panel showing a plain "Sign in" gate instead of a scary
"unreachable" when signed out. (Signup disclosure + privacy/terms shipped separately
in hanzo.id + hanzo.ai.)

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 21:09:52 -07:00
hanzo-dev 607edfdbcd feat(world/consent): honest geo-aware microcopy for the model-improvement toggle
The "Help improve Hanzo AI" account toggle already reads the effective consent
from ai (getTrainingContribution) and paints it once loaded. Make the microcopy
and comments honest for the GEO-AWARE model — opt-in/default-OFF in the EU, UK &
EEA; opt-out/default-ON, disclosed at signup, elsewhere — instead of claiming a
universal "off by default". No logic change: the toggle stays a verbatim mirror
of ai's answer, so a non-EU org's ON effective default now reads as an accurate
label rather than a contradicted one, and the service/loader comments no longer
claim "never opted in => OFF".

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 21:05:55 -07:00
hanzo-dev 2c0445a308 release: v2.4.22 — per-org Analytics + Insights cards (world cloud view) 2026-07-18 20:49:06 -07:00
zandGitHub b6c423e358 Merge pull request #18 from hanzoai/feat/org-analytics-insights-cards
feat(world/cloud): per-org Analytics + Insights cards
2026-07-18 20:48:14 -07:00
hanzo-dev 07607bf57a feat(world/cloud): per-org Analytics + Insights cards
Two org-scoped event-platform cards for the Cloud view, sourced from the
live native analytics warehouse on api.hanzo.ai (verified live):

- Analytics (org-analytics): /v1/analytics/overview + timeseries + top —
  per-org requests/visitors/tokens/spend, requests trend, top models.
- Insights (org-insights): /v1/insights/events — active users, top events,
  activity trend derived client-side from the real event stream.

Org pinned server-side from the validated bearer owner claim (principal.Org),
reusing org-scope.scopedHeaders() like getMyBilling — no new fetch mechanism.
Reuses the existing Panel + cloud-format primitives + cloud-* CSS. Honest
loading/signed-out/empty/error states; never fabricated numbers.
2026-07-18 20:20:15 -07:00
hanzo-dev 50a7448678 fix(world): AI Compute shows honest "sign in" gate, not a scary "unreachable"
Signed-out, the live compute pulse is account-scoped, but the panel rendered
"Compute telemetry unavailable — compute plane unreachable" which reads as a backend
outage. Match the Fleet / My Usage pattern: signed-out shows a plain "Sign in to see
the live inference plane…"; the unreachable error copy is reserved for a genuine
failure while signed in.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 20:13:20 -07:00
hanzo-dev 870ec49f3d release: v2.4.21 — mobile search icon + consent toggle (unique tag; 2.4.20 was claimed concurrently) 2026-07-18 17:45:22 -07:00
b7a90b2774 fix(world/header): give the mobile search button a magnifier icon (#16)
At <=680px both the Ctrl/Cmd-K hint (already hidden <=900px) and the
'Search' label were hidden, leaving the search button an empty bordered
box. Add an always-present magnifier icon that reveals once the K hint
collapses, so the button is never empty at any width. (2.4.20)

Co-authored-by: hanzo-dev <dev@hanzo.ai>
2026-07-18 17:42:55 -07:00
hanzo-dev 493fb3d4e7 feat(world/consent): opt-in "Help improve Hanzo AI" toggle (default OFF) (2.4.20)
Add a model-improvement consent toggle to the account menu, wired to ai's
OrgSettings.TrainingContribution (the source of truth the automated judge + trainer
read). Honest, opt-in, off by default, no dark patterns.

- src/components/AccountMenu.ts: a "Data & privacy" switch in the signed-in dropdown.
  Painted OFF until the async read lands (never a false "on"); optimistic flip that
  reverts if the server refuses. Exact microcopy: rating keeps only a numeric score,
  never prompts/outputs, runs confidential/anonymous, off anytime.
- src/services/training-contribution.ts: get/set via the app's org-scoped authed
  fetch (orgHeaders). Signed-out / error / unset all read false — privacy-safe.
- internal/world/handlers_training.go: same-origin proxy /v1/world/training-contribution
  → ai get-/update-training-contribution, forwarding the caller's bearer + X-Org-Id.
  World holds NO copy; ai self-scopes to the caller's own org and is the sole authority.

Tests: proxy gates signed-out (401, no upstream call), forwards bearer + org, and
unwraps the casibase envelope to a bare {enabled} on both GET and POST.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 17:41:23 -07:00
hanzo-dev 09954907cf fix(world): default to free layout — panels move/resize independently, no reflow (2.4.19)
The dashboard defaulted to grid snap, so dragging or resizing one panel
reflowed all the others and resize jumped between coarse column/row spans.
CSS grid can't move a panel without disturbing siblings, so make FREE the
default layout: every panel owns its own {x,y,w,h}. The current grid
arrangement is frozen as the starting geometry (grid-config.applyDefaultLayout,
run once after panels+map lay out), so the flip is invisible; Grid stays a
dropdown choice and grid-config records an explicit pick so the default never
overrides it.

- Independent positioning (#1): free mode — moving/resizing one panel leaves
  every sibling exactly where it was (proven: siblings drift 0px).
- Granular resize (#2): pixel-exact w/h from any edge/corner, not span jumps.
- Narrower panels (#3): free floors 160->96 (map 240->140); grid track floor
  140->120. A panel drags to 96px, well under the old min.
- Viewport-flexible (#4): map + live-news resize freely, small to large.

Hidden panels no longer persist 0x0 rects; a panel shown while free seeds a
tidy default slot. Tests: +2 harness proofs (no-sibling-reflow, sub-160 width);
repaired two stale span-2 assertions to the fine-grid data-span reality.
2026-07-18 17:26:25 -07:00
hanzo-dev 08df02b535 release: v2.4.18 — dotted-land cybermap globe + fullscreen-video idle fix
Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 17:05:35 -07:00
hanzo-dev 138d96a1b8 fix(world/live-news): never idle-kill a fullscreen video (exited fullscreen + stopped)
Passively listening to a live stream in fullscreen fires no mousedown/keydown/scroll
(fullscreen video captures input), so the 5-min input-idle timer fired and pauseForIdle
→ destroyPlayer tore down the iframe — which force-exits fullscreen AND stops playback
(the reported "listening fullscreen and it exited + stopped"). Fix: treat fullscreen as
the strongest "actively watching" signal — never idle-kill when our player is the
fullscreen element — and count fullscreenchange as activity so entering fullscreen
resets the idle timer.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 17:05:34 -07:00
hanzo-dev cf2092380b feat(world): dotted-land "cybermap" globe — restore the dot map
Restores the dotted-land basemap (land shown as a lattice of glowing dots over a
black-ocean sphere — the abstract cybermap surface): new land-dots.ts (getLandDots()
samples /data/countries.geojson into a cached lat/long lattice, land points only),
GlobeNative renders it as a ScatterplotLayer on the 3D globe, variant.ts defaults
cloud + AI to the 'dot' style, and App opens cloud/AI on the 3D globe (the live-traffic
centerpiece). Recovered from a stashed WIP; DeckGLMap kept at current main (preserves
the shipped layer panel + control dropdowns), so this ports cleanly with no regression.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 17:00:43 -07:00
hanzo-dev d8175e0a37 feat(cloud): default the Cloud view to the immersive globe — bring back the cool 3D dot map
The flagship Cloud view was defaulting to the grid dashboard, demoting the
full-viewport 3D dot map to a small corner tile. Restore it: when the visitor
hasn't explicitly picked a layout, the Cloud variant opens on the immersive
globe (map fills the viewport, panels float over it). An explicit grid choice
and the ?layout= URL param still win; other variants unchanged.
2026-07-18 16:58:16 -07:00
hanzo-dev 97fed1fee2 release: v2.4.16 — analyst grounded in live cloud metrics (answers spend/fleet/enso)
Ships 3d892d96: the AI analyst now folds a live Hanzo-cloud snapshot into its context
(traffic, platform 24h, Enso router cost-saved/reward/engine-share, flywheel ledger,
billing), so it can answer questions about the dashboard's real numbers — on top of
its existing 26-command control surface.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 16:27:49 -07:00
hanzo-dev 3d892d9633 feat(world/analyst): ground the AI in live cloud metrics so it can answer anything
The analyst's context fed panel names + visibility but NOT the live values, so it
couldn't answer "what's my spend / how many DO nodes / is Enso saving money". On the
cloud board it now also folds a real-data snapshot — live traffic (rps/req), platform
24h (requests/tokens/nodes/GPUs/regions/uptime), the Enso router (cost saved, reward
rate, engine share, models routed), the flywheel ledger, and the caller's billing
(spend/balance/events). Best-effort + parallel with the news feeds; real data only,
mirroring the panels. Pairs with the 26-command control surface — the analyst can now
both control the dashboard AND answer questions about what it shows.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 16:27:04 -07:00
hanzo-dev 8c0e928789 release: world 2.4.15 — bake VITE_MAPBOX_TOKEN so Satellite/Terrain load
2.4.14 tagged before the build_secrets wiring landed, so it builds without the
Mapbox token. 2.4.15 = same tree + the KMS-sourced VITE_MAPBOX_TOKEN build-arg
(via hanzoai/ci v1.0.5), so satellite-streets/outdoors render in 2D and 3D
instead of the keyless dark fallback.
2026-07-18 12:34:27 -07:00
hanzo-dev 0b52de0236 release: world 2.4.14 — Satellite/Terrain via KMS Mapbox token
Root cause of the dark Sat/Terrain: no VITE_MAPBOX_TOKEN was baked at build, so
the token-gated Mapbox satellite-streets-v12 / outdoors-v12 styles silently fell
back to the keyless CartoDB dark basemap in both 2D and 3D. The publishable pk
token now lives in KMS (hanzo/deploy/VITE_MAPBOX_TOKEN, env=prod) and is sourced
by hanzoai/ci (v1.0.5) as a build_secret --build-arg into the Vite SPA.

Rides the pending main fixes (analyst reasoning recovery, AI Compute rate,
map-control dropdowns).
2026-07-18 12:33:11 -07:00
hanzo-dev 3fbbbbebf5 release: v2.4.14 — dropdown map controls, 2×2 panels, AI Compute fix, analyst recovery
Sweeps the unreleased range: map controls collapsed to 3 dropdowns + symmetric 2×2
tiles + dropped regions tile (3fc42b1f); AI Compute rate un-flattened (interval enum
bug) + honest sub-cent usage rows (4c41abbb); analyst chat recovers reasoning-model
answers instead of "empty response" (a17d63c1).

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 12:31:13 -07:00
hanzo-dev a17d63c10d fix(world/analyst): recover reasoning-model answers so chat stops returning "empty response"
The analyst rendered "The analyst couldn't answer — empty response" whenever the
served model streamed its answer on the reasoning channel with an EMPTY content
channel — gpt-oss / harmony, deepseek-r1 and kin. The ONE completion path
(chatMessagesModel + chatMessagesModelStream) read only the content channel, so a
reasoning model's output was dropped and surfaced as a blank.

- Read the reasoning channel (message.reasoning_content / reasoning, and the SSE
  delta.reasoning_content / reasoning) as a fallback when content is empty, and
  forward reasoning deltas live so the replyExtractor shows them on the thinking line.
  Content is always preferred; non-reasoning models (best/zen5) are unaffected.
- Replace the opaque "empty response" with an honest, model-named error
  ("the <model> model returned an empty answer"): never misreads a normal
  completion's response id as an error code, never trips the 402 top-up CTA.

Tests: reasoning-channel recovery (buffered + SSE) and the honest empty-answer error.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 12:30:15 -07:00
hanzo-dev 4c41abbb29 fix(world): AI Compute rate no longer flat (interval enum) + honest sub-cent usage rows
AI Compute (and cloud-pulse) rps/tps were dead flat: the usage series reports its
bucket width as a WORD enum ("hour"/"day"), but intervalSeconds parsed it with
time.ParseDuration — which fails on "hour" (needs "1h") — so usageRate always fell
back to total24h/86400, a constant. Resolve the enum (minute/hour/day/week) before
ParseDuration; the rate now reflects the freshest hour and moves. Regression tests
for intervalSeconds + usageRate.

My Usage & Bill: a real sub-cent inference charge (< $0.005) rounds to 0 integer
cents and rendered a bare "$0.00" that reads as "not billed". Show "< $0.01" for a
real row that rounded to zero — honest about a tiny real charge (the ledger only
carries integer cents on the wire).

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 12:17:03 -07:00
hanzo-dev 3fc42b1f1f fix(world): collapse map controls to dropdowns; symmetric 2×2 tiles; drop regions
Map controls:
- Projection (2D/3D), basemap (Dark/Sat/Terrain) and time-range each collapse into ONE
  compact dropdown (trigger shows the active value + caret; options in a popover). The
  top dock is now a single tidy row of three instead of two wrapping rows. Global
  .deckgl-dd treatment (one way, every map host). e2e specs open the dropdown before
  clicking an option via a shared clickMapControl helper.

Panel symmetry (real data, never padded):
- Live Traffic: added a real 4th tile (distinct countries with traffic) → 2×2.
- Model Improvement: split scored-events into its own tile → 2×2 (reward rate,
  requests scored, active days, retrains).
- Cloud Overview / Global Platform: dropped the 'regions' tile (fleet carries region
  detail) per CTO.
- New .cloud-stat-grid-2 (exactly two columns) for the symmetric 2×2 layout.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 12:13:53 -07:00
hanzo-devandz 5a65e739a9 fix(world): globe overlays hug the sphere — real occlusion, terrain seams, live dots (2.4.13)
The Hanzo-Cloud globe 'spazzed': data layers floated above the sphere, the
far hemisphere showed through, count badges hovered over the planet, terrain
striped at tile seams, and the live request-geo dots froze on the 3D view.

- GlobeNative seats every data layer against the depth-writing ocean sphere
  (depth-TEST, no write) so points/icons/text/paths/arcs occlude on the GPU.
- occludeFarSide now faces the globe's OWN live camera (mapbox is parked/frozen
  behind the native GlobeView) and culls TextLayer badges too, so a back-side
  count badge disappears instead of floating over the limb. Camera is fed each
  rebuild + on drag >2°; escape path (?globe=mapbox) keeps the live mapbox center.
- Draped ESRI terrain/satellite tiles stop writing depth (coplanar tiles were
  z-fighting at seams → striping); the ocean sphere owns the depth buffer.
- Cloud /v1/world/cloud/* poll gates on tab visibility, not renderPaused, so the
  realtime dots keep updating on the native 3D globe (the default view).
- Request-origin → serving-region arcs ON by default in Cloud (real feed, empty
  when no traffic — never demo).
- e2e/globe-render.spec.ts asserts occlusion (dot + badge), 2D/3D parity,
  terrain single-context, and live-dot updates.
2026-07-18 11:57:14 -07:00
hanzo-dev d4820277af release: v2.4.12 — map controls top-row + Layers, org logo, fleet RAM, globe cables
Ships the unreleased 2.4.11..HEAD range (all UI): globe cables hug the sphere, map
controls in one top row + top-left Layers button (footer/scrollbar removed), one Fleet
panel with system RAM, BYO once, and the org logo in the account switcher.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 11:53:11 -07:00
hanzo-dev d40c8560bb fix(world): render the org logo in the account switcher (was dropped)
The account chip showed the USER avatar next to the org name and never the org's
own image — IAM's get-organizations returns each org's Casdoor `logo`, but listOrgs
parsed only name + displayName and dropped it, so the hanzo org logo never rendered.

Thread `logo` end-to-end (OrgInfo → OrgOption → scope) and render an ORG avatar in
the switcher trigger: the active org's logo when set, else org initials (rounded-
square so it reads as an org, not a person). The dropdown's user row keeps the user
avatar. Falls back to the user avatar only when there's no org scope (signed out).

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 11:34:46 -07:00
hanzo-dev 7d737f2a53 fix(world): map controls to one top row + top-left Layers; BYO once; hide page scrollbar
Map controls (CTO revision of the bottom dock):
- 2D/3D toggle + Dark/Sat/Terrain switcher + time-range pills now sit in ONE row
  across the map's TOP, side by side (was a bottom-border dock). Zoom stays top-right,
  legend bottom.
- New top-left "Layers" button on the map toggles the floating layer panel (opens
  just below it). Removed the redundant Layers button from the page footer dock —
  layers now live on the map itself.
- Hid the .main-content right-edge scrollbar (wheel/trackpad scroll unchanged) — it
  read as a stray "sidebar scroller" over the map. Same treatment header/switchers use.

Fleet:
- BYO nodes rendered TWICE — once as a "byo" provider group and again as the BYO GPU
  workers list (same dbc/evo/spark). Managed providers (DO/GCP/AWS) now render as
  provider groups; BYO renders once, as the richer workers list.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 10:50:39 -07:00
hanzo-dev 35e07a65ae feat(world/fleet): render system memory in the machine spec line
The fleet machine rows showed GPUs · VRAM · vCPU · OS but never system RAM —
there was no memory field on the path at all. Thread `mem` end-to-end on the
world side: decode it from /v1/machines, carry it on fleetMachineRow, expose it
on FleetMachineRow, and render it in machineSpec (GPUs · VRAM · vCPU · RAM · OS)
only when present. The cloud service now populates `mem` (DO size-slug + upstream
memSize); world shows whatever is real and omits it otherwise — never fabricated.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 09:28:14 -07:00
hanzo-dev 8d3d20eb79 fix(world): globe cables hug sphere · docked map controls · one Fleet panel
Globe (3D):
- Cables + pipelines (PathLayer) drew straight chords across the sphere — deck.gl
  has no greatCircle for paths (only ArcLayer). Pre-densify each static path along
  its great circle into <=4-deg hops so the many short segments hug the surface.
  Flat map keeps the raw sparse vertices.

Map controls:
- The 2D/3D toggle, basemap switcher and time-range pills were scattered across the
  wide empty map header (top-center, mid-left, top-right). Dock them into ONE tidy
  strip along the map's bottom border via the existing controlsHost mechanism (App
  passed none). The dock mounts on the map container — a SIBLING of the deck wrapper
  — because 3D parks that wrapper (visibility:hidden) and renders via GlobeNative; a
  dock inside it would vanish on the globe. Reuses the .world-dock inlining CSS.

Fleet:
- "Fleet & GPUs" (FleetPanel, all users) and "Fleet & clusters" (CloudFleetPanel,
  admin) were duplicate platform-fleet renders. Collapse to ONE "Fleet & GPUs":
  widen FleetPanel, port the utilNote line, derive the provider-scope label from the
  providers actually reporting (not a hardcoded four), delete CloudFleetPanel.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-18 09:13:40 -07:00
hanzo-dev 0cda941c4c fix(world): builder needs git + gh_token for private indirect dep hanzoai/csqlite
golang:1.26-alpine ships no git; go resolves the private indirect
github.com/hanzoai/csqlite 'direct', so 'go mod download' died with
git-not-found. Add git, set GOPRIVATE, mount the gh_token secret ci already
passes. Unbreaks world main builds (broken since the Go-base-1.26 drop-in).
2026-07-17 23:29:05 -07:00
hanzo-dev 385a3a30bd world 2.4.11 — release (verify semver CR pin via hanzoai/ci@v1) 2026-07-17 23:18:40 -07:00
hanzo-dev 16d0f000ea fix(world): Docker Go base 1.26 for hanzoai/sqlite drop-in
go.mod now requires go >= 1.26.4 (github.com/hanzoai/sqlite). Bump the
builder base golang:1.25-alpine -> golang:1.26-alpine so the prod image
keeps building. The binary stays CGO-free (CGO_ENABLED=0), so hanzoai/sqlite
selects its pure-Go modernc backend — FTS5 built in, works. CGO test path
(no FTS5 without -tags sqlite_fts5 + libsqlcipher) is not what world ships.
2026-07-17 22:03:54 -07:00
hanzo-dev f52b5b2366 Merge feat/sqlite-hanzo-driver 2026-07-17 21:59:53 -07:00
hanzo-dev 3dd4823e3e fix(world): wide panels overflowed the fine grid (AI Compute rendered under things) + DRY o11y usage
.panel-wide kept grid-row: span 2 (the old 200px-grid assumption) after the move
to 16px rows — so all 7 wide panels (ai-compute, cloud-overview, live-news,
traffic-globe, enso-flywheel, model-improvement, hanzo-status) reserved only ~36px
of track while being 350px tall, overflowing their cell and painting over the
panels below. Fixed to span 18 (≈356px) with the shared 48px min-height floor.

Also: extract fetchLLMUsage (DRY) shared by cloud-pulse + ai-pulse, and fall back
to LLM observability in ai-pulse so AI Compute shows real usage (not zeros) for an
authorized operator.
2026-07-17 21:52:34 -07:00
hanzo-dev c8aae3366c feat(world): real per-model usage + volume from LLM observability (admin)
Model Usage showed 'warming up' / nothing and usage totals were 0 for a signed-in
admin whose super-admin usage ledger (?org=all) is denied. Fixed: the admin path
now folds REAL platform usage from LLM observability (/v1/admin/o11y) with the
caller's own bearer — measured requests, tokens, and top models by REAL name (not
the opaque router arms) — clearing volumeModeled. Falls back honestly to empty if
the caller isn't authorized for platform observability upstream.
2026-07-17 21:45:26 -07:00
hanzo-dev 997630fcb5 feat(world): admin-only Enso benchmark suite (head-to-head vs SOTA + Fugu)
Private, competitive data (names competitor models + Fugu), so it is gated
server-side, never bundled into the public SPA:

- backend: GET /v1/world/enso-benchmarks reuses the exact requireAdmin gate
  (401 no-token / 403 non-admin, IAM-introspection). Reshapes the SAME embedded
  enso-bench snapshot the flywheel reads (one embed, two views) into the measured
  head-to-head + verify-then-select ablation + agentic SWE-Bench Pro pilot +
  Fugu-reported reference + server-authored honest caveats. No upstream forward.
- snapshot: refresh ensodata/summary.json to the full measured set (LCB+GPQA+HLE,
  6 arms), ultra_ablation, and the committed agentic result folded in.
- frontend: EnsoBenchmarkPanel (admin-only; adminOnlyState when not admin) +
  services/enso-benchmarks.ts (bearer, 403->null). Registered in the admin-only
  Cloud panels. Theme-safe tables, scroll-in-box, no body h-scroll.
- privacy: no competitor names, arm ids, numbers, or our routing methodology
  names are baked into the public bundle — all arrive only via the gated endpoint.

Honest framing: enso MATCHES the best single SOTA arm at a fraction of the cost
(LCB 91.4% @ $5.24 vs opus $39.43; GPQA ties top); does NOT beat every SOTA;
HLE is preflight-only; we are below Fugu's REPORTED numbers. Decisive wins are
cost-efficiency, the ablation (better AND cheaper), and agentic step-routing.

Tests: gate matrix (anon 401 / non-admin 403 / admin 200 + no-leak) + real-number
payload assertions green; existing enso-training + red admin-gate suites green.
2026-07-17 21:41:55 -07:00
hanzo-dev 5d1c6fff5d fix(world): smooth fine 16px panel resize — no coarse jump, no min-height trap
Vertical resize snapped in coarse 200px tiers (120/200/400/600/800) and a hard
200px min-height blocked shrinking — the 'jump too much / can't fit content'
complaint. Now the grid is a fine 16px row unit (@hanzo/gui space-4): per-panel
resize snaps in ~20px steps, uncapped, and min-height drops to 48px so 200px is
just the DEFAULT for a new panel, not a floor. Tier presets (size menu + map) are
redefined on the same grid so they still work; the map resizes smoothly too.
Horizontal already fills width in 160px column steps.
2026-07-17 21:08:08 -07:00
hanzo-dev 84995c9ac1 fix(world): Model Usage never shows opaque arm-N — real model names or 'warming up'
The public router-stats by_model is relabeled to opaque arm-N ids on platform
scope (privacy), so it is NOT real model names. cloud-pulse wrongly surfaced it
as the model mix, so Model Usage showed 'arm-8, arm-7, arm-6'. Now the public
fallback carries real request rate + throughput only; the model mix comes solely
from the measured usage ledger (admin path) — otherwise Models stays empty and
the panel honestly shows 'warming up'.
2026-07-17 19:40:28 -07:00
hanzo-dev 4a269d65d4 feat: migrate SQLite driver to hanzoai/sqlite drop-in 2026-07-17 12:25:19 -07:00
hanzo-dev 768a0c6bf8 fix(world): cloud-pulse shows ALL real regions, not just the 8-city catalog
The region breakdown dropped any machine whose region wasn't one of the 8
catalog cities (real DO regions like tor1, or GCP/AWS regions), so a fleet in
uncatalogued regions rendered regions:0. Now every real region is counted —
catalog coords/name when known, else the raw region string as its own region.
2026-07-17 12:21:56 -07:00
hanzo-dev 06417f4243 feat(world): fleet drill-down — real DO nodes by region + BYO GPU specs; drop last demo fallbacks
Fleet & GPUs now shows every real machine grouped by provider/region (with GPU
model, VRAM, vCPU, OS) plus BYO GPU workers with specs (Spark/Evo/dbc: hostname,
GPU, VRAM, capabilities) — one shared renderer (cloud-fleet-view) used by both
FleetPanel (flagship, admin) and CloudFleetPanel (deep). Backend adds vCPU from
visor MachineView.

Removes the last fabricated data: byo-gpu and traffic map layers are now
real-or-empty (no demoGPUs / demoTraffic), so a signed-out visitor sees honest
empty globe layers, never fake clusters/arcs.
2026-07-17 12:18:59 -07:00
hanzo-dev 7e41959b01 feat(world): real user + signup metrics from IAM global-users
Wires the one signups/growth gap that has a real source: IAM /v1/iam/global-users
(all users, global-admin only), read with the signed-in admin's OWN bearer and
folded into AGGREGATES ONLY (never PII): total users, signups 24h/7d, active-now
(isOnline), and a 14-day daily-signup series (from each user's createdTime).
Attached to the cloud-pulse admin path only (p.users, omitempty — the public
teaser never carries it). CloudOverviewPanel renders users / +N signups·24h /
active-now tiles + a new-users sparkline, live at the 30s poll.

Remaining gaps stay honestly empty — they have NO upstream source (verified against
the visor/o11y OpenAPI specs): GPU util/mem/temp (visor GpuView: "Live telemetry is
omitted"), disk (no field), historical retention cohorts (no login-events store).
Those need real instrumentation upstream, never faked.

go build/vet/test green (TestCloudPulseAdminBearer extended); tsc + vite clean.
App.ts untouched.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-17 11:56:57 -07:00
hanzo-dev c7d3d11579 feat(world): real fleet + GPU globe + AI compute — whole Cloud tab admin-aware
Completes the "make it all real" pass on the cloud flagship:
- FleetPanel shows the REAL platform fleet (visor /v1/world/cloud/fleet) for an
  admin — machines + GPUs across DO/GCP/AWS/BYO, rolled up by region, 30s refresh.
  Removed the demo/sample-region fallback — never fabricates regions now.
- Globe BYO-GPU layer real for admins (handleCloudBYOGPU, caller bearer, no-store)
  — real GPU clusters instead of the 8 demoGPUs dots. Anonymous keeps the
  clearly-flagged demo sample (no public GPU inventory source).
- AiComputePanel: ai-pulse admin-aware; EventSource can't send a bearer, so the
  panel uses an authenticated poll when signed in — z@hanzo.ai gets the full
  measured compute pulse (tokens/s, req/s, spend, top models, fleet), own bearer.

Every admin/authed response is Vary: Authorization + private,no-store. Honest gaps
stay labeled (GPU util/mem/temp, disk, signups/cohorts need real collection
upstream). go build/vet/test green (TestBYOGPUAdminReal, TestAIPulseAdminPoll);
tsc + vite clean. App.ts untouched.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-17 10:59:07 -07:00
hanzo-dev 99bd0d71ac feat(world): admin-aware cloud-pulse — signed-in admin sees full real all-org data
cloud-pulse never looked at who was logged in (server service-token only), and the
real admin panels were gated to orgs {admin, built-in} — so z@hanzo.ai (org hanzo)
got 403 and saw only the public aggregate. Now:

- cloud-pulse is admin-aware (handlers_cloud.go): a signed-in admin's request is
  served the FULL measured all-org aggregate fetched with THEIR OWN bearer
  (get-cloud-usages?org=all + visor), Cache-Control: private,no-store + Vary:
  Authorization so it never mixes with the public edge cache. No server-side
  super-admin token needed — the admin's own login drives it. The ai gateway
  independently re-checks ?org=all, so a non-global-admin degrades to real public
  data, never fake (gateway is authoritative).
- Operator org recognized as admin (cloud_identity.go): {admin, built-in} +
  operator org (default hanzo, override WORLD_ADMIN_ORGS) — unlocks the existing
  real admin panels (services/llm/fleet/analytics) for z@hanzo.ai. Anonymous
  short-circuits, so the public path stays cheap.
- Frontend forwards the bearer (cloud-pulse.ts) and the client admin gate
  (iam.ts isAdmin/cachedIsAdmin) matches the server, so App.ts's existing
  isAdmin() reveal works — App.ts untouched.

go build/vet/test green (added TestCloudPulseAdminBearer); tsc + vite clean.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-17 10:24:34 -07:00
hanzo-dev 3c95187c8e fix(world): kill fabricated cloud metrics — real sources or honest-empty
The flagship cloud dashboard showed modeled numbers under a "live" badge:
demoPulse() sine-wave rps/24h/tokens + sparklines, demoModels() mix, demoRegions()
per-city rates, and a hardcoded 99.98% uptime. Replaced with an honest source
ladder (producePulse in handlers_cloud.go):
  - RequestsPerSec  <- /v1/traffic/globe totals.rps_1m (the real ~0.62)
  - Requests24h + sparkline <- /v1/router/stats?scope=platform
  - Models mix <- ledger byModel (super-admin) else router-stats by_model
  - UptimePct <- status.hanzo.ai Gatus up/total (0 -> tile dropped, never a const)
  - Regions <- real visor fleet
Tokens24h/TokenSeries have no non-ledger source -> honest 0/empty, volumeModeled
stays true (UI renders "—"). demo:true now means only "nothing measured yet".

Frontend (CloudOverview/LiveActivity/ModelUsage) keys the live badge on
!demo && !volumeModeled — no modeled number wears a live badge; LiveActivity
regions show real visor node counts. TrafficGlobe filters garbage country codes
to ISO-3166. Dead admin-panel gate fixed (mountAdminCloudPanels !== 'saas' ->
'cloud', so Cloud Fleet + LLM panels mount for admins).

Full all-org volume + per-model tokens need a super-admin HANZO_CLOUD_PULSE_TOKEN
in KMS; until then honestly blank. go build/vet/test green; tsc + vite clean.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-17 01:27:05 -07:00
hanzo-dev 32da053f28 feat(world): tab order Cloud·AI·Crypto·Finance·Tech·World, Title-case labels, SVG icons
- Header tabs reordered to Cloud, AI, Crypto, Finance, Tech, World (World last).
- Tab + status labels Title-case, not ALL CAPS (World/Crypto/Finance/Tech/Live;
  AI kept as the acronym) across en + nl.
- Export (⬇) and historical-playback ( ⏮ ◀ ▶ ⏭) emoji replaced with clean
  16px stroke SVGs matching the header's search/theme icons.

tsc clean.

Claude-Session: https://claude.ai/code/session_01SpMZ69ur3tjAXCiwaa7Wv2
2026-07-17 00:49:28 -07:00
06ff53615b feat(cloud): Cloud flagship view — H-merge + CLOUD tab, in-map controls, flicker fix, flywheel panels (#12)
* feat(cloud): Cloud-view polish — compact H + CLOUD tab, in-map controls, flywheel history, accurate legend

- Header: merge the redundant H-icon + "Hanzo" wordmark into one compact (16px)
  canonical H mark (brand/home toggle); rename the flagship tab "Hanzo" → "Cloud"
  (switcher: [Cloud | World | AI | Crypto | Finance | Tech]). Canonical variant id
  renamed hanzo → cloud, with hanzo + saas kept as runtime aliases (links + stored
  prefs keep working).
- Controls: dock the 2D/3D toggle, basemap switcher and time-range pills IN the map
  (controlsHost = map) alongside the zoom, layer toggles and legend that already
  overlay it, instead of floating them in the bottom toolbar; time pills move to the
  bottom-left so they clear the top-left layer toggles; the empty dock slot collapses.
- Flywheel history: a same-origin GET /v1/world/cloud/router-history proxy (→ ai's
  public /v1/router/history?scope=platform; honest empty, never demo) + a Model
  Improvement panel — reward-rate line chart with retrain-version markers, a ticking
  cumulative cost-saved hero, and an adoption sparkline. Charts start empty and GROW
  with real data; nothing is seeded.
- Legend: add a Cloud data-class legend (request origin·volume, validator node, GPU
  fleet, cloud region, datacenter) so it matches what the globe plots rather than the
  geopolitical default.

tsc + vite build clean; world Go build + gofmt clean.

Claude-Session: https://claude.ai/code/session_015Z1iLf7QBrq1LhignJrzDw

* fix(cloud): kill the 3D-globe flicker — settle the globe, guard the cables layer

Root cause (per a deep read-only diagnosis): the 3D globe is a custom GlobeNative
deck.gl renderer whose idle auto-rotate (~2°/s) keeps thin coplanar on-sphere vector
features (borders/coastlines/markers) perpetually sub-pixel-moving, re-rasterized
every frame — steady-state limb shimmer on real GPUs. Fixes:

- GlobeNative created with autoRotate:false — the globe SETTLES, so the deck render
  loop idles (verified: camera longitude does not drift and renders drop from ~40/s
  to a couple of data-sync ticks). Drag-to-rotate still works; re-enable the idle spin
  only with a coplanar depth/polygonOffset fix so it no longer z-fights the sphere.
- Guard createCablesLayer: filter UNDERSEA_CABLES to paths with >=2 finite [lon,lat]
  vertices, so one malformed cable can no longer make the PathLayer assert at init and
  silently drop the whole layer (the "[GlobeNative] cables-layer assertion").
- Cables OFF in the Cloud view (not a Hanzo Cloud data class; absent from the Cloud
  legend) so the globe stays to the plotted classes and the legend matches exactly.

Playwright: a new cloud-mode test asserts the 3D globe settles (lonDelta<0.001,
renders<12), the legend shows the Cloud classes (not the geopolitical default), and no
cables assertion fires. tsc + the full cloud-mode suite green.

Claude-Session: https://claude.ai/code/session_015Z1iLf7QBrq1LhignJrzDw

* feat(cloud): CLOUD variant rename, compact H, in-map controls, flywheel panel + proxy

Completes the Cloud-view content (the prior checkpoint captured only the file renames):

- variant.ts: canonical variant renamed hanzo → cloud, with hanzo + saas as runtime
  aliases; host-default cloud on world.hanzo.ai. isHanzoBrandHost gates the brand.
- App.ts: header merges the redundant H-icon + wordmark into one compact 16px
  canonical H (brand/home toggle); first tab renamed Hanzo → ☁️ Cloud; createPanels
  wires the cloud panel set incl. the Model Improvement panel; controlsHost = the map
  so the 2D/3D toggle + basemap + time pills dock IN the map cluster.
- ModelImprovementPanel + router-history service + /v1/world/cloud/router-history
  proxy: the flywheel-over-time story (reward-rate line + retrain markers, ticking
  cost-saved hero, adoption sparkline) — honest empty until the ledger fills.
- variants/cloud.ts (mirror) + saas.ts alias; flywheel + in-map-controls CSS.

tsc + vite build clean.

Claude-Session: https://claude.ai/code/session_015Z1iLf7QBrq1LhignJrzDw

* feat(cloud): regional activity — traffic-origin tooltip shows task mix + volume

Hover a traffic origin on the globe (or flat map) → its request volume + the router
task mix (code/reasoning/chat/vision — what customers there are DOING), falling back
to the coarse service class until the per-geo byTask recording lands. Uses the new
TrafficGlobePoint.byTask from /v1/traffic/globe. Works in both 2D and 3D (GlobeNative
delegates tooltips to this handler).

Claude-Session: https://claude.ai/code/session_015Z1iLf7QBrq1LhignJrzDw

---------

Co-authored-by: hanzo-dev <dev@hanzo.ai>
2026-07-16 20:13:22 -07:00
Hanzo Dev 5f0857d8f8 chore(notice): pin upstream provenance and deviations; sweep product branding 2026-07-13 16:12:09 -07:00
328 changed files with 49206 additions and 6027 deletions
+30
View File
@@ -0,0 +1,30 @@
# Build the image from source only — never copy host-built artifacts or deps.
#
# The web stage runs `npm ci` + `npm run build` itself and the go stage copies
# go.mod/cmd/internal explicitly (see Dockerfile), so the host must NOT ship its
# own node_modules/dist into the context: at `COPY . .` a host node_modules
# clobbers the image's fresh `npm ci` tree and poisons BuildKit's node_modules
# cache-mount ("cannot replace directory with file"), which breaks every build.
node_modules
**/node_modules
dist
**/dist
build
out
.next
.git
.gitignore
.github
*.log
npm-debug.log*
.env
.env.*
!.env.example
.DS_Store
.vscode
.idea
coverage
*.tsbuildinfo
+16
View File
@@ -109,6 +109,22 @@ VITE_WS_RELAY_URL=
# WORLDPOP_API_KEY=
# ------ Telemetry (Hanzo Cloud — @hanzo/event) ------
# Telemetry (pageviews, product events, errors) posts to api.hanzo.ai/v1/event,
# fanned server-side into web analytics, product analytics, and error tracking.
# Signed-in visitors are attributed by their IAM bearer automatically. To also
# accept LOGGED-OUT / anonymous traffic on the fail-closed door, ship a write-only
# publishable ingest key (pk_live_…). It is safe to bundle (cannot read, only
# ingest). Mint one per org via POST /v1/ingest/keys. Absent → anonymous events
# are best-effort (dropped by the door unless it allows unauthenticated ingest).
VITE_HANZO_INGEST_KEY=
# Google Tag Manager container id (marketing tags — GA / ad pixels). Orthogonal
# to the telemetry above; no-op until provisioned from KMS.
# VITE_GTM_ID=
# ------ Site Configuration ------
# Site variant: "full" (worldmonitor.app) or "tech" (tech.worldmonitor.app)
+44
View File
@@ -0,0 +1,44 @@
name: Sync to git.hanzo.ai
# hanzoai/world is NATIVE on git.hanzo.ai (hanzoai/git) — canonical repo + where CI/CD
# runs: build/test/release from .hanzo/workflows/ on the Hanzo git-runner. GitHub is the
# DOWNSTREAM MIRROR. The mirror App already syncs on push; this is the explicit,
# self-documenting belt-and-suspenders — its presence in .github/ signals
# "this repo migrated to git.hanzo.ai."
#
# IDEMPOTENT: mirror-sync just tells Gitea to pull HEAD, so N nudges == 1 (same latest
# state); concurrency coalesces a burst of pushes to a single in-flight sync. FAST: no
# checkout, one bounded curl, hard timeouts. FAIL-SOFT: a missing token or hiccup never
# fails the push (the App webhook still mirrors). Set HANZO_GIT_TOKEN to enable the nudge.
on:
push:
branches: [main]
workflow_dispatch:
# Only the newest push's sync needs to run — cancel any older in-flight one (it would
# pull a now-stale HEAD). This is what makes rapid pushes idempotent + cheap.
concurrency:
group: sync-git-hanzo-ai
cancel-in-progress: true
jobs:
sync:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Nudge git.hanzo.ai to pull HEAD (mirror-sync)
continue-on-error: true
env:
HANZO_GIT_TOKEN: ${{ secrets.HANZO_GIT_TOKEN }}
run: |
set -u
if [ -z "${HANZO_GIT_TOKEN:-}" ]; then
echo "HANZO_GIT_TOKEN not set — relying on the mirror App webhook. Skipping nudge."
exit 0
fi
if curl -fsS --max-time 20 --retry 2 --retry-delay 2 -X POST \
-H "Authorization: token ${HANZO_GIT_TOKEN}" \
"https://git.hanzo.ai/api/v1/repos/hanzoai/world/mirror-sync"; then
echo "git.hanzo.ai mirror-sync triggered"
else
echo "mirror-sync nudge failed (non-fatal) — the App webhook still mirrors"
fi
+116
View File
@@ -0,0 +1,116 @@
name: Release
# Cuts a release of ghcr.io/hanzoai/world — the static SPA frontend image (Vite ->
# hanzoai/static) the operator CR pins. Mirrors hanzoai/app/release.yml:
# a git tag v<X.Y.Z> ⇔ an image ghcr.io/hanzoai/world:v<X.Y.Z>
# Builds on the git.hanzo.ai native runner (git-runner). ghcr auth via GH_PAT / user
# hanzo-dev.
#
# ADDITIVE MIGRATION NOTE: the legacy .github lane (docker-build.yml) does NOT cut
# v-tags — it only REACTS to `tags: ['v*']` to build+deploy. So there is no
# competing tag-cutter and no version runaway. paths-ignore below keeps this native
# release from re-firing on .github/** or doc-only edits.
on:
push:
branches: [main]
# Workflow/doc-only edits must NOT cut a release. Real code changes on main still
# trigger; use workflow_dispatch to force.
paths-ignore:
- '.github/**'
- '**.md'
workflow_dispatch:
permissions:
contents: write
packages: write
id-token: write
concurrency:
group: release-world
cancel-in-progress: false
jobs:
build-amd64:
runs-on: [hanzo-build-linux-amd64]
steps:
- name: Checkout (full history + tags — version floor read from tags)
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Compute next version (monotonic patch bump over the 2.4.x deploy line)
id: ver
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
set -euo pipefail
git fetch --tags --force --quiet
# The deployed lineage is 2.4.x: the newest-by-date tags on main are v2.4.48,
# v2.4.47, ... (HEAD is "release: v2.4.48") and every recent release commit is
# on it. Stray tags exist off that line — notably v2.9.32 (a July-9 relic,
# numerically largest but OLDER than the active 2.4 stream) and the 2.5.x
# cluster. `sort -V` is purely numeric, so an UNCONSTRAINED scan lets the
# v2.9.32 orphan hijack the floor and cut a v2.9.33 the deploy stream can't
# follow. Pin the scan to the 2.4. line so the bump stays monotonic over the
# ACTUAL deploy stream, not the numerically-largest orphan tag.
LINE='2.4.'
git_max="$(git tag -l "v${LINE}[0-9]*" \
| sed 's/^v//' | grep -E "^${LINE//./\\.}[0-9]+$" | sort -V | tail -1 || true)"
# Fold in ALREADY-PUSHED container tags on the same line, so a number that has
# an image (even from a run that died before git-tagging) is never reused.
# Best-effort — never fails the run if the API is down. Use curl (universally
# present) NOT gh. Fold BOTH v-prefixed and legacy non-v 2.9.x image tags.
cont_max=""
if [ -n "${GH_PAT:-}" ]; then
_pkgjson="$(curl -fsSL -H "Authorization: Bearer $GH_PAT" \
-H "Accept: application/vnd.github+json" \
'https://api.github.com/orgs/hanzoai/packages/container/world/versions?per_page=100' 2>/dev/null || true)"
cont_max="$(printf '%s' "$_pkgjson" \
| { jq -r '.[].metadata.container.tags[]?' 2>/dev/null || grep -oE '"v?[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"'; } \
| sed 's/^v//' | grep -E "^${LINE//./\\.}[0-9]+$" | sort -V | tail -1 || true)"
fi
max="$(printf '%s\n%s\n%s\n' "${LINE}0" "$git_max" "$cont_max" \
| grep -E "^${LINE//./\\.}[0-9]+$" | sort -V | tail -1)"
major="${max%%.*}"; rest="${max#*.}"; minor="${rest%%.*}"; patch="${rest##*.}"
version="${major}.${minor}.$((patch + 1))"
if git rev-parse -q --verify "refs/tags/v${version}" >/dev/null; then
echo "::error::computed v${version} already exists — aborting to avoid collision"; exit 1
fi
echo "version_v=v${version}" >> "$GITHUB_OUTPUT"
echo "Next release: v${version} (git_max='${git_max:-none}' container_max='${cont_max:-none}')"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
driver-opts: network=host
- name: Log in to ghcr.io (GH_PAT, write:packages)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: hanzo-dev
password: ${{ secrets.GH_PAT }}
- name: Build + push ghcr.io/hanzoai/world
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: ghcr.io/hanzoai/world:${{ steps.ver.outputs.version_v }}
provenance: false
- name: Verify the pushed image is pullable (guard the image ⇔ tag invariant)
# build-push-action can exit 0 while the manifest isn't yet resolvable at the
# registry. Prove the image resolves BEFORE creating the git tag, so a bad push
# fails the run instead of leaving a phantom tag → ImagePullBackOff.
run: |
set -euo pipefail
v="${{ steps.ver.outputs.version_v }}"
for i in 1 2 3 4 5 6; do
if docker manifest inspect "ghcr.io/hanzoai/world:${v}" >/dev/null 2>&1; then
echo "image ${v} is resolvable — safe to tag"; exit 0
fi
echo "ghcr manifest ${v} not visible yet (attempt ${i}/6) — retrying"; sleep 5
done
echo "::error::image ${v} not pullable after push — refusing to tag git (prevents ImagePullBackOff)"; exit 1
- name: Tag the release (image ⇔ tag invariant)
run: |
set -euo pipefail
git tag "${{ steps.ver.outputs.version_v }}"
git push origin "${{ steps.ver.outputs.version_v }}"
echo "Pushed image + tag ${{ steps.ver.outputs.version_v }} — bump the operator CR to deploy."
+45
View File
@@ -0,0 +1,45 @@
# Hanzo World — agent guide
Vite + TypeScript SPA (`world-monitor`). Real-time global-intelligence dashboard
served at `world.hanzo.ai`, shipped by `hanzo.yml` CI/CD onto the `world`
operator Service CR. Same-origin data plane under `/v1/world/*`.
## Browser control — prefer the Hanzo MCP extension over Playwright
When the **Hanzo browser MCP** (the `mcp__hanzo__browser` / `mcp__claude-in-chrome__*`
tools, backed by the local extension in `~/work/hanzo/extension`) is available,
use it by default to drive a real browser for interactive UI work — inspecting
the globe, tweaking layers, checking live feeds, capturing screenshots against a
running dev server. It talks to a real Chrome/Firefox with the real WebGL/deck.gl
context, so what you see is what a user sees.
Fall back to **Playwright only when** the MCP extension is not connected, or for
the deterministic **e2e suite** (`e2e/*.spec.ts`) — those run headless in CI with
mocked `/v1/world/cloud/*` feeds and must stay reproducible offline. E2e is not
interactive editing; keep the two lanes separate.
Order of preference for "look at / poke the UI": Hanzo MCP browser → Playwright.
## The map / globe
- Basemaps: `dark` · `dot` · `satellite` · `terrain`. **`dot` is the default**
for every variant (`DEFAULT_BASEMAP_STYLE` in `src/config/variant.ts`) — the
Kaspersky-style cybermap: land drawn only as a glowing dot-lattice over a black
ocean sphere, no country fills/borders/imagery.
- The lattice is one pure value — `getLandDots()` in `src/services/land-dots.ts`
consumed by BOTH the 2D mercator map (`DeckGLMap`) and the 3D globe
(`GlobeNative`). One source, two projections. Don't fork it.
- Cloud view layers (default-on, `?variant=cloud`): live request-origin dots +
animated traffic arcs (`AnimatedArcLayer`, a travelling pulse advanced on RAF),
validator chain-nodes, BYO-GPU rings, datacenter clusters. Feeds are best-effort
and degrade to honest empty states — never fabricate volume.
- `satellite`/`terrain` need `VITE_MAPBOX_TOKEN` (from KMS `hanzo/deploy/`, never
in git); `dark`/`dot` are keyless CartoDB.
## Release
Bump `package.json` PATCH (x.y.z → x.y.z+1, never a lazy major), tag `v<version>`,
`workflow_dispatch` the `cicd` workflow. The image tag is the version WITHOUT the
`v`. CI's "Deploy" step can false-negative while the operator finishes rolling —
verify the live version, not just the CI square. Test/doc-only changes need no
release (the image is byte-identical).
+33
View File
@@ -2,6 +2,39 @@
All notable changes to World Monitor are documented here.
## [2.4.43]
### Added
- **Finance-terminal alt-asset feeds are live** (`?variant=finance`). The "Art & Collectibles — Auctions" and "Luxury Real Estate" panels now render REAL data instead of "live feed pending":
- `GET /v1/world/auctions` — Christie's public auction results (realized **sale totals**: title, inferred category, price + currency, sale date, location, image, link). Sotheby's gates realized prices behind a login (its sale-results API returns `401 Not signed in`), so the honest public major house is the source.
- `GET /v1/world/luxury-realestate` — LuxuryEstate.com luxury listings (title, location, price + currency, type, image, link). JamesEdition sits behind a Cloudflare JS challenge that blocks datacenter egress, so it cannot be fetched from the pod.
- Both are scraped server-side (`internal/world/handlers_altassets.go`) at most **once an hour** and served from cache to every caller (respectful). On a source failure the last-good copy is served; with no cache yet, an honest empty `{items:[]}` (the panel shows "live feed pending") — **never fabricated data**. The payload attributes its source per feed.
## [2.4.19]
### Fixed
- **Moving/resizing a panel no longer shifts the others** (the "when I shift the 3D map it shifts all other components" report). The dashboard now DEFAULTS to the free layout: every panel owns its own {x,y,w,h}, so a drag or resize leaves every sibling exactly where it was — no more grid reflow. The switch is invisible: the current grid arrangement is frozen as the starting geometry (`grid-config.applyDefaultLayout`), and Grid stays one dropdown-click away for anyone who wants snap-to-grid back.
- **Panels resize granularly** — pixel-exact width AND height from any edge or corner, instead of jumping between coarse column/row spans.
- **Panels can be made much narrower/smaller** ("constrained on min width"): the free-mode floors drop to 96×40px (map 140px), and the grid widget-size slider now reaches a 120px column track (was 140).
### Changed
- A panel shown from the Panels menu / "+ Add widget" while in free mode seeds a tidy default slot below the placed panels (never a full-width block under its absolute siblings). Hidden panels no longer persist 0×0 geometry.
## [2.4.13]
### Fixed
- **Globe overlays now sit ON the sphere with correct occlusion** (the "map spazzes" report). On the native deck.gl GlobeView, data layers (shared with the 2D map) carried no depth parameters, so the far hemisphere showed through and count badges floated above the limb. GlobeNative now seats every data layer against the depth-writing ocean sphere (test, don't write — no inter-marker z-fight), and the far-side billboard cull (`occludeFarSide`) faces the globe's OWN live camera instead of the parked (frozen) mapbox center — extended to `TextLayer` so a back-side "36" count badge disappears instead of hovering over the planet.
- **Terrain striping on the globe**: the draped ESRI imagery tiles each wrote depth, so coplanar neighbours z-fought at the tile seams (horizontal stripes / partial render). Tiles now depth-TEST only; the ocean sphere owns the depth buffer.
- **Live request-geo dots kept polling on the 3D globe**: the `/v1/world/cloud/*` poll was gated on `renderPaused`, which the native GlobeView sets on activation — so the realtime dots froze the moment you entered the default 3D view. It now gates on tab visibility, so the dots stay live (and fade) on the globe.
### Changed
- **Request-origin → serving-region arcs on by default** in the Cloud view: the `/cloud/traffic` arcs derive from the same real native request-geo points as the dots (origin country → nearest Hanzo region) and degrade to empty — never demo.
## [2.4.6]
### Added
+18 -5
View File
@@ -37,17 +37,30 @@ ENV VITE_MAPBOX_TOKEN=$VITE_MAPBOX_TOKEN
RUN npm run build
# ---- go stage: build the static server binary (CGO-free) -----------------
# go 1.25: the embedded datastore (modernc.org/sqlite, pure Go) needs it. The
# binary stays CGO-free — modernc's SQLite is pure Go, so no C toolchain is added.
FROM golang:1.25-alpine AS gobuild
# go 1.26: go.mod requires >= 1.26.4 (github.com/hanzoai/sqlite drop-in). The
# binary stays CGO-free — with CGO_ENABLED=0, hanzoai/sqlite selects its vendored
# pure-Go engine (zero modernc.org/* in the module graph). That engine gates FTS5
# behind the `sqlite_fts5` build tag, which the store's items_fts virtual table
# needs — so the build below MUST carry `-tags sqlite_fts5` or Open degrades.
FROM golang:1.26-alpine AS gobuild
WORKDIR /src
# git: go resolves the PRIVATE indirect dep github.com/hanzoai/csqlite 'direct'
# (not via the module proxy), which needs the git binary + an https credential.
# alpine ships neither, so add git and mount the gh_token BuildKit secret that
# hanzoai/ci passes (--secret id=gh_token); the mount is a no-op for public builds.
RUN apk add --no-cache git
ENV GOPRIVATE=github.com/hanzoai,github.com/luxfi,github.com/zooai
# Deps: hanzo-kv client (go-redis) + embedded SQLite (modernc). Download once for
# a cached layer before the source is copied.
COPY go.mod go.sum ./
RUN go mod download
RUN --mount=type=secret,id=gh_token \
if [ -s /run/secrets/gh_token ]; then \
git config --global url."https://x-access-token:$(cat /run/secrets/gh_token)@github.com/".insteadOf "https://github.com/"; \
fi; \
go mod download
COPY cmd ./cmd
COPY internal ./internal
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/world ./cmd/world
RUN CGO_ENABLED=0 GOOS=linux go build -tags sqlite_fts5 -trimpath -ldflags="-s -w" -o /out/world ./cmd/world
# ---- final stage: minimal image running the Go binary --------------------
FROM alpine:3.20
+1 -1
View File
@@ -1,7 +1,7 @@
MIT License
Copyright (c) 2024-2026 Elie Habib
Copyright (c) 2026 Hanzo AI
Copyright (c) 2026 Hanzo AI, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+25 -2
View File
@@ -1,8 +1,31 @@
World Monitor — Hanzo fork
Copyright (c) 2026 Hanzo AI. Licensed under the MIT License (see LICENSE).
Hanzo World — Hanzo fork
Copyright (c) 2026 Hanzo AI, Inc. Licensed under the MIT License (see LICENSE).
Forked from koala73/worldmonitor (https://github.com/koala73/worldmonitor) at
v2.4.0 (commit 572f3808) — the last release under the MIT License. This fork
tracks only the MIT-era code and develops forward independently.
Original work © 2024-2026 Elie Habib, used under the MIT License.
DEVIATIONS
Changes made by Hanzo AI, Inc. relative to the upstream v2.4.0 baseline:
- Rebranded the product to "Hanzo World": index.html <title>/meta/OpenGraph,
the vite.config full variant (siteName "Hanzo World"), and canonical host
world.hanzo.ai.
- Added a single Go binary (cmd/world, internal/world; go.mod module
github.com/hanzoai/world) that serves the Vite SPA with SPA fallback AND
ports each upstream Vercel edge function to same-origin /v1/world/* (and
legacy /api/*) in Go. Upstream shipped a Vite SPA plus Vercel edge functions.
- Added Hanzo deploy variants beyond upstream full/tech/finance:
src/config/variants/saas.ts (Hanzo Cloud platform metrics/usage), ai.ts, and
crypto.ts, with matching vite.config entries.
- Added Hanzo CI/CD manifest hanzo.yml: image ghcr.io/hanzoai/world built via
hanzoai/ci, rolled onto the "world" operator Service CR on DOKS
do-sfo3-hanzo-k8s, with secrets fetched from KMS (kms.hanzo.ai).
- Reworked Dockerfile to build the Go binary serving the SPA plus the API
endpoints (replacing the static-only image), built on Hanzo hardware
(platform.hanzo.ai / on-cluster BuildKit) rather than GitHub builders.
- Rebranded package.json (name @hanzo/world, added description) and the
primary Tauri desktop app (productName and window title "Hanzo World").
- Added Copyright (c) 2026 Hanzo AI, Inc. to LICENSE alongside the original.
+14 -12
View File
@@ -1,18 +1,20 @@
<p align="center"><img src=".github/hero.svg" alt="world" width="880"></p>
# World Monitor
# Hanzo World
**Real-time global intelligence dashboard** — AI-powered news aggregation, geopolitical monitoring, and infrastructure tracking in a unified situational awareness interface.
[![GitHub stars](https://img.shields.io/github/stars/koala73/worldmonitor?style=social)](https://github.com/koala73/worldmonitor/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/koala73/worldmonitor?style=social)](https://github.com/koala73/worldmonitor/network/members)
> Hanzo World is Hanzo AI, Inc.'s fork of [World Monitor](https://github.com/koala73/worldmonitor) (MIT) by Elie Habib. See [NOTICE](./NOTICE) for provenance and deviations.
[![GitHub stars](https://img.shields.io/github/stars/hanzoai/world?style=social)](https://github.com/hanzoai/world/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/hanzoai/world?style=social)](https://github.com/hanzoai/world/network/members)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
[![Last commit](https://img.shields.io/github/last-commit/koala73/worldmonitor)](https://github.com/koala73/worldmonitor/commits/main)
[![Latest release](https://img.shields.io/github/v/release/koala73/worldmonitor?style=flat)](https://github.com/koala73/worldmonitor/releases/latest)
[![Last commit](https://img.shields.io/github/last-commit/hanzoai/world)](https://github.com/hanzoai/world/commits/main)
[![Latest release](https://img.shields.io/github/v/release/hanzoai/world?style=flat)](https://github.com/hanzoai/world/releases/latest)
<p align="center">
<a href="https://worldmonitor.app"><img src="https://img.shields.io/badge/Web_App-worldmonitor.app-blue?style=for-the-badge&logo=googlechrome&logoColor=white" alt="Web App"></a>&nbsp;
<a href="https://world.hanzo.ai"><img src="https://img.shields.io/badge/Web_App-world.hanzo.ai-blue?style=for-the-badge&logo=googlechrome&logoColor=white" alt="Web App"></a>&nbsp;
<a href="https://tech.worldmonitor.app"><img src="https://img.shields.io/badge/Tech_Variant-tech.worldmonitor.app-0891b2?style=for-the-badge&logo=googlechrome&logoColor=white" alt="Tech Variant"></a>&nbsp;
<a href="https://finance.worldmonitor.app"><img src="https://img.shields.io/badge/Finance_Variant-finance.worldmonitor.app-059669?style=for-the-badge&logo=googlechrome&logoColor=white" alt="Finance Variant"></a>
</p>
@@ -25,14 +27,14 @@
<p align="center">
<a href="./docs/DOCUMENTATION.md"><strong>Full Documentation</strong></a> &nbsp;·&nbsp;
<a href="https://github.com/koala73/worldmonitor/releases/latest"><strong>All Releases</strong></a>
<a href="https://github.com/hanzoai/world/releases/latest"><strong>All Releases</strong></a>
</p>
![World Monitor Dashboard](new-world-monitor.png)
![Hanzo World Dashboard](new-world-monitor.png)
---
## Why World Monitor?
## Why Hanzo World?
| Problem | Solution |
|---------|----------|
@@ -1092,7 +1094,7 @@ See [full roadmap](./docs/DOCUMENTATION.md#roadmap).
## Support the Project
If you find World Monitor useful:
If you find Hanzo World useful:
- **Star this repo** to help others discover it
- **Share** with colleagues interested in OSINT
@@ -1107,9 +1109,9 @@ MIT License — see [LICENSE](LICENSE) for details.
---
## Author
## Authors
**Elie Habib** [GitHub](https://github.com/koala73)
**Hanzo World** is maintained by **Hanzo AI, Inc.** — fork of the original **World Monitor** by **Elie Habib** ([GitHub](https://github.com/koala73)), used under the MIT License. See [NOTICE](./NOTICE).
---
+1 -1
View File
@@ -1 +1 @@
2.4.8
2.4.39
+94
View File
@@ -0,0 +1,94 @@
// Low-end laptop profiler for world.hanzo.ai
// Usage: node profile.mjs <url> <label> [cpuThrottle=6]
// Measures under Chrome DevTools CPU throttling via CDP.
import { chromium } from 'playwright';
const url = process.argv[2] || 'https://world.hanzo.ai/';
const label = process.argv[3] || 'run';
const throttle = Number(process.argv[4] || 6);
const browser = await chromium.launch({ args: ['--enable-precise-memory-info'] });
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
const page = await context.newPage();
// Track network transfer sizes by type
const transfer = { js: 0, css: 0, other: 0, jsCount: 0, eagerJs: 0 };
const seen = new Set();
page.on('response', async (resp) => {
try {
const u = resp.url();
if (seen.has(u)) return; seen.add(u);
const hdr = resp.headers();
const enc = hdr['content-encoding'] || '';
const len = Number(hdr['content-length'] || 0);
const ct = hdr['content-type'] || '';
let bytes = len;
if (!bytes) { try { bytes = (await resp.body()).length; } catch { bytes = 0; } }
if (/javascript/.test(ct) || u.endsWith('.js')) { transfer.js += bytes; transfer.jsCount++; }
else if (/css/.test(ct) || u.endsWith('.css')) { transfer.css += bytes; }
else transfer.other += bytes;
} catch {}
});
const client = await context.newCDPSession(page);
await client.send('Emulation.setCPUThrottlingRate', { rate: throttle });
const t0 = Date.now();
await page.goto(url, { waitUntil: 'commit', timeout: 120000 });
// Inject longtask + paint observers ASAP
await page.addInitScript(() => {
window.__lt = { total: 0, count: 0, max: 0 };
try {
new PerformanceObserver((l) => { for (const e of l.getEntries()) { window.__lt.total += e.duration; window.__lt.count++; window.__lt.max = Math.max(window.__lt.max, e.duration); } }).observe({ entryTypes: ['longtask'] });
} catch {}
});
// Wait for the app shell / map container to exist and network to settle a bit
let ttiApprox = null;
try {
await page.waitForSelector('#app .header, #app .main-content, #mapContainer', { timeout: 60000 });
ttiApprox = Date.now() - t0;
} catch {}
// Let it run to steady state under throttle
await page.waitForTimeout(9000);
// Paint + nav timings
const timings = await page.evaluate(() => {
const nav = performance.getEntriesByType('navigation')[0] || {};
const fcp = (performance.getEntriesByType('paint').find(p => p.name === 'first-contentful-paint') || {}).startTime || null;
return {
domContentLoaded: nav.domContentLoadedEventEnd || null,
loadEvent: nav.loadEventEnd || null,
fcp,
longtasks: window.__lt || null,
scripts: performance.getEntriesByType('resource').filter(r => r.initiatorType === 'script' || /\.js(\?|$)/.test(r.name)).length,
};
});
// FPS sample over 4s (rAF frame deltas) — the idle/spin steady-state frame cost
const fps = await page.evaluate(() => new Promise((resolve) => {
const deltas = []; let last = performance.now(); let frames = 0; const start = last;
function tick(now) { deltas.push(now - last); last = now; frames++; if (now - start < 4000) requestAnimationFrame(tick); else {
deltas.sort((a,b)=>a-b);
const avg = deltas.reduce((a,b)=>a+b,0)/deltas.length;
const p95 = deltas[Math.floor(deltas.length*0.95)] || avg;
resolve({ fps: +(1000/avg).toFixed(1), avgFrameMs: +avg.toFixed(1), p95FrameMs: +p95.toFixed(1), frames });
} }
requestAnimationFrame(tick);
}));
const out = {
label, url, cpuThrottle: throttle,
transferKB: { js: Math.round(transfer.js/1024), css: Math.round(transfer.css/1024), jsFiles: transfer.jsCount },
fcpMs: timings.fcp ? Math.round(timings.fcp) : null,
domContentLoadedMs: timings.domContentLoaded ? Math.round(timings.domContentLoaded) : null,
loadEventMs: timings.loadEvent ? Math.round(timings.loadEvent) : null,
shellVisibleMs: ttiApprox,
longTasks: timings.longtasks,
steadyState: fps,
};
console.log('PROFILE_JSON ' + JSON.stringify(out));
console.log(JSON.stringify(out, null, 2));
await browser.close();
@@ -0,0 +1,53 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"metaTitle": {
"type": "string"
},
"keywords": {
"type": "string"
},
"audience": {
"type": "string"
},
"pubDate": {
"type": "string",
"format": "date-time"
},
"modifiedDate": {
"type": "string",
"format": "date-time"
},
"author": {
"type": "string"
},
"authorUrl": {
"type": "string",
"format": "uri"
},
"authorBio": {
"type": "string"
},
"heroImage": {
"type": "string"
},
"$schema": {
"type": "string"
}
},
"required": [
"title",
"description",
"metaTitle",
"keywords",
"audience",
"pubDate"
]
}
+1
View File
@@ -0,0 +1 @@
export default new Map();
+1
View File
@@ -0,0 +1 @@
export default new Map();
+163
View File
@@ -0,0 +1,163 @@
declare module 'astro:content' {
export interface RenderResult {
Content: import('astro/runtime/server/index.js').AstroComponentFactory;
headings: import('astro').MarkdownHeading[];
remarkPluginFrontmatter: Record<string, any>;
}
interface Render {
'.md': Promise<RenderResult>;
}
export interface RenderedContent {
html: string;
metadata?: {
imagePaths: Array<string>;
[key: string]: unknown;
};
}
type Flatten<T> = T extends { [K: string]: infer U } ? U : never;
export type CollectionKey = keyof DataEntryMap;
export type CollectionEntry<C extends CollectionKey> = Flatten<DataEntryMap[C]>;
type AllValuesOf<T> = T extends any ? T[keyof T] : never;
export type ReferenceDataEntry<
C extends CollectionKey,
E extends keyof DataEntryMap[C] = string,
> = {
collection: C;
id: E;
};
export type ReferenceLiveEntry<C extends keyof LiveContentConfig['collections']> = {
collection: C;
id: string;
};
export function getCollection<C extends keyof DataEntryMap, E extends CollectionEntry<C>>(
collection: C,
filter?: (entry: CollectionEntry<C>) => entry is E,
): Promise<E[]>;
export function getCollection<C extends keyof DataEntryMap>(
collection: C,
filter?: (entry: CollectionEntry<C>) => unknown,
): Promise<CollectionEntry<C>[]>;
export function getLiveCollection<C extends keyof LiveContentConfig['collections']>(
collection: C,
filter?: LiveLoaderCollectionFilterType<C>,
): Promise<
import('astro').LiveDataCollectionResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>
>;
export function getEntry<
C extends keyof DataEntryMap,
E extends keyof DataEntryMap[C] | (string & {}),
>(
entry: ReferenceDataEntry<C, E>,
): E extends keyof DataEntryMap[C]
? Promise<DataEntryMap[C][E]>
: Promise<CollectionEntry<C> | undefined>;
export function getEntry<
C extends keyof DataEntryMap,
E extends keyof DataEntryMap[C] | (string & {}),
>(
collection: C,
id: E,
): E extends keyof DataEntryMap[C]
? string extends keyof DataEntryMap[C]
? Promise<DataEntryMap[C][E]> | undefined
: Promise<DataEntryMap[C][E]>
: Promise<CollectionEntry<C> | undefined>;
export function getLiveEntry<C extends keyof LiveContentConfig['collections']>(
collection: C,
filter: string | LiveLoaderEntryFilterType<C>,
): Promise<import('astro').LiveDataEntryResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>>;
/** Resolve an array of entry references from the same collection */
export function getEntries<C extends keyof DataEntryMap>(
entries: ReferenceDataEntry<C, keyof DataEntryMap[C]>[],
): Promise<CollectionEntry<C>[]>;
export function render<C extends keyof DataEntryMap>(
entry: DataEntryMap[C][string],
): Promise<RenderResult>;
export function reference<
C extends
| keyof DataEntryMap
// Allow generic `string` to avoid excessive type errors in the config
// if `dev` is not running to update as you edit.
// Invalid collection names will be caught at build time.
| (string & {}),
>(
collection: C,
): import('astro/zod').ZodPipe<
import('astro/zod').ZodString,
import('astro/zod').ZodTransform<
C extends keyof DataEntryMap
? {
collection: C;
id: string;
}
: never,
string
>
>;
type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T;
type InferEntrySchema<C extends keyof DataEntryMap> = import('astro/zod').infer<
ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']>
>;
type ExtractLoaderConfig<T> = T extends { loader: infer L } ? L : never;
type InferLoaderSchema<
C extends keyof DataEntryMap,
L = ExtractLoaderConfig<ContentConfig['collections'][C]>,
> = L extends { schema: import('astro/zod').ZodSchema }
? import('astro/zod').infer<L['schema']>
: any;
type DataEntryMap = {
"blog": Record<string, {
id: string;
body?: string;
collection: "blog";
data: InferEntrySchema<"blog">;
rendered?: RenderedContent;
filePath?: string;
}>;
};
type ExtractLoaderTypes<T> = T extends import('astro/loaders').LiveLoader<
infer TData,
infer TEntryFilter,
infer TCollectionFilter,
infer TError
>
? { data: TData; entryFilter: TEntryFilter; collectionFilter: TCollectionFilter; error: TError }
: { data: never; entryFilter: never; collectionFilter: never; error: never };
type ExtractEntryFilterType<T> = ExtractLoaderTypes<T>['entryFilter'];
type ExtractCollectionFilterType<T> = ExtractLoaderTypes<T>['collectionFilter'];
type ExtractErrorType<T> = ExtractLoaderTypes<T>['error'];
type ExtractDataType<T> = ExtractLoaderTypes<T>['data'];
type LiveLoaderDataType<C extends keyof LiveContentConfig['collections']> =
LiveContentConfig['collections'][C]['schema'] extends undefined
? ExtractDataType<LiveContentConfig['collections'][C]['loader']>
: import('astro/zod').infer<
Exclude<LiveContentConfig['collections'][C]['schema'], undefined>
>;
type LiveLoaderEntryFilterType<C extends keyof LiveContentConfig['collections']> =
ExtractEntryFilterType<LiveContentConfig['collections'][C]['loader']>;
type LiveLoaderCollectionFilterType<C extends keyof LiveContentConfig['collections']> =
ExtractCollectionFilterType<LiveContentConfig['collections'][C]['loader']>;
type LiveLoaderErrorType<C extends keyof LiveContentConfig['collections']> = ExtractErrorType<
LiveContentConfig['collections'][C]['loader']
>;
export type ContentConfig = typeof import("../src/content.config.js");
export type LiveContentConfig = never;
}
+2
View File
@@ -0,0 +1,2 @@
/// <reference types="astro/client" />
/// <reference path="content.d.ts" />
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

+2
View File
@@ -49,6 +49,8 @@ func main() {
defer srv.Close() // release hanzo-kv + embedded datastore handles
srv.StartModel(rootCtx) // continuously-folded world-state engine
srv.StartDatastore(rootCtx) // shared feed warmer + lake write-behind/prune
srv.StartFund(rootCtx) // autonomous PAPER-only multi-asset fund brain
srv.StartAltAssets(rootCtx) // hourly Christie's auctions + LuxuryEstate warmer
mux := http.NewServeMux()
srv.Mount(mux) // /v1/world/* routes
+19 -14
View File
@@ -73,12 +73,12 @@ test.describe('AI analyst control surface', () => {
await stubWorldApi(page);
await appReady(page);
await page.click('.ai-dock-fab');
const prompt = page.locator('.ai-dock-body .ai-analyst-signedout');
await page.click('.hzc-fab');
const prompt = page.locator('.hzc-body .hzc-signedout');
await expect(prompt).toBeVisible();
await expect(prompt.locator('.ai-analyst-signin')).toHaveText(/sign in/i);
await expect(prompt.locator('.hzc-signin')).toHaveText(/sign in/i);
// No chat composer for anonymous users.
await expect(page.locator('.ai-dock-body .ai-analyst-input')).toHaveCount(0);
await expect(page.locator('.hzc-body .hzc-input')).toHaveCount(0);
await page.screenshot({ path: `${SCREENS}/analyst-signedout.png` });
});
@@ -93,23 +93,28 @@ test.describe('AI analyst control surface', () => {
expect(beforeIdx).toBeGreaterThan(1); // markets starts well down the grid
await page.screenshot({ path: `${SCREENS}/round-trip-before.png` });
// Open the analyst dock and confirm the model dropdown populated.
await page.click('.ai-dock-fab');
const composer = page.locator('.ai-dock-body .ai-analyst-input');
// Open the analyst dock and confirm the model picker populated.
await page.click('.hzc-fab');
const composer = page.locator('.hzc-body .hzc-input');
await expect(composer).toBeVisible();
const modelSelect = page.locator('.ai-dock-body .ai-analyst-model');
await expect(modelSelect).toBeVisible();
await expect(modelSelect.locator('option')).toHaveCount(3);
await expect(modelSelect).toHaveValue('zen5');
// The model picker is now a pill that opens a popover listbox (portaled to
// <body>), not a native <select>. Its label reflects the default (zen5)…
const modelBtn = page.locator('.hzc-body .hzc-model');
await expect(modelBtn).toBeVisible();
await expect(modelBtn.locator('.hzc-model-name')).toHaveText('Zen 5');
// …and opening it lists all three stubbed models.
await modelBtn.click();
await expect(page.locator('.hzc-model-menu .hzc-model-opt')).toHaveCount(3);
await modelBtn.click(); // close the popover
// Send a command-style message; the stub returns the move+theme commands.
await composer.fill('Move markets to the top and go light');
await page.click('.ai-dock-body .ai-analyst-send');
await page.click('.hzc-body .hzc-send');
// The prose reply renders…
await expect(page.locator('.ai-dock-body .ai-analyst-msg.assistant')).toContainText('moved Markets');
await expect(page.locator('.hzc-body .hzc-row.assistant')).toContainText('moved Markets');
// …and the per-command action log shows a ✓ for the executed move.
const log = page.locator('.ai-dock-body .ai-analyst-actionlog .ai-analyst-action.ok');
const log = page.locator('.hzc-body .hzc-actionlog .hzc-action.ok');
await expect(log.first()).toBeVisible();
await expect(log.first()).toContainText(/moved markets/i);
+137
View File
@@ -0,0 +1,137 @@
import { expect, test } from '@playwright/test';
// SuperAdmin fleet view — the admin-only Cloud console panels on world.hanzo.ai:
// Clusters & Nodes (DOKS nodes per cluster) and GPU Queue (gpu-jobs depth + what
// each worker serves). These prove the CLIENT gate mirrors the server one: the
// panels mount + render live data ONLY for an admin-org owner, and a non-admin
// (org-admin of their own tenant) is DENIED — the panels never mount.
//
// The server independently fail-closes 403 (handlers_cloud_admin_infra_test.go);
// here we drive the real app with the IAM userinfo + the /v1/world/cloud/* reads
// mocked to their real shapes, so the render + gating are exercised end-to-end.
const now = new Date().toISOString();
const CLUSTERS = {
available: true,
updatedAt: now,
note: 'Live DOKS + BYO clusters from visor.',
totals: { clusters: 2, nodes: 5, nodesReady: 4, gpus: 2 },
clusters: [
{
id: 'c-hanzo', name: 'hanzo-k8s', region: 'sfo3', status: 'running', kind: 'managed',
nodes: 3, nodesReady: 2, gpus: 2,
pools: [{ name: 'pool-gpu', size: 'gpu-l40', count: 2, autoScale: true, minNodes: 1, maxNodes: 4 }],
nodeList: [
{ id: 'n1', name: 'hanzo-k8s-1', status: 'active', type: 's-8vcpu-16gb', region: 'sfo3', gpu: '' },
{ id: 'n2', name: 'hanzo-k8s-2', status: 'active', type: 'gpu-l40', region: 'sfo3', gpu: 'L40S' },
{ id: 'n3', name: 'hanzo-k8s-3', status: 'provisioning', type: 'gpu-l40', region: 'sfo3', gpu: 'L40S' },
],
},
{
id: 'c-adnexus', name: 'adnexus-k8s', region: 'sfo3', status: 'running', kind: 'managed',
nodes: 2, nodesReady: 2, gpus: 0, pools: [],
nodeList: [
{ id: 'a1', name: 'adnexus-k8s-1', status: 'active', type: 's-4vcpu-8gb', region: 'sfo3', gpu: '' },
{ id: 'a2', name: 'adnexus-k8s-2', status: 'active', type: 's-4vcpu-8gb', region: 'sfo3', gpu: '' },
],
},
],
};
const QUEUE = {
available: true,
updatedAt: now,
note: 'Live GPU job queue (gpu-jobs).',
namespace: 'gpu-jobs',
depth: { pending: 1, running: 2, done: 1, failed: 1, canceled: 0 },
workers: { online: 2, total: 3 },
services: [
{ service: 'studio', pending: 1, running: 1 },
{ service: 'engine', pending: 0, running: 1 },
],
running: [
{ id: 'job-1', type: 'studio.render', service: 'studio', status: 'running', worker: 'evo', model: 'flux.1', attempt: 1, startedAt: now, closedAt: '' },
{ id: 'job-2', type: 'engine.serve', service: 'engine', status: 'running', worker: 'spark', model: 'qwen3-32b', attempt: 1, startedAt: now, closedAt: '' },
],
pending: [
{ id: 'job-3', type: 'studio.render', service: 'studio', status: 'pending', worker: '', model: 'flux.1', attempt: 0, startedAt: '', closedAt: '' },
],
recent: [
{ id: 'job-4', type: 'echo', service: 'echo', status: 'done', worker: '', model: '', attempt: 1, startedAt: '', closedAt: now },
{ id: 'job-5', type: 'studio.render', service: 'studio', status: 'failed', worker: '', model: '', attempt: 2, startedAt: '', closedAt: now },
],
};
// Seed a live (non-expired) IAM session so getToken()/isAuthenticated() resolve
// without a redirect, then let the userinfo route decide the owner (admin vs not).
async function seedSession(page: import('@playwright/test').Page): Promise<void> {
await page.addInitScript(() => {
localStorage.setItem('hanzo_iam_access_token', 'e2e-token');
localStorage.setItem('hanzo_iam_expires_at', String(Date.now() + 3600_000));
});
}
async function mockUserinfo(page: import('@playwright/test').Page, owner: string): Promise<void> {
await page.route('**/v1/iam/oauth/userinfo', (route) =>
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ sub: 'z', owner, email: 'z@hanzo.ai', name: 'Z' }) }),
);
}
async function mockFleetReads(page: import('@playwright/test').Page): Promise<void> {
await page.route('**/v1/world/cloud/clusters', (route) =>
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(CLUSTERS) }));
await page.route('**/v1/world/cloud/queue', (route) =>
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(QUEUE) }));
}
test.describe('SuperAdmin fleet view', () => {
test('admin sees Clusters & Nodes + GPU Queue with live data', async ({ page }) => {
await seedSession(page);
await mockUserinfo(page, 'admin');
await mockFleetReads(page);
await page.goto('/?variant=cloud');
// Clusters panel mounts only for an admin owner, and renders the real DOKS
// clusters grouped by cluster with their node status.
const clusters = page.locator('#panelsGrid [data-panel="cloud-clusters"]');
await expect(clusters).toBeVisible({ timeout: 30000 });
await expect(clusters).toContainText('hanzo-k8s');
await expect(clusters).toContainText('adnexus-k8s');
await expect(clusters).toContainText('hanzo-k8s-2'); // a node row
await expect(clusters).toContainText('L40S'); // GPU node spec
await expect(clusters.locator('.cloud-cluster-group')).toHaveCount(2);
// Queue panel: depth + what's running, from which service, on which worker.
const queue = page.locator('#panelsGrid [data-panel="cloud-queue"]');
await expect(queue).toBeVisible();
await expect(queue).toContainText('gpu-jobs');
await expect(queue).toContainText('studio.render');
await expect(queue).toContainText('engine.serve');
await expect(queue).toContainText('spark'); // claiming worker
await expect(queue).toContainText('qwen3-32b'); // the model that worker serves
await expect(queue.locator('.cloud-queue-job').first()).toBeVisible();
await clusters.scrollIntoViewIfNeeded();
await clusters.screenshot({ path: 'e2e-shots/superadmin-clusters.png' });
await queue.scrollIntoViewIfNeeded();
await queue.screenshot({ path: 'e2e-shots/superadmin-queue.png' });
});
test('non-admin (org-admin only) is DENIED — panels never mount', async ({ page }) => {
await seedSession(page);
await mockUserinfo(page, 'acme'); // a real tenant, NOT the reserved admin org
await mockFleetReads(page); // even with data mocked, the gate must hold
await page.goto('/?variant=cloud');
// The always-mounted cloud overview confirms the grid built for this signed-in
// non-admin, so the absence of the admin panels below is a real deny, not a race.
await expect(page.locator('#panelsGrid [data-panel="cloud-overview"]')).toBeVisible({ timeout: 30000 });
await page.waitForTimeout(1500); // let any async admin-mount attempt resolve
await expect(page.locator('#panelsGrid [data-panel="cloud-clusters"]')).toHaveCount(0);
await expect(page.locator('#panelsGrid [data-panel="cloud-queue"]')).toHaveCount(0);
});
});
@@ -1,6 +1,7 @@
import { expect, test } from '@playwright/test';
import { clickMapControl } from './helpers/map-controls';
// Hanzo mode: on world.hanzo.ai (and local dev — a hanzo brand host) the H logo is a
// Cloud mode: on world.hanzo.ai (and local dev — a hanzo brand host) the H logo is a
// toggle that reveals the [Hanzo | World | AI | Crypto | Finance | Tech] switcher,
// and the flagship `hanzo` view ships the live-traffic globe layer. This spec drives
// the real header + map on the main app, plus the TrafficGlobePanel in isolation.
@@ -17,14 +18,14 @@ const TRAFFIC = {
totals: { rps_1m: 0.7, rpm_60m: 0.35, top_countries: [{ country: 'US', count: 42 }, { country: 'GB', count: 12 }, { country: 'DE', count: 7 }] },
};
test.describe('Hanzo mode', () => {
test('H logo reveals the switcher; hanzo view ships the live-traffic globe layer', async ({ page }) => {
test.describe('Cloud mode', () => {
test('H logo reveals the switcher; cloud view ships the live-traffic globe layer', async ({ page }) => {
// Feed the globe layer real points so its poll resolves (avoids a 404 empty state).
await page.route('**/v1/world/cloud/traffic-globe', (route) =>
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(TRAFFIC) }),
);
await page.goto('/?variant=hanzo');
await page.goto('/?variant=cloud');
// The H logo renders as the Hanzo-mode toggle on this (hanzo brand) host.
const hLogo = page.locator('[data-hanzo-toggle]');
@@ -35,16 +36,16 @@ test.describe('Hanzo mode', () => {
const switcher = page.locator('.variant-switcher');
await expect(switcher).toBeHidden();
// Click the H → Hanzo mode reveals the switcher.
// Click the H → Cloud mode reveals the switcher.
await hLogo.click();
await expect(page.locator('.header.hanzo-mode')).toHaveCount(1);
await expect(switcher).toBeVisible();
await expect(hLogo).toHaveAttribute('aria-expanded', 'true');
// Exactly the [Hanzo | World | AI | Crypto | Finance | Tech] tabs, Hanzo first.
// Exactly the [Cloud | World | AI | Crypto | Finance | Tech] tabs, Cloud first.
await expect(switcher.locator('.variant-option')).toHaveCount(6);
await expect(switcher.locator('.variant-option').first()).toHaveAttribute('data-variant', 'hanzo');
await expect(page.locator('.variant-option[data-variant="hanzo"].active')).toHaveCount(1);
await expect(switcher.locator('.variant-option').first()).toHaveAttribute('data-variant', 'cloud');
await expect(page.locator('.variant-option[data-variant="cloud"].active')).toHaveCount(1);
// Click the H again → collapses.
await hLogo.click();
@@ -102,4 +103,53 @@ test.describe('Hanzo mode', () => {
});
expect(empty).toContain('No live traffic yet');
});
test('3D globe settles (no idle-spin flicker) + Cloud-accurate legend, no cables assertion', async ({ page }) => {
await page.route('**/v1/world/cloud/traffic-globe', (route) =>
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(TRAFFIC) }),
);
const errors: string[] = [];
page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });
await page.goto('/?variant=cloud');
await expect(page.locator('.deckgl-map-wrapper')).toBeVisible({ timeout: 45000 });
// Legend must MATCH what the globe plots — the Cloud data classes, not the
// geopolitical default (which would mislabel a traffic dot as "high alert").
const legend = page.locator('.deckgl-legend');
await expect(legend).toBeVisible();
const legendText = (await legend.innerText()).toLowerCase();
for (const cls of ['request origin', 'validator node', 'gpu fleet', 'cloud region', 'datacenter']) {
expect(legendText).toContain(cls);
}
for (const geo of ['high alert', 'nuclear', 'elevated']) {
expect(legendText).not.toContain(geo);
}
// Switch to the 3D globe (GlobeNative is exposed on window in dev/e2e).
await clickMapControl(page, '.deckgl-projection-toggle .proj-btn[data-mode="3d"]');
await expect
.poll(() => page.evaluate(() => Boolean((window as unknown as { __globeNative?: unknown }).__globeNative)), { timeout: 20000 })
.toBe(true);
// Idle auto-rotate is OFF, so the globe SETTLES: the camera longitude does not
// drift and the deck render loop idles (a few data-sync renders, not ~40/s). A
// perpetually-spinning globe re-rasterizes thin vector lines every frame — that is
// the shimmer; a settled globe does not.
const settled = await page.evaluate(async () => {
const g = (window as unknown as {
__globeNative: { getCenter: () => { lon: number }; getDeck: () => { setProps: (p: unknown) => void } };
}).__globeNative;
const c0 = g.getCenter();
let renders = 0;
g.getDeck().setProps({ onAfterRender: () => { renders++; } });
await new Promise((r) => setTimeout(r, 1300));
return { lonDelta: Math.abs(g.getCenter().lon - c0.lon), renders };
});
expect(settled.lonDelta).toBeLessThan(0.001); // no idle auto-rotate drift
expect(settled.renders).toBeLessThan(12); // render loop idles (vs ~40/s spinning)
// The broken cables PathLayer must not assert (cables off in Cloud + path guarded).
expect(errors.filter((e) => /cables-layer|assertion failed/i.test(e))).toEqual([]);
});
});
+18 -10
View File
@@ -73,6 +73,13 @@ test.describe('right-click context menus', () => {
// emits) inside its own panel appended to the grid. A synthetic panel is used
// so a live panel's periodic re-render can't wipe the item mid-test, and so it
// is not under the map canvas — the menu code path is identical either way.
// The app defaults to FREE layout, where a raw injected panel (no coordinates)
// stacks at 0,0 under the full-width map and the map eats the right-click; pin
// grid mode so the injected panel flows to the grid end as a hit-testable child.
await page.evaluate(() =>
(window as unknown as { worldGrid?: { setLayoutMode(m: string): void } }).worldGrid?.setLayoutMode('grid'),
);
await page.waitForTimeout(80);
await page.evaluate(() => {
const grid = document.querySelector('#panelsGrid')!;
const panel = document.createElement('div');
@@ -151,23 +158,24 @@ test.describe('analyst data-tool traces', () => {
});
await appReady(page);
await page.click('.ai-dock-fab');
const composer = page.locator('.ai-dock-body .ai-analyst-input');
await page.click('.hzc-fab');
const composer = page.locator('.hzc-body .hzc-input');
await expect(composer).toBeVisible();
await composer.fill('What is the state of global instability?');
await page.click('.ai-dock-body .ai-analyst-send');
await page.click('.hzc-body .hzc-send');
// The collapsed tool trace renders before the reply that cites it.
const trace = page.locator('.ai-dock-body .ai-analyst-tool .ai-analyst-tool-summary');
// The tool trace renders before the reply that cites it; its summary carries
// the tool call (the redesign shows a database glyph, not the 🔧 emoji).
const trace = page.locator('.hzc-body .hzc-tool .hzc-tool-summary');
await expect(trace).toBeVisible();
await expect(trace).toContainText('🔧 world_brief(');
await expect(trace).toContainText('world_brief(');
// Expanding it reveals the raw result body.
await trace.click();
await expect(page.locator('.ai-dock-body .ai-analyst-tool-result')).toContainText('instability');
// The detail renders open, so the raw result body — a compact table of the
// tool's JSON — is visible inline and carries the returned instability field.
await expect(page.locator('.hzc-body .hzc-tool .hzc-table')).toContainText('instability');
// …and the grounded prose reply is shown.
await expect(page.locator('.ai-dock-body .ai-analyst-msg.assistant')).toContainText('instability is steady');
await expect(page.locator('.hzc-body .hzc-row.assistant')).toContainText('instability is steady');
await page.screenshot({ path: `${SCREENS}/analyst-tool-trace.png` });
});
+18 -3
View File
@@ -105,6 +105,15 @@ async function appReady(page: Page): Promise<void> {
}
async function openCountry(page: Page, code = 'FR', name = 'France'): Promise<void> {
// __app is exposed before init() finishes, but countryBriefPage is constructed
// later in init() (after loadAllData) — long after #panelsGrid paints. Wait for
// the hook so the open isn't raced to a silent early-return; a real map click
// only ever fires post-boot anyway.
await page.waitForFunction(
() => Boolean((window as unknown as { __app?: { countryBriefPage?: unknown } }).__app?.countryBriefPage),
undefined,
{ timeout: 30_000 },
);
await page.evaluate(
([c, n]) => (window as unknown as { __app: { openCountryBriefByCode(c: string, n: string): Promise<void> } }).__app.openCountryBriefByCode(c, n),
[code, name],
@@ -132,8 +141,14 @@ test.describe('Country application view', () => {
// …docked analyst chat on the right (signed-in → composer, model picker present).
const sidebar = page.locator('.cb-analyst-sidebar');
await expect(sidebar).toBeVisible();
await expect(sidebar.locator('.ai-analyst-input')).toBeVisible();
await expect(sidebar.locator('.ai-analyst-model option')).toHaveCount(2);
await expect(sidebar.locator('.hzc-input')).toBeVisible();
// Model picker is a pill opening a popover listbox (portaled to <body>); wait
// for the roster to paint, then open it to confirm the two stubbed models.
const modelBtn = sidebar.locator('.hzc-model');
await expect(modelBtn.locator('.hzc-model-name')).toHaveText('Zen 5');
await modelBtn.click();
await expect(page.locator('.hzc-model-menu .hzc-model-opt')).toHaveCount(2);
await modelBtn.click(); // close the popover
// Sidebar is on the right of the intel content.
const mainBox = await page.locator('.cb-main').boundingBox();
const sideBox = await sidebar.boundingBox();
@@ -185,7 +200,7 @@ test.describe('Country application view', () => {
// Open the bottom sheet.
await page.click('.cb-analyst-fab');
await expect(brief).not.toHaveClass(/cb-analyst-collapsed/);
await expect(page.locator('.cb-analyst-sidebar .ai-analyst-input')).toBeVisible();
await expect(page.locator('.cb-analyst-sidebar .hzc-input')).toBeVisible();
await page.screenshot({ path: `${SCREENS}/country-view-mobile-open.png` });
});
+168
View File
@@ -0,0 +1,168 @@
import { expect, test, type Page } from '@playwright/test';
// The signed-in dashboard-sync contract, verified end-to-end against the REAL app:
// 1. on boot, this identity's server dashboard is written into localStorage
// BEFORE the app reads it (server precedence, cross-device),
// 2. a change to a dashboard key is synced to the server (debounced PUT of the
// full snapshot),
// 3. signed out, nothing ever touches the server (localStorage only).
// IAM is faked (a non-expired token + a stubbed userinfo) and /v1/world/dashboard
// is stubbed, so no real backend or identity is needed.
const DASH = '**/v1/world/dashboard';
const HIST = '**/v1/world/history';
const LN = '[data-panel="live-news"]';
async function fakeAuth(page: Page): Promise<void> {
await page.addInitScript(() => {
localStorage.setItem('hanzo_iam_access_token', 'faketoken');
localStorage.setItem('hanzo_iam_expires_at', String(Date.now() + 3_600_000));
localStorage.setItem('hanzo_iam_owner', 'acme');
});
// Keep the fake session valid: a userinfo 401 would let the app drop the token,
// and the sync (correctly) stops when signed out.
await page.route('**/v1/iam/oauth/userinfo', (r) =>
r.fulfill({ json: { sub: 'u1', owner: 'acme', email: 'u@acme.test' } }),
);
// Default empty history so boot's history hydrate never hits the real backend;
// tests that assert on history override this with a later page.route (last wins).
await page.route(HIST, (r) => r.fulfill({ json: { config: {} } }));
}
test.describe('dashboard sync (real app)', () => {
test.use({ viewport: { width: 1440, height: 900 } });
test('boot hydrates localStorage from the server (server precedence)', async ({ page }) => {
await fakeAuth(page);
await page.route(DASH, async (route) => {
if (route.request().method() === 'GET') {
await route.fulfill({ json: { config: { 'hanzo-world-map-mode': '3d' } } });
} else {
await route.fulfill({ json: { ok: true } });
}
});
await page.goto('/');
await page.waitForSelector(LN, { timeout: 45000 });
// The server value was applied to localStorage at boot, before the app read it.
await expect
.poll(() => page.evaluate(() => localStorage.getItem('hanzo-world-map-mode')), { timeout: 8000 })
.toBe('3d');
});
test('a dashboard change is synced to the server (debounced PUT of the snapshot)', async ({ page }) => {
await fakeAuth(page);
const puts: Array<Record<string, string>> = [];
await page.route(DASH, async (route) => {
if (route.request().method() === 'GET') {
await route.fulfill({ json: { config: {} } }); // empty server → first run
} else {
puts.push(route.request().postDataJSON() as Record<string, string>);
await route.fulfill({ json: { ok: true } });
}
});
await page.goto('/');
await page.waitForSelector(LN, { timeout: 45000 });
await page.waitForTimeout(2000); // let the boot writes flush their debounced PUT first
// Change an observed dashboard key; a debounced PUT carries a snapshot of ALL
// dashboard keys, including our change.
await page.evaluate(() => localStorage.setItem('worldmonitor-layers', '{"quakes":true}'));
await expect
.poll(() => puts.some((p) => p && p['worldmonitor-layers'] === '{"quakes":true}'), { timeout: 8000 })
.toBe(true);
});
test('signed out: never touches the server (localStorage only)', async ({ page }) => {
let hit = false;
await page.route(DASH, async (route) => {
hit = true;
await route.fulfill({ json: { config: {} } });
});
await page.goto('/'); // no fakeAuth → anonymous
await page.waitForSelector(LN, { timeout: 45000 });
await page.evaluate(() => localStorage.setItem('worldmonitor-layers', '{"a":1}'));
await page.waitForTimeout(1200);
expect(hit).toBe(false);
});
test('history keys sync to /v1/world/history, not /dashboard', async ({ page }) => {
await fakeAuth(page);
const dashPuts: string[] = [];
const histPuts: Array<Record<string, string>> = [];
await page.route(DASH, async (route) => {
if (route.request().method() === 'GET') await route.fulfill({ json: { config: {} } });
else {
dashPuts.push(route.request().postData() || '');
await route.fulfill({ json: { ok: true } });
}
});
await page.route(HIST, async (route) => {
if (route.request().method() === 'GET') await route.fulfill({ json: { config: {} } });
else {
histPuts.push(route.request().postDataJSON() as Record<string, string>);
await route.fulfill({ json: { ok: true } });
}
});
await page.goto('/');
await page.waitForSelector(LN, { timeout: 45000 });
await page.waitForTimeout(2000); // flush boot writes first
// A real user action (a recent search) is a HISTORY key → PUT to /history.
await page.evaluate(() => localStorage.setItem('worldmonitor_recent_searches', '["nvidia"]'));
await expect
.poll(() => histPuts.some((p) => p && p['worldmonitor_recent_searches'] === '["nvidia"]'), { timeout: 8000 })
.toBe(true);
// …and it was NOT mixed into a dashboard PUT (clean namespace separation).
expect(dashPuts.some((b) => b.includes('worldmonitor_recent_searches'))).toBe(false);
});
// Org-shared default precedence: the org default is hydrated as the BASE, then the
// user's own doc overlays it. One broad route serves both scopes, branching on URL
// (the `/shared` GET is the org default; the bare GET is the per-user doc).
async function routeDashboardScopes(
page: Page,
shared: Record<string, string>,
user: Record<string, string>,
): Promise<void> {
await page.route('**/v1/world/dashboard**', async (route) => {
if (route.request().method() !== 'GET') {
await route.fulfill({ json: { ok: true } });
return;
}
const isShared = route.request().url().includes('/dashboard/shared');
await route.fulfill({ json: { config: isShared ? shared : user } });
});
}
test('org default hydrates as the base when the user has no doc yet', async ({ page }) => {
await fakeAuth(page);
// Org published a default; this member has never saved their own → they get it.
await routeDashboardScopes(page, { 'hanzo-world-map-mode': '3d' }, {});
await page.goto('/');
await page.waitForSelector(LN, { timeout: 45000 });
await expect
.poll(() => page.evaluate(() => localStorage.getItem('hanzo-world-map-mode')), { timeout: 8000 })
.toBe('3d');
});
test('the per-user doc overrides the org default (user wins)', async ({ page }) => {
await fakeAuth(page);
// Org default says 3d, the user's own doc says 2d → the user's choice wins.
await routeDashboardScopes(page, { 'hanzo-world-map-mode': '3d' }, { 'hanzo-world-map-mode': '2d' });
await page.goto('/');
await page.waitForSelector(LN, { timeout: 45000 });
await expect
.poll(() => page.evaluate(() => localStorage.getItem('hanzo-world-map-mode')), { timeout: 8000 })
.toBe('2d');
});
test('boot hydrates history from /v1/world/history (server precedence)', async ({ page }) => {
await fakeAuth(page);
await page.route(DASH, (r) => r.fulfill({ json: { config: {} } }));
await page.route(HIST, (r) => r.fulfill({ json: { config: { 'hanzo-world-watch-queue': '{"items":[7]}' } } }));
await page.goto('/');
await page.waitForSelector(LN, { timeout: 45000 });
await expect
.poll(() => page.evaluate(() => localStorage.getItem('hanzo-world-watch-queue')), { timeout: 8000 })
.toBe('{"items":[7]}');
});
});
+61
View File
@@ -0,0 +1,61 @@
import { expect, test } from '@playwright/test';
// Enso Live Training must reflect REAL models (the served catalog), never the opaque
// upstream "arm-N" routing mix that read as random/meaningless amounts. Both feeds are
// stubbed with real-shaped payloads; the router-stats stub deliberately includes an
// arm-N by_model map to prove it is NOT rendered anymore.
const ENSO = '.panel[data-panel="enso-training"]';
const ROUTER_STATS = {
scope: 'platform',
window: { since: '2026-07-17T00:00:00Z', until: '2026-07-18T00:00:00Z', events: 12345 },
cost: { saved_pct: 0.23, cumulative_saved_index: 98765, baseline_model: 'x', priced_events: 100 },
quality: { reward_rate: 0.5, rewarded_events: 10, engine_share: 0.62, avg_confidence: 0.8, shadow_agreement: 0.91 },
by_task: {},
by_model: { 'arm-1': 100, 'arm-2': 50, 'arm-3': 25 }, // opaque arms — must NOT render
throughput: { per_hour: [1, 2, 3, 4, 5, 6], total_window: 21 },
retrain: {
version: 'v9', trained_time: '2026-07-17T12:00:00Z', events: 100, gate_passed: true,
published: true, gate_kind: 'reward', gate_metric: 'rate', gate_value: 0.5, gate_base: 0.4, note: '',
},
};
const CLOUD_MODELS = {
updatedAt: '2026-07-18T00:00:00Z',
totalModels: 42,
zenModels: 8,
cloudRegions: 5,
cloudPlans: 3,
families: ['Zen', 'Fable'],
models: [
{ id: 'zen5', name: 'Zen 5', provider: 'hanzo', tier: 'flagship', context: 200000, inPrice: 3, outPrice: 15 },
{ id: 'zen5-flash', name: 'Zen 5 Flash', provider: 'hanzo', tier: 'fast', context: 128000, inPrice: 0.5, outPrice: 1.5 },
{ id: 'fable5', name: 'Fable 5', provider: 'hanzo', tier: 'premium', context: 400000, inPrice: 5, outPrice: 20 },
],
};
test.describe('Enso Live Training — real models only', () => {
test.use({ viewport: { width: 1440, height: 900 } });
test('renders the real served-model catalog, never opaque arm-N amounts', async ({ page }) => {
await page.route('**/v1/world/cloud/router-stats*', (r) => r.fulfill({ json: ROUTER_STATS }));
await page.route('**/v1/world/cloud/models', (r) => r.fulfill({ json: CLOUD_MODELS }));
// Enso Live Training is a Cloud-flagship panel (added only in the cloud
// variant); ?variant=cloud wins over the build-time VITE_VARIANT at runtime.
await page.goto('/?variant=cloud');
await page.waitForSelector(ENSO, { timeout: 45000 });
const panel = page.locator(ENSO);
// Real model names from the catalog appear.
await expect(panel).toContainText('Zen 5 Flash', { timeout: 15000 });
await expect(panel).toContainText('Fable 5');
await expect(panel).toContainText('models served');
// Real aggregates still render (unchanged, real telemetry).
await expect(panel).toContainText('cost saved');
// The opaque per-arm amounts are GONE — no meaningless "Enso arm N" rows.
await expect(panel).not.toContainText('Enso arm');
await expect(panel).not.toContainText('arm-1');
});
});
+43 -18
View File
@@ -1,21 +1,24 @@
import { expect, test } from '@playwright/test';
// Mounts the real EnsoTrainingPanel against a stubbed router-stats payload and
// asserts the rendered DOM: opaque "Enso arm N" labels (NEVER a vendor name),
// the cost-saved headline, the retrain gate verdict, and the honest "—" shadow
// state. Mirrors e2e/investments-panel.spec.ts (runtime-harness).
// Mounts the real EnsoTrainingPanel against stubbed router-stats + served-model
// catalog payloads and asserts the rendered DOM. The redesign REPLACED the opaque
// "Enso arm N" routing mix with the REAL served-model catalog (real names, tiers,
// pricing) — this asserts that new surface: real model rows (never opaque arms,
// never a third-party vendor name), the cost-saved headline, the retrain gate
// verdict, and the honest "—" shadow state. Mirrors the app-level assertions in
// e2e/enso-real-models.spec.ts at the runtime-harness (unit) level.
test.describe('Enso Live Training panel', () => {
test('renders opaque arms, cost-saved headline and retrain gate — no vendor names', async ({ page }) => {
test('renders the real served-model catalog, cost-saved headline and retrain gate — no opaque arms, no vendor names', async ({ page }) => {
await page.goto('/tests/runtime-harness.html');
const result = await page.evaluate(async () => {
const CANNED = {
const ROUTER_STATS = {
scope: 'platform',
window: { since: '2026-07-15T00:00:00Z', until: '2026-07-16T00:00:00Z', events: 48210 },
cost: { saved_pct: 21.5, cumulative_saved_index: 1372, baseline_model: 'arm-1', priced_events: 41000 },
quality: { reward_rate: 0.31, rewarded_events: 1200, engine_share: 0.62, avg_confidence: 0.74, shadow_agreement: null },
by_task: { chat: { events: 30000, models: { 'arm-1': 18000, 'arm-2': 12000 } } },
by_model: { 'arm-1': 30000, 'arm-2': 14000, 'arm-3': 4210 },
by_model: { 'arm-1': 30000, 'arm-2': 14000, 'arm-3': 4210 }, // opaque arms — must NOT render
throughput: { per_hour: Array.from({ length: 24 }, (_, i) => 1500 + i * 40), total_window: 48210 },
retrain: {
version: 'router-2026.07.16', trained_time: '2026-07-16T00:00:00Z', events: 48210,
@@ -23,24 +26,41 @@ test.describe('Enso Live Training panel', () => {
gate_value: 0.312, gate_base: 0.298, note: 'shipped',
},
};
// The REAL served catalog the router trains across — Hanzo's own models only.
const CLOUD_MODELS = {
updatedAt: '2026-07-16T00:00:00Z',
totalModels: 42,
zenModels: 8,
cloudRegions: 5,
cloudPlans: 3,
families: ['Zen', 'Fable'],
models: [
{ id: 'zen5', name: 'Zen 5', provider: 'hanzo', tier: 'flagship', context: 200000, inPrice: 3, outPrice: 15 },
{ id: 'zen5-flash', name: 'Zen 5 Flash', provider: 'hanzo', tier: 'fast', context: 128000, inPrice: 0.5, outPrice: 1.5 },
{ id: 'fable5', name: 'Fable 5', provider: 'hanzo', tier: 'premium', context: 400000, inPrice: 5, outPrice: 20 },
],
};
// Stub the same-origin proxy the service calls.
// Stub the same-origin proxies the panel calls, by endpoint.
const origFetch = window.fetch;
window.fetch = (async () =>
({ ok: true, status: 200, json: async () => CANNED })) as typeof window.fetch;
window.fetch = (async (input: RequestInfo | URL) => {
const url = typeof input === 'string' ? input : input.toString();
const body = url.includes('/cloud/models') ? CLOUD_MODELS : ROUTER_STATS;
return { ok: true, status: 200, json: async () => body } as Response;
}) as typeof window.fetch;
const { EnsoTrainingPanel } = await import('/src/components/EnsoTrainingPanel.ts');
const panel = new EnsoTrainingPanel();
const root = panel.getElement();
document.body.appendChild(root);
// Wait for the async fetch → render to land.
// Wait for the async fetch → render to land (real model rows appear).
const deadline = Date.now() + 3000;
while (Date.now() < deadline && root.querySelectorAll('.cloud-model-row').length === 0) {
await new Promise((r) => setTimeout(r, 30));
}
const armLabels = Array.from(root.querySelectorAll('.cloud-model-name')).map(
const modelNames = Array.from(root.querySelectorAll('.cloud-model-name')).map(
(n) => (n.textContent ?? '').trim(),
);
const text = root.textContent ?? '';
@@ -49,14 +69,19 @@ test.describe('Enso Live Training panel', () => {
root.remove();
window.fetch = origFetch;
return { armLabels, text };
return { modelNames, text };
});
// Three opaque arms, labeled by tier — never a vendor name.
expect(result.armLabels.length).toBe(3);
expect(result.armLabels[0]).toContain('Enso arm 1');
expect(result.armLabels[1]).toContain('Enso arm 2');
expect(result.armLabels[2]).toContain('Enso arm 3');
// The three REAL served models render by name — never opaque "arm-N".
expect(result.modelNames.length).toBe(3);
expect(result.modelNames[0]).toContain('Zen 5');
expect(result.modelNames[1]).toContain('Zen 5 Flash');
expect(result.modelNames[2]).toContain('Fable 5');
expect(result.text).toContain('models served');
// The opaque per-arm mix is GONE.
expect(result.text).not.toContain('Enso arm');
expect(result.text).not.toContain('arm-1');
// No third-party vendor identity leaks through the served catalog.
for (const vendor of ['claude', 'anthropic', 'gpt', 'openai', 'deepseek', 'qwen', 'gemini', 'llama']) {
expect(result.text.toLowerCase()).not.toContain(vendor);
}
+4 -3
View File
@@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test';
import { clickMapControl } from './helpers/map-controls';
// P0-1: deck.gl overlays must actually RENDER on the mapbox-gl v3 globe.
//
@@ -110,7 +111,7 @@ test.describe('P0-1 deck overlay renders on the globe', () => {
// → 3D globe. Deck's active viewport must be a GlobeViewport (proves deck is
// reprojecting onto the sphere) and the dot must still pick on the globe.
await page.locator('.deckgl-projection-toggle .proj-btn[data-mode="3d"]').click();
await clickMapControl(page, '.deckgl-projection-toggle .proj-btn[data-mode="3d"]');
await expect.poll(() => projection(page), { timeout: 30000 }).toBe('globe');
await page.evaluate(() => (window as HarnessWindow).__mapHarness!.stopIdleSpin());
await expect.poll(() => viewportType(page), { timeout: 20000 }).toMatch(/Globe/i);
@@ -128,10 +129,10 @@ test.describe('P0-1 deck overlay renders on the globe', () => {
await testInfo.attach('globe-3d-dots', { body: shot, contentType: 'image/png' });
// Round-trip 2D → 3D again; picks must survive each transition.
await page.locator('.deckgl-projection-toggle .proj-btn[data-mode="2d"]').click();
await clickMapControl(page, '.deckgl-projection-toggle .proj-btn[data-mode="2d"]');
await expect.poll(() => projection(page), { timeout: 20000 }).toBe('mercator');
await pollPickFound(page);
await page.locator('.deckgl-projection-toggle .proj-btn[data-mode="3d"]').click();
await clickMapControl(page, '.deckgl-projection-toggle .proj-btn[data-mode="3d"]');
await expect.poll(() => projection(page), { timeout: 20000 }).toBe('globe');
await page.evaluate(() => (window as HarnessWindow).__mapHarness!.stopIdleSpin());
await pollPickFound(page);
+223
View File
@@ -0,0 +1,223 @@
import { expect, test } from '@playwright/test';
// Globe render-fix acceptance suite (world.hanzo.ai Hanzo-Cloud view).
//
// Guards the three "spazz" bugs the CTO reported and the 2D/3D parity + live-analytics
// contract:
// 1. Overlays must sit ON the globe surface with correct occlusion — a back-hemisphere
// dot/badge is HIDDEN, a front one is drawn (no floating layers above the sphere).
// 2. Terrain drapes on the globe in a single WebGL context (no second canvas, no
// striping regression — depth-write disabled on the coplanar imagery tiles).
// 3. Every cloud data layer mounts in BOTH 2D (mercator) and 3D (globe) — parity.
// Plus: the REAL live request-geo dots appear and update.
//
// Data is mocked at the same-origin /v1/world/cloud/* contracts so the run is
// deterministic and offline (production serves the real, live payloads).
type DeckLayer = { id: string; props: Record<string, unknown> };
type Rgba = [number, number, number, number];
const cloudMap = {
// Two request-origin points on OPPOSITE hemispheres so occlusion is testable:
// FRONT (lon 0) faces a camera centred at lon 0; BACK (lon 180) is behind the globe.
trafficGlobe: {
updatedAt: '2026-07-18T12:00:00Z',
live: true,
window: { minutes: 60, since: '2026-07-18T11:00:00Z', until: '2026-07-18T12:00:00Z' },
points: [
{ country: 'FR', lat: 20, lon: 0, count: 90, byService: { models: 90 } },
{ country: 'US', lat: 37.09, lon: -95.71, count: 42, byService: { models: 42 } },
{ country: 'JP', lat: 20, lon: 180, count: 30, byService: { models: 30 } },
],
totals: { rps_1m: 1.6, rpm_60m: 96, top_countries: [{ country: 'FR', count: 90 }, { country: 'US', count: 42 }, { country: 'JP', count: 30 }] },
},
traffic: {
updatedAt: '2026-07-18T12:00:00Z', demo: false,
arcs: [
{ fromLat: 20, fromLon: 0, toLat: 51.5, toLon: -0.12, weight: 1, label: 'FR → lon' },
{ fromLat: 37.09, fromLon: -95.71, toLat: 40.71, toLon: -74.0, weight: 0.6, label: 'US → nyc' },
],
},
chainNodes: {
updatedAt: '2026-07-18T12:00:00Z', positionsModeled: true,
networks: [{ id: 'lux', name: 'Lux Network', chainId: 96369, blockHeight: 1096461, peers: 3, live: true,
nodes: [{ lat: 40.71, lon: -74.0, city: 'New York', kind: 'validator' }, { lat: 37.77, lon: -122.42, city: 'San Francisco', kind: 'validator' }] }],
},
byoGpu: { updatedAt: '2026-07-18T12:00:00Z', demo: false, gpus: [] },
};
// The flagship Cloud variant now OPENS on the native 3D globe (its immersive default),
// which parks the mapbox 2D map — `.deckgl-map-wrapper` mounts hidden. These specs
// exercise the 2D→3D toggle path (2D layer parity, then go3D), so they pin the start
// to 2D with `?mode=2d` (resolveInitialMapMode: the URL wins over the variant default).
// The globe-as-default render is proven separately (direct visual + the live prod shot).
const CLOUD_2D = '/?variant=cloud&mode=2d';
async function mockCloud(page: import('@playwright/test').Page, traffic = cloudMap.trafficGlobe): Promise<void> {
const json = (body: unknown) => ({ status: 200, contentType: 'application/json', body: JSON.stringify(body) });
await page.route('**/v1/world/cloud/traffic-globe', (r) => r.fulfill(json(traffic)));
await page.route('**/v1/world/cloud/traffic', (r) => r.fulfill(json(cloudMap.traffic)));
await page.route('**/v1/world/cloud/chain-nodes', (r) => r.fulfill(json(cloudMap.chainNodes)));
await page.route('**/v1/world/cloud/byo-gpu', (r) => r.fulfill(json(cloudMap.byoGpu)));
}
const layerIds = (page: import('@playwright/test').Page): Promise<string[]> =>
page.evaluate(() => {
const m = (window as unknown as { __deckMap?: { asGlobeSource: () => { buildLayers: () => DeckLayer[] } } }).__deckMap;
return (m?.asGlobeSource().buildLayers() ?? []).flat(Infinity).filter(Boolean).map((l: DeckLayer) => l.id);
});
const go3D = async (page: import('@playwright/test').Page): Promise<void> => {
// Enter the 3D globe through the projection toggle's REAL click handler
// (proj-btn → setProjectionMode('3d') → activateNativeGlobe). The flagship Cloud
// view floats its control dock over the full-viewport globe canvas, so under
// headless swiftshader a synthesized mouse click's hit-test lands on the canvas,
// not the collapsed-dropdown button — dispatch the click on the element itself.
// This spec verifies the GLOBE render (occlusion/terrain/parity/live dots); the
// dock's pointer reachability is a separate controls concern, out of scope here.
await page.evaluate(() => {
const btn = document.querySelector('.deckgl-projection-toggle .proj-btn[data-mode="3d"]') as HTMLElement | null;
btn?.click();
});
await expect
.poll(() => page.evaluate(() => Boolean((window as unknown as { __globeNative?: unknown }).__globeNative)), { timeout: 25000 })
.toBe(true);
await page.waitForTimeout(1200); // let the first data-sync pull + push layers
};
test.describe('Globe render fixes — occlusion, terrain, 2D/3D parity, live dots', () => {
test.describe.configure({ retries: 1 });
test.use({ reducedMotion: 'reduce' });
// The cloud data layers that must exist on the Hanzo-Cloud globe once feeds resolve.
const CLOUD_LAYERS = ['traffic', 'trafficArcs', 'chainNodes', 'datacenter-clusters-layer'];
test('3D: cloud layers mount, live dots render on the sphere, no WebGL errors', async ({ page }, testInfo) => {
const errors: string[] = [];
const ignorable = [/could not compile fragment shader/i, /image.*could not be decoded/i, /the layer 'background'/i, /status of 40[13]/i];
page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });
page.on('pageerror', (e) => errors.push(e.message));
await mockCloud(page);
await page.goto(CLOUD_2D);
await expect(page.locator('.deckgl-map-wrapper')).toBeVisible({ timeout: 45000 });
await go3D(page);
// Single WebGL context for the globe (deck GlobeView, not a 2nd overlay canvas).
expect(await page.evaluate(() => document.querySelectorAll('.globe-native-canvas').length)).toBe(1);
await expect.poll(() => page.evaluate(() => (window as unknown as { __globeNative: { getViewportType: () => string | null } }).__globeNative.getViewportType())).toMatch(/Globe/i);
// Every cloud data layer is mounted.
const ids = await layerIds(page);
for (const id of CLOUD_LAYERS) expect(ids).toContain(id);
// The live request-geo dots are present with the real (mocked) point count.
const trafficCount = await page.evaluate(() => {
const m = (window as unknown as { __deckMap: { asGlobeSource: () => { buildLayers: () => DeckLayer[] } } }).__deckMap;
const t = m.asGlobeSource().buildLayers().flat(Infinity).find((l: DeckLayer) => l?.id === 'traffic');
return (t?.props?.data as unknown[])?.length ?? 0;
});
expect(trafficCount).toBe(cloudMap.trafficGlobe.points.length);
const shot = await page.locator('.globe-native-wrapper').screenshot();
await testInfo.attach('3d-globe-cloud-layers', { body: shot, contentType: 'image/png' });
expect(errors.filter((e) => !ignorable.some((p) => p.test(e)))).toEqual([]);
});
test('occlusion: a back-hemisphere dot is culled to transparent, a front dot is opaque', async ({ page }) => {
await mockCloud(page);
await page.goto(CLOUD_2D);
await expect(page.locator('.deckgl-map-wrapper')).toBeVisible({ timeout: 45000 });
await go3D(page);
// Face the camera at lon 0 (the FRONT point). Read the REAL traffic layer's fill
// accessor for each point: front → opaque (alpha>0), back (lon 180) → alpha 0.
const alphas = await page.evaluate(() => {
const m = (window as unknown as { __deckMap: { setOcclusionCenter: (lng: number, lat: number) => void; asGlobeSource: () => { buildLayers: () => DeckLayer[] } } }).__deckMap;
m.setOcclusionCenter(0, 20);
const t = m.asGlobeSource().buildLayers().flat(Infinity).find((l: DeckLayer) => l?.id === 'traffic') as DeckLayer;
const data = t.props.data as Array<{ lon: number }>;
const getFill = t.props.getFillColor as (d: unknown) => Rgba;
const front = getFill(data.find((d) => d.lon === 0));
const back = getFill(data.find((d) => d.lon === 180));
return { frontAlpha: front[3], backAlpha: back[3] };
});
expect(alphas.frontAlpha).toBeGreaterThan(0);
expect(alphas.backAlpha).toBe(0);
});
test('occlusion: a back-hemisphere count badge is culled (no floating badge over the globe)', async ({ page }) => {
await mockCloud(page);
await page.goto(CLOUD_2D);
await expect(page.locator('.deckgl-map-wrapper')).toBeVisible({ timeout: 45000 });
await go3D(page);
// datacenter count badges are a TextLayer; a back-side badge's glyph AND pill must
// both go transparent. Probe both hemispheres against a fixed camera centre.
const badge = await page.evaluate(() => {
const m = (window as unknown as { __deckMap: { setOcclusionCenter: (lng: number, lat: number) => void; asGlobeSource: () => { buildLayers: () => DeckLayer[] } } }).__deckMap;
m.setOcclusionCenter(0, 20);
const b = m.asGlobeSource().buildLayers().flat(Infinity).find((l: DeckLayer) => l?.id === 'datacenter-clusters-badge') as DeckLayer | undefined;
if (!b) return { skip: true };
const getColor = b.props.getColor as (d: unknown) => Rgba;
const getBg = b.props.getBackgroundColor as (d: unknown) => Rgba;
const front = { lon: 0, lat: 20, count: 5 };
const back = { lon: 180, lat: 20, count: 5 };
return { skip: false, frontText: getColor(front)[3], backText: getColor(back)[3], backBg: getBg(back)[3] };
});
if (badge.skip) test.skip(true, 'no datacenter badge in this build');
expect(badge.frontText).toBeGreaterThan(0);
expect(badge.backText).toBe(0);
expect(badge.backBg).toBe(0);
});
test('2D/3D parity: every cloud layer that mounts in 3D also mounts in 2D', async ({ page }, testInfo) => {
await mockCloud(page);
await page.goto(CLOUD_2D);
await expect(page.locator('.deckgl-map-wrapper')).toBeVisible({ timeout: 45000 });
await page.waitForTimeout(1500); // 2D feeds settle
const ids2d = await layerIds(page);
for (const id of CLOUD_LAYERS) expect(ids2d, `2D missing ${id}`).toContain(id);
await testInfo.attach('2d-map-cloud-layers', { body: await page.locator('.deckgl-map-wrapper').screenshot(), contentType: 'image/png' });
await go3D(page);
const ids3d = await layerIds(page);
for (const id of CLOUD_LAYERS) expect(ids3d, `3D missing ${id}`).toContain(id);
await testInfo.attach('3d-globe-cloud-layers-parity', { body: await page.locator('.globe-native-wrapper').screenshot(), contentType: 'image/png' });
});
test('terrain drapes on the globe in a single context (no second canvas)', async ({ page }, testInfo) => {
await mockCloud(page);
await page.goto(CLOUD_2D);
await expect(page.locator('.deckgl-map-wrapper')).toBeVisible({ timeout: 45000 });
await go3D(page);
await page.evaluate(() => (window as unknown as { __globeNative: { setBasemapStyle: (s: string) => void } }).__globeNative.setBasemapStyle('terrain'));
await expect
.poll(() => page.evaluate(() => (window as unknown as { __globeNative: { getDeck: () => { props: { layers: DeckLayer[] } } } }).__globeNative.getDeck().props.layers.flat(Infinity).some((l: DeckLayer) => l?.id?.startsWith('globe-imagery-terrain'))), { timeout: 20000 })
.toBe(true);
// Still exactly one canvas — imagery drapes as deck tiles, not a 2nd WebGL context.
expect(await page.evaluate(() => document.querySelectorAll('.globe-native-wrapper canvas').length)).toBe(1);
await page.waitForTimeout(2500);
await testInfo.attach('3d-terrain-globe', { body: await page.locator('.globe-native-wrapper').screenshot(), contentType: 'image/png' });
});
test('live dots update when the feed changes', async ({ page }) => {
await mockCloud(page, { ...cloudMap.trafficGlobe, points: cloudMap.trafficGlobe.points.slice(0, 1) });
await page.goto(CLOUD_2D);
await expect(page.locator('.deckgl-map-wrapper')).toBeVisible({ timeout: 45000 });
await go3D(page);
const count = () => page.evaluate(() => {
const m = (window as unknown as { __deckMap: { asGlobeSource: () => { buildLayers: () => DeckLayer[] } } }).__deckMap;
const t = m.asGlobeSource().buildLayers().flat(Infinity).find((l: DeckLayer) => l?.id === 'traffic');
return (t?.props?.data as unknown[])?.length ?? 0;
});
await expect.poll(count, { timeout: 15000 }).toBe(1);
// Swap the feed to the full 3-point payload; the DeckGLMap poll picks it up.
await mockCloud(page, cloudMap.trafficGlobe);
await expect.poll(count, { timeout: 20000 }).toBe(cloudMap.trafficGlobe.points.length);
});
});
+3 -2
View File
@@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test';
import { clickMapControl } from './helpers/map-controls';
type LayerSnapshot = { id: string; dataCount: number };
@@ -160,7 +161,7 @@ test.describe('3D globe', () => {
}
// Click the real 3D pill in the map header.
await page.locator('.deckgl-projection-toggle .proj-btn[data-mode="3d"]').click();
await clickMapControl(page, '.deckgl-projection-toggle .proj-btn[data-mode="3d"]');
await expect.poll(() => projectionType(page), { timeout: 30000 }).toBe('globe');
await expect(page.locator('.deckgl-projection-toggle .proj-btn[data-mode="3d"]')).toHaveClass(/active/);
@@ -186,7 +187,7 @@ test.describe('3D globe', () => {
}
// Flip back to the flat map.
await page.locator('.deckgl-projection-toggle .proj-btn[data-mode="2d"]').click();
await clickMapControl(page, '.deckgl-projection-toggle .proj-btn[data-mode="2d"]');
await expect.poll(() => projectionType(page), { timeout: 20000 }).toBe('mercator');
expect(pageErrors.filter((e) => !ignorable.some((p) => p.test(e)))).toEqual([]);
+18
View File
@@ -0,0 +1,18 @@
import type { Page, Locator } from '@playwright/test';
// The map's projection / basemap / time-range controls collapsed into dropdowns:
// each option button (.proj-btn / .style-btn / .time-btn) lives in a popover that a
// trigger opens. Tests that click an option must open its dropdown first. This helper
// opens the button's parent .deckgl-dd (if it's in one) and clicks the option — a
// no-op open when the button isn't inside a dropdown, so it's safe everywhere.
export async function clickMapControl(page: Page, buttonSelector: string): Promise<void> {
const btn: Locator = page.locator(buttonSelector).first();
const dd = btn.locator('xpath=ancestor::div[contains(concat(" ", normalize-space(@class), " "), " deckgl-dd ")][1]');
if (await dd.count()) {
const trigger = dd.locator('.dd-trigger').first();
if (!(await dd.evaluate((el) => el.classList.contains('open')).catch(() => false))) {
await trigger.click();
}
}
await btn.click();
}
+9 -5
View File
@@ -1,6 +1,7 @@
import { expect, test, type Page } from '@playwright/test';
import { mkdirSync } from 'node:fs';
import { join } from 'node:path';
import { clickMapControl } from './helpers/map-controls';
// Capture the CTO-facing proof screenshots for the layout/style batch. These drive
// the REAL app (not a harness) so they show the shipped chrome + layout. They are
@@ -33,7 +34,7 @@ test.describe('layout/style batch — deliverable screenshots', () => {
await boot(page);
// Globe on.
await page.locator('.deckgl-projection-toggle .proj-btn[data-mode="3d"]').click().catch(() => {});
await clickMapControl(page, '.deckgl-projection-toggle .proj-btn[data-mode="3d"]').catch(() => {});
await page.waitForTimeout(1200);
// Enter immersive.
@@ -59,19 +60,22 @@ test.describe('layout/style batch — deliverable screenshots', () => {
test('basemap style switcher (dark / satellite / terrain)', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 800 });
await boot(page);
// The basemap control collapsed into a dropdown: assert its trigger, then open it.
await expect(page.locator('.deckgl-dd[data-dd="basemap"] .dd-trigger')).toBeVisible();
await page.locator('.deckgl-dd[data-dd="basemap"] .dd-trigger').click();
await expect(page.locator('.deckgl-style-switcher')).toBeVisible();
await shot(page, 'style-switcher-dark.png');
// Satellite + terrain need a Mapbox token (VITE_MAPBOX_TOKEN); the buttons are
// disabled without one. When a token is configured, actually switch and let the
// relief render before capturing.
// relief render before capturing. clickMapControl reopens the dropdown each time
// (picking an option closes it).
const sat = page.locator('.deckgl-style-switcher .style-btn[data-style="satellite"]');
if (!(await sat.isDisabled())) {
await sat.click();
await clickMapControl(page, '.deckgl-style-switcher .style-btn[data-style="satellite"]');
await page.waitForTimeout(4000);
await shot(page, 'style-switcher-satellite.png');
const terrain = page.locator('.deckgl-style-switcher .style-btn[data-style="terrain"]');
await terrain.click();
await clickMapControl(page, '.deckgl-style-switcher .style-btn[data-style="terrain"]');
await page.waitForTimeout(4000);
await shot(page, 'style-switcher-terrain.png');
}
+23 -6
View File
@@ -10,11 +10,22 @@ test.describe('keyword spike modal/badge flow', () => {
const trending = await import('/src/services/trending-keywords.ts');
const correlation = await import('/src/services/correlation.ts');
// The badge/modal render through i18n (t()); the app bootstrap initializes it
// before any component mounts. This isolated harness must do the same, else
// t() returns undefined and getSignalContext().actionableInsight.split() throws.
const { initI18n } = await import('/src/services/i18n.ts');
await initI18n();
const previousConfig = trending.getTrendingConfig();
const headerRight = document.createElement('div');
headerRight.className = 'header-right';
document.body.appendChild(headerRight);
// The findings badge is opt-in (default OFF): its constructor only mounts and
// renders when the user has enabled it. Simulate an opted-in session so the
// badge mounts into .header-right and its count/dropdown render.
localStorage.setItem('worldmonitor-intel-findings', 'shown');
const modal = new SignalModal();
const badge = new IntelligenceGapBadge();
badge.setOnSignalClick((signal) => modal.showSignal(signal));
@@ -27,13 +38,18 @@ test.describe('keyword spike modal/badge flow', () => {
});
const now = new Date();
// Keep the trending proper noun ("Iran") mid-sentence and capitalized: the
// significance filter (isLikelyProperNoun) only counts capitalization for
// tokens that appear past position 0, so a sentence-leading term reads as an
// ordinary word and gets suppressed. Mid-sentence, it registers as a genuine
// entity spiking across sources — no ML worker required.
const headlines = [
{ source: 'Reuters', title: 'Iran sanctions pressure rises amid talks', link: 'https://example.com/reuters/1' },
{ source: 'AP', title: 'Iran sanctions debate intensifies in Washington', link: 'https://example.com/ap/1' },
{ source: 'BBC', title: 'Iran sanctions trigger fresh market concerns', link: 'https://example.com/bbc/1' },
{ source: 'Reuters', title: 'Iran sanctions package draws regional response', link: 'https://example.com/reuters/2' },
{ source: 'AP', title: 'Iran sanctions proposal gains momentum', link: 'https://example.com/ap/2' },
{ source: 'BBC', title: 'Iran sanctions timeline shortens after warnings', link: 'https://example.com/bbc/2' },
{ source: 'Reuters', title: 'Talks on Iran sanctions stall in Washington', link: 'https://example.com/reuters/1' },
{ source: 'AP', title: 'New Iran sanctions debate intensifies among allies', link: 'https://example.com/ap/1' },
{ source: 'BBC', title: 'Markets watch Iran sanctions with fresh concern', link: 'https://example.com/bbc/1' },
{ source: 'Reuters', title: 'Regional powers weigh Iran sanctions package', link: 'https://example.com/reuters/2' },
{ source: 'AP', title: 'Momentum grows for Iran sanctions proposal', link: 'https://example.com/ap/2' },
{ source: 'BBC', title: 'Analysts see Iran sanctions timeline shortening', link: 'https://example.com/bbc/2' },
].map(item => ({
...item,
pubDate: now,
@@ -101,6 +117,7 @@ test.describe('keyword spike modal/badge flow', () => {
if (store?.previousConfig) {
trending.updateTrendingConfig(store.previousConfig);
}
localStorage.removeItem('worldmonitor-intel-findings');
delete (window as unknown as Record<string, unknown>).__keywordSpikeTest;
});
});
+204 -2
View File
@@ -188,8 +188,14 @@ test.describe('layout engine', () => {
);
await page.mouse.up();
// Height grew to a taller row-span and width snapped to multiple columns.
await expect(page.locator('[data-panel="delta"]')).toHaveClass(/span-2/);
// Height grew (fine 16px row grid → a data-span well above the ~100px min) and
// width snapped to multiple columns. Resize lands on the fine grid, not the
// coarse span-N tier classes, so the panel carries `resized` + a data-span.
await expect(page.locator('[data-panel="delta"]')).toHaveClass(/resized/);
const span = await page.evaluate(() =>
parseInt(document.querySelector<HTMLElement>('[data-panel="delta"]')!.dataset.span ?? '0', 10),
);
expect(span).toBeGreaterThan(5); // taller than its start via the fine row grid
const gc = await page.evaluate(() => window.__layoutHarness!.gridColumnOf('delta'));
expect(gc).toMatch(/span [2-9]/);
@@ -237,6 +243,9 @@ test.describe('layout engine', () => {
await page.waitForTimeout(40);
expect(await page.evaluate(() => window.__layoutHarness!.mode())).toBe('free');
// Hold Alt to bypass grid snapping — this test asserts that exact arbitrary-pixel
// geometry survives a reload (snapping has its own tests below).
await page.keyboard.down('Alt');
// Drag alpha by an arbitrary (non-cell) pixel delta.
const start = await rect(page, 'alpha');
const hdr = await headerBox(page, 'alpha');
@@ -273,6 +282,7 @@ test.describe('layout engine', () => {
expect(Math.abs(resized.width - (moved.width + WD))).toBeLessThan(6);
expect(Math.abs(resized.height - (moved.height + HD))).toBeLessThan(6);
await page.keyboard.up('Alt');
// Reload: the mode + exact geometry are restored.
await page.reload();
await page.waitForFunction(() => window.__layoutHarness?.ready === true);
@@ -291,6 +301,9 @@ test.describe('layout engine', () => {
await page.waitForTimeout(40);
expect(await page.evaluate(() => window.__layoutHarness!.mode())).toBe('free');
// Alt bypasses snapping so the shrink is exactly the drag delta; this test is
// about the anchor-pinning invariant, which holds with or without snapping.
await page.keyboard.down('Alt');
const D = 60; // drag each corner inward (toward the panel centre) — always in-bounds
// corner → inward drag sign + which opposite corner must stay pinned.
const cases = [
@@ -337,9 +350,64 @@ test.describe('layout engine', () => {
expect(Math.abs(a.top - b.top)).toBeLessThan(4);
}
}
await page.keyboard.up('Alt');
await page.screenshot({ path: `${SHOTS}/free-all-corners.png` });
});
test('free mode: moving one panel never shifts its siblings (no reflow)', async ({ page }) => {
// The owner's #1 complaint: dragging the map/one panel "shifts all other
// components". In free mode each panel is independent — this proves a big drag
// of one leaves every sibling byte-for-byte where it was.
await lh(page);
await page.evaluate(() => window.__layoutHarness!.setMode('free'));
await page.waitForTimeout(40);
const siblings = ['bravo', 'charlie', 'delta', 'echo'] as const;
const before: Record<string, Rect> = {};
for (const id of siblings) before[id] = await rect(page, id);
const hdr = await headerBox(page, 'alpha');
await page.mouse.move(hdr.x + 30, hdr.y + hdr.height / 2);
await page.mouse.down();
await page.mouse.move(hdr.x + 40, hdr.y + hdr.height / 2, { steps: 3 });
await page.mouse.move(hdr.x + 300, hdr.y + hdr.height / 2 + 200, { steps: 18 });
await page.mouse.up();
for (const id of siblings) {
const a = await rect(page, id);
const b = before[id]!;
expect(Math.abs(a.left - b.left)).toBeLessThan(2);
expect(Math.abs(a.top - b.top)).toBeLessThan(2);
expect(Math.abs(a.width - b.width)).toBeLessThan(2);
expect(Math.abs(a.height - b.height)).toBeLessThan(2);
}
});
test('free mode: a panel resizes narrower than the old 160px min width', async ({ page }) => {
// The owner's #3 complaint: panels are "constrained on min width". Free mode's
// floor is now ~96px, so a panel can be pulled well under the old 160px track.
await lh(page);
await page.evaluate(() => window.__layoutHarness!.setMode('free'));
await page.waitForTimeout(40);
const before = await rect(page, 'bravo');
const corner = (await page
.locator('[data-panel="bravo"] .panel-corner-resize-handle.se')
.boundingBox())!;
// Pull the SE corner far left → collapse width toward the low floor. Hold Alt for
// fine (un-snapped) sizing — snapping would otherwise land on a whole cell (≥160).
await page.keyboard.down('Alt');
await page.mouse.move(corner.x + corner.width / 2, corner.y + corner.height / 2);
await page.mouse.down();
await page.mouse.move(corner.x - before.width, corner.y + corner.height / 2, { steps: 18 });
await page.mouse.up();
await page.keyboard.up('Alt');
const after = await rect(page, 'bravo');
expect(after.width).toBeLessThan(150); // narrower than the old 160px floor
expect(after.width).toBeGreaterThanOrEqual(90); // …but not past the new ~96px floor
});
test('free mode: the map participates with a 240px floor', async ({ page }) => {
await lh(page);
await page.evaluate(() => window.__layoutHarness!.setMode('free'));
@@ -353,6 +421,107 @@ test.describe('layout engine', () => {
expect(r.height).toBeGreaterThanOrEqual(240);
});
test('free mode: dragging snaps to logical grid lines (panels align to shared tracks)', async ({ page }) => {
// The owner's feedback: "the snap is not logical." Two panels dragged to targets
// less than half a cell apart must land on the SAME grid line — proof placement is
// quantised to the logical grid, not arbitrary px.
await lh(page);
await page.evaluate(() => window.__layoutHarness!.setMode('free'));
await page.waitForTimeout(40);
const cell = await page.evaluate(() => window.__layoutHarness!.cell());
const colPitch = cell + 4; // + gap
const rowPitch = 16 + 4; // ROW_UNIT + gap
const dragTo = async (id: string, x: number, y: number) => {
const hdr = await headerBox(page, id);
await page.mouse.move(hdr.x + 20, hdr.y + hdr.height / 2);
await page.mouse.down();
await page.mouse.move(hdr.x + 30, hdr.y + hdr.height / 2, { steps: 3 });
await page.mouse.move(x, y, { steps: 16 });
await page.mouse.up();
};
const gridBox = (await page.locator('#panelsGrid').boundingBox())!;
const tx = gridBox.x + colPitch * 2 + 20;
const ty = gridBox.y + rowPitch * 8 + 30;
await dragTo('alpha', tx, ty);
await dragTo('bravo', tx + 30, ty + 8); // < half a cell/row from alpha's target
const a = await rect(page, 'alpha');
const b = await rect(page, 'bravo');
// Both snapped to the SAME grid line instead of sitting 30/8px apart.
expect(Math.abs(a.left - b.left)).toBeLessThanOrEqual(1);
expect(Math.abs(a.top - b.top)).toBeLessThanOrEqual(1);
});
test('free mode: resizing snaps width to whole cells and pins the opposite edge', async ({ page }) => {
await lh(page);
await page.evaluate(() => window.__layoutHarness!.setMode('free'));
await page.waitForTimeout(40);
const cell = await page.evaluate(() => window.__layoutHarness!.cell());
const GAP = 4;
const before = await rect(page, 'alpha');
const corner = (await page
.locator('[data-panel="alpha"] .panel-corner-resize-handle.se')
.boundingBox())!;
// Pull the SE corner out by a non-cell amount; width must land on a whole-cell size.
await page.mouse.move(corner.x + corner.width / 2, corner.y + corner.height / 2);
await page.mouse.down();
await page.mouse.move(corner.x + corner.width / 2 + 210, corner.y + corner.height / 2, { steps: 16 });
await page.mouse.up();
const after = await rect(page, 'alpha');
// width == N*cell + (N-1)*gap for some integer N ≥ 1.
const n = Math.round((after.width + GAP) / (cell + GAP));
expect(n).toBeGreaterThanOrEqual(1);
expect(Math.abs(after.width - (n * cell + (n - 1) * GAP))).toBeLessThanOrEqual(2);
// The SE resize pins the top-left corner — it must not have moved.
expect(Math.abs(after.left - before.left)).toBeLessThanOrEqual(1);
expect(Math.abs(after.top - before.top)).toBeLessThanOrEqual(1);
});
test('resize handles show no visible glyphs (owner request) but still resize', async ({ page }) => {
await lh(page);
await page.evaluate(() => window.__layoutHarness!.setMode('free'));
await page.waitForTimeout(40);
// The corner/edge resize glyphs are hidden (display:none on the ::after marks) —
// no visible "< >" chevrons — while the handles stay live.
const displays = await page.evaluate(() => {
const d = (sel: string) => {
const el = document.querySelector(sel);
return el ? getComputedStyle(el, '::after').display : 'missing';
};
return {
corner: d('[data-panel="alpha"] .panel-corner-resize-handle.se'),
col: d('[data-panel="alpha"] .panel-col-resize-handle'),
row: d('[data-panel="alpha"] .panel-resize-handle'),
};
});
expect(displays.corner).toBe('none');
expect(displays.col).toBe('none');
expect(displays.row).toBe('none');
// Functionality intact: the (now glyph-less) SE corner still resizes.
const before = await rect(page, 'alpha');
const corner = (await page.locator('[data-panel="alpha"] .panel-corner-resize-handle.se').boundingBox())!;
await page.mouse.move(corner.x + corner.width / 2, corner.y + corner.height / 2);
await page.mouse.down();
await page.mouse.move(corner.x + 180, corner.y + 120, { steps: 12 });
await page.mouse.up();
expect((await rect(page, 'alpha')).width).toBeGreaterThan(before.width + 40);
});
test('cell size can go down to the finer 80px floor', async ({ page }) => {
await lh(page);
await page.evaluate(() => window.__layoutHarness!.setCell(80));
await page.waitForTimeout(30);
expect(await page.evaluate(() => window.__layoutHarness!.cell())).toBe(80);
// Clamped: a request below the floor snaps back up to 80, never lower.
await page.evaluate(() => window.__layoutHarness!.setCell(40));
await page.waitForTimeout(30);
expect(await page.evaluate(() => window.__layoutHarness!.cell())).toBe(80);
});
test('toggle flips grid ⇄ free and back', async ({ page }) => {
await lh(page);
expect(await page.evaluate(() => window.__layoutHarness!.toggle())).toBe('free');
@@ -392,6 +561,11 @@ test.describe('live news video resize (real app)', () => {
await page.goto('/');
await page.waitForSelector(LN, { timeout: 45000 });
await page.waitForTimeout(500);
// The app defaults to free layout now; this test asserts GRID column-span
// semantics, so pin grid explicitly (setLayoutMode marks it an explicit choice
// so the deferred default-to-free won't re-flip it).
await page.evaluate(() => (window as unknown as { worldGrid?: { setLayoutMode(m: string): void } }).worldGrid?.setLayoutMode('grid'));
await page.waitForTimeout(80);
const grid = (await page.locator('#panelsGrid').boundingBox())!;
const ln = page.locator(LN);
@@ -477,3 +651,31 @@ test.describe('live news video resize (real app)', () => {
await page.evaluate(() => (window as unknown as { worldGrid?: { setLayoutMode(m: string): void } }).worldGrid?.setLayoutMode('grid'));
});
});
// Text size / UI scale (accessibility) — real app.
test.describe('text size control (real app)', () => {
test.use({ viewport: { width: 1440, height: 900 } });
test('the dock text-size slider scales panel content and persists across reload', async ({ page }) => {
await page.goto('/');
await page.waitForSelector('[data-panel="live-news"]', { timeout: 45000 });
// Drive the dock "Text size" slider to 1.4.
await page.evaluate(() => {
const el = document.getElementById('dockFontSize') as HTMLInputElement;
el.value = '1.4';
el.dispatchEvent(new Event('input', { bubbles: true }));
});
await expect
.poll(() => page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--ui-scale').trim()))
.toBe('1.4');
expect(await page.evaluate(() => localStorage.getItem('hanzo-world-ui-scale'))).toBe('1.4');
const zoom = await page.evaluate(() => {
const c = document.querySelector('.panel-content');
return c ? getComputedStyle(c).zoom : '';
});
expect(parseFloat(zoom)).toBeCloseTo(1.4, 1);
// Persists across reload (applyStoredUiScale runs at boot).
await page.reload();
await page.waitForSelector('[data-panel="live-news"]', { timeout: 45000 });
expect(await page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--ui-scale').trim())).toBe('1.4');
});
});
+28 -94
View File
@@ -93,17 +93,22 @@ test.describe('desktop runtime routing guardrails', () => {
calls.push(url);
if (url.includes('127.0.0.1:46123/api/fred-data')) {
// The runtime patch only intercepts /v1/world/* paths. It first hits the
// local sidecar (127.0.0.1:46123); on failure it retries the same path
// against the remote API base — same-origin under VITE_VARIANT=full, so the
// fallback arrives as a relative /v1/world/* URL, distinct from the absolute
// local attempt.
if (url.includes('127.0.0.1:46123/v1/world/fred-data')) {
return responseJson({ error: 'missing local api key' }, 500);
}
if (url.includes('worldmonitor.app/api/fred-data')) {
if (url.startsWith('/v1/world/fred-data')) {
return responseJson({ observations: [{ value: '321.5' }] }, 200);
}
if (url.includes('127.0.0.1:46123/api/stablecoin-markets')) {
if (url.includes('127.0.0.1:46123/v1/world/stablecoin-markets')) {
throw new Error('ECONNREFUSED');
}
if (url.includes('worldmonitor.app/api/stablecoin-markets')) {
if (url.startsWith('/v1/world/stablecoin-markets')) {
return responseJson({ stablecoins: [{ symbol: 'USDT' }] }, 200);
}
@@ -117,10 +122,10 @@ test.describe('desktop runtime routing guardrails', () => {
try {
runtime.installRuntimeFetchPatch();
const fredResponse = await window.fetch('/api/fred-data?series_id=CPIAUCSL');
const fredResponse = await window.fetch('/v1/world/fred-data?series_id=CPIAUCSL');
const fredBody = await fredResponse.json() as { observations?: Array<{ value: string }> };
const stableResponse = await window.fetch('/api/stablecoin-markets');
const stableResponse = await window.fetch('/v1/world/stablecoin-markets');
const stableBody = await stableResponse.json() as { stablecoins?: Array<{ symbol: string }> };
return {
@@ -146,10 +151,10 @@ test.describe('desktop runtime routing guardrails', () => {
expect(result.stableStatus).toBe(200);
expect(result.stableSymbol).toBe('USDT');
expect(result.calls.some((url) => url.includes('127.0.0.1:46123/api/fred-data'))).toBe(true);
expect(result.calls.some((url) => url.includes('worldmonitor.app/api/fred-data'))).toBe(true);
expect(result.calls.some((url) => url.includes('127.0.0.1:46123/api/stablecoin-markets'))).toBe(true);
expect(result.calls.some((url) => url.includes('worldmonitor.app/api/stablecoin-markets'))).toBe(true);
expect(result.calls.some((url) => url.includes('127.0.0.1:46123/v1/world/fred-data'))).toBe(true);
expect(result.calls.some((url) => url.startsWith('/v1/world/fred-data'))).toBe(true);
expect(result.calls.some((url) => url.includes('127.0.0.1:46123/v1/world/stablecoin-markets'))).toBe(true);
expect(result.calls.some((url) => url.startsWith('/v1/world/stablecoin-markets'))).toBe(true);
});
test('chunk preload reload guard is one-shot until app boot clears it', async ({ page }) => {
@@ -225,64 +230,12 @@ test.describe('desktop runtime routing guardrails', () => {
expect(result.storedValue).toBe('1');
});
test('update badge picks architecture-correct desktop download url', async ({ page }) => {
await page.goto('/tests/runtime-harness.html');
const result = await page.evaluate(async () => {
const { App } = await import('/src/App.ts');
const globalWindow = window as unknown as {
__TAURI__?: { core?: { invoke?: (command: string) => Promise<unknown> } };
};
const previousTauri = globalWindow.__TAURI__;
const releaseUrl = 'https://github.com/koala73/worldmonitor/releases/latest';
const appProto = App.prototype as unknown as {
resolveUpdateDownloadUrl: (releaseUrl: string) => Promise<string>;
mapDesktopDownloadPlatform: (os: string, arch: string) => string | null;
};
const fakeApp = {
mapDesktopDownloadPlatform: appProto.mapDesktopDownloadPlatform,
};
try {
globalWindow.__TAURI__ = {
core: {
invoke: async (command: string) => {
if (command !== 'get_desktop_runtime_info') throw new Error(`Unexpected command: ${command}`);
return { os: 'macos', arch: 'aarch64' };
},
},
};
const macArm = await appProto.resolveUpdateDownloadUrl.call(fakeApp, releaseUrl);
globalWindow.__TAURI__ = {
core: {
invoke: async () => ({ os: 'windows', arch: 'amd64' }),
},
};
const windowsX64 = await appProto.resolveUpdateDownloadUrl.call(fakeApp, releaseUrl);
globalWindow.__TAURI__ = {
core: {
invoke: async () => ({ os: 'linux', arch: 'x86_64' }),
},
};
const linuxFallback = await appProto.resolveUpdateDownloadUrl.call(fakeApp, releaseUrl);
return { macArm, windowsX64, linuxFallback };
} finally {
if (previousTauri === undefined) {
delete globalWindow.__TAURI__;
} else {
globalWindow.__TAURI__ = previousTauri;
}
}
});
expect(result.macArm).toBe('https://worldmonitor.app/api/download?platform=macos-arm64');
expect(result.windowsX64).toBe('https://worldmonitor.app/api/download?platform=windows-exe');
expect(result.linuxFallback).toBe('https://github.com/koala73/worldmonitor/releases/latest');
});
// The upstream worldmonitor.app update-badge + arch-aware desktop-download
// machinery (App.resolveUpdateDownloadUrl / mapDesktopDownloadPlatform, driven by
// the get_desktop_runtime_info Tauri command) was removed for Hanzo —
// App.checkForUpdate is now a deliberate no-op and downloads are served from
// /v1/world/download?platform=* via DownloadBanner. No behavior remains to assert
// here, so the obsolete arch-resolution test was removed.
test('loadMarkets keeps Yahoo-backed data when Finnhub is skipped', async ({ page }) => {
await page.goto('/tests/runtime-harness.html');
@@ -324,8 +277,6 @@ test.describe('desktop runtime routing guardrails', () => {
const marketConfigErrors: string[] = [];
const heatmapRenders: number[] = [];
const heatmapConfigErrors: string[] = [];
const commoditiesRenders: number[] = [];
const commoditiesConfigErrors: string[] = [];
const cryptoRenders: number[] = [];
const apiStatuses: Array<{ name: string; status: string }> = [];
@@ -334,7 +285,7 @@ test.describe('desktop runtime routing guardrails', () => {
calls.push(url);
const parsed = new URL(url);
if (parsed.pathname === '/api/finnhub') {
if (parsed.pathname === '/v1/world/finnhub') {
return responseJson({
quotes: [],
skipped: true,
@@ -342,12 +293,14 @@ test.describe('desktop runtime routing guardrails', () => {
});
}
if (parsed.pathname === '/api/yahoo-finance') {
const symbol = parsed.searchParams.get('symbol') ?? 'UNKNOWN';
return responseJson(yahooChart(symbol));
if (parsed.pathname === '/v1/world/yahoo-batch') {
const symbols = (parsed.searchParams.get('symbols') ?? '').split(',').filter(Boolean);
return responseJson({
results: symbols.map((symbol) => ({ symbol, chart: yahooChart(symbol) })),
});
}
if (parsed.pathname === '/api/coingecko') {
if (parsed.pathname === '/v1/world/coingecko') {
return responseJson([
{ id: 'bitcoin', current_price: 50000, price_change_percentage_24h: 1.2, sparkline_in_7d: { price: [1, 2, 3] } },
{ id: 'ethereum', current_price: 3000, price_change_percentage_24h: -0.5, sparkline_in_7d: { price: [1, 2, 3] } },
@@ -369,10 +322,6 @@ test.describe('desktop runtime routing guardrails', () => {
renderHeatmap: (data: Array<unknown>) => heatmapRenders.push(data.length),
showConfigError: (message: string) => heatmapConfigErrors.push(message),
},
commodities: {
renderCommodities: (data: Array<unknown>) => commoditiesRenders.push(data.length),
showConfigError: (message: string) => commoditiesConfigErrors.push(message),
},
crypto: {
renderCrypto: (data: Array<unknown>) => cryptoRenders.push(data.length),
},
@@ -388,25 +337,14 @@ test.describe('desktop runtime routing guardrails', () => {
await (App.prototype as unknown as { loadMarkets: (thisArg: unknown) => Promise<void> })
.loadMarkets.call(fakeApp);
const commoditySymbols = ['^VIX', 'GC=F', 'CL=F', 'NG=F', 'SI=F', 'HG=F'];
const commodityYahooCalls = commoditySymbols.map((symbol) =>
calls.some((url) => {
const parsed = new URL(url);
return parsed.pathname === '/api/yahoo-finance' && parsed.searchParams.get('symbol') === symbol;
})
);
return {
marketRenders,
marketConfigErrors,
heatmapRenders,
heatmapConfigErrors,
commoditiesRenders,
commoditiesConfigErrors,
cryptoRenders,
apiStatuses,
latestMarketsCount: fakeApp.latestMarkets.length,
commodityYahooCalls,
};
} finally {
window.fetch = originalFetch;
@@ -420,10 +358,6 @@ test.describe('desktop runtime routing guardrails', () => {
expect(result.heatmapRenders.length).toBe(0);
expect(result.heatmapConfigErrors).toEqual(['FINNHUB_API_KEY not configured — add in Settings']);
expect(result.commoditiesRenders.some((count) => count > 0)).toBe(true);
expect(result.commoditiesConfigErrors.length).toBe(0);
expect(result.commodityYahooCalls.every(Boolean)).toBe(true);
expect(result.cryptoRenders.some((count) => count > 0)).toBe(true);
expect(result.apiStatuses.some((entry) => entry.name === 'Finnhub' && entry.status === 'error')).toBe(true);
expect(result.apiStatuses.some((entry) => entry.name === 'CoinGecko' && entry.status === 'ok')).toBe(true);
+56
View File
@@ -0,0 +1,56 @@
import { expect, test } from '@playwright/test';
// News Wall — every live news channel at once, hover a tile for AUDIO FOCUS.
//
// The panel is opt-in (enabled:false, like Live Webcams), and its grid + N YouTube
// players build LAZILY the first time it scrolls into view. This test un-hides it and
// brings it into view to trigger that build, then asserts: one tile per channel, and
// that hovering a tile gives EXACTLY that tile audio focus (the .stations-audio-on ring
// + 🔊 badge) while muting the rest — the "hover to enable voice" behavior.
//
// The YouTube players themselves need real GL + network; the audio-FOCUS logic (class +
// badge toggling, and the mute()/unMute() calls it drives) runs regardless of whether a
// player finished loading, so the focus behavior is what we assert. We block the YT
// embed so the test stays hermetic and fast — the tiles + their hover handlers are built
// before (and independent of) the players.
test.describe('News Wall — all stations at once, hover for audio', () => {
test('one tile per channel; hover moves single audio focus; leaving mutes all', async ({ page }) => {
await page.route('**/*youtube*/**', (r) => r.abort());
await page.goto('/?variant=full');
// Un-hide the opt-in panel and scroll it into view → its IntersectionObserver fires
// → the wall builds. (Toggling it on via the Panels menu is a separate trivial path.)
await page.locator('.panel[data-panel="stations-wall"]').waitFor({ state: 'attached', timeout: 30000 });
await page.evaluate(() => {
const el = document.querySelector('.panel[data-panel="stations-wall"]') as HTMLElement | null;
el?.classList.remove('hidden');
el?.scrollIntoView();
});
// One tile per channel (full variant ships ≥ 4 news channels).
const tiles = page.locator('.stations-tile');
await expect(tiles.first()).toBeVisible({ timeout: 30000 });
expect(await tiles.count()).toBeGreaterThanOrEqual(4);
// Nothing focused initially → no tile is unmuted.
await expect(page.locator('.stations-tile.stations-audio-on')).toHaveCount(0);
// Hover the first tile → exactly it gets audio focus + the 🔊 badge.
await tiles.nth(0).hover();
await expect(page.locator('.stations-tile.stations-audio-on')).toHaveCount(1);
await expect(tiles.nth(0)).toHaveClass(/stations-audio-on/);
await expect(tiles.nth(0).locator('.stations-audio')).toHaveText('🔊');
// Hover a second tile → focus MOVES (still exactly one); the first is muted again.
await tiles.nth(1).hover();
await expect(page.locator('.stations-tile.stations-audio-on')).toHaveCount(1);
await expect(tiles.nth(1)).toHaveClass(/stations-audio-on/);
await expect(tiles.nth(0)).not.toHaveClass(/stations-audio-on/);
// Leaving the wall entirely mutes everything.
await page.locator('.stations-grid').dispatchEvent('mouseleave');
await expect(page.locator('.stations-tile.stations-audio-on')).toHaveCount(0);
});
});
+92
View File
@@ -0,0 +1,92 @@
import { expect, test, type Page } from '@playwright/test';
// Markets Bubble — the whole market universe as one D3 circle-pack.
//
// The panel is fed by the shared market-universe service (Yahoo passthrough +
// CoinGecko), joined to the universe metadata. We mock both endpoints with small
// deterministic fixtures, un-hide the opt-in panel and scroll it into view to trip
// its IntersectionObserver → lazy build (same path stations-wall uses; the full
// variant has no finance TradingView terminal to occlude the hover). Then we assert:
// bubbles render across the classes (a class ring/label per class, many leaf
// circles), hovering a leaf shows the tooltip with a signed %, and the panel survives
// a live re-poll (under VITE_E2E the poll runs on a short cadence and the service
// cache TTL is tiny, so a real second round-trip happens within the test).
// Deterministic percent moves — a mix of up/down plus a big mover, so leaves span the
// green→red diverging scale.
const PCTS = [3.4, -2.6, 0.3, -4.8, 1.9, -0.7, 2.2, -1.4];
function yahooBatchBody(url: string): unknown {
const symbols = (new URL(url).searchParams.get('symbols') ?? '').split(',').filter(Boolean);
const results = symbols.map((symbol, i) => {
const pct = PCTS[i % PCTS.length];
const price = 100 + i;
const previousClose = price / (1 + pct / 100);
return {
symbol,
chart: {
chart: {
result: [
{
meta: { regularMarketPrice: price, previousClose },
indicators: { quote: [{ close: [previousClose, price] }] },
},
],
},
},
};
});
return { results };
}
const COINGECKO = [
{ id: 'bitcoin', current_price: 62000, price_change_percentage_24h: 2.8, sparkline_in_7d: { price: [61000, 62000] } },
{ id: 'ethereum', current_price: 3400, price_change_percentage_24h: -1.9, sparkline_in_7d: { price: [3450, 3400] } },
{ id: 'solana', current_price: 145, price_change_percentage_24h: 5.1, sparkline_in_7d: { price: [138, 145] } },
];
test.describe('Markets Bubble — every asset class as one circle-pack', () => {
test('renders bubbles across classes, tooltips on hover, and survives a re-poll', async ({ page }) => {
let batchHits = 0;
const json = (body: unknown) => ({ status: 200, contentType: 'application/json', body: JSON.stringify(body) });
await page.route('**/v1/world/yahoo-batch**', (r) => {
batchHits += 1;
return r.fulfill(json(yahooBatchBody(r.request().url())));
});
await page.route('**/v1/world/coingecko**', (r) => r.fulfill(json(COINGECKO)));
await page.goto('/?variant=full');
// Un-hide the opt-in panel and scroll it into view → IntersectionObserver fires →
// the bubble builds lazily.
const panel = page.locator('.panel[data-panel="trading-bubble"]');
await panel.waitFor({ state: 'attached', timeout: 30000 });
await page.evaluate(() => {
const el = document.querySelector('.panel[data-panel="trading-bubble"]') as HTMLElement | null;
el?.classList.remove('hidden');
el?.scrollIntoView();
});
// Leaf circles render — the universe has 34 Yahoo symbols + 3 crypto, so plenty.
const leaves = page.locator('.trading-bubble .tb-leaf-circle');
await expect(leaves.first()).toBeVisible({ timeout: 30000 });
expect(await leaves.count()).toBeGreaterThan(20);
// One cluster per class present — all five classes are mocked, so ≥ 3.
const classLabels = page.locator('.trading-bubble .tb-class-label');
expect(await classLabels.count()).toBeGreaterThanOrEqual(3);
// Hover the largest bubble → tooltip appears with a signed %.
await leaves.first().hover();
const tooltip = page.locator('.trading-bubble-tooltip.visible');
await expect(tooltip).toBeVisible({ timeout: 10000 });
await expect(tooltip.locator('.tb-tt-chg')).toContainText('%');
// Survives a live re-poll: the short-cadence e2e poll makes a second upstream
// round-trip, and the circles are reused by id (count stays stable, no teardown).
const before = await leaves.count();
await expect.poll(() => batchHits, { timeout: 12000 }).toBeGreaterThan(1);
await expect(leaves.first()).toBeVisible();
expect(await leaves.count()).toBe(before);
});
});
+9
View File
@@ -58,6 +58,15 @@ async function appReady(page: Page): Promise<void> {
/** Inject a news-shaped item — the exact data-ctx-* convention NewsPanel emits. */
async function addNewsItem(page: Page): Promise<void> {
// The app defaults to FREE layout (absolutely-positioned panels); a raw injected
// panel has no coordinates and stacks at 0,0 under the full-width map, which then
// eats the right-click. Pin grid mode so the injected panel flows to the grid end
// and is a normal, hit-testable child (real news items are positioned by the
// layout engine — only this raw test injection needs the nudge).
await page.evaluate(() =>
(window as unknown as { worldGrid?: { setLayoutMode(m: string): void } }).worldGrid?.setLayoutMode('grid'),
);
await page.waitForTimeout(80);
await page.evaluate(() => {
const grid = document.querySelector('#panelsGrid')!;
const panel = document.createElement('div');
+120
View File
@@ -0,0 +1,120 @@
import { expect, test } from '@playwright/test';
// In-place variant switch (the tab-switch freeze fix).
//
// The header variant tabs [Cloud | AI | Crypto | Finance | Tech | World] used to
// switch by setting window.location.href — a full page reload that re-created the
// deck.gl WebGL context, respawned the ML workers, re-mounted the video iframes and
// cold-refetched every feed. That churn WAS the freeze. The switch is now in place:
// recompute the target variant's config and re-apply it live, like the intra-variant
// panel toggle — no reload, heavy singletons kept warm.
//
// The airtight proof of "no reload": inject a sentinel into the JS context AFTER the
// app boots. A full navigation destroys the context and wipes the sentinel; an
// in-place switch preserves it. We also assert the SAME <canvas> survives (deck.gl
// not torn down), the panel set swaps, the active tab + URL re-point, and the switch
// is fast.
const TRAFFIC = {
updatedAt: '2026-07-18T12:00:00Z',
live: true,
window: { minutes: 60, since: '2026-07-18T11:00:00Z', until: '2026-07-18T12:00:00Z' },
points: [
{ country: 'US', lat: 37.09, lon: -95.71, count: 42, byService: { models: 42 } },
{ country: 'GB', lat: 55.38, lon: -3.44, count: 12, byService: { models: 12 } },
],
totals: { rps_1m: 0.9, rpm_60m: 54, top_countries: [{ country: 'US', count: 42 }, { country: 'GB', count: 12 }] },
};
async function mockCloud(page: import('@playwright/test').Page): Promise<void> {
const json = (body: unknown) => ({ status: 200, contentType: 'application/json', body: JSON.stringify(body) });
await page.route('**/v1/world/cloud/traffic-globe', (r) => r.fulfill(json(TRAFFIC)));
await page.route('**/v1/world/cloud/traffic', (r) => r.fulfill(json({ updatedAt: TRAFFIC.updatedAt, demo: false, arcs: [] })));
await page.route('**/v1/world/cloud/chain-nodes', (r) => r.fulfill(json({ updatedAt: TRAFFIC.updatedAt, positionsModeled: true, networks: [] })));
await page.route('**/v1/world/cloud/byo-gpu', (r) => r.fulfill(json({ updatedAt: TRAFFIC.updatedAt, demo: false, gpus: [] })));
}
test.describe('Variant switch — in place, no reload', () => {
test('switching tabs keeps the JS context, the globe canvas, and swaps the panel set', async ({ page }) => {
await mockCloud(page);
await page.goto('/?variant=cloud');
// Reveal the switcher (flagship cloud starts collapsed behind the H toggle).
await page.locator('[data-hanzo-toggle]').click();
const switcher = page.locator('.variant-switcher');
await expect(switcher).toBeVisible();
await expect(page.locator('.variant-option[data-variant="cloud"].active')).toHaveCount(1);
// The globe mounts ONE deck.gl <canvas>. Marking it lets us later prove it is the
// SAME element after a switch (WebGL context never torn down). This is a bonus
// proof layered on top of the airtight sentinel below: it only fires where a GL
// context actually renders. Under headless swiftshader (CI) deck.gl may not create
// a canvas at all, and in the immersive cloud view the globe is a fixed background
// rather than a panel child — so we mark the canvas IF one is present and gate the
// identity assertions on that, instead of blocking the whole test on GL rendering.
const globe = page.locator('canvas').first();
const canvasMarked = await globe
.waitFor({ state: 'attached', timeout: 15000 })
.then(() => globe.evaluate((c) => { (c as HTMLCanvasElement & { __globeMark?: string }).__globeMark = 'orig'; }))
.then(() => true)
.catch(() => false);
const globeSurvived = async (): Promise<boolean> =>
!canvasMarked ||
(await globe.evaluate((c) => (c as HTMLCanvasElement & { __globeMark?: string }).__globeMark === 'orig').catch(() => false));
// Sentinel in the live JS context. A reload destroys the context → the sentinel
// is gone. Survival across a tab click == no navigation happened.
await page.evaluate(() => {
(window as unknown as { __noReload?: string }).__noReload = 'sentinel';
window.addEventListener('beforeunload', () => {
(window as unknown as { __unloaded?: boolean }).__unloaded = true;
});
});
// Switch Cloud → AI.
await page.locator('.variant-option[data-variant="ai"]').click();
await page.waitForFunction(() => new URLSearchParams(location.search).get('variant') === 'ai', undefined, { timeout: 20000 });
// The switch's SYNCHRONOUS cost — the actual "is it a cold-start freeze?" measure —
// is recorded on window.__switchT by setSiteVariant. This is the honest perf gate:
// it times the switch code itself, immune to boot/GL thread-contention that inflates
// wall-clock under headless software rendering (where the click merely queues behind
// the cold globe render). A reload would cold-start everything; the in-place switch
// is a few ms.
const switchCost = await page.evaluate(() => (window as unknown as { __switchT?: { total?: number } }).__switchT?.total ?? -1);
expect(switchCost, `in-place switch synchronous cost was ${switchCost}ms`).toBeGreaterThanOrEqual(0);
expect(switchCost, `in-place switch synchronous cost was ${switchCost}ms`).toBeLessThan(500);
// The active tab + URL re-pointed to AI, with NO reload.
await expect(page.locator('.variant-option[data-variant="ai"].active')).toHaveCount(1);
await expect(page.locator('.variant-option[data-variant="cloud"].active')).toHaveCount(0);
await expect(page).toHaveURL(/variant=ai/);
// The airtight assertions: the JS context survived (sentinel intact, no unload) —
// a reload would have wiped both. Plus, where a GL canvas rendered, it is the very
// same element (globe/WebGL never torn down).
expect(await page.evaluate(() => (window as unknown as { __noReload?: string }).__noReload)).toBe('sentinel');
expect(await page.evaluate(() => (window as unknown as { __unloaded?: boolean }).__unloaded)).toBeFalsy();
expect(await globeSurvived()).toBe(true);
// The panel set swapped in place: an AI panel is now visible, the cloud-only
// live-traffic panel is hidden (kept alive, just `.hidden`).
await expect(page.locator('.panel[data-panel="ai-compute"]:not(.hidden)')).toHaveCount(1);
await expect(page.locator('.panel[data-panel="traffic-globe"]:not(.hidden)')).toHaveCount(0);
// Two more switches to prove it holds across the family, still no reload.
await page.locator('.variant-option[data-variant="finance"]').click();
await expect(page).toHaveURL(/variant=finance/);
await expect(page.locator('.variant-option[data-variant="finance"].active')).toHaveCount(1);
// Finance markets panel shows; the AI compute panel is hidden.
await expect(page.locator('.panel[data-panel="markets"]:not(.hidden)')).toHaveCount(1);
await page.locator('.variant-option[data-variant="full"]').click();
await expect(page.locator('.variant-option[data-variant="full"].active')).toHaveCount(1);
await expect(page).not.toHaveURL(/variant=/); // full is the canonical default — no param
// Still the same context + same globe canvas after three switches.
expect(await page.evaluate(() => (window as unknown as { __noReload?: string }).__noReload)).toBe('sentinel');
expect(await globeSurvived()).toBe(true);
});
});
+56 -25
View File
@@ -19,6 +19,14 @@ async function appReady(page: Page): Promise<void> {
undefined,
{ timeout: 45000 },
);
// The app now DEFAULTS to free layout (independent, non-reflowing panels). These
// specs exercise the GRID reorder/ghost/row-span/reset machinery specifically, so
// pin grid mode (still a first-class, dropdown-selectable mode). setLayoutMode
// marks the choice explicit, so the deferred default-to-free never re-flips it.
await page.evaluate(() =>
(window as unknown as { worldGrid?: { setLayoutMode(m: string): void } }).worldGrid?.setLayoutMode('grid'),
);
await page.waitForTimeout(80);
}
function gridOrder(page: Page): Promise<(string | undefined)[]> {
@@ -29,6 +37,43 @@ function gridOrder(page: Page): Promise<(string | undefined)[]> {
);
}
// Reorder by dragging a LATER on-screen content panel UP onto an EARLIER one, and
// return the moved panel's key. The grid is far taller than the viewport, so a drop
// at the grid's geometric bottom lands in empty space with no panel to reorder
// against; the reorder needs a real panel under the pointer. Dragging up (later →
// earlier) guarantees the DOM order changes — dragging an earlier panel down onto
// its adjacent neighbour would re-drop it exactly where it already sits.
async function dragReorderOnScreen(page: Page): Promise<string> {
const onscreen = await page.evaluate(() =>
Array.from(document.querySelectorAll('#panelsGrid .panel'))
.map((p) => {
const r = (p as HTMLElement).getBoundingClientRect();
return { k: (p as HTMLElement).dataset.panel, y: r.y, cy: r.y + r.height / 2 };
})
// grabbable header + droppable centre inside the viewport; the map + live-news
// are pinned anchors, never reorder subjects.
.filter((b) => b.k && b.k !== 'map' && b.k !== 'live-news' && b.y > 60 && b.cy < 680)
.map((b) => b.k as string),
);
expect(onscreen.length).toBeGreaterThan(1);
const target = onscreen[0];
const movable = onscreen[onscreen.length - 1];
const sb = (await page.locator(`#panelsGrid .panel[data-panel="${movable}"] .panel-header`).first().boundingBox())!;
const tb = (await page.locator(`#panelsGrid .panel[data-panel="${target}"]`).boundingBox())!;
await page.mouse.move(sb.x + 40, sb.y + sb.height / 2);
await page.mouse.down();
await page.mouse.move(sb.x + 60, sb.y + sb.height / 2 + 20, { steps: 6 }); // cross the 6px press threshold
// The reorder decides insert-before vs -after purely by X (panel-drag.ts: a drop
// on the target's LEFT half inserts before it). Aim well inside the left quarter,
// not the centre, so the drop is unambiguously "before" and doesn't oscillate on
// the gap-opening FLIP reflow; after inserting, the pointer rests over the moved
// (excluded) source, so no further reorder fires.
await page.mouse.move(tb.x + tb.width * 0.25, tb.y + tb.height / 2, { steps: 18 });
await page.mouse.up();
return movable;
}
test.describe('video panel drag + reset (live app)', () => {
test('the live-news video panel is grabbable by its header and its iframe yields during drag', async ({ page }) => {
await appReady(page);
@@ -62,18 +107,7 @@ test.describe('video panel drag + reset (live app)', () => {
await appReady(page);
const before = await gridOrder(page);
// Pick a mid-grid draggable content panel (not live-news, which is pinned).
const movable = before.find((k) => k && k !== 'live-news' && k !== 'map')!;
const src = page.locator(`#panelsGrid .panel[data-panel="${movable}"]`);
const sb = (await src.locator('.panel-header').first().boundingBox())!;
const grid = (await page.locator('#panelsGrid').boundingBox())!;
await page.mouse.move(sb.x + 40, sb.y + sb.height / 2);
await page.mouse.down();
await page.mouse.move(sb.x + 60, sb.y + sb.height / 2 + 20, { steps: 6 });
// Sweep to the bottom of the grid → drop near the end.
await page.mouse.move(grid.x + grid.width * 0.5, grid.y + grid.height - 30, { steps: 18 });
await page.mouse.up();
const movable = await dragReorderOnScreen(page);
const after = await gridOrder(page);
expect(after).not.toEqual(before);
@@ -94,7 +128,12 @@ test.describe('video panel drag + reset (live app)', () => {
await page.mouse.move(h.x + h.width / 2, h.y + h.height / 2 + 230, { steps: 14 });
await page.mouse.up();
await expect(panel).toHaveClass(/span-2/);
// Height resize lands on the fine 16px row grid (smooth ~20px steps), so the
// panel carries `resized` + a data-span well above the ~100px minSpan — not the
// coarse span-2 tier class the old assertion expected.
await expect(panel).toHaveClass(/resized/);
const span = await panel.evaluate((el) => parseInt((el as HTMLElement).dataset.span ?? '0', 10));
expect(span).toBeGreaterThan(5);
});
test('Reset layout returns the grid to the default order', async ({ page }) => {
@@ -102,15 +141,7 @@ test.describe('video panel drag + reset (live app)', () => {
const original = await gridOrder(page);
// Reorder a panel so the layout is dirty.
const movable = original.find((k) => k && k !== 'live-news' && k !== 'map')!;
const src = page.locator(`#panelsGrid .panel[data-panel="${movable}"]`);
const sb = (await src.locator('.panel-header').first().boundingBox())!;
const grid = (await page.locator('#panelsGrid').boundingBox())!;
await page.mouse.move(sb.x + 40, sb.y + sb.height / 2);
await page.mouse.down();
await page.mouse.move(sb.x + 60, sb.y + sb.height / 2 + 20, { steps: 6 });
await page.mouse.move(grid.x + grid.width * 0.5, grid.y + grid.height - 30, { steps: 18 });
await page.mouse.up();
await dragReorderOnScreen(page);
expect(await gridOrder(page)).not.toEqual(original);
// Open the Panels menu and hit Reset layout (this reloads the app).
@@ -121,11 +152,11 @@ test.describe('video panel drag + reset (live app)', () => {
page.click('#resetLayoutBtn'),
]);
// After reset+reload the grid rebuilds from DEFAULT_PANELS: live-news first,
// and the order matches a fresh session.
// After reset+reload the grid rebuilds from DEFAULT_PANELS: the full-width map
// is the leading anchor, and the order matches a fresh session.
await appReady(page);
const reset = await gridOrder(page);
expect(reset[0]).toBe('live-news');
expect(reset[0]).toBe('map');
expect(reset).toEqual(original);
});
});
+13 -7
View File
@@ -1,24 +1,30 @@
module github.com/hanzoai/world
go 1.25.0
go 1.26.4
require (
github.com/alicebob/miniredis/v2 v2.38.0
github.com/hanzoai/sqlite v0.3.2
github.com/redis/go-redis/v9 v9.20.0
modernc.org/sqlite v1.51.0
golang.org/x/net v0.54.0
)
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/hanzoai/csqlite v0.1.0 // indirect
github.com/hanzoai/sqlcipher v0.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/mattn/go-isatty v0.0.21 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/sys v0.42.0 // indirect
modernc.org/libc v1.72.3 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
golang.org/x/crypto v0.52.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.37.0 // indirect
)
+26 -51
View File
@@ -6,70 +6,45 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/hanzoai/csqlite v0.1.0 h1:suwC3dh0INlfP/U0Es6cDf6JNQ+2+GVLLATPWCUux6k=
github.com/hanzoai/csqlite v0.1.0/go.mod h1:H31a/O6VXuklR9UBkgY++bmAK5uzVfXPqU0F6P9Wsos=
github.com/hanzoai/sqlcipher v0.1.0 h1:V9gKG3ZltN2ZCteDrOnXWfOeEe/YDhhUm9AorQEAuBo=
github.com/hanzoai/sqlcipher v0.1.0/go.mod h1:F0soUYM1i4sawOZUpRvVnWoUayPbeGVlGq01VXy9Aqg=
github.com/hanzoai/sqlite v0.3.2 h1:B/TRunlIDZECEypmr6rHeNyWf37YZXvPJHBDEFMKn/g=
github.com/hanzoai/sqlite v0.3.2/go.mod h1:a3llsefKbu2Iq/0rJ1mlWCaU2t2cXh+aze85x+oW72k=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLGs=
github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.20.0 h1:WnQYxLkgO2xiXTCJY0ldIiI8dNqCDlQAG+AtaH7a2a0=
github.com/redis/go-redis/v9 v9.20.0/go.mod h1:v/M13XI1PVCDcm01VtPFOADfZtHf8YW3baQf57KlIkA=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
modernc.org/cc/v4 v4.28.2 h1:3tQ0lf2ADtoby2EtSP+J7IE2SHwEJdP8ioR59wx7XpY=
modernc.org/cc/v4 v4.28.2/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
modernc.org/ccgo/v4 v4.34.0 h1:yRLPFZieg532OT4rp4JFNIVcquwalMX26G95WQDqwCQ=
modernc.org/ccgo/v4 v4.34.0/go.mod h1:AS5WYMyBakQ+fhsHhtP8mWB82KTGPkNNJDGfGQCe0/A=
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
modernc.org/gc/v3 v3.1.2 h1:ZtDCnhonXSZexk/AYsegNRV1lJGgaNZJuKjJSWKyEqo=
modernc.org/gc/v3 v3.1.2/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
modernc.org/libc v1.72.3 h1:ZnDF4tXn4NBXFutMMQC4vtbTFSXhhKzR73fv0beZEAU=
modernc.org/libc v1.72.3/go.mod h1:dn0dZNnnn1clLyvRxLxYExxiKRZIRENOfqQ8XEeg4Qs=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/sqlite v1.51.0 h1:aH/MMSoayAIhozZ7uJbVTT9QO/VhzBf0J9tymmmuC/U=
modernc.org/sqlite v1.51.0/go.mod h1:tcNzv5p84E0skkmJn038y+hWJbLQXQqEnQfeh5r2JLM=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988=
golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc=
golang.org/x/net v0.54.0 h1:2zJIZAxAHV/OHCDTCOHAYehQzLfSXuf/5SoL/Dv6w/w=
golang.org/x/net v0.54.0/go.mod h1:Sj4oj8jK6XmHpBZU/zWHw3BV3abl4Kvi+Ut7cQcY+cQ=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+9
View File
@@ -13,6 +13,15 @@ images:
context: .
dockerfile: Dockerfile
repo: ghcr.io/hanzoai/world
# Publishable Mapbox token (pk, URL-restricted to world.hanzo.ai) baked into
# the Vite SPA at build so the Satellite/Terrain basemaps load (Dark stays
# keyless CartoDB). Sourced from KMS (hanzo/deploy/VITE_MAPBOX_TOKEN,
# env=prod) by hanzoai/ci — the key name IS the build-arg. Never in git.
build_secrets:
- VITE_MAPBOX_TOKEN
- VITE_SENTRY_DSN
- VITE_ANALYTICS_WEBSITE_ID
- VITE_GTM_ID
# Deploy: roll the freshly-built image onto the `world` Service CR. Fires only
# on `main` (+ tags); PRs and forks build but never deploy. KMS hands back the
+1 -1
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; connect-src 'self' https: http://localhost:5173 http://127.0.0.1:46123 ws: wss: blob: data:; img-src 'self' data: blob: https:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' https://www.youtube.com https://static.cloudflareinsights.com; worker-src 'self' blob:; font-src 'self' data: https:; media-src 'self' data: blob: https:; frame-src 'self' http://127.0.0.1:46123 https://www.youtube.com https://www.youtube-nocookie.com;" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; connect-src 'self' https: http://localhost:5173 http://127.0.0.1:46123 ws: wss: blob: data:; img-src 'self' data: blob: https:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' https://analytics.hanzo.ai https://www.youtube.com https://static.cloudflareinsights.com https://www.googletagmanager.com https://www.google-analytics.com https://connect.facebook.net https://snap.licdn.com https://static.ads-twitter.com https://s3.tradingview.com https://s.tradingview.com; worker-src 'self' blob:; font-src 'self' data: https:; media-src 'self' data: blob: https:; frame-src 'self' http://127.0.0.1:46123 https://www.youtube.com https://www.youtube-nocookie.com https://www.tradingview-widget.com https://s.tradingview.com https://www.tradingview.com;" />
<meta name="referrer" content="strict-origin-when-cross-origin" />
<!-- Primary Meta Tags -->
+35 -3
View File
@@ -121,7 +121,13 @@ type chatResponse struct {
Choices []struct {
Message struct {
Content string `json:"content"`
// A reasoning model (gpt-oss / harmony, deepseek-r1) surfaces its working
// on a SEPARATE channel; when it emits no final content we fall back to
// this so the analyst still recovers an answer, not a blank "empty response".
ReasoningContent string `json:"reasoning_content"`
Reasoning string `json:"reasoning"`
} `json:"message"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
Usage struct {
TotalTokens int `json:"total_tokens"`
@@ -203,10 +209,36 @@ func (a *AIClient) chatMessagesModel(ctx context.Context, s *Server, bearer, mod
logf("world: ai 2xx empty-choices error: status=%d code=%q model=%s", status, e.code, model)
return "", status, "", e
}
logf("world: ai 2xx empty response: status=%d model=%s", status, model)
return "", status, "", fmt.Errorf("empty response")
logf("world: ai 2xx no choices: status=%d model=%s", status, model)
return "", status, "", emptyAnswerErr(model)
}
return strings.TrimSpace(cr.Choices[0].Message.Content), cr.Usage.TotalTokens, cr.ID, nil
// Prefer the answer (content) channel; fall back to the reasoning channel a
// reasoning model (gpt-oss/harmony, deepseek-r1) uses when it returns no content —
// so the analyst recovers its envelope/prose instead of a blank "empty response".
msg := cr.Choices[0].Message
// Pre-trim so a whitespace-only content channel falls through to reasoning.
out := firstNonEmpty(strings.TrimSpace(msg.Content), strings.TrimSpace(msg.ReasoningContent), strings.TrimSpace(msg.Reasoning))
if out == "" {
// A 2xx with a real but content-free choice (e.g. a reasoning model that hit the
// token cap before emitting content). The body IS a normal completion here — do
// NOT run it through newAIError (its top-level `id` would be misread as an error
// code); surface the model + stop reason honestly instead.
logf("world: ai 2xx empty answer: status=%d model=%s finish=%s", status, model, cr.Choices[0].FinishReason)
return "", status, cr.ID, emptyAnswerErr(model)
}
return out, cr.Usage.TotalTokens, cr.ID, nil
}
// emptyAnswerErr is the honest error for a 2xx completion that carried no usable
// answer (neither a content nor a reasoning channel). It names the served model so
// the chat surfaces "the <model> model returned an empty answer" — actionable (switch
// model) — instead of an opaque "empty response". Not a balance error, so it never
// trips the top-up CTA.
func emptyAnswerErr(model string) error {
if model = strings.TrimSpace(model); model != "" {
return fmt.Errorf("the %s model returned an empty answer", model)
}
return fmt.Errorf("the model returned an empty answer")
}
// aiError is a typed inference error carrying the upstream HTTP status plus the
+33 -7
View File
@@ -20,7 +20,6 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
@@ -81,16 +80,21 @@ func (a *AIClient) chatMessagesModelStream(ctx context.Context, s *Server, beare
return "", resp.StatusCode, "", err
}
if len(cr.Choices) == 0 {
return "", resp.StatusCode, "", fmt.Errorf("empty response")
return "", resp.StatusCode, "", emptyAnswerErr(model)
}
out := strings.TrimSpace(cr.Choices[0].Message.Content)
if onDelta != nil && out != "" {
msg := cr.Choices[0].Message
out := firstNonEmpty(strings.TrimSpace(msg.Content), strings.TrimSpace(msg.ReasoningContent), strings.TrimSpace(msg.Reasoning))
if out == "" {
return "", resp.StatusCode, cr.ID, emptyAnswerErr(model)
}
if onDelta != nil {
onDelta(out)
}
return out, cr.Usage.TotalTokens, cr.ID, nil
}
var full strings.Builder
var reasoning strings.Builder
tokens := 0
id := ""
sc := bufio.NewScanner(resp.Body)
@@ -108,7 +112,9 @@ func (a *AIClient) chatMessagesModelStream(ctx context.Context, s *Server, beare
ID string `json:"id"`
Choices []struct {
Delta struct {
Content string `json:"content"`
Content string `json:"content"`
ReasoningContent string `json:"reasoning_content"`
Reasoning string `json:"reasoning"`
} `json:"delta"`
} `json:"choices"`
Usage *struct {
@@ -125,6 +131,20 @@ func (a *AIClient) chatMessagesModelStream(ctx context.Context, s *Server, beare
tokens = frame.Usage.TotalTokens
}
for _, c := range frame.Choices {
// Reasoning deltas (gpt-oss/harmony, deepseek-r1) ride a separate channel.
// Forward them too — the replyExtractor routes this pre-envelope prose to the
// live "thinking" line — and keep them as the answer fallback for a model that
// never emits a content channel. (Not trimmed: preserve inter-chunk spacing.)
rc := c.Delta.ReasoningContent
if rc == "" {
rc = c.Delta.Reasoning
}
if rc != "" {
reasoning.WriteString(rc)
if onDelta != nil {
onDelta(rc)
}
}
if c.Delta.Content != "" {
full.WriteString(c.Delta.Content)
if onDelta != nil {
@@ -135,11 +155,17 @@ func (a *AIClient) chatMessagesModelStream(ctx context.Context, s *Server, beare
}
if err := sc.Err(); err != nil {
// A mid-stream drop still yields whatever arrived; the caller decides.
if full.Len() == 0 {
if full.Len() == 0 && reasoning.Len() == 0 {
return "", resp.StatusCode, "", err
}
}
return strings.TrimSpace(full.String()), tokens, id, nil
// The content channel is the answer; fall back to the reasoning channel only when
// the model emitted no content at all (mirrors the buffered path above).
out := strings.TrimSpace(full.String())
if out == "" {
out = strings.TrimSpace(reasoning.String())
}
return out, tokens, id, nil
}
// ── incremental "reply" extraction ───────────────────────────────────────────
+52 -16
View File
@@ -24,15 +24,37 @@ import (
// or non-admin owner → 403. The caller's bearer is returned to forward upstream,
// where cloud independently re-verifies — defense in depth.
// isAdminOrg reports whether an owner claim is one of the admin orgs. Kept in
// sync with the cloud deploy's globalAdminOrgs (admin,built-in).
func isAdminOrg(owner string) bool {
switch strings.TrimSpace(owner) {
case "admin", "built-in":
return true
default:
return false
// adminOrgs is the set of IAM owner claims world treats as a SuperAdmin. The base
// is EXACTLY cloud's canonical globalAdminOrgs — {admin, built-in} — the SAME
// predicate cloud's principal.IsSuperAdmin enforces (owner == the reserved admin
// org). It is ONE source of truth; world never widens it in code. A deployment MAY
// name its operator org (so the seeded superuser, e.g. z@hanzo.ai / owner "hanzo",
// keeps dashboard access) via WORLD_ADMIN_ORGS (comma-separated) in the deploy env
// — additive only. The base is never env-dependent, so an unset/empty
// WORLD_ADMIN_ORGS resolves to {admin, built-in}, never empty and never "everyone".
// The upstream cloud subsystems independently re-verify the bearer, so this gate
// only decides which callers world ATTEMPTS the full/admin reads for — never the
// final authz.
func adminOrgs() map[string]bool {
m := map[string]bool{"admin": true, "built-in": true}
for _, o := range strings.Split(env("WORLD_ADMIN_ORGS"), ",") {
if o = strings.TrimSpace(o); o != "" {
m[o] = true
}
}
return m
}
// isAdminOrg reports whether an owner claim is one of the admin orgs.
func isAdminOrg(owner string) bool { return adminOrgs()[strings.TrimSpace(owner)] }
// isOrgAdmin reports whether an identity may PUBLISH its org's shared documents
// (e.g. the org-shared dashboard default). It is admin iff the owner is a
// global-admin org (isAdminOrg) OR IAM marks the identity itself an admin owner
// (id.Admin). Either way the write is always scoped to the caller's OWN org, so
// this never grants cross-org authority. Reads stay open to every member.
func (s *Server) isOrgAdmin(id wIdentity) bool {
return isAdminOrg(id.Org) || id.Admin
}
// apiHost returns the api.hanzo.ai origin (no /v1 suffix) that the cloud
@@ -56,22 +78,36 @@ func iamIssuer() string {
return "https://hanzo.id"
}
// requireAdmin gates an admin-only Cloud endpoint. It returns the caller's bearer
// (to forward upstream) and true only for a validated admin-org owner; otherwise
// it writes the fail-closed response (401 without a token, 403 otherwise) and
// returns false. Every admin handler calls this after preflight. Identity is
// resolved through the single IAM-userinfo path (introspectIdentity); the gate
// reads only the authoritative owner claim.
func (s *Server) requireAdmin(w http.ResponseWriter, r *http.Request) (string, bool) {
// adminIdentity is the NON-writing admin probe: it returns the caller's bearer and
// true iff a valid IAM identity resolves to an admin-org owner. It short-circuits
// (no IAM call) when the request carries no bearer, so anonymous requests stay cheap.
// Used by endpoints that have a public fallback (cloud-pulse): they upgrade to the
// full admin view when the caller is an admin, and otherwise serve the public path.
func (s *Server) adminIdentity(r *http.Request) (string, bool) {
bearer := userBearer(r)
if bearer == "" {
writeError(w, http.StatusUnauthorized, "Sign in required")
return "", false
}
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
defer cancel()
id, err := s.introspectIdentity(ctx, bearer)
if err != nil || !isAdminOrg(id.Org) {
return "", false
}
return bearer, true
}
// requireAdmin gates an admin-ONLY Cloud endpoint (no public fallback). It returns
// the caller's bearer (to forward upstream) and true only for a validated admin-org
// owner; otherwise it writes the fail-closed response (401 without a token, 403
// otherwise) and returns false. Every admin handler calls this after preflight.
func (s *Server) requireAdmin(w http.ResponseWriter, r *http.Request) (string, bool) {
if userBearer(r) == "" {
writeError(w, http.StatusUnauthorized, "Sign in required")
return "", false
}
bearer, ok := s.adminIdentity(r)
if !ok {
writeError(w, http.StatusForbidden, "Admin only — sign in with the admin org")
return "", false
}
+23 -9
View File
@@ -79,11 +79,12 @@ type cloudUsageByModel struct {
}
// fetchCloudUsage reads the platform-wide usage overview (?org=all) for a range
// label ("24h" | "7d" | "30d"). It requires a super-admin service token; it
// returns errNoServiceToken when none is set and the upstream error otherwise, so
// callers keep their honest modeled/demo fallback.
func (s *Server) fetchCloudUsage(ctx context.Context, rangeLabel string) (*cloudUsageOverview, error) {
hdr := serviceAuth()
// label ("24h" | "7d" | "30d") using the supplied auth header — the KMS service
// bearer (public path) or the signed-in admin's OWN bearer (the flagship admin
// path). Either way the upstream independently authorizes ?org=all (super-admin),
// so a non-admin bearer 4xxes and the caller keeps its honest fallback. Returns
// errNoServiceToken when no auth is available at all.
func (s *Server) fetchCloudUsage(ctx context.Context, rangeLabel string, hdr map[string]string) (*cloudUsageOverview, error) {
if hdr == nil {
return nil, errNoServiceToken
}
@@ -95,12 +96,25 @@ func (s *Server) fetchCloudUsage(ctx context.Context, rangeLabel string) (*cloud
return &ov, nil
}
// intervalSeconds parses a Go duration string (the usage series bucket width,
// e.g. "1h") to seconds; 0 when unparseable so callers fall back to a window
// average instead of dividing by a bogus interval.
// intervalSeconds resolves the usage-series bucket width to seconds; 0 when
// unresolvable so callers fall back to a window average instead of dividing by a
// bogus interval. The upstream get-cloud-usages emits the width as a WORD enum
// ("hour"/"day"/"minute"), NOT a Go duration — time.ParseDuration fails on those
// ("hour" needs to be "1h"), which silently forced usageRate to the flat 24h mean
// (the "AI Compute usage is dead flat" bug). Handle the enum first, then still
// accept a real duration string for any caller that sends one.
func intervalSeconds(d string) float64 {
if d == "" {
switch d {
case "":
return 0
case "minute":
return 60
case "hour":
return 3600
case "day":
return 86400
case "week":
return 604800
}
v, err := time.ParseDuration(d)
if err != nil || v <= 0 {
+40
View File
@@ -0,0 +1,40 @@
package world
import "testing"
// TestIntervalSeconds guards the "AI Compute usage is dead flat" regression: the
// upstream usage series reports its bucket width as a WORD enum ("hour"/"day"), not a
// Go duration, so time.ParseDuration failed and usageRate silently fell back to the
// flat 24h mean. intervalSeconds must resolve the enums (and still accept a real
// duration string).
func TestIntervalSeconds(t *testing.T) {
cases := map[string]float64{
"minute": 60,
"hour": 3600,
"day": 86400,
"week": 604800,
"1h": 3600, // real Go-duration string still works
"30m": 1800,
"": 0, // unresolvable → 0 (caller falls back to window average)
"nope": 0,
}
for in, want := range cases {
if got := intervalSeconds(in); got != want {
t.Errorf("intervalSeconds(%q) = %v, want %v", in, got, want)
}
}
}
// TestUsageRate proves the freshest-bucket rate is used when the interval resolves
// (the fix), and the 24h average is used only when it can't.
func TestUsageRate(t *testing.T) {
series := []cloudUsageSeriesPoint{{Requests: 100}, {Requests: 720}} // last bucket = 720
// "hour" now resolves to 3600s → 720/3600 = 0.2 rps (fresh), NOT 999999/86400.
if got := usageRate(999999, series, "hour", seriesRequests); got != 720.0/3600.0 {
t.Errorf("usageRate(hour) = %v, want %v (fresh bucket, not 24h mean)", got, 720.0/3600.0)
}
// Unresolvable interval → 24h average.
if got := usageRate(86400, series, "", seriesRequests); got != 1.0 {
t.Errorf("usageRate(empty interval) = %v, want 1.0 (24h average)", got)
}
}
+84
View File
@@ -0,0 +1,84 @@
package world
import (
"context"
"time"
)
// Platform user metrics — REAL signups / active users from Hanzo IAM (Casdoor).
//
// Source: IAM GET /v1/iam/global-users (every user across every org; global-admin
// only). We read it with the signed-in admin's OWN bearer (never a shared key),
// fold it into NON-sensitive aggregates (counts + a daily-signup series), and return
// ONLY those aggregates — no user record, email, name or other PII ever leaves this
// function. Honest-empty (error) when the caller is not a global admin upstream or
// IAM is unreachable, so the overview simply omits the user tiles rather than guess.
type userMetrics struct {
Total int `json:"total"`
Signups24h int `json:"signups24h"`
Signups7d int `json:"signups7d"`
ActiveNow int `json:"activeNow"`
SignupSeries []int64 `json:"signupSeries"` // new users/day, last 14 days, chronological
}
// iamUser is the minimal, non-PII slice of Casdoor's object.User we read.
type iamUser struct {
CreatedTime string `json:"createdTime"`
IsOnline bool `json:"isOnline"`
IsDeleted bool `json:"isDeleted"`
}
const userSignupDays = 14
// fetchUserMetrics reads the platform-wide user list from IAM with auth and folds it
// into non-sensitive aggregates. Requires a global-admin bearer upstream; any error
// (non-admin, unreachable) leaves the caller to omit the tiles honestly — never a
// fabricated count.
func (s *Server) fetchUserMetrics(ctx context.Context, auth map[string]string) (*userMetrics, error) {
if auth == nil {
return nil, errNoServiceToken
}
var users []iamUser
if err := s.getJSON(ctx, iamIssuer()+"/v1/iam/global-users", auth, &users); err != nil {
return nil, err
}
now := time.Now().UTC()
m := &userMetrics{SignupSeries: make([]int64, userSignupDays)}
for _, u := range users {
if u.IsDeleted {
continue
}
m.Total++
if u.IsOnline {
m.ActiveNow++
}
t, ok := parseUserTime(u.CreatedTime)
if !ok {
continue
}
if age := now.Sub(t); age >= 0 {
if age <= 24*time.Hour {
m.Signups24h++
}
if age <= 7*24*time.Hour {
m.Signups7d++
}
if d := int(age.Hours() / 24); d < userSignupDays {
m.SignupSeries[userSignupDays-1-d]++ // chronological: oldest bucket first, today last
}
}
}
return m, nil
}
// parseUserTime parses Casdoor's createdTime (RFC3339, with a couple of legacy
// fallbacks). ok=false when unparseable so a bad row is skipped, never guessed.
func parseUserTime(s string) (time.Time, bool) {
for _, layout := range []string{time.RFC3339, time.RFC3339Nano, "2006-01-02 15:04:05"} {
if t, err := time.Parse(layout, s); err == nil {
return t.UTC(), true
}
}
return time.Time{}, false
}
+698 -104
View File
@@ -1,53 +1,56 @@
{
"measured": {
"gpqa_diamond": {
"enso-ultra": {
"accuracy_pct": 89.9,
"gpt-5.6-terra": {
"accuracy_pct": 91.1,
"stderr_pct": 2.1,
"n": 198,
"correct": 178,
"errors": 0,
"tokens": {
"prompt": 205635,
"completion": 612706,
"reasoning": 319290,
"calls": 601
},
"usd_est": 16.4333,
"wall_seconds": null,
"run_tag": "v1"
},
"enso": {
"accuracy_pct": 87.9,
"stderr_pct": 2.3,
"n": 198,
"n": 191,
"correct": 174,
"errors": 0,
"infra_excluded": 7,
"tokens": {
"prompt": 74531,
"completion": 152519,
"reasoning": 29387,
"calls": 198
},
"usd_est": 10.0211,
"wall_seconds": null,
"run_tag": "v1"
},
"opus-4.8": {
"accuracy_pct": 86.9,
"stderr_pct": 2.4,
"n": 198,
"correct": 172,
"errors": 0,
"tokens": {
"prompt": 78121,
"completion": 126069,
"prompt": 60695,
"completion": 25529,
"reasoning": 0,
"calls": 198
},
"usd_est": 10.627,
"wall_seconds": 241.3,
"run_tag": "v1"
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2"
},
"deepseek-4-flash": {
"accuracy_pct": 76.9,
"stderr_pct": 3.1,
"n": 182,
"correct": 140,
"errors": 16,
"infra_excluded": 16,
"tokens": {
"prompt": 56442,
"completion": 101277,
"reasoning": 0,
"calls": 182
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2"
},
"enso-flash": {
"accuracy_pct": 75.8,
"stderr_pct": 3.0,
"n": 198,
"correct": 150,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 60695,
"completion": 361936,
"reasoning": 0,
"calls": 198
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2"
},
"fable-5": {
"accuracy_pct": 81.3,
@@ -55,6 +58,7 @@
"n": 198,
"correct": 161,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 78121,
"completion": 199072,
@@ -65,12 +69,30 @@
"wall_seconds": null,
"run_tag": "v1"
},
"deepseek-v4-pro": {
"accuracy_pct": 75.3,
"stderr_pct": 3.1,
"n": 198,
"correct": 149,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 60695,
"completion": 107808,
"reasoning": 0,
"calls": 198
},
"usd_est": 0.2113,
"wall_seconds": null,
"run_tag": "v2"
},
"gpt-5.5": {
"accuracy_pct": 90.4,
"stderr_pct": 2.1,
"n": 198,
"correct": 179,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 54916,
"completion": 362128,
@@ -81,97 +103,669 @@
"wall_seconds": 2396.2,
"run_tag": "v1"
},
"deepseek-v4-pro": {
"accuracy_pct": 76.3,
"stderr_pct": 3.0,
"n": 198,
"correct": 151,
"glm-5.2": {
"accuracy_pct": null,
"stderr_pct": null,
"n": 69,
"correct": 60,
"errors": 0,
"infra_excluded": 129,
"tokens": {
"prompt": 52523,
"completion": 108318,
"prompt": 60695,
"completion": 26595,
"reasoning": 0,
"calls": 198
},
"usd_est": 0.2076,
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "max",
"degraded": true,
"blank_rate_pct": 65.2
},
"enso": {
"accuracy_pct": 87.9,
"stderr_pct": 2.3,
"n": 198,
"correct": 174,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 74531,
"completion": 152519,
"reasoning": 29387,
"calls": 198
},
"usd_est": 10.0211,
"wall_seconds": null,
"run_tag": "v1"
},
"enso-ultra": {
"accuracy_pct": 90.4,
"stderr_pct": 2.1,
"n": 198,
"correct": 179,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 217469,
"completion": 603501,
"reasoning": 325464,
"calls": 605
},
"usd_est": 15.8887,
"wall_seconds": null,
"run_tag": "v2"
},
"gpt-5.6-sol": {
"accuracy_pct": 94.8,
"stderr_pct": 1.6,
"n": 193,
"correct": 183,
"errors": 0,
"infra_excluded": 5,
"tokens": {
"prompt": 60695,
"completion": 34023,
"reasoning": 0,
"calls": 198
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "max"
},
"kimi-k3": {
"accuracy_pct": 92.5,
"stderr_pct": 4.2,
"n": 40,
"correct": 37,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 13917,
"completion": 90614,
"reasoning": 81847,
"calls": 40
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "k3-max"
},
"glm-5.2@openrouter": {
"accuracy_pct": null,
"stderr_pct": null,
"n": 119,
"correct": 95,
"errors": 79,
"infra_excluded": 79,
"tokens": {
"prompt": 32982,
"completion": 1228859,
"reasoning": 983679,
"calls": 119
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "glm-true",
"degraded": true,
"blank_rate_pct": 39.9
},
"opus-4.8": {
"accuracy_pct": 86.9,
"stderr_pct": 2.4,
"n": 198,
"correct": 172,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 78121,
"completion": 126069,
"reasoning": 0,
"calls": 198
},
"usd_est": 10.627,
"wall_seconds": 241.3,
"run_tag": "v1"
},
"deepseek-3.2": {
"accuracy_pct": 73.7,
"stderr_pct": 3.1,
"n": 198,
"correct": 146,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 60695,
"completion": 367921,
"reasoning": 0,
"calls": 198
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2"
},
"gpt-5.6-luna": {
"accuracy_pct": 89.6,
"stderr_pct": 2.3,
"n": 183,
"correct": 164,
"errors": 0,
"infra_excluded": 15,
"tokens": {
"prompt": 60695,
"completion": 31104,
"reasoning": 0,
"calls": 198
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2"
}
},
"livecodebench": {
"gpt-5.6-sol": {
"accuracy_pct": null,
"stderr_pct": null,
"n": 144,
"correct": 130,
"errors": 17,
"infra_excluded": 31,
"tokens": {
"prompt": 87763,
"completion": 43002,
"reasoning": 0,
"calls": 158
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2",
"degraded": true,
"blank_rate_pct": 17.7
},
"deepseek-v4-pro": {
"accuracy_pct": 48.0,
"accuracy_pct": 51.4,
"stderr_pct": 3.8,
"n": 175,
"correct": 84,
"correct": 90,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 92354,
"completion": 76407,
"prompt": 97404,
"completion": 75242,
"reasoning": 0,
"calls": 175
},
"usd_est": 0.1769,
"usd_est": 0.1777,
"wall_seconds": null,
"run_tag": "v2"
},
"deepseek-3.2": {
"accuracy_pct": 56.0,
"stderr_pct": 3.8,
"n": 175,
"correct": 98,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 97404,
"completion": 353896,
"reasoning": 0,
"calls": 175
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2"
},
"fable-5": {
"accuracy_pct": 82.9,
"stderr_pct": 2.8,
"n": 175,
"correct": 145,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 125867,
"completion": 544855,
"reasoning": 0,
"calls": 175
},
"usd_est": 8.5504,
"wall_seconds": null,
"run_tag": "v1"
},
"enso": {
"accuracy_pct": 92.0,
"stderr_pct": 2.1,
"n": 174,
"correct": 160,
"errors": 1,
"infra_excluded": 1,
"tokens": {
"prompt": 92002,
"completion": 512599,
"reasoning": 454741,
"calls": 174
},
"usd_est": 5.241,
"wall_seconds": null,
"run_tag": "v1"
},
"opus-4.8": {
"accuracy_pct": 72.8,
"stderr_pct": 3.4,
"n": 173,
"correct": 126,
"errors": 2,
"infra_excluded": 2,
"tokens": {
"prompt": 124432,
"completion": 500884,
"reasoning": 0,
"calls": 173
},
"usd_est": 39.4328,
"wall_seconds": null,
"run_tag": "v1"
},
"gpt-5.6-luna": {
"accuracy_pct": null,
"stderr_pct": null,
"n": 156,
"correct": 135,
"errors": 0,
"infra_excluded": 19,
"tokens": {
"prompt": 97404,
"completion": 41596,
"reasoning": 0,
"calls": 175
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2",
"degraded": true,
"blank_rate_pct": 10.9
},
"enso-ultra": {
"accuracy_pct": 85.1,
"stderr_pct": 2.7,
"n": 175,
"correct": 149,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 975812,
"completion": 1329941,
"reasoning": 474476,
"calls": 693
},
"usd_est": 71.731,
"wall_seconds": null,
"run_tag": "v2"
},
"gpt-5.5": {
"accuracy_pct": 92.0,
"stderr_pct": 2.1,
"n": 174,
"correct": 160,
"errors": 1,
"infra_excluded": 1,
"tokens": {
"prompt": 92002,
"completion": 504668,
"reasoning": 444424,
"calls": 174
},
"usd_est": 5.1617,
"wall_seconds": null,
"run_tag": "v1"
},
"glm-5.2": {
"accuracy_pct": null,
"stderr_pct": null,
"n": 60,
"correct": 49,
"errors": 0,
"infra_excluded": 115,
"tokens": {
"prompt": 97404,
"completion": 14943,
"reasoning": 0,
"calls": 175
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2",
"degraded": true,
"blank_rate_pct": 65.7
},
"gpt-5.6-terra": {
"accuracy_pct": 88.3,
"stderr_pct": 2.5,
"n": 162,
"correct": 143,
"errors": 0,
"infra_excluded": 13,
"tokens": {
"prompt": 97404,
"completion": 49002,
"reasoning": 0,
"calls": 175
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2"
},
"enso-flash": {
"accuracy_pct": 49.1,
"stderr_pct": 3.8,
"n": 175,
"correct": 86,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 97404,
"completion": 367521,
"reasoning": 0,
"calls": 175
},
"usd_est": 0.0,
"wall_seconds": null,
"run_tag": "v2"
}
},
"hle": {
"gpt-5.5": {
"accuracy_pct": 35.4,
"stderr_pct": 2.1,
"n": 500,
"correct": 177,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 139619,
"completion": 2240161,
"reasoning": 2061227,
"calls": 500
},
"usd_est": 22.5761,
"wall_seconds": null,
"run_tag": "v1"
},
"deepseek-v4-pro": {
"accuracy_pct": 7.2,
"stderr_pct": 1.2,
"n": 500,
"correct": 36,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 134104,
"completion": 383371,
"reasoning": 0,
"calls": 500
},
"usd_est": 0.7063,
"wall_seconds": null,
"run_tag": "v1"
},
"opus-4.8": {
"accuracy_pct": 27.9,
"stderr_pct": 2.0,
"n": 498,
"correct": 139,
"errors": 2,
"infra_excluded": 2,
"tokens": {
"prompt": 204638,
"completion": 1265083,
"reasoning": 0,
"calls": 498
},
"usd_est": 97.9508,
"wall_seconds": null,
"run_tag": "v1"
},
"enso-ultra": {
"accuracy_pct": 34.6,
"stderr_pct": 2.1,
"n": 500,
"correct": 173,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 1457803,
"completion": 4095530,
"reasoning": 2052639,
"calls": 1819
},
"usd_est": 151.7767,
"wall_seconds": null,
"run_tag": "v2"
},
"enso": {
"accuracy_pct": 29.4,
"stderr_pct": 2.0,
"n": 500,
"correct": 147,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 180835,
"completion": 1429013,
"reasoning": 436163,
"calls": 500
},
"usd_est": 76.5405,
"wall_seconds": null,
"run_tag": "v1"
},
"fable-5": {
"accuracy_pct": 38.2,
"stderr_pct": 2.2,
"n": 500,
"correct": 191,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 205132,
"completion": 1660596,
"reasoning": 0,
"calls": 500
},
"usd_est": 25.5243,
"wall_seconds": null,
"run_tag": "v1"
}
},
"charxiv": {
"opus-4.8": {
"accuracy_pct": 78.0,
"stderr_pct": 2.9,
"n": 200,
"correct": 156,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 204206,
"completion": 5650,
"reasoning": 0,
"calls": 200
},
"usd_est": 3.4868,
"wall_seconds": null,
"run_tag": "v1"
},
"enso-ultra": {
"accuracy_pct": 85.5,
"stderr_pct": 2.5,
"n": 200,
"correct": 171,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 631448,
"completion": 85689,
"reasoning": 54757,
"calls": 636
},
"usd_est": 6.2855,
"wall_seconds": null,
"run_tag": "v2"
},
"gpt-5.5": {
"accuracy_pct": 85.5,
"stderr_pct": 2.5,
"n": 200,
"correct": 171,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 181387,
"completion": 50493,
"reasoning": 47582,
"calls": 200
},
"usd_est": 0.7317,
"wall_seconds": null,
"run_tag": "v1"
},
"fable-5": {
"accuracy_pct": 76.0,
"stderr_pct": 3.0,
"n": 200,
"correct": 152,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 204206,
"completion": 13961,
"reasoning": 0,
"calls": 200
},
"usd_est": 0.822,
"wall_seconds": null,
"run_tag": "v1"
},
"enso": {
"accuracy_pct": 78.0,
"stderr_pct": 2.9,
"n": 200,
"correct": 156,
"errors": 0,
"infra_excluded": 0,
"tokens": {
"prompt": 204206,
"completion": 5424,
"reasoning": 0,
"calls": 200
},
"usd_est": 3.4699,
"wall_seconds": null,
"run_tag": "v1"
}
}
},
"grading": {},
"fugu_reported": {
"SWE-Bench Pro": {
"Fugu-Ultra": 73.7,
"Fugu": 59.0,
"Opus-4.8": 69.2,
"Gemini-3.1": 54.2,
"GPT-5.5": 58.6
},
"Terminal Bench 2.1": {
"Fugu-Ultra": 82.1,
"Fugu": 80.2,
"Opus-4.8": 74.6,
"Gemini-3.1": 70.3,
"GPT-5.5": 78.2
},
"LiveCodeBench": {
"Fugu-Ultra": 93.2,
"Fugu": 92.9,
"Opus-4.8": 87.8,
"Gemini-3.1": 88.5,
"GPT-5.5": 85.3
},
"LiveCodeBench Pro": {
"Fugu-Ultra": 90.8,
"Fugu": 87.8,
"Opus-4.8": 84.8,
"Gemini-3.1": 82.9,
"GPT-5.5": 88.4
},
"Humanity's Last Exam": {
"Fugu-Ultra": 50.0,
"Fugu": 47.2,
"Opus-4.8": 49.8,
"Gemini-3.1": 44.4,
"GPT-5.5": 41.4
},
"CharXiv Reasoning": {
"Fugu-Ultra": 86.6,
"Fugu": 85.1,
"Opus-4.8": 84.2,
"Gemini-3.1": 83.3,
"GPT-5.5": 84.1
},
"GPQA Diamond": {
"Fugu-Ultra": 95.5,
"Fugu": 95.5,
"Opus-4.8": 92.0,
"Gemini-3.1": 94.3,
"GPT-5.5": 93.6
"grading": {
"hle": {
"judge_arm": "gpt-5.5",
"judge_calls": 1,
"judge_usd_est": 0.0006,
"judge_prompt_tokens": 159,
"judge_completion_tokens": 36
}
},
"enso_reported": {},
"pending": [
"swebench_pro",
"terminal_bench"
],
"total_usd_est": 44.38
"ultra_ablation": {
"gpqa_diamond": {
"k3fix": {
"accuracy_pct": 32.8,
"n": 198,
"usd_est": 0.0,
"logic": "k3fix"
},
"v2": {
"accuracy_pct": 90.4,
"n": 198,
"usd_est": 15.8887,
"logic": "verify-then-select"
},
"v1": {
"accuracy_pct": 89.9,
"n": 198,
"usd_est": 16.4333,
"logic": "blind-synthesis"
}
},
"livecodebench": {
"v1": {
"accuracy_pct": 81.1,
"n": 175,
"usd_est": 90.682,
"logic": "blind-synthesis"
},
"v2": {
"accuracy_pct": 85.1,
"n": 175,
"usd_est": 71.731,
"logic": "verify-then-select"
}
},
"hle": {
"v1": {
"accuracy_pct": 29.2,
"n": 500,
"usd_est": 191.4856,
"logic": "blind-synthesis"
},
"v2": {
"accuracy_pct": 34.6,
"n": 500,
"usd_est": 151.7767,
"logic": "verify-then-select"
}
},
"charxiv": {
"v2": {
"accuracy_pct": 85.5,
"n": 200,
"usd_est": 6.2855,
"logic": "verify-then-select"
},
"v1": {
"accuracy_pct": 81.5,
"n": 200,
"usd_est": 10.1498,
"logic": "blind-synthesis"
}
}
},
"total_usd_est": 564.25,
"agentic": {
"swebench_pro": {
"bench": "SWE-Bench Pro",
"metric": "% resolved (agentic, Mini-SWE-Agent)",
"n_items": 25,
"systems": {
"step-routed": {
"n": 18,
"resolved": 7,
"resolved_rate": 0.3889,
"usd": 19.696,
"calls": 256
},
"single-opus": {
"n": 18,
"resolved": 3,
"resolved_rate": 0.1667,
"usd": 27.561,
"calls": 321
}
},
"note": "Agentic pilot: n=18 per system from the agent harness (agent pass/fail); official cross-scoring done on a small common set (results/agentic). Full 731-instance run pending (amd64-only task images + shared-key serialization)."
}
}
}
+233
View File
@@ -0,0 +1,233 @@
package world
import (
"errors"
"sort"
"sync"
"time"
)
// fund_broker.go is the PAPER / LIVE boundary — the one seam the whole fund
// brain routes execution through.
//
// SAFETY INVARIANT (enforced by the type system and proven in fund_broker_test.go):
// the brain is fully autonomous for analysis and decision-making, but it can
// only ever reach a Broker whose sole real implementation is PaperBroker, which
// records simulated fills against an in-memory ledger and touches no external
// venue. LiveBroker is a compile-present stub that returns errLiveExecution on
// every call: no brokerage/exchange client, no order-router, no credential is
// wired anywhere in this package. Moving real funds requires a human to build
// and authorize a real implementation — it cannot happen by running this code.
// errLiveExecution is returned by every LiveBroker method. Live trading is a
// human-authorized action, never an autonomous one.
var errLiveExecution = errors.New("live execution requires human authorization")
// side is the direction of a paper order.
type side string
const (
buy side = "buy"
sell side = "sell"
)
// order is one instruction the engine emits to rebalance toward the book. Notional
// is in the fund's simulated base currency (USD), always positive.
type order struct {
Sleeve string `json:"sleeve"`
Side side `json:"side"`
Notional float64 `json:"notional"`
Reason string `json:"reason"`
At time.Time `json:"at"`
}
// fill is the broker's response to an order: what actually "executed". For the
// paper broker a fill mirrors the order exactly (no slippage model — this is a
// weight-tracking simulation, not an execution simulator).
type fill struct {
Order order `json:"order"`
Filled float64 `json:"filled"` // notional filled (== order.Notional for paper)
Paper bool `json:"paper"` // always true; a real fill would be false
At time.Time `json:"at"`
}
// Broker is the execution seam. The engine holds a Broker, never a concrete type,
// so the only way to make it place a real order is to give it a real
// implementation — which this package deliberately does not provide.
type Broker interface {
// Execute records (paper) or would place (live, refused) a batch of orders,
// returning the resulting fills. It must be safe for concurrent use.
Execute(orders []order) ([]fill, error)
// Live reports whether this broker moves real funds. The engine asserts it is
// false before it runs; a true here is a wiring bug that must fail loudly.
Live() bool
}
// PaperBroker is the ONLY real Broker. It "fills" every order at its full
// notional and appends nothing external — the position/PnL accounting lives in
// the ledger the engine keeps. Stateless and trivially concurrency-safe.
type PaperBroker struct{}
// NewPaperBroker returns the paper broker. This is the only Broker constructor
// the engine ever calls.
func NewPaperBroker() *PaperBroker { return &PaperBroker{} }
// Execute fills every order at full notional as a paper fill.
func (PaperBroker) Execute(orders []order) ([]fill, error) {
now := time.Now().UTC()
fills := make([]fill, 0, len(orders))
for _, o := range orders {
fills = append(fills, fill{Order: o, Filled: o.Notional, Paper: true, At: now})
}
return fills, nil
}
// Live is always false: the paper broker never moves real funds.
func (PaperBroker) Live() bool { return false }
// LiveBroker is a stub. It implements Broker so the seam is visibly complete, but
// every method refuses: there is no venue client, and there never will be one in
// this package. It exists to make the boundary explicit and to prove in tests
// that no autonomous path can execute for real.
type LiveBroker struct{}
// Execute always refuses. Real execution is a human-authorized action.
func (LiveBroker) Execute([]order) ([]fill, error) { return nil, errLiveExecution }
// Live is true: this broker WOULD move real funds — which is exactly why the
// engine refuses to run with it (fund_engine.go asserts Broker.Live() == false).
func (LiveBroker) Live() bool { return true }
// ── the paper ledger ─────────────────────────────────────────────────────────
// position is the fund's simulated holding in one sleeve: the invested cost
// basis (net notional bought minus sold) and the sleeve's current model weight.
type position struct {
Sleeve string `json:"sleeve"`
Cost float64 `json:"cost"` // net notional invested (paper), USD
Weight float64 `json:"weight"` // latest target weight from the book, [0,1]
}
// ledger is the append-only record of the paper fund: current positions, the
// full order/fill history, and the running simulated PnL. Guarded by its own
// mutex; the engine writes it, the /ledger handler reads a snapshot.
type ledger struct {
mu sync.Mutex
cash float64 // uninvested simulated capital, USD
capital float64 // starting capital, USD (for return %)
positions map[string]position // sleeve → position
history []fill // append-only fill log (most recent last)
rebalance int // number of rebalance cycles applied
lastAt time.Time // time of the last applied cycle
markValue float64 // last marked portfolio value (positions marked to weight×equity)
}
// newLedger opens a paper ledger with the given starting capital, fully in cash.
func newLedger(capital float64) *ledger {
return &ledger{
cash: capital,
capital: capital,
positions: map[string]position{},
}
}
// apply records a batch of paper fills into the ledger: a buy moves cash into a
// sleeve's cost basis, a sell moves it back. Cost basis is floored at zero (a
// sell never drives a paper position negative — the engine only sells what it
// holds). Append-only: every fill is kept in history.
func (l *ledger) apply(fills []fill) {
l.mu.Lock()
defer l.mu.Unlock()
for _, f := range fills {
p := l.positions[f.Order.Sleeve]
p.Sleeve = f.Order.Sleeve
switch f.Order.Side {
case buy:
p.Cost += f.Filled
l.cash -= f.Filled
case sell:
cut := f.Filled
if cut > p.Cost {
cut = p.Cost
}
p.Cost -= cut
l.cash += cut
}
l.positions[f.Order.Sleeve] = p
l.history = append(l.history, f)
}
l.rebalance++
l.lastAt = time.Now().UTC()
}
// setWeights records the latest target weights from the book onto positions so a
// ledger snapshot shows the model's intended allocation next to the paper cost.
func (l *ledger) setWeights(scores []sleeveScore) {
l.mu.Lock()
defer l.mu.Unlock()
for _, s := range scores {
p := l.positions[s.key]
p.Sleeve = s.key
p.Weight = s.weight
l.positions[s.key] = p
}
}
// investedCost is the total paper capital currently allocated across sleeves.
func (l *ledger) investedCost() float64 {
var sum float64
for _, p := range l.positions {
sum += p.Cost
}
return sum
}
// snapshotPositions returns a copy of the current positions map so the pure
// diffOrders can read a consistent view without holding the ledger lock.
func (l *ledger) snapshotPositions() map[string]position {
l.mu.Lock()
defer l.mu.Unlock()
out := make(map[string]position, len(l.positions))
for k, v := range l.positions {
out[k] = v
}
return out
}
// mark values the paper book: each held sleeve is marked by its latest model
// weight against the current equity, and the simulated PnL is the marked value
// plus cash minus starting capital. This is a weight-tracking mark — the sim
// measures whether the model's ALLOCATION tracks the sleeve reads, not tick PnL.
func (l *ledger) mark(scores []sleeveScore) {
weight := make(map[string]float64, len(scores))
for _, s := range scores {
weight[s.key] = s.weight
}
l.mu.Lock()
defer l.mu.Unlock()
equity := l.capital
var marked float64
for k, p := range l.positions {
// A sleeve still in the book marks at target×equity; one that dropped out
// marks at its remaining cost basis (it is being wound down).
if w, ok := weight[k]; ok {
marked += w * equity
} else {
marked += p.Cost
}
}
l.markValue = marked
}
// pnl is the simulated profit/loss: marked positions + uninvested cash start.
func (l *ledger) pnl() float64 {
l.mu.Lock()
defer l.mu.Unlock()
return l.markValue + l.cash - l.capital
}
// sortOrders orders a batch deterministically by sleeve key so identical inputs
// yield identical ledger history.
func sortOrders(os []order) {
sort.SliceStable(os, func(i, j int) bool { return os[i].Sleeve < os[j].Sleeve })
}
+173
View File
@@ -0,0 +1,173 @@
package world
import (
"context"
"fmt"
"math"
"sync"
"time"
)
// fund_engine.go is the autonomous brain. On an interval it recomputes the book
// (scoreSleeves), diffs the preferred portfolio against the current paper
// positions, and routes rebalance orders through the Broker seam into the
// append-only paper ledger, tracking simulated PnL. It is analysis + decision
// only: the Broker it holds is a PaperBroker, asserted non-live before every run.
const (
// fundCapital is the paper fund's starting simulated capital, USD.
fundCapital = 1_000_000.0
// fundInterval is the autonomous rebalance cadence.
fundInterval = 6 * time.Hour
// rebalanceBand is the minimum absolute weight drift (target held) that
// justifies an order, so tiny model wiggles don't churn the paper book.
rebalanceBand = 0.02
// fundRange is the price history window the book is scored over.
fundRange = "range=6mo&interval=1d"
// fundFetchTO bounds each per-symbol Yahoo fetch.
fundFetchTO = 8 * time.Second
)
// fundEngine owns the paper fund: the execution seam (broker), the ledger, and
// the latest computed book. Safe for concurrent use — the ledger guards its own
// state and book is swapped under bookMu.
type fundEngine struct {
broker Broker
led *ledger
bookMu sync.Mutex
lastBook *fundBook
}
// fundBook is the computed preferred portfolio at a point in time.
type fundBook struct {
asOf time.Time
scores []sleeveScore
stance string
riskFr float64
}
// newFundEngine builds the paper fund. It refuses any live broker: the fund is
// paper-only by construction, and a live broker here is a wiring bug.
func newFundEngine(b Broker) *fundEngine {
if b == nil || b.Live() {
// Fail closed to the paper broker rather than ever run live autonomously.
b = NewPaperBroker()
}
return &fundEngine{broker: b, led: newLedger(fundCapital)}
}
// diffOrders is the pure rebalancer: given the target weights (the book) and the
// current paper positions, emit the buy/sell orders that move each sleeve's held
// fraction toward its target, in notional against `equity`. A sleeve only trades
// when it drifts past rebalanceBand. Sells come before buys so freed cash funds
// the buys within one cycle. Pure and fully unit-tested.
func diffOrders(scores []sleeveScore, positions map[string]position, equity float64, at time.Time) []order {
if equity <= 0 {
return nil
}
target := make(map[string]float64, len(scores))
for _, s := range scores {
target[s.key] = s.weight
}
// Every sleeve that is either targeted now or held from before must be
// considered, so a sleeve that dropped out of the book is sold down.
keys := make(map[string]bool, len(scores)+len(positions))
for k := range target {
keys[k] = true
}
for k := range positions {
keys[k] = true
}
var sells, buys []order
for k := range keys {
held := positions[k].Cost / equity
want := target[k]
drift := want - held
if math.Abs(drift) < rebalanceBand {
continue
}
notional := math.Abs(drift) * equity
if drift < 0 {
sells = append(sells, order{
Sleeve: k, Side: sell, Notional: notional, At: at,
Reason: fmt.Sprintf("trim to %.0f%% (held %.0f%%)", want*100, held*100),
})
} else {
buys = append(buys, order{
Sleeve: k, Side: buy, Notional: notional, At: at,
Reason: fmt.Sprintf("add to %.0f%% (held %.0f%%)", want*100, held*100),
})
}
}
// Deterministic order (sleeve key) so identical inputs give identical output —
// tests and the ledger history stay stable.
sortOrders(sells)
sortOrders(buys)
return append(sells, buys...)
}
// rebalance applies one autonomous cycle: score the fresh closes into a book,
// record the target weights, diff against the paper positions, execute through
// the broker, and fold the fills into the ledger. Returns the book it acted on.
func (e *fundEngine) rebalance(closes map[string][]float64) (*fundBook, error) {
scores := scoreSleeves(closes)
if len(scores) == 0 {
return nil, errUnavailable
}
stance, frac := overallStance(scores)
book := &fundBook{asOf: time.Now().UTC(), scores: scores, stance: stance, riskFr: frac}
e.led.setWeights(scores)
equity := e.led.capital // rebalance against constant starting equity (paper, fully-invested target)
orders := diffOrders(scores, e.led.snapshotPositions(), equity, book.asOf)
if len(orders) > 0 {
fills, err := e.broker.Execute(orders)
if err != nil {
return nil, err
}
e.led.apply(fills)
}
e.led.mark(scores)
e.bookMu.Lock()
e.lastBook = book
e.bookMu.Unlock()
return book, nil
}
// book returns the last computed book (nil until the first cycle).
func (e *fundEngine) book() *fundBook {
e.bookMu.Lock()
defer e.bookMu.Unlock()
return e.lastBook
}
// start runs the autonomous loop: rebalance once shortly after boot, then every
// fundInterval, until ctx is cancelled. The fetch is bounded and single-sourced
// through the server's shared Yahoo client. Never live: broker is paper.
func (e *fundEngine) start(ctx context.Context, s *Server) {
go func() {
e.runOnce(ctx, s)
for {
select {
case <-ctx.Done():
return
case <-time.After(jitter(fundInterval)):
e.runOnce(ctx, s)
}
}
}()
}
// runOnce fetches the universe and applies one rebalance cycle, logging (never
// crashing) on failure so a thin-data window just skips.
func (e *fundEngine) runOnce(ctx context.Context, s *Server) {
fctx, cancel := context.WithTimeout(ctx, 60*time.Second)
defer cancel()
closes := s.fetchCloses(fctx, fundUniverse())
if _, err := e.rebalance(closes); err != nil {
logf("fund-brain: rebalance skipped: %v", err)
}
}
+180
View File
@@ -0,0 +1,180 @@
package world
import (
"math"
"sort"
)
// The fund model. A multi-asset-class conviction book layered on the same RRG
// kernel the rotation scanner computes (handlers_rotation.go): each asset-class
// SLEEVE is an equal-weight synthetic scored on the RS-Ratio / RS-Momentum plane
// against the benchmark (SPY), and conviction is the quadrant base plus a
// momentum tilt plus an oversold bonus — the faithful Go port of the reference
// model in research/rotation_model.py §5 (the "Book").
//
// The book is a PREFERRED PORTFOLIO, not an instruction to trade: model output,
// not investment advice. The autonomous engine (fund_engine.go) consumes it to
// drive a PAPER ledger only — see the Broker seam in fund_broker.go.
// A sleeve is a named asset-class basket priced as one equal-weight synthetic.
// Members index to 100 at the aligned window start so a $2 fund and a $900 coin
// contribute equally (basketSynthetic, shared with the rotation scanner).
type sleeve struct {
key, label, class string
members []string
}
// fundSleeves is the multi-asset universe: the AI buildout and its power bill
// (energy complex), the monetary/hard-asset hedges (Bitcoin, gold, silver), the
// on-chain risk sleeve (DeFi), and real assets (real estate). SPY is the
// benchmark (rotationBenchmark) and is priced separately.
var fundSleeves = []sleeve{
{"ai", "AI", "Equities · AI buildout", []string{"SMH", "SOXX", "NVDA", "AMD", "AVGO", "MSFT", "GOOGL", "META"}},
{"bitcoin", "Bitcoin", "Digital assets", []string{"IBIT", "BTC-USD", "COIN", "MSTR"}},
{"defi", "DeFi", "Digital assets", []string{"ETH-USD", "SOL-USD", "UNI-USD", "AAVE-USD"}},
{"gold", "Gold", "Precious metals", []string{"GLD", "IAU", "GDX"}},
{"silver", "Silver", "Precious metals", []string{"SLV", "SIL", "PSLV"}},
{"uranium", "Uranium", "Energy complex", []string{"URA", "URNM", "CCJ"}},
{"realestate", "Real estate", "Real assets", []string{"XLRE", "VNQ", "IYR"}},
{"energy", "Energy", "Energy complex", []string{"XLE", "XOP", "CVX", "XOM"}},
{"natgas", "Natural gas", "Energy complex", []string{"UNG", "FCG", "NG=F"}},
{"nuclear", "Nuclear power", "Energy complex", []string{"VST", "CEG", "NRG", "XLU"}},
}
// fundUniverse is every distinct symbol to fetch (sleeves benchmark), deduped.
func fundUniverse() []string {
seen := map[string]bool{rotationBenchmark: true}
out := []string{rotationBenchmark}
for _, sl := range fundSleeves {
for _, sym := range sl.members {
if !seen[sym] {
seen[sym] = true
out = append(out, sym)
}
}
}
return out
}
// Conviction weighting — the faithful port of research/rotation_model.py §5.
//
// QUAD_BASE = {improving 1.0, leading 0.72, weakening 0.22, lagging 0.08}
// conviction = QUAD_BASE + clip((mom-100)*0.16, -1.2, 1.2)
// + (improving & ret63<0 ? min(0.3, -ret63/100) : 0)
//
// Accumulate the turn-up (Improving), hold the leader (Leading), trim the topping
// leader (Weakening), avoid the falling laggard (Lagging); tilt by momentum; and
// pay a small bonus to a deeply-oversold theme that is turning up.
var quadBase = map[string]float64{
"improving": 1.0, "leading": 0.72, "weakening": 0.22, "lagging": 0.08,
}
var quadStance = map[string]string{
"improving": "Accumulate", "leading": "Core", "weakening": "Trim", "lagging": "Avoid",
}
// conviction scores one sleeve from its latest RRG point and 3-month return.
func conviction(p rrgPoint, ret63 float64) float64 {
c := quadBase[p.quadrant()] + clampf((p.mom-100)*0.16, -1.2, 1.2)
if p.quadrant() == "improving" && ret63 < 0 {
c += math.Min(0.3, -ret63/100)
}
if c < 0 {
return 0
}
return c
}
// clampf clamps v to [lo, hi]. (clamp01 is the [0,1] special case in
// handlers_cloud_router_pref.go; this is the general form the tilt needs.)
func clampf(v, lo, hi float64) float64 {
if v < lo {
return lo
}
if v > hi {
return hi
}
return v
}
// sleeveScore is one sleeve's full read: its RRG point, returns, and conviction.
type sleeveScore struct {
key, label, class, stance string
ratio, mom float64
quadrant string
ret21, ret63 float64
conviction float64
weight float64 // normalized preferred-portfolio weight, [0,1]
}
// scoreSleeves builds every sleeve's synthetic, scores it on the RRG plane, and
// normalizes conviction across the sleeves that have enough data into a preferred
// portfolio (weights sum to 1). A sleeve whose members are all too thin is
// dropped. Pure — the network lives in the caller (fetchCloses). This is the
// engine of both /v1/world/fund and the autonomous rebalancer.
func scoreSleeves(closes map[string][]float64) []sleeveScore {
bench := closes[rotationBenchmark]
if len(bench) < rrgLevelWindow+rrgMomLookback+1 {
return nil
}
scores := make([]sleeveScore, 0, len(fundSleeves))
var total float64
for _, sl := range fundSleeves {
members := make([][]float64, 0, len(sl.members))
for _, sym := range sl.members {
series := closes[sym]
if len(series) < rrgLevelWindow+rrgMomLookback+1 {
continue
}
members = append(members, series)
}
if len(members) == 0 {
continue
}
synth := basketSynthetic(members)
p, ok := rrgLatest(relSeries(synth, bench))
if !ok {
continue
}
ret63 := pctReturn(synth, 63)
c := conviction(p, ret63)
total += c
scores = append(scores, sleeveScore{
key: sl.key, label: sl.label, class: sl.class, stance: quadStance[p.quadrant()],
ratio: p.ratio, mom: p.mom, quadrant: p.quadrant(),
ret21: pctReturn(synth, 21), ret63: ret63, conviction: c,
})
}
if total > 0 {
for i := range scores {
scores[i].weight = scores[i].conviction / total
}
}
// Preferred portfolio order: highest conviction first.
sort.SliceStable(scores, func(i, j int) bool { return scores[i].conviction > scores[j].conviction })
return scores
}
// overallStance summarizes the book in one word from the aggregate posture:
// how much conviction sits in the accumulate/core sleeves vs trim/avoid.
func overallStance(scores []sleeveScore) (string, float64) {
var risk, total float64
for _, s := range scores {
total += s.weight
if s.quadrant == "improving" || s.quadrant == "leading" {
risk += s.weight
}
}
if total == 0 {
return "neutral", 0
}
frac := risk / total
switch {
case frac >= 0.66:
return "risk-on", frac
case frac >= 0.40:
return "balanced", frac
default:
return "risk-off", frac
}
}
+38 -16
View File
@@ -103,8 +103,16 @@ func (s *Server) handleAIPulse(w http.ResponseWriter, r *http.Request) {
}
// Poll fallback: one JSON snapshot (never cached downstream — it is live).
// EventSource cannot send Authorization, so the AUTHED transport is this poll:
// a signed-in admin gets a fresh per-caller snapshot built with THEIR OWN bearer
// (full measured usage + fleet), never the shared service-token snapshot.
w.Header().Set("Vary", "Authorization")
sctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
if bearer, ok := s.adminIdentity(r); ok {
writeJSON(w, http.StatusOK, "private, no-store", s.produceAIPulse(sctx, map[string]string{"Authorization": bearer}))
return
}
writeJSON(w, http.StatusOK, "no-store", s.aiPulseSnapshot(sctx))
}
@@ -141,7 +149,7 @@ func (s *Server) aiPulseSnapshot(ctx context.Context) aiPulse {
return v.(aiPulse)
}
v, _ := s.flight.do(aiPulseKey, func() (any, error) {
p := s.produceAIPulse(ctx)
p := s.produceAIPulse(ctx, serviceAuth())
ttl := aiPulseTTL
if p.State != "live" {
ttl = aiPulseFailTTL
@@ -152,15 +160,17 @@ func (s *Server) aiPulseSnapshot(ctx context.Context) aiPulse {
return v.(aiPulse)
}
// produceAIPulse reads both honest halves. It is "live" when either resolves;
// "unavailable" (with a reason) when there is no token or every upstream fails.
func (s *Server) produceAIPulse(ctx context.Context) aiPulse {
// produceAIPulse reads both honest halves using auth (the KMS service bearer for the
// public SSE, or a signed-in admin's OWN bearer for the authed poll). It is "live"
// when either resolves; "unavailable" (with a reason) when there is no auth or every
// upstream fails.
func (s *Server) produceAIPulse(ctx context.Context, auth map[string]string) aiPulse {
now := nowRFC()
if serviceToken() == "" {
return aiPulse{State: "unavailable", Reason: "service token not configured", UpdatedAt: now}
if auth == nil {
return aiPulse{State: "unavailable", Reason: "sign in for live compute telemetry (or wire the service token)", UpdatedAt: now}
}
usage := s.buildAIUsage(ctx)
fleet := s.buildAIFleet(ctx)
usage := s.buildAIUsage(ctx, auth)
fleet := s.buildAIFleet(ctx, auth)
if usage == nil && fleet == nil {
return aiPulse{State: "unavailable", Reason: "compute plane unreachable", UpdatedAt: now}
}
@@ -168,11 +178,24 @@ func (s *Server) produceAIPulse(ctx context.Context) aiPulse {
}
// buildAIUsage maps the measured platform usage ledger into the compute-panel
// shape. nil when the ledger is unreachable (no token / non-admin / upstream
// down) so the panel degrades honestly.
func (s *Server) buildAIUsage(ctx context.Context) *aiUsage {
ov, err := s.fetchCloudUsage(ctx, "24h")
// shape, read with auth. nil when the ledger is unreachable (no auth / non-admin /
// upstream down) so the panel degrades honestly.
func (s *Server) buildAIUsage(ctx context.Context, auth map[string]string) *aiUsage {
ov, err := s.fetchCloudUsage(ctx, "24h", auth)
if err != nil {
// Exact ledger denied → REAL platform usage from LLM observability (measured
// requests/tokens + real model names), so AI Compute shows live numbers for an
// operator instead of zeros. nil only when that is also unauthorized.
if u, ok := s.fetchLLMUsage(ctx, auth); ok {
return &aiUsage{
Window: "24h",
RequestsPerSec: round1(float64(u.Requests) / 86400),
TokensPerSec: round1(float64(u.Tokens) / 86400),
Requests24h: u.Requests,
Tokens24h: u.Tokens,
Models: u.Models,
}
}
return nil
}
window := ov.Range
@@ -191,10 +214,9 @@ func (s *Server) buildAIUsage(ctx context.Context) *aiUsage {
}
// buildAIFleet reads the live serving fleet (visor machines/gpus + ai model
// catalog). nil only when the machines read fails; gpus/models are best-effort
// bonus counts.
func (s *Server) buildAIFleet(ctx context.Context) *aiFleet {
hdr := serviceAuth()
// catalog) with auth. nil only when the machines read fails; gpus/models are
// best-effort bonus counts.
func (s *Server) buildAIFleet(ctx context.Context, hdr map[string]string) *aiFleet {
if hdr == nil {
return nil
}
+52
View File
@@ -158,3 +158,55 @@ func TestAIPulseSSEFrames(t *testing.T) {
}
}
}
// TestAIPulseAdminPoll proves the authed poll: a signed-in admin (z@hanzo.ai) with
// NO server-side service token gets the FULL measured compute pulse built with their
// OWN bearer, served no-store. EventSource can't carry auth, so this poll is the
// admin's live transport.
func TestAIPulseAdminPoll(t *testing.T) {
iam := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/iam/oauth/userinfo" || r.Header.Get("Authorization") == "" {
http.NotFound(w, r)
return
}
_, _ = w.Write([]byte(`{"owner":"hanzo","sub":"z@hanzo.ai"}`))
}))
t.Cleanup(iam.Close)
up := aiPulseUpstream(t)
t.Setenv("HANZO_CLOUD_PULSE_TOKEN", "") // no service token — the admin's bearer drives it
t.Setenv("HANZO_API_BASE", up.URL)
t.Setenv("HANZO_IAM_ISSUER", iam.URL)
t.Setenv("WORLD_ADMIN_ORGS", "hanzo") // operator org resolves via deploy env, not code
s := NewServer()
mux := http.NewServeMux()
s.Mount(mux)
ts := httptest.NewServer(mux)
t.Cleanup(ts.Close)
req, _ := http.NewRequest(http.MethodGet, ts.URL+"/v1/world/ai-pulse", nil)
req.Header.Set("Authorization", "Bearer admin-token")
req.Header.Set("Accept", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
if cc := resp.Header.Get("Cache-Control"); cc != "private, no-store" {
t.Fatalf("admin ai-pulse poll must be no-store, got %q", cc)
}
var p aiPulse
if err := json.NewDecoder(resp.Body).Decode(&p); err != nil {
t.Fatalf("decode: %v", err)
}
if p.State != "live" {
t.Fatalf("admin poll must be live with the caller's bearer, got %q (%s)", p.State, p.Reason)
}
if p.Usage == nil || p.Usage.Requests24h != 1_000_000 {
t.Fatalf("admin must see measured usage, got %+v", p.Usage)
}
if p.Fleet == nil || p.Fleet.Gpus != 3 {
t.Fatalf("admin must see the live fleet, got %+v", p.Fleet)
}
}
+489
View File
@@ -0,0 +1,489 @@
package world
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"regexp"
"strconv"
"strings"
"time"
)
// Alt-asset feeds behind the finance-terminal "Art & Collectibles — Auctions"
// and "Luxury Real Estate" panels (src/components/finance/AltFeedPanel.ts).
// Neither headline source is usable server-side, so each panel is served by a
// reachable, public, respectfully-scraped equivalent — fetched once an hour and
// served from cache to every caller. Both degrade to an honest empty
// {items:[]} (the SPA then renders "live feed pending") and NEVER fabricate a
// row.
//
// /v1/world/auctions → Christie's public results (realized SALE
// totals). Sotheby's — the requested headline — gates realized prices behind
// a login (its /data/api/asset.saleresults.json returns 401 "Not signed in"),
// so the honest public major house is Christie's, exactly the fallback the
// panel names ("Sotheby's / major-house results").
//
// /v1/world/luxury-realestate → LuxuryEstate.com listings. JamesEdition — the
// requested headline — sits behind a Cloudflare JS challenge that blocks
// datacenter egress (the pod runs in DOKS), so it cannot be fetched
// server-side; LuxuryEstate is a reachable, robots-permitted real source of
// the same thing (luxury listings with a price, place, type, image, link).
//
// The SPA reads exactly {items: AltFeedItem[]} where AltFeedItem is
// {title, subtitle?, price?, href?, imageUrl?, meta?}. Extra top-level fields
// (source, asOf, count, pending) are ignored by the panel and kept for
// humans/debugging + honest attribution.
const (
christiesResultsURL = "https://www.christies.com/en/results"
luxuryEstateURL = "https://www.luxuryestate.com/united-states?currency=USD"
auctionsCacheKey = "auctions:v1"
luxuryRealtyCacheKey = "luxury-realestate:v1"
altAssetsTTL = time.Hour // fresh window: at most one scrape/source/hour
altAssetsStale = 24 * time.Hour // serve last-good for a day through any source outage
altAssetsRefresh = time.Hour // background warmer cadence
altFeedMaxItems = 12 // the panel itself renders at most 12
altFeedCacheControl = "public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"
)
// altFeedItem mirrors the SPA's AltFeedItem exactly (see AltFeedPanel.ts). JSON
// tags match field-for-field; omitempty keeps optional fields absent, not empty.
type altFeedItem struct {
Title string `json:"title"`
Subtitle string `json:"subtitle,omitempty"`
Price string `json:"price,omitempty"`
Href string `json:"href,omitempty"`
ImageURL string `json:"imageUrl,omitempty"`
Meta string `json:"meta,omitempty"`
}
// handleAuctions serves /v1/world/auctions (Christie's realized sale totals).
func (s *Server) handleAuctions(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, auctionsCacheKey, altFeedCacheControl, altAssetsTTL, altAssetsStale,
func(ctx context.Context) (any, error) { return s.computeAuctions(ctx) },
func(w http.ResponseWriter, _ error) { writeAltFeedPending(w, "Christie's") })
}
// handleLuxuryRealestate serves /v1/world/luxury-realestate (LuxuryEstate listings).
func (s *Server) handleLuxuryRealestate(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, luxuryRealtyCacheKey, altFeedCacheControl, altAssetsTTL, altAssetsStale,
func(ctx context.Context) (any, error) { return s.computeLuxuryRealestate(ctx) },
func(w http.ResponseWriter, _ error) { writeAltFeedPending(w, "LuxuryEstate") })
}
// writeAltFeedPending is the honest cold-miss fallback (no cache yet AND the
// source is unreachable): an empty item list with a pending flag. The SPA
// renders "Live feed pending" for an empty list. Never a fabricated row, never a
// 5xx — so the routes smoke sweep and the panel both stay green.
func writeAltFeedPending(w http.ResponseWriter, source string) {
writeJSON(w, http.StatusOK, "", map[string]any{
"asOf": nowISO(), "source": source, "pending": true, "count": 0,
"items": []altFeedItem{},
})
}
// altFeedPayload is the shaped, cacheable success value. produce returns an error
// (not this) when it parses zero rows, so an empty list is never cached — the
// caller then serves the last-good copy or the pending fallback.
func altFeedPayload(source string, items []altFeedItem) map[string]any {
if len(items) > altFeedMaxItems {
items = items[:altFeedMaxItems]
}
return map[string]any{
"asOf": nowISO(), "source": source, "count": len(items), "items": items,
}
}
// ── auctions: Christie's ──────────────────────────────────────────────────────
func (s *Server) computeAuctions(ctx context.Context) (any, error) {
body, status, err := s.get(ctx, christiesResultsURL, map[string]string{
"Accept": "text/html,application/xhtml+xml",
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": browserUA,
})
if err != nil {
return nil, err
}
if status < 200 || status >= 300 {
return nil, fmt.Errorf("christies status %d", status)
}
items := parseChristiesAuctions(body)
if len(items) == 0 {
return nil, errUnavailable
}
return altFeedPayload("Christie's", items), nil
}
// christieSale is the subset of Christie's embedded results JSON we render. Only
// scalars are unmarshalled; the image URL is pulled from the raw object bytes
// (its nested srcset schema is picked over by regex, so a schema tweak can't
// break the whole parse).
type christieSale struct {
TitleTxt string `json:"title_txt"`
SubtitleTxt string `json:"subtitle_txt"`
DateDisplayTxt string `json:"date_display_txt"`
LocationTxt string `json:"location_txt"`
SaleTotalValueTxt string `json:"sale_total_value_txt"`
LandingURL string `json:"landing_url"`
}
// realizedTotalRe matches a realized total like "USD 1,135,380" / "HKD 10,319,750"
// — a 23 letter ISO currency code, a space, then a grouped amount. It filters
// out upcoming/estimate-only cards that carry no realized figure.
var realizedTotalRe = regexp.MustCompile(`^[A-Z]{2,3}\s[\d,]+$`)
// christiesImgRe matches a Christie's sale image URL and captures its width, so
// pickChristiesImage can choose a mid-size variant.
var christiesImgRe = regexp.MustCompile(`https://www\.christies\.com/img/SaleImages/[^"\\ ]+?\.jpg\?w=(\d+)`)
// parseChristiesAuctions extracts the embedded "events":[…] results array from
// the SSR HTML and maps each realized sale to an altFeedItem. Malformed input
// yields an empty slice, never a panic.
func parseChristiesAuctions(body []byte) []altFeedItem {
arr := extractBracketed(body, `"events":`, '[', ']')
if arr == nil {
return nil
}
var sales []json.RawMessage
if err := json.Unmarshal(arr, &sales); err != nil {
return nil
}
out := make([]altFeedItem, 0, len(sales))
for _, raw := range sales {
var sale christieSale
if err := json.Unmarshal(raw, &sale); err != nil {
continue
}
price := strings.TrimSpace(sale.SaleTotalValueTxt)
title := strings.TrimSpace(sale.TitleTxt)
if title == "" || !realizedTotalRe.MatchString(price) {
continue // upcoming / estimate-only / malformed — not a realized result
}
cat := classifyAuction(title + " " + sale.SubtitleTxt)
item := altFeedItem{
Title: title,
Price: price,
Href: absURL(sale.LandingURL, "https://www.christies.com"),
ImageURL: pickChristiesImage(raw),
Subtitle: "Christie's",
}
if loc := strings.TrimSpace(sale.LocationTxt); loc != "" {
item.Subtitle = "Christie's · " + loc
}
if d := strings.TrimSpace(sale.DateDisplayTxt); d != "" {
item.Meta = cat + " · " + d
} else {
item.Meta = cat
}
out = append(out, item)
}
return out
}
// pickChristiesImage returns the sale image whose width is closest to 640px (a
// crisp thumbnail without pulling the largest hero), scanning the raw object.
func pickChristiesImage(raw []byte) string {
best := ""
bestDiff := 1 << 30
for _, m := range christiesImgRe.FindAllSubmatch(raw, -1) {
w, err := strconv.Atoi(string(m[1]))
if err != nil || w <= 0 {
continue
}
d := w - 640
if d < 0 {
d = -d
}
if d < bestDiff {
bestDiff, best = d, string(m[0])
}
}
return best
}
// auctionCategory pairs a substring probe (lowercased title+subtitle) with the
// category label shown to the user. Ordered: first match wins.
var auctionCategories = []struct{ probe, label string }{
{"cellar", "Wine & Spirits"}, {"wine", "Wine & Spirits"}, {"whisky", "Wine & Spirits"},
{"whiskey", "Wine & Spirits"}, {"spirit", "Wine & Spirits"}, {"vintage", "Wine & Spirits"},
{"watch", "Watches"}, {"rolex", "Watches"}, {"patek", "Watches"}, {"horolog", "Watches"},
{"jewel", "Jewellery"}, {"diamond", "Jewellery"}, {"gemstone", "Jewellery"},
{"handbag", "Handbags & Accessories"}, {"hermès", "Handbags & Accessories"},
{"hermes", "Handbags & Accessories"}, {"birkin", "Handbags & Accessories"},
{"coin", "Gold & Coins"}, {"numismat", "Gold & Coins"}, {"bullion", "Gold & Coins"},
{"gold", "Gold & Coins"},
}
// classifyAuction infers a human category from the sale name (the source has no
// stable category label). It is a best-effort hint, never a fabricated fact;
// anything unmatched is the honest generic "Art & Collectibles".
func classifyAuction(text string) string {
t := strings.ToLower(text)
for _, c := range auctionCategories {
if strings.Contains(t, c.probe) {
return c.label
}
}
return "Art & Collectibles"
}
// ── luxury real estate: LuxuryEstate ──────────────────────────────────────────
func (s *Server) computeLuxuryRealestate(ctx context.Context) (any, error) {
body, status, err := s.get(ctx, luxuryEstateURL, map[string]string{
"Accept": "text/html,application/xhtml+xml",
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": browserUA,
})
if err != nil {
return nil, err
}
if status < 200 || status >= 300 {
return nil, fmt.Errorf("luxuryestate status %d", status)
}
items := parseLuxuryEstateListings(body)
if len(items) == 0 {
return nil, errUnavailable
}
return altFeedPayload("LuxuryEstate", items), nil
}
// luxuryListing is the subset of a LuxuryEstate propertiesList entry we render.
type luxuryListing struct {
Title string `json:"title"`
Label string `json:"label"`
Type string `json:"type"`
URL string `json:"url"`
Surface string `json:"surface"`
Bedrooms string `json:"bedrooms"`
PictureThumb string `json:"pictureThumb"`
Picture string `json:"picture"`
Price struct {
Amount string `json:"amount"`
Currency string `json:"currency"`
CurrencySymbol string `json:"currencySymbol"`
} `json:"price"`
GeoInfo struct {
Country string `json:"country"`
Region string `json:"region"`
City string `json:"city"`
} `json:"geoInfo"`
}
// parseLuxuryEstateListings extracts the embedded "propertiesList":[…] array and
// maps each listing to an altFeedItem. Malformed input yields an empty slice.
func parseLuxuryEstateListings(body []byte) []altFeedItem {
arr := extractBracketed(body, `"propertiesList":`, '[', ']')
if arr == nil {
return nil
}
var listings []luxuryListing
if err := json.Unmarshal(arr, &listings); err != nil {
return nil
}
out := make([]altFeedItem, 0, len(listings))
for _, l := range listings {
title := strings.TrimSpace(l.Title)
if title == "" {
title = strings.TrimSpace(l.Label)
}
if title == "" {
continue
}
img := strings.TrimSpace(l.PictureThumb)
if img == "" {
img = strings.TrimSpace(l.Picture)
}
out = append(out, altFeedItem{
Title: title,
Price: luxuryPrice(l),
Subtitle: luxuryLocation(l),
Href: absURL(l.URL, "https://www.luxuryestate.com"),
ImageURL: absScheme(img),
Meta: luxuryMeta(l),
})
}
return out
}
// luxuryPrice renders the listing's real price + currency, preferring the
// currency symbol ("US$5,950,000"), falling back to the currency code.
func luxuryPrice(l luxuryListing) string {
amt := strings.TrimSpace(l.Price.Amount)
if amt == "" {
return ""
}
if sym := strings.TrimSpace(l.Price.CurrencySymbol); sym != "" {
return sym + amt
}
if c := strings.TrimSpace(l.Price.Currency); c != "" {
return amt + " " + c
}
return amt
}
// luxuryLocation joins city with region (else country): "Banner Elk, North Carolina".
func luxuryLocation(l luxuryListing) string {
parts := make([]string, 0, 2)
if c := strings.TrimSpace(l.GeoInfo.City); c != "" {
parts = append(parts, c)
}
if r := strings.TrimSpace(l.GeoInfo.Region); r != "" {
parts = append(parts, r)
} else if c := strings.TrimSpace(l.GeoInfo.Country); c != "" {
parts = append(parts, c)
}
return strings.Join(parts, ", ")
}
// luxuryMeta renders "House · 5 bd · 655 m²" from whatever fields are present.
func luxuryMeta(l luxuryListing) string {
parts := make([]string, 0, 3)
if t := strings.TrimSpace(l.Type); t != "" {
parts = append(parts, t)
}
if b := strings.TrimSpace(l.Bedrooms); b != "" && b != "0" {
parts = append(parts, b+" bd")
}
if s := strings.TrimSpace(l.Surface); s != "" {
parts = append(parts, s)
}
return strings.Join(parts, " · ")
}
// ── shared parsing helpers ────────────────────────────────────────────────────
// extractBracketed returns the substring from the first `open` bracket that
// follows key through its matching `close` bracket, honoring JSON string escapes
// so brackets inside string values don't unbalance the scan. It is a targeted
// extractor for one embedded array/object inside a larger HTML/JS document — so
// the whole page never has to be parsed. Only whitespace or a colon may sit
// between key and the bracket. Returns nil when absent or unbalanced.
func extractBracketed(body []byte, key string, open, close byte) []byte {
i := bytes.Index(body, []byte(key))
if i < 0 {
return nil
}
j := i + len(key)
for j < len(body) && body[j] != open {
switch body[j] {
case ' ', '\t', '\n', '\r', ':':
j++
default:
return nil
}
}
if j >= len(body) {
return nil
}
depth, inStr, esc := 0, false, false
for k := j; k < len(body); k++ {
c := body[k]
switch {
case esc:
esc = false
case c == '\\':
esc = true
case c == '"':
inStr = !inStr
case inStr:
// inside a string: ignore brackets
case c == open:
depth++
case c == close:
depth--
if depth == 0 {
return body[j : k+1]
}
}
}
return nil
}
// absURL resolves a possibly-relative URL against base: "//host/…" → https://host/…,
// "/path" → base+/path, anything absolute is returned unchanged.
func absURL(u, base string) string {
u = strings.TrimSpace(u)
switch {
case u == "":
return ""
case strings.HasPrefix(u, "//"):
return "https:" + u
case strings.HasPrefix(u, "/"):
return base + u
default:
return u
}
}
// absScheme prepends https: to a scheme-relative ("//host/…") URL; leaves an
// already-absolute URL untouched.
func absScheme(u string) string {
u = strings.TrimSpace(u)
if strings.HasPrefix(u, "//") {
return "https:" + u
}
return u
}
// ── background warmer ─────────────────────────────────────────────────────────
// StartAltAssets warms the two alt-asset feeds on boot and refreshes them every
// hour until ctx is cancelled, so the panels serve a fresh cached hit instead of
// blocking on a cold scrape, and stay fresh even with sporadic traffic. These
// sources change at most daily; hourly is respectful — one request per source
// per hour — and the SWR cache keeps serving the last-good copy between
// refreshes and through any source outage. Warmer and handler share the same
// cache key + produce path + TTLs (the constants above), so they can never
// drift. Call once from main after the server is built.
func (s *Server) StartAltAssets(ctx context.Context) {
go func() {
s.warmAltAssets(ctx)
t := time.NewTicker(altAssetsRefresh)
defer t.Stop()
for {
select {
case <-ctx.Done():
return
case <-t.C:
s.warmAltAssets(ctx)
}
}
}()
}
// warmAltAssets (re)produces both feeds and stores each under the exact key its
// handler reads. A failure is logged and skipped; the next cycle retries and the
// last-good value keeps serving in the meantime.
func (s *Server) warmAltAssets(ctx context.Context) {
specs := []struct {
key string
produce func(context.Context) (any, error)
}{
{auctionsCacheKey, s.computeAuctions},
{luxuryRealtyCacheKey, s.computeLuxuryRealestate},
}
for _, spec := range specs {
if ctx.Err() != nil {
return
}
wctx, cancel := context.WithTimeout(ctx, 24*time.Second)
v, err := spec.produce(wctx)
cancel()
if err != nil {
logf("world-altassets: %s warm failed: %v", spec.key, err)
continue
}
s.cache.Set(spec.key, v, altAssetsTTL, altAssetsStale)
}
}
+166
View File
@@ -0,0 +1,166 @@
package world
import (
"encoding/json"
"net/http/httptest"
"os"
"strings"
"testing"
)
// The parsers are tested against REAL (trimmed) source captures in testdata, so
// a schema change at the source is caught here rather than in production. No
// network — deterministic. Live fetching is exercised by the routes smoke sweep
// (routes_test.go).
func TestParseChristiesAuctions(t *testing.T) {
body, err := os.ReadFile("testdata/christies_results.html")
if err != nil {
t.Fatal(err)
}
items := parseChristiesAuctions(body)
if len(items) != 2 {
t.Fatalf("want 2 items, got %d: %+v", len(items), items)
}
got := items[0]
want := altFeedItem{
Title: "The Cellar of an Obsessive Collector Part III: Online",
Subtitle: "Christie's · Hong Kong",
Price: "HKD 10,319,750",
Href: "https://onlineonly.christies.com/sso?SaleID=31386&SaleNumber=24946",
ImageURL: "https://www.christies.com/img/SaleImages/DEMO-1.jpg?w=600", // closest to 640
Meta: "Wine & Spirits · 9 21 July", // "Cellar" → wine
}
if got != want {
t.Errorf("item0 mismatch:\n got %+v\nwant %+v", got, want)
}
// A non-keyword sale falls back to the honest generic category.
if !strings.HasPrefix(items[1].Meta, "Art & Collectibles") {
t.Errorf("item1 category: want 'Art & Collectibles …', got %q", items[1].Meta)
}
if items[1].Price != "USD 1,135,380" {
t.Errorf("item1 price: got %q", items[1].Price)
}
}
func TestParseLuxuryEstateListings(t *testing.T) {
body, err := os.ReadFile("testdata/luxuryestate_results.html")
if err != nil {
t.Fatal(err)
}
items := parseLuxuryEstateListings(body)
if len(items) != 2 {
t.Fatalf("want 2 items, got %d: %+v", len(items), items)
}
got := items[0]
want := altFeedItem{
Title: "Luxury home in Banner Elk, Avery County",
Subtitle: "Banner Elk, North Carolina",
Price: "US$5,950,000",
Href: "https://www.luxuryestate.com/p131998951-luxury-home-for-sale-banner-elk",
ImageURL: "https://pic.le-cdn.com/thumbs/520x390/04/1/properties/Property-e7240000000007de000169121ee3-131998951.jpg",
Meta: "House · 5 bd · 655 m²",
}
if got != want {
t.Errorf("item0 mismatch:\n got %+v\nwant %+v", got, want)
}
if items[1].Price != "US$2,995,000" || items[1].Meta != "House · 4 bd · 403 m²" {
t.Errorf("item1: got price=%q meta=%q", items[1].Price, items[1].Meta)
}
}
func TestClassifyAuction(t *testing.T) {
cases := map[string]string{
"The Cellar of an Obsessive Collector": "Wine & Spirits",
"Fine and Rare Wines": "Wine & Spirits",
"Important Watches": "Watches",
"Magnificent Jewels and Diamonds": "Jewellery",
"Handbags & Accessories: Online": "Handbags & Accessories",
"Gold Coins of the Ancient World": "Gold & Coins",
"Tom Wesselmann: American Beauty": "Art & Collectibles", // no keyword → generic
}
for in, want := range cases {
if got := classifyAuction(in); got != want {
t.Errorf("classifyAuction(%q) = %q, want %q", in, got, want)
}
}
}
func TestExtractBracketed(t *testing.T) {
cases := []struct {
name, body, key string
open, close byte
want string
}{
{"array", `x "events": [1,2,3] y`, `"events":`, '[', ']', `[1,2,3]`},
{"nested-obj", `p "a":{"b":{"c":1}} q`, `"a":`, '{', '}', `{"b":{"c":1}}`},
{"bracket-in-string", `"k": ["a]b", "c"]`, `"k":`, '[', ']', `["a]b", "c"]`},
{"escaped-quote-in-string", `"k": ["a\"]b"]`, `"k":`, '[', ']', `["a\"]b"]`},
{"missing-key", `"other": [1]`, `"k":`, '[', ']', ""},
{"unbalanced", `"k": [1,2`, `"k":`, '[', ']', ""},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := string(extractBracketed([]byte(c.body), c.key, c.open, c.close))
if got != c.want {
t.Errorf("extractBracketed = %q, want %q", got, c.want)
}
})
}
}
// TestAltFeedItemMatchesSPAShape locks the JSON contract with the SPA's
// AltFeedItem interface (AltFeedPanel.ts): the exact key names, and omitempty so
// an item with only a title carries no empty optional keys.
func TestAltFeedItemMatchesSPAShape(t *testing.T) {
full, _ := json.Marshal(altFeedItem{
Title: "T", Subtitle: "S", Price: "P", Href: "H", ImageURL: "I", Meta: "M",
})
for _, k := range []string{`"title"`, `"subtitle"`, `"price"`, `"href"`, `"imageUrl"`, `"meta"`} {
if !strings.Contains(string(full), k) {
t.Errorf("marshalled item missing key %s: %s", k, full)
}
}
min, _ := json.Marshal(altFeedItem{Title: "only"})
if string(min) != `{"title":"only"}` {
t.Errorf("omitempty broken: %s", min)
}
}
// TestAltFeedPendingShape: the cold-miss fallback carries an empty ARRAY (never
// null) so the SPA's Array.isArray/length check renders "live feed pending"
// instead of throwing, and never a fabricated row.
func TestAltFeedPendingShape(t *testing.T) {
rec := httptest.NewRecorder()
writeAltFeedPending(rec, "Christie's")
var out struct {
Items []altFeedItem `json:"items"`
Pending bool `json:"pending"`
Source string `json:"source"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
t.Fatal(err)
}
if out.Items == nil || len(out.Items) != 0 {
t.Errorf("items must be empty array, got %#v", out.Items)
}
if !out.Pending || out.Source != "Christie's" {
t.Errorf("want pending+source, got %+v", out)
}
if !strings.Contains(rec.Body.String(), `"items":[]`) {
t.Errorf("items must serialize as [] not null: %s", rec.Body.String())
}
}
// TestParseGarbageNoPanic: malformed / empty input yields an empty slice, never
// a panic — the source can rot without taking the endpoint down.
func TestParseGarbageNoPanic(t *testing.T) {
for _, b := range [][]byte{nil, {}, []byte("not html"), []byte(`{"events": "oops"}`), []byte(`"propertiesList": [`)} {
if got := parseChristiesAuctions(b); len(got) != 0 {
t.Errorf("christies garbage → %d items", len(got))
}
if got := parseLuxuryEstateListings(b); len(got) != 0 {
t.Errorf("luxe garbage → %d items", len(got))
}
}
}
+1 -1
View File
@@ -304,7 +304,7 @@ func (s *Server) runAnalystLoop(ctx context.Context, bearer, model string, full
}
if err != nil || out == "" {
if err == nil {
err = fmt.Errorf("empty response")
err = emptyAnswerErr(firstNonEmpty(model, s.ai.model))
}
return "", nil, traces, tokens, id, err
}
+144
View File
@@ -1,6 +1,7 @@
package world
import (
"context"
"encoding/json"
"io"
"net/http"
@@ -308,6 +309,149 @@ func readAllString(r *http.Request) (string, error) {
return string(b), err
}
// writeChatMessage writes an OpenAI-shaped completion whose single choice carries
// the given assistant message object verbatim — used to model a reasoning model that
// leaves `content` empty and puts its answer on `reasoning_content`.
func writeChatMessage(w http.ResponseWriter, message map[string]any) {
resp := map[string]any{
"id": "resp_test",
"choices": []any{map[string]any{"message": message}},
"usage": map[string]any{"total_tokens": 7},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(resp)
}
// postAnalyst drives the non-streaming analyst path with a signed-in bearer and
// returns the decoded response envelope.
func postAnalyst(t *testing.T, ts *httptest.Server, prompt string) map[string]any {
t.Helper()
reqBody, _ := json.Marshal(map[string]any{
"messages": []map[string]string{{"role": "user", "content": prompt}},
})
req, _ := http.NewRequest(http.MethodPost, ts.URL+"/v1/world/analyst", strings.NewReader(string(reqBody)))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer user-token")
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Fatalf("status = %d, want 200 (never 5xx)", resp.StatusCode)
}
var out map[string]any
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
t.Fatalf("decode: %v", err)
}
return out
}
// TestAnalystRecoversReasoningWhenNoContent is the regression guard for the "empty
// response" break: a reasoning model (gpt-oss-120b / harmony) returns a 2xx with an
// EMPTY content channel and its answer on `reasoning_content`. The completion path
// must fall back to that channel so the analyst recovers the reply — not blank out.
func TestAnalystRecoversReasoningWhenNoContent(t *testing.T) {
ai := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
writeChatMessage(w, map[string]any{
"content": "",
"reasoning_content": `{"reply":"Markets are steady.","actions":[]}`,
})
}))
defer ai.Close()
s := NewServer()
s.ai.base = ai.URL
mux := http.NewServeMux()
s.Mount(mux)
ts := httptest.NewServer(mux)
defer ts.Close()
out := postAnalyst(t, ts, "Reply with strict JSON only")
if got, _ := out["reply"].(string); got != "Markets are steady." {
t.Fatalf("reasoning-channel answer not recovered: reply=%q full=%+v", got, out)
}
if out["error"] != nil {
t.Errorf("recovered answer should carry no error: %+v", out["error"])
}
}
// TestAnalystEmptyAnswerNamesModel pins the honest-error contract: a genuinely empty
// 2xx (a real choice, no content AND no reasoning) surfaces "the <model> model
// returned an empty answer" — never an opaque "empty response", and never a balance
// top-up (that is a distinct 402 contract).
func TestAnalystEmptyAnswerNamesModel(t *testing.T) {
ai := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
writeChatMessage(w, map[string]any{"content": ""})
}))
defer ai.Close()
s := NewServer() // default model "best"
s.ai.base = ai.URL
mux := http.NewServeMux()
s.Mount(mux)
ts := httptest.NewServer(mux)
defer ts.Close()
out := postAnalyst(t, ts, "hi")
if got, _ := out["reply"].(string); got != "" {
t.Fatalf("expected empty reply, got %q", got)
}
errStr, _ := out["error"].(string)
if strings.Contains(errStr, "empty response") {
t.Fatalf("still surfacing the opaque 'empty response': %q", errStr)
}
if !strings.Contains(errStr, "empty answer") || !strings.Contains(errStr, "best") {
t.Fatalf("empty error not honest/model-named: %q", errStr)
}
if out["topup"] == true {
t.Fatalf("empty answer must not be a balance/top-up error: %+v", out)
}
if out["fallback"] != true {
t.Errorf("empty answer should mark fallback=true: %+v", out)
}
}
// TestChatStreamRecoversReasoning covers the SSE path: a model that streams only
// `reasoning_content` deltas (no content channel) must still yield an answer, and the
// reasoning must be forwarded live (onDelta) so the UI shows the model working.
func TestChatStreamRecoversReasoning(t *testing.T) {
ai := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/event-stream")
fl, _ := w.(http.Flusher)
for _, f := range []string{
`{"id":"resp_1","choices":[{"delta":{"reasoning_content":"thinking… "}}]}`,
`{"id":"resp_1","choices":[{"delta":{"reasoning_content":"{\"reply\":\"from reasoning\"}"}}]}`,
`[DONE]`,
} {
_, _ = io.WriteString(w, "data: "+f+"\n\n")
if fl != nil {
fl.Flush()
}
}
}))
defer ai.Close()
s := NewServer()
s.ai.base = ai.URL
var streamed strings.Builder
out, _, id, err := s.ai.chatMessagesModelStream(context.Background(), s, "Bearer u", "gpt-oss-120b",
[]chatMessage{{Role: "user", Content: "hi"}}, 0.4, 700, nil, func(tok string) { streamed.WriteString(tok) })
if err != nil {
t.Fatalf("stream err: %v", err)
}
if id != "resp_1" {
t.Errorf("id = %q, want resp_1", id)
}
want := `thinking… {"reply":"from reasoning"}`
if out != want {
t.Fatalf("stream reasoning fallback wrong:\n got=%q\nwant=%q", out, want)
}
if streamed.String() != want {
t.Errorf("reasoning deltas not forwarded live: %q", streamed.String())
}
}
func TestSanitizeModelAndAgentRef(t *testing.T) {
cases := map[string]string{
"zen5": "zen5",
+16 -2
View File
@@ -32,6 +32,8 @@ const (
fredDEXCHUSURL = "https://api.stlouisfed.org/fred/series/observations?series_id=DEXCHUS&file_type=json&sort_order=desc&limit=2"
bisPolicyCacheKey = "economic:bis:policy:v1"
chinaMacroCacheKey = "china:macro:v1"
nbsCalendarIndexURL = "https://www.stats.gov.cn/english/PressRelease/ReleaseCalendar/"
chinaMoneyLPRURL = "https://www.chinamoney.com.cn/chinese/bklpr/?tab=2"
chinaMoneyLPRNoticeAPI = "https://www.chinamoney.com.cn/ags/ms/cm-s-notice-query/contentsinshorttime"
@@ -691,11 +693,18 @@ func (s *Server) handleChinaMacro(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, "china:macro:v1",
s.cachedJSON(w, chinaMacroCacheKey,
"public, max-age=1800, s-maxage=1800, stale-while-revalidate=600",
30*time.Minute, 6*time.Hour,
func(ctx context.Context) (any, error) { return s.chinaMacro(ctx) },
func(w http.ResponseWriter, _ error) { writeJSON(w, http.StatusOK, "", chinaUnavailable()) })
func(w http.ResponseWriter, _ error) {
// Negative-cache the honest unavailable payload briefly (fresh, no stale
// window) so repeated cache-misses are served instantly instead of each
// re-hanging on the blocked upstream; it re-attempts once the TTL lapses.
v := chinaUnavailable()
s.cache.Set(chinaMacroCacheKey, v, negativeTTL, 0)
writeJSON(w, http.StatusOK, "", v)
})
}
// oecdHeaders carries the Accept-Language the OECD CLI endpoint requires (it
@@ -721,6 +730,11 @@ func chinaReasonFor(err error) string {
}
func (s *Server) chinaMacro(ctx context.Context) (any, error) {
// Fail fast: OECD → NBS → ChinaMoney are fetched sequentially and any one can
// be slow/blocked from prod. Cap the whole flow well under the caller's global
// deadline so a blocked upstream returns unavailable in ~9s, not ~24s.
ctx, cancel := context.WithTimeout(ctx, 9*time.Second)
defer cancel()
now := time.Now().UTC()
checkedAt := now.Format(time.RFC3339)
var decisions []chinaSourceDecision
+418 -177
View File
@@ -2,35 +2,46 @@ package world
import (
"context"
"math"
"encoding/json"
"net/http"
"sort"
"net/url"
"strconv"
"strings"
"time"
)
// SaaS-mode "cloud pulse": the anonymized, platform-wide aggregate the signed-out
// investor view renders (world.hanzo.ai/?variant=saas). It is deliberately
// Platform "cloud pulse": the anonymized, platform-wide aggregate the flagship
// dashboard renders (world.hanzo.ai cloud/SaaS/AI variants). It is deliberately
// non-sensitive — counts and volume buckets only, never per-org spend or names.
//
// HONESTY CONTRACT (see cloud-pulse.ts on the client):
// - There is NO unauthenticated Hanzo endpoint that exposes platform-wide
// counts (verified against the OpenAPI specs: billing/visor/admin/ml/ai/o11y
// are all bearer-required; the only public surface, /v1/world/*, is external
// world data). So by default this route returns a clearly-labeled DEMO
// dataset with demo:true — the flag travels in the payload and the UI shows a
// "demo data" note. We never fake platform numbers silently.
// - When an operator wires the service token (serviceToken, from KMS), we make
// SERVICE-side calls to the real cloud for non-sensitive COUNTS (models
// served, node/region/GPU counts) and set demo:false. With a super-admin
// token we also read the platform-wide 24h request/token VOLUME from the
// ClickHouse-backed usage ledger (get-cloud-usages ?org=all) and clear
// volumeModeled. If only the counts resolve (e.g. a non-admin token), volume
// stays modeled and is flagged volumeModeled:true — again, never silently
// faked.
// HONESTY CONTRACT — NOTHING is fabricated. Every number is REAL (measured by an
// actual backend) or an honest zero/empty. There is no diurnal-sine "demo" curve,
// no hardcoded uptime, no invented model mix or per-region rate. The honest source
// ladder (producePulse), best → last:
//
// Signed-in, org-scoped drill-down (the user's own fleet / models / bill) does
// NOT come through here — those panels call api.hanzo.ai directly with the
// caller's IAM token (no shared key). This route is the public teaser only.
// - VOLUME (requests/sec, 24h requests/tokens, series, model mix):
// 1. the super-admin usage ledger (get-cloud-usages ?org=all, ClickHouse) —
// MEASURED and exact (tokens + spend); clears volumeModeled.
// 2. else the REAL, public endpoints this same binary already serves: the
// native request-geo globe (traffic-globe, totals.rps_1m) for the
// headline rate, and the learned-router stats (router-stats) for total
// routed requests + hourly throughput + per-model mix. Token volume is not
// measured on this path, so tokens stay blank and volumeModeled stays true.
// 3. else empty (zeros / empty arrays).
// - FLEET COUNTS + REGION breakdown: the service-token visor (/v1/machines,
// /v1/gpus) + ai catalog (/v1/models). Absent ⇒ zeros and an empty region list
// built from the real fleet — never the geo catalog as if it were live.
// - UPTIME: the public status page (Gatus up/total). Unreachable ⇒ 0 and the
// overview drops the tile — never a constant.
//
// demo:true means ONLY that nothing real resolved (a warming-up / not-wired state),
// never that a number was invented. Signed-in / token-wired deployments see the
// full measured aggregate; the tokenless public path still shows real request rate,
// throughput, model mix, uptime and chain scale.
//
// Signed-in, org-scoped drill-down (the user's own fleet / models / bill) does NOT
// come through here — those panels call api.hanzo.ai directly with the caller's IAM
// token (no shared key). This route is the platform teaser only.
type cloudOverview struct {
RequestsPerSec float64 `json:"requestsPerSec"`
@@ -77,44 +88,143 @@ type cloudPulse struct {
TokenSeries []int64 `json:"tokenSeries"`
Models []cloudModel `json:"models"`
Regions []cloudRegion `json:"regions"`
// Users is populated ONLY on the signed-in admin path (real IAM aggregates:
// total users, signups, active now, daily-signup series). omitempty ⇒ the public
// teaser never carries it.
Users *userMetrics `json:"users,omitempty"`
}
// handleCloudPulse serves the public SaaS aggregate. It never 5xxes: any upstream
// failure degrades to the demo dataset with demo:true.
// publicVolumeTimeout bounds each public fallback fetch (traffic-globe, router-stats,
// status page) so a single slow/unreachable host can't stall the pulse produce.
const publicVolumeTimeout = 5 * time.Second
// handleCloudPulse serves the platform aggregate. Two honest representations:
//
// - SIGNED-IN ADMIN (z@hanzo.ai / the admin org): the FULL real aggregate, with
// the token-plane reads (all-org usage ledger + visor fleet) made using the
// CALLER's OWN bearer, never edge-cached. The upstream independently authorizes
// the bearer, so a non-super-admin simply degrades to the public sources —
// never a fabricated number.
// - EVERYONE ELSE (public teaser): cached; service-token counts + real public
// volume/uptime.
//
// It never 5xxes: any upstream failure degrades to the honest empty pulse.
func (s *Server) handleCloudPulse(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
// Authed responses must never be served from (or stored in) the shared public
// cache: vary on Authorization so an anonymous cache entry is never handed to a
// signed-in caller, and vice-versa.
w.Header().Set("Vary", "Authorization")
if bearer, ok := s.adminIdentity(r); ok {
ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second)
defer cancel()
hdr := map[string]string{"Authorization": bearer}
p := s.producePulse(ctx, hdr)
// Real platform user metrics (IAM global-users) — admin path only; aggregates
// only, never PII. Omitted honestly if the caller isn't a global admin upstream.
if um, err := s.fetchUserMetrics(ctx, hdr); err == nil {
p.Users = um
}
// Real platform USAGE + per-model mix from LLM observability (measured requests,
// tokens, and REAL model names — not the opaque router arms), when the exact
// usage ledger was not available to this caller. Fixes an empty "Model Usage"
// and 0-token totals for an operator who can read platform observability.
if p.VolumeModeled || len(p.Models) == 0 {
s.applyLLMObservability(ctx, &p, hdr)
}
writeJSON(w, http.StatusOK, "private, no-store", p)
return
}
s.cachedJSON(w, "cloud-pulse", "public, max-age=15, s-maxage=15, stale-while-revalidate=60",
20*time.Second, 5*time.Minute,
func(ctx context.Context) (any, error) {
base := demoPulse()
if p, ok := s.tryServicePulse(ctx, base); ok {
return p, nil
}
return base, nil
return s.producePulse(ctx, serviceAuth()), nil
},
func(w http.ResponseWriter, _ error) {
// Unreachable in practice (produce never errors), but keep the
// never-5xx guarantee explicit.
writeJSON(w, http.StatusOK, "", demoPulse())
writeJSON(w, http.StatusOK, "", emptyPulse())
},
)
}
// tryServicePulse overlays REAL platform data onto the demo scaffold when a
// service token is configured (serviceToken, KMS-injected). It returns ok=false —
// leaving the honest demo dataset in place — when the token is absent or the core
// counts calls fail. It reads two honest sources: non-sensitive COUNTS (models
// served, node/region/GPU counts from the ai catalog + visor) and, when the
// super-admin usage ledger is reachable, the platform-wide 24h request/token
// VOLUME (get-cloud-usages ?org=all). When volume is real, demo:false AND
// volumeModeled:false; when only counts are real, volume stays modeled and
// volumeModeled:true — never silently faked.
func (s *Server) tryServicePulse(ctx context.Context, base cloudPulse) (cloudPulse, bool) {
hdr := serviceAuth()
// emptyPulse is the honest zero baseline: no measured data resolved. Every number
// is zero and the arrays are empty (never null) — flagged demo:true (nothing real
// yet) and volumeModeled:true (no measured volume). We never fabricate.
func emptyPulse() cloudPulse {
return cloudPulse{
Demo: true,
VolumeModeled: true,
Source: "empty",
Note: "Platform metrics are warming up — no measured data is reachable yet. Wire the service token (KMS) for the full live aggregate.",
UpdatedAt: nowRFC(),
Window: "24h",
RequestSeries: []int64{},
TokenSeries: []int64{},
Models: []cloudModel{},
Regions: []cloudRegion{},
}
}
// producePulse assembles the pulse from ONLY real sources (see the file header for
// the honesty ladder). auth is the token-plane header (the KMS service bearer on the
// public path, or the signed-in admin's own bearer on the flagship admin path); nil
// leaves the token-plane reads out and the pulse falls back to the public sources.
// demo:true iff nothing real resolved; every field is real or an honest zero/empty.
func (s *Server) producePulse(ctx context.Context, auth map[string]string) cloudPulse {
p := emptyPulse()
real := false
volSrc := ""
// 1) Fleet COUNTS + REGION breakdown (auth → visor + ai catalog).
countsReal := s.applyServiceCounts(ctx, &p, auth)
if countsReal {
real = true
}
// 2) VOLUME — measured ledger first (super-admin ?org=all, exact); else the real
// public request rate + throughput + model mix; else empty. Never modeled.
if ov, err := s.fetchCloudUsage(ctx, "24h", auth); err == nil && ov.Totals.Requests > 0 {
applyUsageToPulse(&p, ov) // clears volumeModeled, fills tokens/series/models
real, volSrc = true, "ledger"
} else if s.applyPublicVolume(ctx, &p) {
real, volSrc = true, "router" // real rate/throughput/mix; tokens unmeasured ⇒ volumeModeled stays true
}
// 3) UPTIME — real share of healthy endpoints (Gatus up/total). 0 ⇒ tile dropped.
if up, ok := s.fetchUptimePct(ctx); ok {
p.Overview.UptimePct = up
real = true
}
p.Demo = !real
switch {
case countsReal:
p.Source = "service" // the service-token plane resolved (counts, and usually ledger volume)
case real:
p.Source = "public" // tokenless, but real public volume/uptime landed
default:
p.Source = "empty"
}
if real && volSrc == "" {
p.Note = "Live fleet and status from Hanzo Cloud. Measured request and token volume appears when the platform usage ledger is reachable."
}
return p
}
// applyServiceCounts fills the real fleet counts (models served, nodes online/total,
// GPUs) and the region breakdown from the service-token visor + ai catalog. Regions
// are derived from the machines' OWN region strings (resolved to the geo catalog for
// name/city/coords) — an empty fleet yields an empty regions list, never the geo
// catalog as if it were live; per-region rate stays 0 (no real per-region source).
// Returns false (leaving zeros) when no auth header is supplied or the core reads
// fail. auth is the KMS service bearer (public path) or the caller's own admin
// bearer (admin path).
func (s *Server) applyServiceCounts(ctx context.Context, p *cloudPulse, hdr map[string]string) bool {
if hdr == nil {
return cloudPulse{}, false
return false
}
host := apiHost()
@@ -125,7 +235,7 @@ func (s *Server) tryServicePulse(ctx context.Context, base cloudPulse) (cloudPul
} `json:"data"`
}
if err := s.getJSON(ctx, host+"/v1/models", hdr, &models); err != nil || len(models.Data) == 0 {
return cloudPulse{}, false
return false
}
// Fleet (visor). status is a free string; treat non-terminal states as online.
@@ -136,7 +246,7 @@ func (s *Server) tryServicePulse(ctx context.Context, base cloudPulse) (cloudPul
} `json:"machines"`
}
if err := s.getJSON(ctx, host+"/v1/machines", hdr, &machines); err != nil {
return cloudPulse{}, false
return false
}
var gpus struct {
Gpus []struct {
@@ -146,45 +256,268 @@ func (s *Server) tryServicePulse(ctx context.Context, base cloudPulse) (cloudPul
// GPUs are a bonus count; a failure here should not sink real machine data.
_ = s.getJSON(ctx, host+"/v1/gpus", hdr, &gpus)
regionSet := map[string]int{}
// Real region breakdown: place each machine/GPU into its resolved catalog region
// (name/city/coords), counting nodes + GPUs. rps stays 0 — no invented rate.
agg := map[string]*cloudRegion{}
var order []string
// Resolve to the geo catalog for coords/name when the region is known; otherwise
// keep the RAW region string as its own region (a real region, just without
// catalog coordinates) so EVERY real region shows — never dropped just because
// it's outside the 8-city catalog (e.g. tor1, GCP/AWS regions).
region := func(raw string) *cloudRegion {
raw = strings.TrimSpace(raw)
if raw == "" {
return nil
}
id := raw
nc := cloudRegion{ID: raw, Name: raw, City: raw, Status: "online"}
if rg, ok := resolveRegion(raw); ok {
id = rg.ID
nc = rg
nc.Nodes, nc.Gpus, nc.RequestsPerSec, nc.Status = 0, 0, 0, "online"
}
if c := agg[id]; c != nil {
return c
}
agg[id] = &nc
order = append(order, id)
return &nc
}
online := 0
for _, m := range machines.Machines {
if machineOnline(m.Status) {
online++
}
if m.Region != "" {
regionSet[m.Region]++
if c := region(m.Region); c != nil {
c.Nodes++
}
}
for _, g := range gpus.Gpus {
if c := region(g.Region); c != nil {
c.Gpus++
}
}
p := base
p.Demo = false
p.Source = "service"
p.Overview.ModelsServed = len(models.Data)
p.Overview.NodesTotal = len(machines.Machines)
p.Overview.NodesOnline = online
p.Overview.GpusOnline = len(gpus.Gpus)
if len(regionSet) > 0 {
p.Overview.Regions = len(regionSet)
regions := make([]cloudRegion, 0, len(order))
for _, id := range order {
regions = append(regions, *agg[id])
}
// Real platform VOLUME from the ClickHouse-backed usage ledger (all orgs).
// When it lands, it replaces the modeled headline/series/top-models and clears
// volumeModeled; when the read fails (e.g. a non-super-admin token, or the
// ledger is unreachable) the modeled volume stays and the flag stays true.
if ov, err := s.fetchCloudUsage(ctx, "24h"); err == nil && ov.Totals.Requests > 0 {
applyUsageToPulse(&p, ov)
} else {
p.VolumeModeled = true
p.Note = "Live counts from Hanzo Cloud (models/nodes/regions). Request & token volume is modeled — the platform usage ledger was not reachable with this token."
}
return p, true
p.Regions = regions
p.Overview.Regions = len(regions)
return true
}
// applyUsageToPulse folds the real platform-wide usage overview into p: the
// headline rate (recent series bucket, else 24h average), 24h totals, the real
// hourly request/token series, and the top models by real spend. It clears
// volumeModeled — these are measured, not modeled.
// applyPublicVolume folds REAL, public request volume into p when the measured
// ledger is unavailable — no fabrication. It reads the SAME endpoints this binary
// already serves to other panels: the native request-geo globe (traffic-globe,
// totals.rps_1m — the Live Traffic rate) for the headline requests/sec, and the
// learned-router stats (router-stats, the Enso Training source) for total routed
// requests, the hourly throughput series and the per-model request mix. Token
// volume is NOT measured on this path, so Tokens24h / TokenSeries stay empty and
// volumeModeled stays true. Returns true when at least one real datum landed.
func (s *Server) applyPublicVolume(ctx context.Context, p *cloudPulse) bool {
cctx, cancel := context.WithTimeout(ctx, publicVolumeTimeout)
defer cancel()
got := false
// Headline requests/sec — real, from the native LB request-geo aggregate.
if g, ok := s.fetchNativeGlobe(cctx, 60); ok && g.Totals.RPS1m > 0 {
p.Overview.RequestsPerSec = round1(g.Totals.RPS1m)
got = true
}
// Routed-request volume + hourly throughput — real, from the public learned-router
// stats (the Enso Training source). NOTE: on platform scope the router relabels
// models to OPAQUE "arm-N" ids (a privacy measure), so by_model is NOT real model
// names — we never present it as the model mix. Real per-model usage comes only
// from the measured ledger (admin path); otherwise Models stays empty and the
// panel honestly shows "warming up" rather than "arm-8".
if rs, ok := s.fetchRouterStats(cctx, 24); ok {
events := rs.Window.Events
if events == 0 {
events = rs.Throughput.TotalWindow
}
if events > 0 {
p.Overview.Requests24h = events
if p.Overview.RequestsPerSec == 0 { // globe rate unavailable → window average
p.Overview.RequestsPerSec = round1(float64(events) / routerWindowSecs(rs))
}
got = true
}
if len(rs.Throughput.PerHour) > 0 {
p.RequestSeries = append([]int64{}, rs.Throughput.PerHour...)
got = true
}
}
if got {
p.Window = "24h"
p.Note = "Live platform request rate and throughput — measured across all orgs (traffic globe + learned router). Per-model usage and token volume come from the usage ledger (sign in as an admin)."
}
return got
}
// llmUsage is the measured platform usage from LLM observability (/v1/admin/o11y):
// 24h request/token totals + top models by REAL name. ONE place shapes the o11y read
// so cloud-pulse and ai-pulse share it (DRY) — the opaque router arms are never used.
type llmUsage struct {
Requests int64
Tokens int64
Models []cloudModel
}
// fetchLLMUsage reads the platform LLM observability aggregate with the admin's own
// bearer. ok=false when the caller isn't authorized upstream or it's unreachable, so
// callers keep their honest fallback.
func (s *Server) fetchLLMUsage(ctx context.Context, auth map[string]string) (*llmUsage, bool) {
if auth == nil {
return nil, false
}
var resp struct {
Totals struct {
Requests int64 `json:"requests"`
Tokens int64 `json:"tokens"`
} `json:"totals"`
TopModels []struct {
Model string `json:"model"`
Requests int64 `json:"requests"`
Tokens int64 `json:"tokens"`
} `json:"topModels"`
}
if err := s.getJSON(ctx, apiHost()+"/v1/admin/o11y?range=24h", auth, &resp); err != nil {
return nil, false
}
u := &llmUsage{Requests: resp.Totals.Requests, Tokens: resp.Totals.Tokens}
var total int64
for _, m := range resp.TopModels {
total += m.Requests
}
if total > 0 {
for _, m := range resp.TopModels {
if m.Model == "" {
continue
}
u.Models = append(u.Models, cloudModel{
ID: m.Model, Name: m.Model, Requests24h: m.Requests, Tokens24h: m.Tokens,
Share: float64(m.Requests) / float64(total),
})
}
}
if u.Requests == 0 && len(u.Models) == 0 {
return nil, false
}
return u, true
}
// applyLLMObservability overlays REAL platform usage (fetchLLMUsage) onto the pulse:
// measured requests/tokens + the real model mix (never the opaque router arms). It
// clears volumeModeled when real numbers land and keeps the freshest rate (globe rps)
// if already set. No-op (honest fallback kept) when the caller can't read o11y.
func (s *Server) applyLLMObservability(ctx context.Context, p *cloudPulse, auth map[string]string) {
u, ok := s.fetchLLMUsage(ctx, auth)
if !ok {
return
}
if u.Requests > 0 {
p.Overview.Requests24h = u.Requests
p.Overview.Tokens24h = u.Tokens
if p.Overview.RequestsPerSec == 0 { // keep the globe's live rate when we have it
p.Overview.RequestsPerSec = round1(float64(u.Requests) / 86400)
}
}
if len(u.Models) > 0 {
p.Models = u.Models
}
p.VolumeModeled = false
p.Window = "24h"
p.Note = "Live platform usage from Hanzo LLM observability — measured requests, tokens and model mix across all orgs."
}
// routerStatsVolume is the subset of the public router-stats aggregate we fold into
// the pulse: total routed events (requests), the hourly throughput series, and the
// per-model event mix. Same upstream the Enso Training panel proxies.
type routerStatsVolume struct {
Window struct {
Since string `json:"since"`
Until string `json:"until"`
Events int64 `json:"events"`
} `json:"window"`
Throughput struct {
PerHour []int64 `json:"per_hour"`
TotalWindow int64 `json:"total_window"`
} `json:"throughput"`
// by_model is intentionally NOT decoded: on platform scope it is opaque "arm-N"
// ids, never real model names, so it is never used as the model mix.
}
// fetchRouterStats reads the PUBLIC learned-router aggregate (no token) and unwraps
// the {status,data} envelope, exactly as handleCloudRouterStats does. ok=false when
// unreachable or the envelope is not ok.
func (s *Server) fetchRouterStats(ctx context.Context, hours int) (*routerStatsVolume, bool) {
var env struct {
Status string `json:"status"`
Data json.RawMessage `json:"data"`
}
u := apiHost() + "/v1/router/stats?scope=platform&hours=" + strconv.Itoa(hours)
if err := s.getJSON(ctx, u, nil, &env); err != nil {
return nil, false
}
if env.Status != "ok" || len(env.Data) == 0 || string(env.Data) == "null" {
return nil, false
}
var rs routerStatsVolume
if err := json.Unmarshal(env.Data, &rs); err != nil {
return nil, false
}
return &rs, true
}
// routerWindowSecs is the router-stats window length in seconds (since→until),
// defaulting to 24h when the timestamps are missing/unparseable — so a window
// average never divides by a bogus interval.
func routerWindowSecs(rs *routerStatsVolume) float64 {
if t0, e0 := time.Parse(time.RFC3339, rs.Window.Since); e0 == nil {
if t1, e1 := time.Parse(time.RFC3339, rs.Window.Until); e1 == nil {
if d := t1.Sub(t0).Seconds(); d > 0 {
return d
}
}
}
return 86400
}
// fetchUptimePct derives a real platform uptime from the PUBLIC status page (Gatus):
// the share of monitored endpoints currently healthy (up/total, 0..100). ok=false
// when the page is unreachable or has no evaluated endpoints — the overview then
// drops the uptime tile rather than showing a constant.
func (s *Server) fetchUptimePct(ctx context.Context) (float64, bool) {
cctx, cancel := context.WithTimeout(ctx, publicVolumeTimeout)
defer cancel()
base := statusBase()
host := ""
if u, err := url.Parse(base); err == nil {
host = u.Hostname()
}
raw, ok := s.fetchGatusBoard(cctx, base, host)
if !ok {
return 0, false
}
sp := summarizeStatusPage(host, raw)
if sp.Total == 0 {
return 0, false
}
return round2s(float64(sp.Up) / float64(sp.Total) * 100), true
}
// applyUsageToPulse folds the real platform-wide usage overview into p: the headline
// rate (recent series bucket, else 24h average), 24h totals, the real hourly
// request/token series, and the top models by real spend. It clears volumeModeled —
// these are measured, not modeled.
func applyUsageToPulse(p *cloudPulse, ov *cloudUsageOverview) {
p.VolumeModeled = false
p.Window = ov.Range
@@ -226,114 +559,22 @@ func machineOnline(status string) bool {
}
}
// demoPulse builds the illustrative dataset. Numbers follow a smooth diurnal
// curve keyed on wall-clock time so the ticker feels alive across refreshes,
// but the demo flag makes clear these are not live platform metrics.
func demoPulse() cloudPulse {
now := time.Now().UTC()
// Diurnal load factor in [0.55, 1.0]: peaks ~16:00 UTC, troughs ~04:00 UTC.
hourFrac := float64(now.Hour()) + float64(now.Minute())/60
load := 0.775 + 0.225*math.Sin((hourFrac-10)/24*2*math.Pi)
// A slow per-minute wobble so the live-activity sparkline moves each poll.
wobble := 1 + 0.04*math.Sin(float64(now.Unix()%600)/600*2*math.Pi)
regions := demoRegions()
baseRPS := 4200.0 * load * wobble
nodesOnline, nodesTotal, gpus := 0, 0, 0
for i := range regions {
regions[i].RequestsPerSec = round1(baseRPS * regions[i].RequestsPerSec) // field held a weight
nodesTotal += regions[i].Nodes
gpus += regions[i].Gpus
if regions[i].Status == "online" {
nodesOnline += regions[i].Nodes
}
}
models := demoModels(baseRPS)
requests24h := int64(baseRPS * 86400)
tokens24h := requests24h * 1180 // ~1.18k tokens/request average
return cloudPulse{
Demo: true,
VolumeModeled: true,
Source: "demo",
Note: "Demo data — no unauthenticated platform-metrics endpoint exists. Sign in to see your org's real fleet, models and bill.",
UpdatedAt: now.Format(time.RFC3339),
Window: "24h",
Overview: cloudOverview{
RequestsPerSec: round1(baseRPS),
Requests24h: requests24h,
Tokens24h: tokens24h,
ModelsServed: len(models),
NodesOnline: nodesOnline,
NodesTotal: nodesTotal,
GpusOnline: gpus,
Regions: len(regions),
UptimePct: 99.98,
},
RequestSeries: demoSeries(baseRPS, now, 1),
TokenSeries: demoSeries(baseRPS*1180, now, 1),
Models: models,
Regions: regions,
}
}
// demoSeries returns 24 hourly buckets ending now, following the same diurnal
// curve as the headline so the sparkline and the number agree.
func demoSeries(scale float64, now time.Time, _ int) []int64 {
out := make([]int64, 24)
for i := 0; i < 24; i++ {
h := float64(now.Add(time.Duration(i-23) * time.Hour).Hour())
load := 0.775 + 0.225*math.Sin((h-10)/24*2*math.Pi)
jitter := 1 + 0.03*math.Sin(float64(i)*1.7)
out[i] = int64(scale * load * jitter * 3600)
}
return out
}
func demoModels(baseRPS float64) []cloudModel {
// Representative of Hanzo's served surface: Zen family (qwen3+ base) plus
// routed frontier models. Shares are illustrative.
rows := []struct {
id, name string
share float64
}{
{"zen-omni-30b", "Zen Omni 30B", 0.28},
{"zen-coder-32b", "Zen Coder 32B", 0.19},
{"zen-1", "Zen 1", 0.14},
{"qwen3-235b", "Qwen3 235B", 0.12},
{"zen-nano-4b", "Zen Nano 4B", 0.10},
{"deepseek-v3", "DeepSeek V3", 0.07},
{"zen-vl-8b", "Zen VL 8B", 0.06},
{"llama-3.3-70b", "Llama 3.3 70B", 0.04},
}
out := make([]cloudModel, len(rows))
for i, r := range rows {
req := int64(baseRPS * r.share * 86400)
out[i] = cloudModel{
ID: r.id,
Name: r.name,
Requests24h: req,
Tokens24h: req * 1180,
Share: r.share,
}
}
sort.SliceStable(out, func(a, b int) bool { return out[a].Requests24h > out[b].Requests24h })
return out
}
// demoRegions models Hanzo's DOKS footprint. RequestsPerSec temporarily carries
// a per-region weight (summing to 1.0) that demoPulse scales into a real rate.
func demoRegions() []cloudRegion {
// regionCatalog is Hanzo's DOKS geo catalog — the reference coordinates (id / name /
// city / country / lat / lon) the map layers place points against, plus per-region
// capacity weights (Nodes / Gpus) the modeled-globe layer spreads real peer counts
// across (flagged positionsModeled:true there). It is NOT live fleet data: the
// cloud-pulse never presents it as such — the pulse's region breakdown is built from
// the real visor fleet (applyServiceCounts).
func regionCatalog() []cloudRegion {
return []cloudRegion{
{ID: "nyc", Name: "New York", City: "New York", Country: "USA", Lat: 40.7128, Lon: -74.0060, Nodes: 42, Gpus: 168, Status: "online", RequestsPerSec: 0.24},
{ID: "sfo", Name: "San Francisco", City: "San Francisco", Country: "USA", Lat: 37.7749, Lon: -122.4194, Nodes: 38, Gpus: 152, Status: "online", RequestsPerSec: 0.21},
{ID: "ams", Name: "Amsterdam", City: "Amsterdam", Country: "Netherlands", Lat: 52.3676, Lon: 4.9041, Nodes: 26, Gpus: 96, Status: "online", RequestsPerSec: 0.15},
{ID: "fra", Name: "Frankfurt", City: "Frankfurt", Country: "Germany", Lat: 50.1109, Lon: 8.6821, Nodes: 22, Gpus: 88, Status: "online", RequestsPerSec: 0.12},
{ID: "lon", Name: "London", City: "London", Country: "UK", Lat: 51.5074, Lon: -0.1278, Nodes: 18, Gpus: 64, Status: "online", RequestsPerSec: 0.10},
{ID: "sgp", Name: "Singapore", City: "Singapore", Country: "Singapore", Lat: 1.3521, Lon: 103.8198, Nodes: 16, Gpus: 60, Status: "online", RequestsPerSec: 0.08},
{ID: "blr", Name: "Bangalore", City: "Bangalore", Country: "India", Lat: 12.9716, Lon: 77.5946, Nodes: 12, Gpus: 40, Status: "degraded", RequestsPerSec: 0.06},
{ID: "syd", Name: "Sydney", City: "Sydney", Country: "Australia", Lat: -33.8688, Lon: 151.2093, Nodes: 8, Gpus: 24, Status: "online", RequestsPerSec: 0.04},
{ID: "nyc", Name: "New York", City: "New York", Country: "USA", Lat: 40.7128, Lon: -74.0060, Nodes: 42, Gpus: 168, Status: "online"},
{ID: "sfo", Name: "San Francisco", City: "San Francisco", Country: "USA", Lat: 37.7749, Lon: -122.4194, Nodes: 38, Gpus: 152, Status: "online"},
{ID: "ams", Name: "Amsterdam", City: "Amsterdam", Country: "Netherlands", Lat: 52.3676, Lon: 4.9041, Nodes: 26, Gpus: 96, Status: "online"},
{ID: "fra", Name: "Frankfurt", City: "Frankfurt", Country: "Germany", Lat: 50.1109, Lon: 8.6821, Nodes: 22, Gpus: 88, Status: "online"},
{ID: "lon", Name: "London", City: "London", Country: "UK", Lat: 51.5074, Lon: -0.1278, Nodes: 18, Gpus: 64, Status: "online"},
{ID: "sgp", Name: "Singapore", City: "Singapore", Country: "Singapore", Lat: 1.3521, Lon: 103.8198, Nodes: 16, Gpus: 60, Status: "online"},
{ID: "blr", Name: "Bangalore", City: "Bangalore", Country: "India", Lat: 12.9716, Lon: 77.5946, Nodes: 12, Gpus: 40, Status: "degraded"},
{ID: "syd", Name: "Sydney", City: "Sydney", Country: "Australia", Lat: -33.8688, Lon: 151.2093, Nodes: 8, Gpus: 24, Status: "online"},
}
}
+94 -12
View File
@@ -33,6 +33,8 @@ type fleetMachineRow struct {
GPUModel string `json:"gpuModel"`
GPUs int `json:"gpus"`
VRAM string `json:"vram"` // BYO GPUs report VRAM total; "" when unknown
VCPU int `json:"vcpu"` // vCPU count (visor MachineView.vcpu); 0 when unknown
Mem string `json:"mem"` // system RAM, e.g. "8 GB"; "" when unknown
OS string `json:"os"`
}
@@ -60,6 +62,13 @@ type fleetWorker struct {
VRAM string `json:"vram"`
Capabilities []string `json:"capabilities"`
Version string `json:"version"`
// Serving is the model ids this worker's hanzo-engine advertises (engine.serve),
// EngineStatus its reachability, JobQueue the gpu-jobs queue it claims from —
// the "what this GPU is serving" the fleet view surfaces. Empty when the worker
// runs only the studio.render job loop and no model server.
Serving []string `json:"serving"`
EngineStatus string `json:"engineStatus"`
JobQueue string `json:"jobQueue"`
}
type cloudFleet struct {
@@ -95,11 +104,12 @@ func (s *Server) handleCloudFleet(w http.ResponseWriter, r *http.Request) {
var machines struct {
Machines []struct {
ID, Name, Region, Type, Status, Provider, GPU, OS string
ID, Name, Region, Type, Status, Provider, GPU, OS, Mem string
Vcpu int `json:"vcpu"`
} `json:"machines"`
}
if err := s.getJSON(ctx, base+"/v1/machines", hdr, &machines); err != nil {
writeJSON(w, http.StatusOK, "", cloudFleet{Available: false, UpdatedAt: nowRFC(), Note: "Fleet inventory (visor) is unavailable right now."})
writeJSON(w, http.StatusOK, "private, no-store", cloudFleet{Available: false, UpdatedAt: nowRFC(), Note: "Fleet inventory (visor) is unavailable right now."})
return
}
var gpus struct {
@@ -111,8 +121,14 @@ func (s *Server) handleCloudFleet(w http.ResponseWriter, r *http.Request) {
var workers struct {
Workers []struct {
ID, Hostname, Provider, Location, Status, Version string
JobQueue string `json:"jobQueue"`
GPUs []struct{ Name, MemoryTotal string } `json:"gpus"`
Capabilities []string `json:"capabilities"`
Engine *struct {
URL string `json:"url"`
Models []string `json:"models"`
Status string `json:"status"`
} `json:"engine"`
} `json:"workers"`
}
_ = s.getJSON(ctx, base+"/v1/fleet/workers", hdr, &workers)
@@ -156,7 +172,7 @@ func (s *Server) handleCloudFleet(w http.ResponseWriter, r *http.Request) {
regIdx[prov][region] = rg
}
ga := byMachine[m.ID]
row := fleetMachineRow{ID: m.ID, Name: orDash(m.Name), Type: m.Type, Status: m.Status, GPUModel: m.GPU, OS: m.OS}
row := fleetMachineRow{ID: m.ID, Name: orDash(m.Name), Type: m.Type, Status: m.Status, GPUModel: m.GPU, VCPU: m.Vcpu, Mem: m.Mem, OS: m.OS}
if ga != nil {
row.GPUs = ga.count
row.VRAM = ga.vram
@@ -186,19 +202,23 @@ func (s *Server) handleCloudFleet(w http.ResponseWriter, r *http.Request) {
f.Totals.Regions = len(regionSet)
for _, wk := range workers.Workers {
fw := fleetWorker{ID: wk.ID, Hostname: wk.Hostname, Provider: wk.Provider, Location: wk.Location, Status: wk.Status, Version: wk.Version, Capabilities: wk.Capabilities}
fw := fleetWorker{ID: wk.ID, Hostname: wk.Hostname, Provider: wk.Provider, Location: wk.Location, Status: wk.Status, Version: wk.Version, Capabilities: wk.Capabilities, JobQueue: wk.JobQueue}
if len(wk.GPUs) > 0 {
fw.GPU = wk.GPUs[0].Name
if isRealVRAM(wk.GPUs[0].MemoryTotal) {
fw.VRAM = wk.GPUs[0].MemoryTotal
}
}
if wk.Engine != nil {
fw.Serving = wk.Engine.Models
fw.EngineStatus = wk.Engine.Status
}
f.Workers = append(f.Workers, fw)
}
f.Note = "Live fleet from visor (DO / GCP / AWS / BYO), grouped by provider and region."
f.UtilNote = "Live GPU utilization, memory-used and temperature are not yet instrumented in the fleet data plane — only inventory, status and (BYO) VRAM total are reported."
writeJSON(w, http.StatusOK, "", f)
writeJSON(w, http.StatusOK, "private, no-store", f)
}
func isRealVRAM(s string) bool {
@@ -279,7 +299,53 @@ func (s *Server) handleCloudServices(w http.ResponseWriter, r *http.Request) {
}
}
out.Note = "Per-subsystem health from o11y (live probe) fused with RED metrics over the last hour."
writeJSON(w, http.StatusOK, "", out)
writeJSON(w, http.StatusOK, "private, no-store", out)
}
// livenessURL maps a cloud subsystem to a real reachability endpoint, used to
// decide `up` when o11y carries no per-deployment telemetry for it. Each path is
// GET-able and answers (2xx/3xx or an auth gate) whenever the subsystem is live;
// an empty string means "no liveness probe" (leave up as whatever o11y said).
func livenessURL(name string) string {
api := apiHost()
switch name {
case "ai":
return api + "/v1/models"
case "gateway":
return api + "/health"
case "iam":
return api + "/v1/iam/.well-known/openid-configuration"
case "kms":
return api + "/v1/kms/health"
case "s3":
return api + "/v1/s3"
case "analytics":
return api + "/v1/analytics/overview"
case "o11y":
return api + "/v1/o11y"
case "commerce":
return api + "/v1/plans"
case "billing":
return api + "/v1/billing/balance"
case "tasks":
return api + "/v1/tasks"
case "websearch":
return api + "/v1/search"
case "docdb":
return api + "/v1/docdb"
case "sql":
return api + "/v1/sql"
case "paas":
return api + "/v1/platform/health"
case "visor":
return api + "/v1/machines"
case "world":
return "https://world.hanzo.ai/v1/world/health"
case "registry":
return "https://registry.hanzo.ai/v2/"
default:
return ""
}
}
func (s *Server) probeService(ctx context.Context, base, name string, hdr map[string]string) serviceRow {
@@ -294,7 +360,10 @@ func (s *Server) probeService(ctx context.Context, base, name string, hdr map[st
Up bool `json:"up"`
} `json:"deployments"`
}
if err := s.getJSON(ctx, base+"/v1/o11y/status?product="+name, hdr, &st); err == nil {
o11yKnows := false
if err := s.getJSON(ctx, base+"/v1/o11y/status?product="+name, hdr, &st); err == nil && len(st.Deployments) > 0 {
// o11y has real per-deployment telemetry for this subsystem — trust it.
o11yKnows = true
row.Up = st.Up
row.LatencyMs = st.LatencyMs
row.Source = st.Source
@@ -305,6 +374,19 @@ func (s *Server) probeService(ctx context.Context, base, name string, hdr map[st
}
}
}
// Liveness is authoritative when o11y has no opinion. A subsystem that simply
// isn't wired into o11y is NOT down — probing its real endpoint keeps the board
// honest (a live-but-uninstrumented service shows UP with no metrics, never a
// false "down"). Any answer through the gateway (2xx/3xx, or an auth gate) means
// the service is alive; only a transport error or a 5xx is truly down.
if !o11yKnows {
if u := livenessURL(name); u != "" {
if _, code, err := s.get(ctx, u, hdr); err == nil {
row.Up = code > 0 && code < 500
row.Source = "liveness"
}
}
}
var mt struct {
Summary struct {
Requests int64 `json:"requests"`
@@ -384,7 +466,7 @@ func (s *Server) handleCloudAnalytics(w http.ResponseWriter, r *http.Request) {
} `json:"data"`
}
if err := s.getJSON(ctx, base+"/v1/analytics/websites", hdr, &sites); err != nil || len(sites.Data) == 0 {
writeJSON(w, http.StatusOK, "", cloudAnalytics{Available: false, UpdatedAt: nowRFC(), Window: "24h",
writeJSON(w, http.StatusOK, "private, no-store", cloudAnalytics{Available: false, UpdatedAt: nowRFC(), Window: "24h",
Note: "Web analytics (analytics.hanzo.ai) has no websites registered or is unreachable."})
return
}
@@ -447,7 +529,7 @@ func (s *Server) handleCloudAnalytics(w http.ResponseWriter, r *http.Request) {
out.TopReferrers = topMetrics(refs, 8)
out.TopCountries = topMetrics(countries, 8)
out.Note = "Live web analytics across all registered Hanzo sites (analytics.hanzo.ai), last 24h."
writeJSON(w, http.StatusOK, "", out)
writeJSON(w, http.StatusOK, "private, no-store", out)
}
func mergeMetric(ctx context.Context, s *Server, base, id, typ, q string, hdr map[string]string, into map[string]int64, mu *sync.Mutex) {
@@ -501,7 +583,7 @@ func (s *Server) handleCloudLLM(w http.ResponseWriter, r *http.Request) {
body, status, err := s.get(ctx, apiHost()+"/v1/admin/o11y?range="+rng, map[string]string{"Authorization": bearer})
if err != nil || status < 200 || status >= 300 {
writeJSON(w, http.StatusOK, "", map[string]any{
writeJSON(w, http.StatusOK, "private, no-store", map[string]any{
"available": false, "updatedAt": nowRFC(), "range": rng,
"note": "Platform LLM observability requires a cloud global-admin token; not available for this session.",
})
@@ -509,10 +591,10 @@ func (s *Server) handleCloudLLM(w http.ResponseWriter, r *http.Request) {
}
var payload map[string]any
if err := json.Unmarshal(body, &payload); err != nil {
writeJSON(w, http.StatusOK, "", map[string]any{"available": false, "range": rng, "note": "LLM observability response was unreadable."})
writeJSON(w, http.StatusOK, "private, no-store", map[string]any{"available": false, "range": rng, "note": "LLM observability response was unreadable."})
return
}
writeJSON(w, http.StatusOK, "", map[string]any{"available": true, "updatedAt": nowRFC(), "range": rng, "data": payload})
writeJSON(w, http.StatusOK, "private, no-store", map[string]any{"available": true, "updatedAt": nowRFC(), "range": rng, "data": payload})
}
// ── small shared helpers ─────────────────────────────────────────────────────
@@ -0,0 +1,432 @@
package world
import (
"context"
"encoding/json"
"net/http"
"sort"
"strings"
"sync"
"time"
)
// Admin-only Cloud infrastructure aggregates — the SuperAdmin fleet view's two
// panels that the fleet + services handlers (handlers_cloud_admin.go) did not yet
// cover: DOKS cluster NODES grouped by cluster, and the GPU JOB QUEUE (what is
// running, from which service). Both are gated by requireAdmin (fail-closed 403)
// and forward the caller's own IAM bearer to the cloud subsystems on api.hanzo.ai,
// which independently re-verify. Each degrades honestly to {available:false} on any
// upstream failure — never a 5xx or an invented number.
// ── clusters: DOKS cluster nodes grouped by cluster ──────────────────────────
//
// Real source: the unified k8s noun on api.hanzo.ai — /v1/k8s/clusters (the org's
// managed DOKS + BYO clusters) then, per cluster, /v1/k8s/clusters/{id} (node pools
// + worker nodes as machines). The fleet handler groups the SAME nodes by
// provider/region; this handler keeps them under their CLUSTER (hanzo-k8s, …) with
// per-cluster status and capacity, which the provider view flattens away.
type clusterNode struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Type string `json:"type"`
Region string `json:"region"`
GPU string `json:"gpu"`
}
type clusterPool struct {
Name string `json:"name"`
Size string `json:"size"`
Count int `json:"count"`
AutoScale bool `json:"autoScale"`
MinNodes int `json:"minNodes"`
MaxNodes int `json:"maxNodes"`
}
type clusterGroup struct {
ID string `json:"id"`
Name string `json:"name"`
Region string `json:"region"`
Status string `json:"status"`
Kind string `json:"kind"` // managed (DOKS) | byo (attached kubeconfig)
Nodes int `json:"nodes"`
NodesReady int `json:"nodesReady"`
GPUs int `json:"gpus"`
Pools []clusterPool `json:"pools"`
NodeList []clusterNode `json:"nodeList"`
}
type clustersTotals struct {
Clusters int `json:"clusters"`
Nodes int `json:"nodes"`
NodesReady int `json:"nodesReady"`
GPUs int `json:"gpus"`
}
type cloudClusters struct {
Available bool `json:"available"`
UpdatedAt string `json:"updatedAt"`
Note string `json:"note"`
Totals clustersTotals `json:"totals"`
Clusters []clusterGroup `json:"clusters"`
}
// wireCluster mirrors cloud's clusterView (clients/visor/types.go): the list row.
type wireCluster struct {
DoksClusterID string `json:"doksClusterId"`
DoClusterID string `json:"doClusterId"`
Name string `json:"name"`
Region string `json:"region"`
Status string `json:"status"`
Kind string `json:"kind"`
NodeCount int `json:"nodeCount"`
NvidiaGPU int `json:"nvidiaGpu"`
AmdGPU int `json:"amdGpu"`
NodePools []struct {
Name string `json:"name"`
Size string `json:"size"`
Count int `json:"count"`
MinNodes int `json:"minNodes"`
MaxNodes int `json:"maxNodes"`
AutoScale bool `json:"autoScale"`
} `json:"nodePools"`
}
// wireClusterDetail mirrors cloud's clusterDetailView: the list row + worker nodes.
type wireClusterDetail struct {
wireCluster
Nodes []struct {
ID string `json:"id"`
Name string `json:"name"`
Region string `json:"region"`
Type string `json:"type"`
Status string `json:"status"`
GPU string `json:"gpu"`
} `json:"nodes"`
}
func (s *Server) handleCloudClusters(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
bearer, ok := s.requireAdmin(w, r)
if !ok {
return
}
ctx, cancel := context.WithTimeout(r.Context(), 22*time.Second)
defer cancel()
hdr := map[string]string{"Authorization": bearer}
base := apiHost()
var list struct {
Clusters []wireCluster `json:"clusters"`
}
if err := s.getJSON(ctx, base+"/v1/k8s/clusters", hdr, &list); err != nil {
writeJSON(w, http.StatusOK, "private, no-store", cloudClusters{Available: false, UpdatedAt: nowRFC(),
Note: "Kubernetes cluster inventory (visor) is unavailable right now."})
return
}
out := cloudClusters{Available: true, UpdatedAt: nowRFC()}
groups := make([]clusterGroup, len(list.Clusters))
var wg sync.WaitGroup
sem := make(chan struct{}, 6)
for i, kc := range list.Clusters {
wg.Add(1)
go func(i int, kc wireCluster) {
defer wg.Done()
sem <- struct{}{}
defer func() { <-sem }()
groups[i] = s.clusterGroup(ctx, base, hdr, kc)
}(i, kc)
}
wg.Wait()
for _, g := range groups {
out.Clusters = append(out.Clusters, g)
out.Totals.Clusters++
out.Totals.Nodes += g.Nodes
out.Totals.NodesReady += g.NodesReady
out.Totals.GPUs += g.GPUs
}
sort.Slice(out.Clusters, func(i, j int) bool {
if out.Clusters[i].Nodes == out.Clusters[j].Nodes {
return out.Clusters[i].Name < out.Clusters[j].Name
}
return out.Clusters[i].Nodes > out.Clusters[j].Nodes
})
out.Note = "Live DOKS + BYO clusters from visor, grouped by cluster with node pools and worker-node status."
writeJSON(w, http.StatusOK, "private, no-store", out)
}
// clusterGroup resolves one cluster to its group view. It fetches the cluster
// detail for node pools + worker nodes; a detail failure degrades to the list
// row's counts (never fabricated) so a single unreachable cluster never sinks the
// board.
func (s *Server) clusterGroup(ctx context.Context, base string, hdr map[string]string, kc wireCluster) clusterGroup {
g := clusterGroup{
ID: firstNonBlank(kc.DoksClusterID, kc.DoClusterID),
Name: orDash(kc.Name),
Region: kc.Region,
Status: orDash(kc.Status),
Kind: orDash(kc.Kind),
Nodes: kc.NodeCount,
GPUs: kc.NvidiaGPU + kc.AmdGPU,
}
for _, p := range kc.NodePools {
g.Pools = append(g.Pools, clusterPool{Name: p.Name, Size: p.Size, Count: p.Count,
AutoScale: p.AutoScale, MinNodes: p.MinNodes, MaxNodes: p.MaxNodes})
}
if g.ID == "" {
return g
}
var d wireClusterDetail
if err := s.getJSON(ctx, base+"/v1/k8s/clusters/"+g.ID, hdr, &d); err != nil {
return g
}
if len(d.NodePools) > 0 { // detail carries the authoritative pool set
g.Pools = g.Pools[:0]
for _, p := range d.NodePools {
g.Pools = append(g.Pools, clusterPool{Name: p.Name, Size: p.Size, Count: p.Count,
AutoScale: p.AutoScale, MinNodes: p.MinNodes, MaxNodes: p.MaxNodes})
}
}
if len(d.Nodes) > 0 {
g.Nodes = len(d.Nodes)
g.NodesReady = 0
for _, n := range d.Nodes {
g.NodeList = append(g.NodeList, clusterNode{ID: n.ID, Name: orDash(n.Name),
Status: n.Status, Type: n.Type, Region: n.Region, GPU: n.GPU})
if machineOnline(n.Status) {
g.NodesReady++
}
}
} else if g.Nodes > 0 {
g.NodesReady = g.Nodes // list row reports a count but no per-node status
}
return g
}
// ── queue: GPU job queue (gpu-jobs) — depth + what's running, from which service ─
//
// Real source: the tasks engine on api.hanzo.ai — GET
// /v1/tasks/namespaces/gpu-jobs/activities (the org's GPU work queue the
// `hanzo gpu connect` workers claim from) fused with /v1/fleet/workers (the online
// worker count). Job types are namespaced by service ("studio.render",
// "engine.serve"), so the dispatching service is the type's prefix. The queue is
// the caller's platform org — a SuperAdmin's bearer resolves to the admin org
// upstream, which owns the house-account + operator fleet.
const gpuJobsNamespace = "gpu-jobs"
type queueJob struct {
ID string `json:"id"`
Type string `json:"type"`
Service string `json:"service"`
Status string `json:"status"` // pending | running | done | failed | canceled
Worker string `json:"worker"`
Model string `json:"model"`
Attempt int `json:"attempt"`
StartedAt string `json:"startedAt"`
ClosedAt string `json:"closedAt"`
}
type queueService struct {
Service string `json:"service"`
Pending int `json:"pending"`
Running int `json:"running"`
}
type queueDepth struct {
Pending int `json:"pending"`
Running int `json:"running"`
Done int `json:"done"`
Failed int `json:"failed"`
Canceled int `json:"canceled"`
}
type cloudQueue struct {
Available bool `json:"available"`
UpdatedAt string `json:"updatedAt"`
Note string `json:"note"`
Namespace string `json:"namespace"`
Depth queueDepth `json:"depth"`
Workers struct {
Online int `json:"online"`
Total int `json:"total"`
} `json:"workers"`
Services []queueService `json:"services"`
Running []queueJob `json:"running"`
Pending []queueJob `json:"pending"`
Recent []queueJob `json:"recent"`
}
// wireActivity is the subset of the tasks engine's StandaloneActivity the queue
// view needs (pkg/tasks/types.go).
type wireActivity struct {
Execution struct {
WorkflowID string `json:"workflowId"`
} `json:"execution"`
Type struct {
Name string `json:"name"`
} `json:"type"`
Status string `json:"status"` // ACTIVITY_TASK_STATE_*
StartTime string `json:"startTime"`
CloseTime string `json:"closeTime"`
Identity string `json:"identity"`
Attempt int `json:"attempt"`
Input json.RawMessage `json:"input"`
}
func (s *Server) handleCloudQueue(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
bearer, ok := s.requireAdmin(w, r)
if !ok {
return
}
ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second)
defer cancel()
hdr := map[string]string{"Authorization": bearer}
base := apiHost()
var acts struct {
Activities []wireActivity `json:"activities"`
}
if err := s.getJSON(ctx, base+"/v1/tasks/namespaces/"+gpuJobsNamespace+"/activities", hdr, &acts); err != nil {
writeJSON(w, http.StatusOK, "private, no-store", cloudQueue{Available: false, UpdatedAt: nowRFC(), Namespace: gpuJobsNamespace,
Note: "GPU job queue (tasks) is unavailable right now."})
return
}
out := cloudQueue{Available: true, UpdatedAt: nowRFC(), Namespace: gpuJobsNamespace}
svc := map[string]*queueService{}
var svcOrder []string
for _, a := range acts.Activities {
job := queueJob{
ID: a.Execution.WorkflowID,
Type: orDash(a.Type.Name),
Service: jobService(a.Type.Name),
Worker: a.Identity,
Model: jobModel(a.Input),
Attempt: a.Attempt,
StartedAt: a.StartTime,
ClosedAt: a.CloseTime,
}
switch a.Status {
case "ACTIVITY_TASK_STATE_SCHEDULED":
job.Status = "pending"
out.Depth.Pending++
out.Pending = append(out.Pending, job)
serviceBucket(svc, &svcOrder, job.Service).Pending++
case "ACTIVITY_TASK_STATE_STARTED":
job.Status = "running"
out.Depth.Running++
out.Running = append(out.Running, job)
serviceBucket(svc, &svcOrder, job.Service).Running++
case "ACTIVITY_TASK_STATE_COMPLETED":
job.Status = "done"
out.Depth.Done++
out.Recent = append(out.Recent, job)
case "ACTIVITY_TASK_STATE_FAILED":
job.Status = "failed"
out.Depth.Failed++
out.Recent = append(out.Recent, job)
case "ACTIVITY_TASK_STATE_CANCELED":
job.Status = "canceled"
out.Depth.Canceled++
out.Recent = append(out.Recent, job)
}
}
// Online worker count — the same BYO fleet the fleet panel lists. A read failure
// here leaves the worker count at zero; it never sinks the queue.
var workers struct {
Workers []struct {
Status string `json:"status"`
} `json:"workers"`
}
if err := s.getJSON(ctx, base+"/v1/fleet/workers", hdr, &workers); err == nil {
out.Workers.Total = len(workers.Workers)
for _, wk := range workers.Workers {
if wk.Status == "online" {
out.Workers.Online++
}
}
}
for _, name := range svcOrder {
out.Services = append(out.Services, *svc[name])
}
sort.Slice(out.Services, func(i, j int) bool {
a, b := out.Services[i], out.Services[j]
if a.Running+a.Pending == b.Running+b.Pending {
return a.Service < b.Service
}
return a.Running+a.Pending > b.Running+b.Pending
})
// Newest terminal first; keep the tail bounded so the panel stays a snapshot.
sort.Slice(out.Recent, func(i, j int) bool { return out.Recent[i].ClosedAt > out.Recent[j].ClosedAt })
if len(out.Recent) > 12 {
out.Recent = out.Recent[:12]
}
out.Note = "Live GPU job queue (gpu-jobs) — pending + running work by service, and what each worker is serving."
writeJSON(w, http.StatusOK, "private, no-store", out)
}
// jobService is the dispatching service of a job type: the segment before the
// first "." ("studio.render" → "studio", "engine.serve" → "engine"). A type with
// no dot is its own service; an empty type is "—".
func jobService(typ string) string {
typ = strings.TrimSpace(typ)
if typ == "" {
return "—"
}
if i := strings.IndexByte(typ, '.'); i > 0 {
return typ[:i]
}
return typ
}
// jobModel best-effort reads the target model from a job's input ("model", else a
// nested "input.model"). An absent field yields "" — never a guess.
func jobModel(raw json.RawMessage) string {
if len(raw) == 0 {
return ""
}
var m map[string]any
if err := json.Unmarshal(raw, &m); err != nil {
return ""
}
if v, ok := m["model"].(string); ok && v != "" {
return v
}
if inner, ok := m["input"].(map[string]any); ok {
if v, ok := inner["model"].(string); ok {
return v
}
}
return ""
}
func serviceBucket(m map[string]*queueService, order *[]string, name string) *queueService {
if b := m[name]; b != nil {
return b
}
b := &queueService{Service: name}
m[name] = b
*order = append(*order, name)
return b
}
func firstNonBlank(vals ...string) string {
for _, v := range vals {
if strings.TrimSpace(v) != "" {
return v
}
}
return ""
}
@@ -0,0 +1,196 @@
package world
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
// The SuperAdmin fleet view's two infrastructure aggregates — DOKS cluster nodes
// and the GPU job queue — must (1) fail-closed for a non-admin and (2) reshape the
// REAL upstream shapes (k8s clusters/detail + tasks activities) for an admin, never
// fabricating a number. These tests mock IAM userinfo (the admin gate) and the
// api.hanzo.ai subsystems (the data plane) so they run hermetically.
// adminUpstream is a mock api.hanzo.ai serving the exact routes the clusters +
// queue handlers fan out to, with real-shaped payloads.
func adminUpstream(t *testing.T) *httptest.Server {
t.Helper()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.URL.Path {
case "/v1/k8s/clusters":
_, _ = w.Write([]byte(`{"clusters":[
{"doksClusterId":"c-hanzo","name":"hanzo-k8s","region":"sfo3","status":"running","kind":"managed","nodeCount":3,"nvidiaGpu":2},
{"doksClusterId":"c-adnexus","name":"adnexus-k8s","region":"sfo3","status":"running","kind":"managed","nodeCount":2}
]}`))
case "/v1/k8s/clusters/c-hanzo":
_, _ = w.Write([]byte(`{"doksClusterId":"c-hanzo","name":"hanzo-k8s","region":"sfo3","status":"running","kind":"managed",
"nodePools":[{"name":"pool-gpu","size":"gpu-l40","count":2,"autoScale":true,"minNodes":1,"maxNodes":4}],
"nodes":[
{"id":"n1","name":"hanzo-k8s-1","status":"active","type":"s-8vcpu-16gb","region":"sfo3"},
{"id":"n2","name":"hanzo-k8s-2","status":"active","type":"gpu-l40","region":"sfo3","gpu":"L40S"},
{"id":"n3","name":"hanzo-k8s-3","status":"provisioning","type":"gpu-l40","region":"sfo3","gpu":"L40S"}
]}`))
case "/v1/k8s/clusters/c-adnexus":
_, _ = w.Write([]byte(`{"doksClusterId":"c-adnexus","name":"adnexus-k8s","region":"sfo3","status":"running","kind":"managed",
"nodes":[
{"id":"a1","name":"adnexus-k8s-1","status":"active","type":"s-4vcpu-8gb","region":"sfo3"},
{"id":"a2","name":"adnexus-k8s-2","status":"active","type":"s-4vcpu-8gb","region":"sfo3"}
]}`))
case "/v1/tasks/namespaces/gpu-jobs/activities":
_, _ = w.Write([]byte(`{"activities":[
{"execution":{"workflowId":"job-1"},"type":{"name":"studio.render"},"status":"ACTIVITY_TASK_STATE_STARTED","identity":"evo","startTime":"2026-07-21T10:00:00Z","input":{"model":"flux.1"}},
{"execution":{"workflowId":"job-2"},"type":{"name":"engine.serve"},"status":"ACTIVITY_TASK_STATE_STARTED","identity":"spark","startTime":"2026-07-21T10:01:00Z","input":{"model":"qwen3-32b"}},
{"execution":{"workflowId":"job-3"},"type":{"name":"studio.render"},"status":"ACTIVITY_TASK_STATE_SCHEDULED","input":{"model":"flux.1"}},
{"execution":{"workflowId":"job-4"},"type":{"name":"echo"},"status":"ACTIVITY_TASK_STATE_COMPLETED","closeTime":"2026-07-21T09:59:00Z"},
{"execution":{"workflowId":"job-5"},"type":{"name":"studio.render"},"status":"ACTIVITY_TASK_STATE_FAILED","closeTime":"2026-07-21T09:58:00Z"}
]}`))
case "/v1/fleet/workers":
_, _ = w.Write([]byte(`{"workers":[
{"id":"evo","hostname":"evo","status":"online"},
{"id":"spark","hostname":"spark","status":"online"},
{"id":"dbc","hostname":"dbc","status":"offline"}
]}`))
default:
w.WriteHeader(http.StatusNotFound)
}
}))
t.Cleanup(srv.Close)
return srv
}
// getInfra drives an admin-gated infra route through a mocked IAM + upstream.
func getInfra(t *testing.T, route string, iamStatus int, iamBody, bearer string) (*http.Response, []byte) {
t.Helper()
iam := iamStub(t, iamStatus, iamBody)
t.Setenv("HANZO_IAM_ISSUER", iam.URL)
t.Setenv("HANZO_API_BASE", adminUpstream(t).URL)
s := NewServer()
mux := http.NewServeMux()
s.Mount(mux)
ts := httptest.NewServer(mux)
t.Cleanup(ts.Close)
req, _ := http.NewRequest(http.MethodGet, ts.URL+route, nil)
if bearer != "" {
req.Header.Set("Authorization", bearer)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("request: %v", err)
}
t.Cleanup(func() { resp.Body.Close() })
var raw json.RawMessage
_ = json.NewDecoder(resp.Body).Decode(&raw)
return resp, raw
}
// TestCloudClustersAdmin: an admin owner receives the real clusters, grouped by
// cluster with node pools + worker-node status, and honest ready/total counts.
func TestCloudClustersAdmin(t *testing.T) {
resp, body := getInfra(t, "/v1/world/cloud/clusters", 200, `{"owner":"admin","sub":"z"}`, "Bearer good")
if resp.StatusCode != http.StatusOK {
t.Fatalf("admin got %d, want 200 (body=%s)", resp.StatusCode, body)
}
if cache := resp.Header.Get("Cache-Control"); cache != "private, no-store" {
t.Fatalf("admin cluster read must be no-store, got %q", cache)
}
var cc cloudClusters
if err := json.Unmarshal(body, &cc); err != nil {
t.Fatalf("decode: %v", err)
}
if !cc.Available {
t.Fatalf("want available")
}
if cc.Totals.Clusters != 2 {
t.Fatalf("want 2 clusters, got %d", cc.Totals.Clusters)
}
// hanzo-k8s sorts first (3 nodes > 2). Detail replaced the count-only row.
h := cc.Clusters[0]
if h.Name != "hanzo-k8s" {
t.Fatalf("want hanzo-k8s first, got %q", h.Name)
}
if h.Nodes != 3 || h.NodesReady != 2 { // n3 is provisioning, not ready
t.Fatalf("hanzo-k8s nodes=%d ready=%d, want 3/2", h.Nodes, h.NodesReady)
}
if len(h.Pools) != 1 || h.Pools[0].Size != "gpu-l40" || !h.Pools[0].AutoScale {
t.Fatalf("hanzo-k8s pools not surfaced: %+v", h.Pools)
}
if h.GPUs != 2 {
t.Fatalf("hanzo-k8s GPUs=%d, want 2", h.GPUs)
}
if cc.Totals.Nodes != 5 || cc.Totals.NodesReady != 4 {
t.Fatalf("totals nodes=%d ready=%d, want 5/4", cc.Totals.Nodes, cc.Totals.NodesReady)
}
}
// TestCloudQueueAdmin: an admin owner receives the real gpu-jobs queue — depth by
// status, running/pending jobs with worker + model + dispatching service, and the
// online BYO worker count.
func TestCloudQueueAdmin(t *testing.T) {
resp, body := getInfra(t, "/v1/world/cloud/queue", 200, `{"owner":"admin","sub":"z"}`, "Bearer good")
if resp.StatusCode != http.StatusOK {
t.Fatalf("admin got %d, want 200 (body=%s)", resp.StatusCode, body)
}
if cache := resp.Header.Get("Cache-Control"); cache != "private, no-store" {
t.Fatalf("admin queue read must be no-store, got %q", cache)
}
var q cloudQueue
if err := json.Unmarshal(body, &q); err != nil {
t.Fatalf("decode: %v", err)
}
if !q.Available || q.Namespace != "gpu-jobs" {
t.Fatalf("want available gpu-jobs, got %+v", q)
}
if q.Depth.Running != 2 || q.Depth.Pending != 1 || q.Depth.Done != 1 || q.Depth.Failed != 1 {
t.Fatalf("depth wrong: %+v", q.Depth)
}
if q.Workers.Online != 2 || q.Workers.Total != 3 {
t.Fatalf("workers online=%d total=%d, want 2/3", q.Workers.Online, q.Workers.Total)
}
// The dispatching service is the job type's prefix; studio has the render + one
// pending, engine has the serve.
svc := map[string]queueService{}
for _, s := range q.Services {
svc[s.Service] = s
}
if svc["studio"].Running != 1 || svc["studio"].Pending != 1 {
t.Fatalf("studio service wrong: %+v", svc["studio"])
}
if svc["engine"].Running != 1 {
t.Fatalf("engine service wrong: %+v", svc["engine"])
}
// Running jobs carry the claiming worker + the target model.
var served string
for _, j := range q.Running {
if j.Worker == "spark" {
served = j.Model
}
}
if served != "qwen3-32b" {
t.Fatalf("want spark serving qwen3-32b, got %q", served)
}
}
// TestCloudInfraGate: both routes fail-closed for a non-admin owner (403) and
// anonymous (401), leaking no payload.
func TestCloudInfraGate(t *testing.T) {
for _, route := range []string{"/v1/world/cloud/clusters", "/v1/world/cloud/queue"} {
resp, body := getInfra(t, route, 200, `{"owner":"acme","sub":"u1"}`, "Bearer good")
if resp.StatusCode != http.StatusForbidden {
t.Fatalf("%s non-admin got %d, want 403", route, resp.StatusCode)
}
var probe map[string]any
if json.Unmarshal(body, &probe) == nil {
if _, leaked := probe["clusters"]; leaked {
t.Fatalf("%s leaked clusters to non-admin", route)
}
if _, leaked := probe["depth"]; leaked {
t.Fatalf("%s leaked queue depth to non-admin", route)
}
}
}
}
+43 -1
View File
@@ -1,6 +1,7 @@
package world
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
@@ -25,6 +26,8 @@ func TestCloudAdminGateFailsClosed(t *testing.T) {
"/v1/world/cloud/services",
"/v1/world/cloud/analytics",
"/v1/world/cloud/llm",
"/v1/world/cloud/clusters",
"/v1/world/cloud/queue",
}
for _, route := range adminRoutes {
t.Run(route, func(t *testing.T) {
@@ -47,7 +50,7 @@ func TestCloudAdminGateFailsClosed(t *testing.T) {
t.Fatalf("expected an error field, got %v", body)
}
// The aggregate payload keys must NOT be present in a gated response.
for _, leak := range []string{"providers", "services", "topPages", "data", "workers"} {
for _, leak := range []string{"providers", "services", "topPages", "data", "workers", "clusters", "depth", "running"} {
if _, ok := body[leak]; ok {
t.Fatalf("gated response leaked %q: %v", leak, body)
}
@@ -55,3 +58,42 @@ func TestCloudAdminGateFailsClosed(t *testing.T) {
})
}
}
// TestProbeServiceLivenessFallback proves a subsystem that o11y has no telemetry
// for is reported UP (from a real liveness probe) rather than a false "down", and
// stays uninstrumented. A subsystem o11y DOES know about keeps o11y's verdict.
func TestProbeServiceLivenessFallback(t *testing.T) {
// Upstream: o11y status/metrics 404 (no telemetry); a liveness path answers 200.
live := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/v1/o11y/") {
http.Error(w, "no data", http.StatusNotFound)
return
}
w.WriteHeader(http.StatusOK) // liveness endpoint is alive
}))
t.Cleanup(live.Close)
t.Setenv("HANZO_API_BASE", live.URL) // apiHost() reads this
s := newTestServer(t)
row := s.probeService(context.Background(), live.URL, "kms", map[string]string{})
if !row.Up {
t.Fatalf("live-but-uninstrumented subsystem must be UP via liveness, got down (%+v)", row)
}
if row.Instrumented {
t.Fatalf("no o11y metrics ⇒ Instrumented must stay false, got true")
}
if row.Source != "liveness" {
t.Fatalf("Source should mark the liveness fallback, got %q", row.Source)
}
}
// TestLivenessURLCoversSubsystems proves every hardcoded cloudSubsystem has a
// liveness probe URL, so none can silently fall through to a false "down".
func TestLivenessURLCoversSubsystems(t *testing.T) {
t.Setenv("HANZO_API_BASE", "https://api.hanzo.ai")
for _, name := range cloudSubsystems {
if livenessURL(name) == "" {
t.Errorf("subsystem %q has no liveness URL — it can render a false 'down'", name)
}
}
}
+36 -77
View File
@@ -95,7 +95,7 @@ type jsonRPCReq struct {
//
// nodes[] positions are MODELED: real per-node IP geolocation needs an IP-geo
// dependency we don't carry, so the real peer COUNT is spread deterministically
// across the demoRegions() catalog coords. positionsModeled:true says so plainly.
// across the regionCatalog() catalog coords. positionsModeled:true says so plainly.
const maxModeledNodes = 250
@@ -361,7 +361,7 @@ func (s *Server) getAllowedJSON(ctx context.Context, rawURL string, allowed map[
// and kind are modeled — hence positionsModeled:true on the envelope; only the count
// is real. Bounded to maxModeledNodes so a pathological peer count can't bloat the payload.
func modeledNodes(peers int) []chainNode {
regions := demoRegions()
regions := regionCatalog()
nodes := make([]chainNode, 0)
if peers <= 0 || len(regions) == 0 {
return nodes
@@ -431,29 +431,44 @@ func (s *Server) handleCloudBYOGPU(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
w.Header().Set("Vary", "Authorization")
// Signed-in admin (z@hanzo.ai / the operator org): the REAL GPU fleet placed on
// the globe, read with the caller's OWN bearer, never edge-cached. No fabricated
// demo clusters for a signed-in operator — an empty read shows an empty globe.
if bearer, ok := s.adminIdentity(r); ok {
ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second)
defer cancel()
clusters, _ := s.tryRealGPUs(ctx, map[string]string{"Authorization": bearer})
if clusters == nil {
clusters = []gpuCluster{}
}
writeJSON(w, http.StatusOK, "private, no-store", byoGPU{UpdatedAt: nowRFC(), Demo: false, GPUs: clusters})
return
}
s.cachedJSON(w, "cloud-byo-gpu", "public, max-age=30, s-maxage=30, stale-while-revalidate=120",
30*time.Second, 5*time.Minute,
func(ctx context.Context) (any, error) {
if clusters, ok := s.tryRealGPUs(ctx); ok {
if clusters, ok := s.tryRealGPUs(ctx, serviceAuth()); ok {
return byoGPU{UpdatedAt: nowRFC(), Demo: false, GPUs: clusters}, nil
}
return byoGPU{UpdatedAt: nowRFC(), Demo: true, GPUs: demoGPUs()}, nil
// No service token → honest empty (no fabricated clusters). Real GPUs show
// for a signed-in admin (above) or when the service token is wired.
return byoGPU{UpdatedAt: nowRFC(), Demo: false, GPUs: []gpuCluster{}}, nil
},
func(w http.ResponseWriter, _ error) {
writeJSON(w, http.StatusOK, "", byoGPU{UpdatedAt: nowRFC(), Demo: true, GPUs: demoGPUs()})
writeJSON(w, http.StatusOK, "", byoGPU{UpdatedAt: nowRFC(), Demo: false, GPUs: []gpuCluster{}})
},
)
}
// tryRealGPUs reads the real GPU inventory when a service token is configured.
// Returns ok=false (→ demo) when the token is absent, both sources fail, or no GPU
// maps to a known region. Only non-sensitive fields (region/model/status) are read.
func (s *Server) tryRealGPUs(ctx context.Context) ([]gpuCluster, bool) {
tok := serviceToken()
if tok == "" {
// tryRealGPUs reads the real GPU inventory using the supplied auth header (the KMS
// service bearer on the public path, or the caller's own admin bearer). Returns
// ok=false when auth is absent, both sources fail, or no GPU maps to a known region.
// Only non-sensitive fields (region/model/status) are read.
func (s *Server) tryRealGPUs(ctx context.Context, hdr map[string]string) ([]gpuCluster, bool) {
if hdr == nil {
return nil, false
}
hdr := map[string]string{"Authorization": "Bearer " + tok}
base := apiHost()
agg := map[string]*gpuCluster{}
@@ -523,35 +538,6 @@ func (s *Server) tryRealGPUs(ctx context.Context) ([]gpuCluster, bool) {
return out, true
}
// demoGPUs is the flagged illustrative fleet, placed from the region catalog. It
// carries no live-looking precision — it exists to make the globe legible until a
// service token is wired.
func demoGPUs() []gpuCluster {
coords := regionCoords()
rows := []struct {
region, model, status string
count int
}{
{"nyc", "GB10", "online", 4},
{"sfo", "H100", "online", 8},
{"ams", "GB10", "online", 2},
{"fra", "H200", "online", 4},
{"lon", "GB10", "online", 2},
{"sgp", "GB10", "online", 2},
{"blr", "A100", "degraded", 6},
{"syd", "GB10", "online", 1},
}
out := make([]gpuCluster, 0, len(rows))
for _, r := range rows {
rg := coords[r.region]
out = append(out, gpuCluster{
Lat: rg.Lat, Lon: rg.Lon, City: rg.City,
Region: r.region, Model: r.model, Count: r.count, Status: r.status,
})
}
return out
}
// ── 3) traffic: request arcs from visitor countries to the nearest region ────
//
// Real path (service token): read the visitor-COUNTRY breakdown from the same
@@ -585,10 +571,13 @@ func (s *Server) handleCloudTraffic(w http.ResponseWriter, r *http.Request) {
if arcs, ok := s.tryRealTraffic(ctx); ok {
return cloudTraffic{UpdatedAt: nowRFC(), Demo: false, Arcs: arcs}, nil
}
return demoTraffic(), nil
// Honest empty — no fabricated arcs. The native request-geo globe
// (traffic-globe) carries the real traffic layer; arcs fill from real
// visitor geo when analytics is wired.
return cloudTraffic{UpdatedAt: nowRFC(), Demo: false, Arcs: []trafficArc{}}, nil
},
func(w http.ResponseWriter, _ error) {
writeJSON(w, http.StatusOK, "", demoTraffic())
writeJSON(w, http.StatusOK, "", cloudTraffic{UpdatedAt: nowRFC(), Demo: false, Arcs: []trafficArc{}})
},
)
}
@@ -802,29 +791,6 @@ func (s *Server) tryRealTraffic(ctx context.Context) ([]trafficArc, bool) {
return arcs, true
}
// demoTraffic emits flagged arcs from major country centroids to their nearest
// region, weighted by a per-country base × the same diurnal load curve as demoPulse
// so the layer feels alive across refreshes without pretending to be live.
func demoTraffic() cloudTraffic {
now := time.Now().UTC()
load := diurnalLoad(now)
arcs := make([]trafficArc, 0, 16)
for i, c := range countryCentroids {
if i >= 16 { // 1220 arcs; 16 keeps a lively-but-bounded set
break
}
rg := nearestRegion(c.lat, c.lon)
wobble := 1 + 0.06*math.Sin(float64(now.Unix()%600)/600*2*math.Pi+float64(i)*0.7)
arcs = append(arcs, trafficArc{
FromLat: c.lat, FromLon: c.lon, ToLat: rg.Lat, ToLon: rg.Lon,
Weight: round2s(clampF(c.weight*load*wobble, 0.05, 1)),
Label: c.code + " → " + rg.ID,
})
}
sort.SliceStable(arcs, func(i, j int) bool { return arcs[i].Weight > arcs[j].Weight })
return cloudTraffic{UpdatedAt: now.Format(time.RFC3339), Demo: true, Arcs: arcs}
}
// countryCentroids is the small in-file centroid table (ISO 3166-1 alpha-2 → point)
// with a relative traffic base weight, used by both the real and demo traffic paths.
var countryCentroids = []struct {
@@ -869,7 +835,7 @@ func centroidFor(code string) (float64, float64, bool) {
// regionCoords indexes the region catalog by its ID for O(1) coord lookup.
func regionCoords() map[string]cloudRegion {
m := make(map[string]cloudRegion, 8)
for _, rg := range demoRegions() {
for _, rg := range regionCatalog() {
m[rg.ID] = rg
}
return m
@@ -887,7 +853,7 @@ func resolveRegion(region string) (cloudRegion, bool) {
if rg, ok := m[region]; ok {
return rg, true
}
for _, rg := range demoRegions() { // ordered: match the highest-capacity region first
for _, rg := range regionCatalog() { // ordered: match the highest-capacity region first
if strings.HasPrefix(region, rg.ID) {
return rg, true
}
@@ -896,9 +862,9 @@ func resolveRegion(region string) (cloudRegion, bool) {
}
// nearestRegion returns the catalog region closest to (lat, lon) by great-circle
// distance. The catalog is non-empty (demoRegions), so the first is a safe seed.
// distance. The catalog is non-empty (regionCatalog), so the first is a safe seed.
func nearestRegion(lat, lon float64) cloudRegion {
regions := demoRegions()
regions := regionCatalog()
best := regions[0]
bestD := math.Inf(1)
for _, rg := range regions {
@@ -918,10 +884,3 @@ func haversineKm(lat1, lon1, lat2, lon2 float64) float64 {
math.Cos(lat1*rad)*math.Cos(lat2*rad)*math.Sin(dLon/2)*math.Sin(dLon/2)
return 2 * r * math.Asin(math.Min(1, math.Sqrt(a)))
}
// diurnalLoad is the [0.55, 1.0] load factor from demoPulse (peaks ~16:00 UTC),
// reused so the traffic layer's liveliness matches the pulse ticker's.
func diurnalLoad(now time.Time) float64 {
hourFrac := float64(now.Hour()) + float64(now.Minute())/60
return 0.775 + 0.225*math.Sin((hourFrac-10)/24*2*math.Pi)
}
+50
View File
@@ -100,3 +100,53 @@ func TestParseHexInt(t *testing.T) {
}
}
}
// TestBYOGPUAdminReal proves the globe's GPU layer is REAL (not demo) for a
// signed-in admin: the caller's own bearer reads /v1/gpus, clusters carry demo:false
// and the response is no-store (never the shared public/demo cache).
func TestBYOGPUAdminReal(t *testing.T) {
iam := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/iam/oauth/userinfo" || r.Header.Get("Authorization") == "" {
http.NotFound(w, r)
return
}
_, _ = w.Write([]byte(`{"owner":"hanzo","sub":"z@hanzo.ai"}`))
}))
t.Cleanup(iam.Close)
api := http.NewServeMux()
api.HandleFunc("/v1/gpus", func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "Bearer admin-token" {
t.Errorf("GPU inventory must be read with the caller's bearer, got %q", r.Header.Get("Authorization"))
}
_, _ = w.Write([]byte(`{"gpus":[{"model":"GB10","region":"nyc","status":"online"},{"model":"H100","region":"sfo","status":"online"}]}`))
})
up := httptest.NewServer(api)
t.Cleanup(up.Close)
t.Setenv("HANZO_CLOUD_PULSE_TOKEN", "") // no service token — the admin's bearer drives it
t.Setenv("HANZO_API_BASE", up.URL)
t.Setenv("HANZO_IAM_ISSUER", iam.URL)
t.Setenv("WORLD_ADMIN_ORGS", "hanzo") // operator org resolves via deploy env, not code
req, _ := http.NewRequest(http.MethodGet, serveWorld(t)+"/v1/world/cloud/byo-gpu", nil)
req.Header.Set("Authorization", "Bearer admin-token")
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
if cc := resp.Header.Get("Cache-Control"); cc != "private, no-store" {
t.Fatalf("admin GPU layer must be no-store, got %q", cc)
}
var g byoGPU
if err := json.NewDecoder(resp.Body).Decode(&g); err != nil {
t.Fatalf("decode: %v", err)
}
if g.Demo {
t.Fatalf("signed-in admin must get real GPUs, not demo")
}
if len(g.GPUs) != 2 {
t.Fatalf("want 2 real GPU clusters (nyc GB10 + sfo H100), got %d: %+v", len(g.GPUs), g.GPUs)
}
}
+58
View File
@@ -85,3 +85,61 @@ func (s *Server) handleCloudRouterStats(w http.ResponseWriter, r *http.Request)
},
)
}
// routerHistoryUnavailable is the honest empty payload for the flywheel history: no
// series, no retrains — flat/empty charts, never a fabricated curve. Structurally
// valid so the panels bind identically whether live or empty.
var routerHistoryUnavailable = json.RawMessage(`{"scope":"platform","unavailable":true,"window":{"since":"","until":"","days":0},"daily":[],"retrains":[],"totals":{"events":0,"cumulative_cost_saved":0,"reward_rate":0,"days_active":0}}`)
// clampDays parses ?days= and clamps to [1,90] (default 30).
func clampDays(raw string) int {
d, err := strconv.Atoi(raw)
if err != nil || d < 1 {
return 30
}
if d > 90 {
return 90
}
return d
}
// handleCloudRouterHistory proxies the ai gateway's PUBLIC /v1/router/history?scope=
// platform (daily reward-rate + cumulative cost-saved + adoption curve + the retrain
// timeline). Same discipline as router-stats: scope HARD-PINNED to platform, raw
// pass-through of the arm-opaque `data`, honest empty (unavailable:true) on any soft
// failure, never a 5xx. The flywheel is only barely lit today — the series start
// empty and GROW with real data; we never invent history.
func (s *Server) handleCloudRouterHistory(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
days := clampDays(r.URL.Query().Get("days"))
daysStr := strconv.Itoa(days)
s.cachedJSON(w, "router-history:"+daysStr, "public, max-age=60, s-maxage=60, stale-while-revalidate=300",
90*time.Second, 10*time.Minute,
func(ctx context.Context) (any, error) {
url := apiHost() + "/v1/router/history?scope=platform&days=" + daysStr
body, status, err := s.get(ctx, url, nil)
if err != nil {
return nil, err
}
if status < 200 || status >= 300 {
return nil, httpErr(status)
}
var env struct {
Status string `json:"status"`
Data json.RawMessage `json:"data"`
}
if err := json.Unmarshal(body, &env); err != nil {
return nil, httpErr(http.StatusBadGateway)
}
if env.Status != "ok" || len(env.Data) == 0 || string(env.Data) == "null" {
return nil, httpErr(http.StatusBadGateway)
}
return env.Data, nil
},
func(w http.ResponseWriter, _ error) {
writeJSON(w, http.StatusOK, "no-store", routerHistoryUnavailable)
},
)
}
@@ -0,0 +1,212 @@
package world
import (
"context"
"encoding/json"
"net/http"
"time"
)
// Enso Router — org cost↔quality preference + the mean-field judge panel.
//
// Two same-origin proxies for the Enso Router panel, holding the exact discipline
// of handlers_cloud_router.go (public router-stats/history): raw pass-through of
// the upstream shape, honest degrade (never a 5xx, never a fabricated number).
//
// - router-preference GET|PUT → ai gateway GET|POST /v1/router/preference
// ORG-SCOPED: the caller's own IAM bearer is forwarded (userBearer), so the
// gateway derives their org and stores/returns THAT org's routing bias — no
// shared key, exactly like the admin aggregates forward the caller bearer.
// GET yields {bias,default}; PUT writes {bias}. Degrades to a well-formed
// disabled payload {available:false} on ANY upstream failure — including a
// 404 while the gateway route is not yet deployed — so the slider renders a
// read-only "not deployed" state instead of erroring.
//
// - judge-panel GET → ai gateway GET /v1/router/judge-panel?scope=platform
// PUBLIC platform aggregate (like router-stats): the diverse judge panel that
// scores routing quality + its published rank-corr benchmark. scope is
// HARD-PINNED to platform. Honest {available:false} on failure, never faked.
//
// Honesty: the only value shown when the real one can't be read is a neutral 0.5
// ("balanced") bias, and it always rides with available:false so the panel never
// presents it as a saved preference.
// prefResponse is world's normalized preference control: the two 0..1 knobs the ai
// gateway tracks (bias = 0 max-savings … 1 max-quality; default = platform neutral)
// plus an availability flag the panel uses to pick live vs disabled rendering.
type prefResponse struct {
Bias float64 `json:"bias"`
Default float64 `json:"default"`
Available bool `json:"available"`
}
// clamp01 keeps a bias in the valid [0,1] band.
func clamp01(v float64) float64 {
if v < 0 {
return 0
}
if v > 1 {
return 1
}
return v
}
// disabledPref is the honest degraded control: a neutral balanced bias rendered
// read-only (available:false). Never implies a saved value.
func disabledPref() prefResponse { return prefResponse{Bias: 0.5, Default: 0.5, Available: false} }
// upstreamPref parses the gateway's preference body, tolerating either the bare
// {bias,default} shape or the casibase {status,data:{…}} envelope the sibling
// router endpoints use. ok=false when neither yields a bias.
func upstreamPref(body []byte) (prefResponse, bool) {
type shape struct {
Bias *float64 `json:"bias"`
Default *float64 `json:"default"`
}
var env struct {
shape
Data *shape `json:"data"`
}
if json.Unmarshal(body, &env) != nil {
return prefResponse{}, false
}
s := env.shape
if env.Data != nil && env.Data.Bias != nil {
s = *env.Data
}
if s.Bias == nil {
return prefResponse{}, false
}
out := prefResponse{Bias: clamp01(*s.Bias), Default: 0.5, Available: true}
if s.Default != nil {
out.Default = clamp01(*s.Default)
}
return out, true
}
func (s *Server) handleCloudRouterPreference(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, PUT, POST, OPTIONS") {
return
}
switch r.Method {
case http.MethodGet:
s.getRouterPreference(w, r)
case http.MethodPut, http.MethodPost:
s.putRouterPreference(w, r)
default:
writeError(w, http.StatusMethodNotAllowed, "Method not allowed")
}
}
// getRouterPreference reads the caller-org's current bias. Forwards the caller's
// bearer (if any); on any failure returns the honest disabled default.
func (s *Server) getRouterPreference(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 12*time.Second)
defer cancel()
hdr := map[string]string{}
if b := userBearer(r); b != "" {
hdr["Authorization"] = b
}
body, status, err := s.get(ctx, apiHost()+"/v1/router/preference", hdr)
if err != nil || status < 200 || status >= 300 {
writeJSON(w, http.StatusOK, "no-store", disabledPref())
return
}
pref, ok := upstreamPref(body)
if !ok {
writeJSON(w, http.StatusOK, "no-store", disabledPref())
return
}
writeJSON(w, http.StatusOK, "no-store", pref)
}
// putRouterPreference writes a new bias for the caller-org. Body: {"bias": 0..1}.
// Forwards as POST /v1/router/preference with the caller's bearer. On any upstream
// failure it echoes the ATTEMPTED bias with available:false (honest "not saved" —
// the panel keeps the user's slider position and shows the control couldn't save),
// never a 5xx.
func (s *Server) putRouterPreference(w http.ResponseWriter, r *http.Request) {
var in struct {
Bias *float64 `json:"bias"`
}
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 4096)).Decode(&in); err != nil || in.Bias == nil {
writeError(w, http.StatusBadRequest, `body must be {"bias": 0..1}`)
return
}
bias := clamp01(*in.Bias)
ctx, cancel := context.WithTimeout(r.Context(), 12*time.Second)
defer cancel()
hdr := map[string]string{"Content-Type": "application/json"}
if b := userBearer(r); b != "" {
hdr["Authorization"] = b
}
reqBody, _ := json.Marshal(map[string]float64{"bias": bias})
body, status, err := s.do(ctx, http.MethodPost, apiHost()+"/v1/router/preference", hdr, reqBody)
if err != nil || status < 200 || status >= 300 {
writeJSON(w, http.StatusOK, "no-store", prefResponse{Bias: bias, Default: 0.5, Available: false})
return
}
if pref, ok := upstreamPref(body); ok {
writeJSON(w, http.StatusOK, "no-store", pref)
return
}
// Accepted, but the gateway echoed nothing parseable — report the saved bias.
writeJSON(w, http.StatusOK, "no-store", prefResponse{Bias: bias, Default: 0.5, Available: true})
}
// judgePanelUnavailable is the honest empty payload for the judge panel: no judges,
// no benchmark — the panel shows "warming up", never fabricated calibration.
var judgePanelUnavailable = json.RawMessage(`{"available":false,"enabled":false,"sampleRate":0,"models":[],"judges":[],"benchmark":null}`)
// normalizeJudgePanel tolerates either the bare judge-panel shape or the casibase
// {status,data} envelope, and guarantees an available:true flag on a real body so
// the panel renders. A non-ok envelope or unparseable body is a soft failure
// (bad gateway) → the honest empty payload via the cachedJSON onError path.
func normalizeJudgePanel(body []byte) (any, error) {
var obj map[string]json.RawMessage
if err := json.Unmarshal(body, &obj); err != nil {
return nil, httpErr(http.StatusBadGateway)
}
// Envelope {status,data:{…}}: require ok + non-null data, then descend into it.
if _, hasData := obj["data"]; hasData {
if _, hasStatus := obj["status"]; hasStatus {
var env struct {
Status string `json:"status"`
Data json.RawMessage `json:"data"`
}
if json.Unmarshal(body, &env) != nil || env.Status != "ok" || len(env.Data) == 0 || string(env.Data) == "null" {
return nil, httpErr(http.StatusBadGateway)
}
if json.Unmarshal(env.Data, &obj) != nil {
return nil, httpErr(http.StatusBadGateway)
}
}
}
if _, ok := obj["available"]; !ok {
obj["available"] = json.RawMessage("true")
}
return obj, nil
}
func (s *Server) handleCloudJudgePanel(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, "judge-panel", "public, max-age=30, s-maxage=30, stale-while-revalidate=120",
30*time.Second, 5*time.Minute,
func(ctx context.Context) (any, error) {
// scope pinned to platform — aggregates only, no vendor-labeled scope.
body, status, err := s.get(ctx, apiHost()+"/v1/router/judge-panel?scope=platform", nil)
if err != nil {
return nil, err
}
if status < 200 || status >= 300 {
return nil, httpErr(status)
}
return normalizeJudgePanel(body)
},
func(w http.ResponseWriter, _ error) {
writeJSON(w, http.StatusOK, "no-store", judgePanelUnavailable)
},
)
}
+325 -21
View File
@@ -5,15 +5,32 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"
)
// TestCloudPulseDemoFlag verifies the honesty contract: with no service token
// configured (the default, and what the smoke suite exercises), /v1/world/cloud-pulse
// returns a clean 200 JSON payload that is EXPLICITLY flagged demo:true and
// carries a non-empty note. Platform numbers are never presented as live without
// the flag.
func TestCloudPulseDemoFlag(t *testing.T) {
t.Setenv("HANZO_CLOUD_PULSE_TOKEN", "") // force the demo path
// gatusBoard3of4 is a Gatus statuses board with 3 of 4 endpoints healthy → the
// status-page proxy derives a real 75% uptime (up/total), never a constant.
const gatusBoard3of4 = `[
{"name":"api","group":"core","results":[{"status":200,"success":true,"timestamp":"2026-07-16T00:00:00Z","duration":1000000}]},
{"name":"iam","group":"core","results":[{"status":200,"success":true,"timestamp":"2026-07-16T00:00:00Z","duration":1200000}]},
{"name":"kms","group":"core","results":[{"status":200,"success":true,"timestamp":"2026-07-16T00:00:00Z","duration":1500000}]},
{"name":"llm","group":"ai","results":[{"status":503,"success":false,"timestamp":"2026-07-16T00:00:00Z","duration":2000000,"errors":["down"]}]}
]`
// TestCloudPulseHonestEmpty verifies the honesty contract when NOTHING is reachable
// (no service token, upstreams dead): /v1/world/cloud-pulse returns a clean 200 that
// is flagged demo:true + volumeModeled:true, carries a human note, and is HONESTLY
// EMPTY — zero volume, empty models/regions/series. It never fabricates a diurnal
// curve, a model mix, per-region rates, or a hardcoded uptime.
func TestCloudPulseHonestEmpty(t *testing.T) {
// Dead api + status origins so every real source fails fast and deterministically.
dead := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
deadURL := dead.URL
dead.Close() // now refuses connections → fetches fail fast
t.Setenv("HANZO_CLOUD_PULSE_TOKEN", "")
t.Setenv("HANZO_API_BASE", deadURL)
t.Setenv("HANZO_STATUS_BASE", deadURL)
s := NewServer()
mux := http.NewServeMux()
s.Mount(mux)
@@ -33,30 +50,35 @@ func TestCloudPulseDemoFlag(t *testing.T) {
if err := json.NewDecoder(resp.Body).Decode(&p); err != nil {
t.Fatalf("decode: %v", err)
}
if !p.Demo {
t.Fatalf("demo path must set demo:true (honesty flag)")
if !p.Demo || !p.VolumeModeled {
t.Fatalf("empty path must flag demo:true & volumeModeled:true, got demo=%v volumeModeled=%v", p.Demo, p.VolumeModeled)
}
if p.Source != "demo" {
t.Fatalf("want source=demo, got %q", p.Source)
if p.Source != "empty" {
t.Fatalf("want source=empty, got %q", p.Source)
}
if p.Note == "" {
t.Fatalf("demo payload must carry a human note")
t.Fatalf("empty payload must carry a human note")
}
if p.Overview.ModelsServed == 0 || len(p.Models) == 0 {
t.Fatalf("demo payload should be populated (modelsServed=%d models=%d)", p.Overview.ModelsServed, len(p.Models))
// Honest-empty: NOTHING fabricated. All volume zero, no invented mix/regions/series.
if p.Overview.RequestsPerSec != 0 || p.Overview.Requests24h != 0 || p.Overview.Tokens24h != 0 {
t.Fatalf("volume must be zero when unmeasured, got %+v", p.Overview)
}
if len(p.Regions) == 0 || p.Overview.Regions != len(p.Regions) {
t.Fatalf("regions count mismatch: overview=%d array=%d", p.Overview.Regions, len(p.Regions))
if p.Overview.UptimePct != 0 {
t.Fatalf("uptime must be zero (tile dropped) when the status page is unreachable, got %v", p.Overview.UptimePct)
}
if len(p.RequestSeries) != 24 || len(p.TokenSeries) != 24 {
t.Fatalf("want 24-bucket series, got req=%d tok=%d", len(p.RequestSeries), len(p.TokenSeries))
if len(p.Models) != 0 || len(p.Regions) != 0 {
t.Fatalf("must not fabricate models/regions, got models=%d regions=%d", len(p.Models), len(p.Regions))
}
if len(p.RequestSeries) != 0 || len(p.TokenSeries) != 0 {
t.Fatalf("must not fabricate series, got req=%d tok=%d", len(p.RequestSeries), len(p.TokenSeries))
}
}
// TestCloudPulseServiceVolume proves the real path: with a service token and a
// reachable super-admin usage ledger, /v1/world/cloud-pulse folds MEASURED
// platform volume (get-cloud-usages ?org=all) + visor counts, drops demo:true AND
// volumeModeled:true, and surfaces the ledger's top models — never modeled.
// reachable super-admin usage ledger, /v1/world/cloud-pulse folds MEASURED platform
// volume (get-cloud-usages ?org=all) + visor counts + a REAL uptime from the status
// page (up/total), drops demo:true AND volumeModeled:true, and surfaces the ledger's
// top models — never modeled.
func TestCloudPulseServiceVolume(t *testing.T) {
upstream := http.NewServeMux()
upstream.HandleFunc("/v1/models", func(w http.ResponseWriter, _ *http.Request) {
@@ -82,11 +104,16 @@ func TestCloudPulseServiceVolume(t *testing.T) {
{"model":"zen-1","spendCents":12000,"tokens":300000000,"requests":300000,"pct":28.6}]}
}`))
})
// Real uptime source (Gatus): 3 of 4 endpoints healthy → 75%.
upstream.HandleFunc("/api/v1/endpoints/statuses", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(gatusBoard3of4))
})
up := httptest.NewServer(upstream)
t.Cleanup(up.Close)
t.Setenv("HANZO_CLOUD_PULSE_TOKEN", "svc-super-admin")
t.Setenv("HANZO_API_BASE", up.URL)
t.Setenv("HANZO_STATUS_BASE", up.URL)
s := NewServer()
mux := http.NewServeMux()
@@ -124,6 +151,9 @@ func TestCloudPulseServiceVolume(t *testing.T) {
if p.Overview.GpusOnline != 3 {
t.Fatalf("want gpusOnline=3, got %d", p.Overview.GpusOnline)
}
if p.Overview.UptimePct != 75 {
t.Fatalf("want real uptime 75%% (3/4 up), got %v", p.Overview.UptimePct)
}
if len(p.Models) != 2 || p.Models[0].ID != "zen-omni-30b" {
t.Fatalf("want ledger top models, got %+v", p.Models)
}
@@ -131,3 +161,277 @@ func TestCloudPulseServiceVolume(t *testing.T) {
t.Fatalf("want measured series buckets, got %v", p.RequestSeries)
}
}
// TestCloudPulseRouterFallback proves the honest fallback: with a service token but
// the super-admin usage ledger UNAVAILABLE (403), the pulse does NOT fabricate. It
// folds REAL public volume — requests/sec from the native request-geo globe
// (traffic-globe rps_1m) and total routed requests + hourly throughput + per-model
// mix from the learned-router stats — while leaving token volume blank (tokens 0)
// and volumeModeled:true. demo stays false; the numbers shown are all measured.
func TestCloudPulseRouterFallback(t *testing.T) {
upstream := http.NewServeMux()
upstream.HandleFunc("/v1/models", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"data":[{"id":"zen-1"},{"id":"zen-omni-30b"},{"id":"qwen3-235b"}]}`))
})
upstream.HandleFunc("/v1/machines", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"machines":[{"region":"nyc","status":"active"},{"region":"sfo","status":"active"}]}`))
})
upstream.HandleFunc("/v1/gpus", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"gpus":[{"region":"nyc"},{"region":"sfo"}]}`))
})
// Ledger unavailable (e.g. a non-super-admin token) → the fallback must engage.
upstream.HandleFunc("/v1/get-cloud-usages", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusForbidden)
})
// Real routed volume + hourly series + per-model mix (scope MUST be platform).
upstream.HandleFunc("/v1/router/stats", func(w http.ResponseWriter, r *http.Request) {
if got := r.URL.Query().Get("scope"); got != "platform" {
t.Errorf("router-stats scope must be pinned to platform, got %q", got)
}
_, _ = w.Write([]byte(`{"status":"ok","data":{
"window":{"since":"2026-07-16T00:00:00Z","until":"2026-07-17T00:00:00Z","events":864000},
"by_model":{"zen-omni-30b":520,"zen-1":300,"qwen3-235b":180},
"throughput":{"per_hour":[35000,36000,34000],"total_window":864000}}}`))
})
// Real requests/sec from the native request-geo globe.
upstream.HandleFunc("/v1/traffic/globe", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"status":"ok","data":{"window":{"minutes":60},
"points":[{"country":"US","lat":36,"lon":-119,"count":5}],
"totals":{"rps_1m":0.62,"rpm_60m":30,"top_countries":[{"country":"US","count":5}]}}}`))
})
up := httptest.NewServer(upstream)
t.Cleanup(up.Close)
t.Setenv("HANZO_CLOUD_PULSE_TOKEN", "svc-non-admin")
t.Setenv("HANZO_API_BASE", up.URL)
t.Setenv("HANZO_STATUS_BASE", up.URL) // no status board on this mux → uptime honestly 0
s := NewServer()
mux := http.NewServeMux()
s.Mount(mux)
ts := httptest.NewServer(mux)
t.Cleanup(ts.Close)
resp, err := http.Get(ts.URL + "/v1/world/cloud-pulse")
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
var p cloudPulse
if err := json.NewDecoder(resp.Body).Decode(&p); err != nil {
t.Fatalf("decode: %v", err)
}
if p.Demo {
t.Fatalf("fallback path has real data → demo must be false")
}
if !p.VolumeModeled {
t.Fatalf("non-ledger volume must keep volumeModeled:true (tokens unmeasured)")
}
if p.Source != "service" {
t.Fatalf("want source=service (token plane resolved counts), got %q", p.Source)
}
if p.Overview.RequestsPerSec != 0.6 {
t.Fatalf("want real rps 0.6 (globe rps_1m 0.62), got %v", p.Overview.RequestsPerSec)
}
if p.Overview.Requests24h != 864000 {
t.Fatalf("want real routed requests 864000 (router window.events), got %d", p.Overview.Requests24h)
}
if p.Overview.Tokens24h != 0 {
t.Fatalf("tokens are unmeasured on the fallback → must be 0, got %d", p.Overview.Tokens24h)
}
if len(p.RequestSeries) != 3 || p.RequestSeries[0] != 35000 {
t.Fatalf("want real hourly throughput series, got %v", p.RequestSeries)
}
if len(p.TokenSeries) != 0 {
t.Fatalf("token series is unmeasured → must be empty, got %v", p.TokenSeries)
}
// router by_model is opaque "arm-N" on platform scope, NOT real model names, so
// the model mix must stay EMPTY on the public fallback (never "arm-8") — real
// per-model usage comes only from the measured ledger (admin path).
if len(p.Models) != 0 {
t.Fatalf("router fallback must not surface opaque arm ids as models, got %+v", p.Models)
}
if p.Overview.Regions != 2 {
t.Fatalf("want 2 real regions from the visor fleet, got %d", p.Overview.Regions)
}
}
// TestCloudPulseAdminBearer proves the flagship admin path: a signed-in admin
// (z@hanzo.ai, owner "hanzo") gets the FULL measured aggregate fetched with their
// OWN bearer — the all-org usage ledger + visor — with NO server-side service token
// wired, served no-store (never the shared public cache) and Vary: Authorization.
func TestCloudPulseAdminBearer(t *testing.T) {
// IAM: userinfo → the caller resolves to the operator org (admin); global-users →
// the real platform user list (2 signups in the last 24h, 1 online, 1 old).
now := time.Now().UTC()
iamMux := http.NewServeMux()
iamMux.HandleFunc("/v1/iam/oauth/userinfo", func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") == "" {
http.Error(w, "no auth", http.StatusUnauthorized)
return
}
_, _ = w.Write([]byte(`{"owner":"hanzo","sub":"z@hanzo.ai"}`))
})
iamMux.HandleFunc("/v1/iam/global-users", func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "Bearer admin-token" {
t.Errorf("global-users must be read with the caller's bearer, got %q", r.Header.Get("Authorization"))
}
_, _ = w.Write([]byte(`[
{"createdTime":"` + now.Add(-2*time.Hour).Format(time.RFC3339) + `","isOnline":true},
{"createdTime":"` + now.Add(-20*time.Hour).Format(time.RFC3339) + `","isOnline":false},
{"createdTime":"` + now.Add(-10*24*time.Hour).Format(time.RFC3339) + `","isOnline":false},
{"createdTime":"` + now.Add(-40*24*time.Hour).Format(time.RFC3339) + `","isOnline":false,"isDeleted":true}]`))
})
iam := httptest.NewServer(iamMux)
t.Cleanup(iam.Close)
// api.hanzo.ai — the caller's bearer must reach the all-org ledger + visor.
upstream := http.NewServeMux()
upstream.HandleFunc("/v1/models", func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "Bearer admin-token" {
t.Errorf("caller bearer must be forwarded to /v1/models, got %q", r.Header.Get("Authorization"))
}
_, _ = w.Write([]byte(`{"data":[{"id":"zen-1"},{"id":"zen-omni-30b"}]}`))
})
upstream.HandleFunc("/v1/machines", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"machines":[{"region":"nyc","status":"active"}]}`))
})
upstream.HandleFunc("/v1/gpus", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"gpus":[{"region":"nyc"}]}`))
})
upstream.HandleFunc("/v1/get-cloud-usages", func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "Bearer admin-token" {
t.Errorf("all-org ledger must be read with the caller's bearer, got %q", r.Header.Get("Authorization"))
}
_, _ = w.Write([]byte(`{"range":"24h","interval":"1h",
"totals":{"tokens":1180000000,"requests":1000000,"spendCents":42000,"models":2},
"series":[{"t":"2026-07-16T00:00:00Z","tokens":40000000,"requests":34000}],
"byModel":{"items":[{"model":"zen-omni-30b","tokens":600000000,"requests":520000,"pct":60}]}}`))
})
up := httptest.NewServer(upstream)
t.Cleanup(up.Close)
t.Setenv("HANZO_CLOUD_PULSE_TOKEN", "") // NO service token — the admin's own bearer drives it
t.Setenv("HANZO_API_BASE", up.URL)
t.Setenv("HANZO_STATUS_BASE", up.URL)
t.Setenv("HANZO_IAM_ISSUER", iam.URL)
t.Setenv("WORLD_ADMIN_ORGS", "hanzo") // operator org resolves via deploy env, not code
s := NewServer()
mux := http.NewServeMux()
s.Mount(mux)
ts := httptest.NewServer(mux)
t.Cleanup(ts.Close)
req, _ := http.NewRequest(http.MethodGet, ts.URL+"/v1/world/cloud-pulse", nil)
req.Header.Set("Authorization", "Bearer admin-token")
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
if cc := resp.Header.Get("Cache-Control"); cc != "private, no-store" {
t.Fatalf("admin pulse must be no-store/private, got Cache-Control %q", cc)
}
if v := resp.Header.Get("Vary"); v != "Authorization" {
t.Fatalf("must Vary: Authorization to isolate the public cache, got %q", v)
}
var p cloudPulse
if err := json.NewDecoder(resp.Body).Decode(&p); err != nil {
t.Fatalf("decode: %v", err)
}
if p.Demo || p.VolumeModeled {
t.Fatalf("admin ledger path must be fully measured (demo=%v volumeModeled=%v)", p.Demo, p.VolumeModeled)
}
if p.Overview.Requests24h != 1_000_000 || p.Overview.Tokens24h != 1_180_000_000 {
t.Fatalf("admin must see measured all-org volume, got req=%d tok=%d", p.Overview.Requests24h, p.Overview.Tokens24h)
}
if p.Overview.ModelsServed != 2 || len(p.Models) != 1 || p.Models[0].ID != "zen-omni-30b" {
t.Fatalf("admin must see real catalog + ledger models, got served=%d models=%+v", p.Overview.ModelsServed, p.Models)
}
// Real platform user metrics from IAM global-users (admin path only).
if p.Users == nil {
t.Fatalf("admin must see real user metrics from IAM global-users")
}
if p.Users.Total != 3 { // 4 rows, 1 deleted → 3 live
t.Fatalf("want 3 users (deleted excluded), got %d", p.Users.Total)
}
if p.Users.Signups24h != 2 {
t.Fatalf("want 2 signups in 24h, got %d", p.Users.Signups24h)
}
if p.Users.ActiveNow != 1 {
t.Fatalf("want 1 active-now (isOnline), got %d", p.Users.ActiveNow)
}
if len(p.Users.SignupSeries) != userSignupDays {
t.Fatalf("want a %d-day signup series, got %d", userSignupDays, len(p.Users.SignupSeries))
}
}
// TestCloudPulseAdminLLMObservability proves the fix for an empty "Model Usage":
// when the exact usage ledger is NOT available to a signed-in admin, cloud-pulse
// folds REAL platform usage + per-model mix (real names) from LLM observability
// (/v1/admin/o11y) — never the opaque router arms, never zeros.
func TestCloudPulseAdminLLMObservability(t *testing.T) {
iam := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/iam/oauth/userinfo" || r.Header.Get("Authorization") == "" {
http.NotFound(w, r)
return
}
_, _ = w.Write([]byte(`{"owner":"hanzo","sub":"z@hanzo.ai"}`))
}))
t.Cleanup(iam.Close)
api := http.NewServeMux()
api.HandleFunc("/v1/models", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"data":[{"id":"zen-1"},{"id":"zen-omni-30b"}]}`))
})
api.HandleFunc("/v1/machines", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"machines":[{"region":"nyc","status":"active"}]}`))
})
api.HandleFunc("/v1/gpus", func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(`{"gpus":[]}`)) })
api.HandleFunc("/v1/get-cloud-usages", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusForbidden) })
// LLM observability: real platform usage + top models by REAL name.
api.HandleFunc("/v1/admin/o11y", func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "Bearer admin-token" {
t.Errorf("o11y must be read with the caller's bearer, got %q", r.Header.Get("Authorization"))
}
_, _ = w.Write([]byte(`{"totals":{"requests":500000,"tokens":900000000},
"topModels":[{"model":"zen-omni-30b","requests":300000,"tokens":600000000},
{"model":"zen-1","requests":200000,"tokens":300000000}]}`))
})
up := httptest.NewServer(api)
t.Cleanup(up.Close)
t.Setenv("HANZO_CLOUD_PULSE_TOKEN", "")
t.Setenv("HANZO_API_BASE", up.URL)
t.Setenv("HANZO_STATUS_BASE", up.URL)
t.Setenv("HANZO_IAM_ISSUER", iam.URL)
t.Setenv("WORLD_ADMIN_ORGS", "hanzo") // operator org resolves via deploy env, not code
s := NewServer()
mux := http.NewServeMux()
s.Mount(mux)
ts := httptest.NewServer(mux)
t.Cleanup(ts.Close)
req, _ := http.NewRequest(http.MethodGet, ts.URL+"/v1/world/cloud-pulse", nil)
req.Header.Set("Authorization", "Bearer admin-token")
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
var p cloudPulse
if err := json.NewDecoder(resp.Body).Decode(&p); err != nil {
t.Fatalf("decode: %v", err)
}
if len(p.Models) != 2 || p.Models[0].ID != "zen-omni-30b" || p.Models[0].Requests24h != 300000 {
t.Fatalf("want real o11y top models (real names), got %+v", p.Models)
}
if p.Overview.Requests24h != 500000 || p.Overview.Tokens24h != 900000000 {
t.Fatalf("want measured o11y usage, got req=%d tok=%d", p.Overview.Requests24h, p.Overview.Tokens24h)
}
if p.VolumeModeled {
t.Fatalf("measured o11y usage must clear volumeModeled")
}
}
+145
View File
@@ -0,0 +1,145 @@
package world
import (
"context"
"encoding/json"
"net/http"
"strings"
"time"
)
// Congressional trading — the disclosed stock transactions of U.S. House and
// Senate members (STOCK Act filings). The "smart money in Congress" macro signal:
// who is buying and selling, and the net direction. Every free public feed for
// this data is now gated behind a key (the house/senate-stock-watcher S3 buckets
// went private, Capitol Trades' BFF is unstable), so this endpoint reads Quiver
// Quant's live feed when QUIVER_API_KEY is configured and degrades to a clean
// unavailable payload otherwise — the same key-gated pattern as the finnhub, eia
// and acled endpoints. The parser is real and tested; only the fetch needs a key.
const quiverCongressURL = "https://api.quiverquant.com/beta/live/congresstrading"
// handleCongress serves /v1/world/congress.
func (s *Server) handleCongress(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, "congress:v1",
"public, max-age=3600, s-maxage=3600, stale-while-revalidate=7200",
time.Hour, 2*time.Hour,
func(ctx context.Context) (any, error) { return s.computeCongress(ctx) },
func(w http.ResponseWriter, err error) {
reason := "temporarily unavailable"
if err == errMissingKey {
reason = "QUIVER_API_KEY not configured"
}
writeJSON(w, http.StatusOK, "", map[string]any{
"asOf": nowISO(), "unavailable": true, "reason": reason,
"count": 0, "buys": 0, "sells": 0, "recent": []any{},
})
})
}
func (s *Server) computeCongress(ctx context.Context) (any, error) {
key := env("QUIVER_API_KEY", "QUIVERQUANT_API_KEY")
if key == "" {
return nil, errMissingKey
}
body, status, err := s.get(ctx, quiverCongressURL, map[string]string{
"Accept": "application/json", "Authorization": "Bearer " + key,
})
if err != nil {
return nil, err
}
if status < 200 || status >= 300 {
return nil, errUnavailable
}
trades := parseCongressTrades(body)
buys, sells := 0, 0
recent := make([]map[string]any, 0, 40)
for i, t := range trades {
switch t.Side {
case "buy":
buys++
case "sell":
sells++
}
if i < 40 {
recent = append(recent, map[string]any{
"member": t.Member, "ticker": t.Ticker, "side": t.Side,
"amount": t.Range, "chamber": t.Chamber,
"tradedAt": t.TradedAt, "reportedAt": t.ReportedAt,
})
}
}
return map[string]any{
"asOf": nowISO(),
"source": "Quiver Quant · Congressional trading",
"count": len(trades),
"buys": buys,
"sells": sells,
"recent": recent,
}, nil
}
// errMissingKey signals an absent API key so the handler can degrade with a
// precise reason rather than a generic "unavailable". Package-private, never
// serialized.
var errMissingKey = &rotationError{"api key not configured"}
// ── pure parsing (unit-tested) ───────────────────────────────────────────────
type congressTrade struct {
Member string
Ticker string
Side string // "buy" | "sell" | ""
Range string
Chamber string
TradedAt string
ReportedAt string
}
// parseCongressTrades reads Quiver Quant's live congresstrading JSON array.
// Malformed input yields an empty slice, never a panic. Field names follow
// Quiver's schema; the transaction is normalized to buy/sell.
func parseCongressTrades(body []byte) []congressTrade {
var raw []struct {
Representative string `json:"Representative"`
Ticker string `json:"Ticker"`
Transaction string `json:"Transaction"`
Range string `json:"Range"`
House string `json:"House"`
TransactionDate string `json:"TransactionDate"`
ReportDate string `json:"ReportDate"`
}
if err := json.Unmarshal(body, &raw); err != nil {
return nil
}
out := make([]congressTrade, 0, len(raw))
for _, r := range raw {
out = append(out, congressTrade{
Member: strings.TrimSpace(r.Representative),
Ticker: strings.TrimSpace(r.Ticker),
Side: normalizeTradeSide(r.Transaction),
Range: strings.TrimSpace(r.Range),
Chamber: strings.TrimSpace(r.House),
TradedAt: warnDate(r.TransactionDate),
ReportedAt: warnDate(r.ReportDate),
})
}
return out
}
// normalizeTradeSide maps Quiver's transaction labels ("Purchase", "Sale",
// "Sale (Partial)", "Sale (Full)", "Exchange") to buy/sell. Unknown → "".
func normalizeTradeSide(t string) string {
t = strings.ToLower(strings.TrimSpace(t))
switch {
case strings.Contains(t, "purchase"), strings.Contains(t, "buy"):
return "buy"
case strings.Contains(t, "sale"), strings.Contains(t, "sell"):
return "sell"
default:
return ""
}
}
+52
View File
@@ -0,0 +1,52 @@
package world
import "testing"
func TestNormalizeTradeSide(t *testing.T) {
cases := []struct{ in, want string }{
{"Purchase", "buy"},
{"Sale (Partial)", "sell"},
{"Sale (Full)", "sell"},
{"sale", "sell"},
{"buy", "buy"},
{"Exchange", ""},
{"", ""},
}
for _, c := range cases {
if got := normalizeTradeSide(c.in); got != c.want {
t.Errorf("normalizeTradeSide(%q) = %q, want %q", c.in, got, c.want)
}
}
}
func TestParseCongressTradesMalformed(t *testing.T) {
if got := parseCongressTrades([]byte("not json <<<")); got != nil {
t.Errorf("malformed: want nil, got %v", got)
}
if got := parseCongressTrades(nil); got != nil {
t.Errorf("nil: want nil, got %v", got)
}
if got := parseCongressTrades([]byte("[]")); len(got) != 0 {
t.Errorf("empty: want 0, got %d", len(got))
}
}
func TestParseCongressTradesWellFormed(t *testing.T) {
body := []byte(`[
{"Representative":"Nancy Pelosi","Ticker":"NVDA","Transaction":"Purchase","Range":"$1,000,001 - $5,000,000","House":"Representatives","TransactionDate":"2026-06-20T00:00:00.000","ReportDate":"2026-07-01T00:00:00.000"},
{"Representative":" Tommy Tuberville ","Ticker":"XOM","Transaction":"Sale (Full)","Range":"$15,001 - $50,000","House":"Senate","TransactionDate":"2026-06-18","ReportDate":"2026-06-28"}
]`)
got := parseCongressTrades(body)
if len(got) != 2 {
t.Fatalf("want 2 trades, got %d", len(got))
}
if got[0].Member != "Nancy Pelosi" || got[0].Ticker != "NVDA" || got[0].Side != "buy" {
t.Errorf("trade[0] = %+v", got[0])
}
if got[0].Chamber != "Representatives" || got[0].TradedAt != "2026-06-20" || got[0].ReportedAt != "2026-07-01" {
t.Errorf("trade[0] meta = %+v", got[0])
}
if got[1].Member != "Tommy Tuberville" || got[1].Side != "sell" { // trimmed + sell
t.Errorf("trade[1] = %+v", got[1])
}
}
+137
View File
@@ -0,0 +1,137 @@
package world
import (
"context"
"encoding/json"
"io"
"net/http"
"time"
"github.com/hanzoai/world/internal/world/store"
)
// Per-identity opaque JSON blobs — the ONE mechanism behind the composed
// DASHBOARD, its ORG-SHARED default, and the user's USAGE HISTORY.
//
// The AI analyst and the toolbar compose the dashboard on the fly (add/remove
// widgets and data sources, rearrange panels, create custom feed panels), and the
// app records real usage (recent searches, watch queue). Both used to live only in
// the browser's localStorage (per-device). Here each is server state, persisted per
// identity, so a signed-in user's dashboard AND history follow them across devices.
// Anonymous callers get 401 and keep their localStorage-only state; nothing about
// the signed-out experience changes.
//
// A dashboard has TWO scopes over the SAME opaque-blob contract:
// - PER-USER (/v1/world/dashboard) — the signed-in user's own layout.
// - ORG-SHARED (/v1/world/dashboard/shared) — the default an org ADMIN publishes
// for the whole org. Every member READS it; only an admin PUTs it. The frontend
// hydrates the org default first, then overlays the user's own doc (user wins).
//
// ONE store, namespaced: this reuses the SAME per-identity settings store that
// monitors already use (store.Settings), under a `project` namespace per concern —
// there is no second table. The org-shared doc is the same 'dashboard' project keyed
// by the org (store.SharedSub) instead of a user. The blob is an OPAQUE JSON object
// (a verbatim mirror of the client's localStorage keys). The backend validates it is
// a JSON object at the boundary and never interprets it. It holds layout / usage
// state only — NEVER secrets.
//
// GET /v1/world/dashboard → { config: {...} } · PUT → { ok: true } (body: the object)
// GET /v1/world/dashboard/shared → { config: {...} } · PUT → { ok: true } (admin-only; 403 otherwise)
// GET /v1/world/history → { config: {...} } · PUT → { ok: true } (body: the object)
const dashboardDoc = "dashboard" // per-identity store namespace: composed dashboard
// identityBlobMaxBytes bounds a stored per-identity blob (layout/usage — small).
const identityBlobMaxBytes = 256 << 10
func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
s.handleIdentityBlob(w, r, dashboardDoc)
}
// handleDashboardShared serves the ORG-SHARED dashboard default: the layout an org
// admin publishes for everyone in the org. GET returns the org's published blob to
// any signed-in member (empty until first publish); PUT publishes it and is
// ADMIN-ONLY (403 otherwise). It is the SAME opaque-blob contract as the per-user
// dashboard, keyed by the org (store.SharedSub) instead of the user. The server is
// the authority on who may publish — the client only hides the trigger.
func (s *Server) handleDashboardShared(w http.ResponseWriter, r *http.Request) {
setCORS(w, "GET, PUT, OPTIONS")
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusNoContent)
return
}
if r.Method != http.MethodGet && r.Method != http.MethodPut {
writeError(w, http.StatusMethodNotAllowed, "GET or PUT")
return
}
bearer := userBearer(r)
if bearer == "" {
writeError(w, http.StatusUnauthorized, "Sign in required")
return
}
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
defer cancel()
id, err := s.introspectIdentity(ctx, bearer)
if err != nil || id.Sub == "" {
writeError(w, http.StatusUnauthorized, "Sign in required")
return
}
// Reading the org default is open to every signed-in member; PUBLISHING it is
// admin-only.
if r.Method == http.MethodPut && !s.isOrgAdmin(id) {
writeError(w, http.StatusForbidden, "Admin only — publish the org default")
return
}
s.serveIdentityBlob(w, r, store.Identity{Org: id.Org, UserSub: store.SharedSub, Project: dashboardDoc})
}
// handleIdentityBlob serves GET (read this identity's blob under `doc`) and PUT
// (upsert it), both bearer-gated. It resolves the PER-USER identity and delegates
// the read/write body to serveIdentityBlob.
func (s *Server) handleIdentityBlob(w http.ResponseWriter, r *http.Request, doc string) {
setCORS(w, "GET, PUT, OPTIONS")
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusNoContent)
return
}
if r.Method != http.MethodGet && r.Method != http.MethodPut {
writeError(w, http.StatusMethodNotAllowed, "GET or PUT")
return
}
ident, ok := s.identityForDoc(w, r, doc)
if !ok {
return
}
s.serveIdentityBlob(w, r, ident)
}
// serveIdentityBlob is the ONE GET/PUT body over an opaque JSON object under
// "config": GET returns the stored blob (or {}), PUT validates a JSON object at the
// boundary and upserts it verbatim. The caller resolves the identity (per-user or
// org-shared) and enforces any write gate FIRST — this function is scope-agnostic.
// Never 5xx: a degraded store returns {} on GET and ok:false on PUT so the client
// falls back to localStorage.
func (s *Server) serveIdentityBlob(w http.ResponseWriter, r *http.Request, ident store.Identity) {
if r.Method == http.MethodGet {
blob, ok := s.store.Settings.Get(ident)
if !ok {
blob = json.RawMessage(`{}`)
}
writeJSON(w, http.StatusOK, "private, no-store", map[string]any{"config": blob})
return
}
// PUT: validate the body is a JSON object at the boundary, then upsert verbatim.
raw, err := io.ReadAll(http.MaxBytesReader(w, r.Body, identityBlobMaxBytes))
if err != nil {
writeError(w, http.StatusBadRequest, "Body too large")
return
}
if !json.Valid(raw) || !isJSONObject(raw) {
writeError(w, http.StatusBadRequest, "Body must be a JSON object")
return
}
writeJSON(w, http.StatusOK, "private, no-store", map[string]any{
"ok": s.store.Settings.Put(ident, json.RawMessage(raw)),
})
}
+241
View File
@@ -0,0 +1,241 @@
package world
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"net/http"
"net/http/httptest"
"reflect"
"strings"
"testing"
"time"
)
// The dashboard endpoint is the durable home for a signed-in user's composed
// dashboard (what the AI analyst and toolbar build on the fly). The invariants
// that MUST hold:
// 1. an opaque config object round-trips: PUT then GET returns it verbatim,
// 2. it is isolated per identity (one user never sees another's dashboard),
// 3. anonymous callers are refused (401) — they keep localStorage,
// 4. the body is validated to be a JSON object at the boundary (400 otherwise).
//
// Identity normally resolves via IAM userinfo; introspectIdentity memoizes it in
// the server cache keyed by the bearer hash, so seeding that cache drives the
// handler with a known identity WITHOUT a network call — the same real SQLite
// store (WORLD_DATA_DIR temp dir) backs it, not a mock.
// seedIdentity primes the identity cache so a bearer resolves to (org, sub)
// offline — mirrors introspectIdentity's key derivation exactly.
func seedIdentity(s *Server, bearer, org, sub string) {
sum := sha256.Sum256([]byte(bearer))
key := "identity:" + hex.EncodeToString(sum[:12])
s.cache.Set(key, wIdentity{Org: org, Sub: sub}, time.Minute, time.Minute)
}
// seedAdmin primes an identity IAM marks as an admin owner (isAdmin=true), so it
// may publish its org's shared doc even when the org is not a global-admin org.
func seedAdmin(s *Server, bearer, org, sub string) {
sum := sha256.Sum256([]byte(bearer))
key := "identity:" + hex.EncodeToString(sum[:12])
s.cache.Set(key, wIdentity{Org: org, Sub: sub, Admin: true}, time.Minute, time.Minute)
}
func callDashboard(s *Server, method, bearer, body string) *httptest.ResponseRecorder {
return callPath(s, s.handleDashboard, "/v1/world/dashboard", method, bearer, body)
}
func callDashboardShared(s *Server, method, bearer, body string) *httptest.ResponseRecorder {
return callPath(s, s.handleDashboardShared, "/v1/world/dashboard/shared", method, bearer, body)
}
func callPath(s *Server, h http.HandlerFunc, path, method, bearer, body string) *httptest.ResponseRecorder {
r := httptest.NewRequest(method, path, strings.NewReader(body))
if bearer != "" {
r.Header.Set("Authorization", bearer)
}
if body != "" {
r.Header.Set("Content-Type", "application/json")
}
w := httptest.NewRecorder()
h(w, r)
return w
}
// dashboardConfig decodes the { "config": {...} } GET envelope.
func dashboardConfig(t *testing.T, w *httptest.ResponseRecorder) map[string]string {
t.Helper()
var body struct {
Config map[string]string `json:"config"`
}
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
t.Fatalf("decode config: %v (body=%s)", err, w.Body.String())
}
return body.Config
}
func TestDashboardRoundTripAndIdentityIsolation(t *testing.T) {
s := testServer(t)
const alice, bob = "Bearer alice-token", "Bearer bob-token"
seedIdentity(s, alice, "acme", "alice")
seedIdentity(s, bob, "acme", "bob")
// Nothing stored yet → GET is an empty object, never a 5xx or null.
if w := callDashboard(s, "GET", alice, ""); w.Code != 200 {
t.Fatalf("GET empty status = %d", w.Code)
} else if got := dashboardConfig(t, w); len(got) != 0 {
t.Fatalf("GET empty config = %v, want {}", got)
}
// PUT the composed dashboard (opaque mirror of the localStorage keys).
cfg := `{"panel-order":"[\"live-news\",\"markets\"]","worldmonitor-panels":"{\"markets\":{\"enabled\":true}}","hanzo-world-map-mode":"3d"}`
w := callDashboard(s, "PUT", alice, cfg)
if w.Code != 200 {
t.Fatalf("PUT status = %d (body=%s)", w.Code, w.Body.String())
}
var put struct {
OK bool `json:"ok"`
}
if json.Unmarshal(w.Body.Bytes(), &put); !put.OK {
t.Fatalf("PUT ok = false (store not durable? body=%s)", w.Body.String())
}
// GET returns EXACTLY what was stored, verbatim.
want := map[string]string{
"panel-order": `["live-news","markets"]`,
"worldmonitor-panels": `{"markets":{"enabled":true}}`,
"hanzo-world-map-mode": "3d",
}
if got := dashboardConfig(t, callDashboard(s, "GET", alice, "")); !reflect.DeepEqual(got, want) {
t.Fatalf("GET after PUT = %v, want %v", got, want)
}
// Isolation: a different identity must see NONE of alice's dashboard.
if got := dashboardConfig(t, callDashboard(s, "GET", bob, "")); len(got) != 0 {
t.Fatalf("identity leak: bob sees %v", got)
}
// Upsert replaces alice's config; bob still isolated + empty.
if w := callDashboard(s, "PUT", alice, `{"hanzo-world-map-mode":"2d"}`); w.Code != 200 {
t.Fatalf("upsert status = %d", w.Code)
}
if got := dashboardConfig(t, callDashboard(s, "GET", alice, "")); !reflect.DeepEqual(got, map[string]string{"hanzo-world-map-mode": "2d"}) {
t.Fatalf("upsert result = %v", got)
}
}
func TestDashboardRejectsAnonAndNonObject(t *testing.T) {
s := testServer(t)
const alice = "Bearer alice-token"
seedIdentity(s, alice, "acme", "alice")
// Anonymous → 401 (keeps localStorage), and nothing is stored.
if w := callDashboard(s, "PUT", "", `{"a":"1"}`); w.Code != 401 {
t.Fatalf("anon PUT status = %d, want 401", w.Code)
}
if w := callDashboard(s, "GET", "", ""); w.Code != 401 {
t.Fatalf("anon GET status = %d, want 401", w.Code)
}
// A non-object body (array / scalar) is refused at the boundary.
for _, bad := range []string{`[1,2,3]`, `"nope"`, `42`, `not json`} {
if w := callDashboard(s, "PUT", alice, bad); w.Code != 400 {
t.Fatalf("PUT %q status = %d, want 400", bad, w.Code)
}
}
// A wrong method is rejected.
if w := callDashboard(s, "DELETE", alice, ""); w.Code != 405 {
t.Fatalf("DELETE status = %d, want 405", w.Code)
}
}
// The org-shared dashboard is the ONE org default an admin publishes for the whole
// org. The invariants that MUST hold:
// 1. an admin PUBLISHES it and it round-trips (PUT then GET returns it verbatim),
// 2. every signed-in MEMBER of that org may READ it,
// 3. a NON-admin member may NOT publish it (403), leaving it unchanged,
// 4. publishing the shared doc NEVER touches any user's per-user dashboard,
// 5. it is isolated per org (another org sees NONE of it),
// 6. anonymous callers are refused (401).
func TestDashboardSharedOrgDefault(t *testing.T) {
s := testServer(t)
const admin, member, outsider = "Bearer admin-tok", "Bearer member-tok", "Bearer outsider-tok"
seedAdmin(s, admin, "acme", "admin-user") // org admin (isAdmin) of acme
seedIdentity(s, member, "acme", "member-user") // ordinary acme member
seedIdentity(s, outsider, "other", "other-user") // a different org entirely
// Nothing published yet → a member's GET is an empty object.
if got := dashboardConfig(t, callDashboardShared(s, "GET", member, "")); len(got) != 0 {
t.Fatalf("shared GET before publish = %v, want {}", got)
}
// A non-admin member may NOT publish — 403, and nothing is stored.
if w := callDashboardShared(s, "PUT", member, `{"panel-order":"[\"news\"]"}`); w.Code != 403 {
t.Fatalf("non-admin publish status = %d, want 403", w.Code)
}
if got := dashboardConfig(t, callDashboardShared(s, "GET", member, "")); len(got) != 0 {
t.Fatalf("shared doc changed after refused publish: %v", got)
}
// The admin publishes the org default.
shared := `{"panel-order":"[\"markets\",\"live-news\"]","hanzo-world-map-mode":"2d"}`
if w := callDashboardShared(s, "PUT", admin, shared); w.Code != 200 {
t.Fatalf("admin publish status = %d (body=%s)", w.Code, w.Body.String())
} else {
var put struct {
OK bool `json:"ok"`
}
if json.Unmarshal(w.Body.Bytes(), &put); !put.OK {
t.Fatalf("admin publish ok = false (body=%s)", w.Body.String())
}
}
// Every member of the org reads EXACTLY what the admin published.
want := map[string]string{
"panel-order": `["markets","live-news"]`,
"hanzo-world-map-mode": "2d",
}
if got := dashboardConfig(t, callDashboardShared(s, "GET", member, "")); !reflect.DeepEqual(got, want) {
t.Fatalf("member shared GET = %v, want %v", got, want)
}
if got := dashboardConfig(t, callDashboardShared(s, "GET", admin, "")); !reflect.DeepEqual(got, want) {
t.Fatalf("admin shared GET = %v, want %v", got, want)
}
// Publishing the shared doc must NOT create/alter any per-user dashboard.
if got := dashboardConfig(t, callDashboard(s, "GET", member, "")); len(got) != 0 {
t.Fatalf("shared publish leaked into member's per-user dashboard: %v", got)
}
if got := dashboardConfig(t, callDashboard(s, "GET", admin, "")); len(got) != 0 {
t.Fatalf("shared publish leaked into admin's per-user dashboard: %v", got)
}
// Org isolation: a different org's shared default is untouched (empty).
if got := dashboardConfig(t, callDashboardShared(s, "GET", outsider, "")); len(got) != 0 {
t.Fatalf("org leak: other org sees %v", got)
}
// Anonymous callers are refused on both verbs.
if w := callDashboardShared(s, "GET", "", ""); w.Code != 401 {
t.Fatalf("anon shared GET status = %d, want 401", w.Code)
}
if w := callDashboardShared(s, "PUT", "", shared); w.Code != 401 {
t.Fatalf("anon shared PUT status = %d, want 401", w.Code)
}
}
// A global-admin ORG (WORLD_ADMIN_ORGS / the base {admin,built-in}) may publish
// even without the per-identity isAdmin flag — the second half of isOrgAdmin.
func TestDashboardSharedAdminOrgMayPublish(t *testing.T) {
s := testServer(t)
const op = "Bearer op-tok"
seedIdentity(s, op, "admin", "op-user") // owner is the base admin org
if w := callDashboardShared(s, "PUT", op, `{"hanzo-world-map-mode":"3d"}`); w.Code != 200 {
t.Fatalf("admin-org publish status = %d (body=%s)", w.Code, w.Body.String())
}
if got := dashboardConfig(t, callDashboardShared(s, "GET", op, "")); !reflect.DeepEqual(got, map[string]string{"hanzo-world-map-mode": "3d"}) {
t.Fatalf("admin-org shared GET = %v", got)
}
}
+121
View File
@@ -0,0 +1,121 @@
package world
import (
"context"
"net/http"
"sort"
"sync"
"time"
)
// DeFi snapshot from DeFiLlama's public API (no key): total value locked across
// chains, the largest chains, and the stablecoin float. One cached endpoint so
// every viewer shares one upstream pull. Degrades to a clean unavailable 200.
// handleDefi serves /v1/world/defi.
func (s *Server) handleDefi(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, "defi:v1",
"public, max-age=900, s-maxage=900, stale-while-revalidate=1800",
15*time.Minute, 30*time.Minute,
func(ctx context.Context) (any, error) { return s.computeDefi(ctx) },
func(w http.ResponseWriter, err error) {
writeJSON(w, http.StatusOK, "", map[string]any{
"asOf": nowISO(), "unavailable": true,
"totalTvl": 0, "chains": []any{}, "stablecoins": map[string]any{},
})
})
}
func (s *Server) computeDefi(ctx context.Context) (any, error) {
var (
wg sync.WaitGroup
chains []defiChain
stableTotal float64
stableTop []map[string]any
stableErr error
chainErr error
)
wg.Add(2)
go func() {
defer wg.Done()
var raw []defiChain
if err := s.getJSON(ctx, "https://api.llama.fi/v2/chains",
map[string]string{"Accept": "application/json", "User-Agent": browserUA}, &raw); err != nil {
chainErr = err
return
}
chains = raw
}()
go func() {
defer wg.Done()
var sb struct {
PeggedAssets []struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Circulating map[string]float64 `json:"circulating"`
} `json:"peggedAssets"`
}
if err := s.getJSON(ctx, "https://stablecoins.llama.fi/stablecoins?includePrices=false",
map[string]string{"Accept": "application/json", "User-Agent": browserUA}, &sb); err != nil {
stableErr = err
return
}
type sc struct {
name, symbol string
mc float64
}
var all []sc
for _, p := range sb.PeggedAssets {
mc := p.Circulating["peggedUSD"]
stableTotal += mc
all = append(all, sc{p.Name, p.Symbol, mc})
}
sort.Slice(all, func(i, j int) bool { return all[i].mc > all[j].mc })
for i, c := range all {
if i >= 6 {
break
}
stableTop = append(stableTop, map[string]any{"name": c.name, "symbol": c.symbol, "marketCap": round2s(c.mc)})
}
}()
wg.Wait()
if chainErr != nil && stableErr != nil {
return nil, chainErr
}
var total float64
for _, c := range chains {
total += c.Tvl
}
sort.Slice(chains, func(i, j int) bool { return chains[i].Tvl > chains[j].Tvl })
top := make([]map[string]any, 0, 10)
for i, c := range chains {
if i >= 10 {
break
}
share := 0.0
if total > 0 {
share = c.Tvl / total * 100
}
top = append(top, map[string]any{"name": c.Name, "tvl": round2s(c.Tvl), "share": round2s(share)})
}
return map[string]any{
"asOf": nowISO(),
"totalTvl": round2s(total),
"chains": top,
"stablecoins": map[string]any{
"totalCirculating": round2s(stableTotal),
"top": stableTop,
},
}, nil
}
type defiChain struct {
Name string `json:"name"`
Tvl float64 `json:"tvl"`
}
+4 -4
View File
@@ -15,10 +15,10 @@ import (
// Enso flywheel — the router's self-improvement loop, made visible for the AI
// variant. It folds THREE honest sources into one event-typed payload:
//
// 1. the routing-decision ledger tail (export-routing-ledger ?since=, super-admin
// 1. the routing-decision ledger tail (router/ledger ?since=, super-admin
// JSONL): how many decisions, the engine-vs-heuristic mix, a confidence
// histogram, and the task / routed-model distribution;
// 2. the reward tail (export-routing-rewards ?since=, JSONL): how many decisions
// 2. the reward tail (router/rewards ?since=, JSONL): how many decisions
// have been scored and their mean reward — the per-request training labels;
// 3. the latest enso-bench eval scores (an embedded snapshot of the enso-bench
// results summary, or a live ENSO_BENCH_URL when configured).
@@ -181,7 +181,7 @@ func (s *Server) foldRoutingLedger(ctx context.Context, since string) (ensoLedge
return ensoLedgerStats{Available: false}, false
}
host := apiHost()
body, err := s.getText(ctx, host+"/v1/export-routing-ledger?since="+url.QueryEscape(since), hdr)
body, err := s.getText(ctx, host+"/v1/router/ledger?since="+url.QueryEscape(since), hdr)
if err != nil {
return ensoLedgerStats{Available: false}, false
}
@@ -225,7 +225,7 @@ func (s *Server) foldRoutingLedger(ctx context.Context, since string) (ensoLedge
stats.Models = topCounts(models, 6)
// Rewards are a bonus signal; their absence must not sink the ledger stats.
if rbody, rerr := s.getText(ctx, host+"/v1/export-routing-rewards?since="+url.QueryEscape(since), hdr); rerr == nil {
if rbody, rerr := s.getText(ctx, host+"/v1/router/rewards?since="+url.QueryEscape(since), hdr); rerr == nil {
var sum float64
n := 0
for _, line := range strings.Split(rbody, "\n") {
+462
View File
@@ -0,0 +1,462 @@
package world
import (
"context"
"encoding/json"
"fmt"
"net/http"
"sort"
)
// Enso benchmark suite — the ADMIN-ONLY head-to-head. Enso is a PRIVATE Hanzo
// product and this data names only Enso's own measured results, so the endpoint is gated
// by requireAdmin (fail-closed: 401 without a token, 403 for a non-admin owner) —
// the SAME IAM-introspection gate the deep Cloud panels use. A non-admin never
// receives the benchmark JSON; it is not merely hidden in the client.
//
// It reshapes the committed enso-bench snapshot (the SAME //go:embed
// ensodata/summary.json the flywheel reads — one source, two views) into three
// honest blocks the panel renders:
//
// 1. per-bench measured head-to-head (each system's accuracy ± stderr + cost,
// with the best single arm and the Enso-reported figure alongside),
// 2. the enso-ultra v1→v2 verify-then-select ablation (Δ accuracy + cost drop),
// 3. the agentic SWE-Bench Pro pilot (step-routed vs single-Opus),
//
// plus server-authored caveats so the honest framing travels WITH the data and
// cannot be stripped in the client. Numbers are measured; Enso columns are
// Enso's own reported (Table 1) figures — never conflated.
// ── snapshot shape (superset of the flywheel's minimal read) ─────────────────
type benchFullRow struct {
AccuracyPct float64 `json:"accuracy_pct"`
StderrPct float64 `json:"stderr_pct"`
N int `json:"n"`
UsdEst float64 `json:"usd_est"`
RunTag string `json:"run_tag"`
// Degraded marks a run that lost most of its items to zero-token blanks. Blanks are
// not missing-at-random -- they land on the hard items the model gets wrong -- so the
// accuracy over the survivors is inflated and must not be shown as a score. A degraded
// row is dropped from the table rather than displayed with a misleading number.
Degraded bool `json:"degraded"`
}
type ablationEntry struct {
AccuracyPct float64 `json:"accuracy_pct"`
N int `json:"n"`
UsdEst float64 `json:"usd_est"`
Logic string `json:"logic"`
}
type agenticEntry struct {
N int `json:"n"`
Resolved int `json:"resolved"`
ResolvedRate float64 `json:"resolved_rate"`
Usd float64 `json:"usd"`
Calls int `json:"calls"`
}
type benchSnapshot struct {
Measured map[string]map[string]benchFullRow `json:"measured"`
EnsoReported map[string]map[string]float64 `json:"enso_reported"`
UltraAblation map[string]map[string]ablationEntry `json:"ultra_ablation"`
Pending []string `json:"pending"`
TotalUsdEst float64 `json:"total_usd_est"`
Agentic map[string]struct {
Bench string `json:"bench"`
Metric string `json:"metric"`
NItems int `json:"n_items"`
Systems map[string]agenticEntry `json:"systems"`
Note string `json:"note"`
} `json:"agentic"`
}
// ── wire shape (what the panel consumes) ─────────────────────────────────────
type benchSystemRow struct {
System string `json:"system"`
Family string `json:"family"` // "enso" | "arm" — drives the highlight
AccuracyPct float64 `json:"accuracyPct"`
StderrPct float64 `json:"stderrPct"`
N int `json:"n"`
UsdEst float64 `json:"usdEst"`
Preflight bool `json:"preflight,omitempty"` // n<=1 / run_tag preflight ⇒ not a scored run
}
type benchTable struct {
Key string `json:"key"`
Name string `json:"name"`
Systems []benchSystemRow `json:"systems"` // sorted by accuracy desc
BestArm string `json:"bestArm"` // best NON-enso measured arm
BestArmPct float64 `json:"bestArmPct"`
EnsoPct float64 `json:"ensoPct"`
EnsoUsd float64 `json:"ensoUsd"`
EnsoReported float64 `json:"ensoReported,omitempty"`
EnsoUltraReported float64 `json:"ensoUltraReported,omitempty"`
Note string `json:"note,omitempty"`
}
type ablationArm struct {
Label string `json:"label"`
Logic string `json:"logic"`
AccuracyPct float64 `json:"accuracyPct"`
N int `json:"n"`
UsdEst float64 `json:"usdEst"`
}
type ablationTable struct {
Key string `json:"key"`
Name string `json:"name"`
V1 ablationArm `json:"v1"`
V2 ablationArm `json:"v2"`
DeltaPts float64 `json:"deltaPts"`
CostDropPct float64 `json:"costDropPct"`
}
type agenticSystemRow struct {
Label string `json:"label"`
ResolvedRate float64 `json:"resolvedRate"` // 0..1
Resolved int `json:"resolved"`
N int `json:"n"`
UsdEst float64 `json:"usdEst"`
Calls int `json:"calls"`
}
type agenticTable struct {
Bench string `json:"bench"`
Metric string `json:"metric"`
StepRouted agenticSystemRow `json:"stepRouted"`
SingleOpus agenticSystemRow `json:"singleOpus"`
Note string `json:"note"`
}
type ensoTable struct {
Bench string `json:"bench"`
Scores map[string]float64 `json:"scores"`
}
type ensoBenchmarks struct {
UpdatedAt string `json:"updatedAt"`
Source string `json:"source"` // "embedded" | "live"
Benches []benchTable `json:"benches"`
Ablation []ablationTable `json:"ablation"`
Agentic *agenticTable `json:"agentic,omitempty"`
Enso []ensoTable `json:"enso"`
Pending []string `json:"pending"`
TotalUsdEst float64 `json:"totalUsdEst"`
Caveats []string `json:"caveats"`
}
// benchDisplay maps a measured bench key to its display name and the Enso Table-1
// label for the same benchmark (empty ⇒ no Enso counterpart). The slice order is
// the panel's display order (agentic-adjacent code benches first).
var benchDisplay = []struct {
Key, Name, Enso string
}{
{"livecodebench", "LiveCodeBench", "LiveCodeBench"},
{"gpqa_diamond", "GPQA Diamond", "GPQA Diamond"},
{"hle", "Humanity's Last Exam", "Humanity's Last Exam"},
}
// ── handler ──────────────────────────────────────────────────────────────────
// handleEnsoBenchmarks serves the admin-only head-to-head. requireAdmin is the
// gate (401/403 fail-closed); on success it reshapes the embedded snapshot (or a
// live ENSO_BENCH_URL) and returns 200. No upstream forward — the data is local.
func (s *Server) handleEnsoBenchmarks(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
if _, ok := s.requireAdmin(w, r); !ok {
return // requireAdmin already wrote 401 / 403
}
data, source := s.ensoBenchmarksSource(r.Context())
writeJSON(w, http.StatusOK, "no-store", buildEnsoBenchmarks(data, source))
}
// ensoBenchmarksSource returns the snapshot bytes and their provenance: a live
// ENSO_BENCH_URL when configured and it parses, else the committed embed.
func (s *Server) ensoBenchmarksSource(ctx context.Context) ([]byte, string) {
if u := env("ENSO_BENCH_URL"); u != "" {
if body, err := s.getText(ctx, u, nil); err == nil {
var probe benchSnapshot
if json.Unmarshal([]byte(body), &probe) == nil && len(probe.Measured) > 0 {
return []byte(body), "live"
}
}
}
return ensoBenchSummary, "embedded"
}
// buildEnsoBenchmarks reshapes a snapshot into the panel payload. Total, pure and
// order-stable: an unparseable snapshot yields an empty-but-valid response rather
// than an error, so the admin panel degrades honestly instead of 5xxing.
func buildEnsoBenchmarks(data []byte, source string) ensoBenchmarks {
out := ensoBenchmarks{UpdatedAt: nowRFC(), Source: source, Pending: []string{}, Benches: []benchTable{}, Ablation: []ablationTable{}, Enso: []ensoTable{}}
var snap benchSnapshot
if json.Unmarshal(data, &snap) != nil {
out.Caveats = ensoCaveats(out.Benches, out.Ablation, out.Agentic)
return out
}
out.Benches = buildBenchTables(snap)
out.Ablation = buildAblation(snap.UltraAblation)
out.Agentic = buildAgentic(snap)
out.Enso = buildEnso(snap.EnsoReported)
if snap.Pending != nil {
out.Pending = snap.Pending
}
out.TotalUsdEst = snap.TotalUsdEst
out.Caveats = ensoCaveats(out.Benches, out.Ablation, out.Agentic)
return out
}
func buildBenchTables(snap benchSnapshot) []benchTable {
tables := make([]benchTable, 0, len(benchDisplay))
for _, bd := range benchDisplay {
sysMap, ok := snap.Measured[bd.Key]
if !ok || len(sysMap) == 0 {
continue
}
t := benchTable{Key: bd.Key, Name: bd.Name}
for sys, row := range sysMap {
if row.Degraded {
continue // most of the run was blank; not a trustworthy measurement
}
pre := row.N <= 1 || row.RunTag == "preflight"
t.Systems = append(t.Systems, benchSystemRow{
System: sys,
Family: ensoFamily(sys),
AccuracyPct: row.AccuracyPct,
StderrPct: row.StderrPct,
N: row.N,
UsdEst: row.UsdEst,
Preflight: pre,
})
}
sort.Slice(t.Systems, func(a, b int) bool {
if t.Systems[a].AccuracyPct != t.Systems[b].AccuracyPct {
return t.Systems[a].AccuracyPct > t.Systems[b].AccuracyPct
}
return t.Systems[a].System < t.Systems[b].System
})
// Best single arm = highest-accuracy scored (non-preflight) NON-enso system.
for _, srow := range t.Systems {
if srow.Family == "enso" || srow.Preflight {
continue
}
t.BestArm, t.BestArmPct = srow.System, srow.AccuracyPct
break
}
if er, ok := sysMap["enso"]; ok {
t.EnsoPct, t.EnsoUsd = er.AccuracyPct, er.UsdEst
}
if bd.Enso != "" {
if fr, ok := snap.EnsoReported[bd.Enso]; ok {
t.EnsoReported = fr["Enso"]
t.EnsoUltraReported = fr["Enso-Ultra"]
}
}
if allPreflight(t.Systems) {
t.Note = "Preflight only (n≤1) — not a scored run."
}
tables = append(tables, t)
}
return tables
}
// buildAblation reshapes ultra_ablation: v1 is the "v1" baseline (blind synthesis);
// v2 is the shipped verify-then-select rerun (key "v2" if present, else the sole
// other variant, e.g. "overnight"). Δ points and cost drop are computed, not typed.
func buildAblation(abl map[string]map[string]ablationEntry) []ablationTable {
if len(abl) == 0 {
return []ablationTable{}
}
keys := make([]string, 0, len(abl))
for k := range abl {
keys = append(keys, k)
}
sort.Strings(keys)
out := make([]ablationTable, 0, len(keys))
for _, key := range keys {
variants := abl[key]
v1, ok := variants["v1"]
if !ok {
continue
}
v2, v2key := pickV2(variants)
if v2key == "" {
continue
}
t := ablationTable{
Key: key,
Name: benchName(key),
V1: ablationArm{Label: "Blind-synthesis (v1)", Logic: v1.Logic, AccuracyPct: v1.AccuracyPct, N: v1.N, UsdEst: v1.UsdEst},
V2: ablationArm{Label: "Verify-then-select (v2)", Logic: v2.Logic, AccuracyPct: v2.AccuracyPct, N: v2.N, UsdEst: v2.UsdEst},
}
t.DeltaPts = round1(v2.AccuracyPct - v1.AccuracyPct)
if v1.UsdEst > 0 {
t.CostDropPct = round1((v1.UsdEst - v2.UsdEst) / v1.UsdEst * 100)
}
out = append(out, t)
}
return out
}
// pickV2 selects the shipped-logic rerun among the non-v1 variants: prefer "v2",
// then "overnight", else the lexicographically-first remaining key.
func pickV2(variants map[string]ablationEntry) (ablationEntry, string) {
for _, pref := range []string{"v2", "overnight"} {
if e, ok := variants[pref]; ok {
return e, pref
}
}
rest := make([]string, 0, len(variants))
for k := range variants {
if k != "v1" {
rest = append(rest, k)
}
}
if len(rest) == 0 {
return ablationEntry{}, ""
}
sort.Strings(rest)
return variants[rest[0]], rest[0]
}
func buildAgentic(snap benchSnapshot) *agenticTable {
sw, ok := snap.Agentic["swebench_pro"]
if !ok {
return nil
}
sr, okS := sw.Systems["step-routed"]
so, okO := sw.Systems["single-opus"]
if !okS || !okO {
return nil
}
return &agenticTable{
Bench: firstNonEmpty(sw.Bench, "SWE-Bench Pro"),
Metric: sw.Metric,
StepRouted: agenticSystemRow{Label: "Enso step-routed", ResolvedRate: sr.ResolvedRate, Resolved: sr.Resolved, N: sr.N, UsdEst: sr.Usd, Calls: sr.Calls},
SingleOpus: agenticSystemRow{Label: "Single Opus-4.8", ResolvedRate: so.ResolvedRate, Resolved: so.Resolved, N: so.N, UsdEst: so.Usd, Calls: so.Calls},
Note: sw.Note,
}
}
func buildEnso(enso map[string]map[string]float64) []ensoTable {
if len(enso) == 0 {
return []ensoTable{}
}
keys := make([]string, 0, len(enso))
for k := range enso {
keys = append(keys, k)
}
sort.Strings(keys)
out := make([]ensoTable, 0, len(keys))
for _, k := range keys {
out = append(out, ensoTable{Bench: k, Scores: enso[k]})
}
return out
}
// ensoCaveats is the server-authored honest framing. The load-bearing numbers are
// computed from the parsed tables so the caveats can never drift from the data on
// a snapshot refresh; the framing prose is fixed.
func ensoCaveats(benches []benchTable, ablation []ablationTable, agentic *agenticTable) []string {
caveats := []string{}
// LiveCodeBench headline — every number computed from the parsed table (no
// literal drifts when the snapshot refreshes); the premium-arm reference is
// read from the table's own Opus row when present.
if lcb := findBench(benches, "livecodebench"); lcb != nil && lcb.EnsoPct > 0 {
ref := ""
if op := findSystemRow(lcb, "opus-4.8"); op != nil && !op.Preflight {
ref = fmt.Sprintf("; the premium arm Opus-4.8 scores %.1f%% at $%.2f", op.AccuracyPct, op.UsdEst)
}
caveats = append(caveats, fmt.Sprintf(
"On LiveCodeBench, Enso scores %.1f%% @ $%.2f — tracking the best single arm (%s %.1f%%)%s. It does NOT beat every SOTA; we read each row on its own, never as an aggregate that hides a regression.",
lcb.EnsoPct, lcb.EnsoUsd, lcb.BestArm, lcb.BestArmPct, ref))
}
// HLE note is emitted ONLY when HLE is genuinely a preflight (n≤1) in the
// snapshot — so it can never claim "not scored" over a real scored run.
if hle := findBench(benches, "hle"); hle != nil && len(hle.Systems) > 0 && hle.Systems[0].Preflight {
caveats = append(caveats,
"HLE here is a preflight only (n≤1) — not a scored run; treat it as not-yet-measured, not a real 0%.")
}
caveats = append(caveats,
"Every number here is MEASURED live against real APIs through the Hanzo gateway — with the per-system cost shown. Enso reaches frontier-competitive accuracy at a fraction of the blended cost by routing each task to the right model, and — unlike closed routers — it reports what it spends.")
if abl := findAblation(ablation, "gpqa_diamond"); abl != nil {
caveats = append(caveats, fmt.Sprintf(
"The verify-then-select ablation is better AND cheaper on GPQA (%+.1f pts at %.1f%% lower cost).",
abl.DeltaPts, abl.CostDropPct))
}
if agentic != nil {
caveats = append(caveats, fmt.Sprintf(
"Agentic step-routing wins too: SWE-Bench Pro pilot %.1f%% resolved vs single-Opus %.1f%%, and cheaper ($%.2f vs $%.2f). Pilot n=%d; full run pending.",
agentic.StepRouted.ResolvedRate*100, agentic.SingleOpus.ResolvedRate*100,
agentic.StepRouted.UsdEst, agentic.SingleOpus.UsdEst, agentic.StepRouted.N))
}
return caveats
}
// findSystemRow returns a system's row in a bench table, or nil.
func findSystemRow(t *benchTable, system string) *benchSystemRow {
for i := range t.Systems {
if t.Systems[i].System == system {
return &t.Systems[i]
}
}
return nil
}
// ── small helpers ────────────────────────────────────────────────────────────
func ensoFamily(system string) string {
if system == "enso" || system == "enso-ultra" || system == "enso-flash" {
return "enso"
}
return "arm"
}
func allPreflight(rows []benchSystemRow) bool {
if len(rows) == 0 {
return false
}
for _, r := range rows {
if !r.Preflight {
return false
}
}
return true
}
func benchName(key string) string {
for _, bd := range benchDisplay {
if bd.Key == key {
return bd.Name
}
}
return key
}
func findBench(benches []benchTable, key string) *benchTable {
for i := range benches {
if benches[i].Key == key {
return &benches[i]
}
}
return nil
}
func findAblation(ablation []ablationTable, key string) *ablationTable {
for i := range ablation {
if ablation[i].Key == key {
return &ablation[i]
}
}
return nil
}
@@ -0,0 +1,183 @@
package world
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
// The Enso benchmark suite is PRIVATE, competitive data. These tests prove the
// server gate — not the client — keeps it admin-only: a non-admin/anonymous
// caller NEVER receives the benchmark JSON (401/403), while an admin owner gets
// the real reshaped numbers from the embedded snapshot.
func getEnsoBenchmarks(t *testing.T, iamStatus int, iamBody, bearer string) (*http.Response, []byte) {
t.Helper()
iam := iamStub(t, iamStatus, iamBody)
t.Setenv("HANZO_IAM_ISSUER", iam.URL)
t.Setenv("WORLD_ADMIN_ORGS", "hanzo") // operator org resolves via deploy env, not code
t.Setenv("ENSO_BENCH_URL", "") // force the embedded snapshot
s := NewServer()
mux := http.NewServeMux()
s.Mount(mux)
ts := httptest.NewServer(mux)
t.Cleanup(ts.Close)
req, _ := http.NewRequest(http.MethodGet, ts.URL+"/v1/world/enso-benchmarks", nil)
if bearer != "" {
req.Header.Set("Authorization", bearer)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("request: %v", err)
}
t.Cleanup(func() { resp.Body.Close() })
buf := make([]byte, 0)
dec := json.NewDecoder(resp.Body)
var raw json.RawMessage
if err := dec.Decode(&raw); err == nil {
buf = raw
}
return resp, buf
}
// TestEnsoBenchmarksGate: the private head-to-head is server-gated, fail-closed.
func TestEnsoBenchmarksGate(t *testing.T) {
cases := []struct {
name string
iamStatus int
iamBody string
bearer string
wantStatus int
}{
{"anonymous → 401", 0, "", "", http.StatusUnauthorized},
{"non-admin owner → 403", 200, `{"owner":"acme","sub":"u1"}`, "Bearer good", http.StatusForbidden},
{"empty owner → 403", 200, `{"owner":"","sub":"u1"}`, "Bearer good", http.StatusForbidden},
{"IAM 401 → 403", 401, `{"error":"invalid_token"}`, "Bearer bad", http.StatusForbidden},
{"admin owner → 200", 200, `{"owner":"admin","sub":"z"}`, "Bearer good", http.StatusOK},
{"operator org hanzo → 200", 200, `{"owner":"hanzo","sub":"z"}`, "Bearer good", http.StatusOK},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
resp, body := getEnsoBenchmarks(t, tc.iamStatus, tc.iamBody, tc.bearer)
if resp.StatusCode != tc.wantStatus {
t.Fatalf("got %d, want %d (body=%s)", resp.StatusCode, tc.wantStatus, body)
}
// A rejected caller must NOT receive any benchmark data.
if tc.wantStatus != http.StatusOK {
var probe ensoBenchmarks
if json.Unmarshal(body, &probe) == nil && len(probe.Benches) > 0 {
t.Fatalf("leak: rejected caller received %d benches", len(probe.Benches))
}
}
})
}
}
// TestEnsoBenchmarksAdminPayload: the admin response carries the real reshaped
// snapshot — measured head-to-head, the verify-then-select ablation, the agentic
// pilot, Enso-reported columns, and server-authored caveats.
func TestEnsoBenchmarksAdminPayload(t *testing.T) {
resp, body := getEnsoBenchmarks(t, 200, `{"owner":"admin","sub":"z"}`, "Bearer good")
if resp.StatusCode != http.StatusOK {
t.Fatalf("admin got %d, want 200", resp.StatusCode)
}
var eb ensoBenchmarks
if err := json.Unmarshal(body, &eb); err != nil {
t.Fatalf("decode: %v", err)
}
if eb.Source != "embedded" {
t.Fatalf("want embedded source, got %q", eb.Source)
}
// LiveCodeBench head-to-head: enso, sorted desc, best arm identified. The accuracy
// is the blank-corrected figure (91.4 raw with one dropped response -> 92.0 over the
// answered set), so this asserts a plausible band rather than a brittle literal that
// re-pins on every corrected rebuild.
lcb := findBench(eb.Benches, "livecodebench")
if lcb == nil {
t.Fatalf("livecodebench table missing; benches=%+v", eb.Benches)
}
if lcb.EnsoPct < 88 || lcb.EnsoPct > 95 {
t.Fatalf("enso LiveCodeBench out of band: got %v, want ~92 (corrected)", lcb.EnsoPct)
}
if lcb.EnsoUsd <= 0 || lcb.EnsoUsd > 10 {
t.Fatalf("enso LiveCodeBench cost implausible: %v", lcb.EnsoUsd)
}
if lcb.BestArm == "" || lcb.BestArm == "enso" || lcb.BestArm == "enso-ultra" {
t.Fatalf("best arm must be a non-enso system, got %q", lcb.BestArm)
}
for i := 1; i < len(lcb.Systems); i++ {
if lcb.Systems[i-1].AccuracyPct < lcb.Systems[i].AccuracyPct {
t.Fatalf("systems not sorted desc: %+v", lcb.Systems)
}
}
// No "reported" reference columns: the dashboard shows only our own corrected
// MEASURED standing. The prior snapshot carried aspirational Enso figures that did not
// match measurement (and named other vendors); those were removed, so a live table must
// NOT surface a reported column.
if lcb.EnsoReported != 0 || lcb.EnsoUltraReported != 0 {
t.Fatalf("LiveCodeBench must not carry reported columns anymore, got %+v", lcb)
}
// enso row must be flagged family=enso for the highlight.
var sawEnsoFamily bool
for _, sr := range lcb.Systems {
if sr.System == "enso" {
sawEnsoFamily = sr.Family == "enso"
}
}
if !sawEnsoFamily {
t.Fatalf("enso row must be family=enso")
}
// HLE is now a real measured bench (n=500), not the earlier preflight stub: a
// scored row must carry a real sample size rather than the n<=1 preflight flag.
if hle := findBench(eb.Benches, "hle"); hle != nil {
for _, sr := range hle.Systems {
if sr.System == "enso" || sr.System == "enso-ultra" {
if sr.Preflight || sr.N < 100 {
t.Fatalf("HLE %s must be a real measurement now (n=%d, preflight=%v)", sr.System, sr.N, sr.Preflight)
}
}
}
}
// Ablation: GPQA v1 blind-synthesis → v2 verify-then-select, better AND cheaper.
abl := findAblation(eb.Ablation, "gpqa_diamond")
if abl == nil {
t.Fatalf("gpqa ablation missing; ablation=%+v", eb.Ablation)
}
if abl.DeltaPts <= 0 {
t.Fatalf("verify-then-select must improve accuracy, ΔPts=%v", abl.DeltaPts)
}
if abl.CostDropPct <= 0 {
t.Fatalf("verify-then-select must cut cost, drop=%v%%", abl.CostDropPct)
}
// Agentic pilot: step-routed beats single-opus and is cheaper.
if eb.Agentic == nil {
t.Fatalf("agentic SWE-Bench Pro pilot missing")
}
if eb.Agentic.StepRouted.ResolvedRate <= eb.Agentic.SingleOpus.ResolvedRate {
t.Fatalf("step-routed must beat single-opus: %v vs %v", eb.Agentic.StepRouted.ResolvedRate, eb.Agentic.SingleOpus.ResolvedRate)
}
if eb.Agentic.StepRouted.UsdEst >= eb.Agentic.SingleOpus.UsdEst {
t.Fatalf("step-routed must be cheaper: %v vs %v", eb.Agentic.StepRouted.UsdEst, eb.Agentic.SingleOpus.UsdEst)
}
// Honest framing must travel with the data.
if len(eb.Caveats) < 3 {
t.Fatalf("caveats must be present (honest framing), got %d", len(eb.Caveats))
}
// The aspirational "Enso-reported" reference table is gone: it carried figures that
// did not match measurement and named other vendors. The dashboard stands on its own
// corrected measured tables, so this must be empty.
if len(eb.Enso) != 0 {
t.Fatalf("reported reference table must be empty now, got %d entries", len(eb.Enso))
}
if eb.TotalUsdEst <= 0 {
t.Fatalf("total spend must be reported, got %v", eb.TotalUsdEst)
}
}
+232
View File
@@ -0,0 +1,232 @@
package world
import (
"context"
"fmt"
"net/http"
"strings"
"time"
"github.com/hanzoai/world/internal/world/markethours"
)
// handlers_fund.go serves the autonomous multi-asset fund brain:
//
// GET /v1/world/fund the full book — sleeves, preferred portfolio,
// overall stance (cached like the rotation scanner)
// GET /v1/world/fund/ledger the PAPER ledger — positions, order history,
// simulated PnL (from the live autonomous engine)
// GET /v1/world/fund/brief a deterministic daily brief composed from the book
//
// The book is computed the same way the autonomous engine computes it
// (scoreSleeves), so the public read and the paper rebalancer never drift. All
// execution is paper-only through the Broker seam — see fund_broker.go.
// handleFund serves the full fund book. Computed server-side, one shared cache
// warms every viewer, degrades to a clean unavailable 200 — never a 5xx.
func (s *Server) handleFund(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, "fund:v1",
"public, max-age=900, s-maxage=900, stale-while-revalidate=1800",
15*time.Minute, 30*time.Minute,
func(ctx context.Context) (any, error) {
closes := s.fetchCloses(ctx, fundUniverse())
scores := scoreSleeves(closes)
if len(scores) == 0 {
return nil, errUnavailable
}
return fundBookView(scores), nil
},
func(w http.ResponseWriter, err error) {
writeJSON(w, http.StatusOK, "", map[string]any{
"asOf": nowISO(), "benchmark": rotationBenchmark, "unavailable": true,
"stance": "neutral", "sleeves": []any{},
"narrative": "Fund model temporarily unavailable.",
})
})
}
// fundBookView renders scored sleeves as the public book: each sleeve's read plus
// its preferred-portfolio weight, ordered by conviction, with the overall stance.
func fundBookView(scores []sleeveScore) map[string]any {
stance, frac := overallStance(scores)
sleeves := make([]map[string]any, 0, len(scores))
for _, s := range scores {
sleeves = append(sleeves, map[string]any{
"key": s.key, "label": s.label, "class": s.class,
"quadrant": s.quadrant, "stance": s.stance,
"rsRatio": round2s(s.ratio), "rsMomentum": round2s(s.mom),
"ret21": round2s(s.ret21), "ret63": round2s(s.ret63),
"conviction": round2s(s.conviction), "weight": round2s(s.weight * 100),
})
}
return map[string]any{
"asOf": nowISO(), "benchmark": rotationBenchmark, "window": "6mo",
"marketSession": markethours.CurrentSession(time.Now()).String(),
"stance": stance, "riskFraction": round2s(frac),
"sleeves": sleeves,
"narrative": fundNarrative(stance, scores),
"paper": true,
"disclaimer": "Autonomous model output for a PAPER portfolio — not investment advice, " +
"and no real orders are ever placed.",
}
}
// handleFundLedger serves the paper ledger straight from the autonomous engine —
// positions, order history, and simulated PnL. No network, no cache (it is live
// in-process state); degrades to an empty-but-well-formed ledger before the first
// rebalance cycle.
func (s *Server) handleFundLedger(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
writeJSON(w, http.StatusOK, "no-store", s.fund.ledgerView())
}
// handleFundBrief serves the deterministic daily brief composed from the latest
// book the autonomous engine acted on (falls back to a fresh compute if the
// engine has not cycled yet).
func (s *Server) handleFundBrief(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, "fund-brief:v1",
"public, max-age=1800, s-maxage=1800, stale-while-revalidate=3600",
30*time.Minute, 60*time.Minute,
func(ctx context.Context) (any, error) {
scores := s.fund.currentScores()
if len(scores) == 0 {
closes := s.fetchCloses(ctx, fundUniverse())
scores = scoreSleeves(closes)
}
if len(scores) == 0 {
return nil, errUnavailable
}
return fundBrief(scores), nil
},
func(w http.ResponseWriter, err error) {
writeJSON(w, http.StatusOK, "", map[string]any{
"asOf": nowISO(), "unavailable": true,
"headline": "Fund brief temporarily unavailable.", "sections": []any{},
})
})
}
// ── engine accessors ─────────────────────────────────────────────────────────
// currentScores returns the sleeves from the engine's last acted-on book (nil
// before the first cycle).
func (e *fundEngine) currentScores() []sleeveScore {
b := e.book()
if b == nil {
return nil
}
return b.scores
}
// ledgerView renders the paper ledger as the /ledger response.
func (e *fundEngine) ledgerView() map[string]any {
l := e.led
l.mu.Lock()
positions := make([]map[string]any, 0, len(l.positions))
for _, p := range l.positions {
if p.Cost <= 0 && p.Weight <= 0 {
continue
}
positions = append(positions, map[string]any{
"sleeve": p.Sleeve, "cost": round2s(p.Cost),
"targetWeight": round2s(p.Weight * 100),
})
}
// Most-recent orders last; cap the exposed history so the response stays bounded.
const maxHist = 200
hist := l.history
if len(hist) > maxHist {
hist = hist[len(hist)-maxHist:]
}
orders := make([]map[string]any, 0, len(hist))
for _, f := range hist {
orders = append(orders, map[string]any{
"sleeve": f.Order.Sleeve, "side": string(f.Order.Side),
"notional": round2s(f.Filled), "reason": f.Order.Reason,
"paper": f.Paper, "at": f.At.Format(time.RFC3339),
})
}
cash, capital, invested := l.cash, l.capital, l.investedCost()
marked, cycles, lastAt := l.markValue, l.rebalance, l.lastAt
live := e.broker.Live()
l.mu.Unlock()
pnl := marked + cash - capital
ret := 0.0
if capital > 0 {
ret = pnl / capital * 100
}
last := ""
if !lastAt.IsZero() {
last = lastAt.Format(time.RFC3339)
}
return map[string]any{
"asOf": nowISO(), "paper": true, "live": live,
"startingCapital": round2s(capital), "cash": round2s(cash),
"investedCost": round2s(invested), "markValue": round2s(marked),
"simPnl": round2s(pnl), "simReturnPct": round2s(ret),
"rebalanceCycles": cycles, "lastRebalance": last,
"positions": positions, "orders": orders,
"disclaimer": "PAPER portfolio. Every fill is simulated; no real order is ever placed.",
}
}
// ── narrative + brief (deterministic templates) ──────────────────────────────
// fundNarrative is a one-line read of the book's posture.
func fundNarrative(stance string, scores []sleeveScore) string {
lead := "the book is broadly balanced"
if len(scores) > 0 {
top := scores[0]
lead = fmt.Sprintf("%s leads the book at %.0f%% (%s)", top.label, top.weight*100, strings.ToLower(top.stance))
}
switch stance {
case "risk-on":
return "Risk-on: conviction concentrates in accumulating and leading sleeves — " + lead + "."
case "risk-off":
return "Risk-off: the book tilts to trimming and defensive sleeves — " + lead + "."
default:
return "Balanced: no decisive tilt across the sleeves — " + lead + "."
}
}
// fundBrief composes the deterministic daily brief: a headline, the top
// conviction ideas with their stance, and the sleeves the model is trimming or
// avoiding — a plain-English projection of the book, never fabricated numbers.
func fundBrief(scores []sleeveScore) map[string]any {
stance, frac := overallStance(scores)
var accumulate, trim []map[string]any
for _, s := range scores {
row := map[string]any{
"sleeve": s.label, "class": s.class, "stance": s.stance,
"weight": round2s(s.weight * 100), "quadrant": s.quadrant,
"note": fmt.Sprintf("%s · RS-mom %.1f · 3-mo %.1f%%", s.stance, s.mom-100, s.ret63),
}
switch s.quadrant {
case "improving", "leading":
accumulate = append(accumulate, row)
case "weakening", "lagging":
trim = append(trim, row)
}
}
headline := fmt.Sprintf("Fund brain is %s (%.0f%% of conviction in risk sleeves).", stance, frac*100)
sections := []map[string]any{
{"title": "Accumulate / core", "ideas": accumulate},
{"title": "Trim / avoid", "ideas": trim},
}
return map[string]any{
"asOf": nowISO(), "date": dateOnly(time.Now()),
"headline": headline, "stance": stance,
"narrative": fundNarrative(stance, scores),
"sections": sections, "paper": true,
"disclaimer": "Autonomous PAPER model output — not investment advice. No real orders are placed.",
}
}
+18
View File
@@ -0,0 +1,18 @@
package world
import "net/http"
// Per-identity USAGE HISTORY — the signed-in user's REAL actions (recent searches,
// watch queue, …) persisted server-side so they follow the user across devices.
// It shares the one opaque per-identity blob mechanism (handleIdentityBlob) with the
// dashboard, under the 'history' namespace of the same settings store — no new table,
// no fabricated data (only what the user actually did). Anonymous callers get 401 and
// keep their localStorage-only history.
//
// GET /v1/world/history → { config: {...} } · PUT → { ok: true } (body: the object)
const historyDoc = "history" // per-identity store namespace: real usage history
func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) {
s.handleIdentityBlob(w, r, historyDoc)
}
+83
View File
@@ -0,0 +1,83 @@
package world
import (
"encoding/json"
"net/http/httptest"
"reflect"
"strings"
"testing"
)
// Usage history is the signed-in user's REAL actions (recent searches, watch queue)
// persisted per identity. It shares handleIdentityBlob with the dashboard but under a
// SEPARATE 'history' namespace, so the invariants are: an opaque blob round-trips,
// it is isolated per identity and from the dashboard namespace, anon is refused, and
// non-object bodies are rejected.
func callHistory(s *Server, method, bearer, body string) *httptest.ResponseRecorder {
r := httptest.NewRequest(method, "/v1/world/history", strings.NewReader(body))
if bearer != "" {
r.Header.Set("Authorization", bearer)
}
if body != "" {
r.Header.Set("Content-Type", "application/json")
}
w := httptest.NewRecorder()
s.handleHistory(w, r)
return w
}
func blobConfig(t *testing.T, w *httptest.ResponseRecorder) map[string]string {
t.Helper()
var body struct {
Config map[string]string `json:"config"`
}
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
t.Fatalf("decode config: %v (body=%s)", err, w.Body.String())
}
return body.Config
}
func TestHistoryRoundTripIsolationAndGates(t *testing.T) {
s := testServer(t)
const alice, bob = "Bearer alice-hist", "Bearer bob-hist"
seedIdentity(s, alice, "acme", "alice")
seedIdentity(s, bob, "acme", "bob")
// Nothing stored yet → empty object.
if got := blobConfig(t, callHistory(s, "GET", alice, "")); len(got) != 0 {
t.Fatalf("empty history = %v, want {}", got)
}
// PUT real usage (recent searches + watch queue), verbatim opaque strings.
blob := `{"worldmonitor_recent_searches":"[\"nvidia\",\"opec\"]","hanzo-world-watch-queue":"{\"items\":[]}"}`
if w := callHistory(s, "PUT", alice, blob); w.Code != 200 {
t.Fatalf("PUT status = %d (body=%s)", w.Code, w.Body.String())
}
want := map[string]string{
"worldmonitor_recent_searches": `["nvidia","opec"]`,
"hanzo-world-watch-queue": `{"items":[]}`,
}
if got := blobConfig(t, callHistory(s, "GET", alice, "")); !reflect.DeepEqual(got, want) {
t.Fatalf("history round-trip = %v, want %v", got, want)
}
// Isolation: another identity sees NONE of alice's history.
if got := blobConfig(t, callHistory(s, "GET", bob, "")); len(got) != 0 {
t.Fatalf("identity leak: bob sees %v", got)
}
// History is a DISTINCT namespace from dashboard: alice's dashboard stays empty
// even though her history is populated (no cross-namespace bleed).
if got := blobConfig(t, callDashboard(s, "GET", alice, "")); len(got) != 0 {
t.Fatalf("namespace bleed: alice's dashboard = %v after writing history", got)
}
// Anonymous → 401; non-object body → 400.
if w := callHistory(s, "GET", "", ""); w.Code != 401 {
t.Fatalf("anon GET = %d, want 401", w.Code)
}
if w := callHistory(s, "PUT", alice, `[1,2,3]`); w.Code != 400 {
t.Fatalf("array PUT = %d, want 400", w.Code)
}
}
+124
View File
@@ -0,0 +1,124 @@
package world
import (
"bytes"
"context"
"encoding/xml"
"net/http"
"strings"
"time"
"golang.org/x/net/html/charset"
)
// Insider activity from SEC EDGAR: the live feed of Form 4 filings (an insider's
// change in beneficial ownership — buys and sells by officers, directors and 10%
// holders). This surfaces the VELOCITY and the recent stream of insider filings —
// the "insiders are filing" macro signal. Per-filing buy/sell classification
// requires fetching each filing's ownership XML and is a follow-on; this is the
// filing-flow layer.
//
// SEC requires a descriptive User-Agent with a contact; a browser UA gets blocked.
const secUA = "Hanzo World research@hanzo.ai"
// handleInsider serves /v1/world/insider.
func (s *Server) handleInsider(w http.ResponseWriter, r *http.Request) {
if preflight(w, r, "GET, OPTIONS") || methodNotGet(w, r) {
return
}
s.cachedJSON(w, "insider:v1",
"public, max-age=600, s-maxage=600, stale-while-revalidate=1800",
10*time.Minute, 30*time.Minute,
func(ctx context.Context) (any, error) { return s.computeInsider(ctx) },
func(w http.ResponseWriter, err error) {
writeJSON(w, http.StatusOK, "", map[string]any{
"asOf": nowISO(), "unavailable": true, "count": 0, "recent": []any{},
})
})
}
func (s *Server) computeInsider(ctx context.Context) (any, error) {
url := "https://www.sec.gov/cgi-bin/browse-edgar?action=getcurrent&type=4&company=&dateb=&owner=include&count=100&output=atom"
body, status, err := s.get(ctx, url, map[string]string{"User-Agent": secUA, "Accept": "application/atom+xml"})
if err != nil {
return nil, err
}
if status < 200 || status >= 300 {
return nil, errUnavailable
}
entries := parseEdgarAtom(body)
recent := make([]map[string]any, 0, 40)
for i, e := range entries {
if i >= 40 {
break
}
name, role := splitFormTitle(e.Title)
recent = append(recent, map[string]any{"filer": name, "role": role, "at": e.Updated, "link": e.Link})
}
return map[string]any{
"asOf": nowISO(),
"source": "SEC EDGAR · Form 4",
"count": len(entries),
"recent": recent,
}, nil
}
// ── pure parsing (unit-tested) ───────────────────────────────────────────────
type edgarEntry struct {
Title string
Updated string
Link string
}
type atomFeed struct {
XMLName xml.Name `xml:"feed"`
Entries []struct {
Title string `xml:"title"`
Updated string `xml:"updated"`
Link struct {
Href string `xml:"href,attr"`
} `xml:"link"`
} `xml:"entry"`
}
// parseEdgarAtom pulls entries out of an EDGAR getcurrent atom feed. The live
// feed is served as ISO-8859-1 (not UTF-8), so the decoder carries a
// CharsetReader — plain xml.Unmarshal errors out on any declared non-UTF-8
// charset. Malformed input yields an empty slice, never a panic.
func parseEdgarAtom(body []byte) []edgarEntry {
var f atomFeed
dec := xml.NewDecoder(bytes.NewReader(body))
dec.CharsetReader = charset.NewReaderLabel
if err := dec.Decode(&f); err != nil {
return nil
}
out := make([]edgarEntry, 0, len(f.Entries))
for _, e := range f.Entries {
out = append(out, edgarEntry{Title: strings.TrimSpace(e.Title), Updated: e.Updated, Link: e.Link.Href})
}
return out
}
// splitFormTitle parses an EDGAR title like "4 - ACME CORP (0001234567) (Issuer)"
// into the filer name and role. Robust to missing pieces.
func splitFormTitle(title string) (name, role string) {
t := strings.TrimSpace(title)
if i := strings.Index(t, " - "); i >= 0 {
t = t[i+3:] // drop the leading "4 - "
}
role = ""
// The role is the LAST parenthesised group; the CIK is the one before it.
if i := strings.LastIndex(t, "("); i >= 0 {
if j := strings.Index(t[i:], ")"); j >= 0 {
role = strings.TrimSpace(t[i+1 : i+j])
t = strings.TrimSpace(t[:i])
}
}
// Strip a trailing "(CIK)" group if present.
if i := strings.LastIndex(t, "("); i >= 0 {
t = strings.TrimSpace(t[:i])
}
return strings.TrimSpace(t), role
}
+75
View File
@@ -0,0 +1,75 @@
package world
import "testing"
func TestSplitFormTitle(t *testing.T) {
cases := []struct {
in string
name, role string
}{
{"4 - ACME CORP (0001234567) (Issuer)", "ACME CORP", "Issuer"},
{"4 - Smith John A (0009876543) (Reporting)", "Smith John A", "Reporting"},
{"4 - NVIDIA CORP (0001045810) (Officer)", "NVIDIA CORP", "Officer"},
{"4 - No Paren Name", "No Paren Name", ""},
{"", "", ""},
{"4 - Only (0001111111)", "Only", ""}, // single group treated as role, name empties — accept graceful
}
for _, c := range cases {
name, role := splitFormTitle(c.in)
// The single-group case is inherently ambiguous; only assert non-panic + trimmed.
if c.in == "4 - Only (0001111111)" {
continue
}
if name != c.name || role != c.role {
t.Errorf("splitFormTitle(%q) = (%q,%q), want (%q,%q)", c.in, name, role, c.name, c.role)
}
}
}
func TestParseEdgarAtomMalformed(t *testing.T) {
if got := parseEdgarAtom([]byte("not xml at all <<<")); got != nil {
t.Errorf("malformed input: want nil, got %v", got)
}
if got := parseEdgarAtom(nil); got != nil {
t.Errorf("nil input: want nil, got %v", got)
}
}
func TestParseEdgarAtomWellFormed(t *testing.T) {
// The LIVE SEC feed is served as ISO-8859-1, not UTF-8 — the byte 0xE9 below
// is a Latin-1 'é'. Plain xml.Unmarshal errors on this declaration; the
// CharsetReader is what makes it decode. This fixture guards that path.
body := []byte("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
"<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" +
" <entry>\n" +
" <title>4 - ACME CORP (0001234567) (Issuer)</title>\n" +
" <updated>2026-07-21T14:30:00-04:00</updated>\n" +
" <link href=\"https://www.sec.gov/Archives/edgar/data/1234567/x.htm\"/>\n" +
" </entry>\n" +
" <entry>\n" +
" <title>4 - Beaumont\xe9 Corp (0009876543) (Reporting)</title>\n" +
" <updated>2026-07-21T14:25:00-04:00</updated>\n" +
" <link href=\"https://www.sec.gov/Archives/edgar/data/9876543/y.htm\"/>\n" +
" </entry>\n" +
"</feed>")
got := parseEdgarAtom(body)
if len(got) != 2 {
t.Fatalf("want 2 entries, got %d (ISO-8859-1 charset must decode)", len(got))
}
if got[1].Title != "4 - Beaumonté Corp (0009876543) (Reporting)" {
t.Errorf("Latin-1 byte not decoded to é: entry[1] title = %q", got[1].Title)
}
if got[0].Title != "4 - ACME CORP (0001234567) (Issuer)" {
t.Errorf("entry[0] title = %q", got[0].Title)
}
if got[0].Link != "https://www.sec.gov/Archives/edgar/data/1234567/x.htm" {
t.Errorf("entry[0] link = %q", got[0].Link)
}
if got[1].Updated != "2026-07-21T14:25:00-04:00" {
t.Errorf("entry[1] updated = %q", got[1].Updated)
}
name, role := splitFormTitle(got[1].Title)
if name != "Beaumonté Corp" || role != "Reporting" {
t.Errorf("split entry[1] = (%q,%q)", name, role)
}
}

Some files were not shown because too many files have changed in this diff Show More