Skip to content

Conversation

@dorianjp
Copy link

Add originalLineNumbers option for line number placement control

Overview

This PR introduces a new configuration option originalLineNumbers and CLI flag --output-original-line-numbers that allows users to control when line numbers are added to the content during processing. When enabled, line numbers are added to the original content before any transformations (like comment removal, empty line removal, or compression) are applied.

Changes

  1. Configuration Schema

    • Added originalLineNumbers to the configuration schema in src/config/configSchema.ts
    • Set default value to false
  2. CLI Option

    • Added --output-original-line-numbers CLI option in src/cli/cliRun.ts
    • Updated the CliOptions interface in src/cli/types.ts
    • Added handling for the option in src/cli/actions/defaultAction.ts
  3. Processing Logic

    • Refactored the file processing logic in src/core/file/fileProcessContent.ts:
      • Extracted line number addition logic into a reusable addLineNumbers function
      • Added conditional logic to add line numbers at different stages based on the originalLineNumbers setting
      • Changed the order of operations to ensure line numbers are added before or after transformations as appropriate
  4. Documentation

    • Updated the configuration documentation in website/client/src/en/guide/configuration.md
    • Updated the command line options documentation in website/client/src/en/guide/command-line-options.md
    • Updated the README.md with the new CLI option
  5. Tests

    • Added tests for the originalLineNumbers feature in tests/core/file/fileProcessContent.test.ts
    • Added tests for the CLI option in tests/cli/actions/defaultAction.test.ts
    • Updated the schema tests in tests/config/configSchema.test.ts
    • Fixed the failing tests in tests/core/file/fileProcess.test.ts

Feature Behavior

The originalLineNumbers feature works as follows:

  1. When showLineNumbers is false:

    • No line numbers are added, regardless of the originalLineNumbers setting
  2. When showLineNumbers is true and originalLineNumbers is false:

    • Line numbers are added after all transformations (compression, comment removal, empty line removal)
    • This is the previous default behavior
  3. When showLineNumbers is true and originalLineNumbers is true:

    • Line numbers are added to the original content before any transformations
    • Transformations are then applied to the content with line numbers

Benefits

  1. Preserves Original Line Numbers: When using features like comment removal or empty line removal, the original line numbers are preserved, making it easier to reference specific lines in the original file.

  2. Better Compression Integration: When using compression with line numbers, the line numbers are included in the compressed output, providing context for the compressed code.

  3. Improved Readability: Line numbers added before transformations can make it easier to understand how the transformations affected the content.

Usage Examples

Configuration File

{
  "output": {
    "showLineNumbers": true,
    "originalLineNumbers": true,
    "removeComments": true
  }
}

CLI Command

repomix --output-show-line-numbers --output-original-line-numbers --remove-comments

Testing

All tests are passing. The implementation has been tested with various combinations of options to ensure it works correctly in all scenarios.

This feature adds a new configuration option 'originalLineNumbers' and CLI flag '--output-original-line-numbers' that allows users to control when line numbers are added to the content. When enabled, line numbers are added to the original content before any transformations (like comment removal, empty line removal, or compression) are applied.

- Added originalLineNumbers to configuration schema
- Added --output-original-line-numbers CLI option
- Refactored file processing logic to support the new option
- Updated documentation
- Added tests for the new functionality
@dorianjp dorianjp requested a review from yamadashy as a code owner July 11, 2025 17:40
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @dorianjp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the file processing capabilities by providing granular control over when line numbers are added to the output. Previously, line numbers were always added after content transformations. With this change, users can now choose to have line numbers applied to the original content before any modifications, which can be particularly useful for maintaining context when transformations like comment removal or compression are applied.

Highlights

  • New Configuration Option: Introduced a new originalLineNumbers boolean option within the output configuration, defaulting to false. This option controls whether line numbers are added to the content before or after transformations.
  • New CLI Flag: Added a corresponding --output-original-line-numbers CLI flag to allow users to control this new behavior directly from the command line.
  • Refactored Processing Logic: The core file processing logic in src/core/file/fileProcessContent.ts has been refactored. Line number addition is now conditional, occurring either at the very beginning of the processing pipeline (if originalLineNumbers is true) or after other transformations like comment/empty line removal and compression (if originalLineNumbers is false, maintaining the previous behavior).
  • Comprehensive Testing and Documentation: New unit and integration tests have been added to cover the various scenarios and interactions of the originalLineNumbers feature. The README.md and website documentation have also been updated to reflect the new option and its usage.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new originalLineNumbers option to control when line numbers are added during file processing. The implementation refactors the content processing logic and adds corresponding CLI options, configuration schema updates, tests, and documentation.

However, applying transformations after prepending line numbers breaks key features like code compression and empty line removal, as these tools expect valid source code, not text with arbitrary prefixes. These issues are critical and need to be addressed before this feature can be merged.

