Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat: refine worker state management and leaderboard ranking logic

nirholas53c314aade55
diff --git a/api/_lib/agora-task-live.js b/api/_lib/agora-task-live.js
index d98a3c888..3282ef7bf 100644
--- a/api/_lib/agora-task-live.js
+++ b/api/_lib/agora-task-live.js
@@ -15,10 +15,11 @@
// and a Guild share is the escrow-measured figure the engine projected. Nothing is
// fabricated: no roster entry, no winner, no split is invented here.
-// Per-worker state, highest precedence first. A worker that completed with the
-// `won` outcome is the Arena winner; `contributed` is a Guild part landed; a
-// `stood_down` row is a racer that lost; a bare claim is still working.
-export const WORKER_STATES = ['won', 'contributed', 'completed', 'lost', 'working', 'engaged'];
+// Per-worker state, highest precedence first (leaderboard order). A worker that
+// completed with the `won` outcome is the Arena winner; `contributed` is a Guild
+// part landed; a bare claim is still `working`; a `stood_down` racer `lost` and
+// sinks to the bottom — it's out of the race even though it did the work.
+export const WORKER_STATES = ['won', 'contributed', 'completed', 'working', 'engaged', 'lost'];
/** Reduce one citizen's rows for a task into their live state. */
export function deriveWorkerState(rows) {
diff --git a/src/agora/citizen-avatar.js b/src/agora/citizen-avatar.js
index 0e661b88c..8d74c8b52 100644
--- a/src/agora/citizen-avatar.js
+++ b/src/agora/citizen-avatar.js
@@ -82,9 +82,16 @@ function buildLabelSprite(name, profession, accent) {
const padX = 22, nameSize = 34, profSize = 22, gap = 8;
const font = (px, w) => `${w} ${px}px Inter, system-ui, sans-serif`;
+ // Clamp a pathologically long display name so its billboard can't dominate the
+ // square (the 3D sprite has no CSS ellipsis to fall back on). Truncate to a
+ // sane width with an ellipsis; the full name still shows in the passport.
+ const MAX_NAME = 24;
+ const raw = String(name ?? 'Citizen');
+ const shown = raw.length > MAX_NAME ? `${raw.slice(0, MAX_NAME - 1)}…` : raw;
+
const measure = document.createElement('canvas').getContext('2d');
measure.font = font(nameSize, 700);
- const nameW = measure.measureText(name).width;
+ const nameW = measure.measureText(shown).width;
const profText = (profession || 'Citizen').toUpperCase();
measure.font = font(profSize, 600);
const profW = measure.measureText(profText).width;
diff --git a/src/agora/passport-panel.js b/src/agora/passport-panel.js
index 7434652fc..3b1eea665 100644
--- a/src/agora/passport-panel.js
+++ b/src/agora/passport-panel.js
@@ -381,7 +381,9 @@ export class PassportPanel {
}
_trapTab(e) {
- const items = [...this._el.querySelectorAll('a[href],button:not([disabled]),[tabindex]:not([tabindex="-1"])')].filter((n) => n.offsetParent !== null);
+ // getClientRects() is fixed-safe (offsetParent can be null for visible
+ // children inside a position:fixed panel in some engines).
+ const items = [...this._el.querySelectorAll('a[href],button:not([disabled]),[tabindex]:not([tabindex="-1"])')].filter((n) => n === document.activeElement || n.getClientRects().length > 0);
if (!items.length) return;
const first = items[0];
const last = items[items.length - 1];
diff --git a/src/agora/task-progress.js b/src/agora/task-progress.js
index 7e64cabce..739c3b6e8 100644
--- a/src/agora/task-progress.js
+++ b/src/agora/task-progress.js
@@ -42,17 +42,20 @@ export function stateLabel(state, { arena = false } = {}) {
}
}
-// Ordering for the leaderboard / roster HUD: furthest-along first, ties broken by
-// claim time (earlier claim ranks higher — it's been in the race longer). The API
-// already sorts by state precedence; this is the same order, re-derivable client-side
-// so the HUD can re-rank live without a round-trip.
+// Leaderboard rank by state: winners/contributors on top, then those still working,
+// and a stood-down racer sinks to the bottom (it's out of the race even though its
+// frozen track position sits mid-course). This is the same order the API's roster
+// uses, re-derivable client-side so the HUD can re-rank live without a round-trip.
+const STATE_RANK = { won: 6, contributed: 5, completed: 5, working: 3, engaged: 2, lost: 1 };
+
export function rankRoster(roster) {
return [...(roster || [])].sort((a, b) => {
- const pa = stateProgress(a.state);
- const pb = stateProgress(b.state);
- if (pb !== pa) return pb - pa;
- // Won always outranks a same-progress non-winner.
+ const ra = STATE_RANK[a.state] ?? 0;
+ const rb = STATE_RANK[b.state] ?? 0;
+ if (rb !== ra) return rb - ra;
+ // Won always outranks a same-rank non-winner.
if (a.won !== b.won) return a.won ? -1 : 1;
+ // Ties broken by claim time — the earlier claim has been in it longer.
return String(a.claimedAt || '').localeCompare(String(b.claimedAt || ''));
});
}