11package cli
22
33import (
4+ "encoding/json"
45 "fmt"
56 "os"
67 "path/filepath"
@@ -9,16 +10,19 @@ import (
910
1011 "github.com/randomcodespace/codeiq/internal/analyzer"
1112 "github.com/randomcodespace/codeiq/internal/cache"
13+ "github.com/randomcodespace/codeiq/internal/detector"
1214 "github.com/spf13/cobra"
1315)
1416
1517func init () {
1618 registerSubcommand (func () * cobra.Command {
1719 var (
18- graphDir string
19- memProfile string
20- maxBufferPool int64
21- copyThreads int
20+ graphDir string
21+ memProfile string
22+ maxBufferPool int64
23+ copyThreads int
24+ force bool
25+ diffOnly bool
2226 )
2327 cmd := & cobra.Command {
2428 Use : "enrich [path]" ,
@@ -56,7 +60,34 @@ become available and the stdio MCP server can serve clients.`,
5660 return fmt .Errorf ("open cache %s: %w" , cachePath , err )
5761 }
5862 defer c .Close ()
59- opts := analyzer.EnrichOptions {GraphDir : graphDir }
63+
64+ // --diff: print Diff against the cache as JSON and exit.
65+ // Does not touch the graph. Useful for previewing what an
66+ // incremental enrich would do.
67+ if diffOnly {
68+ a := analyzer .NewAnalyzer (analyzer.Options {Cache : c , Registry : detector .Default })
69+ d , dErr := a .Diff (root )
70+ if dErr != nil {
71+ return dErr
72+ }
73+ out := map [string ]any {
74+ "added" : d .Added ,
75+ "modified" : d .Modified ,
76+ "deleted" : d .Deleted ,
77+ "unchanged" : d .Unchanged ,
78+ "counts" : map [string ]int {
79+ "added" : len (d .Added ),
80+ "modified" : len (d .Modified ),
81+ "deleted" : len (d .Deleted ),
82+ "unchanged" : len (d .Unchanged ),
83+ },
84+ }
85+ enc := json .NewEncoder (cmd .OutOrStdout ())
86+ enc .SetIndent ("" , " " )
87+ return enc .Encode (out )
88+ }
89+
90+ opts := analyzer.EnrichOptions {GraphDir : graphDir , Force : force }
6091 if maxBufferPool > 0 {
6192 opts .StoreBufferPoolBytes = uint64 (maxBufferPool )
6293 }
@@ -79,9 +110,14 @@ become available and the stdio MCP server can serve clients.`,
79110 }
80111 fmt .Fprintf (cmd .ErrOrStderr (), "heap profile written to %s\n " , memProfile )
81112 }
82- fmt .Fprintf (cmd .OutOrStdout (),
83- "enrich complete: %d nodes, %d edges, %d services\n " ,
84- summary .Nodes , summary .Edges , summary .Services )
113+ if summary .ShortCircuited {
114+ fmt .Fprintln (cmd .OutOrStdout (),
115+ "enrich short-circuited: graph already matches cache manifest" )
116+ } else {
117+ fmt .Fprintf (cmd .OutOrStdout (),
118+ "enrich complete: %d nodes, %d edges, %d services\n " ,
119+ summary .Nodes , summary .Edges , summary .Services )
120+ }
85121 return nil
86122 },
87123 }
@@ -93,6 +129,10 @@ become available and the stdio MCP server can serve clients.`,
93129 "Cap Kuzu BufferPoolSize in bytes (default: 2 GiB; 0 means default)." )
94130 cmd .Flags ().IntVar (& copyThreads , "copy-threads" , 0 ,
95131 "Cap Kuzu COPY FROM parallelism (default: min(4, GOMAXPROCS); 0 means default)." )
132+ cmd .Flags ().BoolVar (& force , "force" , false ,
133+ "Bypass the incremental short-circuit; rebuild the graph from scratch." )
134+ cmd .Flags ().BoolVar (& diffOnly , "diff" , false ,
135+ "Print the cache vs disk delta as JSON and exit without touching the graph." )
96136 return cmd
97137 })
98138}
0 commit comments