@@ -11,7 +11,9 @@ use socket_patch_core::api::ranking::severity_order;
1111use socket_patch_core:: api:: types:: { PatchResponse , PatchSearchResult , VulnerabilityResponse } ;
1212use socket_patch_core:: crawlers:: { CrawlerOptions , Ecosystem } ;
1313use socket_patch_core:: manifest:: operations:: { read_manifest, write_manifest} ;
14- use socket_patch_core:: manifest:: records:: { build_patch_record, files_for_manifest} ;
14+ use socket_patch_core:: manifest:: records:: {
15+ build_patch_record, files_for_manifest, refresh_opt_in_metadata,
16+ } ;
1517use socket_patch_core:: manifest:: schema:: { PatchFileInfo , PatchManifest , PatchRecord } ;
1618use socket_patch_core:: patch:: apply:: { is_valid_blob_hash, select_installed_variants_any} ;
1719use socket_patch_core:: patch:: apply_lock:: { LockError , LockGuard } ;
@@ -388,6 +390,7 @@ pub struct DownloadParams {
388390 /// `--patch-server-url`: the extra origin whose URLs count as hosted
389391 /// when lockfile discovery reads the project's hosted pins.
390392 pub patch_server_url : Option < String > ,
393+ pub opt_in_notes_shown : Vec < String > ,
391394}
392395
393396impl DownloadParams {
@@ -701,6 +704,7 @@ pub(crate) struct FetchBatch {
701704 failed : usize ,
702705 /// Fetched, recordable patches in selection order.
703706 fetched : Vec < FetchedPatch > ,
707+ metadata_refreshes : Vec < PatchResponse > ,
704708 /// Ledger store only: `(purl, record)` reused from a detached entry
705709 /// already at the selected uuid (no fetch).
706710 reused : Vec < ( String , PatchRecord ) > ,
@@ -912,6 +916,7 @@ pub(crate) async fn fetch_selected_patches(
912916 already_recorded : 0 ,
913917 failed : 0 ,
914918 fetched : Vec :: new ( ) ,
919+ metadata_refreshes : Vec :: new ( ) ,
915920 reused : Vec :: new ( ) ,
916921 events : Vec :: new ( ) ,
917922 warnings,
@@ -1039,13 +1044,15 @@ pub(crate) async fn fetch_selected_patches(
10391044 } ,
10401045 } ;
10411046 if action == PatchAction :: Skipped {
1047+ batch. metadata_refreshes . push ( patch. clone ( ) ) ;
10421048 if !quiet {
10431049 eprintln ! ( "{}" , format_record_skip( & patch. purl, "already in manifest" ) ) ;
10441050 }
10451051 batch. events . push (
10461052 PatchEvent :: new ( EventAction :: Skipped , patch. purl . as_str ( ) )
10471053 . with_uuid ( patch. uuid . as_str ( ) )
1048- . with_reason ( ALREADY_IN_MANIFEST , "already in manifest" ) ,
1054+ . with_reason ( ALREADY_IN_MANIFEST , "already in manifest" )
1055+ . with_details ( patch_event_metadata ( & patch) ) ,
10491056 ) ;
10501057 batch. skipped += 1 ;
10511058 batch. already_recorded += 1 ;
@@ -1405,6 +1412,7 @@ pub(crate) async fn run_nested_apply(
14051412 common : GlobalArgs ,
14061413 json : bool ,
14071414 report_user_patch_skips : bool ,
1415+ shown_opt_in_uuids : Vec < String > ,
14081416 recorded : & [ ( String , String ) ] ,
14091417 client : & ApiClient ,
14101418 lock : LockGuard ,
@@ -1419,6 +1427,7 @@ pub(crate) async fn run_nested_apply(
14191427 nested : Some ( super :: apply:: NestedApply {
14201428 caller_json : json,
14211429 report_user_patch_skips,
1430+ shown_opt_in_uuids,
14221431 } ) ,
14231432 } ;
14241433 // The nested apply runs on the host's client: seeded, never rebuilt.
@@ -1713,6 +1722,12 @@ pub async fn download_and_apply_patches_into(
17131722 // matching the per-patch event (`downloaded` / `updated`) and the
17141723 // single-uuid flow's summary in `save_and_apply_patch`; their sum gates
17151724 // the apply step.
1725+ let mut metadata_changed = false ;
1726+ for patch in & batch. metadata_refreshes {
1727+ if let Some ( record) = manifest. patches . get_mut ( & patch. purl ) {
1728+ metadata_changed |= refresh_opt_in_metadata ( record, patch) ;
1729+ }
1730+ }
17161731 let downloaded = batch. fetched . len ( ) ;
17171732 let mut updated = 0usize ;
17181733 let mut new_blobs: Vec < String > = Vec :: new ( ) ;
@@ -1748,7 +1763,7 @@ pub async fn download_and_apply_patches_into(
17481763 let added = downloaded - updated;
17491764 // Write only when a record changed: an all-skipped or all-failed run
17501765 // leaves the manifest bytes (and a fresh project's tree) untouched.
1751- if downloaded > 0 {
1766+ if downloaded > 0 || metadata_changed {
17521767 if let Err ( e) = write_manifest ( & manifest_path, & manifest) . await {
17531768 // The blobs this run just wrote have no record pointing at them:
17541769 // unwind exactly those (a pre-existing record's blobs stay).
@@ -1819,6 +1834,7 @@ pub async fn download_and_apply_patches_into(
18191834 nested_apply_args_from_params ( params, run, & manifest_path) ,
18201835 params. json ,
18211836 !params. user_patch_skips_reported ,
1837+ params. opt_in_notes_shown . clone ( ) ,
18221838 & recorded,
18231839 run. api_client ,
18241840 lock,
0 commit comments