pointbreak 0.6.0

Durable terminal code review for changes humans and coding agents collaborate on together
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
// Translate a parsed Claude Code session into a deterministic
// `AdapterIntent` stream that downstream write code maps onto `ShoreEvent`s.
// The translator is intentionally a translator — not an
// interpreter. Transcript-native checkpoint boundaries only; hook outputs
// surface as observation-on-checkpoint with shared `source_ref`; no
// similarity-based lineage; no payload-level lifting of `assertion_mode`
// or `source_ref` because those stay on event envelopes.

use super::parse::{AssistantMessage, ParsedMessage, ParsedSession, ToolUse, UserMessage};
use crate::canonical_hash::sha256_bytes_hex;
use crate::model::{
    ActorId, CheckpointId, JournalId, TargetRef, TaskTargetRef, WorkObjectId, id_prefix,
};
use crate::session::event::{AssertionMode, SourceRef, SourceSpeaker, Writer, WriterProducer};

const SOURCE_SYSTEM_CLAUDE_CODE: &str = "claude_code";

/// Translate a parsed session into the deterministic intent stream.
pub fn translate_session(parsed: &ParsedSession) -> Vec<AdapterIntent> {
    let mut intents: Vec<AdapterIntent> = Vec::new();

    let initial_prompt_text = first_user_prompt_text(parsed);
    let initial_prompt_hash = sha256_bytes_hex(initial_prompt_text.as_bytes());

    let task_attempt_material = format!(
        "project_path={}\nsession_uuid={}\ninitial_prompt_hash={}",
        parsed.project_path, parsed.claude_session_uuid, initial_prompt_hash
    );
    let task_attempt_id = WorkObjectId::new(format!(
        "{}:sha256:{}",
        id_prefix::TASK_ATTEMPT,
        sha256_bytes_hex(task_attempt_material.as_bytes())
    ));

    let first_user_msg: Option<&UserMessage> = parsed.messages.iter().find_map(|m| match m {
        ParsedMessage::User(u) => Some(u),
        _ => None,
    });
    let first_user_ts = first_user_msg
        .and_then(|u| u.timestamp.clone())
        .unwrap_or_default();

    intents.push(AdapterIntent::TaskAttemptCaptured {
        task_attempt_id: task_attempt_id.clone(),
        session_id: parsed.session_id.clone(),
        source_ref: Some(SourceRef::new(
            SOURCE_SYSTEM_CLAUDE_CODE,
            parsed.claude_session_uuid.clone(),
        )),
        assertion_mode: AssertionMode::Advisory,
        writer: writer_user(),
        occurred_at: first_user_ts,
        project_path: parsed.project_path.clone(),
        claude_session_uuid: parsed.claude_session_uuid.clone(),
        initial_prompt_hash,
        predecessor: None,
        source_speaker: SourceSpeaker::User,
    });

    for msg in &parsed.messages {
        let ParsedMessage::Assistant(a) = msg else {
            continue;
        };
        if !assistant_turn_produces_boundary(a) {
            continue;
        }
        let tool_use_ids: Vec<String> = a.tool_uses.iter().map(|t| t.id.clone()).collect();
        let cp_material = format!(
            "session_uuid={}\nassistant_message_id={}\ntool_use_ids={}",
            parsed.claude_session_uuid,
            a.message_id,
            tool_use_ids.join(",")
        );
        let checkpoint_id = CheckpointId::new(format!(
            "{}:sha256:{}",
            id_prefix::CHECKPOINT,
            sha256_bytes_hex(cp_material.as_bytes())
        ));
        let target = TargetRef::Task(TaskTargetRef::Checkpoint {
            checkpoint_id: checkpoint_id.clone(),
        });
        let occurred_at = a.timestamp.clone().unwrap_or_default();

        intents.push(AdapterIntent::CheckpointCaptured {
            checkpoint_id: checkpoint_id.clone(),
            parent_task_attempt_id: task_attempt_id.clone(),
            target: target.clone(),
            session_id: parsed.session_id.clone(),
            source_ref: Some(SourceRef::new(
                SOURCE_SYSTEM_CLAUDE_CODE,
                format!("{}#assistant:{}", parsed.claude_session_uuid, a.message_id),
            )),
            assertion_mode: AssertionMode::Advisory,
            writer: writer_agent(),
            occurred_at: occurred_at.clone(),
            assistant_message_id: a.message_id.clone(),
            tool_use_ids,
            source_speaker: SourceSpeaker::Agent,
        });

        for tu in &a.tool_uses {
            let Some(result) = &tu.matching_result else {
                continue;
            };
            if !content_carries_hook_output(&result.content) {
                continue;
            }
            intents.push(AdapterIntent::ObservationRecorded {
                parent_task_attempt_id: task_attempt_id.clone(),
                target: target.clone(),
                session_id: parsed.session_id.clone(),
                source_ref: Some(SourceRef::new(
                    SOURCE_SYSTEM_CLAUDE_CODE,
                    format!("{}#tool_result:{}", parsed.claude_session_uuid, tu.id),
                )),
                assertion_mode: AssertionMode::Advisory,
                writer: writer_agent(),
                occurred_at: occurred_at.clone(),
                title: format!("tool_result: {}", tu.name),
                source_speaker: SourceSpeaker::Agent,
            });
        }
    }

    intents
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum AdapterIntent {
    TaskAttemptCaptured {
        task_attempt_id: WorkObjectId,
        session_id: JournalId,
        source_ref: Option<SourceRef>,
        assertion_mode: AssertionMode,
        writer: Writer,
        occurred_at: String,
        project_path: String,
        claude_session_uuid: String,
        initial_prompt_hash: String,
        predecessor: Option<WorkObjectId>,
        source_speaker: SourceSpeaker,
    },
    CheckpointCaptured {
        checkpoint_id: CheckpointId,
        parent_task_attempt_id: WorkObjectId,
        target: TargetRef,
        session_id: JournalId,
        source_ref: Option<SourceRef>,
        assertion_mode: AssertionMode,
        writer: Writer,
        occurred_at: String,
        assistant_message_id: String,
        tool_use_ids: Vec<String>,
        source_speaker: SourceSpeaker,
    },
    ObservationRecorded {
        parent_task_attempt_id: WorkObjectId,
        target: TargetRef,
        session_id: JournalId,
        source_ref: Option<SourceRef>,
        assertion_mode: AssertionMode,
        writer: Writer,
        occurred_at: String,
        title: String,
        source_speaker: SourceSpeaker,
    },
    /// Reserved variant. The Claude Code session adapter never emits this:
    /// fabricating input-request structure from a transcript would cross from
    /// translator into interpreter. Future work may surface
    /// input-request intents from a different write-side signal.
    InputRequestRequested,
}

fn first_user_prompt_text(parsed: &ParsedSession) -> String {
    for msg in &parsed.messages {
        if let ParsedMessage::User(u) = msg
            && !u.text.is_empty()
        {
            return u.text.clone();
        }
    }
    String::new()
}

/// Assistant turns produce a checkpoint when they either mutate state (file
/// edit, side-effecting tool call) **or** carry verification output (hook tail)
/// on a paired tool_result. Hook output on a read-only turn still counts — it
/// is a structural signal that something verified the turn, not a prose
/// interpretation.
fn assistant_turn_produces_boundary(msg: &AssistantMessage) -> bool {
    assistant_turn_is_state_mutating(msg) || assistant_turn_has_verification_output(msg)
}

fn assistant_turn_is_state_mutating(msg: &AssistantMessage) -> bool {
    msg.tool_uses.iter().any(tool_use_is_state_mutating)
}

fn assistant_turn_has_verification_output(msg: &AssistantMessage) -> bool {
    msg.tool_uses.iter().any(|t| {
        t.matching_result
            .as_ref()
            .is_some_and(|r| content_carries_hook_output(&r.content))
    })
}

fn tool_use_is_state_mutating(tool: &ToolUse) -> bool {
    match tool.name.as_str() {
        "Edit" | "Write" | "MultiEdit" | "NotebookEdit" => true,
        "Bash" => bash_input_has_side_effect(&tool.input),
        _ => false,
    }
}

/// Bash mutation classifier: shell operators (`>`, `|`, `;`, `&&`, `||`) make
/// a Bash command state-mutating; otherwise the first word of the command must
/// appear in a deliberately short read-only allowlist or the command is
/// classified as mutating. The bias is false-negative on read-only: ambiguous
/// commands count as state-mutating so the translator does not silently drop
/// a checkpoint. `find` is **not** on the allowlist — `find -delete`,
/// `find -exec`, and similar argv forms are mutating. Future tuning may
/// tighten this rule when projection-time evidence accumulates. Do not infer
/// effect from `tool_result` content — that crosses into interpretation.
fn bash_input_has_side_effect(input: &serde_json::Value) -> bool {
    let command = input.get("command").and_then(|v| v.as_str()).unwrap_or("");
    if command.contains('>')
        || command.contains('|')
        || command.contains(';')
        || command.contains("&&")
        || command.contains("||")
    {
        return true;
    }
    let head = command.split_whitespace().next().unwrap_or("");
    !matches!(
        head,
        "ls" | "cat" | "grep" | "rg" | "head" | "tail" | "wc" | "stat" | "file"
    )
}

fn content_carries_hook_output(content: &str) -> bool {
    content.contains("<system-reminder>")
}

// The speaker fact rides in the task payloads as `sourceSpeaker` (ADR-0007);
// these writers differ only by the synthetic actor id attributing the write.
fn writer_user() -> Writer {
    Writer {
        actor_id: ActorId::new(format!("{}:claude_code:user", id_prefix::ACTOR)),
        producer: WriterProducer {
            name: "claude_code".to_owned(),
            version: String::new(),
        },
    }
}

fn writer_agent() -> Writer {
    Writer {
        actor_id: ActorId::new(format!("{}:claude_code:assistant", id_prefix::ACTOR)),
        producer: WriterProducer {
            name: "claude_code".to_owned(),
            version: String::new(),
        },
    }
}

#[cfg(test)]
mod tests {
    use std::io::Write;

    use super::super::parse::parse_session;
    use super::*;
    use crate::session::event::SourceSpeaker;

    const FIXTURE_UUID: &str = "a0ce57f0-485d-45b7-98fc-f0f13f467d72";
    const FIRST_USER_PROMPT: &str = "Can we update the README.md to use `boardwalk::transitions!` like the drivers/boardwalk-mock-led/src/lib.rs?";

    fn fixture_path() -> std::path::PathBuf {
        std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
            .join("tests/fixtures/claude_code_session/a0ce57f0-485d-45b7-98fc-f0f13f467d72.jsonl")
    }

    #[test]
    fn translate_emits_task_attempt_captured_intent_first() {
        let parsed = parse_session(&fixture_path()).expect("parses");
        let intents = translate_session(&parsed);

        let initial_prompt_hash = sha256_bytes_hex(FIRST_USER_PROMPT.as_bytes());
        let material = format!(
            "project_path={}\nsession_uuid={}\ninitial_prompt_hash={}",
            parsed.project_path, FIXTURE_UUID, initial_prompt_hash
        );
        let expected_id = WorkObjectId::new(format!(
            "task-attempt:sha256:{}",
            sha256_bytes_hex(material.as_bytes())
        ));

        match &intents[0] {
            AdapterIntent::TaskAttemptCaptured {
                task_attempt_id,
                session_id,
                source_ref,
                assertion_mode,
                claude_session_uuid,
                predecessor,
                ..
            } => {
                assert_eq!(task_attempt_id, &expected_id);
                assert_eq!(
                    session_id,
                    &JournalId::new(format!("journal:claude:{FIXTURE_UUID}"))
                );
                assert_eq!(
                    source_ref,
                    &Some(SourceRef::new("claude_code", FIXTURE_UUID))
                );
                assert_eq!(*assertion_mode, AssertionMode::Advisory);
                assert_eq!(claude_session_uuid, FIXTURE_UUID);
                assert_eq!(predecessor, &None);
            }
            other => panic!("intents[0] must be TaskAttemptCaptured, got {other:?}"),
        }
    }

    #[test]
    fn translate_emits_checkpoint_captured_at_state_mutating_assistant_turns() {
        let parsed = parse_session(&fixture_path()).expect("parses");
        let intents = translate_session(&parsed);

        let task_attempt_id = match &intents[0] {
            AdapterIntent::TaskAttemptCaptured {
                task_attempt_id, ..
            } => task_attempt_id.clone(),
            _ => panic!("expected TaskAttemptCaptured first"),
        };

        let target_state_mutating = parsed.messages.iter().find_map(|m| match m {
            ParsedMessage::Assistant(a) if assistant_turn_is_state_mutating(a) => Some(a.clone()),
            _ => None,
        });
        let target_a = target_state_mutating.expect("fixture has a state-mutating turn");
        let tool_use_ids: Vec<String> = target_a.tool_uses.iter().map(|t| t.id.clone()).collect();
        let material = format!(
            "session_uuid={}\nassistant_message_id={}\ntool_use_ids={}",
            FIXTURE_UUID,
            target_a.message_id,
            tool_use_ids.join(",")
        );
        let expected_checkpoint_id = CheckpointId::new(format!(
            "checkpoint:sha256:{}",
            sha256_bytes_hex(material.as_bytes())
        ));

        let matching = intents
            .iter()
            .filter_map(|i| match i {
                AdapterIntent::CheckpointCaptured {
                    checkpoint_id,
                    parent_task_attempt_id,
                    target,
                    assistant_message_id,
                    ..
                } if assistant_message_id == &target_a.message_id => {
                    Some((checkpoint_id, parent_task_attempt_id, target))
                }
                _ => None,
            })
            .next();
        let (cp_id, parent, target) =
            matching.expect("matching CheckpointCaptured intent for the state-mutating turn");
        assert_eq!(cp_id, &expected_checkpoint_id);
        assert_eq!(parent, &task_attempt_id);

        let target_json = serde_json::to_value(target).unwrap();
        assert_eq!(target_json["task"]["kind"], "checkpoint");
        assert_eq!(
            target_json["task"]["checkpointId"],
            expected_checkpoint_id.as_str()
        );
    }

    #[test]
    fn translate_does_not_emit_checkpoint_at_non_state_mutating_assistant_turns() {
        let dir = tempfile::tempdir().expect("tempdir");
        let path = dir.path().join("synthetic-readonly.jsonl");
        let uuid = "22222222-2222-2222-2222-222222222222";
        let mut f = std::fs::File::create(&path).unwrap();
        writeln!(f, r#"{{"type":"agent-setting","sessionId":"{uuid}"}}"#).unwrap();
        writeln!(
            f,
            r#"{{"type":"user","sessionId":"{uuid}","uuid":"u1","timestamp":"t1","message":{{"role":"user","content":"please inspect"}}}}"#
        )
        .unwrap();
        writeln!(
            f,
            r#"{{"type":"assistant","sessionId":"{uuid}","uuid":"a1","timestamp":"t2","message":{{"id":"msg_readonly","role":"assistant","content":[{{"type":"tool_use","id":"tu_r1","name":"Read","input":{{"file_path":"/tmp/x"}}}}]}}}}"#
        )
        .unwrap();
        writeln!(
            f,
            r#"{{"type":"user","sessionId":"{uuid}","uuid":"u2","timestamp":"t3","message":{{"role":"user","content":[{{"type":"tool_result","tool_use_id":"tu_r1","content":"file contents"}}]}}}}"#
        )
        .unwrap();

        let parsed = parse_session(&path).expect("parses");
        let intents = translate_session(&parsed);

        let has_checkpoint = intents
            .iter()
            .any(|i| matches!(i, AdapterIntent::CheckpointCaptured { .. }));
        assert!(
            !has_checkpoint,
            "a turn whose only tool_use is Read must not produce a checkpoint"
        );
    }

    #[test]
    fn translate_emits_observation_recorded_for_hook_output() {
        let dir = tempfile::tempdir().expect("tempdir");
        let path = dir.path().join("synthetic-hook.jsonl");
        let uuid = "33333333-3333-3333-3333-333333333333";
        let tu_id = "tu_hook_1";
        let mut f = std::fs::File::create(&path).unwrap();
        writeln!(f, r#"{{"type":"agent-setting","sessionId":"{uuid}"}}"#).unwrap();
        writeln!(
            f,
            r#"{{"type":"user","sessionId":"{uuid}","uuid":"u1","timestamp":"t1","message":{{"role":"user","content":"please update the file"}}}}"#
        )
        .unwrap();
        writeln!(
            f,
            r#"{{"type":"assistant","sessionId":"{uuid}","uuid":"a1","timestamp":"t2","message":{{"id":"msg_edit","role":"assistant","content":[{{"type":"tool_use","id":"{tu_id}","name":"Edit","input":{{"file_path":"/tmp/x","old_string":"a","new_string":"b"}}}}]}}}}"#
        )
        .unwrap();
        writeln!(
            f,
            r#"{{"type":"user","sessionId":"{uuid}","uuid":"u2","timestamp":"t3","message":{{"role":"user","content":[{{"type":"tool_result","tool_use_id":"{tu_id}","content":"edit applied\n<system-reminder>formatter ran</system-reminder>"}}]}}}}"#
        )
        .unwrap();

        let parsed = parse_session(&path).expect("parses");
        let intents = translate_session(&parsed);

        let checkpoint_id = intents
            .iter()
            .find_map(|i| match i {
                AdapterIntent::CheckpointCaptured { checkpoint_id, .. } => {
                    Some(checkpoint_id.clone())
                }
                _ => None,
            })
            .expect("checkpoint should be emitted for the Edit turn");

        let observation = intents
            .iter()
            .find_map(|i| match i {
                AdapterIntent::ObservationRecorded {
                    target,
                    source_ref,
                    assertion_mode,
                    ..
                } => Some((target.clone(), source_ref.clone(), *assertion_mode)),
                _ => None,
            })
            .expect("hook output emits an ObservationRecorded");

        assert_eq!(
            observation.0,
            TargetRef::Task(TaskTargetRef::Checkpoint { checkpoint_id })
        );
        assert_eq!(
            observation.1,
            Some(SourceRef::new(
                "claude_code",
                format!("{uuid}#tool_result:{tu_id}")
            ))
        );
        assert_eq!(observation.2, AssertionMode::Advisory);
    }

    #[test]
    fn translate_emits_checkpoint_and_observation_for_verification_output_on_read_only_turn() {
        let dir = tempfile::tempdir().expect("tempdir");
        let path = dir.path().join("synthetic-verification.jsonl");
        let uuid = "55555555-5555-5555-5555-555555555555";
        let tu_id = "tu_verify_1";
        let mut f = std::fs::File::create(&path).unwrap();
        writeln!(f, r#"{{"type":"agent-setting","sessionId":"{uuid}"}}"#).unwrap();
        writeln!(
            f,
            r#"{{"type":"user","sessionId":"{uuid}","uuid":"u1","timestamp":"t1","message":{{"role":"user","content":"please inspect"}}}}"#
        )
        .unwrap();
        writeln!(
            f,
            r#"{{"type":"assistant","sessionId":"{uuid}","uuid":"a1","timestamp":"t2","message":{{"id":"msg_readonly_verified","role":"assistant","content":[{{"type":"tool_use","id":"{tu_id}","name":"Read","input":{{"file_path":"/tmp/x"}}}}]}}}}"#
        )
        .unwrap();
        writeln!(
            f,
            r#"{{"type":"user","sessionId":"{uuid}","uuid":"u2","timestamp":"t3","message":{{"role":"user","content":[{{"type":"tool_result","tool_use_id":"{tu_id}","content":"contents\n<system-reminder>hook ran</system-reminder>"}}]}}}}"#
        )
        .unwrap();

        let parsed = parse_session(&path).expect("parses");
        let intents = translate_session(&parsed);

        let checkpoint_id = intents
            .iter()
            .find_map(|i| match i {
                AdapterIntent::CheckpointCaptured { checkpoint_id, .. } => {
                    Some(checkpoint_id.clone())
                }
                _ => None,
            })
            .expect("verification output creates a checkpoint even on a read-only tool");

        let observation = intents.iter().find_map(|i| match i {
            AdapterIntent::ObservationRecorded {
                target, source_ref, ..
            } => Some((target.clone(), source_ref.clone())),
            _ => None,
        });
        let (target, source_ref) = observation.expect("observation emitted for the hook output");
        assert_eq!(
            target,
            TargetRef::Task(TaskTargetRef::Checkpoint { checkpoint_id })
        );
        assert_eq!(
            source_ref,
            Some(SourceRef::new(
                "claude_code",
                format!("{uuid}#tool_result:{tu_id}")
            ))
        );
    }

    #[test]
    fn translate_attaches_distinct_writer_actors_to_each_intent() {
        let parsed = parse_session(&fixture_path()).expect("parses");
        let intents = translate_session(&parsed);

        let task_writer = match &intents[0] {
            AdapterIntent::TaskAttemptCaptured { writer, .. } => writer.clone(),
            _ => panic!("first intent is TaskAttemptCaptured"),
        };
        let assistant_writer = intents
            .iter()
            .find_map(|i| match i {
                AdapterIntent::CheckpointCaptured { writer, .. } => Some(writer.clone()),
                _ => None,
            })
            .expect("at least one CheckpointCaptured intent");

        assert_eq!(task_writer.actor_id.as_str(), "actor:claude_code:user");
        assert_eq!(
            assistant_writer.actor_id.as_str(),
            "actor:claude_code:assistant"
        );
        assert_ne!(task_writer.actor_id, assistant_writer.actor_id);
    }

    #[test]
    fn translate_records_source_speaker_on_each_intent() {
        let parsed = parse_session(&fixture_path()).expect("parses");
        let intents = translate_session(&parsed);

        match &intents[0] {
            AdapterIntent::TaskAttemptCaptured { source_speaker, .. } => {
                assert_eq!(*source_speaker, SourceSpeaker::User);
            }
            other => panic!("first intent must be TaskAttemptCaptured, got {other:?}"),
        }
        let mut saw_assistant_intent = false;
        for intent in &intents[1..] {
            match intent {
                AdapterIntent::CheckpointCaptured { source_speaker, .. }
                | AdapterIntent::ObservationRecorded { source_speaker, .. } => {
                    saw_assistant_intent = true;
                    assert_eq!(*source_speaker, SourceSpeaker::Agent);
                }
                _ => {}
            }
        }
        assert!(saw_assistant_intent, "fixture yields assistant intents");
    }

    #[test]
    fn translate_does_not_emit_input_request_intents() {
        let parsed = parse_session(&fixture_path()).expect("parses");
        let intents = translate_session(&parsed);

        let any_input_request = intents
            .iter()
            .any(|i| matches!(i, AdapterIntent::InputRequestRequested));
        assert!(
            !any_input_request,
            "adapter never fabricates input-request structure from a transcript"
        );
    }

    #[test]
    fn translate_does_not_set_predecessor_by_similarity() {
        let parsed = parse_session(&fixture_path()).expect("parses");
        let intents_a = translate_session(&parsed);
        let intents_b = translate_session(&parsed);

        for intent in intents_a.iter().chain(intents_b.iter()) {
            if let AdapterIntent::TaskAttemptCaptured { predecessor, .. } = intent {
                assert!(
                    predecessor.is_none(),
                    "adapter never sets predecessor by similarity"
                );
            }
        }
    }

    #[test]
    fn translate_is_deterministic() {
        let parsed = parse_session(&fixture_path()).expect("parses");
        let first = translate_session(&parsed);
        let second = translate_session(&parsed);
        assert_eq!(first, second);
    }
}