Add dev demo seed for busy HUD previews

tessera-demo crate, seed-demo CLI, TESSERA_SEED_DEMO hub hook,
12 orbits and 30 historical snapshots.
This commit is contained in:
Tessera Agent
2026-11-09 10:40:55 +00:00
parent d358c73291
commit 50fe4ffffa
8 changed files with 454 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ members = [
"crates/tessera-hub", "crates/tessera-hub",
"crates/tessera-agent", "crates/tessera-agent",
"crates/tessera-cli", "crates/tessera-cli",
"crates/tessera-demo",
] ]
[workspace.package] [workspace.package]

View File

@@ -11,6 +11,7 @@ path = "src/main.rs"
[dependencies] [dependencies]
tessera-core = { path = "../tessera-core" } tessera-core = { path = "../tessera-core" }
tessera-store = { path = "../tessera-store" } tessera-store = { path = "../tessera-store" }
tessera-demo = { path = "../tessera-demo" }
tessera-providers = { path = "../tessera-providers" } tessera-providers = { path = "../tessera-providers" }
anyhow.workspace = true anyhow.workspace = true
clap.workspace = true clap.workspace = true

View File

@@ -50,6 +50,15 @@ enum Commands {
#[command(subcommand)] #[command(subcommand)]
cmd: WormholeCmd, cmd: WormholeCmd,
}, },
/// Dev-only: populate demo orbits and snapshot history for UI previews.
SeedDemo {
/// Replace existing demo seed data.
#[arg(long)]
force: bool,
/// Remove demo data (orbits/snapshots marker) only.
#[arg(long)]
reset: bool,
},
} }
#[derive(Subcommand, Clone)] #[derive(Subcommand, Clone)]
@@ -84,6 +93,29 @@ fn main() -> Result<()> {
Commands::Wormhole { ref cmd } => match cmd { Commands::Wormhole { ref cmd } => match cmd {
WormholeCmd::Pair { code, name } => wormhole_pair(&cli, code, name)?, WormholeCmd::Pair { code, name } => wormhole_pair(&cli, code, name)?,
}, },
Commands::SeedDemo { force, reset } => cmd_seed_demo(&cli, force, reset)?,
}
Ok(())
}
fn cmd_seed_demo(cli: &Cli, force: bool, reset: bool) -> Result<()> {
let data = std::path::Path::new(&cli.data_dir);
if reset {
tessera_demo::clear_demo(data, &cli.vault_pass)?;
println!("Demo seed cleared.");
return Ok(());
}
let report = tessera_demo::apply(data, &cli.vault_pass, force)?;
if report.skipped {
println!(
"Demo seed already applied ({} orbits, {} snapshots). Use --force to re-seed.",
report.orbits, report.snapshots
);
} else {
println!(
"Demo seed complete: {} orbits, {} snapshots, {} outposts.",
report.orbits, report.snapshots, report.outposts
);
} }
Ok(()) Ok(())
} }

View File

@@ -0,0 +1,16 @@
[package]
name = "tessera-demo"
version.workspace = true
edition.workspace = true
license.workspace = true
[dependencies]
tessera-core = { path = "../tessera-core" }
tessera-store = { path = "../tessera-store" }
anyhow.workspace = true
chrono.workspace = true
rusqlite.workspace = true
serde.workspace = true
serde_json.workspace = true
uuid = { workspace = true, features = ["v4", "v5", "serde"] }
tracing.workspace = true

View File

