summaryrefslogtreecommitdiffstats
path: root/src/repl
diff options
context:
space:
mode:
Diffstat (limited to 'src/repl')
-rw-r--r--src/repl/mod.rs67
1 files changed, 40 insertions, 27 deletions
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index d7ddb96..97d8f84 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -24,25 +24,30 @@ use reedline::{
ReedlineEvent, ReedlineMenu, ValidationResult, Validator, Vi,
};
use reedline::{MenuBuilder, Signal};
+use std::sync::LazyLock;
use std::{env, process};
const MENU_NAME: &str = "completion_menu";
-lazy_static::lazy_static! {
- static ref REPL_COMMANDS: [ReplCommand; 36] = [
+static REPL_COMMANDS: LazyLock<[ReplCommand; 36]> = LazyLock::new(|| {
+ [
ReplCommand::new(".help", "Show this help guide", AssertState::pass()),
ReplCommand::new(".info", "Show system info", AssertState::pass()),
- ReplCommand::new(".edit config", "Modify configuration file", AssertState::False(StateFlags::AGENT)),
+ ReplCommand::new(
+ ".edit config",
+ "Modify configuration file",
+ AssertState::False(StateFlags::AGENT),
+ ),
ReplCommand::new(".model", "Switch LLM model", AssertState::pass()),
ReplCommand::new(
".prompt",
"Set a temporary role using a prompt",
- AssertState::False(StateFlags::SESSION | StateFlags::AGENT)
+ AssertState::False(StateFlags::SESSION | StateFlags::AGENT),
),
ReplCommand::new(
".role",
"Create or switch to a role",
- AssertState::False(StateFlags::SESSION | StateFlags::AGENT)
+ AssertState::False(StateFlags::SESSION | StateFlags::AGENT),
),
ReplCommand::new(
".info role",
@@ -57,7 +62,10 @@ lazy_static::lazy_static! {
ReplCommand::new(
".save role",
"Save current role to file",
- AssertState::TrueFalse(StateFlags::ROLE, StateFlags::SESSION_EMPTY | StateFlags::SESSION),
+ AssertState::TrueFalse(
+ StateFlags::ROLE,
+ StateFlags::SESSION_EMPTY | StateFlags::SESSION,
+ ),
),
ReplCommand::new(
".exit role",
@@ -72,12 +80,12 @@ lazy_static::lazy_static! {
ReplCommand::new(
".empty session",
"Clear session messages",
- AssertState::True(StateFlags::SESSION)
+ AssertState::True(StateFlags::SESSION),
),
ReplCommand::new(
".compress session",
"Compress session messages",
- AssertState::True(StateFlags::SESSION)
+ AssertState::True(StateFlags::SESSION),
),
ReplCommand::new(
".info session",
@@ -87,23 +95,23 @@ lazy_static::lazy_static! {
ReplCommand::new(
".edit session",
"Modify current session",
- AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION)
+ AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION),
),
ReplCommand::new(
".save session",
"Save current session to file",
- AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION)
+ AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION),
),
ReplCommand::new(
".exit session",
"Exit active session",
- AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION)
+ AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION),
),
ReplCommand::new(".agent", "Use an agent", AssertState::bare()),
ReplCommand::new(
".starter",
"Use a conversation starter",
- AssertState::True(StateFlags::AGENT)
+ AssertState::True(StateFlags::AGENT),
),
ReplCommand::new(
".edit agent-config",
@@ -118,12 +126,12 @@ lazy_static::lazy_static! {
ReplCommand::new(
".exit agent",
"Leave agent",
- AssertState::True(StateFlags::AGENT)
+ AssertState::True(StateFlags::AGENT),
),
ReplCommand::new(
".rag",
"Initialize or access RAG",
- AssertState::False(StateFlags::AGENT)
+ AssertState::False(StateFlags::AGENT),
),
ReplCommand::new(
".edit rag-docs",
@@ -150,30 +158,35 @@ lazy_static::lazy_static! {
"Leave RAG",
AssertState::TrueFalse(StateFlags::RAG, StateFlags::AGENT),
),
- ReplCommand::new(
- ".macro",
- "Execute a macro",
- AssertState::pass()
- ),
+ ReplCommand::new(".macro", "Execute a macro", AssertState::pass()),
ReplCommand::new(
".file",
"Include files, directories, URLs or commands",
- AssertState::pass()
+ AssertState::pass(),
+ ),
+ ReplCommand::new(
+ ".continue",
+ "Continue previous response",
+ AssertState::pass(),
),
- ReplCommand::new(".continue", "Continue previous response", AssertState::pass()),
ReplCommand::new(
".regenerate",
"Regenerate last response",
- AssertState::pass()
+ AssertState::pass(),
),
ReplCommand::new(".copy", "Copy last response", AssertState::pass()),
ReplCommand::new(".set", "Modify runtime settings", AssertState::pass()),
- ReplCommand::new(".delete", "Delete roles, sessions, RAGs, or agents", AssertState::pass()),
+ ReplCommand::new(
+ ".delete",
+ "Delete roles, sessions, RAGs, or agents",
+ AssertState::pass(),
+ ),
ReplCommand::new(".exit", "Exit REPL", AssertState::pass()),
- ];
- static ref COMMAND_RE: Regex = Regex::new(r"^\s*(\.\S*)\s*").unwrap();
- static ref MULTILINE_RE: Regex = Regex::new(r"(?s)^\s*:::\s*(.*)\s*:::\s*$").unwrap();
-}
+ ]
+});
+static COMMAND_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\s*(\.\S*)\s*").unwrap());
+static MULTILINE_RE: LazyLock<Regex> =
+ LazyLock::new(|| Regex::new(r"(?s)^\s*:::\s*(.*)\s*:::\s*$").unwrap());
pub struct Repl {
config: GlobalConfig,