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