wire/answer/proposals.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! The proposal cards still open on one document, and every document of
7//! the city that has one (`crates/wire/spec/Answer/Proposals.lean` ยง8-73).
8//!
9//! The document's version now is answered once, and each card carries
10//! the version it was made on: a page compares the two to say which
11//! cards have gone stale. A card holds no "stale" field of its own,
12//! because staleness is a fact about the file now and a card is a fact
13//! about the history.
14
15use documents::{Slice, Span};
16use kernel::{Address, B3Hash, RunId, TimeMs};
17use serde::{Deserialize, Serialize};
18
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
20#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
21pub struct ProposalsAnswer {
22 pub doc: Address,
23 /// The document's version now; `None` when it is missing or cannot
24 /// be read.
25 pub version: Option<B3Hash>,
26 /// The open cards, in the order they were offered.
27 pub open: Vec<ProposalCard>,
28}
29
30/// One open card: who offered it, on which stretch of which version,
31/// and its sentences.
32#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
33#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
34pub struct ProposalCard {
35 pub id: B3Hash,
36 pub run: RunId,
37 pub baseline: B3Hash,
38 pub span: Span,
39 pub slices: Vec<Slice>,
40}
41
42/// Every card still open in the city, newest offer first: the list a
43/// person deciding reads before they open any one document.
44///
45/// Names and moments only. A card's sentences and the document's
46/// version are [`ProposalsAnswer`]'s, asked per document, so the diff
47/// of a card nobody looks at is never laid out to be counted.
48#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
49#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
50pub struct OpenProposalsAnswer {
51 pub open: Vec<OfferedCard>,
52}
53
54/// One open card, by the document it is on and the moment it was
55/// offered.
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
58pub struct OfferedCard {
59 pub doc: Address,
60 pub id: B3Hash,
61 /// When the `proposal_offered` line was written; absent only for a
62 /// card the answering fold holds without having seen its line.
63 pub at: Option<TimeMs>,
64}