Skip to content

Commit bf1814f

Browse files
authored
Merge pull request #13 from thinkgrid-labs/dev
fix(cli): implement smart diff exclusions and memory safety guards
2 parents 0a89db3 + 0946032 commit bf1814f

12 files changed

Lines changed: 51 additions & 14 deletions

File tree

apps/local-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@diffmind/cli",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "diffmind CLI — local-first AI code review for your git diffs",
55
"author": "Thinkgrid Labs <hello@thinkgrid.com>",
66
"license": "MIT",

apps/local-cli/src/formatters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ export function filterBySeverity(report: ReviewReport, minSeverity: Severity): R
7272
}
7373

7474
export function printBanner(): void {
75-
console.log(chalk.cyan.bold("\n diffmind") + chalk.dim(" v0.4.2 — local-first AI code review"));
75+
console.log(chalk.cyan.bold("\n diffmind") + chalk.dim(" v0.4.3 — local-first AI code review"));
7676
console.log(chalk.dim(" Model: Qwen2.5-Coder-1.5B-Instruct | Inference: Dual-Engine (Native + Wasm)\n"));
7777
}

apps/local-cli/src/index.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ const MODELS: Record<string, ModelConfig> = {
6868

6969
const DEFAULT_MODEL = "1.5b";
7070

71+
/**
72+
* Common generated or dependency files that should be excluded from the AI review
73+
* to prevent massive diffs and memory exhaustion.
74+
*/
75+
const DEFAULT_IGNORED_PATHSPECS = [
76+
":!node_modules",
77+
":!*-lock.json",
78+
":!pnpm-lock.yaml",
79+
":!package-lock.json",
80+
":!yarn.lock",
81+
":!dist",
82+
":!build",
83+
":!.next",
84+
":!.cache",
85+
":!*.map",
86+
":!*.min.js",
87+
":!*.min.css",
88+
];
89+
7190
function getActiveModelId(): string {
7291
const configPath = path.join(os.homedir(), ".diffmind", "config.json");
7392
if (fs.existsSync(configPath)) {
@@ -109,7 +128,7 @@ const opts: {
109128
program
110129
.name("diffmind")
111130
.description("Local-first AI code review for your git diffs")
112-
.version("0.4.2")
131+
.version("0.4.3")
113132
.option("-b, --branch <name>", "Target branch to diff against", "main")
114133
.option("-f, --format <type>", 'Output format: "markdown" or "json"', "markdown")
115134
.option("-o, --output <file>", "Write output to a file instead of stdout")
@@ -338,11 +357,11 @@ async function getDiff(): Promise<string> {
338357
try {
339358
const result = child_process.spawnSync(
340359
"git",
341-
["diff", `${opts.branch}...HEAD`],
360+
["diff", `${opts.branch}...HEAD`, "--", ".", ...DEFAULT_IGNORED_PATHSPECS],
342361
{
343-
maxBuffer: 10 * 1024 * 1024, // 10MB max diff
362+
maxBuffer: 20 * 1024 * 1024, // 20MB max raw buffer
344363
encoding: "utf-8",
345-
shell: false, // Explicitly disable shell for security
364+
shell: false,
346365
}
347366
);
348367

@@ -354,6 +373,16 @@ async function getDiff(): Promise<string> {
354373
const sizeKB = Math.round(diff.length / 1024);
355374
spinner.succeed(`Diff captured (${sizeKB}KB)`);
356375

376+
// Hard Safety Limit: 1.5MB
377+
if (sizeKB > 1500) {
378+
spinner.fail(chalk.red(`Diff too large to process (${sizeKB}KB)`));
379+
console.log(chalk.yellow(`\n⚠️ The diff exceeds the 1.5MB safety limit for local AI.`));
380+
console.log(chalk.dim(` This is usually caused by large generated files or many changes at once.`));
381+
console.log(chalk.dim(` Try reviewing specific files or smaller branches using:`));
382+
console.log(chalk.cyan(` diffmind --branch ${opts.branch} path/to/folder\n`));
383+
process.exit(1);
384+
}
385+
357386
if (sizeKB > 500) {
358387
console.log(chalk.yellow(`\n⚠️ Warning: Large diff detected (${sizeKB}KB).`));
359388
console.log(chalk.dim(` Analyzing very large diffs can be slow on local AI and may impact quality.`));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diffmind",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"private": true,
55
"description": "Local-first AI code review agent — powered by on-device Wasm inference",
66
"author": "Thinkgrid Labs <dennis@thinkgrid.dev>",

packages/core-engine/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "core-engine"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
edition = "2021"
55
description = "diffmind shared AI engine core"
66

packages/core-engine/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,15 @@ fn chunk_diff(diff: &str, max_lines: usize) -> Vec<String> {
207207
chunks.push(std::mem::take(&mut current));
208208
line_count = 0;
209209
}
210-
current.push_str(line);
210+
211+
// Truncate extremely long lines (e.g. minified code) to prevent OOM
212+
if line.len() > 2048 {
213+
current.push_str(&line[..2048]);
214+
current.push_str("... [line truncated]");
215+
} else {
216+
current.push_str(line);
217+
}
218+
211219
current.push('\n');
212220
line_count += 1;
213221
}

packages/core-native/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "core-native"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
edition = "2021"
55

66
[lib]
1 KB
Binary file not shown.

packages/core-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@diffmind/core-native",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "Native Node.js addon for diffmind AI engine",
55
"main": "index.js",
66
"types": "index.d.ts",

packages/core-wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "core-wasm"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
edition = "2021"
55
description = "diffmind Wasm core — on-device security analysis via Qwen2.5-Coder"
66

0 commit comments

Comments
 (0)