@@ -62,6 +62,13 @@ class DiffResult:
6262 added_dirs : List [str ] = field (default_factory = list )
6363 deleted_dirs : List [str ] = field (default_factory = list )
6464
65+ def to_changes (self ) -> Dict [str , List [str ]]:
66+ return {
67+ "added" : self .added_files + self .added_dirs ,
68+ "modified" : self .updated_files ,
69+ "deleted" : self .deleted_files + self .deleted_dirs ,
70+ }
71+
6572
6673class RequestQueueStats :
6774 processed : int = 0
@@ -352,24 +359,36 @@ async def on_dequeue(
352359 else :
353360 is_incremental = False
354361 target_uri = msg .target_uri
362+ run_uri = msg .uri
363+ changes = msg .changes
355364 viking_fs = get_viking_fs ()
356365 if msg .target_uri :
357366 target_exists = await viking_fs .exists (
358367 msg .target_uri , ctx = self ._current_ctx
359368 )
360- # Check if target URI exists and is not the same as the source URI(避免重复处理)
361369 if msg .uri != msg .target_uri :
362- if msg .target_preexisting is None :
363- target_preexisting = target_exists
364- else :
365- target_preexisting = bool (msg .target_preexisting )
366- else :
367- target_preexisting = target_exists
368- if target_preexisting and msg .uri != msg .target_uri :
369- is_incremental = True
370370 logger .info (
371- f"Target URI exists, using incremental update: { msg .target_uri } "
371+ "Syncing semantic source into target before processing: "
372+ f"{ msg .uri } -> { msg .target_uri } "
372373 )
374+ diff = await self ._sync_topdown_recursive (
375+ msg .uri ,
376+ msg .target_uri ,
377+ ctx = self ._current_ctx ,
378+ lock = semantic_lock .lock ,
379+ )
380+ logger .info (
381+ "[SyncDiff] Diff computed: "
382+ f"added_files={ len (diff .added_files )} , "
383+ f"deleted_files={ len (diff .deleted_files )} , "
384+ f"updated_files={ len (diff .updated_files )} , "
385+ f"added_dirs={ len (diff .added_dirs )} , "
386+ f"deleted_dirs={ len (diff .deleted_dirs )} "
387+ )
388+ changes = diff .to_changes ()
389+ is_incremental = True
390+ target_uri = msg .target_uri
391+ run_uri = msg .target_uri
373392 elif target_exists and msg .changes and msg .uri == msg .target_uri :
374393 is_incremental = True
375394 logger .info (
@@ -394,18 +413,17 @@ async def on_dequeue(
394413 recursive = msg .recursive ,
395414 lock = semantic_lock .lock ,
396415 is_code_repo = msg .is_code_repo ,
397- sync_to_target = bool (target_uri and msg .uri != target_uri ),
398- changes = msg .changes ,
416+ changes = changes ,
399417 skip_vectorization = msg .skip_vectorization ,
400418 coalesce_key = msg .coalesce_key ,
401419 coalesce_version = msg .coalesce_version ,
402420 )
403421 self ._dag_executor = executor
404422 lock_transferred = True
405- await executor .run (msg . uri )
423+ await executor .run (run_uri )
406424 self ._cache_dag_stats (
407425 msg .telemetry_id ,
408- msg . uri ,
426+ run_uri ,
409427 executor .get_stats (),
410428 )
411429 if not executor .stale :
@@ -723,7 +741,7 @@ async def list_children(dir_uri: str) -> Tuple[Dict[str, str], Dict[str, str]]:
723741 name = entry .get ("name" , "" )
724742 if not name or name in ["." , ".." ]:
725743 continue
726- if name .startswith ("." ) and name not in [ ".abstract.md" , ".overview.md" ] :
744+ if name .startswith ("." ):
727745 continue
728746 item_uri = VikingURI (dir_uri ).join (name ).uri
729747 if entry .get ("isDir" , False ):
@@ -736,18 +754,6 @@ async def sync_dir(root_dir: str, target_dir: str) -> None:
736754 root_files , root_dirs = await list_children (root_dir )
737755 target_files , target_dirs = await list_children (target_dir )
738756
739- try :
740- await viking_fs ._mv_vector_store_l0_l1 (
741- root_dir ,
742- target_dir ,
743- ctx = ctx ,
744- lock_handle = lock_handle ,
745- )
746- except Exception as e :
747- logger .error (
748- f"[SyncDiff] Failed to move L0/L1 index: { root_dir } -> { target_dir } , error={ e } "
749- )
750-
751757 file_names = set (root_files .keys ()) | set (target_files .keys ())
752758 for name in sorted (file_names ):
753759 root_file = root_files .get (name )
@@ -804,7 +810,7 @@ async def sync_dir(root_dir: str, target_dir: str) -> None:
804810 )
805811 changed = False
806812 if changed :
807- diff .updated_files .append (root_file )
813+ diff .updated_files .append (target_file )
808814 try :
809815 await viking_fs .rm (target_file , ctx = ctx , lock_handle = lock_handle )
810816 except Exception as e :
@@ -825,8 +831,8 @@ async def sync_dir(root_dir: str, target_dir: str) -> None:
825831 continue
826832
827833 if root_file and not target_file :
828- diff .added_files .append (root_file )
829834 target_file_uri = VikingURI (target_dir ).join (name ).uri
835+ diff .added_files .append (target_file_uri )
830836 try :
831837 await viking_fs .mv (
832838 root_file ,
@@ -876,8 +882,8 @@ async def sync_dir(root_dir: str, target_dir: str) -> None:
876882 continue
877883
878884 if root_subdir and not target_subdir :
879- diff .added_dirs .append (root_subdir )
880885 target_subdir_uri = VikingURI (target_dir ).join (name ).uri
886+ diff .added_dirs .append (target_subdir_uri )
881887 try :
882888 await viking_fs .mv (
883889 root_subdir ,
@@ -899,7 +905,7 @@ async def sync_dir(root_dir: str, target_dir: str) -> None:
899905 parent_uri = VikingURI (target_uri ).parent
900906 if parent_uri :
901907 await viking_fs .mkdir (parent_uri .uri , exist_ok = True , ctx = ctx )
902- diff .added_dirs .append (root_uri )
908+ diff .added_dirs .append (target_uri )
903909 await viking_fs .mv (root_uri , target_uri , ctx = ctx , lock_handle = lock_handle )
904910 return diff
905911
0 commit comments