Files
hyperframes/packages/cli/src/commands/lint.ts
T
JamesandClaude Opus 4.6 cd15c68a2e feat(cli): add version check system with agent-friendly output
- New `updateCheck.ts` utility: cached npm registry check (24h TTL),
  sync `getUpdateMeta()` for _meta envelope, `printUpdateNotice()` for
  passive stderr banner
- `upgrade --check --json`: machine-readable version check for AI agents
  Returns { current, latest, updateAvailable }
- `_meta` envelope on all --json commands (info, lint, benchmark,
  compositions): includes version, latestVersion, updateAvailable
- `doctor` shows version check as first row
- Passive update notice on stderr after command completes (skipped in
  CI, non-TTY, --json, --quiet)
- Background check fires on startup (non-blocking, populates cache)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 01:41:34 +00:00

48 lines
1.8 KiB
TypeScript

import { defineCommand } from "citty";
import { readFileSync } from "node:fs";
import { lintHyperframeHtml } from "@hyperframes/core/lint";
import { c } from "../ui/colors.js";
import { resolveProject } from "../utils/project.js";
import { withMeta } from "../utils/updateCheck.js";
export default defineCommand({
meta: { name: "lint", description: "Validate a composition for common mistakes" },
args: {
dir: { type: "positional", description: "Project directory", required: false },
json: { type: "boolean", description: "Output findings as JSON", default: false },
},
async run({ args }) {
const project = resolveProject(args.dir);
const html = readFileSync(project.indexPath, "utf-8");
const result = lintHyperframeHtml(html, { filePath: project.indexPath });
if (args.json) {
console.log(JSON.stringify(withMeta(result), null, 2));
process.exit(result.ok ? 0 : 1);
}
console.log(`${c.accent("◆")} Linting ${c.accent(project.name + "/index.html")}`);
console.log();
if (result.ok) {
console.log(`${c.success("◇")} ${c.success("0 errors, 0 warnings")}`);
return;
}
for (const finding of result.findings) {
const prefix = finding.severity === "error" ? c.error("✗") : c.warn("⚠");
const loc = finding.elementId ? ` ${c.accent(`[${finding.elementId}]`)}` : "";
console.log(`${prefix} ${c.bold(finding.code)}${loc}: ${finding.message}`);
if (finding.fixHint) {
console.log(` ${c.dim(`Fix: ${finding.fixHint}`)}`);
}
}
const summaryIcon = result.errorCount > 0 ? c.error("◇") : c.success("◇");
console.log(
`\n${summaryIcon} ${result.errorCount} error(s), ${result.warningCount} warning(s)`,
);
process.exit(result.errorCount > 0 ? 1 : 0);
},
});