OXYGENHUB

Coverage / crates/hub/src/web/help.rs 76.3%

29 of 38 lines run, 8 of 18 functions · run #537 on main · run missed

1
//! `/help` (hub spec §6.3): getting started with this hub's own address,
2
//! remote name and certificate filled in, the keyboard, and a glossary
3
//! for people coming from GitHub.
4
5
use super::repo::Quickstart;
6
use super::{Page, Shell};
7
use crate::auth::Viewer;
8
use crate::Shared;
9
use askama::Template;
10
use axum::extract::State;
11
12
#[derive(Template)]
13
#[template(path = "help.html")]
14
pub struct HelpPage {
15
    shell: Shell,
16
    q: Quickstart,
17
    base: String,
18
    /// The signed-in user, or a placeholder, for example URLs.
19
    who: String,
20
    /// What an agent's changes are authored as: the signed-in user's
21
    /// name, email and newest linked key, or placeholders (#352).
22
    author: (String, String, String),
23
}
24
251×
pub async fn help(State(app): State<Shared>, viewer: Viewer) -> Page<HelpPage> {
261×
    let shell = Shell::new(&app, "/help", &viewer);
271×
    let who = shell.user.clone().unwrap_or_else(|| "OWNER".into());
281×
    let base = app.config.base_url().trim_end_matches('/').to_string();
291×
    let mut author = ("YOUR NAME".to_string(), "[email protected]".to_string(), "YOUR_KEY".to_string());
301×
    if let Some(name) = &shell.user {
310×
        if let Ok(Some(a)) = crate::db::accounts::account_by_name(&app.db, name).await {
320×
            let newest = crate::db::accounts::identities_of(&app.db, a.id).await.ok().and_then(|ids| ids.into_iter().next());
330×
            if let Some(id) = newest {
340×
                author = (id.name, id.email, id.key);
350×
            } else {
360×
                author.0 = if a.display_name.is_empty() { a.username } else { a.display_name };
37
            }
380×
        }
391×
    }
401×
    Page(HelpPage { shell, q: Quickstart::new(&app, true), base, who, author })
411×
}
42
43
impl HelpPage {
44
    /// An example repository address on this hub.
452×
    pub fn repo_url(&self) -> String {
462×
        format!("{}/{}/REPOSITORY", self.base, self.who)
472×
    }
48
49
    /// An agent's own home, keyless, with its grant kept (#287), authored
50
    /// as you with the key you make its grant with (#352): without an
51
    /// author its changes are unattributed, and a grant made by a newer key
52
    /// than its author key does not count for it.
531×
    pub fn agent_home_cmd(&self) -> String {
541×
        let (name, email, key) = &self.author;
551×
        format!(
56
            "mkdir -p ~/.oxy-agents/claude/keys\n\
57
             oxy identity export ~/.oxy-agents/claude/keys/{key}.identity   # in a checkout of yours, as you\n\
58
             export OXY_HOME=~/.oxy-agents/claude\n\
59
             oxy config --user author.name \"{name}\"\n\
60
             oxy config --user author.email \"{email}\"\n\
61
             oxy config --user author.key {key}\n\
62
             oxy config --user author.signer keyless\n\
63
             oxy config --user keyless.hub {base}\n\
64
             oxy config --user core.sign seal\n\
65
             oxy auth grant {base}   # paste the token, then Ctrl-D",
66
            base = self.base
67
        )
681×
    }
69
70
    /// A repository's trust policy admitting an agent's certified keys (#287).
711×
    pub fn subject_grant_cmd(&self) -> String {
721×
        format!(
73
            "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy policy grant-subject agent:claude@{} --issuer hub.identity --scope changes,refs",
74
            self.base, self.who
75
        )
761×
    }
77
781×
    pub fn delegate_cmd(&self) -> String {
791×
        format!(
80
            "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy identity delegate add hub.identity --scope changes,refs",
81
            self.base
82
        )
831×
    }
84
851×
    pub fn clone_cmd(&self) -> String {
861×
        let url = self.repo_url();
871×
        match &self.q.ca_url {
880×
            Some(_) => format!("OXY_CA={} oxy clone {url}", self.q.ca_file),
891×
            None => format!("oxy clone {url}"),
90
        }
911×
    }
92
}