Files
hyperframes/scripts/check-core-skills.mjs
T
Miguel Ángel 7f54fded08 fix(skills): ask before usage notes and destroy, and keep media downloads on public hosts (#8555)
* fix(skills): ask before usage notes and destroy, and keep media downloads on public hosts

Media downloads now connect only to an address the host name resolved to after checking it is public; a name that points at a private address is refused before connecting. Skills tell the person once before sending usage notes and honour a no; a catalog gap report no longer carries the search text. Reverse says plainly it needs a HyperFrames Pro sign-in, and cloudrun/lambda destroy wait for the person's yes.

* fix(media-use): give each media download its own connection

* chore(skills): refresh the skills manifest and split out the gap report step
2026-11-23 07:12:36 +00:00

136 lines
5.7 KiB
JavaScript

#!/usr/bin/env node
// Holds the core skills to their size budgets and checks what their entry files name: every
// `npx hyperframes <command>` against the commands packages/cli/src/cli.ts registers, and every
// path in backticks against the skill folder it is relative to.
import { existsSync, readFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
// Every installed skill's description is listed on every turn; an entry is read in full when it opens.
export const DESCRIPTION_MAX = 320;
// Each budget carries +256 B for the usage note line (`beaconProblems`) and +160 B for the line
// that has every CLI command run through the launcher (`launcherProblems`).
export const CORE_SKILLS = {
// +128 B for the routing rows to the video rebuilds and to a reference's style, which only trigger when the entry hands them on.
// +64 B for the lane pointer to format.md.
hyperframes: 7776,
// +256 B for the `_meta.updateNotice` line: the agent relays it, the person updates.
// +256 B for the unattended pointer: a script or CI job with no TTY pins the release.
// +64 B for the rating line naming the person's no to usage notes.
"hyperframes-cli": 8160,
"hyperframes-registry": 5536,
"media-use": 5536,
figma: 7584,
slideshow: 5536,
"remotion-to-hyperframes": 5536,
"reverse-any-video": 5536,
"style-sampling": 5536,
};
/** @param {string} skill */
const skillFile = (skill, root = REPO_ROOT) => join(root, "skills", skill, "SKILL.md");
/** @param {string} content */
export function descriptionOf(content) {
const frontmatter = /^---\n([\s\S]*?)\n---/.exec(content)?.[1] ?? "";
return /^description:[ \t]*(.*)$/m.exec(frontmatter)?.[1].trim() ?? "";
}
/** The top-level command names the CLI registers. @param {string} cliSource */
export function registeredCommands(cliSource) {
const block = /const commandLoaders = \{([\s\S]*?)\n\};/.exec(cliSource)?.[1] ?? "";
return new Set([...block.matchAll(/^\s+"?([a-z][a-z-]*)"?:/gm)].map((m) => m[1]));
}
/** @param {string} content @param {Set<string>} commands */
export function unknownCommands(content, commands) {
const named = [...content.matchAll(/npx hyperframes(?:@[\w.]+)? ([a-z][a-z-]*)/g)].map(
(m) => m[1],
);
return [...new Set(named)].filter((name) => !commands.has(name));
}
// A backtick span that is a relative path to a file this skill ships, such as one under references/.
const PATH_SPAN = /`((?:\.\.\/)*[a-z0-9][\w.-]*(?:\/[\w.-]+)+\.(?:md|html|json))(?:#[^`]*)?`/g;
/** @param {string} content @param {string} skillDir */
export function missingPaths(content, skillDir) {
const paths = [...content.matchAll(PATH_SPAN)].map((m) => m[1]);
return [...new Set(paths)].filter((p) => !p.includes("<") && !existsSync(join(skillDir, p)));
}
/** Size problems: the entry over its budget, the description over the per-skill cap. */
function sizeProblems(skill, content, maxBytes) {
const bytes = Buffer.byteLength(content);
const description = Buffer.byteLength(descriptionOf(content));
return [
...(maxBytes !== null && bytes > maxBytes
? [`${skill}/SKILL.md is ${bytes} B, over its ${maxBytes} B budget`]
: []),
...(description > DESCRIPTION_MAX
? [`${skill} description is ${description} B, over ${DESCRIPTION_MAX} B`]
: []),
];
}
/** Names the entry teaches that do not exist: CLI commands and shipped paths. */
function nameProblems(skill, content, skillDir, commands) {
return [
...unknownCommands(content, commands).map(
(name) =>
`${skill}/SKILL.md names \`npx hyperframes ${name}\`, which the CLI does not register`,
),
...missingPaths(content, skillDir).map(
(path) => `${skill}/SKILL.md points at \`${path}\`, which does not exist`,
),
];
}
/** The skill's own `skill_invoked` beacon, so every run of it is counted by name. */
export const beaconCommand = (skill) => `npx hyperframes events --skill=${skill}\``;
/** @param {string} skill @param {string} content */
export function beaconProblems(skill, content) {
return content.includes(beaconCommand(skill))
? []
: [`${skill}/SKILL.md does not run \`npx hyperframes events --skill=${skill}\` as it starts`];
}
/** The line that has the skill run every CLI command through the launcher, never a project's npx. */
export const LAUNCHER_LINE = "means `node <SKILLS>/hyperframes/scripts/plugin-cli.mjs <command>`";
/** @param {string} skill @param {string} content */
export function launcherProblems(skill, content) {
const beacon = content.indexOf(beaconCommand(skill));
const launcher = content.indexOf(LAUNCHER_LINE);
return launcher !== -1 && (beacon === -1 || launcher < beacon)
? []
: [`${skill}/SKILL.md does not run the CLI through the launcher before its beacon`];
}
/** @param {string} root */
export function checkCoreSkills(root = REPO_ROOT) {
const commands = registeredCommands(readFileSync(join(root, "packages/cli/src/cli.ts"), "utf8"));
return Object.entries(CORE_SKILLS).flatMap(([skill, maxBytes]) => {
const file = skillFile(skill, root);
const content = readFileSync(file, "utf8");
const names = maxBytes === null ? [] : nameProblems(skill, content, dirname(file), commands);
return [
...sizeProblems(skill, content, maxBytes),
...names,
...beaconProblems(skill, content),
...launcherProblems(skill, content),
];
});
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const problems = checkCoreSkills();
for (const problem of problems) console.error(`✗ ${problem}`);
if (problems.length > 0) process.exit(1);
console.log(`✓ core skills within budget; commands and paths resolve`);
}