-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
940 lines (797 loc) · 31.8 KB
/
Program.cs
File metadata and controls
940 lines (797 loc) · 31.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
using System.Reflection;
using CodeScan.Commands;
using CodeScan.Services;
using CodeScan.Tui;
namespace CodeScan;
class Program
{
static string Version =>
typeof(Program).Assembly
.GetCustomAttribute<System.Reflection.AssemblyInformationalVersionAttribute>()
?.InformationalVersion?.Split('+')[0] ?? "0.0.0";
static SqliteStore OpenDb() => new(AppPaths.DbPath);
static int Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
if (args.Length == 0)
{
PrintHelp();
return 0;
}
var globalArgs = ParseGlobalOptions(args, out var remaining);
if (globalArgs.ShowHelp && remaining.Length == 0)
{
PrintHelp();
return 0;
}
if (globalArgs.ShowVersion)
{
Console.WriteLine($"codescan v{Version}");
return 0;
}
if (remaining.Length == 0)
{
PrintHelp();
return 0;
}
var command = remaining[0].ToLowerInvariant();
var commandArgs = remaining[1..];
return command switch
{
"scan" => RunScan(commandArgs, globalArgs),
"list" => RunList(commandArgs, globalArgs),
"search" => RunSearch(commandArgs),
"graph" => RunGraph(commandArgs),
"query" or "cypher" => RunGraphQuery(commandArgs),
"gui" => RunGui(commandArgs),
"projects" => RunProjects(commandArgs),
"project" => RunProject(commandArgs),
"project-addinfo" => RunProjectAddInfo(commandArgs),
"project-update" => RunProjectUpdate(commandArgs),
"project-delete" => RunProjectDelete(commandArgs),
"tui" => RunTui(),
"semantic" => RunSemantic(commandArgs),
"graph-edit" => RunGraphEdit(commandArgs),
"help" => RunHelp(commandArgs),
_ => UnknownCommand(command)
};
}
static int RunSemantic(string[] args) => new SemanticCommand().Execute(args);
static int RunGraphEdit(string[] args)
{
using var db = OpenDb();
return new GraphEditCommand(db).Execute(args);
}
static int RunScan(string[] args, GlobalOptions global)
{
if (global.ShowHelp || (args.Length > 0 && args[0] is "-h" or "--help"))
{
PrintScanHelp();
return 0;
}
// scan = list --detail --tree --stats (defaults applied)
var scanArgs = new List<string>();
string? path = null;
for (int i = 0; i < args.Length; i++)
{
switch (args[i])
{
case "-i" or "--include" when i + 1 < args.Length:
scanArgs.Add(args[i]);
scanArgs.Add(args[++i]);
break;
case "-e" or "--exclude" when i + 1 < args.Length:
scanArgs.Add(args[i]);
scanArgs.Add(args[++i]);
break;
case "-d" or "--depth" when i + 1 < args.Length:
scanArgs.Add(args[i]);
scanArgs.Add(args[++i]);
break;
default:
if (!args[i].StartsWith('-') && path == null)
path = args[i];
else
scanArgs.Add(args[i]);
break;
}
}
// Default path: current directory
path ??= ".";
scanArgs.Insert(0, path);
// Always enable --detail --tree --stats for scan
if (!scanArgs.Contains("--detail")) scanArgs.Add("--detail");
if (!scanArgs.Contains("--tree")) scanArgs.Add("--tree");
if (!scanArgs.Contains("-s") && !scanArgs.Contains("--stats")) scanArgs.Add("--stats");
return RunList(scanArgs.ToArray(), global);
}
static int RunList(string[] args, GlobalOptions global)
{
if (global.ShowHelp)
{
PrintListHelp();
return 0;
}
var options = new ListOptions();
string? path = null;
for (int i = 0; i < args.Length; i++)
{
switch (args[i])
{
case "-h" or "--help":
PrintListHelp();
return 0;
case "-i" or "--include" when i + 1 < args.Length:
options.Include = [.. args[++i].Split(',', StringSplitOptions.RemoveEmptyEntries)];
break;
case "-e" or "--exclude" when i + 1 < args.Length:
options.Exclude = [.. args[++i].Split(',', StringSplitOptions.RemoveEmptyEntries)];
break;
case "-d" or "--depth" when i + 1 < args.Length:
if (int.TryParse(args[++i], out var depth))
options.Depth = depth;
break;
case "--tree":
options.Tree = true;
break;
case "-s" or "--stats":
options.Stats = true;
break;
case "--detail":
options.Detail = true;
break;
default:
if (!args[i].StartsWith('-') && path == null)
path = args[i];
break;
}
}
if (path == null)
{
Console.Error.WriteLine("Error: path is required.");
Console.Error.WriteLine("Usage: codescan list <path> [options]");
return 1;
}
IResultStore? store = null;
if (global.DevMode)
{
store = new FileResultStore(AppPaths.GetLogDir());
}
options.Verbose = global.Verbose;
using var db = OpenDb();
var cmd = new ListCommand(store, db);
return cmd.Execute(path, options);
}
static int RunSearch(string[] args)
{
string? query = null;
var options = new SearchOptions();
for (int i = 0; i < args.Length; i++)
{
switch (args[i])
{
case "-t" or "--type" when i + 1 < args.Length:
options.Type = args[++i];
break;
case "-l" or "--limit" when i + 1 < args.Length:
if (int.TryParse(args[++i], out var lim))
options.Limit = lim;
break;
case "-p" or "--project" when i + 1 < args.Length:
if (long.TryParse(args[++i], out var pid))
options.ProjectId = pid;
break;
case "--graph":
options.Graph = true;
break;
case "--query" or "--cypher":
options.Graph = true;
options.GraphQuery = true;
break;
case "--depth" when i + 1 < args.Length:
if (int.TryParse(args[++i], out var depth))
options.GraphDepth = depth;
break;
case "-h" or "--help":
PrintSearchHelp();
return 0;
default:
if (!args[i].StartsWith('-') && query == null)
query = args[i];
break;
}
}
if (query == null)
{
Console.Error.WriteLine("Error: search query is required.");
Console.Error.WriteLine("Usage: codescan search <query> [options]");
return 1;
}
using var db = OpenDb();
var cmd = new SearchCommand(db);
return cmd.Execute(query, options);
}
static int RunGraph(string[] args)
{
string query = "";
var options = new GraphOptions();
for (int i = 0; i < args.Length; i++)
{
switch (args[i])
{
case "-l" or "--limit" when i + 1 < args.Length:
if (int.TryParse(args[++i], out var lim))
options.Limit = lim;
break;
case "-p" or "--project" when i + 1 < args.Length:
if (long.TryParse(args[++i], out var pid))
options.ProjectId = pid;
break;
case "-d" or "--depth" when i + 1 < args.Length:
if (int.TryParse(args[++i], out var depth))
options.Depth = depth;
break;
case "-h" or "--help":
PrintGraphHelp();
return 0;
default:
if (!args[i].StartsWith('-') && string.IsNullOrEmpty(query))
query = args[i];
break;
}
}
using var db = OpenDb();
var cmd = new GraphCommand(db);
return cmd.Execute(query, options);
}
static int RunGraphQuery(string[] args)
{
string query = "";
var options = new GraphOptions();
for (int i = 0; i < args.Length; i++)
{
switch (args[i])
{
case "-l" or "--limit" when i + 1 < args.Length:
if (int.TryParse(args[++i], out var lim))
options.Limit = lim;
break;
case "-p" or "--project" when i + 1 < args.Length:
if (long.TryParse(args[++i], out var pid))
options.ProjectId = pid;
break;
case "-d" or "--depth" when i + 1 < args.Length:
if (int.TryParse(args[++i], out var depth))
options.Depth = depth;
break;
case "-h" or "--help":
PrintGraphQueryHelp();
return 0;
default:
if (!args[i].StartsWith('-') && string.IsNullOrEmpty(query))
query = args[i];
break;
}
}
if (string.IsNullOrWhiteSpace(query))
{
Console.Error.WriteLine("Error: graph query is required.");
Console.Error.WriteLine("Usage: codescan query \"MATCH (n:class) WHERE n.label CONTAINS 'HttpClient' LIMIT 20\"");
return 1;
}
using var db = OpenDb();
var cmd = new GraphCommand(db);
return cmd.ExecuteQuery(query, options);
}
static int RunGui(string[] args)
{
if (args.Length == 0 || args[0] is "-h" or "--help")
{
PrintGuiHelp();
return args.Length > 0 ? 0 : 1;
}
var action = args[0].ToLowerInvariant();
var port = 8085;
for (int i = 1; i < args.Length; i++)
{
if (args[i] is "-p" or "--port" && i + 1 < args.Length && int.TryParse(args[++i], out var parsedPort))
port = parsedPort;
}
return action switch
{
"start" => GuiCommand.Start(port),
"stop" => GuiCommand.Stop(port),
_ => UnknownCommand($"gui {action}")
};
}
static int RunProjects(string[] args)
{
if (args.Length > 0 && args[0] is "-h" or "--help")
{
PrintProjectsHelp();
return 0;
}
using var db = OpenDb();
var cmd = new ProjectsCommand(db);
return cmd.Execute();
}
static int RunProject(string[] args)
{
if (args.Length == 0 || args[0] is "-h" or "--help")
{
PrintProjectHelp();
return args.Length > 0 ? 0 : 1;
}
if (!long.TryParse(args[0], out var projectId))
{
Console.Error.WriteLine($"Error: invalid project ID '{args[0]}'");
return 1;
}
bool detail = args.Any(a => a is "--detail");
using var db = OpenDb();
var cmd = new ProjectCommand(db);
return cmd.Execute(projectId, detail);
}
static int RunProjectAddInfo(string[] args)
{
if (args.Length < 2 || args[0] is "-h" or "--help")
{
PrintProjectAddInfoHelp();
return args.Length > 0 && args[0] is "-h" or "--help" ? 0 : 1;
}
if (!long.TryParse(args[0], out var projectId))
{
Console.Error.WriteLine($"Error: invalid project ID '{args[0]}'");
return 1;
}
var description = string.Join(" ", args[1..]);
using var db = OpenDb();
var cmd = new ProjectAddInfoCommand(db);
return cmd.Execute(projectId, description);
}
static int RunProjectUpdate(string[] args)
{
if (args.Length < 2 || args[0] is "-h" or "--help")
{
PrintProjectUpdateHelp();
return args.Length > 0 && args[0] is "-h" or "--help" ? 0 : 1;
}
if (!long.TryParse(args[0], out var projectId))
{
Console.Error.WriteLine($"Error: invalid project ID '{args[0]}'");
return 1;
}
string? newPath = null;
string? newAddInfo = null;
bool sourceUpdate = false;
// First pass: extract --source and --path (non-greedy flags)
var addinfoArgs = new List<string>();
bool collectingAddinfo = false;
for (int i = 1; i < args.Length; i++)
{
if (collectingAddinfo)
{
addinfoArgs.Add(args[i]);
continue;
}
switch (args[i])
{
case "--path" when i + 1 < args.Length:
newPath = args[++i];
break;
case "--source":
sourceUpdate = true;
break;
case "--addinfo" when i + 1 < args.Length:
collectingAddinfo = true;
break;
}
}
if (addinfoArgs.Count > 0)
{
// Filter out any flags that got swept in
var textParts = addinfoArgs.Where(a => a is not "--source" and not "--path").ToList();
if (textParts.Count > 0)
newAddInfo = string.Join(" ", textParts);
// Check if --source was in the addinfo tail
if (addinfoArgs.Contains("--source"))
sourceUpdate = true;
}
using var db = OpenDb();
var cmd = new ProjectUpdateCommand(db);
return cmd.Execute(projectId, newPath, newAddInfo, sourceUpdate);
}
static int RunProjectDelete(string[] args)
{
if (args.Length == 0 || args[0] is "-h" or "--help")
{
PrintProjectDeleteHelp();
return args.Length > 0 ? 0 : 1;
}
if (!long.TryParse(args[0], out var projectId))
{
Console.Error.WriteLine($"Error: invalid project ID '{args[0]}'");
return 1;
}
bool force = args.Any(a => a is "-f" or "--force");
using var db = OpenDb();
var cmd = new ProjectDeleteCommand(db);
return cmd.Execute(projectId, force);
}
static int RunTui()
{
var app = new TuiApp();
app.Run();
return 0;
}
static int RunHelp(string[] args)
{
if (args.Length == 0)
{
PrintHelp();
return 0;
}
switch (args[0].ToLowerInvariant())
{
case "scan": PrintScanHelp(); break;
case "list": PrintListHelp(); break;
case "search": PrintSearchHelp(); break;
case "graph": PrintGraphHelp(); break;
case "query":
case "cypher": PrintGraphQueryHelp(); break;
case "gui": PrintGuiHelp(); break;
case "projects": PrintProjectsHelp(); break;
case "project": PrintProjectHelp(); break;
case "project-addinfo": PrintProjectAddInfoHelp(); break;
case "project-update": PrintProjectUpdateHelp(); break;
case "project-delete": PrintProjectDeleteHelp(); break;
case "tui": Console.WriteLine(" codescan tui - Interactive TUI mode."); break;
default:
Console.WriteLine($"Unknown command: {args[0]}");
PrintHelp();
break;
}
return 0;
}
static int UnknownCommand(string command)
{
Console.Error.WriteLine($"Unknown command: {command}");
Console.Error.WriteLine("Run 'codescan --help' to see available commands.");
return 1;
}
static GlobalOptions ParseGlobalOptions(string[] args, out string[] remaining)
{
var global = new GlobalOptions();
var rest = new List<string>();
bool commandFound = false;
for (int i = 0; i < args.Length; i++)
{
// Once a command word is found, pass everything else through
if (commandFound)
{
rest.Add(args[i]);
continue;
}
switch (args[i])
{
case "-h" or "--help": global.ShowHelp = true; break;
case "-v" or "--version": global.ShowVersion = true; break;
case "--verbose": global.Verbose = true; break;
case "--devmode": global.DevMode = true; break;
default:
rest.Add(args[i]);
if (!args[i].StartsWith('-'))
commandFound = true;
break;
}
}
remaining = rest.ToArray();
return global;
}
static void PrintHelp()
{
Console.WriteLine($"""
codescan v{Version} - Code Scanner & Indexer
Usage: codescan [command] [options]
Commands:
scan [path] Scan & register project (= list --detail --tree --stats)
list <path> Scan directory with custom options
search <query> Search indexed methods, files, and docs
graph [query] Search/browse source knowledge graph
query <graph-query> Run Cypher-like graph query subset
gui start|stop Start/stop local web GUI viewer
projects List all indexed projects
project <id> [--detail] Show project info (summary / detail)
project-addinfo <id> <text> Add description to a project
project-update <id> [opts] Update project fields (path, addinfo, source)
project-delete <id> Delete a project from DB
tui Interactive TUI mode
semantic <sub> Compiler-backed analysis via docker (Phase 1 PoC)
graph-edit <sub> Manually curate graph nodes/edges (LLM-friendly)
help [command] Show help
Global Options:
-h, --help Show help
-v, --version Show version
--verbose Verbose output
--devmode Also save results to ~/.codescan/logs/ as log files
Data:
DB: ~/.codescan/db/codescan.db
Logs: ~/.codescan/logs/
Quick Start:
codescan scan Scan current directory
codescan scan D:\Code\MyProject Scan specific project
codescan projects See registered projects
codescan project 1 View project summary
codescan project 1 --detail View full project detail
codescan project-addinfo 1 "description" Add project description
codescan project-update 1 --path D:\new Update project path
codescan project-update 1 --source Full rescan (git pull + scan)
codescan project-delete 1 Delete project from DB
codescan search "HttpClient" Search across all projects
codescan search "HttpClient" --graph Graph search
codescan query "MATCH (c:class)-[r:uses_type]->(t:type) LIMIT 20"
codescan gui start --port 8085 Start web GUI viewer
""");
}
static void PrintScanHelp()
{
Console.WriteLine("""
codescan scan - Scan & register a project to DB
Usage: codescan scan [path] [options]
Scans a directory, analyzes source code (class:method + git blame +
comments), and indexes everything to the local DB. This is the
recommended way to register a new project.
If [path] is omitted, scans the current directory.
Equivalent to: codescan list <path> --detail --tree --stats
Options:
-i, --include <exts> Include extensions (comma-sep, e.g. .cs,.js)
-e, --exclude <dirs> Exclude directories (comma-sep, e.g. bin,obj)
-d, --depth <n> Max traversal depth
-h, --help Show help
Examples:
codescan scan Scan current directory
codescan scan D:\Code\MyProject Scan specific path
codescan scan ./src -i ".cs,.js" Scan with extension filter
codescan scan . --depth 3 Scan with depth limit
After scanning:
codescan projects See all registered projects
codescan project <id> View project detail
codescan project-addinfo <id> "text" Add project description
""");
}
static void PrintListHelp()
{
Console.WriteLine("""
codescan list - Scan directory, analyze source, and index to DB
Usage: codescan list <path> [options]
Options:
-i, --include <exts> Include extensions (comma-sep, e.g. .cs,.js)
-e, --exclude <dirs> Exclude directories (comma-sep, e.g. bin,obj)
-d, --depth <n> Max traversal depth
--tree Tree format output
-s, --stats Include file/size statistics
--detail Analyze class:method + git blame per source file
-h, --help Show help
Notes:
Results are always saved to ~/.codescan/db/codescan.db (SQLite).
.md files are always included even with --include filter.
--detail shows last commit info when used in a git repository.
Examples:
codescan list D:\Code\MyProject --tree --stats
codescan list ./src --include ".cs" --tree --detail
codescan list ./src --depth 2 --stats --devmode
""");
}
static void PrintSearchHelp()
{
Console.WriteLine("""
codescan search - Search indexed methods, files, and docs
Usage: codescan search <query> [options]
Options:
-t, --type <type> Filter by: method, file, doc, comment, commit
-l, --limit <n> Max results (default: 30)
-p, --project <id> Search within a specific project only
--graph Search graph nodes/edges instead of text index
--query, --cypher Treat <query> as CodeScan graph query syntax
--depth <n> Graph neighbor depth with --graph (default: 1)
-h, --help Show help
Examples:
codescan search "HttpClient"
codescan search "auth" --type method --limit 10
codescan search "SSE" --type doc
codescan search "TODO" --project 1 --type comment
codescan search "HttpClient" --graph --depth 2
codescan search "MATCH (f:file)-[r:imports]->(m:module) LIMIT 20" --query
""");
}
static void PrintGraphHelp()
{
Console.WriteLine("""
codescan graph - Search source knowledge graph
Usage: codescan graph [query] [options]
Graph data is stored in the same embedded SQLite DB and is updated
whenever a project is scanned. Nodes include projects, directories,
files, classes, methods, comments, docs, and git authors.
Query mode:
If [query] starts with MATCH, CodeScan treats it as a Cypher-like
graph query subset. This is not full Cypher; it maps only to the
CodeScan graph schema.
Supported pattern:
MATCH (n:kind)
MATCH (a:kind)-[r:edge_kind]->(b:kind)
Supported WHERE fields:
Node aliases: kind, label, path, detail
Edge aliases: kind, label
Operators: =, CONTAINS, STARTS WITH, ENDS WITH
Combine conditions with AND.
Supported clauses:
WHERE ... AND ...
RETURN ... accepted for readability, ignored by renderer
LIMIT <n> limits matched seed nodes/edges
Options:
-p, --project <id> Search within a specific project only
-d, --depth <n> Expand neighbor depth (default: 1, max: 4)
-l, --limit <n> Max matched seed nodes (default: 80)
-h, --help Show help
Examples:
codescan graph
codescan graph "HttpClient"
codescan graph "SearchCommand" --project 1 --depth 2
codescan graph "MATCH (c:class)-[r:uses_type]->(t:type) WHERE c.label CONTAINS 'Command' LIMIT 25"
codescan graph "MATCH (f:file)-[r:imports]->(m:module) WHERE m.label CONTAINS 'Sqlite'"
""");
}
static void PrintGraphQueryHelp()
{
Console.WriteLine("""
codescan query - Run CodeScan's Cypher-like graph query subset
Usage: codescan query "<graph-query>" [options]
codescan cypher "<graph-query>" [options]
This command is designed for AI/tools that need structured graph
retrieval without direct SQL access. It supports only the graph data
CodeScan stores: project, directory, file, class, method, comment,
doc, author, type, and module nodes plus scanned relationship edges.
Supported MATCH patterns:
MATCH (n:kind)
MATCH (a:kind)-[r:edge_kind]->(b:kind)
Supported WHERE fields:
Node aliases: kind, label, path, detail
Edge aliases: kind, label
Supported operators:
=, CONTAINS, STARTS WITH, ENDS WITH
Supported clauses:
WHERE ... AND ...
RETURN ... accepted for readability, ignored by CLI/TUI/GUI
LIMIT <n> max matched seed nodes/edges
Common node kinds:
project, directory, file, class, method, comment, doc, author, type, module
Common edge kinds:
contains, defines, authored, has_comment, documents,
imports, inherits_or_implements, creates, uses_type
Options:
-p, --project <id> Query within a specific project only
-d, --depth <n> Expand neighbor depth after query match (default: 0, max: 4)
-l, --limit <n> Max matched seed nodes/edges if query has no LIMIT
-h, --help Show help
Examples:
codescan query "MATCH (c:class) WHERE c.label CONTAINS 'HttpClient' LIMIT 20"
codescan query "MATCH (c:class)-[r:uses_type]->(t:type) WHERE t.label = 'HttpClient'"
codescan query "MATCH (f:file)-[r:imports]->(m:module) WHERE m.label CONTAINS 'System.Net'"
codescan query "MATCH (a:author)-[r:authored]->(m:method) WHERE a.label CONTAINS 'kim'" --depth 1
""");
}
static void PrintGuiHelp()
{
Console.WriteLine("""
codescan gui - Local web GUI viewer
Usage: codescan gui start [--port 8085]
codescan gui stop [--port 8085]
The GUI provides keyword search, graph search, and 2D/3D graph views.
Examples:
codescan gui start
codescan gui start --port 8090
codescan gui stop
""");
}
static void PrintProjectsHelp()
{
Console.WriteLine("""
codescan projects - List all indexed projects
Usage: codescan projects
Shows a table of all projects that have been scanned and indexed:
- Project ID, file/dir count, total size
- Last scan timestamp
- Project path
Use project IDs with other commands:
codescan project <id> View project detail
codescan project-addinfo <id> <text> Add description
codescan search <query> --project <id> Search within project
Examples:
codescan projects
""");
}
static void PrintProjectHelp()
{
Console.WriteLine("""
codescan project - Show project info
Usage: codescan project <id> [--detail]
Shows project information. By default shows a summary:
- Project path, file/dir count, size, scan date
- Method/comment counts, extensions, authors
- AddInfo (description) if set
With --detail, also shows:
- Project documentation files (README, AGENT.md, etc.)
- Full file list
- All methods grouped by file (with git blame)
- All comments grouped by file
- Scan history
Examples:
codescan project 1 Summary view
codescan project 1 --detail Full detail view
""");
}
static void PrintProjectAddInfoHelp()
{
Console.WriteLine("""
codescan project-addinfo - Add description to a project
Usage: codescan project-addinfo <id> <description>
Adds or replaces a single description for the specified project.
Only one description per project is stored (overwrites previous).
This is useful for providing context that cannot be derived from
code alone. LLMs can use 'codescan project <id>' to understand
the project, then add their analysis as addinfo:
1. codescan project <id> # Review project info
2. codescan search "" --project <id> # Browse indexed data
3. codescan project-addinfo <id> "..." # Save understanding
Examples:
codescan project-addinfo 1 "ASP.NET Core + Akka.NET web API with LLM chatbot"
codescan project-addinfo 2 "React frontend with TypeScript, i18n support"
""");
}
static void PrintProjectUpdateHelp()
{
Console.WriteLine("""
codescan project-update - Update project fields
Usage: codescan project-update <id> [options]
Updates specific fields of a registered project.
Options:
--path <path> Update the project root path
--addinfo <text> Update the project description
--source Full source update (git pull + rescan)
-h, --help Show help
--source performs:
1. Check if git is available for the project
2. Run 'git pull' to fetch latest code (skipped with warning if fails)
3. Full scan: directory traversal + method/comment analysis + git blame
4. Update DB index with new scan results
Examples:
codescan project-update 1 --path D:\Code\NewLocation
codescan project-update 1 --addinfo "Updated project description"
codescan project-update 1 --source
codescan project-update 1 --path D:\New --addinfo "New desc"
""");
}
static void PrintProjectDeleteHelp()
{
Console.WriteLine("""
codescan project-delete - Delete a project from DB
Usage: codescan project-delete <id> [-f|--force]
Removes a project and all its scan data (files, methods, comments,
docs, search index) from the database. This does NOT delete actual
source files on disk.
Options:
-f, --force Skip confirmation prompt
-h, --help Show help
Examples:
codescan project-delete 1 Delete with confirmation
codescan project-delete 1 --force Delete without confirmation
""");
}
}
sealed class GlobalOptions
{
public bool ShowHelp { get; set; }
public bool ShowVersion { get; set; }
public bool Verbose { get; set; }
public bool DevMode { get; set; }
}