Files
skills/orchestrator/templates/page-slash.js
T
Kevin Veen-BirkenbachandClaude Opus 5.5 2722cda1b5 feat(hub): requirements 023 to 031 and line comments on grant-time code
023 box heads: one head band per box under its top border; in widget mode
its controls join the widget title band.
024 Match card content: merge cards show their diff (the runner previews a
review's tree against its worktree HEAD), every card carries legal and
architecture scores, the null under command cards is gone.
025 Radio speak card: no hint text, a rounder flowing card, a MAYDAY toggle
beside push to talk.
026 widget zoom: zoom a widget's content by keyboard and the context menu.
027 slash skill suggestions: every field that messages agents suggests
skills after a slash, from a skills index the tree timer writes.
028 Resources accounts: an Accounts panel (provider, renewal, resets, usage
and remaining, host-local, emails never in git) and panel checkboxes.
029 Controls layout: Rules and Groups pages laid out.
030 Yes/No answers as buttons, and nothing hides: rows the runner cannot
run stay greyed with the reason.
031 mic in fields.
Line comments (operator 2026-11-24): wherever code waits for a grant
(Waits on Operator, the stream, the review overlay) selected lines or a
right-clicked row take a comment that marks its lines and collects on the
card; Deny opens with them as the reason and Call preselected, Grant sends
them after the signed grant as one post. Requirement 003 decision 4 and
its contract follow.

Tests are written for every requirement and run once on this head.

🎯 Fix: 80 %
💥 Break: 20 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: ~95 %
🏆 Score: 61
🚦 Gate: ⛔ fix 80 % < 90, break 20 % > 5; security ~95 % < 100: ask the operator before the commit

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 01:22:03 +00:00

143 lines
5.8 KiB
JavaScript

const SLASH_LIMIT = 8;
const SLASH_FRESH = 60000;
const SLASH_FIELDS = "textarea[data-skills], input[data-skills]";
const SLASH_TOKEN = /(^|\s)\/([A-Za-z0-9:_.-]*)$/;
const slash = {skills: [], fetched: 0, loading: null, bound: new WeakSet(), box: null, field: null, shown: [], active: 0, token: null};
/**
* @param {Array<{name: string, description: string, source: string}>} skills the rows /api/skills serves.
* @param {string} prefix what follows the "/", case ignored.
* @param {string} repo the repository the field's agent or card works in, "" for none.
* @returns {Array} at most SLASH_LIMIT rows, one per name: names that start with prefix before names that hold it,
* then the repository's own skills, then by name.
*/
function slashRank(skills, prefix, repo) {
const typed = prefix.toLowerCase();
const hits = skills.map((skill) => ({skill, at: skill.name.toLowerCase().indexOf(typed)})).filter((hit) => hit.at >= 0);
hits.sort((a, b) => Number(a.at !== 0) - Number(b.at !== 0) || Number(b.skill.source === repo) - Number(a.skill.source === repo) || a.skill.name.localeCompare(b.skill.name));
const seen = new Set();
return hits.map((hit) => hit.skill).filter((skill) => !seen.has(skill.name) && Boolean(seen.add(skill.name))).slice(0, SLASH_LIMIT);
}
/**
* @param {string} text the field's value.
* @param {number} caret where the caret stands.
* @returns {Object|null} {start, prefix}: the "/" word the caret ends: a "/" at the start or after
* whitespace, then skill name characters only; null inside a word or a path.
*/
function slashToken(text, caret) {
const found = SLASH_TOKEN.exec(text.slice(0, caret));
return found ? {start: caret - found[2].length - 1, prefix: found[2]} : null;
}
/**
* @returns {Object} {value, caret}: text with the token up to caret replaced by "/<name> ".
*/
function slashInsert(text, token, caret, name) {
const head = `${text.slice(0, token.start)}/${name} `;
return {value: head + text.slice(caret), caret: head.length};
}
function slashLoad() {
if (!slash.loading && Date.now() - slash.fetched > SLASH_FRESH) {
slash.loading = fetch("/api/skills", {cache: "no-store"}).then((response) => (response.ok ? response.json() : {skills: []})).then((data) => {
slash.skills = Array.isArray(data.skills) ? data.skills : [];
slash.fetched = Date.now();
}).catch(() => null).finally(() => {
slash.loading = null;
if (slash.field) {
slashShow(slash.field);
}
});
}
}
function slashClose() {
if (slash.box) {
slash.box.remove();
}
Object.assign(slash, {box: null, field: null, shown: [], active: 0, token: null});
}
function slashPick(field, skill) {
const next = slashInsert(field.value, slash.token, field.selectionStart, skill.name);
field.value = next.value;
field.setSelectionRange(next.caret, next.caret);
field.dispatchEvent(new Event("input", {bubbles: true}));
slashClose();
field.focus();
}
function slashPaint() {
slash.box.replaceChildren(...slash.shown.map((skill, index) => {
const option = h("div", {role: "option", class: "slash-option", id: `slash-option-${index}`, "aria-selected": String(index === slash.active), title: skill.source},
h("strong", {}, `/${skill.name}`), h("span", {class: "muted"}, skill.description));
option.addEventListener("pointerdown", (event) => {
event.preventDefault();
slashPick(slash.field, skill);
});
return option;
}));
slash.field.setAttribute("aria-activedescendant", `slash-option-${slash.active}`);
}
function slashShow(field) {
const token = field.selectionStart === field.selectionEnd ? slashToken(field.value, field.selectionStart) : null;
slashLoad();
const shown = token ? slashRank(slash.skills, token.prefix, field.dataset.skills) : [];
if (!shown.length) {
slashClose();
slash.field = token && slash.loading ? field : null;
return;
}
if (!slash.box || slash.field !== field) {
slashClose();
slash.box = h("div", {class: "slash-list", role: "listbox", "aria-label": "Skills"});
document.body.append(slash.box);
}
const box = field.getBoundingClientRect();
Object.assign(slash, {field, shown, token, active: Math.min(slash.active, shown.length - 1)});
slash.box.style.left = `${Math.max(8, Math.min(box.left, window.innerWidth - 8 - Math.min(448, window.innerWidth - 16)))}px`;
slash.box.style.top = `${box.bottom + 4}px`;
slashPaint();
}
function slashKeys(event, field) {
if (!slash.box || slash.field !== field) {
return;
}
const moves = {ArrowDown: 1, ArrowUp: -1};
if (Object.hasOwn(moves, event.key)) {
slash.active = (slash.active + moves[event.key] + slash.shown.length) % slash.shown.length;
slashPaint();
} else if (event.key === "Enter" || event.key === "Tab") {
slashPick(field, slash.shown[slash.active]);
} else if (event.key === "Escape") {
slashClose();
} else {
return;
}
event.preventDefault();
event.stopPropagation();
}
/**
* @param {HTMLElement} field a text field whose text reaches an agent; data-skills names the repository of its agent or card.
*/
function slashBind(field) {
if (slash.bound.has(field)) {
return;
}
slash.bound.add(field);
field.setAttribute("aria-autocomplete", "list");
field.addEventListener("input", () => slashShow(field));
field.addEventListener("keydown", (event) => slashKeys(event, field));
field.addEventListener("blur", () => window.setTimeout(() => slash.field === field && slashClose(), 0));
}
function slashWatch() {
const sweep = () => document.querySelectorAll(SLASH_FIELDS).forEach(slashBind);
sweep();
new MutationObserver(sweep).observe(document.body, {childList: true, subtree: true});
}