ローカルディレクトリのファイル一式をNotebookLM にコードを読ませるためのツールを書いた

GoogleのNoteBookLMが優秀すぎて、コードリーディングや調査・考える系タスクが捗る。プライベートなリポジトリに関して検索対象としたいときのために、指定したローカルのディレクトリのファイル一式を一つのファイルに纏めるツールを書いた(AIに書いてもらった)。

一度ローカルにcloneする必要はあるけど、セキュア。某オンラインツールのローカル・プライベート版。

Repository

https://github.com/nakamurakzz/merge-repo

How to use

Usage:

go run combinefiles.go -repo=<repositorypath> [options]

Options:

-dir string Path to the GitHub repository(required)

-out string Path to the output file(default: “combined_output.txt”)

-ext string Target file extensions(comma-separated, e.g. 'py,js,md')

-exclude string Exclude directories(comma-separated, default: “.git,node_modules,venv,dist,build”)

-help Show this help

Example:

go run combine_files.go -dir=./my-repo -out=combined.txt -ext=py,js,md

出力してみる

go run github.com/nakamurakzz/merge-repo@latest --dir=. --ext=go
Collecting files from the repository...
Processing: main.go
Processing: main_test.go
Processing: rapper.go
Done! Combined 3 files into 'combined_output.txt'

combined_output.txt が出力される。

冒頭にファイルリストが出力される。freeコマンドのように階層構造がわかりやすいようにしようかと考えたが、対人間以外にどこまで効果があるか不明だったので、一旦相対パスでファイル名を出力するようにした。

head -n 30 combined_output.txt
# Directory structure

main.go
main_test.go
rapper.go


----------------------------------------
# File: main.go
----------------------------------------

package main

import (
	"bytes"
	"context"
	"fmt"
	"io"
	"strings"

	"golang.org/x/text/encoding/japanese"
	"golang.org/x/text/transform"
)

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

func ConvertUTF8ToSJIS(ctx context.Context, input string) (string, error) {
	var r io.ReadCloser

出力したファイルをNotebookLMに食わせる。

Have a good NotebookLM Li