Adapt a normalized hook event without discarding its raw payload. Turn starts become goals, tool hooks retain before/after phase and full input/output JSON, and lifecycle boundaries remain terminal events.
(
event_id: impl Into<String>,
turn_number: u32,
generation: u64,
event: &TurnEvent,
)
| 660 | /// Turn starts become goals, tool hooks retain before/after phase and full |
| 661 | /// input/output JSON, and lifecycle boundaries remain terminal events. |
| 662 | pub fn from_turn_event( |
| 663 | event_id: impl Into<String>, |
| 664 | turn_number: u32, |
| 665 | generation: u64, |
| 666 | event: &TurnEvent, |
| 667 | ) -> Self { |
| 668 | let raw = event.raw_json.clone(); |
| 669 | let journal_event = match event.event_type { |
| 670 | HookType::TurnStart if event.prompt.is_some() => ProvenanceJournalEvent::Goal { |
| 671 | prompt: event.prompt.clone().unwrap_or_default(), |
| 672 | }, |
| 673 | HookType::PreToolUse | HookType::PostToolUse => { |
| 674 | let input = raw.as_ref().and_then(|value| { |
| 675 | value |
| 676 | .get("tool_input") |
| 677 | .or_else(|| value.get("input")) |
| 678 | .or_else(|| value.get("arguments")) |
| 679 | .cloned() |
| 680 | }); |
| 681 | let output = raw.as_ref().and_then(|value| { |
| 682 | value |
| 683 | .get("tool_output") |
| 684 | .or_else(|| value.get("output")) |
| 685 | .or_else(|| value.get("result")) |
| 686 | .cloned() |
| 687 | }); |
| 688 | let status = raw |
| 689 | .as_ref() |
| 690 | .and_then(|value| value.get("status")) |
| 691 | .and_then(serde_json::Value::as_str) |
| 692 | .map(ToOwned::to_owned); |
| 693 | let duration_ms = raw |
| 694 | .as_ref() |
| 695 | .and_then(|value| value.get("duration_ms").or_else(|| value.get("duration"))) |
| 696 | .and_then(serde_json::Value::as_u64); |
| 697 | ProvenanceJournalEvent::Tool { |
| 698 | phase: if event.event_type == HookType::PreToolUse { |
| 699 | ProvenanceToolPhase::Before |
| 700 | } else { |
| 701 | ProvenanceToolPhase::After |
| 702 | }, |
| 703 | tool_name: event.tool_name.clone().unwrap_or_default(), |
| 704 | tool_call_id: event.tool_use_id.clone(), |
| 705 | input, |
| 706 | output, |
| 707 | status, |
| 708 | duration_ms, |
| 709 | raw, |
| 710 | } |
| 711 | } |
| 712 | _ => ProvenanceJournalEvent::Terminal { |
| 713 | hook_type: event.event_type, |
| 714 | reason: raw |
| 715 | .as_ref() |
| 716 | .and_then(|value| value.get("reason")) |
| 717 | .and_then(serde_json::Value::as_str) |
| 718 | .map(ToOwned::to_owned), |
| 719 | payload: raw, |
nothing calls this directly
no test coverage detected