Skip to content

fix(cli): figma commands print manifest and folder text with visible escapes - #8126

Queued
michaelwang11394 wants to merge 2 commits into
mainfrom
sec-low37a-1117
Queued

michaelwang11394 wants to merge 2 commits into
mainfrom
sec-low37a-1117

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

hyperframes figma asset and hyperframes figma tokens now print text that comes from the project with control characters shown as visible escapes, such as \x1b.

Why

When figma asset reuses an asset it already imported, it prints the id, path and description from the project's .media/manifest.jsonl, plus an <img> snippet built from them. A project folder from someone else can put terminal control sequences in those fields. Printed raw, they can forge or overwrite earlier terminal lines or change the window title. The CLI already escapes other project text this way with terminalText.

Related work

None.

How

  • figma asset passes the reused/imported line and the snippet through terminalText from @hyperframes/core when it prints them.
  • The index.md regeneration failed warning goes through terminalText too, because its message names paths under the project folder.
  • figma tokens passes its wrote <path> line through terminalText, because that path starts from the project folder.
  • The escaping happens only when a line is printed. The manifest file, index.md and the records that runAssetImport and runAssetImportMany return are unchanged.
  • figma component needed no change. Its one warning built from Figma node names was already escaped, and the other lines print slugged names and paths relative to the project folder.

No visible change

Output for normal text is the same. Only control characters, which print as visible escapes now, look different.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

New packages/cli/src/commands/figma/terminalOutput.test.ts runs the real commands through citty with a stubbed Figma client:

  • A manifest row whose id, path and description contain ESC, BEL, CR and C1 bytes, with provenance that matches the request, takes the reuse path. The output has no raw control bytes, it shows the visible escapes, and the manifest bytes are unchanged.
  • A project folder whose name contains control characters, with a .media link that makes index.md regeneration fail, prints the warning with visible escapes.
  • figma tokens run in a project folder whose name contains control characters prints the wrote path with visible escapes.

fails without the fix: with the old asset.ts and tokens.ts, all 3 new tests fail on raw control bytes in the output.

Also run: figma command tests (50 pass), the terminalText parity test in media-use and the core terminalText tests, tsc --noEmit for cli (no new errors), oxlint, oxfmt --check, the comment ratchet and fallow.

…escapes

figma asset prints a manifest row's id, path and description, and the <img> snippet built
from them. These lines, the index.md regeneration warning and the tokens 'wrote' line now go
through terminalText, so control characters show as visible escapes. The manifest file and the
returned records are unchanged.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 414211afc9b3dafcfec25e54c420f8ba02e8eecc.

Approve. The four print sites that can carry project text now go through terminalText from @hyperframes/core:

  • the reused/imported line
  • the <img> snippet
  • the index.md regeneration failed warning
  • the figma tokens wrote line

The escaping happens only when the line is printed. runAssetImport, runAssetImportMany and the manifest bytes are untouched, and the first test pins the manifest bytes.

Coverage, checked:

  • I listed every console.* call under commands/figma. The other lines in asset.ts and tokens.ts print counts or fixed text.
  • In component.ts:
    • The rasterize warning already went through terminalText.
    • The imported component line prints a slugifyd name and an htmlPath relative to the project folder.
    • The overwrite warning prints only the slug.
  • Errors go through withFigmaErrors → errorBox, which already escapes the title (terminalText) and the hint (terminalLines).
  • The PR body's claim that figma component needed no change holds.

Need: real, since a received project's manifest row can rewrite the terminal on a reuse · Size: right, +8 source lines · Reuse: the existing terminalText · Simpler: no · Structure: fine

Risk: low. The change is output only, and plain text prints the same.

Tests (npx vitest run src/commands/figma in packages/cli, after the hf-oss build recipe):

  • Head: 50/50.
  • 4 mutants, one per site, each reverting that site to a raw print. Each one turns its own test red:
    1. The reuse line: red.
    2. The snippet alone: red. The alt= assertion catches it even with the line above it escaped.
    3. The index warning: red.
    4. The tokens line: red.

CI: 13 pass, 20 skipped, 26 still pending when I posted.

— Rames

@michaelwang11394

Copy link
Copy Markdown
Contributor Author

The Windows lane failed twice on the three new tests in figma/terminalOutput.test.ts. They create file and folder names with control characters, which Windows refuses (EINVAL and ENOENT). dc7558f skips that describe block on win32, as other CLI tests do. No code changed. @jrusso1020, could you re-approve at the new head?

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Eddy's agent) Reviewed by Eddy's Claude agent at commit dc7558f.

Verdict: approved.

Summary. Three places in the design-import commands printed text taken from a manifest, a folder path or an error message straight to the terminal. I read the whole diff: each now passes through the existing helper that shows control characters as visible escapes, so a name cannot move the cursor, recolour or overwrite earlier output. The tests cover a manifest row, an index regeneration failure that names the project folder, and the tokens file path.

No blocker found.

Non-blockers:

  • The new test file is skipped on Windows. The helper is platform-neutral, so the behaviour is the same there; the skip only means that platform does not exercise these three call sites.
  • The JSON block printed after the tokens file path is produced by the JSON encoder, which already escapes control characters, so it does not need the helper.

CI: 51 pass, 19 skipped, none failing or pending.

How this was reviewed: I read the diff myself. Nothing was built or run.

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 18, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 18, 2026
@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 18, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 18, 2026
@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 18, 2026
Any commits made after this event will not be merged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants