Skip to content

fix(cli): escape audio and media-use output, pin model files - #8013

Merged
michaelwang11394 merged 11 commits into
mainfrom
sec-low23a-1117
Nov 17, 2026
Merged

michaelwang11394 merged 11 commits into
mainfrom
sec-low23a-1117

Conversation

@michaelwang11394

@michaelwang11394 michaelwang11394 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

Two small hardening fixes in the CLI:

  1. hyperframes audio, hyperframes audio --read and hyperframes media-use resolve print control characters from project and cache files as visible \xNN escapes. For media-use resolve, this covers results, --candidates, recipes, --stats and error messages.
  2. The background-removal weights and the Kokoro TTS model and voices files are pinned to a fixed size and sha256, and they are checked before use.

The playlist folder hardening this PR first carried landed on main in #8014. The merge keeps main's version, so this PR no longer changes packages/engine.

Why

  1. Some printed text comes from a project or a shared cache: file names, element ids, transcript words, model descriptions, media manifest fields, recipe names and missed intents. These commands printed it as it was. A project could therefore send terminal control sequences, or a fake extra line, to whoever ran them.
  2. The model files came from release URLs. Whatever bytes arrived were used, and a cached copy was trusted because it existed.

How

  1. Terminal escaping:
    • Each line of the audio formatters' output is escaped whole with core's terminalText, so a newline inside a field shows as \x0a.
    • The media-use engine runs without the CLI's packages installed, so lib/terminal-text.mjs carries a small copy of terminalText. A CLI test compares the copy with core's over U+0000 to U+00A0, so the two cannot drift apart.
    • resolve.mjs and formatCandidates use the copy for their result, low-confidence, adopt, recipe, stats and error: lines.
    • --json output is unchanged.
  2. Model pinning:
    • The new ensurePinnedFile helper uses the existing verifies check (size and sha256). A cached copy that matches is used as it is.
    • Otherwise, downloadFile gets a new keepExisting option. Under the download lock, it keeps a copy that passes. It removes a copy that fails and downloads the file again, so existing caches keep working and concurrent runs never delete each other's files.
    • A download that does not match is discarded. The error says the file does not match its expected checksum, and that a retry helps only if the download was interrupted or corrupted.
    • The hashes come from downloading the exact URLs the code uses. The sizes match the sizes GitHub reports for those release assets.
    • whisper/modelFile.ts is added to the CI edit_accuracy: paths filter, because the pinned download now imports it.

No visible change

  • Normal text prints exactly as before. Only control characters change, and they now show as \xNN.
  • --json output is unchanged.
  • Existing users' cached models still pass the check, so nothing is downloaded again. Checking the hashes adds about 0.2 s on a recent laptop.

Test plan

fails without the fix: the new tests in audio/analysis/format.test.ts, audio/read/format.test.ts, media-use/lib/candidates.test.mjs, media-use/resolve.test.mjs, media-use/terminalText.parity.test.ts, utils/download.test.ts, background-removal/manager.pin.test.ts and tts/manager.pin.test.ts each fail when the matching source change is reverted.

  • Manual checks:

    • The real cached model files pass without a download.
    • A tampered cached voices file is downloaded again and then matches its pin.
  • Ran:

    • tsc --noEmit for cli and engine.
    • oxlint, oxfmt, the comment ratchet, check-comment-citations, check-test-reachability and check-edit-accuracy-filter.
  • 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

…iles as visible escapes

hyperframes audio, audio --read and media-use resolve (including
--candidates) printed file names, element ids, transcript words, model
descriptions and media manifest fields as they were. They now pass
through terminalText, so a control character shows as a visible \xNN
escape. The media-use engine runs without the CLI's packages, so it
carries a small copy of the helper. --json output is unchanged.
…efixed entries

ffmpeg reads an HLS or ffconcat entry with a colon before its first
separator as a URL or a drive, and opens it apart from the list's
folder. The folder check read entries such as C:Videos\a.mp4 or c:x.mp4
as names inside the folder and approved them. It now refuses any entry,
raw or percent-decoded, whose colon comes before its first /, \, ? or #,
as it already refuses absolute and parent-folder paths. http and https
segments are still kept.
… a sha256

The u2net_human_seg weights and the Kokoro model and voices files were
downloaded from release URLs and used whatever bytes arrived, and any
cached copy was trusted because it existed. Each file now has a pinned
size and sha256. A cached copy is checked before it is loaded and
downloaded again when it does not match. A download that does not
match is discarded with a message that names the file.
ffmpeg resolves a list's entries against its path cut at the first ? or
#. A list at proj/h#z/list.m3u8 naming ../h#z/x.ts was judged against
proj/h#z and approved, while ffmpeg opened proj/../h#z/x.ts. Entries are
now judged against the same cut folder. A list in a folder such as
"Take #2" still passes when its entries resolve inside that folder.
…he download lock

