@@ -68,6 +68,25 @@ const MODELS: Record<string, ModelConfig> = {
6868
6969const 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+
7190function getActiveModelId ( ) : string {
7291 const configPath = path . join ( os . homedir ( ) , ".diffmind" , "config.json" ) ;
7392 if ( fs . existsSync ( configPath ) ) {
@@ -109,7 +128,7 @@ const opts: {
109128program
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.` ) ) ;
0 commit comments