Repository navigation
Expand file tree
/
Copy pathconstants.py
More file actions
3079 lines (2745 loc) · 92.9 KB
/
Copy pathconstants.py
File metadata and controls
3079 lines (2745 loc) · 92.9 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
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from enum import StrEnum
from typing import NamedTuple
class PyInstallerPackage(NamedTuple):
name: str
collect_all: bool = False
collect_data: bool = False
hidden_import: str | None = None
class ModelRole(StrEnum):
ORCHESTRATOR = "orchestrator"
CYPHER = "cypher"
class Provider(StrEnum):
OLLAMA = "ollama"
ANTHROPIC = "anthropic"
OPENAI = "openai"
GOOGLE = "google"
AZURE = "azure"
COHERE = "cohere"
LOCAL = "local"
VLLM = "vllm"
class Color(StrEnum):
GREEN = "green"
YELLOW = "yellow"
CYAN = "cyan"
RED = "red"
MAGENTA = "magenta"
BLUE = "blue"
class KeyBinding(StrEnum):
CTRL_J = "c-j"
ENTER = "enter"
CTRL_C = "c-c"
class StyleModifier(StrEnum):
BOLD = "bold"
DIM = "dim"
NONE = ""
class FileAction(StrEnum):
READ = "read"
EDIT = "edit"
DEFAULT_MODEL_ROLE = "model"
BINARY_EXTENSIONS: frozenset[str] = frozenset(
{
".pdf",
".png",
".jpg",
".jpeg",
".gif",
".bmp",
".ico",
".tiff",
".webp",
}
)
# (H) Source file extensions by language
EXT_PY = ".py"
EXT_JS = ".js"
EXT_JSX = ".jsx"
EXT_TS = ".ts"
EXT_TSX = ".tsx"
EXT_RS = ".rs"
EXT_GO = ".go"
EXT_SCALA = ".scala"
EXT_SC = ".sc"
EXT_JAVA = ".java"
EXT_CLASS = ".class"
EXT_CPP = ".cpp"
EXT_H = ".h"
EXT_HPP = ".hpp"
EXT_CC = ".cc"
EXT_CXX = ".cxx"
EXT_HXX = ".hxx"
EXT_HH = ".hh"
EXT_IXX = ".ixx"
EXT_CPPM = ".cppm"
EXT_CCM = ".ccm"
EXT_C = ".c"
EXT_CS = ".cs"
EXT_PHP = ".php"
EXT_LUA = ".lua"
# (H) File extension tuples by language
PY_EXTENSIONS = (EXT_PY,)
JS_EXTENSIONS = (EXT_JS, EXT_JSX)
TS_EXTENSIONS = (EXT_TS, EXT_TSX)
RS_EXTENSIONS = (EXT_RS,)
GO_EXTENSIONS = (EXT_GO,)
SCALA_EXTENSIONS = (EXT_SCALA, EXT_SC)
JAVA_EXTENSIONS = (EXT_JAVA,)
C_EXTENSIONS = (EXT_C,)
CPP_EXTENSIONS = (
EXT_CPP,
EXT_H,
EXT_HPP,
EXT_CC,
EXT_CXX,
EXT_HXX,
EXT_HH,
EXT_IXX,
EXT_CPPM,
EXT_CCM,
)
CS_EXTENSIONS = (EXT_CS,)
PHP_EXTENSIONS = (EXT_PHP,)
LUA_EXTENSIONS = (EXT_LUA,)
EXT_AL = ".al"
AL_EXTENSIONS = (EXT_AL,)
# (H) Package indicator files
PKG_INIT_PY = "__init__.py"
PKG_CARGO_TOML = "Cargo.toml"
PKG_CMAKE_LISTS = "CMakeLists.txt"
PKG_MAKEFILE = "Makefile"
PKG_VCXPROJ_GLOB = "*.vcxproj"
PKG_CONANFILE = "conanfile.txt"
DEFAULT_REGION = "us-central1"
DEFAULT_MODEL = "llama3.2"
DEFAULT_API_KEY = "ollama"
ENV_OPENAI_API_KEY = "OPENAI_API_KEY"
ENV_GOOGLE_API_KEY = "GOOGLE_API_KEY"
ENV_ANTHROPIC_API_KEY = "ANTHROPIC_API_KEY"
ENV_AZURE_API_KEY = "AZURE_API_KEY"
ENV_AZURE_ENDPOINT = "AZURE_OPENAI_ENDPOINT"
ENV_AZURE_API_VERSION = "AZURE_API_VERSION"
HELP_ARG = "help"
class GoogleProviderType(StrEnum):
GLA = "gla"
VERTEX = "vertex"
# (H) Provider endpoints
OPENAI_DEFAULT_ENDPOINT = "https://api.openai.com/v1"
OLLAMA_HEALTH_PATH = "/api/tags"
GOOGLE_CLOUD_SCOPE = "https://www.googleapis.com/auth/cloud-platform"
V1_PATH = "/v1"
# (H) HTTP status codes
HTTP_OK = 200
UNIXCODER_MODEL = "microsoft/unixcoder-base"
EMBEDDING_DEFAULT_BATCH_SIZE = 32
EMBEDDING_CACHE_FILENAME = ".embedding_cache.json"
KEY_NODES = "nodes"
KEY_RELATIONSHIPS = "relationships"
KEY_NODE_ID = "node_id"
KEY_LABELS = "labels"
KEY_PROPERTIES = "properties"
KEY_FROM_ID = "from_id"
KEY_TO_ID = "to_id"
KEY_TYPE = "type"
KEY_METADATA = "metadata"
KEY_TOTAL_NODES = "total_nodes"
KEY_TOTAL_RELATIONSHIPS = "total_relationships"
KEY_NODE_LABELS = "node_labels"
KEY_RELATIONSHIP_TYPES = "relationship_types"
KEY_EXPORTED_AT = "exported_at"
KEY_PARSER = "parser"
KEY_NAME = "name"
KEY_QUALIFIED_NAME = "qualified_name"
KEY_START_LINE = "start_line"
KEY_END_LINE = "end_line"
KEY_PATH = "path"
KEY_ABSOLUTE_PATH = "absolute_path"
KEY_EXTENSION = "extension"
KEY_MODULE_TYPE = "module_type"
KEY_IMPLEMENTS_MODULE = "implements_module"
KEY_PROPS = "props"
KEY_CREATED = "created"
KEY_FROM_VAL = "from_val"
KEY_TO_VAL = "to_val"
KEY_VERSION_SPEC = "version_spec"
KEY_PREFIX = "prefix"
KEY_PROJECT_NAME = "project_name"
KEY_IS_EXTERNAL = "is_external"
ERR_SUBSTR_ALREADY_EXISTS = "already exists"
ERR_SUBSTR_CONSTRAINT = "constraint"
# (H) File names
INIT_PY = "__init__.py"
# (H) Encoding
ENCODING_UTF8 = "utf-8"
# (H) Protobuf file names
PROTOBUF_INDEX_FILE = "index.bin"
PROTOBUF_NODES_FILE = "nodes.bin"
PROTOBUF_RELS_FILE = "relationships.bin"
# (H) Protobuf oneof field names
ONEOF_PROJECT = "project"
ONEOF_PACKAGE = "package"
ONEOF_FOLDER = "folder"
ONEOF_MODULE = "module"
ONEOF_CLASS = "class_node"
ONEOF_FUNCTION = "function"
ONEOF_METHOD = "method"
ONEOF_FILE = "file"
ONEOF_EXTERNAL_PACKAGE = "external_package"
ONEOF_MODULE_IMPLEMENTATION = "module_implementation"
ONEOF_MODULE_INTERFACE = "module_interface"
# (H) CLI error and info messages
CLI_ERR_OUTPUT_REQUIRES_UPDATE = (
"Error: --output/-o option requires --update-graph to be specified."
)
CLI_ERR_ONLY_JSON = "Error: Currently only JSON format is supported."
CLI_ERR_STARTUP = "Startup Error: {error}"
CLI_ERR_CONFIG = "Configuration Error: {error}"
CLI_ERR_INDEXING = "An error occurred during indexing: {error}"
CLI_ERR_EXPORT_FAILED = "Failed to export graph: {error}"
CLI_ERR_LOAD_GRAPH = "Failed to load graph: {error}"
CLI_ERR_MCP_SERVER = "MCP Server Error: {error}"
CLI_MSG_UPDATING_GRAPH = "Updating knowledge graph for: {path}"
CLI_MSG_CLEANING_DB = "Cleaning database..."
CLI_MSG_CLEANING_HASH_CACHE = "Removing hash cache: {path}"
CLI_MSG_CLEAN_DONE = "Clean completed successfully!"
CLI_MSG_EXPORTING_TO = "Exporting graph to: {path}"
CLI_MSG_GRAPH_UPDATED = "Graph update completed!"
CLI_MSG_APP_TERMINATED = "\nApplication terminated by user."
CLI_MSG_INDEXING_AT = "Indexing codebase at: {path}"
CLI_MSG_OUTPUT_TO = "Output will be written to: {path}"
CLI_MSG_INDEXING_DONE = "Indexing process completed successfully!"
CLI_MSG_CONNECTING_MEMGRAPH = "Connecting to Memgraph to export graph..."
CLI_MSG_EXPORTING_DATA = "Exporting graph data..."
CLI_MSG_OPTIMIZATION_TERMINATED = "\nOptimization session terminated by user."
CLI_MSG_MCP_TERMINATED = "\nMCP server terminated by user."
CLI_MSG_HINT_TARGET_REPO = (
"\nHint: Make sure TARGET_REPO_PATH environment variable is set."
)
CLI_MSG_GRAPH_SUMMARY = "Graph Summary:"
CLI_MSG_CONNECTING_STATS = "Fetching graph statistics..."
CLI_STATS_NODE_TITLE = "Node Statistics"
CLI_STATS_REL_TITLE = "Relationship Statistics"
CLI_STATS_COL_NODE_TYPE = "Node Type"
CLI_STATS_COL_REL_TYPE = "Relationship Type"
CLI_STATS_COL_COUNT = "Count"
CLI_STATS_TOTAL_NODES = "Total Nodes"
CLI_STATS_TOTAL_RELS = "Total Relationships"
CLI_STATS_UNKNOWN = "Unknown"
CLI_ERR_STATS_FAILED = "Failed to get graph statistics: {error}"
CLI_MSG_AUTO_EXCLUDE = (
"Auto-excluding common directories (venv, node_modules, .git, etc.). "
"Use --interactive-setup to customize."
)
UI_DIFF_FILE_HEADER = "[bold cyan]File: {path}[/bold cyan]"
UI_NEW_FILE_HEADER = "[bold cyan]New file: {path}[/bold cyan]"
UI_SHELL_COMMAND_HEADER = "[bold cyan]Shell command:[/bold cyan]"
UI_TOOL_APPROVAL = "[bold yellow]⚠️ Tool '{tool_name}' requires approval:[/bold yellow]"
UI_FEEDBACK_PROMPT = (
"[bold yellow]Feedback (why rejected, or press Enter to skip)[/bold yellow]"
)
UI_OPTIMIZATION_START = (
"[bold green]Starting {language} optimization session...[/bold green]"
)
UI_OPTIMIZATION_PANEL = (
"[bold yellow]The agent will analyze your codebase{document_info} and propose specific optimizations."
" You'll be asked to approve each suggestion before implementation."
" Type 'exit' or 'quit' to end the session.[/bold yellow]"
)
UI_OPTIMIZATION_INIT = "[bold cyan]Initializing optimization session for {language} codebase: {path}[/bold cyan]"
UI_GRAPH_EXPORT_SUCCESS = (
"[bold green]Graph exported successfully to: {path}[/bold green]"
)
UI_GRAPH_EXPORT_STATS = "[bold cyan]Export contains {nodes} nodes and {relationships} relationships[/bold cyan]"
UI_ERR_UNEXPECTED = "[bold red]An unexpected error occurred: {error}[/bold red]"
UI_ERR_EXPORT_FAILED = "[bold red]Failed to export graph: {error}[/bold red]"
UI_MODEL_SWITCHED = "[bold green]Model switched to: {model}[/bold green]"
UI_MODEL_CURRENT = "[bold cyan]Current model: {model}[/bold cyan]"
UI_MODEL_SWITCH_ERROR = "[bold red]Failed to switch model: {error}[/bold red]"
UI_MODEL_USAGE = "[bold yellow]Usage: /model <provider:model> (e.g., /model google:gemini-3.1-pro-preview)[/bold yellow]"
UI_HELP_COMMANDS = """[bold cyan]Available commands:[/bold cyan]
/model <provider:model> - Switch to a different model
/model - Show current model
/help - Show this help
exit, quit - Exit the session"""
UI_TOOL_ARGS_FORMAT = " Arguments: {args}"
UI_REFERENCE_DOC_INFO = " using the reference document: {reference_document}"
UI_INPUT_PROMPT_HTML = (
"<ansigreen><b>{prompt}</b></ansigreen> <ansiyellow>{hint}</ansiyellow>: "
)
# (H) ModelConfig field names
FIELD_PROVIDER = "provider"
FIELD_MODEL_ID = "model_id"
FIELD_API_KEY = "api_key"
FIELD_ENDPOINT = "endpoint"
# (H) Tool argument field names
ARG_TARGET_CODE = "target_code"
ARG_REPLACEMENT_CODE = "replacement_code"
ARG_FILE_PATH = "file_path"
ARG_CONTENT = "content"
ARG_COMMAND = "command"
# (H) Qualified name separators
SEPARATOR_DOT = "."
SEPARATOR_SLASH = "/"
# (H) Path navigation
PATH_CURRENT_DIR = "."
PATH_PARENT_DIR = ".."
GLOB_ALL = "*"
PATH_RELATIVE_PREFIX = "./"
PATH_PARENT_PREFIX = "../"
CPP_IMPORT_PARTITION_PREFIX = "import :"
CPP_PARTITION_PREFIX = "partition_"
# (H) Trie internal keys
TRIE_TYPE_KEY = "__type__"
TRIE_QN_KEY = "__qn__"
TRIE_INTERNAL_PREFIX = "__"
class UniqueKeyType(StrEnum):
NAME = KEY_NAME
PATH = KEY_PATH
QUALIFIED_NAME = KEY_QUALIFIED_NAME
class NodeLabel(StrEnum):
PROJECT = "Project"
PACKAGE = "Package"
FOLDER = "Folder"
FILE = "File"
MODULE = "Module"
CLASS = "Class"
FUNCTION = "Function"
METHOD = "Method"
INTERFACE = "Interface"
ENUM = "Enum"
TYPE = "Type"
UNION = "Union"
MODULE_INTERFACE = "ModuleInterface"
MODULE_IMPLEMENTATION = "ModuleImplementation"
EXTERNAL_PACKAGE = "ExternalPackage"
TABLE = "Table"
TABLE_EXTENSION = "TableExtension"
PAGE = "Page"
PAGE_EXTENSION = "PageExtension"
CODEUNIT = "Codeunit"
REPORT = "Report"
REPORT_EXTENSION = "ReportExtension"
ENUM_EXTENSION = "EnumExtension"
AL_QUERY = "ALQuery"
XMLPORT = "Xmlport"
CONTROL_ADDIN = "ControlAddin"
PERMISSION_SET = "PermissionSet"
ENTITLEMENT = "Entitlement"
PROFILE = "Profile"
PROCEDURE = "Procedure"
TRIGGER = "Trigger"
EVENT_SUBSCRIBER = "EventSubscriber"
FIELD = "Field"
KEY = "Key"
ACTION = "Action"
DATA_ITEM = "DataItem"
EXTERNAL_OBJECT = "ExternalObject"
_NODE_LABEL_UNIQUE_KEYS: dict[NodeLabel, UniqueKeyType] = {
NodeLabel.PROJECT: UniqueKeyType.NAME,
NodeLabel.PACKAGE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.FOLDER: UniqueKeyType.PATH,
NodeLabel.FILE: UniqueKeyType.PATH,
NodeLabel.MODULE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.CLASS: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.FUNCTION: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.METHOD: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.INTERFACE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.ENUM: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.TYPE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.UNION: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.MODULE_INTERFACE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.MODULE_IMPLEMENTATION: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.EXTERNAL_PACKAGE: UniqueKeyType.NAME,
NodeLabel.TABLE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.TABLE_EXTENSION: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.PAGE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.PAGE_EXTENSION: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.CODEUNIT: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.REPORT: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.REPORT_EXTENSION: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.ENUM_EXTENSION: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.AL_QUERY: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.XMLPORT: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.CONTROL_ADDIN: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.PERMISSION_SET: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.ENTITLEMENT: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.PROFILE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.PROCEDURE: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.TRIGGER: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.EVENT_SUBSCRIBER: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.FIELD: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.KEY: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.ACTION: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.DATA_ITEM: UniqueKeyType.QUALIFIED_NAME,
NodeLabel.EXTERNAL_OBJECT: UniqueKeyType.QUALIFIED_NAME,
}
_missing_keys = set(NodeLabel) - set(_NODE_LABEL_UNIQUE_KEYS.keys())
if _missing_keys:
raise RuntimeError(
f"NodeLabel(s) missing from _NODE_LABEL_UNIQUE_KEYS: {_missing_keys}. "
"Every NodeLabel MUST have a unique key defined."
)
class RelationshipType(StrEnum):
CONTAINS_PACKAGE = "CONTAINS_PACKAGE"
CONTAINS_FOLDER = "CONTAINS_FOLDER"
CONTAINS_FILE = "CONTAINS_FILE"
CONTAINS_MODULE = "CONTAINS_MODULE"
DEFINES = "DEFINES"
DEFINES_METHOD = "DEFINES_METHOD"
IMPORTS = "IMPORTS"
EXPORTS = "EXPORTS"
EXPORTS_MODULE = "EXPORTS_MODULE"
IMPLEMENTS_MODULE = "IMPLEMENTS_MODULE"
INHERITS = "INHERITS"
IMPLEMENTS = "IMPLEMENTS"
OVERRIDES = "OVERRIDES"
CALLS = "CALLS"
DEPENDS_ON_EXTERNAL = "DEPENDS_ON_EXTERNAL"
EXTENDS = "EXTENDS"
SUBSCRIBES_TO = "SUBSCRIBES_TO"
BINDS_TABLE = "BINDS_TABLE"
HAS_FIELD = "HAS_FIELD"
HAS_KEY = "HAS_KEY"
HAS_TRIGGER = "HAS_TRIGGER"
HAS_ACTION = "HAS_ACTION"
HAS_DATAITEM = "HAS_DATAITEM"
READS_TABLE = "READS_TABLE"
DISPLAYS_FIELD = "DISPLAYS_FIELD"
NODE_PROJECT = NodeLabel.PROJECT
EXCLUDED_DEPENDENCY_NAMES = frozenset({"python", "php"})
# (H) Byte size constants
BYTES_PER_MB = 1024 * 1024
# (H) Property keys
KEY_PARAMETERS = "parameters"
KEY_DECORATORS = "decorators"
KEY_DOCSTRING = "docstring"
KEY_IS_EXPORTED = "is_exported"
# (H) Method signature formatting
EMPTY_PARENS = "()"
DOCSTRING_STRIP_CHARS = "'\" \n"
# (H) Inline module path prefix
INLINE_MODULE_PATH_PREFIX = "inline_module_"
# (H) Dependency files
DEPENDENCY_FILES = frozenset(
{
"pyproject.toml",
"requirements.txt",
"package.json",
"cargo.toml",
"go.mod",
"gemfile",
"composer.json",
}
)
CSPROJ_SUFFIX = ".csproj"
# (H) Cypher queries
CYPHER_DEFAULT_LIMIT = 50
_CYPHER_EMBEDDING_BASE = """
MATCH (m:Module)-[:DEFINES]->(n)
WHERE (n:Function OR n:Method)
AND m.qualified_name STARTS WITH ($project_name + '.')
"""
CYPHER_QUERY_EMBEDDINGS = (
_CYPHER_EMBEDDING_BASE
+ """RETURN id(n) AS node_id, n.qualified_name AS qualified_name,
n.start_line AS start_line, n.end_line AS end_line,
m.path AS path
"""
)
CYPHER_QUERY_PROJECT_NODE_IDS = _CYPHER_EMBEDDING_BASE + "RETURN id(n) AS node_id\n"
class SupportedLanguage(StrEnum):
PYTHON = "python"
JS = "javascript"
TS = "typescript"
RUST = "rust"
GO = "go"
SCALA = "scala"
JAVA = "java"
C = "c"
CPP = "cpp"
CSHARP = "c-sharp"
PHP = "php"
LUA = "lua"
AL = "al"
class LanguageStatus(StrEnum):
FULL = "Fully Supported"
DEV = "In Development"
class LanguageMetadata(NamedTuple):
status: LanguageStatus
additional_features: str
display_name: str
LANGUAGE_METADATA: dict[SupportedLanguage, LanguageMetadata] = {
SupportedLanguage.PYTHON: LanguageMetadata(
LanguageStatus.FULL,
"Type inference, decorators, nested functions",
"Python",
),
SupportedLanguage.JS: LanguageMetadata(
LanguageStatus.FULL,
"ES6 modules, CommonJS, prototype methods, object methods, arrow functions",
"JavaScript",
),
SupportedLanguage.TS: LanguageMetadata(
LanguageStatus.FULL,
"Interfaces, type aliases, enums, namespaces, ES6/CommonJS modules",
"TypeScript",
),
SupportedLanguage.C: LanguageMetadata(
LanguageStatus.FULL,
"Functions, structs, unions, enums, preprocessor includes",
"C",
),
SupportedLanguage.CPP: LanguageMetadata(
LanguageStatus.FULL,
"Constructors, destructors, operator overloading, templates, lambdas, C++20 modules, namespaces",
"C++",
),
SupportedLanguage.LUA: LanguageMetadata(
LanguageStatus.FULL,
"Local/global functions, metatables, closures, coroutines",
"Lua",
),
SupportedLanguage.RUST: LanguageMetadata(
LanguageStatus.FULL,
"impl blocks, associated functions",
"Rust",
),
SupportedLanguage.JAVA: LanguageMetadata(
LanguageStatus.FULL,
"Generics, annotations, modern features (records/sealed classes), concurrency, reflection",
"Java",
),
SupportedLanguage.GO: LanguageMetadata(
LanguageStatus.DEV,
"Methods, type declarations",
"Go",
),
SupportedLanguage.SCALA: LanguageMetadata(
LanguageStatus.DEV,
"Case classes, objects",
"Scala",
),
SupportedLanguage.CSHARP: LanguageMetadata(
LanguageStatus.DEV,
"Classes, interfaces, generics (planned)",
"C#",
),
SupportedLanguage.PHP: LanguageMetadata(
LanguageStatus.DEV,
"Classes, functions, namespaces",
"PHP",
),
SupportedLanguage.AL: LanguageMetadata(
status=LanguageStatus.DEV,
additional_features="Tables, pages, codeunits, extensions, triggers, event subscriptions",
display_name="AL",
),
}
# (H) Tree-sitter AST node type constants
FUNCTION_NODES_BASIC = ("function_declaration", "function_definition")
FUNCTION_NODES_LAMBDA = (
"lambda_expression",
"arrow_function",
"anonymous_function",
"closure_expression",
)
FUNCTION_NODES_METHOD = (
"method_declaration",
"constructor_declaration",
"destructor_declaration",
)
FUNCTION_NODES_TEMPLATE = (
"template_declaration",
"function_signature_item",
"function_signature",
)
FUNCTION_NODES_GENERATOR = ("generator_function_declaration", "function_expression")
CLASS_NODES_BASIC = ("class_declaration", "class_definition")
CLASS_NODES_STRUCT = ("struct_declaration", "struct_specifier", "struct_item")
CLASS_NODES_INTERFACE = ("interface_declaration", "trait_declaration", "trait_item")
CLASS_NODES_ENUM = ("enum_declaration", "enum_item", "enum_specifier")
CLASS_NODES_TYPE_ALIAS = ("type_alias_declaration", "type_item")
CLASS_NODES_UNION = ("union_specifier", "union_item")
CALL_NODES_BASIC = ("call_expression", "function_call")
CALL_NODES_METHOD = (
"method_invocation",
"member_call_expression",
"field_expression",
)
CALL_NODES_OPERATOR = ("binary_expression", "unary_expression", "update_expression")
CALL_NODES_SPECIAL = ("new_expression", "delete_expression", "macro_invocation")
IMPORT_NODES_STANDARD = ("import_declaration", "import_statement")
IMPORT_NODES_FROM = ("import_from_statement",)
IMPORT_NODES_MODULE = ("lexical_declaration", "export_statement")
IMPORT_NODES_INCLUDE = ("preproc_include",)
IMPORT_NODES_USING = ("using_directive",)
# (H) JS/TS specific node types
JS_TS_FUNCTION_NODES = (
"function_declaration",
"generator_function_declaration",
"function_expression",
"arrow_function",
"method_definition",
)
JS_TS_CLASS_NODES = ("class_declaration", "class")
JS_TS_IMPORT_NODES = ("import_statement", "lexical_declaration", "export_statement")
JS_TS_LANGUAGES = frozenset({SupportedLanguage.JS, SupportedLanguage.TS})
# (H) C++ import node types
CPP_IMPORT_NODES = ("preproc_include", "template_function", "declaration")
# (H) Index file names
INDEX_INIT = "__init__"
INDEX_INDEX = "index"
INDEX_MOD = "mod"
# (H) AST field names for name extraction
NAME_FIELDS = ("identifier", "name", "id")
# (H) Tree-sitter field name constants for child_by_field_name
FIELD_OBJECT = "object"
FIELD_PROPERTY = "property"
FIELD_NAME = "name"
FIELD_ALIAS = "alias"
FIELD_MODULE_NAME = "module_name"
FIELD_ARGUMENTS = "arguments"
FIELD_BODY = "body"
FIELD_CONSTRUCTOR = "constructor"
FIELD_DECLARATOR = "declarator"
FIELD_PARAMETERS = "parameters"
FIELD_TYPE = "type"
FIELD_VALUE = "value"
FIELD_LEFT = "left"
FIELD_RIGHT = "right"
FIELD_FIELD = "field"
FIELD_SUPERCLASS = "superclass"
FIELD_SUPERCLASSES = "superclasses"
FIELD_INTERFACES = "interfaces"
# (H) Method name constants for getattr/hasattr
METHOD_FIND_WITH_PREFIX = "find_with_prefix"
METHOD_ITEMS = "items"
# (H) Image file extensions for chat image handling
IMAGE_EXTENSIONS = (".png", ".jpg", ".jpeg", ".gif")
# (H) CLI exit commands
EXIT_COMMANDS = frozenset({"exit", "quit"})
# (H) CLI commands
MODEL_COMMAND_PREFIX = "/model"
HELP_COMMAND = "/help"
# (H) UI separators and formatting
HORIZONTAL_SEPARATOR = "─" * 60
# (H) Session log header
SESSION_LOG_HEADER = "=== CODE-GRAPH RAG SESSION LOG ===\n\n"
# (H) Logger format
LOG_FORMAT = "{time:YYYY-MM-DD HH:mm:ss.SSS} | {message}"
# (H) Temporary directory
TMP_DIR = ".tmp"
SESSION_LOG_PREFIX = "session_"
SESSION_LOG_EXT = ".log"
# (H) Session log prefixes
SESSION_PREFIX_USER = "USER: "
SESSION_PREFIX_ASSISTANT = "ASSISTANT: "
# (H) Session context format
SESSION_CONTEXT_START = (
"\n\n[SESSION CONTEXT - Previous conversation in this session]:\n"
)
SESSION_CONTEXT_END = "\n[END SESSION CONTEXT]\n\n"
# (H) Confirmation status display
CONFIRM_ENABLED = "Enabled"
CONFIRM_DISABLED = "Disabled (YOLO Mode)"
# (H) Diff labels
DIFF_LABEL_BEFORE = "before"
DIFF_LABEL_AFTER = "after"
DIFF_FALLBACK_PATH = "file"
class DiffMarker:
ADD = "+"
DEL = "-"
HUNK = "@"
HEADER_ADD = "+++"
HEADER_DEL = "---"
# (H) Table column headers
TABLE_COL_CONFIGURATION = "Configuration"
TABLE_COL_VALUE = "Value"
# (H) Table row labels
TABLE_ROW_TARGET_LANGUAGE = "Target Language"
TABLE_ROW_ORCHESTRATOR_MODEL = "Orchestrator Model"
TABLE_ROW_CYPHER_MODEL = "Cypher Model"
TABLE_ROW_OLLAMA_ENDPOINT = "Ollama Endpoint"
TABLE_ROW_OLLAMA_ORCHESTRATOR = "Ollama Endpoint (Orchestrator)"
TABLE_ROW_OLLAMA_CYPHER = "Ollama Endpoint (Cypher)"
TABLE_ROW_EDIT_CONFIRMATION = "Edit Confirmation"
TABLE_ROW_TARGET_REPOSITORY = "Target Repository"
# (H) UI status messages
MSG_CONNECTED_MEMGRAPH = "Successfully connected to Memgraph."
MSG_THINKING_CANCELLED = "Thinking cancelled."
MSG_TIMEOUT_FORMAT = "Operation timed out after {timeout} seconds."
MSG_CHAT_INSTRUCTIONS = (
"Ask questions about your codebase graph. Type 'exit' or 'quit' to end."
)
# (H) Default titles and prompts
DEFAULT_TABLE_TITLE = "Code-Graph-RAG Initializing..."
OPTIMIZATION_TABLE_TITLE = "Optimization Session Configuration"
PROMPT_ASK_QUESTION = "Ask a question"
PROMPT_YOUR_RESPONSE = "Your response"
MULTILINE_INPUT_HINT = "(Press Ctrl+J to submit, Enter for new line)"
# (H) Interactive setup prompt - grouped view
INTERACTIVE_TITLE_GROUPED = "Detected Directories (will be excluded unless kept)"
INTERACTIVE_TITLE_NESTED = "Nested paths in '{pattern}'"
INTERACTIVE_COL_NUM = "#"
INTERACTIVE_COL_PATTERN = "Pattern"
INTERACTIVE_COL_NESTED = "Nested"
INTERACTIVE_COL_PATH = "Path"
INTERACTIVE_STYLE_DIM = "dim"
INTERACTIVE_STATUS_DETECTED = "auto-detected"
INTERACTIVE_STATUS_CLI = "--exclude"
INTERACTIVE_STATUS_CGRIGNORE = ".cgrignore"
INTERACTIVE_NESTED_SINGULAR = "{count} dir"
INTERACTIVE_NESTED_PLURAL = "{count} dirs"
INTERACTIVE_INSTRUCTIONS_GROUPED = (
"These directories would normally be excluded. "
"Options: 'all' (keep all), 'none' (keep none), "
"numbers like '1,3' (keep groups), or '1e' to expand group 1"
)
INTERACTIVE_INSTRUCTIONS_NESTED = (
"Select paths to keep from '{pattern}'. "
"Options: 'all', 'none', or numbers like '1,3'"
)
INTERACTIVE_PROMPT_KEEP = "Keep"
INTERACTIVE_KEEP_ALL = "all"
INTERACTIVE_KEEP_NONE = "none"
INTERACTIVE_EXPAND_SUFFIX = "e"
INTERACTIVE_BFS_MAX_DEPTH = 10
INTERACTIVE_DEFAULT_GROUP = "."
# (H) JSON formatting
JSON_INDENT = 2
# (H) Parser loader paths and args
GRAMMARS_DIR = "grammars"
TREE_SITTER_PREFIX = "tree-sitter-"
TREE_SITTER_MODULE_PREFIX = "tree_sitter_"
BINDINGS_DIR = "bindings"
SETUP_PY = "setup.py"
BUILD_EXT_CMD = "build_ext"
INPLACE_FLAG = "--inplace"
LANG_ATTR_PREFIX = "language_"
LANG_ATTR_TYPESCRIPT = "language_typescript"
class TreeSitterModule(StrEnum):
PYTHON = "tree_sitter_python"
JS = "tree_sitter_javascript"
TS = "tree_sitter_typescript"
RUST = "tree_sitter_rust"
GO = "tree_sitter_go"
SCALA = "tree_sitter_scala"
JAVA = "tree_sitter_java"
C = "tree_sitter_c"
CPP = "tree_sitter_cpp"
LUA = "tree_sitter_lua"
AL = "tree_sitter_al"
# (H) Query dict keys
QUERY_FUNCTIONS = "functions"
QUERY_CLASSES = "classes"
QUERY_CALLS = "calls"
QUERY_IMPORTS = "imports"
QUERY_LOCALS = "locals"
QUERY_CONFIG = "config"
QUERY_LANGUAGE = "language"
# (H) Query capture names
CAPTURE_FUNCTION = "function"
CAPTURE_CLASS = "class"
CAPTURE_CALL = "call"
CAPTURE_IMPORT = "import"
CAPTURE_IMPORT_FROM = "import_from"
# (H) Locals query patterns for JS/TS
JS_LOCALS_PATTERN = """
; Variable definitions
(variable_declarator name: (identifier) @local.definition)
(function_declaration name: (identifier) @local.definition)
(class_declaration name: (identifier) @local.definition)
; Variable references
(identifier) @local.reference
"""
TS_LOCALS_PATTERN = """
; Variable definitions (TypeScript has multiple declaration types)
(variable_declarator name: (identifier) @local.definition)
(lexical_declaration (variable_declarator name: (identifier) @local.definition))
(variable_declaration (variable_declarator name: (identifier) @local.definition))
; Function definitions
(function_declaration name: (identifier) @local.definition)
; Class definitions (uses type_identifier for class names)
(class_declaration name: (type_identifier) @local.definition)
; Variable references
(identifier) @local.reference
"""
# (H) Patterns to detect at repo root and offer as exclude candidates (user selects which to exclude)
IGNORE_PATTERNS = frozenset(
{
".cache",
".claude",
".eclipse",
".eggs",
".env",
".git",
".gradle",
".hg",
".idea",
".maven",
".mypy_cache",
".nox",
".npm",
".nyc_output",
".pnpm-store",
".pytest_cache",
".qdrant_code_embeddings",
".ruff_cache",
".svn",
".tmp",
".tox",
".venv",
".vs",
".vscode",
".yarn",
"__pycache__",
"bin",
"bower_components",
"build",
"coverage",
"dist",
"env",
"htmlcov",
"node_modules",
"obj",
"out",
"Pods",
"site-packages",
"target",
"temp",
"tmp",
"vendor",
"venv",
}
)
IGNORE_SUFFIXES = frozenset(
{".tmp", "~", ".pyc", ".pyo", ".o", ".a", ".so", ".dll", ".class"}
)
PAYLOAD_NODE_ID = "node_id"
PAYLOAD_QUALIFIED_NAME = "qualified_name"
class EventType(StrEnum):
MODIFIED = "modified"
CREATED = "created"
DELETED = "deleted"
CYPHER_DELETE_MODULE = "MATCH (m:Module {path: $path})-[*0..]->(c) DETACH DELETE m, c"
CYPHER_DELETE_FILE = "MATCH (f:File {path: $path}) DETACH DELETE f"
CYPHER_DELETE_FOLDER = "MATCH (f:Folder {path: $path}) DETACH DELETE f"
CYPHER_DELETE_CALLS = "MATCH ()-[r:CALLS]->() DELETE r"
# (H) Queries for orphan pruning — returns all paths stored in the graph
CYPHER_ALL_FILE_PATHS = "MATCH (f:File) RETURN f.path AS path"
CYPHER_ALL_MODULE_PATHS = "MATCH (m:Module) RETURN m.path AS path"
CYPHER_ALL_FOLDER_PATHS = "MATCH (f:Folder) RETURN f.path AS path"
REALTIME_LOGGER_FORMAT = (
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | "
"<level>{level: <8}</level> | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
"<level>{message}</level>"
)
WATCHER_SLEEP_INTERVAL = 1
LOG_LEVEL_INFO = "INFO"
class Architecture(StrEnum):
X86_64 = "x86_64"
AARCH64 = "aarch64"
ARM64 = "arm64"
AMD64 = "amd64"
BINARY_NAME_TEMPLATE = "code-graph-rag-{system}-{machine}"
BINARY_FILE_PERMISSION = 0o755
DIST_DIR = "dist"
BYTES_PER_MB_FLOAT = 1024 * 1024
PYPROJECT_PATH = "pyproject.toml"
TREESITTER_EXTRA_KEY = "treesitter-full"
TREESITTER_PKG_PREFIX = "tree-sitter-"
# (H) PyInstaller CLI constants
PYINSTALLER_CMD = "pyinstaller"
PYINSTALLER_ARG_NAME = "--name"
PYINSTALLER_ARG_ONEFILE = "--onefile"
PYINSTALLER_ARG_NOCONFIRM = "--noconfirm"
PYINSTALLER_ARG_CLEAN = "--clean"
PYINSTALLER_ARG_COLLECT_ALL = "--collect-all"
PYINSTALLER_ARG_COLLECT_DATA = "--collect-data"
PYINSTALLER_ARG_HIDDEN_IMPORT = "--hidden-import"
PYINSTALLER_ARG_EXCLUDE_MODULE = "--exclude-module"
PYINSTALLER_ENTRY_POINT = "main.py"
PYINSTALLER_EXCLUDED_MODULES = ["logfire"]
# (H) TOML parsing constants
TOML_KEY_PROJECT = "project"
TOML_KEY_OPTIONAL_DEPS = "optional-dependencies"
# (H) Version string parsing
VERSION_SPLIT_GTE = ">="
VERSION_SPLIT_EQ = "=="