daemon: take the artifact-value summary from a new copy::artifact_value
The one-line artifact summary ("In progress: m:ss", "Bookmark: page N",
"(sealed)", …) was written three times — lib's FFI helpers, the desktop's
document detail, and the daemon's `docs show` — differing only in how much
body text each keeps; `Gender`'s display words likewise (FFI, daemon,
CLI). `copy::artifact_value::{summary(value, max_chars), gender}` is new
code in lib (nothing existing there is changed), and the daemon and the
CLI's `humans show` now use it; the daemon's blob-backed arm stops being an
`unreachable!`. Switching the FFI helper and the desktop's copy over is
queued for those batches.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
19c9400195
commit
fa6efcc9db
3 files changed
+70
-61
No files matched your search
@@ -1055,7 +1055,7 @@ fn handle_qr_code(sub: cli::QrCodeCmd) -> Result<()> {
|
||||
fn handle_humans(store_path: &Path, sub: cli::HumansCmd) -> Result<()> {
|
||||
use colored::Colorize;
|
||||
use syn_daemon::protocol::{HumanAddArgs, HumanShowResult, HumansCmd};
|
||||
use synchronicity::documents::Gender;
|
||||
use synchronicity::copy::artifact_value;
|
||||
|
||||
match sub {
|
||||
cli::HumansCmd::List => {
|
||||
@@ -1116,12 +1116,7 @@ fn handle_humans(store_path: &Path, sub: cli::HumansCmd) -> Result<()> {
|
||||
println!("{} {}", lbl("Birth date"), d);
|
||||
}
|
||||
if let Some(g) = &profile.gender {
|
||||
let g_str = match g {
|
||||
Gender::Male => "Male".to_string(),
|
||||
Gender::Female => "Female".to_string(),
|
||||
Gender::Other(s) => s.clone(),
|
||||
};
|
||||
println!("{} {}", lbl("Gender"), g_str);
|
||||
println!("{} {}", lbl("Gender"), artifact_value::gender(g));
|
||||
}
|
||||
if !profile.notes.is_empty() {
|
||||
println!("{} {}", lbl("Notes"), profile.notes);
|
||||
|
||||
@@ -3086,3 +3086,66 @@ mod no_source_indentation_in_copy {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One artifact's value as a single line, for the listings that show a
|
||||
/// document's artifacts — the FFI's, the desktop's document detail, and the
|
||||
/// daemon's `docs show`. Written once so the three agree on every word;
|
||||
/// only how much text a body may keep is the caller's.
|
||||
pub mod artifact_value {
|
||||
use super::elide_middle;
|
||||
use crate::documents::{ArtifactValue, Gender, ListenState};
|
||||
|
||||
/// `value` as one line, with a text body cut from the middle to
|
||||
/// `max_chars`.
|
||||
pub fn summary(value: &ArtifactValue, max_chars: usize) -> String {
|
||||
match value {
|
||||
ArtifactValue::NoteBody(body) => elide_middle(body.text.trim(), max_chars),
|
||||
ArtifactValue::TextBody(text) => elide_middle(text.trim(), max_chars),
|
||||
// Never the plaintext, and never a length: this reaches UIs — and
|
||||
// linked clients — that show artifact values verbatim, and a
|
||||
// sealed secret has nothing worth showing there (ADR 0051).
|
||||
ArtifactValue::SealedSecret { .. } => "(sealed)".to_string(),
|
||||
ArtifactValue::NoteFormat(format) => format.display_name().to_string(),
|
||||
ArtifactValue::ListenProgress(state) => match state {
|
||||
ListenState::NotStarted => "Not started".to_string(),
|
||||
ListenState::InProgress { position_secs } => {
|
||||
let mins = (*position_secs as u64) / 60;
|
||||
let secs = (*position_secs as u64) % 60;
|
||||
format!("In progress: {mins}:{secs:02}")
|
||||
}
|
||||
ListenState::Finished => "Finished".to_string(),
|
||||
},
|
||||
ArtifactValue::ReadingPosition(pos) => format!("Page {}", pos.current_page),
|
||||
ArtifactValue::Bookmark(bm) => match &bm.label {
|
||||
Some(label) => format!("Bookmark: {label} (page {})", bm.page),
|
||||
None => format!("Bookmark: page {}", bm.page),
|
||||
},
|
||||
ArtifactValue::LatestReadChild(v) => format!("Latest read: {}", v.child_id),
|
||||
ArtifactValue::Fact(fact) | ArtifactValue::ListFact(fact) => {
|
||||
format!("{}: {}", fact.key, fact.value)
|
||||
}
|
||||
ArtifactValue::ContactMethod(m) => match m.label.as_str() {
|
||||
"" => format!("{}: {}", m.protocol.display_name(), m.value),
|
||||
label => format!("{} ({label}): {}", m.protocol.display_name(), m.value),
|
||||
},
|
||||
ArtifactValue::HumanFullName(s)
|
||||
| ArtifactValue::HumanNickname(s)
|
||||
| ArtifactValue::HumanNotes(s) => s.clone(),
|
||||
ArtifactValue::HumanBirthDate(d) => d.to_string(),
|
||||
ArtifactValue::HumanGender(g) => gender(g).to_string(),
|
||||
ArtifactValue::PrimaryContent(r)
|
||||
| ArtifactValue::Thumbnail(r)
|
||||
| ArtifactValue::Attachment(r) => format!("{} ({} bytes)", r.blob_hash, r.size_bytes),
|
||||
ArtifactValue::QueuedEpisode(q) => format!("Queued: {}", q.episode_id),
|
||||
}
|
||||
}
|
||||
|
||||
/// A gender as a person reads it: the word, or their own description.
|
||||
pub fn gender(gender: &Gender) -> &str {
|
||||
match gender {
|
||||
Gender::Male => "Male",
|
||||
Gender::Female => "Female",
|
||||
Gender::Other(text) => text,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,6 @@ fn ensemble_members_snapshot(store: &Store) -> Result<EnsembleMembersSnapshot> {
|
||||
/// here, against the store, so the CLI can render the snapshot without any
|
||||
/// store access of its own.
|
||||
fn document_detail_snapshot(store: &Store, id: &DocumentID) -> Result<DocumentDetailSnapshot> {
|
||||
use synchronicity::documents::{ArtifactValue, Gender, ListenState};
|
||||
use synchronicity::node_status::{
|
||||
NodePresence, artifact_presence_for_node, artifact_stub_summary, blob_presence_for_node,
|
||||
build_peer_name_lookup, peer_display_name,
|
||||
@@ -362,54 +361,9 @@ fn document_detail_snapshot(store: &Store, id: &DocumentID) -> Result<DocumentDe
|
||||
};
|
||||
|
||||
let (summary, modified_at) = if let Some(a) = art {
|
||||
let s = match &a.value {
|
||||
ArtifactValue::NoteBody(body) => truncate_for_summary(&body.text),
|
||||
ArtifactValue::TextBody(text) => truncate_for_summary(text),
|
||||
// Never the plaintext, and never a length. A linked client
|
||||
// reaches this listing, and a sealed secret has nothing worth
|
||||
// showing it (ADR 0051).
|
||||
ArtifactValue::SealedSecret { .. } => "(sealed)".to_string(),
|
||||
ArtifactValue::NoteFormat(format) => format.display_name().to_string(),
|
||||
ArtifactValue::ListenProgress(state) => match state {
|
||||
ListenState::NotStarted => "Not started".to_string(),
|
||||
ListenState::InProgress { position_secs } => {
|
||||
let mins = (*position_secs as u64) / 60;
|
||||
let secs = (*position_secs as u64) % 60;
|
||||
format!("In progress: {mins}:{secs:02}")
|
||||
}
|
||||
ListenState::Finished => "Finished".to_string(),
|
||||
},
|
||||
ArtifactValue::ReadingPosition(pos) => format!("Page {}", pos.current_page),
|
||||
ArtifactValue::Bookmark(bm) => match &bm.label {
|
||||
Some(label) => format!("Bookmark: {label} (page {})", bm.page),
|
||||
None => format!("Bookmark: page {}", bm.page),
|
||||
},
|
||||
ArtifactValue::LatestReadChild(v) => format!("Latest read: {}", v.child_id),
|
||||
ArtifactValue::Fact(fact) | ArtifactValue::ListFact(fact) => {
|
||||
format!("{}: {}", fact.key, fact.value)
|
||||
}
|
||||
ArtifactValue::ContactMethod(m) => match m.label.as_str() {
|
||||
"" => format!("{}: {}", m.protocol.display_name(), m.value),
|
||||
label => format!("{} ({label}): {}", m.protocol.display_name(), m.value),
|
||||
},
|
||||
ArtifactValue::HumanFullName(s)
|
||||
| ArtifactValue::HumanNickname(s)
|
||||
| ArtifactValue::HumanNotes(s) => s.clone(),
|
||||
ArtifactValue::HumanBirthDate(d) => d.to_string(),
|
||||
ArtifactValue::HumanGender(g) => match g {
|
||||
Gender::Male => "Male".to_string(),
|
||||
Gender::Female => "Female".to_string(),
|
||||
Gender::Other(text) => text.clone(),
|
||||
},
|
||||
// Blob-backed kinds never reach here: `art` is drawn from
|
||||
// `inline_artifacts`, which is filtered to Storage::Inline.
|
||||
ArtifactValue::PrimaryContent(_)
|
||||
| ArtifactValue::Thumbnail(_)
|
||||
| ArtifactValue::Attachment(_) => {
|
||||
unreachable!("blob-backed kind in inline_artifacts")
|
||||
}
|
||||
ArtifactValue::QueuedEpisode(q) => format!("Queued: {}", q.episode_id),
|
||||
};
|
||||
// Blob-backed kinds never reach here: `art` is drawn from
|
||||
// `inline_artifacts`, which is filtered to Storage::Inline.
|
||||
let s = copy::artifact_value::summary(&a.value, SUMMARY_CHARS);
|
||||
(s, a.modified_at.to_rfc3339())
|
||||
} else if let Some(s) = stub {
|
||||
(
|
||||
@@ -1011,11 +965,8 @@ fn humans_manager(store: &Store) -> Result<synchronicity::agents::humans::Humans
|
||||
Ok(HumansManager::new(store, local_node(store)?))
|
||||
}
|
||||
|
||||
/// One line of a text artifact for a `docs show` row.
|
||||
fn truncate_for_summary(text: &str) -> String {
|
||||
const MAX: usize = 80;
|
||||
copy::elide_middle(text.trim(), MAX)
|
||||
}
|
||||
/// How much of a text artifact a `docs show` row keeps.
|
||||
const SUMMARY_CHARS: usize = 80;
|
||||
|
||||
/// Answer one [`DaemonCommand`] — the one place every command is answered,
|
||||
/// whichever process is doing the answering.
|
||||
|
||||
Reference in new issue
Block a user