ensurePinnedFile removed a cached copy that failed its check before the
download lock was taken, so a concurrent run could delete a file another
run had just published. downloadFile now takes a keepExisting check and
runs it under the lock: a copy that passes is kept, one that fails is
removed and downloaded again. The mismatch error now says the file does
not match its expected checksum, and that a retry helps only if the
download was interrupted or corrupted.
…es recipe and stats output

The audio formatters escaped their output line by line, so a newline
inside a src, warning or transcript still printed as a real line break.
Each output line is now escaped whole with terminalText, which shows a
newline inside a field as \x0a. media-use resolve also escapes its
recipe lines and its --stats lines, which print recipe names, paths and
missed intents.

@miguel-heygen miguel-heygen 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.

Approving at 4af2604. I found no blockers. I checked the three changes against their siblings:

  • Playlist check. ffmpegListFolder cuts the same absolute path that listLeaves resolves, and that is the path the frame extractor hands to -i, so the check and ffmpeg judge the same base. The single COLON_BEFORE_SEPARATOR test covers what the old scheme and drive patterns missed (C:Videos\a.mp4, one-letter schemes) and keeps parts/take:2.ts. The Take #2/ cases in the tests match the base cut ffmpeg makes.
  • Pins. Every downloadFile caller that fetches a model is now pinned: background removal, the Kokoro model and voices through ensurePinnedFile, whisper through its existing verify, and the registry embedding model through its own size and sha256 check in localModel.ts. Without keepExisting, keepsDest returns waited, so other callers behave exactly as before. A copy is removed only after it fails its pin, so a good file another run is reading is never deleted.
  • Escaping. The remaining unescaped prints in resolve.mjs show the person's own arguments (--for, --from, --type), JSON-encoded values, or doctor output from tools on their machine. None of them print project or cache fields.

Non-blocking, take or leave:

  1. utils/download.ts: keepsDest was inserted between downloadFile and its doc comment, so the comment about resuming from the partial file now documents keepsDest. Moving the helper above that comment puts it back on downloadFile. keepExisting could also get a one-line doc like verify has.
  2. media-use/lib/terminal-text.mjs is a copy of core's terminalText. Its logic matches today, but nothing keeps the two in step. A small test in the CLI package that compares both over code points 0x00 to 0xA0 would fail the day one of them changes.
  3. A project inside a parent folder whose name has # or ? now gets its HLS lists refused as leaving their folder. That matches what ffmpeg opens, but the person sees a normal project. If the refusal message named the # or ? in the path, the cause would be obvious.
  4. Later, not here: registry/localModel.ts keeps its own download-then-check-then-unlink path. Moving it onto ensurePinnedFile would give the pin check a single owner.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 103 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

@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.

Requesting changes at 4af26042. Both blockers have small fixes.

