OXYGENHUB
◆ v0.9.2 oxygenhub / crates / hub / src / web / help.rs
2.2 KiB · Rust · last changed Keys say when each was last used; Help explains AI identities (closes #286, closes #287) 15 days ago source blame history raw
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
}
21
22
pub async fn help(State(app): State<Shared>, viewer: Viewer) -> Page<HelpPage> {
23
    let shell = Shell::new(&app, "/help", &viewer);
24
    let who = shell.user.clone().unwrap_or_else(|| "OWNER".into());
25
    let base = app.config.base_url().trim_end_matches('/').to_string();
26
    Page(HelpPage { shell, q: Quickstart::new(&app, true), base, who })
27
}
28
29
impl HelpPage {
30
    /// An example repository address on this hub.
31
    pub fn repo_url(&self) -> String {
32
        format!("{}/{}/REPOSITORY", self.base, self.who)
33
    }
34
35
    /// An agent's own home, keyless, with its grant kept (#287).
36
    pub fn agent_home_cmd(&self) -> String {
37
        format!(
38
            "export OXY_HOME=~/.oxy-agents/claude\noxy config --user author.signer keyless\noxy config --user keyless.hub {base}\noxy config --user core.sign seal\noxy auth grant {base}   # paste the token, then Ctrl-D",
39
            base = self.base
40
        )
41
    }
42
43
    /// A repository's trust policy admitting an agent's certified keys (#287).
44
    pub fn subject_grant_cmd(&self) -> String {
45
        format!(
46
            "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy policy grant-subject agent:claude@{} --issuer hub.identity --scope changes,refs",
47
            self.base, self.who
48
        )
49
    }
50
51
    pub fn delegate_cmd(&self) -> String {
52
        format!(
53
            "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy identity delegate add hub.identity --scope changes,refs",
54
            self.base
55
        )
56
    }
57
58
    pub fn clone_cmd(&self) -> String {
59
        let url = self.repo_url();
60
        match &self.q.ca_url {
61
            Some(_) => format!("OXY_CA={} oxy clone {url}", self.q.ca_file),
62
            None => format!("oxy clone {url}"),
63
        }
64
    }
65
}