@@ -0,0 +1,369 @@
//! Dev-only demo seed for HUD previews. Gated by CLI or `TESSERA_SEED_DEMO=1`.
use anyhow::{Context, Result};
use chrono::{Duration, Utc};
use rusqlite::{params, Connection};
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::Path;
use tessera_core::manifest::SnapshotManifest;
use tessera_store::Vault;
use uuid::Uuid;
const MARKER: &str = ".tessera-demo-seed-v1.json";
const DEMO_NS: &str = "tessera-demo-v1";
#[derive(Debug, Serialize, Deserialize)]
pub struct SeedReport {
pub skipped: bool,
pub orbits: usize,
pub snapshots: usize,
pub outposts: usize,
}
#[derive(Clone)]
struct DemoOrbit {
slug: &'static str,
provider: &'static str,
config: serde_json::Value,
schedule: &'static str,
decay: &'static str,
dry_run: bool,
status: &'static str,
snap_count: usize,
base_size_kb: u32,
}
fn demo_id(kind: &str, name: &str) -> Uuid {
Uuid::new_v5(&Uuid::NAMESPACE_OID, format!("{DEMO_NS}:{kind}:{name}").as_bytes())
}
pub fn apply(data_dir: &Path, vault_pass: &str, force: bool) -> Result<SeedReport> {
let marker_path = data_dir.join(MARKER);
if marker_path.exists() && !force {
let existing: StoredMarker = serde_json::from_str(&fs::read_to_string(&marker_path)?)?;
return Ok(SeedReport {
skipped: true,
orbits: existing.orbits,
snapshots: existing.snapshots,
outposts: existing.outposts,
});
}
if force {
clear_demo(data_dir, vault_pass)?;
}
fs::create_dir_all(data_dir)?;
let db_path = data_dir.join("tessera.db");
let conn = Connection::open(&db_path).context("open sqlite")?;
migrate(&conn)?;
let vault_path = data_dir.join("vault");
let mut vault = if vault_path.join("config").exists() {
Vault::open(&vault_path, vault_pass)?
} else {
Vault::init(&vault_path, vault_pass)?
};
let orbits = demo_orbits();
let mut snap_total = 0;
let now = Utc::now();
for o in &orbits {
let orbit_id = demo_id("orbit", o.slug);
let config = serde_json::to_string(&o.config)?;
conn.execute(
r#"INSERT INTO orbits (id, name, provider, provider_config, schedule, decay_preset, dry_run, last_status)
VALUES (?1,?2,?3,?4,?5,?6,?7,?8)
ON CONFLICT(id) DO UPDATE SET
name=excluded.name, provider=excluded.provider, provider_config=excluded.provider_config,
schedule=excluded.schedule, decay_preset=excluded.decay_preset, dry_run=excluded.dry_run,
last_status=excluded.last_status"#,
params![
orbit_id.to_string(),
o.slug,
o.provider,
config,
o.schedule,
o.decay,
o.dry_run as i64,
o.status,
],
)?;
if o.dry_run {
continue;
}
for i in 0..o.snap_count {
let snap_id = demo_id("snap", &format!("{}:{}", o.slug, i));
let taken_at = now - Duration::hours((i as i64 + 1) * 9 + (o.slug.len() as i64 % 5));
let payload = synthetic_payload(o.slug, o.base_size_kb + (i as u32) * 17);
let manifest = SnapshotManifest {
snapshot_id: snap_id,
orbit_id,
orbit_name: o.slug.into(),
labels: vec![o.provider.into()],
provider: o.provider.into(),
paths: vec![format!("/var/backups/{}", o.slug)],
restore_hints: serde_json::json!({ "demo": true }),
};
vault.snapshot_at(manifest, &payload, false, taken_at)?;
snap_total += 1;
}
}
let outposts = seed_outposts(&conn)?;
let report = StoredMarker {
orbits: orbits.len(),
snapshots: snap_total,
outposts,
seeded_at: now.to_rfc3339(),
};
fs::write(&marker_path, serde_json::to_string_pretty(&report)?)?;
Ok(SeedReport {
skipped: false,
orbits: orbits.len(),
snapshots: snap_total,
outposts,
})
}
pub fn clear_demo(data_dir: &Path, vault_pass: &str) -> Result<()> {
let marker_path = data_dir.join(MARKER);
let db_path = data_dir.join("tessera.db");
if db_path.exists() {
let conn = Connection::open(&db_path)?;
migrate(&conn)?;
for o in demo_orbits() {
let id = demo_id("orbit", o.slug).to_string();
conn.execute("DELETE FROM orbits WHERE id = ?1", params![id])?;
}
conn.execute(
"DELETE FROM outposts WHERE id LIKE 'demo-%'",
[],
)?;
}
let vault_path = data_dir.join("vault");
if vault_path.join("config").exists() {
let vault = Vault::open(&vault_path, vault_pass)?;
for o in demo_orbits() {
if o.dry_run {
continue;
}
for i in 0..o.snap_count {
let snap_id = demo_id("snap", &format!("{}:{}", o.slug, i));
let p = vault
.root()
.join("snapshots")
.join(format!("{snap_id}.json"));
if p.exists() {
fs::remove_file(p)?;
}
}
}
}
if marker_path.exists() {
fs::remove_file(marker_path)?;
}
Ok(())
}
#[derive(Serialize, Deserialize)]
struct StoredMarker {
orbits: usize,
snapshots: usize,
outposts: usize,
seeded_at: String,
}
fn migrate(conn: &Connection) -> Result<()> {
conn.execute_batch(
r#"
CREATE TABLE IF NOT EXISTS orbits (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
provider TEXT NOT NULL,
provider_config TEXT NOT NULL,
schedule TEXT,
decay_preset TEXT NOT NULL DEFAULT 'week-of-dailies',
dry_run INTEGER NOT NULL DEFAULT 0,
last_status TEXT NOT NULL DEFAULT 'idle'
);
CREATE TABLE IF NOT EXISTS outposts (
id TEXT PRIMARY KEY,
name TEXT,
last_seen TEXT,
pairing_state TEXT NOT NULL DEFAULT 'unpaired'
);
"#,
)?;
Ok(())
}
fn seed_outposts(conn: &Connection) -> Result<usize> {
let rows = [
("demo-edge-1", "homelab-edge", "active"),
("demo-edge-2", "office-nuc", "active"),
("demo-edge-3", "dr-site-cold", "offline"),
];
for (id, name, state) in rows {
conn.execute(
"INSERT INTO outposts (id, name, last_seen, pairing_state) VALUES (?1,?2,datetime('now'),?3)
ON CONFLICT(id) DO UPDATE SET name=excluded.name, pairing_state=excluded.pairing_state",
params![id, name, state],
)?;
}
Ok(rows.len())
}
fn synthetic_payload(slug: &str, size_kb: u32) -> Vec<u8> {
let unit = format!("tessera-demo::{slug}::").into_bytes();
let target = (size_kb as usize).saturating_mul(1024).max(256);
let mut out = Vec::with_capacity(target);
while out.len() < target {
let take = (target - out.len()).min(unit.len());
out.extend_from_slice(&unit[..take]);
}
out
}
fn demo_orbits() -> Vec<DemoOrbit> {
vec![
DemoOrbit {
slug: "prod-api",
provider: "postgres",
config: serde_json::json!({ "connection_url": "postgres://demo/prod" }),
schedule: "0 2 * * *",
decay: "year-of-monthlies",
dry_run: false,
status: "completed",
snap_count: 4,
base_size_kb: 420,
},
DemoOrbit {
slug: "wiki",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/data/wiki"] }),
schedule: "0 3 * * *",
decay: "week-of-dailies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 88,
},
DemoOrbit {
slug: "gitea",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/var/gitea"] }),
schedule: "0 1 * * *",
decay: "month-of-weeklies",
dry_run: false,
status: "running",
snap_count: 3,
base_size_kb: 220,
},
DemoOrbit {
slug: "monitoring",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/etc/prometheus", "/var/lib/grafana"] }),
schedule: "0 */6 * * *",
decay: "week-of-dailies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 64,
},
DemoOrbit {
slug: "staging-db",
provider: "postgres",
config: serde_json::json!({ "connection_url": "postgres://demo/staging" }),
schedule: "0 4 * * 0",
decay: "week-of-dailies",
dry_run: false,
status: "failed",
snap_count: 2,
base_size_kb: 310,
},
DemoOrbit {
slug: "legal-docs",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/vault/legal"] }),
schedule: "0 0 * * 1",
decay: "year-of-monthlies",
dry_run: false,
status: "completed",
snap_count: 2,
base_size_kb: 1200,
},
DemoOrbit {
slug: "matrix-synapse",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/var/matrix"] }),
schedule: "0 2 * * *",
decay: "month-of-weeklies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 540,
},
DemoOrbit {
slug: "home-assistant",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/config"] }),
schedule: "0 */12 * * *",
decay: "week-of-dailies",
dry_run: false,
status: "completed",
snap_count: 2,
base_size_kb: 45,
},
DemoOrbit {
slug: "deno-api",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/app/deno"] }),
schedule: "0 5 * * *",
decay: "week-of-dailies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 96,
},
DemoOrbit {
slug: "mail-archive",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/mail/archive"] }),
schedule: "0 3 * * 6",
decay: "year-of-monthlies",
dry_run: false,
status: "completed",
snap_count: 2,
base_size_kb: 890,
},
DemoOrbit {
slug: "rehearse-nightly",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/tmp/rehearse"] }),
schedule: "0 2 * * *",
decay: "week-of-dailies",
dry_run: true,
status: "rehearsed",
snap_count: 0,
base_size_kb: 0,
},
DemoOrbit {
slug: "observability-pg",
provider: "postgres",
config: serde_json::json!({ "connection_url": "postgres://demo/metrics" }),
schedule: "0 1 * * *",
decay: "month-of-weeklies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 180,
},
]
}