1. media-use error messages still print raw control characters from project files. This is the same class as #8008. The PR escapes the success line (resolved recipe …) but not the failure path.

  • When a recipe isn't found, useRecipe throws no recipe named "<slug>" (known: <names>) (lib/recipe-store.mjs:341). The names come from .media/recipes/*/recipe.json in the project.
  • That message reaches exitError (resolve.mjs:294), which prints console.error(\error: ${message}`)at:678` without escaping.
  • Repro: name a recipe evil\x1b]0;PWNED\x07\x1b[31mred, then run resolve.mjs --type recipe --entity nope --project …. stderr carries ESC ] 0 ; PWNED BEL ESC [31m as is.
  • The same raw error: ${…} sink is at :560, :678, :750 and :1408 (run().catch). Wrapping those four in terminalText covers the class. A test with an unknown recipe name, in a project holding a recipe whose name has control characters, would pin it.

2. The required Test check is red because of this PR. Test (support) fails scripts/check-edit-accuracy-filter.test.mjs: "the edit accuracy filter covers every file the bench runs, imports or is built from". The new pinnedFile.ts import chain pulls in packages/cli/src/whisper/modelFile.ts, which the edit_accuracy: paths filter in .github/workflows/ci.yml doesn't list. Adding it next to packages/cli/src/utils/** fixes it. Base a6dd840 is green.

What's verified clean

  • audio: the top-level handler escapes thrown errors (cli.ts:708, terminalLines). formatReport and formatRead escape every line. --json output is unchanged.
  • HLS: strace on ffmpeg n8.0.1 confirms ffmpeg uses the parent folder for a#b/list.m3u8 and c?d/list.m3u8, so ffmpegListFolder matches it.
    • Refused at head: C:x.ts, c:x, UNC paths, //host, absolute paths, file:, .., %2e%2e, backslash .., and a nested playlist that leaves the folder.
    • Base allowed C:x.ts and c:x.
    • All three call sites use the check.
  • Pinned models: all three pins match the real files (downloaded and hashed): u2net, kokoro and voices.
    • A download is verified before the atomic rename.
    • A .part file that doesn't match is discarded.
    • A cached copy is re-checked under the lock.
  • Tests: without the PR's source changes, 22 tests fail. All 6 mutants were killed: colon guard, ffmpegListFolder→dirname, keepExisting, the post-download check, the cached-copy check, and media-use terminalText.

Follow-ups, not blocking (pre-existing)

  • An HLS entry that is only a query (?x) resolves against the playlist file, not its folder. strace showed ffmpeg open list.m3u8?x and then a segment outside the folder. playlistLeavesItsFolder misses it, as base does. It's the same resolution class this PR fixes, so worth doing here if you're touching it.
  • cli.ts:76 → dotEnv.ts:129 prints .env key names raw on every command, and auth/resolver.ts:120 prints the .env folder path.
  • terminal-text.mjs is a hand-kept copy of core's helper with no drift check. Miguel's note about keepsDest splitting downloadFile from its JSDoc also stands.
  • CodeQL's 8 alerts look like false positives (test temp files, and lock/part creation that already existed in download.ts).

— Rames

The playlist folder check on main (#8014) already refuses colon-prefixed
entries and entries read from a folder whose path holds ? or #, so the
merge keeps main's notMediaPayload.ts and its tests.
… escapes

resolve printed error messages as they were, and some name project or
cache data, such as the known recipe names when a recipe is not found.
Every error: line now passes through terminalText, as the success lines
already do.
The CLI's pinned model download now imports whisper/modelFile.ts, so a
change to it must run the edit accuracy bench too.
…e downloadFile

The tests wrote fixtures under fixed names in the shared temp folder,
and their download stand-in checked for a file before replacing it.
Each test now works in its own mkdtemp folder, and the stand-in asks
keepExisting directly and renames the part file into place, as
downloadFile does.
The media-use engine keeps its own copy of terminalText. A CLI test now
compares the two over U+0000 to U+00A0, so a change to either fails
until both match. keepsDest moves above downloadFile's doc comment,
which belongs to downloadFile.
@michaelwang11394 michaelwang11394 changed the title fix: escape audio output, judge HLS entries like ffmpeg, pin model files fix(cli): escape audio and media-use output, pin model files Nov 17, 2026
@michaelwang11394

Copy link
Copy Markdown
Contributor Author

Thanks, both. Every blocker and failing check is fixed in plain follow-up commits on top of 4af26042.

Blocker 1: media-use errors print raw control characters (370ac62)

  • All four error: ${…} sinks in resolve.mjs now pass through terminalText: the generic one, exitError, the provider-error one, and run().catch.
  • The cache-type mismatch line (sha "…" is a <type> asset) also passes through terminalText, because its type comes from the cache manifest.
  • The recipe test now also runs --type recipe --entity nope in a project that holds a recipe named with ESC. It checks that stderr shows known: promo\x1b[2K and no raw ESC or BEL. It fails without the change.

Blocker 2: Test (support) fails on the edit accuracy filter (c475d9d)

  • Added packages/cli/src/whisper/modelFile.ts to the edit_accuracy: filter, next to packages/cli/src/utils/**.
  • scripts/check-edit-accuracy-filter.test.mjs passes locally.

CodeQL (ac3c52a)

  • pinnedFile.test.ts now gives each test its own mkdtemp folder instead of a fixed name in the shared temp folder.
  • The manager pin tests now set their cache folder with mkdtemp.
  • In all three tests, the downloadFile stand-in no longer calls existsSync before replacing the file. It asks keepExisting directly and renames the .part file into place, the same way downloadFile does.

Merge conflict with main (a580b5b)

Non-blocking notes

  • Miguel 1: I moved keepsDest above the downloadFile doc comment, so the comment documents downloadFile again (019a362). I did not add a doc line to keepExisting, because the comment ratchet does not allow download.ts a higher comment share.
  • Miguel 2 and the drift note: a new CLI test compares the media-use terminalText copy with core's over U+0000 to U+00A0. It fails as soon as the two differ. I checked this by editing one range bound (019a362).
  • Miguel 3, Miguel 4 and Rames' query-only ?x entry: these are about the playlist check on main (fix(engine): the playlist folder check reads colon, query and fragment names as ffmpeg resolves them #8014) or registry/localModel.ts. I left them for a follow-up.
  • Rames' .env key and folder printing (dotEnv.ts, auth/resolver.ts): this is outside the files this PR touches, so I left it for a follow-up too.

Checks run locally

  • The touched CLI tests pass: audio, media-use, pinned file, download, TTS and background removal.
  • resolve.test.mjs passes 69 of 69, and candidates.test.mjs passes 8 of 8.
  • notMediaPayload.test.ts passes after the merge.
  • tsc --noEmit passes for cli and engine.
  • oxlint, oxfmt, the comment ratchet, the citations check and the test-reachability check pass.
  • bun run test:scripts passes 975 of 976. The one failure is publish-workflow.test.mjs, where npm and tar read different files in core.tgz on this Mac. That test passed in this PR's CI run.

@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.

Approving at 019a3628. Both blockers are resolved.

  • Escaping: all four resolve.mjs sinks (:560, :678, :750, :1408) and the cache-type line at :1287 use terminalText. The new resolve.test.mjs case runs --entity nope in a project with a recipe named with control characters, then asserts stderr shows known: promo\x1b[2K with no raw ESC or BEL.
  • CI filter: packages/cli/src/whisper/modelFile.ts is now in the edit_accuracy: filter. check-edit-accuracy-filter.test.mjs passes locally and in Test (support).
  • Earlier nits: a drift test now compares the media-use copy of terminalText with core's from U+0000 to U+00A0, and keepsDest's doc comment is fixed.
  • Merge: a580b5b1 takes main's #8014 for the engine, so the PR no longer touches packages/engine.

Tests:

  • resolve.test.mjs: 69 of 69.
  • Filter test: 2 of 2.
  • Parity and pin tests: 11 of 11.
  • The :678 mutant was killed by the recipe test.

CI: one run's Studio: edit accuracy gate failed 266 vs the base's 267, on the undo case pathpause-none-px-r0-nested-z100. That case is also listed as unstable in the same report, the PR touches no Studio code, and the rerun scored 267. I read it as a flake, and final CI is green.

Non-blocking: mutants on the :560 and :1408 sinks survive; only the exitError path is tested.

— Rames

@miguel-heygen miguel-heygen 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.

Re-review: the range from our approval at 4af2604 to 019a362. All of it stays inside this PR's scope.

  • 370ac62: media-use resolve now runs its five error: lines through terminalText (resolve.mjs), which covers the "error messages" the body lists. resolve.test.mjs asserts the escaped output.
  • c475d9d: one line in ci.yml. The edit-accuracy path filter now includes packages/cli/src/whisper/modelFile.ts, so changes there run the edit-accuracy job. The file sits next to the download code this PR changes. This is CI coverage only, with no behaviour change.
  • ac3c52a: the pinned-model tests (background-removal/manager.pin.test.ts, tts/manager.pin.test.ts, utils/pinnedFile.test.ts) use private temp folders and rename files the way downloadFile does. Tests only.
  • 019a362: terminalText.parity.test.ts checks the media-use copy of terminalText against core's for every code point from U+0000 to U+00A0, and terminal-text.d.mts types it. download.ts only moves an existing doc comment back above downloadFile, the function it describes.
  • a580b5b merges main and has no conflict hunks. As the body says, the PR no longer changes packages/engine: #8014's version on main stands. The net diff against main is the 21 CLI files plus the ci.yml line.

CI is green at this head.

Verdict: APPROVE

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit c443989 Nov 17, 2026
258 of 306 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-low23a-1117 branch November 17, 2026 07:37
ukimsanov added a commit that referenced this pull request Nov 18, 2026
…d cube-validate lines

#8013 escaped resolve's results, recipes, stats and error lines, and
#8087 the adopt skip line. A few resolve lines still printed their
values raw: argument errors that repeat --type, --provider, --from,
--reuse and the --for path, the measured-grade note and the
similar-asset hint that repeats the intent. cube-validate's error can
quote a value from the LUT file. They now go through the same
terminalText copy, so a control character shows as \xNN. --json output
is unchanged.
imaderaya pushed a commit to pub-forks/hyperframes that referenced this pull request Nov 18, 2026
…d cube-validate lines (heygen-com#8059)

heygen-com#8013 escaped resolve's results, recipes, stats and error lines, and
heygen-com#8087 the adopt skip line. A few resolve lines still printed their
values raw: argument errors that repeat --type, --provider, --from,
--reuse and the --for path, the measured-grade note and the
similar-asset hint that repeats the intent. cube-validate's error can
quote a value from the LUT file. They now go through the same
terminalText copy, so a control character shows as \xNN. --json output
is unchanged.
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.

4 participants