MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / build_turn_envelope

Function build_turn_envelope

atomic-agent/src/record/provenance.rs:179–220  ·  view source on GitHub ↗

Build a `SessionEnvelope` for embedding in `HashedChange.metadata`.

(
    options: &TurnRecordOptions<'_>,
    recorded_files: &[String],
)

Source from the content-addressed store, hash-verified

177
178/// Build a `SessionEnvelope` for embedding in `HashedChange.metadata`.
179pub(crate) fn build_turn_envelope(
180 options: &TurnRecordOptions<'_>,
181 recorded_files: &[String],
182) -> SessionEnvelope {
183 let prompt_summary = options
184 .prompt
185 .as_deref()
186 .filter(|p| is_meaningful_prompt(p))
187 .map(|p| truncate_prompt(p, 200));
188
189 let prompt_hash = options
190 .prompt
191 .as_deref()
192 .filter(|p| is_meaningful_prompt(p))
193 .map(|p| *blake3::hash(p.as_bytes()).as_bytes());
194
195 let files_in_turn: Vec<String> = recorded_files.to_vec();
196
197 let session_started_at = options.session.started_at.timestamp();
198 let turn_ended_at = options.event.timestamp.timestamp();
199 let turn_started_at = turn_ended_at - (options.turn_duration_ms as i64 / 1000);
200
201 let mut builder =
202 SessionEnvelope::builder(&options.session.session_id, &options.session.agent_name)
203 .agent_display_name(&options.session.agent_display_name)
204 .turn_number(options.turn_number)
205 .session_started_at(session_started_at)
206 .turn_started_at(turn_started_at)
207 .turn_ended_at(turn_ended_at)
208 .turn_duration_ms(options.turn_duration_ms)
209 .files_in_turn(files_in_turn)
210 .files_in_session(options.session.files_touched_count());
211
212 if let Some(summary) = prompt_summary {
213 builder = builder.prompt_summary(summary);
214 }
215 if let Some(hash) = prompt_hash {
216 builder = builder.prompt_hash(hash);
217 }
218
219 builder.build()
220}
221
222// Step 6 Helper: Build Unhashed Turn Data
223

Calls 15

is_meaningful_promptFunction · 0.85
hashFunction · 0.85
files_in_sessionMethod · 0.80
files_in_turnMethod · 0.80
turn_duration_msMethod · 0.80
turn_ended_atMethod · 0.80
turn_started_atMethod · 0.80
session_started_atMethod · 0.80
turn_numberMethod · 0.80
files_touched_countMethod · 0.80
truncate_promptFunction · 0.70
as_bytesMethod · 0.45