codemelt 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +232 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vinnu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @codemelt/cli
|
|
2
|
+
|
|
3
|
+
Structured repository context exports for AI-assisted code understanding.
|
|
4
|
+
|
|
5
|
+
CodeMelt is a calm, developer-focused command-line tool that extracts codebase structures, configuration files, and critical modules into a single, high-density context file optimized for ingestion by LLMs.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Ensure Node.js version 18 or higher is installed.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Install globally from npm registry
|
|
15
|
+
npm install -g @codemelt/cli
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Verify that the CLI has been successfully installed:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
codemelt --version
|
|
22
|
+
codemelt --help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Core Commands & Workflow
|
|
28
|
+
|
|
29
|
+
### 1. Initialize Ignore Profile
|
|
30
|
+
Initialize a custom `.codemeltignore` file containing sensible developer defaults (ignoring build folders, dependency directories, binary files, lockfiles, and generated documents):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
codemelt init
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Export Repository Context
|
|
37
|
+
Export the directory structures and semantic file contexts into a file:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Standard markdown export to process.cwd()
|
|
41
|
+
codemelt export
|
|
42
|
+
|
|
43
|
+
# Export custom directory to XML format
|
|
44
|
+
codemelt export /path/to/project -f xml
|
|
45
|
+
|
|
46
|
+
# Export in Deep mode with a Debugging intent directive
|
|
47
|
+
codemelt export -m deep -i debugging -o build-debug-context.md
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Options & Arguments
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
Usage: codemelt export [options] [directory]
|
|
56
|
+
|
|
57
|
+
Export repository files and architecture intelligence into a structured context.
|
|
58
|
+
|
|
59
|
+
Arguments:
|
|
60
|
+
directory The path to the target directory to scan (default: process.cwd())
|
|
61
|
+
|
|
62
|
+
Options:
|
|
63
|
+
-f, --format <format> Export output format (markdown, xml) (default: "markdown")
|
|
64
|
+
-m, --mode <mode> Extraction mode (tiny, standard, deep, maximum) (default: "standard")
|
|
65
|
+
-i, --intent <intent> Context goals intention (general, debugging, onboarding, architecture, security) (default: "general")
|
|
66
|
+
-o, --output <output> Custom context export destination filename
|
|
67
|
+
-h, --help display help for command
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Export Extraction Modes
|
|
71
|
+
* **`tiny`**: Emits only critical/high-importance configurations and files (like `package.json`, `tsconfig.json`) to fit inside small prompts.
|
|
72
|
+
* **`standard`**: Excludes low-importance files and binaries; perfect for daily debugging.
|
|
73
|
+
* **`deep`**: Indexes all text files, ignoring only typical build cache outputs and media folders.
|
|
74
|
+
* **`maximum`**: Comprehensive index of everything scanned in the directory.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Ignore Resolution Rules
|
|
79
|
+
|
|
80
|
+
CodeMelt prioritizes directory stability by performing fast, early path pruning during recursion:
|
|
81
|
+
1. Loads default rules (e.g. `node_modules`, `.next`, `dist`, `.git`).
|
|
82
|
+
2. Merges `.codemeltignore` if present in the scanning root.
|
|
83
|
+
3. Merges `.gitignore` rules dynamically to align with your source control.
|
|
84
|
+
|
|
85
|
+
To add custom skips, append standard glob match patterns to your `.codemeltignore` file.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Troubleshooting
|
|
90
|
+
|
|
91
|
+
### Low Performance or RAM Spikes on Large Projects
|
|
92
|
+
* **Issue**: Scanning an enterprise monorepo or highly nested workspace is slow.
|
|
93
|
+
* **Solution**: CodeMelt uses a concurrency batch size of `20` to protect your CPU/RAM. For massive repos, refine your `.codemeltignore` to skip large generated directories (e.g. logs, testing dumps, public static assets).
|
|
94
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import ora from "ora";
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { performance } from "node:perf_hooks";
|
|
8
|
+
import { scanFiles, generateRepositoryContext, shouldIgnore } from "@codemelt/core";
|
|
9
|
+
import { DEFAULT_IGNORES, MAX_DIRECTORY_DEPTH } from "@codemelt/shared";
|
|
10
|
+
const majorNodeVersion = parseInt(process.versions.node.split(".")[0], 10);
|
|
11
|
+
if (majorNodeVersion < 18) {
|
|
12
|
+
console.error("Error: CodeMelt requires Node.js version 18 or higher.");
|
|
13
|
+
console.error(`Current version: ${process.versions.node}`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const program = new Command();
|
|
17
|
+
program
|
|
18
|
+
.name("codemelt")
|
|
19
|
+
.description("Repository intelligence and structured context exports for modern codebases.")
|
|
20
|
+
.version("0.1.0");
|
|
21
|
+
// --- Helper: Parse ignore rules file lines ---
|
|
22
|
+
function parseIgnoreFile(content) {
|
|
23
|
+
return content
|
|
24
|
+
.split("\n")
|
|
25
|
+
.map(line => line.trim())
|
|
26
|
+
.filter(line => line && !line.startsWith("#") && !line.startsWith("!"));
|
|
27
|
+
}
|
|
28
|
+
// --- Helper: Traverse directory recursively with early-pruning & concurrency ---
|
|
29
|
+
async function getFilesRecursively(dir, baseDir, rules, depth = 0) {
|
|
30
|
+
if (depth > MAX_DIRECTORY_DEPTH)
|
|
31
|
+
return []; // Enforce maximum directory depth
|
|
32
|
+
const list = await fs.readdir(dir);
|
|
33
|
+
list.sort(); // Deterministic folder list sorting
|
|
34
|
+
const BATCH_SIZE = 20;
|
|
35
|
+
const results = [];
|
|
36
|
+
for (let offset = 0; offset < list.length; offset += BATCH_SIZE) {
|
|
37
|
+
const batch = list.slice(offset, offset + BATCH_SIZE);
|
|
38
|
+
const batchResults = await Promise.all(batch.map(async (file) => {
|
|
39
|
+
const absolutePath = path.join(dir, file);
|
|
40
|
+
const relativePath = path.relative(baseDir, absolutePath);
|
|
41
|
+
// Early Pruning: skip immediately if ignored
|
|
42
|
+
if (shouldIgnore(relativePath, rules)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const stat = await fs.lstat(absolutePath);
|
|
47
|
+
if (stat.isSymbolicLink()) {
|
|
48
|
+
return []; // Protect against symlink loops
|
|
49
|
+
}
|
|
50
|
+
if (stat.isDirectory()) {
|
|
51
|
+
return await getFilesRecursively(absolutePath, baseDir, rules, depth + 1);
|
|
52
|
+
}
|
|
53
|
+
else if (stat.isFile()) {
|
|
54
|
+
return [{
|
|
55
|
+
name: file,
|
|
56
|
+
path: relativePath,
|
|
57
|
+
size: stat.size,
|
|
58
|
+
text: () => fs.readFile(absolutePath, "utf8"),
|
|
59
|
+
readChunk: async (bytes) => {
|
|
60
|
+
const fd = await fs.open(absolutePath, 'r');
|
|
61
|
+
const buffer = Buffer.alloc(bytes);
|
|
62
|
+
const { bytesRead } = await fs.read(fd, buffer, 0, bytes, 0);
|
|
63
|
+
await fs.close(fd);
|
|
64
|
+
return buffer.subarray(0, bytesRead);
|
|
65
|
+
}
|
|
66
|
+
}];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Safe boundary fallback for traversal failures
|
|
71
|
+
}
|
|
72
|
+
return [];
|
|
73
|
+
}));
|
|
74
|
+
for (const batchResult of batchResults) {
|
|
75
|
+
results.push(...batchResult);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Deterministic sorting of paths for reproducible outputs
|
|
79
|
+
results.sort((a, b) => a.path.localeCompare(b.path));
|
|
80
|
+
return results;
|
|
81
|
+
}
|
|
82
|
+
// --- COMMAND: init ---
|
|
83
|
+
program
|
|
84
|
+
.command("init")
|
|
85
|
+
.description("Initialize a custom .codemeltignore file with standard dev-tooling defaults.")
|
|
86
|
+
.action(async () => {
|
|
87
|
+
const ignorePath = path.join(process.cwd(), ".codemeltignore");
|
|
88
|
+
if (await fs.pathExists(ignorePath)) {
|
|
89
|
+
console.log(chalk.yellow("ℹ .codemeltignore already exists in this folder."));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const defaults = parseIgnoreFile(`
|
|
93
|
+
# Dependencies & package caches
|
|
94
|
+
node_modules
|
|
95
|
+
dist
|
|
96
|
+
build
|
|
97
|
+
.next
|
|
98
|
+
coverage
|
|
99
|
+
*.log
|
|
100
|
+
|
|
101
|
+
# Environment configs & lockfiles
|
|
102
|
+
.env
|
|
103
|
+
.env.*
|
|
104
|
+
package-lock.json
|
|
105
|
+
pnpm-lock.yaml
|
|
106
|
+
yarn.lock
|
|
107
|
+
.DS_Store
|
|
108
|
+
Thumbs.db
|
|
109
|
+
*.tsbuildinfo
|
|
110
|
+
|
|
111
|
+
# Media and asset structures
|
|
112
|
+
*.png
|
|
113
|
+
*.jpg
|
|
114
|
+
*.jpeg
|
|
115
|
+
*.gif
|
|
116
|
+
*.webp
|
|
117
|
+
*.ico
|
|
118
|
+
*.mp4
|
|
119
|
+
*.mp3
|
|
120
|
+
*.zip
|
|
121
|
+
*.tar
|
|
122
|
+
*.gz
|
|
123
|
+
*.tar.gz
|
|
124
|
+
*.tgz
|
|
125
|
+
|
|
126
|
+
# Generated Context
|
|
127
|
+
codemelt-context.md
|
|
128
|
+
codemelt-context.xml
|
|
129
|
+
`);
|
|
130
|
+
await fs.writeFile(ignorePath, defaults.join("\n") + "\n", "utf8");
|
|
131
|
+
console.log(chalk.green("✔ Generated .codemeltignore with sensible defaults."));
|
|
132
|
+
});
|
|
133
|
+
// --- COMMAND: export ---
|
|
134
|
+
program
|
|
135
|
+
.command("export [directory]")
|
|
136
|
+
.description("Export repository files and architecture intelligence into a structured context.")
|
|
137
|
+
.option("-f, --format <format>", "Export output format (markdown, xml)", "markdown")
|
|
138
|
+
.option("-m, --mode <mode>", "Extraction mode details (tiny, standard, deep, maximum)", "standard")
|
|
139
|
+
.option("-i, --intent <intent>", "Context goals intention (general, debugging, onboarding, architecture, security)", "general")
|
|
140
|
+
.option("-o, --output <output>", "Custom context export destination filename")
|
|
141
|
+
.action(async (directory, options) => {
|
|
142
|
+
const targetDir = directory ? path.resolve(directory) : process.cwd();
|
|
143
|
+
if (!(await fs.pathExists(targetDir))) {
|
|
144
|
+
console.error(chalk.red(`Error: Target directory '${targetDir}' does not exist.`));
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
const startedAt = performance.now();
|
|
148
|
+
const spinner = ora("Scanning repository files...").start();
|
|
149
|
+
// Clean interrupts SIGINT handler
|
|
150
|
+
const sigintHandler = () => {
|
|
151
|
+
spinner.stop();
|
|
152
|
+
console.log(chalk.yellow("\n[CodeMelt] Export cancelled by user."));
|
|
153
|
+
process.exit(130);
|
|
154
|
+
};
|
|
155
|
+
process.on("SIGINT", sigintHandler);
|
|
156
|
+
try {
|
|
157
|
+
// 1. Resolve ignore rules database (.codemeltignore preferred, fallback to .reporazorignore, then .packoraignore, then optional .gitignore)
|
|
158
|
+
let ignoreRules = [...DEFAULT_IGNORES];
|
|
159
|
+
const codemeltignorePath = path.join(targetDir, ".codemeltignore");
|
|
160
|
+
const reporazorignorePath = path.join(targetDir, ".reporazorignore");
|
|
161
|
+
const packoraignorePath = path.join(targetDir, ".packoraignore");
|
|
162
|
+
if (await fs.pathExists(codemeltignorePath)) {
|
|
163
|
+
const content = await fs.readFile(codemeltignorePath, "utf8");
|
|
164
|
+
ignoreRules = parseIgnoreFile(content);
|
|
165
|
+
}
|
|
166
|
+
else if (await fs.pathExists(reporazorignorePath)) {
|
|
167
|
+
const content = await fs.readFile(reporazorignorePath, "utf8");
|
|
168
|
+
ignoreRules = parseIgnoreFile(content);
|
|
169
|
+
console.log(chalk.yellow("ℹ Using existing .reporazorignore as fallback for .codemeltignore."));
|
|
170
|
+
}
|
|
171
|
+
else if (await fs.pathExists(packoraignorePath)) {
|
|
172
|
+
const content = await fs.readFile(packoraignorePath, "utf8");
|
|
173
|
+
ignoreRules = parseIgnoreFile(content);
|
|
174
|
+
console.log(chalk.yellow("ℹ Using existing .packoraignore as fallback for .codemeltignore."));
|
|
175
|
+
}
|
|
176
|
+
// Merge .gitignore constraints dynamically
|
|
177
|
+
const gitignorePath = path.join(targetDir, ".gitignore");
|
|
178
|
+
if (await fs.pathExists(gitignorePath)) {
|
|
179
|
+
const content = await fs.readFile(gitignorePath, "utf8");
|
|
180
|
+
const gitRules = parseIgnoreFile(content);
|
|
181
|
+
for (const rule of gitRules) {
|
|
182
|
+
if (!ignoreRules.includes(rule)) {
|
|
183
|
+
ignoreRules.push(rule);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// 2. Scan and traverse files recursively with early path exclusions
|
|
188
|
+
const rawFiles = await getFilesRecursively(targetDir, targetDir, ignoreRules);
|
|
189
|
+
const totalBytes = rawFiles.reduce((acc, f) => acc + f.size, 0);
|
|
190
|
+
if (rawFiles.length > 500 || totalBytes > 10 * 1024 * 1024) {
|
|
191
|
+
spinner.stop();
|
|
192
|
+
console.log(chalk.yellow("\n⚠ Large repository detected. Export may take longer and use significant system resources."));
|
|
193
|
+
console.log(chalk.yellow("Consider using --mode tiny or --mode standard for reduced memory usage."));
|
|
194
|
+
console.log(chalk.yellow("Press Ctrl+C anytime to cancel.\n"));
|
|
195
|
+
spinner.start("Analyzing codebase structure...");
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
spinner.text = "Analyzing codebase structure...";
|
|
199
|
+
}
|
|
200
|
+
// 3. Scan files using core engine
|
|
201
|
+
const scanResult = await scanFiles(rawFiles, ignoreRules);
|
|
202
|
+
spinner.text = "Compiling semantic context maps...";
|
|
203
|
+
// 4. Generate structured context synthesizers
|
|
204
|
+
const formatVal = options.format === "xml" ? "xml" : "markdown";
|
|
205
|
+
const modeVal = options.mode;
|
|
206
|
+
const intentVal = options.intent;
|
|
207
|
+
const outputContent = generateRepositoryContext(scanResult.scannedFiles, formatVal, modeVal, intentVal);
|
|
208
|
+
// 5. Save context file safely
|
|
209
|
+
const ext = formatVal === "xml" ? "xml" : "md";
|
|
210
|
+
const defaultFilename = `codemelt-context.${ext}`;
|
|
211
|
+
const finalFilename = options.output ? options.output : defaultFilename;
|
|
212
|
+
const outputPath = path.resolve(targetDir, finalFilename);
|
|
213
|
+
await fs.writeFile(outputPath, outputContent, "utf8");
|
|
214
|
+
spinner.stop();
|
|
215
|
+
process.off("SIGINT", sigintHandler);
|
|
216
|
+
// Professional, calm progress ticks (no meme/ASCII spam)
|
|
217
|
+
console.log(chalk.green("✔ Repository scanned"));
|
|
218
|
+
console.log(chalk.green("✔ Ignore rules applied"));
|
|
219
|
+
console.log(chalk.green("✔ Export generated"));
|
|
220
|
+
const duration = ((performance.now() - startedAt) / 1000).toFixed(2);
|
|
221
|
+
console.log(`Files processed: ${scanResult.scannedFiles.length}`);
|
|
222
|
+
console.log(`Completed in ${duration}s`);
|
|
223
|
+
console.log(chalk.gray(`Output: ${path.relative(process.cwd(), outputPath)}`));
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
spinner.stop();
|
|
227
|
+
process.off("SIGINT", sigintHandler);
|
|
228
|
+
console.error(chalk.red(`✖ Failed to export repository context: ${error.message}`));
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "codemelt",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"codemelt": "dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"chalk": "^5.3.0",
|
|
27
|
+
"commander": "^12.1.0",
|
|
28
|
+
"fs-extra": "^11.2.0",
|
|
29
|
+
"ora": "^8.0.1",
|
|
30
|
+
"codemelt-core": "^0.1.0",
|
|
31
|
+
"@codemelt/shared": "^0.1.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/fs-extra": "^11.0.4",
|
|
35
|
+
"@types/node": "^20.0.0",
|
|
36
|
+
"typescript": "^5.0.0"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
}
|
|
42
|
+
}
|