Skip to content

Optimize reviewDoc.ts to correctly handle removed lines when only reviewing changed chunks #153

Open
@aymericzip

Description

@aymericzip

Background

The @intlayer/cli package provides two commands for translation workflows that are based on LLM translations :

  1. Generate translations

    npx intlayer doc translate --doc-pattern ./myFile.md

    This creates a translated version of your source file.

  2. Review translations (with optimization)

    npx intlayer doc review --doc-pattern ./myFile.md

    Intended to only re-review (and possibly re-translate) the chunks that have changed, saving API costs by skipping unchanged sections.


The Problem

An optimization branch of code (around line 275 in reviewDoc.ts has been commented out. Re-enabling it:

  • ✅ Works perfectly when the “base translation” file and the “to-be-reviewed” file have the same number of lines.
  • ❌ Fails (produces bad formatting) when the base file translated is longer than the file under review (i.e. when lines have been removed in the source).

In other words, the current diff-based chunking logic doesn’t correctly handle cases where lines were deleted in the updated file, causing mis-aligned chunks and garbled output.


Steps to Reproduce

  1. Prepare original.md and produce its translation:

    npx intlayer doc translate --doc-pattern original.md
  2. Edit original.md to remove or reorder some lines.

  3. Run review:

    npx intlayer doc review --doc-pattern original.md
  4. Observe that the translated output is misformatted or chunks are skipped incorrectly.


Expected Behavior

  • Only the modified chunks (including those affected by line deletions) should be passed to the review/LLM step.

  • Unchanged chunks should remain exactly as in the existing translated file, preserving formatting.

  • The script should gracefully handle:

    • Inserted lines
    • Deleted lines
    • Moved blocks

Actual Behavior

  • When lines are deleted in the source, the diff-based chunk slicing falls out of sync.
  • Unchanged sections are sometimes reprocessed—or worse, dropped or mangled—resulting in formatting issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issuejavascriptPull requests that update javascript codeonlydust-waveContribute to awesome OSS repos during OnlyDust's open source week

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions