Skip to content

Commit 55f60c8

Browse files
committed
Feature: Add source.
1 parent 790973e commit 55f60c8

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed

CodeIngest.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

CodeIngest.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeIngest", "CodeIngest.csproj", "{62FB7B79-4FBA-41F0-876A-5644EDD79A77}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{62FB7B79-4FBA-41F0-876A-5644EDD79A77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{62FB7B79-4FBA-41F0-876A-5644EDD79A77}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{62FB7B79-4FBA-41F0-876A-5644EDD79A77}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{62FB7B79-4FBA-41F0-876A-5644EDD79A77}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

Program.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace CodeIngest;
2+
3+
internal static class Program
4+
{
5+
private static void Main(string[] args)
6+
{
7+
// Getting directory argument from the command line (Report error if none found).
8+
if (args.Length != 2)
9+
{
10+
Console.WriteLine("Usage: CodeIngest <directory> <output.cs>");
11+
return;
12+
}
13+
14+
var sourceDirectory = new DirectoryInfo(args[0]);
15+
16+
// Check directory exists (Report error if not found).
17+
if (!sourceDirectory.Exists)
18+
{
19+
Console.WriteLine("Directory not found: " + sourceDirectory.FullName);
20+
return;
21+
}
22+
23+
// Recurse directory to file all .cs files.
24+
var sourceFiles =
25+
sourceDirectory
26+
.GetFiles("*.cs", SearchOption.AllDirectories)
27+
.Where(f => !ShouldSkipFile(f))
28+
.ToDictionary(o => o.FullName, o => File.ReadLines(o.FullName).Where(ShouldIncludeSourceLine).Select(s => s.Trim()));
29+
30+
// Write header.
31+
using var fileStream = new FileInfo(args[1]).Open(FileMode.Create);
32+
using var writer = new StreamWriter(fileStream);
33+
writer.WriteLine("// CodeIngest Source Dump - A CLI tool that merges and processes .cs files for GPT reviews.");
34+
writer.WriteLine("// Notes: Comments, namespaces, and using statements removed to reduce noise.");
35+
writer.WriteLine("// Language: C#");
36+
37+
// Combine files into a single output file.
38+
foreach (var kvp in sourceFiles)
39+
{
40+
var lines = kvp.Value.ToList(); // Force evaluation to count
41+
var lineCount = lines.Count;
42+
var padWidth = lineCount.ToString().Length;
43+
44+
writer.WriteLine($"// File: {kvp.Key} ({lineCount:N0} lines)");
45+
46+
var lineNumber = 1;
47+
foreach (var line in lines)
48+
writer.WriteLine($"{lineNumber++.ToString().PadLeft(padWidth)} | {line}");
49+
}
50+
51+
// Report summary.
52+
Console.WriteLine("CodeIngest completed successfully.");
53+
Console.WriteLine($"Processed {sourceFiles.Count:N0} files, producing {fileStream.Length:N0} bytes.");
54+
}
55+
56+
private static bool ShouldSkipFile(FileInfo f) =>
57+
new[] {"resx", ".g.", ".designer.", "\\obj\\", "/obj/", "\\bin\\", "/bin/", "assemblyinfo.cs" }.Any(o => f.FullName.Contains(o, StringComparison.OrdinalIgnoreCase));
58+
59+
private static bool ShouldIncludeSourceLine(string s)
60+
{
61+
if (string.IsNullOrWhiteSpace(s))
62+
return false;
63+
64+
var trimmed = s.Trim();
65+
if (trimmed.StartsWith("//"))
66+
return false;
67+
if (trimmed.StartsWith("namespace"))
68+
return false;
69+
if (trimmed.StartsWith("using"))
70+
return false;
71+
return true;
72+
}
73+
}

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
# CodeIngest
2-
CLI tool that strips and merges C# files for GPT-friendly source analysis.
2+
3+
**CodeIngest** is a cross-platform C# CLI tool that recursively scans a directory of `.cs` files, filters out noise (comments, using statements, namespaces), and generates a flattened source dump designed for GPT code review or large-scale source inspection.
4+
5+
## Features
6+
7+
- Cross-platform (.NET 6+)
8+
- Strips comments, `using` directives, and `namespace` blocks
9+
- Outputs a single readable `.cs` file with:
10+
- File headers
11+
- Line numbers
12+
- Cleaned source code
13+
- Skips generated and irrelevant files (e.g. `.designer.cs`, `bin`, `obj`, `.resx`, etc.)
14+
15+
## Usage
16+
17+
```
18+
CodeIngest.exe <source-folder> <output-file.cs>
19+
```

0 commit comments

Comments
 (0)