Files
skills/orchestrator/templates/limits.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

87 lines
3.7 KiB
JavaScript

const Limits = (() => {
"use strict";
const METRICS = ["cpu", "ram", "swap", "disk", "psi"];
const LEVELS = ["lower", "upper", "stop", "mayday"];
const TARGETED = ["cpu", "ram"];
const NAMES = {cpu: "CPU", ram: "RAM", swap: "Swap", disk: "Disk", psi: "PSI"};
const LEVEL_NAMES = {lower: "lower", upper: "upper", stop: "STOP", mayday: "MAYDAY"};
const ORDER = "lower < upper < STOP < MAYDAY";
const percent = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 100;
const plain = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
const exactly = (value, keys) => plain(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
/**
* @param limits - a limits object as the page would save it.
* @returns why it is no limits object, the same rules as kvb-org-organize limits.py problem(): exactly METRICS, each
* with exactly LEVELS, every value a percent from 0 to 100, lower < upper < STOP < MAYDAY; null when it is one.
*/
function problem(limits) {
if (!exactly(limits, METRICS)) {
return `the limits are no object of exactly ${METRICS.join(", ")}`;
}
for (const metric of METRICS) {
const levels = limits[metric];
if (!exactly(levels, LEVELS)) {
return `${NAMES[metric]} holds not exactly ${LEVELS.join(", ")}`;
}
const values = LEVELS.map((level) => levels[level]);
if (!values.every(percent)) {
return `${NAMES[metric]} holds a value that is no percent from 0 to 100`;
}
if (!values.every((value, index) => index === 0 || values[index - 1] < value)) {
return `${NAMES[metric]} breaks ${ORDER}: ${values.join(" / ")} %`;
}
}
return null;
}
/**
* @param next - valid limits the page would save.
* @param held - the limits in force, null while the queue config applies.
* @returns every value of next above the one in force as {metric, level, from, to}, from null while none is in
* force: a higher lower or upper admits more load, a higher STOP or MAYDAY raises an alarm threshold, so each needs
* the passkey; an empty list means every value stays or tightens.
*/
function loosened(next, held) {
return METRICS.flatMap((metric) => LEVELS.map((level) => ({metric, level, from: held ? held[metric][level] : null, to: next[metric][level]})))
.filter((change) => change.from === null || change.to > change.from);
}
/**
* @param limits - valid limits.
* @param metric - one of METRICS.
* @param level - one of LEVELS.
* @param value - the new value.
* @returns a copy of limits with only that value changed.
*/
function withValue(limits, metric, level, value) {
return {...limits, [metric]: {...limits[metric], [level]: value}};
}
/**
* @param limits - the limits in force, or null.
* @param profiles - {name: limits} of the hub.
* @returns the name of the profile holding exactly these values, null for none.
*/
function profileOf(limits, profiles) {
if (!limits) {
return null;
}
const found = Object.entries(profiles).find(([, values]) => METRICS.every((metric) => LEVELS.every((level) => values[metric][level] === limits[metric][level])));
return found ? found[0] : null;
}
/**
* @param change - one entry of loosened().
* @returns it as words, like `CPU upper 90 → 95 %`.
*/
function said(change) {
return `${NAMES[change.metric]} ${LEVEL_NAMES[change.level]} ${change.from === null ? "unset" : change.from} → ${change.to} %`;
}
return {METRICS, LEVELS, TARGETED, NAMES, LEVEL_NAMES, ORDER, problem, loosened, withValue, profileOf, said};
})();
if (typeof module === "object" && module.exports) {
module.exports = Limits;
}