From 10de6025b579169cecb26fc8b2ea599da54e2fc2 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Wed, 10 Jun 2026 20:26:17 -0600 Subject: [PATCH] feat: Added an --init-memory [global|workspace] flag to easily and quickly enable memory --- src/cli/mod.rs | 5 ++++- src/config/mod.rs | 6 ++++++ src/main.rs | 33 +++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index a7571b5..54dae2e 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -4,7 +4,7 @@ use crate::cli::completer::{ ShellCompletion, agent_completer, macro_completer, model_completer, rag_completer, role_completer, secrets_completer, session_completer, }; -use crate::config::{AssetCategory, InstallFilter}; +use crate::config::{AssetCategory, InstallFilter, MemoryScope}; use anyhow::{Context, Result}; use clap::ValueHint; use clap::{Parser, crate_authors, crate_description, crate_version}; @@ -78,6 +78,9 @@ pub struct Cli { /// Disable memory for this invocation #[arg(long)] pub no_memory: bool, + /// Bootstrap a memory marker so coyote begins loading memory next run + #[arg(long, value_name = "SCOPE", value_enum)] + pub init_memory: Option, /// Display the message without sending it #[arg(long)] pub dry_run: bool, diff --git a/src/config/mod.rs b/src/config/mod.rs index a26a1a0..ebe4258 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -363,6 +363,12 @@ impl AssetCategory { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)] +pub enum MemoryScope { + Global, + Workspace, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)] pub enum InstallFilter { Agents, diff --git a/src/main.rs b/src/main.rs index fa235f5..43c74b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,9 +22,9 @@ use crate::client::{ }; use crate::config::paths; use crate::config::{ - Agent, AppConfig, AppState, CODE_ROLE, Config, EXPLAIN_SHELL_ROLE, Input, RequestContext, - SHELL_ROLE, TEMP_SESSION_NAME, WorkingMode, ensure_parent_exists, install_builtins, - list_agents, load_env_file, macro_execute, sync_models, + Agent, AppConfig, AppState, CODE_ROLE, Config, EXPLAIN_SHELL_ROLE, Input, MemoryScope, + RequestContext, SHELL_ROLE, TEMP_SESSION_NAME, WorkingMode, ensure_parent_exists, + install_builtins, list_agents, load_env_file, macro_execute, sync_models, }; use crate::render::{prompt_theme, render_error}; use crate::repl::Repl; @@ -42,7 +42,7 @@ use log4rs::config::{Appender, Logger, Root}; use log4rs::encode::pattern::PatternEncoder; use oauth::OAuthProvider; use std::path::PathBuf; -use std::{env, process, sync::Arc}; +use std::{env, fs, process, sync::Arc}; #[tokio::main] async fn main() -> Result<()> { @@ -301,6 +301,31 @@ async fn run( if cli.save_session { ctx.set_save_session_this_time()?; } + if let Some(scope) = cli.init_memory { + let (path, content) = match scope { + MemoryScope::Global => ( + paths::global_memory_index_path(), + "# Global Memory\n\n\n\n", + ), + MemoryScope::Workspace => ( + std::env::current_dir()?.join("COYOTE.md"), + "# Workspace Memory\n\n\n", + ), + }; + + if path.exists() { + eprintln!("Memory marker already exists at '{}'.", path.display()); + return Ok(()); + } + + if let Some(parent) = path.parent() { + fs::create_dir_all(parent)?; + } + + fs::write(&path, content)?; + println!("✓ Created memory marker at '{}'.", path.display()); + return Ok(()); + } if cli.info { let app: Arc = Arc::clone(&ctx.app.config); let info = ctx.info(app.as_ref())?;