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
//! Port trait definitions for the shiplog pipeline.
//!
//! Defines the four core abstractions: [`Ingestor`] (data collection),
//! [`WorkstreamClusterer`] (event grouping), [`Renderer`] (output generation),
//! and [`Redactor`] (privacy-aware projection). Adapters depend on ports;
//! ports never depend on adapters.
use Result;
use CoverageManifest;
use EventEnvelope;
use SourceFreshness;
use WorkstreamsFile;
/// Output of an ingestion run.
///
/// The tool treats these as immutable receipts. `freshness` carries
/// per-source attribution for cache hits vs fresh fetches; adapters
/// that have no notion of freshness (or do not yet emit it) may leave
/// the vector empty.
///
/// # Examples
///
/// ```
/// use shiplog::ports::IngestOutput;
/// use shiplog::schema::coverage::{CoverageManifest, Completeness, TimeWindow};
/// use chrono::{NaiveDate, Utc};
/// use shiplog::ids::RunId;
///
/// let output = IngestOutput {
/// events: vec![],
/// coverage: CoverageManifest {
/// run_id: RunId::now("test"),
/// generated_at: Utc::now(),
/// user: "octocat".into(),
/// window: TimeWindow {
/// since: NaiveDate::from_ymd_opt(2025, 1, 1).unwrap(),
/// until: NaiveDate::from_ymd_opt(2025, 2, 1).unwrap(),
/// },
/// mode: "merged".into(),
/// sources: vec!["github".into()],
/// slices: vec![],
/// warnings: vec![],
/// completeness: Completeness::Complete,
/// },
/// freshness: vec![],
/// };
/// assert!(output.events.is_empty());
/// ```
/// Basic ingestion trait.
///
/// Adapters live in `shiplog-ingest-*` crates.
///
/// # Examples
///
/// ```rust,no_run
/// use shiplog::ports::{Ingestor, IngestOutput};
/// use anyhow::Result;
///
/// struct MyIngestor;
///
/// impl Ingestor for MyIngestor {
/// fn ingest(&self) -> Result<IngestOutput> {
/// todo!("fetch events from your source")
/// }
/// }
/// ```
/// Workstream clustering.
///
/// This is intentionally a port so the default clustering can be swapped without rewriting the app.
///
/// # Examples
///
/// ```rust,no_run
/// use shiplog::ports::WorkstreamClusterer;
/// use shiplog::schema::event::EventEnvelope;
/// use shiplog::schema::workstream::WorkstreamsFile;
/// use anyhow::Result;
///
/// struct RepoClusterer;
///
/// impl WorkstreamClusterer for RepoClusterer {
/// fn cluster(&self, events: &[EventEnvelope]) -> Result<WorkstreamsFile> {
/// todo!("group events by repository")
/// }
/// }
/// ```
/// Rendering.
///
/// Renderers should be pure: input in, bytes out.
///
/// # Examples
///
/// ```rust,no_run
/// use shiplog::ports::Renderer;
/// use shiplog::schema::event::EventEnvelope;
/// use shiplog::schema::workstream::WorkstreamsFile;
/// use shiplog::schema::coverage::CoverageManifest;
/// use anyhow::Result;
///
/// struct MarkdownRenderer;
///
/// impl Renderer for MarkdownRenderer {
/// fn render_packet_markdown(
/// &self,
/// user: &str,
/// window_label: &str,
/// events: &[EventEnvelope],
/// workstreams: &WorkstreamsFile,
/// coverage: &CoverageManifest,
/// ) -> Result<String> {
/// Ok(format!("# Packet for {user}\n"))
/// }
/// }
/// ```
/// Redaction.
///
/// Redaction is a rendering mode. Same underlying ledger, different projections.
///
/// # Examples
///
/// ```rust,no_run
/// use shiplog::ports::Redactor;
/// use shiplog::schema::event::EventEnvelope;
/// use shiplog::schema::workstream::WorkstreamsFile;
/// use anyhow::Result;
///
/// struct NoOpRedactor;
///
/// impl Redactor for NoOpRedactor {
/// fn redact_events(&self, events: &[EventEnvelope], _profile: &str) -> Result<Vec<EventEnvelope>> {
/// Ok(events.to_vec())
/// }
/// fn redact_workstreams(&self, ws: &WorkstreamsFile, _profile: &str) -> Result<WorkstreamsFile> {
/// Ok(ws.clone())
/// }
/// }
/// ```