Files
skills/orchestrator/templates/page-account-bar.js
T
Kevin Veen-BirkenbachandClaude Opus 5.5 f356083a24 feat(orchestrator): hub requirements 066 to 082 and 084
Radio footer, rules page, schedules editor (System timers and Claude
tasks through signed runner jobs), account usage bar, usage explorer
with a streamed usage.jsonl, queue Controls tab and override, running
tasks on the board, stale task prune with the generic dial, greyed card
stamps, commit-tree diffs from the runner preview, VS Code path links,
expired asks and decisions that stay as EXPIRED cards (asks keyed by a
call digest; an async PostToolUse hook closes those answered in the
terminal), the Match refresh hourglass, attachments by paste, drop and
paperclip in every text field (page CSP gains img-src blob: for the
thumbnails) and the limits board with profiles and a passkey to loosen.
Fixes: one red accept on a red-gate commit and no release while a risk
is open, the send bar footer segments share one height, the mic button
survives a redraw, new Match cards queue before the release card.

E2E specs were still running at commit time (operator order); their
failures follow as separate fixes.

🎯 Fix: 88 %
💥 Break: 8 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 81
🚦 Gate: ⛔ fix 88 % < 90, break 8 % > 5 (committed on the operator's word)

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 19:05:38 +00:00

121 lines
5.2 KiB
JavaScript

const USAGE_DELAY = 400;
const USAGE_STEPS = {ArrowRight: 1, ArrowUp: 1, ArrowLeft: -1, ArrowDown: -1, PageUp: 10, PageDown: -10};
const usageTenth = (value) => Math.round(value * 10) / 10;
const usageClamp = (value) => Math.min(100, Math.max(0, value));
let usageSaved = Promise.resolve();
function forecastToggle() {
const toggle = h("button", {type: "button", class: "btn small soft acc-switch", "data-forecast-toggle": "", "aria-pressed": String(settings.forecast),
...named("Auto forecast", "Auto forecast: mark the share each account reaches at its reset if the tokens of the last 24 hours keep their rate")}, icon("bi-graph-up-arrow"), h("span", {}, "Auto forecast"));
toggle.addEventListener("click", async () => {
if (await saveSettings({...settings, forecast: !settings.forecast})) {
drawAccounts();
}
});
accountsView.toggle = toggle;
return toggle;
}
function dayTime(ms) {
const at = new Date(ms);
return momentText({day: at.getDay(), time: `${String(at.getHours()).padStart(2, "0")}:${String(at.getMinutes()).padStart(2, "0")}`});
}
function forecastMark(row, now) {
if (!settings.forecast || row.account.limit <= 0) {
return null;
}
const expected = UsageBar.forecast(row.account.limit, row.entry, row.bar.share, now, row.next);
const hint = expected.full === null ? `${Math.round(expected.share)} % expected at the reset, ${dayTime(row.next)}` : `100 % at ${dayTime(expected.full)}`;
const mark = h("span", {class: "acc-forecast", "data-forecast": expected.full === null ? "reset" : "full", title: hint});
mark.style.setProperty("--forecast", `${usageClamp(expected.share)}%`);
return mark;
}
/**
* @param bar - the slider whose share waits to be stored.
* @param id - the account's id.
* @param share - the percent to store.
* @param delay - milliseconds to wait for a further step; each step restarts it.
* Holds the Accounts redraw until the newest calibration of the account is stored, then draws it.
*/
function calibrateLater(bar, id, share, delay) {
const held = accountsView.held.get(id);
if (held) {
window.clearTimeout(held.timer);
}
const mark = {timer: 0};
accountsView.held.set(id, mark);
bar.setAttribute("data-pending", "");
mark.timer = window.setTimeout(() => {
usageSaved = usageSaved.then(async () => {
const result = await sendJson(`/api/accounts/${id}/calibrate`, {share});
if (result.ok && result.data) {
accountsView.data.calibrations[id] = result.data;
} else {
toast("Usage: not calibrated", fail(result), false);
}
if (accountsView.held.get(id) === mark) {
accountsView.held.delete(id);
drawAccounts();
}
});
}, delay);
}
/**
* @param row - an accountRows() row of an account with a limit.
* @param now - epoch milliseconds.
* @returns the usage bar: an ARIA slider whose fill shows the share in its flowing colour; dragging it or the arrows
* (1 %) and Page Up and Down (10 %) calibrate the share to what the provider shows.
*/
function usageBar(row, now) {
const {account} = row;
const mark = forecastMark(row, now);
const bar = h("div", {class: "acc-bar", role: "slider", tabindex: "0", "data-usage": account.id, "aria-label": `Usage of ${account.email}`, "aria-valuemin": "0", "aria-valuemax": "100",
...(row.bar.calibrated ? {"data-calibrated": ""} : {})}, h("span", {class: "acc-fill"}), mark, h("span", {class: "acc-handle"}));
let share = row.bar.share;
const show = (value) => {
share = value;
bar.style.setProperty("--share", `${usageClamp(value)}%`);
bar.style.setProperty("--fill", UsageBar.fillColor(value));
bar.setAttribute("aria-valuenow", String(usageTenth(usageClamp(value))));
bar.setAttribute("aria-valuetext", `${usageTenth(value)} % of ${Resources.compact(account.limit)} tokens${mark ? `; ${mark.title}` : ""}`);
};
const pointed = (event) => {
const box = bar.getBoundingClientRect();
show(usageTenth(usageClamp((100 * (event.clientX - box.left)) / box.width)));
};
const release = () => {
window.removeEventListener("pointermove", pointed);
window.removeEventListener("pointerup", release);
window.removeEventListener("pointercancel", release);
bar.removeAttribute("data-dragging");
calibrateLater(bar, account.id, share, 0);
};
bar.addEventListener("pointerdown", (event) => {
if (event.button !== 0) {
return;
}
event.preventDefault();
bar.focus({preventScroll: true});
bar.setAttribute("data-dragging", "");
accountsView.held.set(account.id, {timer: 0});
pointed(event);
window.addEventListener("pointermove", pointed);
window.addEventListener("pointerup", release);
window.addEventListener("pointercancel", release);
});
bar.addEventListener("keydown", (event) => {
if (!(event.key in USAGE_STEPS)) {
return;
}
event.preventDefault();
event.stopPropagation();
show(usageTenth(usageClamp(usageClamp(share) + USAGE_STEPS[event.key])));
calibrateLater(bar, account.id, share, USAGE_DELAY);
});
show(share);
return bar;
}