From 7fcc4909b442ba79918ae69d8a67416820d730f9 Mon Sep 17 00:00:00 2001 From: James Russo Date: Sat, 21 Nov 2026 12:35:15 +0000 Subject: [PATCH] fix(cli): show control characters as text in capture, figma, usage and notice lines (#8366) * fix(cli): keep notices and capture warnings to the line they are printed on A warning or failure reason from capture, and the command named in the left-out-files notice, could carry a line break and start a line of their own. They are printed as one line now, control characters shown as text. The figma component, usage and measure hands status lines go through the same helper. Co-Authored-By: Claude Fable 5.2 * docs(cli): describe how printed lines show control characters and line breaks Co-Authored-By: Claude Fable 5.2 * docs(cli): name the commands whose printed lines changed Co-Authored-By: Claude Fable 5.2 --------- Co-authored-by: Claude Fable 5.2 --- docs/packages/cli.mdx | 12 +++++++++++ packages/cli/src/commands/capture.test.ts | 21 ++++++++++++++++++- packages/cli/src/commands/capture.ts | 6 +++--- packages/cli/src/commands/figma/component.ts | 4 +++- packages/cli/src/commands/measure/hands.ts | 3 ++- packages/cli/src/commands/usage.ts | 4 +++- .../src/utils/stageReferencedFiles.test.ts | 3 ++- .../cli/src/utils/stageReferencedFiles.ts | 2 +- 8 files changed, 46 insertions(+), 9 deletions(-) diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index c1377eca9a..959ff0d1fa 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -47,6 +47,14 @@ default to the current directory: `npx hyperframes check ./my-video`. A few take it as a flag instead — `add`, `transcribe`, `feedback`, `skills`, `history`, and the `timeline` edit commands use `--dir`. +**Control characters in a few printed lines.** `figma component` (the +`imported component` line), `usage` (the reason on a `Usage unknown` line), +`measure hands` (its notices) and `compare` and `keyframes` (the notice +about files left out) print control characters in a repeated value as visible +text such as `\x1b` and `\x07`, and keep the value on its line, with a line break +shown as `\x0a`. [`capture`](#capture) does the same for its warnings and failure +reason. `--json` output is not changed by this. + **`--json` for agents and scripts.** Most commands accept it, and the ones that do not reject it with exit 2. The payload is wrapped with a `_meta` field so a script can spot an outdated CLI from any command's output, without a @@ -410,6 +418,10 @@ the `/hyperframes` skill uses it when a real product has to appear on screen. Dy partial results, so read `dropped`, the warnings, and the contact sheets before you build. +Each warning, and the reason on a `Capture failed:` line, is printed on one +line: a line break inside the text is shown as `\x0a` instead of starting a new +terminal line. `--json` output is unchanged and carries the full text. + Downloaded fonts are saved under `assets/fonts/`, and their CSS references point to those local files. Distinct URLs such as `demo.woff2?v=1` and `demo.woff2?v=10` keep separate files. A failed font download leaves its original diff --git a/packages/cli/src/commands/capture.test.ts b/packages/cli/src/commands/capture.test.ts index 68f9f9e6bc..2d95a07c69 100644 --- a/packages/cli/src/commands/capture.test.ts +++ b/packages/cli/src/commands/capture.test.ts @@ -491,7 +491,7 @@ describe("capture command: what it prints", () => { tokens: { sections: [], fonts: [] }, assets: [], dropped: {}, - warnings: [] as string[], + warnings: ["Kept the existing a\n ⚠ b.md"], } as never); try { @@ -506,7 +506,26 @@ describe("capture command: what it prints", () => { expect(text).toContain("Capturing https://example.com/a\\x07b"); // The folder is printed as a full path, whose root and separators differ by platform. expect(text).toMatch(/Captured Example → \S*hf-capture\\x1b\[2Jout/); + expect(text).toContain("⚠ Kept the existing a\\x0a ⚠ b.md"); expect(text).not.toContain("\u0007"); expect(text).not.toContain("\u001b[2J"); }); + + // fails without the fix: a line break in the reason started a line of its own + it("keeps the reason a capture failed on one line", async () => { + vi.useFakeTimers(); + registerRootExitRequester(() => {}); + const error = vi.spyOn(console, "error").mockImplementation(() => {}); + captureWebsiteMock.mockRejectedValueOnce(new Error("no route\n ✓ Captured")); + const output = mkdtempSync(join(tmpdir(), "hf-capture-failed-")); + try { + await captureCommand.run!({ args: { url: "https://example.com", output } } as never); + } catch { + /* the run reports its failure by throwing too */ + } finally { + vi.useRealTimers(); + rmSync(output, { recursive: true, force: true }); + } + expect(printed(error)).toContain("Capture failed: no route\\x0a ✓ Captured"); + }); }); diff --git a/packages/cli/src/commands/capture.ts b/packages/cli/src/commands/capture.ts index 479804d9a0..b9acff6678 100644 --- a/packages/cli/src/commands/capture.ts +++ b/packages/cli/src/commands/capture.ts @@ -8,7 +8,7 @@ import { diag } from "../ui/diagnostics.js"; import type { CapturePhaseProgress } from "../capture/types.js"; import { parseCaptureDeadline } from "../capture/captureWatchdog.js"; import { jsonFailure, printFailureLine } from "../utils/jsonError.js"; -import { terminalLines, terminalText } from "@hyperframes/core"; +import { terminalText } from "@hyperframes/core"; import { parseTimeoutMs } from "../utils/timeoutArg.js"; const CAPTURE_PHASE_PREFIX = "HYPERFRAMES_CAPTURE_PHASE "; @@ -335,7 +335,7 @@ export default defineCommand({ if (result.warnings.length > 0) { console.log(); for (const w of result.warnings) { - console.log(` ${c.warn("⚠")} ${terminalLines(w)}`); + console.log(` ${c.warn("⚠")} ${terminalText(w)}`); } } console.log(); @@ -359,7 +359,7 @@ export default defineCommand({ if (isJson) { console.log(JSON.stringify(jsonFailure("runtime_error", errMsg))); } else { - console.error(`\n ✗ Capture failed: ${terminalLines(errMsg)}\n`); + console.error(`\n ✗ Capture failed: ${terminalText(errMsg)}\n`); } scheduleCliExit(1); failCommand(); diff --git a/packages/cli/src/commands/figma/component.ts b/packages/cli/src/commands/figma/component.ts index 747ecd21bb..63ba478f56 100644 --- a/packages/cli/src/commands/figma/component.ts +++ b/packages/cli/src/commands/figma/component.ts @@ -206,7 +206,9 @@ export default defineCommand({ download: downloadRender, name: args.name, }); - console.log(`imported component "${result.name}" → ${result.htmlPath}`); + console.log( + `imported component "${terminalText(result.name)}" → ${terminalText(result.htmlPath)}`, + ); if (result.rasterized.length > 0) { const ok = result.rasterized.length - result.failedRasterize.length; console.log( diff --git a/packages/cli/src/commands/measure/hands.ts b/packages/cli/src/commands/measure/hands.ts index 198b8037b2..8d9bacb9f6 100644 --- a/packages/cli/src/commands/measure/hands.ts +++ b/packages/cli/src/commands/measure/hands.ts @@ -1,3 +1,4 @@ +import { terminalText } from "@hyperframes/core"; import { defineCommand } from "../../utils/defineCommand.js"; import type { Example } from "../_examples.js"; import { jsonArg, num, runMeasure, videoArg, window } from "../../measure/command.js"; @@ -67,7 +68,7 @@ export default defineCommand({ which: choice(args.which, "--which", HAND_CHOICES, "largest"), fps: num(args.fps, "--fps", 15), }, - (message) => console.error(message), + (message) => console.error(terminalText(message)), ); return { video: info.path, diff --git a/packages/cli/src/commands/usage.ts b/packages/cli/src/commands/usage.ts index b8239f91ec..f4051a041d 100644 --- a/packages/cli/src/commands/usage.ts +++ b/packages/cli/src/commands/usage.ts @@ -1,3 +1,4 @@ +import { terminalText } from "@hyperframes/core"; import { defineCommand } from "../utils/defineCommand.js"; import { readHarnessUsage } from "../utils/harnessUsage.js"; @@ -18,7 +19,8 @@ export default defineCommand({ const harness = args.harness ?? detectHarness(); const usage = await readHarnessUsage(harness); if (args.json) console.log(JSON.stringify(usage)); - else if (usage.status === "unknown") console.log(`Usage unknown (${usage.reason}).`); + else if (usage.status === "unknown") + console.log(`Usage unknown (${terminalText(usage.reason)}).`); else console.log(JSON.stringify(usage, null, 2)); }, }); diff --git a/packages/cli/src/utils/stageReferencedFiles.test.ts b/packages/cli/src/utils/stageReferencedFiles.test.ts index 51bd885652..5fdd997b9a 100644 --- a/packages/cli/src/utils/stageReferencedFiles.test.ts +++ b/packages/cli/src/utils/stageReferencedFiles.test.ts @@ -160,9 +160,10 @@ describe("leftOutNotice", () => { it("names the first five escaped, counts the rest and says how to keep them", () => { const leftOut = ["a\x1b[2J.png", "b.txt", "c.txt", "d.txt", "e.txt", "f.txt", "g.txt"]; - const notice = leftOutNotice("compare a.html", { leftOut, complete: false }); + const notice = leftOutNotice("compare a\x1b[2J\nb.html", { leftOut, complete: false }); expect(notice).not.toContain("\x1b"); + expect(notice).toMatch(/^compare a\\x1b\[2J\\x0ab\.html: left out /); expect(notice).toContain("a\\x1b[2J.png, b.txt, c.txt, d.txt, e.txt, and 2 more."); expect(notice).toContain("too large or too many"); expect(notice).toContain("pass the project folder"); diff --git a/packages/cli/src/utils/stageReferencedFiles.ts b/packages/cli/src/utils/stageReferencedFiles.ts index 7b7476b49c..85dd5c88f2 100644 --- a/packages/cli/src/utils/stageReferencedFiles.ts +++ b/packages/cli/src/utils/stageReferencedFiles.ts @@ -114,5 +114,5 @@ export function leftOutNotice(command: string, result: StagedFiles): string | nu result.leftOut.length > NAMES_SHOWN ? `, and ${result.leftOut.length - NAMES_SHOWN} more` : ""; const named = shown.length > 0 ? ` left out ${shown.join(", ")}${more}.` : ""; const partial = result.complete ? "" : " Some files were too large or too many to read in full."; - return `${command}:${named}${partial} Only the files the page names in its own folder are served; pass the project folder to keep the rest.`; + return `${terminalText(command)}:${named}${partial} Only the files the page names in its own folder are served; pass the project folder to keep the rest.`; }