| 1 | |
|
| 2 | |
|
| 3 | |
|
| 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 | | |
| 19 | | who: String, |
| 20 | | |
| 21 | | |
| 22 | | author: (String, String, String), |
| 23 | | } |
| 24 | |
|
| 25 | 1× | pub async fn help(State(app): State<Shared>, viewer: Viewer) -> Page<HelpPage> { |
| 26 | 1× | let shell = Shell::new(&app, "/help", &viewer); |
| 27 | 1× | let who = shell.user.clone().unwrap_or_else(|| "OWNER".into()); |
| 28 | 1× | let base = app.config.base_url().trim_end_matches('/').to_string(); |
| 29 | 1× | let mut author = ("YOUR NAME".to_string(), "[email protected]".to_string(), "YOUR_KEY".to_string()); |
| 30 | 1× | if let Some(name) = &shell.user { |
| 31 | 0× | if let Ok(Some(a)) = crate::db::accounts::account_by_name(&app.db, name).await { |
| 32 | 0× | let newest = crate::db::accounts::identities_of(&app.db, a.id).await.ok().and_then(|ids| ids.into_iter().next()); |
| 33 | 0× | if let Some(id) = newest { |
| 34 | 0× | author = (id.name, id.email, id.key); |
| 35 | 0× | } else { |
| 36 | 0× | author.0 = if a.display_name.is_empty() { a.username } else { a.display_name }; |
| 37 | | } |
| 38 | 0× | } |
| 39 | 1× | } |
| 40 | 1× | Page(HelpPage { shell, q: Quickstart::new(&app, true), base, who, author }) |
| 41 | 1× | } |
| 42 | |
|
| 43 | | impl HelpPage { |
| 44 | | |
| 45 | 2× | pub fn repo_url(&self) -> String { |
| 46 | 2× | format!("{}/{}/REPOSITORY", self.base, self.who) |
| 47 | 2× | } |
| 48 | |
|
| 49 | | |
| 50 | | |
| 51 | | |
| 52 | | |
| 53 | 1× | pub fn agent_home_cmd(&self) -> String { |
| 54 | 1× | let (name, email, key) = &self.author; |
| 55 | 1× | 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 | | ) |
| 68 | 1× | } |
| 69 | |
|
| 70 | | |
| 71 | 1× | pub fn subject_grant_cmd(&self) -> String { |
| 72 | 1× | 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 | | ) |
| 76 | 1× | } |
| 77 | |
|
| 78 | 1× | pub fn delegate_cmd(&self) -> String { |
| 79 | 1× | format!( |
| 80 | | "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy identity delegate add hub.identity --scope changes,refs", |
| 81 | | self.base |
| 82 | | ) |
| 83 | 1× | } |
| 84 | |
|
| 85 | 1× | pub fn clone_cmd(&self) -> String { |
| 86 | 1× | let url = self.repo_url(); |
| 87 | 1× | match &self.q.ca_url { |
| 88 | 0× | Some(_) => format!("OXY_CA={} oxy clone {url}", self.q.ca_file), |
| 89 | 1× | None => format!("oxy clone {url}"), |
| 90 | | } |
| 91 | 1× | } |
| 92 | | } |