Merge feature/fullscreen-ux-phase-2a: smart-input affordances
Phase 2A of the fullscreen UX redesign — 8 form-level smart-input affordances (URL fill-from-tab + hostname chip, group autocomplete, password reveal + strength bar, TOTP live preview + QR decode, notes monospace toggle), shared between popup and fullscreen vault tabs via the new extension/src/shared/form-affordances/ module set. CLI parity: - relicario rate <passphrase> (zxcvbn score / guess estimate) - relicario completions <SHELL> (bash/zsh/fish via clap_complete) - --group <TAB> dynamic enumeration via .relicario/groups.cache (plaintext leak surface; opt out with RELICARIO_NO_GROUPS_CACHE=1) - --totp-qr <path> on add login + edit (rqrr decode) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,8 @@ mod session;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap::{CommandFactory, Parser, Subcommand};
|
||||
use clap_complete::{generate, Shell};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(
|
||||
@@ -65,7 +66,12 @@ enum Commands {
|
||||
},
|
||||
|
||||
/// Edit an item interactively.
|
||||
Edit { query: String },
|
||||
Edit {
|
||||
query: String,
|
||||
/// Decode an `otpauth://` QR image to set the TOTP secret (login items only).
|
||||
#[arg(long, value_name = "PATH")]
|
||||
totp_qr: Option<PathBuf>,
|
||||
},
|
||||
|
||||
/// View captured field history for an item. Values are masked by
|
||||
/// default; pass `--show` to reveal them.
|
||||
@@ -163,6 +169,31 @@ enum Commands {
|
||||
|
||||
/// Lock the vault (no-op in CLI; present for UX parity with the extension).
|
||||
Lock,
|
||||
|
||||
/// Emit a shell completion script for the given shell.
|
||||
///
|
||||
/// For `--group <TAB>` autocomplete, the bash/zsh/fish scripts read
|
||||
/// the plaintext `${RELICARIO_VAULT}/.relicario/groups.cache` file,
|
||||
/// which the CLI refreshes on every manifest read. Set
|
||||
/// `RELICARIO_NO_GROUPS_CACHE=1` to opt out of the cache (completion
|
||||
/// will fall back to no value enumeration).
|
||||
///
|
||||
/// Pipe stdout to your shell's completion location (e.g.
|
||||
/// `relicario completions bash > /etc/bash_completion.d/relicario`).
|
||||
Completions {
|
||||
#[arg(value_enum)]
|
||||
shell: Shell,
|
||||
},
|
||||
|
||||
/// Rate a passphrase with zxcvbn — prints score (0-4) and estimated
|
||||
/// guesses. Informational only; does not gate vault operations.
|
||||
///
|
||||
/// Pass `-` as the argument to read one line from stdin instead, which
|
||||
/// keeps the passphrase out of shell history.
|
||||
Rate {
|
||||
/// Passphrase to score, or `-` to read from stdin.
|
||||
passphrase: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -177,6 +208,8 @@ enum AddKind {
|
||||
#[arg(long)] group: Option<String>,
|
||||
#[arg(long, value_delimiter = ',')] tags: Vec<String>,
|
||||
#[arg(long)] favorite: bool,
|
||||
/// Decode an `otpauth://` QR image to fill the TOTP secret.
|
||||
#[arg(long, value_name = "PATH")] totp_qr: Option<PathBuf>,
|
||||
},
|
||||
SecureNote {
|
||||
#[arg(long)] title: Option<String>,
|
||||
@@ -334,7 +367,7 @@ fn main() -> Result<()> {
|
||||
Commands::Add { kind } => cmd_add(kind),
|
||||
Commands::Get { query, show, copy } => cmd_get(query, show, copy),
|
||||
Commands::List { r#type, group, tag, trashed } => cmd_list(r#type, group, tag, trashed),
|
||||
Commands::Edit { query } => cmd_edit(query),
|
||||
Commands::Edit { query, totp_qr } => cmd_edit(query, totp_qr),
|
||||
Commands::History { query, show, field } => cmd_history(query, show, field),
|
||||
Commands::Rm { query } => cmd_rm(query),
|
||||
Commands::Restore { query } => cmd_restore(query),
|
||||
@@ -354,9 +387,33 @@ fn main() -> Result<()> {
|
||||
Commands::Status => cmd_status(),
|
||||
Commands::Device { action } => cmd_device(action),
|
||||
Commands::Lock => { eprintln!("no cached session to lock"); Ok(()) }
|
||||
Commands::Completions { shell } => {
|
||||
let mut cmd = Cli::command();
|
||||
generate(shell, &mut cmd, "relicario", &mut std::io::stdout());
|
||||
Ok(())
|
||||
}
|
||||
Commands::Rate { passphrase } => cmd_rate(passphrase),
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect all non-empty group names from the manifest and write them to the
|
||||
/// plaintext `groups.cache` file so shell completion can enumerate `--group`
|
||||
/// candidates without prompting for the vault passphrase.
|
||||
///
|
||||
/// Failures are silently swallowed — a missing cache is merely a UX degradation,
|
||||
/// not a correctness problem.
|
||||
fn refresh_groups_cache(vault_dir: &std::path::Path, manifest: &relicario_core::Manifest) {
|
||||
let mut set = std::collections::BTreeSet::<String>::new();
|
||||
for entry in manifest.items.values() {
|
||||
if let Some(g) = entry.group.as_ref() {
|
||||
if !g.is_empty() {
|
||||
set.insert(g.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = helpers::write_groups_cache(vault_dir, &set);
|
||||
}
|
||||
|
||||
/// `rpassword::prompt_password` wrapper that honours `RELICARIO_TEST_ITEM_SECRET`
|
||||
/// for integration-test use (rpassword reads /dev/tty by default, which is
|
||||
/// unavailable in assert_cmd-spawned children).
|
||||
@@ -476,8 +533,8 @@ fn cmd_add(kind: AddKind) -> Result<()> {
|
||||
let mut manifest = vault.load_manifest()?;
|
||||
|
||||
let item = match kind {
|
||||
AddKind::Login { title, username, url, password_prompt, password, group, tags, favorite } =>
|
||||
build_login_item(title, username, url, password_prompt, password, group, tags, favorite)?,
|
||||
AddKind::Login { title, username, url, password_prompt, password, group, tags, favorite, totp_qr } =>
|
||||
build_login_item(title, username, url, password_prompt, password, group, tags, favorite, totp_qr)?,
|
||||
AddKind::SecureNote { title, body_prompt, group, tags } =>
|
||||
build_secure_note_item(title, body_prompt, group, tags)?,
|
||||
AddKind::Identity { title, full_name, email, phone, date_of_birth, group, tags } =>
|
||||
@@ -495,6 +552,7 @@ fn cmd_add(kind: AddKind) -> Result<()> {
|
||||
vault.save_item(&item)?;
|
||||
manifest.upsert(&item);
|
||||
vault.save_manifest(&manifest)?;
|
||||
refresh_groups_cache(vault.root(), &manifest);
|
||||
|
||||
let mut paths: Vec<String> = vec![
|
||||
format!("items/{}.enc", item.id.as_str()),
|
||||
@@ -525,8 +583,9 @@ fn build_login_item(
|
||||
group: Option<String>,
|
||||
tags: Vec<String>,
|
||||
favorite: bool,
|
||||
totp_qr: Option<PathBuf>,
|
||||
) -> Result<relicario_core::Item> {
|
||||
use relicario_core::item_types::LoginCore;
|
||||
use relicario_core::item_types::{LoginCore, TotpAlgorithm, TotpConfig, TotpKind};
|
||||
use relicario_core::{Item, ItemCore};
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
@@ -544,8 +603,21 @@ fn build_login_item(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let totp = if let Some(path) = totp_qr {
|
||||
let secret_b32 = crate::helpers::decode_totp_qr(&path)?;
|
||||
let secret_bytes = base32_decode_lenient(&secret_b32)?;
|
||||
Some(TotpConfig {
|
||||
secret: Zeroizing::new(secret_bytes),
|
||||
algorithm: TotpAlgorithm::Sha1,
|
||||
digits: 6,
|
||||
period_seconds: 30,
|
||||
kind: TotpKind::Totp,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut item = Item::new(title, ItemCore::Login(LoginCore {
|
||||
username, password, url: parsed_url, totp: None,
|
||||
username, password, url: parsed_url, totp,
|
||||
}));
|
||||
item.group = group;
|
||||
item.tags = tags;
|
||||
@@ -835,6 +907,7 @@ fn cmd_get(query: String, show: bool, copy: bool) -> Result<()> {
|
||||
|
||||
let vault = crate::session::UnlockedVault::unlock_interactive()?;
|
||||
let manifest = vault.load_manifest()?;
|
||||
refresh_groups_cache(vault.root(), &manifest);
|
||||
let entry = resolve_query(&manifest, &query)?;
|
||||
let item = vault.load_item(&entry.id)?;
|
||||
|
||||
@@ -852,6 +925,13 @@ fn cmd_get(query: String, show: bool, copy: bool) -> Result<()> {
|
||||
ItemCore::Login(l) => {
|
||||
if let Some(u) = &l.username { println!("Username: {u}"); }
|
||||
if let Some(u) = &l.url { println!("URL: {u}"); }
|
||||
if let Some(t) = &l.totp {
|
||||
if show {
|
||||
println!("TOTP: {}", data_encoding::BASE32.encode(&*t.secret));
|
||||
} else {
|
||||
println!("TOTP: **** (use --show to reveal)");
|
||||
}
|
||||
}
|
||||
if let Some(p) = &l.password { Some(p.clone()) } else { None }
|
||||
}
|
||||
ItemCore::SecureNote(n) => {
|
||||
@@ -952,6 +1032,7 @@ fn cmd_list(
|
||||
|
||||
let vault = crate::session::UnlockedVault::unlock_interactive()?;
|
||||
let manifest = vault.load_manifest()?;
|
||||
refresh_groups_cache(vault.root(), &manifest);
|
||||
|
||||
let parsed_type: Option<ItemType> = match type_filter.as_deref() {
|
||||
None => None,
|
||||
@@ -990,7 +1071,7 @@ fn cmd_list(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn cmd_edit(query: String) -> Result<()> {
|
||||
fn cmd_edit(query: String, totp_qr: Option<PathBuf>) -> Result<()> {
|
||||
use relicario_core::time::now_unix;
|
||||
use relicario_core::ItemCore;
|
||||
|
||||
@@ -1012,7 +1093,7 @@ fn cmd_edit(query: String) -> Result<()> {
|
||||
|
||||
let history = &mut item.field_history;
|
||||
match &mut item.core {
|
||||
ItemCore::Login(l) => edit_login(l, history)?,
|
||||
ItemCore::Login(l) => edit_login(l, history, totp_qr)?,
|
||||
ItemCore::SecureNote(n) => edit_secure_note(n, history)?,
|
||||
ItemCore::Identity(i) => edit_identity(i)?,
|
||||
ItemCore::Card(c) => edit_card(c, history)?,
|
||||
@@ -1025,6 +1106,7 @@ fn cmd_edit(query: String) -> Result<()> {
|
||||
vault.save_item(&item)?;
|
||||
manifest.upsert(&item);
|
||||
vault.save_manifest(&manifest)?;
|
||||
refresh_groups_cache(vault.root(), &manifest);
|
||||
commit_paths(&vault, &format!("edit: {} ({})", item.title, item.id.as_str()),
|
||||
&[&format!("items/{}.enc", item.id.as_str()), "manifest.enc"])?;
|
||||
eprintln!("Updated {}", item.id.as_str());
|
||||
@@ -1040,7 +1122,12 @@ type FieldHistory = std::collections::HashMap<
|
||||
Vec<relicario_core::item::FieldHistoryEntry>,
|
||||
>;
|
||||
|
||||
fn edit_login(l: &mut relicario_core::item_types::LoginCore, history: &mut FieldHistory) -> Result<()> {
|
||||
fn edit_login(
|
||||
l: &mut relicario_core::item_types::LoginCore,
|
||||
history: &mut FieldHistory,
|
||||
totp_qr: Option<PathBuf>,
|
||||
) -> Result<()> {
|
||||
use relicario_core::item_types::{TotpAlgorithm, TotpConfig, TotpKind};
|
||||
use zeroize::Zeroizing;
|
||||
if let Some(v) = prompt_keep_opt("Username", l.username.as_deref())? { l.username = Some(v); }
|
||||
if let Some(v) = prompt_keep_opt("URL", l.url.as_ref().map(|u| u.as_str()))? {
|
||||
@@ -1053,6 +1140,18 @@ fn edit_login(l: &mut relicario_core::item_types::LoginCore, history: &mut Field
|
||||
push_history(history, "login_password", Zeroizing::new(old_pw.as_str().to_string()));
|
||||
}
|
||||
}
|
||||
if let Some(path) = totp_qr {
|
||||
let secret_b32 = crate::helpers::decode_totp_qr(&path)?;
|
||||
let secret_bytes = base32_decode_lenient(&secret_b32)?;
|
||||
l.totp = Some(TotpConfig {
|
||||
secret: Zeroizing::new(secret_bytes),
|
||||
algorithm: TotpAlgorithm::Sha1,
|
||||
digits: 6,
|
||||
period_seconds: 30,
|
||||
kind: TotpKind::Totp,
|
||||
});
|
||||
eprintln!("TOTP secret set from QR image.");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1224,6 +1323,7 @@ fn cmd_rm(query: String) -> Result<()> {
|
||||
vault.save_item(&item)?;
|
||||
manifest.upsert(&item);
|
||||
vault.save_manifest(&manifest)?;
|
||||
refresh_groups_cache(vault.root(), &manifest);
|
||||
commit_paths(&vault, &format!("trash: {} ({})", item.title, item.id.as_str()),
|
||||
&[&format!("items/{}.enc", item.id.as_str()), "manifest.enc"])?;
|
||||
eprintln!("Moved to trash: {}", item.title);
|
||||
@@ -1241,6 +1341,7 @@ fn cmd_restore(query: String) -> Result<()> {
|
||||
vault.save_item(&item)?;
|
||||
manifest.upsert(&item);
|
||||
vault.save_manifest(&manifest)?;
|
||||
refresh_groups_cache(vault.root(), &manifest);
|
||||
commit_paths(&vault, &format!("restore: {} ({})", item.title, item.id.as_str()),
|
||||
&[&format!("items/{}.enc", item.id.as_str()), "manifest.enc"])?;
|
||||
eprintln!("Restored: {}", item.title);
|
||||
@@ -1282,6 +1383,7 @@ fn cmd_purge(query: String) -> Result<()> {
|
||||
|
||||
purge_item(&vault, &mut manifest, &id, &title)?;
|
||||
vault.save_manifest(&manifest)?;
|
||||
refresh_groups_cache(vault.root(), &manifest);
|
||||
|
||||
let status = crate::helpers::git_command(vault.root(), &["add", "manifest.enc"]).status()?;
|
||||
if !status.success() { anyhow::bail!("git add manifest.enc failed"); }
|
||||
@@ -2134,3 +2236,28 @@ struct ParamsKdf {
|
||||
argon2_t: u32,
|
||||
argon2_p: u32,
|
||||
}
|
||||
|
||||
fn cmd_rate(passphrase: String) -> Result<()> {
|
||||
let pw: String = if passphrase == "-" {
|
||||
use std::io::BufRead;
|
||||
let stdin = std::io::stdin();
|
||||
let mut line = String::new();
|
||||
stdin.lock().read_line(&mut line)?;
|
||||
line.trim_end_matches(&['\r', '\n'][..]).to_string()
|
||||
} else {
|
||||
passphrase
|
||||
};
|
||||
let est = relicario_core::generators::rate_passphrase(&pw);
|
||||
let label = match est.score {
|
||||
0 => "very weak",
|
||||
1 => "weak",
|
||||
2 => "fair",
|
||||
3 => "good",
|
||||
4 => "strong",
|
||||
_ => "?",
|
||||
};
|
||||
println!("score: {}/4 ({})", est.score, label);
|
||||
println!("guesses: ~10^{:.1}", est.guesses_log10);
|
||||
println!("note: init requires score ≥ 3 (see `relicario init`)");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user