Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(cli): share the admin-route fallback with show; name --enable-api
AkitaOnRails5507b790f9a1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 02218af6..f1181a54 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,11 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Fixed-- `ai-memory list-projects` no longer fails with `404 Not Found` against a- server started without `--enable-web`. `GET /api/v1/projects` is mounted only- with the web UI, so on a 404 the command now reads the always-mounted- `GET /admin/projects` and applies `--workspace` on the client. If that call- fails too, the error names both routes and the two ways to fix it.+- Fixed `ai-memory list-projects` failing with `404 Not Found` against a+ server started without `--enable-web` or `--enable-api`, the routes that+ mount `GET /api/v1/projects`. On a 404 it now reads the always-mounted+ `GET /admin/projects` and applies `--workspace` itself; `ai-memory show`+ lists projects the same way instead of falling back to local scan results.+ If both calls fail, the error names both routes and the likely causes.+ (#1236)- Replaced the unmaintained YAML library (`serde_yaml` and its`unsafe-libyaml` parser, RUSTSEC-2024-0449) with `serde-saphyr`. The serverreads existing page frontmatter to exactly the same values as before. Onediff --git a/crates/ai-memory-cli/src/cli.rs b/crates/ai-memory-cli/src/cli.rsindex 6f77ba02..f069ad80 100644--- a/crates/ai-memory-cli/src/cli.rs+++ b/crates/ai-memory-cli/src/cli.rs@@ -118,7 +118,7 @@ pub enum Command {/// List every workspace/project pair the server knows about (plain,/// scriptable output — the read-only equivalent of hitting/// `GET /api/v1/projects` directly, falling back to `GET /admin/projects`- /// when the server runs without `--enable-web`).+ /// when the server runs without `--enable-web` or `--enable-api`).ListProjects(ListProjectsArgs),/// Check capture coverage: compare local harness session stores for this/// project against what the server captured, and warn when a harness randiff --git a/crates/ai-memory-cli/src/commands/list_projects.rs b/crates/ai-memory-cli/src/commands/list_projects.rsindex 333b5569..61efd9bf 100644--- a/crates/ai-memory-cli/src/commands/list_projects.rs+++ b/crates/ai-memory-cli/src/commands/list_projects.rs@@ -7,8 +7,9 @@//! falls back to client-local scan results when the server call fails, so it//! was never a plain, scriptable listing on its own.//!-//! `/api/v1/projects` is mounted only by `serve --enable-web`, so a 404 there-//! falls back to the always-mounted `GET /admin/projects`.+//! `/api/v1/projects` is mounted only by `serve --enable-web` or+//! `--enable-api`, so a 404 there falls back to the always-mounted+//! `GET /admin/projects`. `show` lists projects through the same fallback.use anyhow::{Context, Result};use serde::Deserialize;@@ -43,17 +44,26 @@ async fn fetch_sorted(endpoint: &ServerEndpoint,workspace: Option<&str>,) -> Result<Vec<ProjectRow>> {- let workspace = workspace.map(str::trim).filter(|value| !value.is_empty());- let query = workspace.map_or_else(Vec::new, |workspace| vec![("workspace", workspace)]);- let mut rows = match get_json::<Vec<ProjectRow>>(endpoint, WEB_PROJECTS_PATH, &query).await {- Ok(rows) => rows,- Err(error) if is_not_found(&error) => fetch_from_admin(endpoint, workspace).await?,- Err(error) => return Err(error),- };+ let mut rows = fetch_project_rows(endpoint, workspace).await?;sort_rows(&mut rows);Ok(rows)}+/// The server's project listing, from `/api/v1/projects` or, when that route+/// is not mounted, from `/admin/projects` filtered to `workspace` here.+pub(crate) async fn fetch_project_rows(+ endpoint: &ServerEndpoint,+ workspace: Option<&str>,+) -> Result<Vec<ProjectRow>> {+ let workspace = workspace.map(str::trim).filter(|value| !value.is_empty());+ let query = workspace.map_or_else(Vec::new, |workspace| vec![("workspace", workspace)]);+ match get_json::<Vec<ProjectRow>>(endpoint, WEB_PROJECTS_PATH, &query).await {+ Ok(rows) => Ok(rows),+ Err(error) if is_not_found(&error) => fetch_from_admin(endpoint, workspace).await,+ Err(error) => Err(error),+ }+}+async fn fetch_from_admin(endpoint: &ServerEndpoint,workspace: Option<&str>,@@ -62,9 +72,10 @@ async fn fetch_from_admin(.await.with_context(|| {format!(- "{WEB_PROJECTS_PATH} returned 404 (the server runs without `serve --enable-web`), \- and the fallback {ADMIN_PROJECTS_PATH} also failed; restart the server with \- `--enable-web`, or use a token the server accepts on admin routes"+ "{WEB_PROJECTS_PATH} returned 404 and the fallback {ADMIN_PROJECTS_PATH} also \+ failed. The server may run without `--enable-api` (or `--enable-web`), the \+ server URL or base path may be wrong, or, on a multi-user server, the admin \+ route needs the root token")})?;Ok(keep_workspace(listing.projects, workspace))diff --git a/crates/ai-memory-cli/src/commands/show.rs b/crates/ai-memory-cli/src/commands/show.rsindex 111af70e..7fc9926f 100644--- a/crates/ai-memory-cli/src/commands/show.rs+++ b/crates/ai-memory-cli/src/commands/show.rs@@ -21,7 +21,7 @@ use crate::cli::{};use crate::commands::{install_instructions, project_registry};use crate::config::{Config, DEFAULT_WORKSPACE};-use crate::http_client::{ServerEndpoint, get_json};+use crate::http_client::ServerEndpoint;const PROJECT_MARKERS: [&str; 12] = [".git",@@ -251,10 +251,12 @@ async fn collect_candidates(workspace_filter: Option<&str>,scan: bool,) -> Vec<Candidate> {- let query = workspace_filter- .filter(|value| !value.is_empty())- .map_or_else(Vec::new, |workspace| vec![("workspace", workspace)]);- let rows: Option<Vec<ProjectRow>> = match get_json(endpoint, "/api/v1/projects", &query).await {+ let rows: Option<Vec<ProjectRow>> = match crate::commands::list_projects::fetch_project_rows(+ endpoint,+ workspace_filter,+ )+ .await+ {Ok(rows) => Some(rows),Err(error) => {eprintln!(