AI

【AI】RepomixでLLMが理解しやすいコードに変換!

AIを用いて開発していると、いろんなファイルを一括で見て一気に質問したいシーンなどがあるかと思います。その際に便利なのがこのRepomixというツールで、リポジトリの内容を1ファイルにまとめることができます!

https://zenn.dev/yamadashy/articles/ai-tool-repomix-5000-star

インストール

https://github.com/yamadashy/repomix

npmやyarn、 Homebrewでインストールできます。

# Install using npm
npm install -g repomix

# Alternatively using yarn
yarn global add repomix

# Alternatively using Homebrew (macOS/Linux)
brew install repomix

使い方

# npmでインストールした場合
npx repomix

# Homebrewでインストールした場合
repomix

AI用にまとめたいファイルが有るフォルダで実行すると、同一フォルダ以下のファイルを再帰的に参照しアーカイブしてくれます。

.
├── forder1
│   └── main.go
└── forder2
    └── dir2-1
        └── script.py

repomix-output.txt というファイルが生成され、中身は以下のようにAIが認識しやすいように1ファイルにまとめられています!

This file is a merged representation of the entire codebase, combined into a single document by Repomix.

================================================================
File Summary
================================================================

Purpose:
--------
This file contains a packed representation of the entire repository's contents.
It is designed to be easily consumable by AI systems for analysis, code review,
or other automated processes.

File Format:
------------
The content is organized as follows:
1. This summary section
2. Repository information
3. Directory structure
4. Multiple file entries, each consisting of:
  a. A separator line (================)
  b. The file path (File: path/to/file)
  c. Another separator line
  d. The full contents of the file
  e. A blank line

Usage Guidelines:
-----------------
- This file should be treated as read-only. Any changes should be made to the
  original repository files, not this packed version.
- When processing this file, use the file path to distinguish
  between different files in the repository.
- Be aware that this file may contain sensitive information. Handle it with
  the same level of security as you would the original repository.

Notes:
------
- Some files may have been excluded based on .gitignore rules and Repomix's configuration
- Binary files are not included in this packed representation. Please refer to the Repository Structure section for a complete list of file paths, including binary files
- Files matching patterns in .gitignore are excluded
- Files matching default ignore patterns are excluded

Additional Info:
----------------

================================================================
Directory Structure
================================================================
forder1/
  main.go
forder2/
  dir2-1/
    script.py

================================================================
Files
================================================================

================
File: forder1/main.go
================
package main

import "fmt"

func main() {
	sayHello()
}

func sayHello() {
	fmt.Println("Hello, World!")
}

================
File: forder2/dir2-1/script.py
================
def greet(name: str = "World") -> str:
    """
    Returns a greeting message for the given name.

    Args:
        name (str): Name to greet, defaults to "World"

    Returns:
        str: Formatted greeting message
    """
    return f"Hello, {name}!"

def main():
    # Example usage with different names
    print(greet())  # Default greeting
    print(greet("Alice"))
    print(greet("Bob"))

if __name__ == "__main__":
    main()



================================================================
End of Codebase
================================================================

このツールを使うとLLMに与えるデータソースを1つに集約できるので、AI利用回数の削減だったり、何度もファイルを添付したりする手間がかなり減ります!特にOllamaやAnythingLLMのようなローカルでのAI活用ツールと合わせると相性が良さそうです!

-AI