wire/answer/identity.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//! What the city calls the person and the Mayor, as a page reads it
7//! (`crates/wire/spec/Answer/Identity.lean` ยง8-59).
8
9use kernel::B3Hash;
10use serde::{Deserialize, Serialize};
11
12use crate::command::GovernedDocument;
13
14/// The two identity areas as they stand, or where one stopped reading.
15///
16/// An area that does not read is its own answer rather than a default
17/// name: a page that drew the default would let its next save write over
18/// the line the person got wrong.
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
20#[serde(rename_all = "snake_case")]
21#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
22pub enum IdentityAnswer {
23 Stated(StatedIdentity),
24 Unreadable {
25 document: GovernedDocument,
26 /// The line of the document, counted from its first.
27 line: u32,
28 why: String,
29 },
30}
31
32/// The names a new session would freeze, and the two texts a save names
33/// as its `base`.
34#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
36pub struct StatedIdentity {
37 /// What the city calls the person; absent until somebody says, and
38 /// the page then says "you" in its own language.
39 pub user_id: Option<String>,
40 /// The host whose `gh` the user id was imported from; absent for a
41 /// name typed by hand.
42 pub imported_from: Option<String>,
43 /// What the person wants every agent to know: `PREFERENCES.md`
44 /// below its identity area.
45 pub about: String,
46 /// What the Mayor is called; absent until somebody says, and the
47 /// page then draws the name its language table ships.
48 pub mayor: Option<String>,
49 /// The version a new session freezes; a `run_started` line naming
50 /// another version ran under other names.
51 #[cfg_attr(feature = "schema", schemars(with = "String"))]
52 pub version: B3Hash,
53 pub preferences_text: String,
54 pub mayor_text: String,
55}