Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

style: rustfmt #825 web-login files (CI fmt gate)

AkitaOnRailsb2db2e000af7
diff --git a/crates/ai-memory-cli/src/commands/serve.rs b/crates/ai-memory-cli/src/commands/serve.rs
index 0698ee8f..ea29a263 100644
--- a/crates/ai-memory-cli/src/commands/serve.rs
+++ b/crates/ai-memory-cli/src/commands/serve.rs
@@ -4179,18 +4179,17 @@ mod tests {
.html_auth
.expect("builtin wiki mount must return html_auth");
let router = apply_host_layer(
- web.public
- .merge(
- web.protected
- .layer(axum::middleware::from_fn_with_state(
- auth,
- require_dual_auth,
- ))
- .layer(axum::middleware::from_fn_with_state(
- html_auth,
- html_auth_redirect_mw,
- )),
- ),
+ web.public.merge(
+ web.protected
+ .layer(axum::middleware::from_fn_with_state(
+ auth,
+ require_dual_auth,
+ ))
+ .layer(axum::middleware::from_fn_with_state(
+ html_auth,
+ html_auth_redirect_mw,
+ )),
+ ),
vec!["localhost".to_string()],
);
@@ -4252,7 +4251,10 @@ mod tests {
.unwrap();
let html = std::str::from_utf8(&body).unwrap();
assert!(html.contains("Sign in"), "login page body: {html}");
- assert!(html.contains("ai-memory-base-path"), "inject base-path meta");
+ assert!(
+ html.contains("ai-memory-base-path"),
+ "inject base-path meta"
+ );
// Change-password HTML is public (must_change_password flow).
let change = router
diff --git a/crates/ai-memory-web/src/html_auth.rs b/crates/ai-memory-web/src/html_auth.rs
index b6956948..86f3e7e9 100644
--- a/crates/ai-memory-web/src/html_auth.rs
+++ b/crates/ai-memory-web/src/html_auth.rs
@@ -75,17 +75,13 @@ pub fn sanitize_next(raw: Option<&str>, web_root: &str) -> String {
let Some(raw) = raw.map(str::trim).filter(|s| !s.is_empty()) else {
return default;
};
- if raw.contains("://") || raw.starts_with("//") || raw.contains('\\') || raw.contains('\0')
- {
+ if raw.contains("://") || raw.starts_with("//") || raw.contains('\\') || raw.contains('\0') {
return default;
}
if !raw.starts_with('/') {
return default;
}
- let path = raw
- .split_once(['?', '#'])
- .map(|(p, _)| p)
- .unwrap_or(raw);
+ let path = raw.split_once(['?', '#']).map(|(p, _)| p).unwrap_or(raw);
if web_root.is_empty() {
// Wiki mounted at host/base root — still reject escaping to
// sibling host routes by requiring a single-path absolute form
@@ -141,10 +137,8 @@ pub async fn html_auth_redirect_mw(
}
match resp.status() {
StatusCode::UNAUTHORIZED => {
- let next_q = urlencoding_encode(&sanitize_next(
- Some(&full_path_and_query),
- &cfg.web_root,
- ));
+ let next_q =
+ urlencoding_encode(&sanitize_next(Some(&full_path_and_query), &cfg.web_root));
Redirect::to(&format!("{}?next={next_q}", cfg.login_path)).into_response()
}
StatusCode::FORBIDDEN => Redirect::to(&cfg.change_password_path).into_response(),
@@ -220,10 +214,7 @@ mod tests {
#[test]
fn sanitize_next_under_base_path() {
- assert_eq!(
- sanitize_next(Some("/wiki/web"), "/wiki/web"),
- "/wiki/web"
- );
+ assert_eq!(sanitize_next(Some("/wiki/web"), "/wiki/web"), "/wiki/web");
assert_eq!(
sanitize_next(Some("/wiki/web/w/a"), "/wiki/web"),
"/wiki/web/w/a"
@@ -249,15 +240,15 @@ mod tests {
fn redirect_probe(status: StatusCode) -> Router {
let cfg = Arc::new(HtmlAuthRedirectConfig::from_mount("", "/web"));
Router::new()
- .route(
- "/wiki",
- get(move || async move { status.into_response() }),
- )
+ .route("/wiki", get(move || async move { status.into_response() }))
.route(
"/api/v1/projects",
get(move || async move { StatusCode::UNAUTHORIZED.into_response() }),
)
- .layer(axum::middleware::from_fn_with_state(cfg, html_auth_redirect_mw))
+ .layer(axum::middleware::from_fn_with_state(
+ cfg,
+ html_auth_redirect_mw,
+ ))
}
#[tokio::test]
diff --git a/crates/ai-memory-web/src/mount.rs b/crates/ai-memory-web/src/mount.rs
index 88f33893..cbc099ab 100644
--- a/crates/ai-memory-web/src/mount.rs
+++ b/crates/ai-memory-web/src/mount.rs
@@ -360,14 +360,7 @@ pub fn split_web_routers(
spec.base_path,
mount,
),
- protected: mount_builtin_browser(
- protected_api,
- reader,
- wiki,
- &slug,
- mount,
- browser_inject,
- ),
+ protected: mount_builtin_browser(protected_api, reader, wiki, &slug, mount, browser_inject),
html_auth: Some(auth_cfg),
})
}