Skip to content

Commit ef1586f

Browse files
committed
Carry opt-in notes through CLI output
Preserve optional activation metadata in manifest records and render it in get, list, apply, and OpenVEX output. Absent fields stay absent when serializing, so existing responses and manifests keep their current shape. Assisted-by: Claude Code:kimi-k3p1-pro
1 parent 63f791d commit ef1586f

89 files changed

Lines changed: 755 additions & 9 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/socket-patch-cli/src/commands/agent_download.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ pub(crate) fn patch_event_metadata(patch: &PatchResponse) -> serde_json::Value {
148148
serde_json::Value::String(patch.license.clone()),
149149
);
150150
meta.insert("tier".into(), serde_json::Value::String(patch.tier.clone()));
151+
if let Some(requires_opt_in) = patch.requires_opt_in {
152+
meta.insert("requiresOptIn".into(), serde_json::json!(requires_opt_in));
153+
}
154+
if let Some(opt_in_note) = &patch.opt_in_note {
155+
meta.insert("optInNote".into(), serde_json::json!(opt_in_note));
156+
}
151157
meta.insert(
152158
"exportedAt".into(),
153159
serde_json::Value::String(patch.published_at.clone()),

‎crates/socket-patch-cli/src/commands/apply.rs‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,23 @@ fn collect_apply_outcomes(
15011501
(applied, skipped)
15021502
}
15031503

1504+
type OptInPatches = Vec<(String, String, Option<bool>, Option<String>)>;
1505+
1506+
fn opt_in_patches(manifest: &PatchManifest) -> OptInPatches {
1507+
manifest
1508+
.patches
1509+
.iter()
1510+
.map(|(purl, patch)| {
1511+
(
1512+
purl.clone(),
1513+
patch.uuid.clone(),
1514+
patch.requires_opt_in,
1515+
patch.opt_in_note.clone(),
1516+
)
1517+
})
1518+
.collect()
1519+
}
1520+
15041521
/// The locked half of `apply`: everything from the manifest read on — the
15051522
/// package-manager layout gate, the apply loop, embedded VEX, output and
15061523
/// telemetry — over a `lock` the caller already holds and the caller's
@@ -1557,6 +1574,7 @@ pub(crate) async fn run_locked(
15571574

15581575
// Packages the project patched itself sit this run out (warned); every
15591576
// other record still applies. The read-only `--check` verifies them all.
1577+
let opt_ins = opt_in_patches(&manifest);
15601578
let mut manifest = manifest;
15611579
let (user_patch_warnings, user_patch_skips) = if args.check {
15621580
Default::default()
@@ -1830,6 +1848,15 @@ pub(crate) async fn run_locked(
18301848
for line in block {
18311849
println!("{line}");
18321850
}
1851+
if args.nested.is_none() {
1852+
let notes = format_opt_in_notes(&opt_ins, &results, &unmatched);
1853+
if !notes.is_empty() {
1854+
println!("\nOpt-in required:");
1855+
for note in notes {
1856+
println!("{note}");
1857+
}
1858+
}
1859+
}
18331860
if args.common.verbose && !results.is_empty() {
18341861
print_verbose_verification(&results);
18351862
}
@@ -1872,6 +1899,9 @@ pub(crate) async fn run_locked(
18721899
if args.common.json {
18731900
let mut env = Envelope::new(Command::Apply);
18741901
env.dry_run = args.common.dry_run;
1902+
for (purl, uuid, requires_opt_in, opt_in_note) in &opt_ins {
1903+
env.register_opt_in(purl, uuid, *requires_opt_in, opt_in_note.as_deref());
1904+
}
18751905
for skip in &user_patch_skips {
18761906
env.record(skip.clone());
18771907
}
@@ -2367,6 +2397,36 @@ fn format_dry_run_summary(tally: &ApplyTally, not_found: usize) -> Vec<String> {
23672397
lines
23682398
}
23692399

2400+
fn format_opt_in_notes(
2401+
opt_ins: &OptInPatches,
2402+
results: &[ApplyResult],
2403+
unmatched: &[String],
2404+
) -> Vec<String> {
2405+
let shown: HashSet<&str> = results
2406+
.iter()
2407+
.map(|result| result.package_key.as_str())
2408+
.chain(unmatched.iter().map(String::as_str))
2409+
.collect();
2410+
let mut notes: Vec<(&str, &str)> = opt_ins
2411+
.iter()
2412+
.filter_map(|(purl, _, requires_opt_in, opt_in_note)| {
2413+
if requires_opt_in != &Some(true) || !shown.contains(purl.as_str()) {
2414+
return None;
2415+
}
2416+
let note = opt_in_note.as_deref()?;
2417+
(!note.trim().is_empty()).then_some((purl.as_str(), note))
2418+
})
2419+
.collect();
2420+
notes.sort_unstable();
2421+
notes
2422+
.into_iter()
2423+
.map(|(purl, note)| {
2424+
let note = crate::ui::terminal_text(note).replace('\n', "\n ");
2425+
format!(" {}: {note}", normalize_purl(purl))
2426+
})
2427+
.collect()
2428+
}
2429+
23702430
/// One `Patched packages:` line. `copy` names the physical copy when a
23712431
/// package has more than one (otherwise the lines are indistinguishable).
23722432
fn format_patched_line(purl: &str, copy: Option<&str>, detail: &str) -> String {

‎crates/socket-patch-cli/src/commands/fetch_stage.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ mod tests {
284284
description: String::new(),
285285
license: "MIT".to_string(),
286286
tier: "free".to_string(),
287+
requires_opt_in: None,
288+
opt_in_note: None,
287289
},
288290
);
289291
manifest

‎crates/socket-patch-cli/src/commands/get.rs‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ fn format_search_results(
367367
if !desc.is_empty() {
368368
out.push_str(&format!(" Description: {desc}\n"));
369369
}
370+
if patch.requires_opt_in == Some(true) {
371+
if let Some(note) = &patch.opt_in_note {
372+
let note = crate::ui::terminal_text(note).replace('\n', "\n ");
373+
out.push_str(&format!(" Opt-in required: {note}\n"));
374+
}
375+
}
370376
let mut fixes: Vec<(String, String)> = patch
371377
.vulnerabilities
372378
.iter()
@@ -1284,6 +1290,15 @@ pub async fn run(args: GetArgs) -> i32 {
12841290
crate::ui::stderr_color(),
12851291
)
12861292
);
1293+
if patch.requires_opt_in == Some(true) {
1294+
if let Some(note) = &patch.opt_in_note {
1295+
let note = crate::ui::terminal_text(note).replace('\n', "\n ");
1296+
println!(
1297+
"Opt-in required for {}: {note}",
1298+
normalize_purl(&patch.purl)
1299+
);
1300+
}
1301+
}
12871302
}
12881303

12891304
// Record the fetch BEFORE the save+apply step so the
@@ -1802,6 +1817,7 @@ pub async fn run(args: GetArgs) -> i32 {
18021817
verbose: args.common.verbose,
18031818
};
18041819
let mut env = new_envelope(&args.common);
1820+
register_opt_ins(&mut env, &selected);
18051821
// The narrowing skips came first (before any download).
18061822
fold_narrowing_into_result(&mut env, &narrow_skips, &narrow_warnings);
18071823
// The engine records into `env` and never prints it: exactly one JSON
@@ -1904,6 +1920,7 @@ async fn agent_dry_run(
19041920
if args.common.json {
19051921
let mut env = new_envelope(&args.common);
19061922
env.dry_run = true;
1923+
register_opt_ins(&mut env, selected);
19071924
fold_narrowing_into_result(&mut env, narrow_skips, narrow_warnings);
19081925
for event in events {
19091926
env.record(event);
@@ -2159,6 +2176,12 @@ async fn save_and_apply_patch(
21592176

21602177
if args.common.json {
21612178
let mut env = new_envelope(&args.common);
2179+
env.register_opt_in(
2180+
&patch.purl,
2181+
&patch.uuid,
2182+
patch.requires_opt_in,
2183+
patch.opt_in_note.as_deref(),
2184+
);
21622185
fold_narrowing_into_result(&mut env, &[], run_warnings);
21632186
// The metadata rides only a changed record — an `already_in_manifest`
21642187
// skip means the consumer already saw it last time.
@@ -2206,6 +2229,19 @@ fn search_result_from_response(patch: &PatchResponse) -> PatchSearchResult {
22062229
license: patch.license.clone(),
22072230
tier: patch.tier.clone(),
22082231
vulnerabilities: patch.vulnerabilities.clone(),
2232+
requires_opt_in: patch.requires_opt_in,
2233+
opt_in_note: patch.opt_in_note.clone(),
2234+
}
2235+
}
2236+
2237+
fn register_opt_ins(env: &mut Envelope, patches: &[PatchSearchResult]) {
2238+
for patch in patches {
2239+
env.register_opt_in(
2240+
&patch.purl,
2241+
&patch.uuid,
2242+
patch.requires_opt_in,
2243+
patch.opt_in_note.as_deref(),
2244+
);
22092245
}
22102246
}
22112247

@@ -2254,6 +2290,7 @@ async fn run_get_hosted(
22542290
// common.json (see run_redirect_selected's doc).
22552291
let scan_result = args.common.json.then(|| {
22562292
let mut env = new_envelope(&args.common);
2293+
register_opt_ins(&mut env, selected);
22572294
fold_narrowing_into_result(&mut env, narrow_skips, narrow_warnings);
22582295
env
22592296
});
@@ -2305,6 +2342,7 @@ async fn run_get_vendored(
23052342
telemetry: &TelemetryAuth,
23062343
) -> i32 {
23072344
let mut env = new_envelope(&args.common);
2345+
register_opt_ins(&mut env, selected);
23082346
fold_narrowing_into_result(&mut env, narrow_skips, narrow_warnings);
23092347
// Dry run: ledger-classification preview only (scan's posture) — no
23102348
// download, no vendor step, no writes.
@@ -2568,6 +2606,8 @@ mod tests {
25682606
license: "MIT".into(),
25692607
tier: tier.into(),
25702608
vulnerabilities: HashMap::<String, VulnerabilityResponse>::new(),
2609+
requires_opt_in: None,
2610+
opt_in_note: None,
25712611
}
25722612
}
25732613

@@ -2899,6 +2939,8 @@ mod tests {
28992939
description: String::new(),
29002940
license: String::new(),
29012941
tier: "free".to_string(),
2942+
requires_opt_in: None,
2943+
opt_in_note: None,
29022944
},
29032945
);
29042946
m
@@ -3080,6 +3122,8 @@ mod tests {
30803122
description: "desc".into(),
30813123
license: "MIT".into(),
30823124
tier: "free".into(),
3125+
requires_opt_in: None,
3126+
opt_in_note: None,
30833127
};
30843128
let meta = patch_event_metadata(&patch);
30853129
assert!(meta.as_object().unwrap().get("severity").is_none());
@@ -3110,6 +3154,8 @@ mod tests {
31103154
description: "Fixes prototype pollution in minimist".into(),
31113155
license: "MIT".into(),
31123156
tier: "free".into(),
3157+
requires_opt_in: None,
3158+
opt_in_note: None,
31133159
};
31143160
let meta = patch_event_metadata(&patch);
31153161
assert_eq!(meta["description"], "Fixes prototype pollution in minimist");
@@ -3151,6 +3197,8 @@ mod tests {
31513197
description: String::new(),
31523198
license: String::new(),
31533199
tier: String::new(),
3200+
requires_opt_in: None,
3201+
opt_in_note: None,
31543202
};
31553203
let meta = patch_event_metadata(&patch);
31563204
let ids: Vec<&str> = meta["vulnerabilities"]
@@ -3173,6 +3221,8 @@ mod tests {
31733221
description: "desc".into(),
31743222
license: "MIT".into(),
31753223
tier: "free".into(),
3224+
requires_opt_in: None,
3225+
opt_in_note: None,
31763226
};
31773227
let meta = patch_event_metadata(&patch);
31783228
// `severity` is intentionally omitted (not null) when there
@@ -3748,6 +3798,8 @@ mod tests {
37483798
description: "desc".into(),
37493799
license: "MIT".into(),
37503800
tier: "free".into(),
3801+
requires_opt_in: None,
3802+
opt_in_note: None,
37513803
}
37523804
}
37533805

‎crates/socket-patch-cli/src/commands/list.rs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ fn build_list_envelope(entries: &[ListEntry<'_>]) -> Envelope {
185185
details["lockfiles"] = serde_json::json!(entry.lockfiles);
186186
}
187187

188+
env.register_opt_in(
189+
entry.purl,
190+
&patch.uuid,
191+
patch.requires_opt_in,
192+
patch.opt_in_note.as_deref(),
193+
);
188194
env.record(
189195
PatchEvent::new(PatchAction::Discovered, entry.purl.to_string())
190196
.with_uuid(patch.uuid.clone())
@@ -246,10 +252,7 @@ fn failed_listing(
246252
/// control characters that would rewrite the terminal (ESC, a stray
247253
/// `\r`), keeping newlines and tabs, and normalize `\r\n`.
248254
fn sanitize(s: &str) -> String {
249-
s.replace("\r\n", "\n")
250-
.chars()
251-
.filter(|&c| c == '\n' || c == '\t' || !c.is_control())
252-
.collect()
255+
crate::ui::terminal_text(s)
253256
}
254257

255258
/// `"{indent}{label}: {value}"`, or `None` when the value is blank (no
@@ -290,6 +293,11 @@ fn format_entry(entry: &ListEntry<'_>, color: bool) -> String {
290293
lines.extend(field(" ", "License", &patch.license));
291294
lines.extend(field(" ", "Exported", &patch.exported_at));
292295
lines.extend(field(" ", "Description", &patch.description));
296+
if patch.requires_opt_in == Some(true) {
297+
if let Some(note) = &patch.opt_in_note {
298+
lines.extend(field(" ", "Opt-in required", note));
299+
}
300+
}
293301

294302
let mut vuln_entries: Vec<_> = patch.vulnerabilities.iter().collect();
295303
vuln_entries.sort_by(|a, b| a.0.cmp(b.0));
@@ -667,6 +675,8 @@ mod tests {
667675
description: "Fixes prototype pollution".to_string(),
668676
license: "MIT".to_string(),
669677
tier: "free".to_string(),
678+
requires_opt_in: None,
679+
opt_in_note: None,
670680
},
671681
);
672682

@@ -712,6 +722,8 @@ mod tests {
712722
description: "desc".to_string(),
713723
license: "MIT".to_string(),
714724
tier: "free".to_string(),
725+
requires_opt_in: None,
726+
opt_in_note: None,
715727
}
716728
}
717729

‎crates/socket-patch-cli/src/commands/remove.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,8 @@ mod tests {
18921892
description: "test".to_string(),
18931893
license: "MIT".to_string(),
18941894
tier: "free".to_string(),
1895+
requires_opt_in: None,
1896+
opt_in_note: None,
18951897
}
18961898
}
18971899

‎crates/socket-patch-cli/src/commands/rollback.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4305,6 +4305,8 @@ mod tests {
43054305
description: "test patch".to_string(),
43064306
license: "MIT".to_string(),
43074307
tier: "free".to_string(),
4308+
requires_opt_in: None,
4309+
opt_in_note: None,
43084310
}
43094311
}
43104312

0 commit comments

Comments
 (0)