Skip to main content

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, Seq, 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    /// The `proposal_offered` line that offered this card, in `run`'s
41    /// session (`crates/wire/spec/Answer/Proposals.lean` D44). `None`
42    /// when the line is outside that session's window or does not read
43    /// back; a letter then draws the whole conversation.
44    #[serde(default)]
45    pub offered: Option<Seq>,
46}
47
48/// Every card still open in the city, newest offer first: the list a
49/// person deciding reads before they open any one document.
50///
51/// Names and moments only. A card's sentences and the document's
52/// version are [`ProposalsAnswer`]'s, asked per document, so the diff
53/// of a card nobody looks at is never laid out to be counted.
54#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
55#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
56pub struct OpenProposalsAnswer {
57    pub open: Vec<OfferedCard>,
58}
59
60/// One open card, by the document it is on and the moment it was
61/// offered.
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
64pub struct OfferedCard {
65    pub doc: Address,
66    pub id: B3Hash,
67    /// When the `proposal_offered` line was written; absent only for a
68    /// card the answering fold holds without having seen its line.
69    pub at: Option<TimeMs>,
70}