hyperhive/hive-sh4re/src/assets.rs
iris e525dcb6d4 agent icon: 404 when unconfigured, client-side fallback
hive_sh4re::assets::branding_svg() resolved a server-side default
icon at runtime from HIVE_ASSETS_DIR — the only consumer was
serve_icon(), which fell back to it whenever the agent had no
`hyperhive.icon` override. Removed both the fallback and the
function: serve_icon() now 404s when /etc/hyperhive/icon.svg is
absent, and the per-agent web UI (app.js) picks up the existing
dashboard swarm.js pattern — swap the <img> src to the
frontend-bundled /favicon.svg on load failure, guarded against
looping if the fallback itself 404s.

Updated the doc/comment claims that said the server always returns
an image (docs/web-ui/agent.md, nix/agent-modules/default.nix, the
hive-c0re/forge/users.rs comment referencing the old shared-asset
set). forge-avatar-sync and the matrix avatar sync are unaffected —
both are gated on hyperhive.icon != null and never depended on the
removed fallback.
2026-08-10 20:59:59 +02:00

53 lines
2.2 KiB
Rust

//! Resolve the on-disk path to hyperhive's static assets (branding +
//! claude prompts). Single source of truth for both the host daemon
//! (`hive-c0re`) and the in-container harness binaries so they agree
//! on the lookup contract.
//!
//! At runtime, the path is read from `$HIVE_ASSETS_DIR`. In nix
//! builds that env var is set by the `hive-c0re` / `harness-base` modules
//! to `${pkgs.hyperhive-assets}/share/hyperhive` (see `nix/assets.nix`).
//! For `cargo run` outside nix, set it yourself:
//!
//! ```sh
//! HIVE_ASSETS_DIR=$(pwd)/dev-assets cargo run ...
//! ```
//!
//! where `dev-assets/` mirrors the nix output's `branding/` + `prompts/`
//! layout.
//!
//! Each crate that wants a specific asset goes through one of the
//! typed helpers (currently just `prompt_template()` — the branding
//! SVG used to live here too; the per-agent icon now 404s server-side
//! when unconfigured and falls back to a frontend-bundled default
//! client-side instead of a server-resolved runtime path, see
//! `hive-agent::web_ui::screen::serve_icon`) so the lookup contract is
//! centralised. Missing files panic at first call with a clear "set
//! `HIVE_ASSETS_DIR` + put the file at …" message.
use std::path::PathBuf;
/// Read `$HIVE_ASSETS_DIR`. Panics with a clear remediation message
/// when unset — every code path that calls into this module is one
/// the binary cannot run without, so a hard early failure is the
/// right shape.
fn dir() -> PathBuf {
match std::env::var("HIVE_ASSETS_DIR") {
Ok(v) if !v.is_empty() => PathBuf::from(v),
_ => panic!(
"HIVE_ASSETS_DIR is not set. Inside the nix-built systemd \
units this is wired automatically from \
`pkgs.hyperhive-assets`; for `cargo run` outside nix, \
set it to a directory laid out like \
`nix/assets.nix`'s output (branding/ + prompts/ \
subdirs). See hive-sh4re/src/assets.rs for the contract.",
),
}
}
/// `$HIVE_ASSETS_DIR/prompts/system.md` — the claude system prompt
/// template. `hive-agent::prompt::render` filters the role markers
/// inside it per agent / manager flavor.
#[must_use]
pub fn prompt_template() -> PathBuf {
dir().join("prompts/system.md")
}