View File

@@ -12,6 +12,7 @@ path = "src/main.rs"
tessera-core = { path = "../tessera-core" } tessera-core = { path = "../tessera-core" }
tessera-store = { path = "../tessera-store" } tessera-store = { path = "../tessera-store" }
tessera-providers = { path = "../tessera-providers" } tessera-providers = { path = "../tessera-providers" }
tessera-demo = { path = "../tessera-demo" }
anyhow.workspace = true anyhow.workspace = true
axum.workspace = true axum.workspace = true
chrono.workspace = true chrono.workspace = true

View File

@@ -19,6 +19,27 @@ async fn main() -> Result<()> {
let vault_pass = std::env::var("TESSERA_VAULT_PASSPHRASE").unwrap_or_else(|_| "dev-vault-key".into()); let vault_pass = std::env::var("TESSERA_VAULT_PASSPHRASE").unwrap_or_else(|_| "dev-vault-key".into());
let state = HubState::bootstrap(&data_dir, &vault_pass).await?; let state = HubState::bootstrap(&data_dir, &vault_pass).await?;
if std::env::var("TESSERA_SEED_DEMO")
.map(|v| v == "1" || v == "true")
.unwrap_or(false)
{
match tessera_demo::apply(std::path::Path::new(&data_dir), &vault_pass, false) {
Ok(r) if !r.skipped => {
tracing::info!(
"demo seed: {} orbits, {} snapshots",
r.orbits,
r.snapshots
);
let vault_path = std::path::Path::new(&data_dir).join("vault");
let vault = tessera_store::Vault::open(&vault_path, &vault_pass)?;
*state.vault.write().await = vault;
}
Ok(r) => tracing::info!("demo seed skipped (already applied, {} orbits)", r.orbits),
Err(e) => tracing::warn!("demo seed failed: {e}"),
}
}
scheduler::start_orbit_scheduler(state.clone()).await?; scheduler::start_orbit_scheduler(state.clone()).await?;
let app = api::router(state); let app = api::router(state);

View File

@@ -117,11 +117,22 @@ impl Vault {
manifest: SnapshotManifest, manifest: SnapshotManifest,
payload: &[u8], payload: &[u8],
dry_run: bool, dry_run: bool,
) -> Result<StoredSnapshot> {
self.snapshot_at(manifest, payload, dry_run, Utc::now())
}
/// Like `snapshot`, but allows a custom timestamp (demo/historical imports).
pub fn snapshot_at(
&mut self,
manifest: SnapshotManifest,
payload: &[u8],
dry_run: bool,
taken_at: DateTime<Utc>,
) -> Result<StoredSnapshot> { ) -> Result<StoredSnapshot> {
if dry_run { if dry_run {
return Ok(StoredSnapshot { return Ok(StoredSnapshot {
id: manifest.snapshot_id, id: manifest.snapshot_id,
taken_at: Utc::now(), taken_at,
manifest, manifest,
size_bytes: payload.len() as u64, size_bytes: payload.len() as u64,
tree_root: "dry-run".into(), tree_root: "dry-run".into(),
@@ -133,7 +144,7 @@ impl Vault {
let snap = StoredSnapshot { let snap = StoredSnapshot {
id: manifest.snapshot_id, id: manifest.snapshot_id,
taken_at: Utc::now(), taken_at,
manifest, manifest,
size_bytes: payload.len() as u64, size_bytes: payload.len() as u64,
tree_root: chunk_id, tree_root: chunk_id,