71
71
app = cli_app
72
72
73
73
74
+ # --- Typer Option Constants ---
75
+ # add_json options
76
+ JSON_FILE_OPTION = typer .Option (
77
+ ...,
78
+ '--json-file' ,
79
+ '-f' ,
80
+ help = 'Path to the JSON file to ingest.' ,
81
+ exists = True ,
82
+ file_okay = True ,
83
+ dir_okay = False ,
84
+ readable = True ,
85
+ resolve_path = True ,
86
+ )
87
+ NAME_OPTION = typer .Option (..., '--name' , '-n' , help = 'Name for the episode.' )
88
+ SOURCE_DESC_OPTION = typer .Option (None , '--desc' , '-d' , help = 'Description of the data source.' )
89
+ GROUP_ID_OPTION = typer .Option (
90
+ None ,
91
+ '--group-id' ,
92
+ '-g' ,
93
+ help = 'Optional group ID for the graph. If not provided, generates one based on workspace path.' ,
94
+ )
95
+ UUID_OPTION = typer .Option (None , '--uuid' , help = 'Optional UUID for the episode.' )
96
+ WORKSPACE_PATH_OPTION = typer .Option (
97
+ None ,
98
+ '--workspace' ,
99
+ '-w' ,
100
+ help = 'Workspace path for generating consistent group_id. If not provided, uses CURSOR_WORKSPACE env var or cwd.' ,
101
+ )
102
+
103
+ # add_json_string options
104
+ JSON_DATA_OPTION = typer .Option (
105
+ ..., '--json-data' , '-d' , help = 'JSON string to ingest (must be valid JSON).'
106
+ )
107
+ SOURCE_DESC_STRING_OPTION = typer .Option (None , '--desc' , '-s' , help = 'Description of the data source.' )
108
+
109
+ # search_nodes options
110
+ QUERY_OPTION = typer .Option (..., '--query' , '-q' , help = 'Search query string' )
111
+ MAX_NODES_OPTION = typer .Option (10 , '--max' , '-m' , help = 'Maximum number of nodes to return' )
112
+ CENTER_NODE_UUID_OPTION = typer .Option (
113
+ None , '--center' , '-c' , help = 'Optional UUID of a node to center the search around'
114
+ )
115
+ ENTITY_OPTION = typer .Option (
116
+ '' ,
117
+ '--entity' ,
118
+ '-e' ,
119
+ help = "Optional entity type to filter results (e.g., 'Preference', 'Procedure')" ,
120
+ )
121
+
122
+ # search_facts options
123
+ MAX_FACTS_OPTION = typer .Option (10 , '--max' , '-m' , help = 'Maximum number of facts to return' )
124
+
125
+ # get_episodes options
126
+ LAST_N_OPTION = typer .Option (
127
+ 10 , '--last' , '-n' , help = 'Number of most recent episodes to retrieve'
128
+ )
129
+
130
+ # delete options
131
+ CONFIRM_OPTION = typer .Option (False , '--confirm' , help = 'Confirmation flag is required for deletion' )
132
+ SKIP_PREVIEW_OPTION = typer .Option (False , '--skip-preview' , help = 'Skip the preview step' )
133
+
134
+ # clear_graph options
135
+ FORCE_OPTION = typer .Option (False , '--force' , help = 'Force flag as secondary confirmation' )
136
+
137
+ # General options used in multiple commands
138
+ UUID_EDGE_OPTION = typer .Option (..., '--uuid' , '-u' , help = 'UUID of the entity edge to retrieve/delete' )
139
+ UUID_EPISODE_OPTION = typer .Option (..., '--uuid' , '-u' , help = 'UUID of the episode to delete' )
140
+ CONFIRM_FLAG_OPTION = typer .Option (False , '--confirm' , help = 'Initial confirmation flag' )
141
+
142
+
74
143
def generate_project_group_id (workspace_path : str = None ) -> str :
75
144
"""
76
145
Generate a consistent group_id based on the workspace path.
@@ -267,34 +336,12 @@ async def _add_json_string_episode(
267
336
268
337
@cli_app .command ()
269
338
def add_json (
270
- json_file : Path = typer .Option (
271
- ...,
272
- '--json-file' ,
273
- '-f' ,
274
- help = 'Path to the JSON file to ingest.' ,
275
- exists = True ,
276
- file_okay = True ,
277
- dir_okay = False ,
278
- readable = True ,
279
- resolve_path = True ,
280
- ),
281
- name : str = typer .Option (..., '--name' , '-n' , help = 'Name for the episode.' ),
282
- source_description : str | None = typer .Option (
283
- None , '--desc' , '-d' , help = 'Description of the data source.'
284
- ),
285
- group_id : str | None = typer .Option (
286
- None ,
287
- '--group-id' ,
288
- '-g' ,
289
- help = 'Optional group ID for the graph. If not provided, generates one based on workspace path.' ,
290
- ),
291
- uuid_str : str | None = typer .Option (None , '--uuid' , help = 'Optional UUID for the episode.' ),
292
- workspace_path : str | None = typer .Option (
293
- None ,
294
- '--workspace' ,
295
- '-w' ,
296
- help = 'Workspace path for generating consistent group_id. If not provided, uses CURSOR_WORKSPACE env var or cwd.' ,
297
- ),
339
+ json_file : Path = JSON_FILE_OPTION ,
340
+ name : str = NAME_OPTION ,
341
+ source_description : str | None = SOURCE_DESC_OPTION ,
342
+ group_id : str | None = GROUP_ID_OPTION ,
343
+ uuid_str : str | None = UUID_OPTION ,
344
+ workspace_path : str | None = WORKSPACE_PATH_OPTION ,
298
345
):
299
346
"""
300
347
Adds a JSON file content as an episode to Graphiti using graphiti-core.
@@ -315,26 +362,12 @@ def add_json(
315
362
316
363
@cli_app .command ()
317
364
def add_json_string (
318
- json_data : str = typer .Option (
319
- ..., '--json-data' , '-d' , help = 'JSON string to ingest (must be valid JSON).'
320
- ),
321
- name : str = typer .Option (..., '--name' , '-n' , help = 'Name for the episode.' ),
322
- source_description : str | None = typer .Option (
323
- None , '--desc' , '-s' , help = 'Description of the data source.'
324
- ),
325
- group_id : str | None = typer .Option (
326
- None ,
327
- '--group-id' ,
328
- '-g' ,
329
- help = 'Optional group ID for the graph. If not provided, generates one based on workspace path.' ,
330
- ),
331
- uuid_str : str | None = typer .Option (None , '--uuid' , help = 'Optional UUID for the episode.' ),
332
- workspace_path : str | None = typer .Option (
333
- None ,
334
- '--workspace' ,
335
- '-w' ,
336
- help = 'Workspace path for generating consistent group_id. If not provided, uses CURSOR_WORKSPACE env var or cwd.' ,
337
- ),
365
+ json_data : str = JSON_DATA_OPTION ,
366
+ name : str = NAME_OPTION ,
367
+ source_description : str | None = SOURCE_DESC_STRING_OPTION ,
368
+ group_id : str | None = GROUP_ID_OPTION ,
369
+ uuid_str : str | None = UUID_OPTION ,
370
+ workspace_path : str | None = WORKSPACE_PATH_OPTION ,
338
371
):
339
372
"""
340
373
Adds a JSON string directly as an episode to Graphiti using graphiti-core.
@@ -388,29 +421,12 @@ async def _check():
388
421
389
422
@cli_app .command ()
390
423
def search_nodes (
391
- query : str = typer .Option (..., '--query' , '-q' , help = 'Search query string' ),
392
- group_id : str | None = typer .Option (
393
- None ,
394
- '--group-id' ,
395
- '-g' ,
396
- help = 'Optional group ID for search scope. If not provided, generates one based on workspace path.' ,
397
- ),
398
- max_nodes : int = typer .Option (10 , '--max' , '-m' , help = 'Maximum number of nodes to return' ),
399
- center_node_uuid : str | None = typer .Option (
400
- None , '--center' , '-c' , help = 'Optional UUID of a node to center the search around'
401
- ),
402
- entity : str = typer .Option (
403
- '' ,
404
- '--entity' ,
405
- '-e' ,
406
- help = "Optional entity type to filter results (e.g., 'Preference', 'Procedure')" ,
407
- ),
408
- workspace_path : str | None = typer .Option (
409
- None ,
410
- '--workspace' ,
411
- '-w' ,
412
- help = 'Workspace path for generating consistent group_id. If not provided, uses CURSOR_WORKSPACE env var or cwd.' ,
413
- ),
424
+ query : str = QUERY_OPTION ,
425
+ group_id : str | None = GROUP_ID_OPTION ,
426
+ max_nodes : int = MAX_NODES_OPTION ,
427
+ center_node_uuid : str | None = CENTER_NODE_UUID_OPTION ,
428
+ entity : str = ENTITY_OPTION ,
429
+ workspace_path : str | None = WORKSPACE_PATH_OPTION ,
414
430
):
415
431
"""
416
432
Searches the knowledge graph for relevant nodes matching the query.
@@ -543,23 +559,11 @@ async def _search_nodes(
543
559
544
560
@cli_app .command ()
545
561
def search_facts (
546
- query : str = typer .Option (..., '--query' , '-q' , help = 'Search query string' ),
547
- group_id : str | None = typer .Option (
548
- None ,
549
- '--group-id' ,
550
- '-g' ,
551
- help = 'Optional group ID for search scope. If not provided, generates one based on workspace path.' ,
552
- ),
553
- max_facts : int = typer .Option (10 , '--max' , '-m' , help = 'Maximum number of facts to return' ),
554
- center_node_uuid : str | None = typer .Option (
555
- None , '--center' , '-c' , help = 'Optional UUID of a node to center the search around'
556
- ),
557
- workspace_path : str | None = typer .Option (
558
- None ,
559
- '--workspace' ,
560
- '-w' ,
561
- help = 'Workspace path for generating consistent group_id. If not provided, uses CURSOR_WORKSPACE env var or cwd.' ,
562
- ),
562
+ query : str = QUERY_OPTION ,
563
+ group_id : str | None = GROUP_ID_OPTION ,
564
+ max_facts : int = MAX_FACTS_OPTION ,
565
+ center_node_uuid : str | None = CENTER_NODE_UUID_OPTION ,
566
+ workspace_path : str | None = WORKSPACE_PATH_OPTION ,
563
567
):
564
568
"""
565
569
Searches the knowledge graph for relevant facts (relationships) matching the query.
@@ -670,7 +674,7 @@ async def _search_facts(
670
674
671
675
@cli_app .command ()
672
676
def get_entity_edge (
673
- uuid : str = typer . Option (..., '--uuid' , '-u' , help = 'UUID of the entity edge to retrieve' ) ,
677
+ uuid : str = UUID_EDGE_OPTION ,
674
678
):
675
679
"""
676
680
Retrieves detailed information about a specific entity edge (relationship) from the knowledge graph.
@@ -768,21 +772,9 @@ async def _get_entity_edge(uuid: str):
768
772
769
773
@cli_app .command ()
770
774
def get_episodes (
771
- group_id : str | None = typer .Option (
772
- None ,
773
- '--group-id' ,
774
- '-g' ,
775
- help = 'ID of the group to retrieve episodes from. If not provided, generates one based on workspace path.' ,
776
- ),
777
- last_n : int = typer .Option (
778
- 10 , '--last' , '-n' , help = 'Number of most recent episodes to retrieve'
779
- ),
780
- workspace_path : str | None = typer .Option (
781
- None ,
782
- '--workspace' ,
783
- '-w' ,
784
- help = 'Workspace path for generating consistent group_id. If not provided, uses CURSOR_WORKSPACE env var or cwd.' ,
785
- ),
775
+ group_id : str | None = GROUP_ID_OPTION ,
776
+ last_n : int = LAST_N_OPTION ,
777
+ workspace_path : str | None = WORKSPACE_PATH_OPTION ,
786
778
):
787
779
"""
788
780
Retrieves the most recent episodes for a specific group from the knowledge graph.
@@ -966,11 +958,9 @@ async def _get_episodes(group_id: str, last_n: int):
966
958
967
959
@cli_app .command ()
968
960
def delete_entity_edge (
969
- uuid : str = typer .Option (..., '--uuid' , '-u' , help = 'UUID of the entity edge to delete' ),
970
- confirm : bool = typer .Option (
971
- False , '--confirm' , help = 'Confirmation flag is required for deletion'
972
- ),
973
- skip_preview : bool = typer .Option (False , '--skip-preview' , help = 'Skip the preview step' ),
961
+ uuid : str = UUID_EDGE_OPTION ,
962
+ confirm : bool = CONFIRM_OPTION ,
963
+ skip_preview : bool = SKIP_PREVIEW_OPTION ,
974
964
):
975
965
"""
976
966
Deletes an entity edge (relationship) from the knowledge graph.
@@ -1065,11 +1055,9 @@ async def _delete_entity_edge(uuid: str, skip_preview: bool = False):
1065
1055
1066
1056
@cli_app .command ()
1067
1057
def delete_episode (
1068
- uuid : str = typer .Option (..., '--uuid' , '-u' , help = 'UUID of the episode to delete' ),
1069
- confirm : bool = typer .Option (
1070
- False , '--confirm' , help = 'Confirmation flag is required for deletion'
1071
- ),
1072
- skip_preview : bool = typer .Option (False , '--skip-preview' , help = 'Skip the preview step' ),
1058
+ uuid : str = UUID_EPISODE_OPTION ,
1059
+ confirm : bool = CONFIRM_OPTION ,
1060
+ skip_preview : bool = SKIP_PREVIEW_OPTION ,
1073
1061
):
1074
1062
"""
1075
1063
Deletes an episode from the knowledge graph.
@@ -1230,8 +1218,8 @@ async def _delete_episode(uuid: str, skip_preview: bool = False):
1230
1218
1231
1219
@cli_app .command ()
1232
1220
def clear_graph (
1233
- confirm : bool = typer . Option ( False , '--confirm' , help = 'Initial confirmation flag' ) ,
1234
- force : bool = typer . Option ( False , '--force' , help = 'Force flag as secondary confirmation' ) ,
1221
+ confirm : bool = CONFIRM_FLAG_OPTION ,
1222
+ force : bool = FORCE_OPTION ,
1235
1223
):
1236
1224
"""
1237
1225
Clears all data from the knowledge graph and rebuilds indices.
0 commit comments