Comment on lines +54 to +62
if (manipulator) {
if (config.output.removeComments && typeof manipulator.removeComments === 'function') {
processedContent = manipulator.removeComments(processedContent);
}

if (config.output.removeEmptyLines && typeof manipulator.removeEmptyLines === 'function') {
processedContent = manipulator.removeEmptyLines(processedContent);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

When originalLineNumbers is true, removeComments and removeEmptyLines will not function as expected. After adding line numbers, an originally empty line becomes a non-empty string like '42: '. The current implementation of removeEmptyLines will not identify this as an empty line to be removed.

This issue likely affects other manipulators as well, as they are designed to work on source code, not source code with line number prefixes. For example, block comment removal might fail if the start and end of the block are on different lines, each with a prefix.

To fix this, the manipulators would need to be aware of the line number prefixes and ignore them, which makes them more complex and brittle. A better approach might be to perform manipulations before adding line numbers.

Comment on lines +258 to +261
const result = await processContent(rawFile, config);
// Line numbers should be added before compression
expect(parseFile).toHaveBeenCalledWith('1: const x = 1;\n2: const y = 2;', rawFile.path, config);
expect(result).toBe('parsed content');
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This test is misleading as it tests a success path for a scenario that is fundamentally broken. When originalLineNumbers and compress are both true, parseFile is called with content that includes line numbers (e.g., '1: const x = 1;...'). This is not valid source code and will cause Tree-sitter to fail parsing.

The test mock for parseFile currently returns a successful result ('parsed content'), which hides the underlying issue. A more accurate test would:

  1. Mock parseFile to throw an error when it receives content with line numbers.
  2. Assert that processContent either handles this error gracefully (e.g., falls back to using the uncompressed content) or re-throws the error as expected.

As it stands, this test gives a false sense of security that the feature combination works correctly.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new feature was added to the Repomix CLI and configuration: the ability to add line numbers to the original content before any processing occurs, controlled by the --output-original-line-numbers CLI flag and the output.originalLineNumbers config option. Documentation, schema, CLI, implementation, and tests were updated accordingly.

Changes

File(s) Change Summary
README.md, website/client/src/en/guide/command-line-options.md, website/client/src/en/guide/configuration.md Updated documentation to describe the new output.originalLineNumbers/--output-original-line-numbers option.
src/cli/cliRun.ts, src/cli/types.ts, src/cli/actions/defaultAction.ts Added CLI flag --output-original-line-numbers and support for it in CLI options and config merging logic.
src/config/configSchema.ts Added originalLineNumbers boolean property to the output config schema with default false.
src/core/file/fileProcessContent.ts Refactored processing logic to conditionally insert line numbers before or after content manipulation.
tests/cli/actions/defaultAction.test.ts, tests/core/file/fileProcessContent.test.ts Added/extended tests for CLI/config merging and content processing with the new line numbering option.
tests/config/configSchema.test.ts Updated schema tests to include the new originalLineNumbers property in valid config objects.
tests/core/file/fileProcess.test.ts Adjusted line number output expectations and formatting in relevant tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Config
    participant FileProcessor

    User->>CLI: Runs with --output-original-line-numbers
    CLI->>Config: Merge CLI options into config
    Config->>FileProcessor: Pass config with originalLineNumbers flag
    FileProcessor->>FileProcessor: If originalLineNumbers, add line numbers before processing
    FileProcessor->>FileProcessor: Process content (compression, comment removal, etc.)
    FileProcessor->>User: Output content (with line numbers as per config)
Loading

Suggested reviewers

  • yamadashy
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
yamadashy and others added 2 commits July 14, 2025 00:43
…ations

Added originalLineNumbers: false to all test mock configurations to fix
TypeScript compilation errors after the originalLineNumbers feature was
merged. This ensures all test configurations match the updated schema.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Extract the addLineNumbers helper function from processContent to improve
code organization and reusability. The function is now exported and can
be used by other modules if needed.

Changes:
- Move addLineNumbers function outside processContent
- Add proper JSDoc documentation
- Export function for potential reuse

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@yamadashy
Copy link
Owner

yamadashy commented Jul 13, 2025

@dorianjp
Thank you for the PR!
Is this the implementation for what DanielusG and I were discussing?

I've made some minor adjustments to the code.
There are still a few things I'd like to adjust, so I'll work on them tomorrow or later.

Regarding the option name, since this option is dependent on showLineNumbers, I'm thinking of renaming it to showLineNumbersPreserveOriginal even though it's a bit long.

Remove the unnecessary `?? false` fallback for config.output.originalLineNumbers
since it already has a default value of false in the schema.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@yamadashy
Copy link
Owner

I need to be cautious here since I'm not sure if compression (tree-sitter) will work correctly with this implementation.

My initial assumption was that we would need to properly insert the original line numbers after compression within the compress function itself.

@dorianjp
Copy link
Author

dorianjp commented Jul 14, 2025

I need to be cautious here since I'm not sure if compression (tree-sitter) will work correctly with this implementation.

My initial assumption was that we would need to properly insert the original line numbers after compression within the compress function itself.

Good call, I never tested that since I don't use the compression aspect. I found it speeds up LLM comprehension and edits by a huge factor with original line numbers, in fact some of the 'dumb' LLMs are effective now with accurate line numbers to go on, whereas before without line numbers or misleading line numbers they would just YOLO random shit or break similar but not the same code blocks for intentional edits. The 'new' line numbering actually trips up a few LLMs, which is why I made this PR.

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

Labels

None yet

2 participants