Files
hyperframes/packages/cli/src/utils/lintFormat.ts
T
Michael WangandClaude Opus 5.5 c4d60c347f fix: Studio media routes refuse cross-site load, CLI escapes terminal text, batch outputs stay in their folder (#7779)
* fix(cli): batch render outputs stay inside the --output folder

A row value may still name a subfolder of the folder written before the
template's first placeholder, but a value that resolves outside it stops
the batch before any folder is made or file is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): project text shows control characters as visible escapes

compositions, lint, snapshot and info --media print composition ids, sources,
element ids, lint messages and media paths through one helper that writes
C0, DEL and C1 control characters out as \xNN, so they reach the terminal as
text. The CLI's own colors are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(studio-server): waveform and peaks key one cache entry per file and refuse other sites

Both caches are keyed on the resolved project-relative path, so another
spelling of the same file (a doubled or trailing slash) reads the cached
peaks instead of decoding again. Waveform and peaks requests that another
site makes are refused the way thumbnail requests already are; the Studio
page asks for both as itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(studio-server): preview stills run at most four at a time

A video's stand-in still is made through a small job queue: four at once,
32 more waiting, and a 503 with Retry-After beyond that. A waiting request
whose client goes away leaves the queue without starting ffmpeg.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): batch output folder check keeps backslash names and row-named paths

A trailing backslash counts as a separator only where it is one, and the
check compares path segments. A template that starts with a placeholder names
no folder, so each row's value is the whole output path as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): lint header shows control characters in file names as escapes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(studio-server): a finished or in-progress still never waits for a still slot

Only a still that is neither on disk nor already being made takes one of
the four slots, through a hook resolveStill gives the route. Waiters queue
without a cap and nothing answers 503, since a poster is never asked for
again. A waiter whose client leaves still never starts ffmpeg; a request
that shared that waiter's still tries again on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: raise the studio-server packed budget to 172000

main already packs about 170 KB against a 168500 budget; the request guards,
still slots and cache-key change here add about 550 bytes.

* fix(core,studio-server): a preview served to another site offers no editing port

When the Studio server answers a preview document to another site's
request, it now marks the document, and the runtime's editing agent
ignores every connect in a marked document. The Studio's own frames,
which load the preview from the same origin, keep the editing port.
The marked copy carries no ETag, so it is never revalidated in place of
the unmarked one.

* fix(studio-server): a media still stops when no request waits on it

Each still job now counts the requests waiting on it. A request whose
connection closes leaves the job, and when the last one leaves, the
job's ffmpeg is killed and the job is forgotten, so the next request
starts afresh. A caller that passes no signal keeps the job running,
and a request that has already closed starts nothing.

* test(studio-server): group the still cancellation tests after the real-ffmpeg still test

* fix(studio-server): a preview framed by another site is never revalidated

A frame load of a preview from another site now drops If-None-Match and
If-Modified-Since before the route answers, so it always gets a fresh,
marked document instead of a 304 that could reuse the unmarked copy a
browser cached for the Studio's own page on the same site. Subresource
loads keep their validators.

* fix(cli): check findings and keyframes headers show control characters as escapes

check prints each finding's message, source file, selector and fix hint, and
keyframes prints each composition's name and source, through terminalText.

* test(studio-server): a request sharing an abandoned still waiter gets its still

* chore(studio-server): raise the unpacked size budget for the still job slots and cross-site guards

* fix(cli): layout and contrast lines in check show control characters as escapes

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:57:32 +00:00

111 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { c } from "../ui/colors.js";
import { terminalText } from "./terminalText.js";
import type { ProjectLintResult } from "./lintProject.js";
export interface LintFormatOptions {
/** Show elementId in brackets after the code (default: true) */
showElementId?: boolean;
/** Show summary line with error/warning counts (default: false) */
showSummary?: boolean;
/** Group errors before warnings per file (default: false — interleaved) */
errorsFirst?: boolean;
/** Include info-level findings in output (default: false — only errors/warnings) */
verbose?: boolean;
}
/**
* Format lint findings for console output. Used by lint, render, and preview commands.
*/
export function formatLintFindings(
{ results, totalErrors, totalWarnings, totalInfos }: ProjectLintResult,
options: LintFormatOptions = {},
): string[] {
const {
showElementId = true,
showSummary = false,
errorsFirst = false,
verbose = false,
} = options;
const lines: string[] = [];
const multiFile = results.length > 1;
for (const { file, result } of results) {
if (result.findings.length === 0) continue;
const format = (finding: (typeof result.findings)[0]) => {
if (!verbose && finding.severity === "info") return;
const prefix =
finding.severity === "error"
? c.error("✗")
: finding.severity === "warning"
? c.warn("⚠")
: c.dim("ℹ");
const fileLabel = findingFileLabel(file, finding, multiFile);
const loc =
showElementId && finding.elementId
? ` ${c.accent(`[${terminalText(finding.elementId)}]`)}`
: "";
const message = terminalText(finding.message);
lines.push(` ${prefix} ${fileLabel}${c.bold(finding.code)}${loc}: ${message}`);
if (finding.fixHint) lines.push(` ${c.dim(`Fix: ${terminalText(finding.fixHint)}`)}`);
};
if (errorsFirst) {
for (const f of result.findings) if (f.severity === "error") format(f);
for (const f of result.findings) if (f.severity === "warning") format(f);
if (verbose) for (const f of result.findings) if (f.severity === "info") format(f);
} else {
for (const f of result.findings) format(f);
}
}
if (showSummary) {
const icon = totalErrors > 0 ? c.error("◇") : c.success("◇");
lines.push("");
lines.push(`${icon} ${formatLintCounts(totalErrors, totalWarnings, totalInfos, verbose)}`);
}
return lines;
}
function formatLintCounts(
totalErrors: number,
totalWarnings: number,
totalInfos: number,
verbose: boolean,
): string {
const parts = [`${totalErrors} error(s)`, `${totalWarnings} warning(s)`];
if (verbose && totalInfos > 0) parts.push(`${totalInfos} info(s)`);
return parts.join(", ");
}
/** Full findings in verbose mode, a one-line summary otherwise. `pointer` (summary
* mode) picks the hint: both name the lint command, "studio" also the Studio badge. --lint-verbose is
* not named: only render, preview and publish take it, and agents tried it on lint and check. */
export type LintMessageMode =
| { kind: "verbose"; options?: LintFormatOptions }
| { kind: "summary"; pointer?: "cli" | "studio" };
export function formatLintStartupMessage(
lintResult: ProjectLintResult,
mode: LintMessageMode,
): string[] {
if (mode.kind === "verbose") return formatLintFindings(lintResult, mode.options);
const counts = formatLintCounts(lintResult.totalErrors, lintResult.totalWarnings, 0, false);
const hint =
mode.pointer === "studio"
? "see the Lint badge in Studio, or run `hyperframes lint` for full output"
: "run `hyperframes lint` for full output";
return [` Lint: ${counts} — ${hint}.`];
}
function findingFileLabel(
file: string,
finding: import("@hyperframes/lint").HyperframeLintFinding,
multiFile: boolean,
): string {
if (finding.line === undefined) return multiFile ? c.dim(`[${terminalText(file)}] `) : "";
const column = finding.column === undefined ? "" : `:${finding.column}`;
return c.dim(`[${terminalText(finding.file ?? file)}:${finding.line}${column}] `);
}