Skip to content

fix(cli): preserve caption arrays during transcript reimport - #6185

Merged
jrusso1020 merged 1 commit into
heygen-com:mainfrom
AksharP5:caption-reimport
Oct 24, 2026
Merged

jrusso1020 merged 1 commit into
heygen-com:mainfrom
AksharP5:caption-reimport

Conversation

@AksharP5

Copy link
Copy Markdown
Contributor

What

Reimporting captions into an existing project now replaces the full transcript when an old caption contains ];, such as items[i];. The CLI could report success while leaving invalid JavaScript in the caption HTML.

Same caption import Main This PR
const TRANSCRIPT with old text items[i]; Syntax error after import Valid script with replacement words
const script with the same text Syntax error after import Valid script with replacement words
Following caption code Follows a leftover array suffix Preserved

Why

The lazy array regex treats characters inside a word string as the array terminator.

Related work

Fixes #6181. #3852 / #3896 address Studio's read-side parser; #5226 addresses CLI script escaping. This fixes the remaining CLI rewrite boundary and retains those escaping rules.

How

Use Acorn to find the complete array expression and its semicolon. Acorn is already in the workspace lockfile and becomes a direct CLI dependency. The surrounding patch selection and script escaping stay in the existing code path.

Test plan

  • Two regression cases fail on main and pass with the fix.
  • Real source CLI before/after comparison for both supported variable names; compile the rewritten script and inspect its complete array and following code.
  • Normalizer and transcribe command suites: 145 tests pass.
  • Strict normalizer typecheck, normalizer bundle, lockfile parsing, lint and formatting.
  • Documentation updated.
  • Comments follow CONTRIBUTING.md.

Independent GPT-6.1 Sol xhigh review: no blocker found. The reviewer independently passed all 145 normalizer/command tests and both real CLI reimports, including parser-boundary, escaping and dependency/lock checks..

Local workspace build/typecheck limitations: missing preinstalled inspector/AWS dependencies. Mintlify is unavailable. No dependency installation was performed. CI results are tracked on this PR.

@mintlify

mintlify Bot commented Oct 24, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 6ac4358.

Approve preview

@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 6ac43580. This fixes a real bug that is still on main, and the tests prove it.

What I verified:

  • On main, patchCaptionHtml finds the array with a lazy \[[\s\S]*?\]; regex, so an old caption word like items[i]; ends the match early and the rewrite leaves a broken script behind. #6181 is still open and no other PR targets it.
  • I applied the PR onto current main: normalize.test.ts passes 81 of 81. With only normalize.ts reverted, both new cases fail, so they guard the fix.
  • The new findCaptionArray still requires the const <name> = [ prefix and a closing ;, the same shape the old regex accepted, so nothing that patched before is skipped now. A file that fails to parse is left untouched, which is the safe direction.
  • Both callers (hyperframes transcribe <file> --dir through importTranscript, and init) go through this one function. The doc line matches that path.
  • Dependency: acorn@^8.17.0 is already in bun.lock with the same integrity hash and is used by lint, parsers, core and studio. No new package gets resolved.

One non-blocking note on reuse. Studio's extractTranscript in packages/studio/src/captions/parser.ts already does exactly this boundary search (Acorn parseExpressionAt, then check the next token is ;). Now the read side and the write side each carry a copy. Moving the boundary finder into @hyperframes/parsers, which both packages already depend on, would keep them from drifting. Studio also accepts let/var and flexible spacing, and the CLI does not. That was true before this PR too, so it is fine as a follow-up.

Need: yes, a reimport can corrupt caption HTML today · Size: ok · Reuse: same logic as Studio's extractTranscript, could share via parsers (follow-up) · Simpler: already minimal

— Rames

@jrusso1020
jrusso1020 added this pull request to the merge queue Oct 24, 2026
Merged via the queue into heygen-com:main with commit 316e723 Oct 24, 2026
74 checks passed
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.

Caption reimport corrupts existing arrays containing ];

2 participants