Skip to content

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

Rust

fix(cli): refuse empty scope flags on message commands

Vinícius DS Andrade97dc901a0ca4
diff --git a/crates/ai-memory-cli/src/commands/message.rs b/crates/ai-memory-cli/src/commands/message.rs
index e34590ad..bacf8f92 100644
--- a/crates/ai-memory-cli/src/commands/message.rs
+++ b/crates/ai-memory-cli/src/commands/message.rs
@@ -89,6 +89,11 @@ struct SendRequest<'a> {
}
async fn send(config: &Config, args: MessageSendArgs) -> Result<()> {
+ super::refuse_empty_explicit(args.from_workspace.as_deref(), "--from-workspace")?;
+ super::refuse_empty_explicit(args.from_project.as_deref(), "--from-project")?;
+ super::refuse_empty_explicit(Some(args.to_workspace.as_str()), "--to-workspace")?;
+ super::refuse_empty_explicit(Some(args.to_project.as_str()), "--to-project")?;
+
let (from_workspace, from_project) = super::resolve_scope(
config,
args.from_workspace.as_deref(),
@@ -189,6 +194,9 @@ async fn list(config: &Config, args: MessageListArgs) -> Result<()> {
}
async fn pop(config: &Config, args: MessagePopArgs) -> Result<()> {
+ super::refuse_empty_explicit(args.workspace.as_deref(), "--workspace")?;
+ super::refuse_empty_explicit(args.project.as_deref(), "--project")?;
+ super::refuse_empty_explicit(args.id.as_deref(), "--id")?;
let (workspace, project) =
super::resolve_scope(config, args.workspace.as_deref(), args.project.as_deref())?;
let endpoint = ServerEndpoint::from_config_resolving_auth(config).await;
@@ -306,6 +314,9 @@ struct PopRequest<'a> {
}
async fn cancel(config: &Config, args: MessageCancelArgs) -> Result<()> {
+ super::refuse_empty_explicit(args.workspace.as_deref(), "--workspace")?;
+ super::refuse_empty_explicit(args.project.as_deref(), "--project")?;
+ super::refuse_empty_explicit(args.id.as_deref(), "--id")?;
if args.id.is_none() && !args.all {
anyhow::bail!("message cancel requires exactly one of --id <MESSAGE_ID> or --all");
}
@@ -448,4 +459,91 @@ mod tests {
let benign = render_popped(&message(Some("export endpoint"), "body"), "ws", "r", "N");
assert!(benign.contains(" subject: export endpoint\n"), "{benign}");
}
+
+ #[tokio::test]
+ async fn pop_refuses_empty_scope_flags_before_any_request() {
+ let config = Config::default();
+ let a = MessagePopArgs {
+ workspace: None,
+ project: Some(" ".into()),
+ id: None,
+ json: false,
+ };
+ let error = pop(&config, a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--project was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn pop_refuses_empty_id_before_any_request() {
+ let config = Config::default();
+ let a = MessagePopArgs {
+ workspace: None,
+ project: None,
+ id: Some(" ".into()),
+ json: false,
+ };
+ let error = pop(&config, a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--id was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn cancel_refuses_empty_scope_flags_before_any_request() {
+ let config = Config::default();
+ let a = MessageCancelArgs {
+ workspace: Some("".into()),
+ project: None,
+ id: None,
+ all: true,
+ json: false,
+ };
+ let error = cancel(&config, a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--workspace was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn send_refuses_empty_scope_flags_before_reading_stdin() {
+ let config = Config::default();
+ let a = MessageSendArgs {
+ from_workspace: None,
+ from_project: Some("".into()),
+ to_workspace: "team".into(),
+ to_project: "api".into(),
+ subject: None,
+ body: None,
+ json: false,
+ };
+ let error = send(&config, a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--from-project was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
+
+ #[tokio::test]
+ async fn send_refuses_empty_to_project_before_reading_stdin() {
+ let config = Config::default();
+ let a = MessageSendArgs {
+ from_workspace: None,
+ from_project: None,
+ to_workspace: "team".into(),
+ to_project: " ".into(),
+ subject: None,
+ body: None,
+ json: false,
+ };
+ let error = send(&config, a).await.unwrap_err();
+ assert!(
+ error.to_string().contains("--to-project was passed empty"),
+ "unexpected error: {error}"
+ );
+ }
}