use super::*;
pub(crate) fn unlabeled_hit(rec: &Record, matcher: &Matcher, excerpt_max: usize) -> Option<Hit> {
let text = record_raw_text(rec)?;
let span = matcher.locate(&text)?;
let (excerpt, truncated) = match_excerpt(&text, span, excerpt_max);
Some(Hit {
class: None,
labels: Vec::new(),
excerpt,
body: uncapped_body(&text, excerpt_max),
timestamp_utc: rec.timestamp.clone(),
tool_name: None,
model: None,
attachment_type: rec.attachment_type(),
version: rec.version.clone(),
is_error: None,
denial_kind: rec.tool_denial_kind.clone(),
direction: None,
tool_use_id: None,
pair: None,
line: 0,
uuid: None,
raw: None,
image_ids: Vec::new(),
from_sidecar: false,
queue_operation: None,
queue_reason: None,
task_ids: Vec::new(),
orphan_kind: None,
delivery: rec.delivery_override(),
resume_paired: None,
survival: crate::model::Survival::Live,
rewound_branch: false,
replay_copy_of: None,
compaction: None,
scheduled_at: None,
truncated,
})
}
pub(crate) fn compaction_facts(rec: &Record, ctx: &ClassifyCtx) -> Option<Box<CompactionHit>> {
if rec.is_compact_boundary() {
return Some(Box::new(CompactionHit {
metadata: rec.compact_metadata.clone(),
mode: ctx
.summarize
.and_then(|ix| ix.mode_for_boundary(rec.uuid.as_deref())),
direction: None,
}));
}
if rec.is_compact_summary.unwrap_or(false) {
return Some(Box::new(CompactionHit {
metadata: None,
mode: rec.summary_compaction_mode(),
direction: rec.summarize_direction().map(str::to_string),
}));
}
None
}
pub(crate) fn backfill_survival(
hits: &mut [Hit],
chain: &crate::model::Chain,
idx: usize,
survivor_line: &HashMap<usize, usize>,
) {
let survival = chain.survival(idx);
let rewound = chain.on_rewound_branch(idx);
let replay = chain
.replay_of(idx)
.and_then(|s| survivor_line.get(&s).copied())
.filter(|&l| l > 0);
for h in hits.iter_mut() {
h.survival = survival;
h.rewound_branch = rewound;
h.replay_copy_of = replay;
}
}
pub(crate) fn backfill_address(hits: &mut [Hit], kept: &Kept) {
for h in hits.iter_mut() {
h.line = kept.line_no;
h.uuid = kept.rec.uuid.clone();
h.from_sidecar = kept.from_sidecar;
}
if let Some(first) = hits.first_mut() {
first.image_ids = crate::image::image_ids_for_record(&kept.rec, kept.line_no);
}
}