Skip to content

An agent-managed museum exhibit, built in Rust with Gajae-Code / LazyCodex — developed and maintained with no human intervention.

Rust

Merge remote-tracking branch 'origin/rcc/ant-tools' into integration/dori-cleanroom

YeonGyu-Kim32f482e79ae8
diff --cc rust/crates/commands/src/lib.rs
index 34bf9ad3,e7f8d137..f4fdc2d0
--- a/rust/crates/commands/src/lib.rs
+++ b/rust/crates/commands/src/lib.rs
@@@ -1297,42 -399,41 +1297,77 @@@ mod tests
fn parses_supported_slash_commands() {
assert_eq!(SlashCommand::parse("/help"), Some(SlashCommand::Help));
assert_eq!(SlashCommand::parse(" /status "), Some(SlashCommand::Status));
+ assert_eq!(SlashCommand::parse("/sandbox"), Some(SlashCommand::Sandbox));
+ assert_eq!(
+ SlashCommand::parse("/bughunter runtime"),
+ Some(SlashCommand::Bughunter {
+ scope: Some("runtime".to_string())
+ })
+ );
+ assert_eq!(SlashCommand::parse("/commit"), Some(SlashCommand::Commit));
+ assert_eq!(
+ SlashCommand::parse("/pr ready for review"),
+ Some(SlashCommand::Pr {
+ context: Some("ready for review".to_string())
+ })
+ );
+ assert_eq!(
+ SlashCommand::parse("/issue flaky test"),
+ Some(SlashCommand::Issue {
+ context: Some("flaky test".to_string())
+ })
+ );
+ assert_eq!(
+ SlashCommand::parse("/ultraplan ship both features"),
+ Some(SlashCommand::Ultraplan {
+ task: Some("ship both features".to_string())
+ })
+ );
+ assert_eq!(
+ SlashCommand::parse("/teleport conversation.rs"),
+ Some(SlashCommand::Teleport {
+ target: Some("conversation.rs".to_string())
+ })
+ );
+ assert_eq!(
+ SlashCommand::parse("/debug-tool-call"),
+ Some(SlashCommand::DebugToolCall)
+ );
+ assert_eq!(
+ SlashCommand::parse("/bughunter runtime"),
+ Some(SlashCommand::Bughunter {
+ scope: Some("runtime".to_string())
+ })
+ );
+ assert_eq!(SlashCommand::parse("/commit"), Some(SlashCommand::Commit));
+ assert_eq!(
+ SlashCommand::parse("/pr ready for review"),
+ Some(SlashCommand::Pr {
+ context: Some("ready for review".to_string())
+ })
+ );
+ assert_eq!(
+ SlashCommand::parse("/issue flaky test"),
+ Some(SlashCommand::Issue {
+ context: Some("flaky test".to_string())
+ })
+ );
+ assert_eq!(
+ SlashCommand::parse("/ultraplan ship both features"),
+ Some(SlashCommand::Ultraplan {
+ task: Some("ship both features".to_string())
+ })
+ );
+ assert_eq!(
+ SlashCommand::parse("/teleport conversation.rs"),
+ Some(SlashCommand::Teleport {
+ target: Some("conversation.rs".to_string())
+ })
+ );
+ assert_eq!(
+ SlashCommand::parse("/debug-tool-call"),
+ Some(SlashCommand::DebugToolCall)
+ );
assert_eq!(
SlashCommand::parse("/model claude-opus"),
Some(SlashCommand::Model {
@@@ -1503,23 -568,22 +1538,39 @@@
let session = Session::new();
assert!(handle_slash_command("/unknown", &session, CompactionConfig::default()).is_none());
assert!(handle_slash_command("/status", &session, CompactionConfig::default()).is_none());
+ assert!(handle_slash_command("/sandbox", &session, CompactionConfig::default()).is_none());
+ assert!(
+ handle_slash_command("/bughunter", &session, CompactionConfig::default()).is_none()
+ );
+ assert!(handle_slash_command("/commit", &session, CompactionConfig::default()).is_none());
+ assert!(handle_slash_command("/pr", &session, CompactionConfig::default()).is_none());
+ assert!(handle_slash_command("/issue", &session, CompactionConfig::default()).is_none());
+ assert!(
+ handle_slash_command("/ultraplan", &session, CompactionConfig::default()).is_none()
+ );
+ assert!(
+ handle_slash_command("/teleport foo", &session, CompactionConfig::default()).is_none()
+ );
+ assert!(
+ handle_slash_command("/debug-tool-call", &session, CompactionConfig::default())
+ .is_none()
+ );
+ assert!(
+ handle_slash_command("/bughunter", &session, CompactionConfig::default()).is_none()
+ );
+ assert!(handle_slash_command("/commit", &session, CompactionConfig::default()).is_none());
+ assert!(handle_slash_command("/pr", &session, CompactionConfig::default()).is_none());
+ assert!(handle_slash_command("/issue", &session, CompactionConfig::default()).is_none());
+ assert!(
+ handle_slash_command("/ultraplan", &session, CompactionConfig::default()).is_none()
+ );
+ assert!(
+ handle_slash_command("/teleport foo", &session, CompactionConfig::default()).is_none()
+ );
+ assert!(
+ handle_slash_command("/debug-tool-call", &session, CompactionConfig::default())
+ .is_none()
+ );
assert!(
handle_slash_command("/model claude", &session, CompactionConfig::default()).is_none()
);
diff --cc rust/crates/runtime/src/conversation.rs
index 8411b8d1,1db2e77f..da12a8b4
--- a/rust/crates/runtime/src/conversation.rs
+++ b/rust/crates/runtime/src/conversation.rs
@@@ -96,7 -103,7 +105,8 @@@ pub struct ConversationRuntime<C, T>
system_prompt: Vec<String>,
max_iterations: usize,
usage_tracker: UsageTracker,
+ hook_runner: HookRunner,
+ auto_compaction_input_tokens_threshold: u32,
}
impl<C, T> ConversationRuntime<C, T>
@@@ -140,7 -128,7 +150,8 @@@ wher
system_prompt,
max_iterations: usize::MAX,
usage_tracker,
+ hook_runner: HookRunner::from_feature_config(&feature_config),
+ auto_compaction_input_tokens_threshold: auto_compaction_threshold_from_env(),
}
}
@@@ -396,11 -387,11 +458,12 @@@ impl ToolExecutor for StaticToolExecuto
#[cfg(test)]
mod tests {
use super::{
- ApiClient, ApiRequest, AssistantEvent, ConversationRuntime, RuntimeError,
- StaticToolExecutor,
+ parse_auto_compaction_threshold, ApiClient, ApiRequest, AssistantEvent,
+ AutoCompactionEvent, ConversationRuntime, RuntimeError, StaticToolExecutor,
+ DEFAULT_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD,
};
use crate::compact::CompactionConfig;
+ use crate::config::{RuntimeFeatureConfig, RuntimeHookConfig};
use crate::permissions::{
PermissionMode, PermissionPolicy, PermissionPromptDecision, PermissionPrompter,
PermissionRequest,
@@@ -789,13 -646,110 +853,120 @@@
);
}
+ #[cfg(windows)]
+ fn shell_snippet(script: &str) -> String {
+ script.replace('\'', "\"")
+ }
+
+ #[cfg(not(windows))]
+ fn shell_snippet(script: &str) -> String {
+ script.to_string()
+ }
++
+ #[test]
+ fn auto_compacts_when_cumulative_input_threshold_is_crossed() {
+ struct SimpleApi;
+ impl ApiClient for SimpleApi {
+ fn stream(
+ &mut self,
+ _request: ApiRequest,
+ ) -> Result<Vec<AssistantEvent>, RuntimeError> {
+ Ok(vec![
+ AssistantEvent::TextDelta("done".to_string()),
+ AssistantEvent::Usage(TokenUsage {
+ input_tokens: 120_000,
+ output_tokens: 4,
+ cache_creation_input_tokens: 0,
+ cache_read_input_tokens: 0,
+ }),
+ AssistantEvent::MessageStop,
+ ])
+ }
+ }
+
+ let session = Session {
+ version: 1,
+ messages: vec![
+ crate::session::ConversationMessage::user_text("one"),
+ crate::session::ConversationMessage::assistant(vec![ContentBlock::Text {
+ text: "two".to_string(),
+ }]),
+ crate::session::ConversationMessage::user_text("three"),
+ crate::session::ConversationMessage::assistant(vec![ContentBlock::Text {
+ text: "four".to_string(),
+ }]),
+ ],
+ };
+
+ let mut runtime = ConversationRuntime::new(
+ session,
+ SimpleApi,
+ StaticToolExecutor::new(),
+ PermissionPolicy::new(PermissionMode::DangerFullAccess),
+ vec!["system".to_string()],
+ )
+ .with_auto_compaction_input_tokens_threshold(100_000);
+
+ let summary = runtime
+ .run_turn("trigger", None)
+ .expect("turn should succeed");
+
+ assert_eq!(
+ summary.auto_compaction,
+ Some(AutoCompactionEvent {
+ removed_message_count: 2,
+ })
+ );
+ assert_eq!(runtime.session().messages[0].role, MessageRole::System);
+ }
+
+ #[test]
+ fn skips_auto_compaction_below_threshold() {
+ struct SimpleApi;
+ impl ApiClient for SimpleApi {
+ fn stream(
+ &mut self,
+ _request: ApiRequest,
+ ) -> Result<Vec<AssistantEvent>, RuntimeError> {
+ Ok(vec![
+ AssistantEvent::TextDelta("done".to_string()),
+ AssistantEvent::Usage(TokenUsage {
+ input_tokens: 99_999,
+ output_tokens: 4,
+ cache_creation_input_tokens: 0,
+ cache_read_input_tokens: 0,
+ }),
+ AssistantEvent::MessageStop,
+ ])
+ }
+ }
+
+ let mut runtime = ConversationRuntime::new(
+ Session::new(),
+ SimpleApi,
+ StaticToolExecutor::new(),
+ PermissionPolicy::new(PermissionMode::DangerFullAccess),
+ vec!["system".to_string()],
+ )
+ .with_auto_compaction_input_tokens_threshold(100_000);
+
+ let summary = runtime
+ .run_turn("trigger", None)
+ .expect("turn should succeed");
+ assert_eq!(summary.auto_compaction, None);
+ assert_eq!(runtime.session().messages.len(), 2);
+ }
+
+ #[test]
+ fn auto_compaction_threshold_defaults_and_parses_values() {
+ assert_eq!(
+ parse_auto_compaction_threshold(None),
+ DEFAULT_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD
+ );
+ assert_eq!(parse_auto_compaction_threshold(Some("4321")), 4321);
+ assert_eq!(
+ parse_auto_compaction_threshold(Some("not-a-number")),
+ DEFAULT_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD
+ );
+ }
}
diff --cc rust/crates/runtime/src/lib.rs
index 03d4191a,8193d57a..68df55fe
--- a/rust/crates/runtime/src/lib.rs
+++ b/rust/crates/runtime/src/lib.rs
@@@ -24,15 -23,15 +24,15 @@@ pub use compact::
get_compact_continuation_message, should_compact, CompactionConfig, CompactionResult,
};
pub use config::{
- ConfigEntry, ConfigError, ConfigLoader, ConfigSource, McpClaudeAiProxyServerConfig,
+ ConfigEntry, ConfigError, ConfigLoader, ConfigSource, McpManagedProxyServerConfig,
McpConfigCollection, McpOAuthConfig, McpRemoteServerConfig, McpSdkServerConfig,
McpServerConfig, McpStdioServerConfig, McpTransport, McpWebSocketServerConfig, OAuthConfig,
- ResolvedPermissionMode, RuntimeConfig, RuntimeFeatureConfig, ScopedMcpServerConfig,
- CLAUDE_CODE_SETTINGS_SCHEMA_NAME,
+ ResolvedPermissionMode, RuntimeConfig, RuntimeFeatureConfig, RuntimeHookConfig,
+ RuntimePluginConfig, ScopedMcpServerConfig, CLAW_SETTINGS_SCHEMA_NAME,
};
pub use conversation::{
- ApiClient, ApiRequest, AssistantEvent, ConversationRuntime, RuntimeError, StaticToolExecutor,
- ToolError, ToolExecutor, TurnSummary,
+ auto_compaction_threshold_from_env, ApiClient, ApiRequest, AssistantEvent, AutoCompactionEvent,
+ ConversationRuntime, RuntimeError, StaticToolExecutor, ToolError, ToolExecutor, TurnSummary,
};
pub use file_ops::{
edit_file, glob_search, grep_search, read_file, write_file, EditFileOutput, GlobSearchOutput,
diff --cc rust/crates/rusty-claude-cli/src/main.rs
index 2619c3f1,6c65202f..ce682c66
--- a/rust/crates/rusty-claude-cli/src/main.rs
+++ b/rust/crates/rusty-claude-cli/src/main.rs
@@@ -788,62 -775,32 +788,66 @@@ fn format_compact_report(removed: usize
}
}
+ fn format_auto_compaction_notice(removed: usize) -> String {
+ format!("[auto-compacted: removed {removed} messages]")
+ }
+
fn parse_git_status_metadata(status: Option<&str>) -> (Option<PathBuf>, Option<String>) {
- let Some(status) = status else {
- return (None, None);
- };
- let branch = status.lines().next().and_then(|line| {
- line.strip_prefix("## ")
- .map(|line| {
- line.split(['.', ' '])
- .next()
- .unwrap_or_default()
- .to_string()
- })
- .filter(|value| !value.is_empty())
- });
- let project_root = find_git_root().ok();
- (project_root, branch)
+ parse_git_status_metadata_for(
+ &env::current_dir().unwrap_or_else(|_| PathBuf::from(".")),
+ status,
+ )
}
-fn find_git_root() -> Result<PathBuf, Box<dyn std::error::Error>> {
+fn parse_git_status_branch(status: Option<&str>) -> Option<String> {
+ let status = status?;
+ let first_line = status.lines().next()?;
+ let line = first_line.strip_prefix("## ")?;
+ if line.starts_with("HEAD") {
+ return Some("detached HEAD".to_string());
+ }
+ let branch = line.split(['.', ' ']).next().unwrap_or_default().trim();
+ if branch.is_empty() {
+ None
+ } else {
+ Some(branch.to_string())
+ }
+}
+
+fn resolve_git_branch_for(cwd: &Path) -> Option<String> {
+ let branch = run_git_capture_in(cwd, &["branch", "--show-current"])?;
+ let branch = branch.trim();
+ if !branch.is_empty() {
+ return Some(branch.to_string());
+ }
+
+ let fallback = run_git_capture_in(cwd, &["rev-parse", "--abbrev-ref", "HEAD"])?;
+ let fallback = fallback.trim();
+ if fallback.is_empty() {
+ None
+ } else if fallback == "HEAD" {
+ Some("detached HEAD".to_string())
+ } else {
+ Some(fallback.to_string())
+ }
+}
+
+fn run_git_capture_in(cwd: &Path, args: &[&str]) -> Option<String> {
+ let output = std::process::Command::new("git")
+ .args(args)
+ .current_dir(cwd)
+ .output()
+ .ok()?;
+ if !output.status.success() {
+ return None;
+ }
+ String::from_utf8(output.stdout).ok()
+}
+
+fn find_git_root_in(cwd: &Path) -> Result<PathBuf, Box<dyn std::error::Error>> {
let output = std::process::Command::new("git")
.args(["rev-parse", "--show-toplevel"])
- .current_dir(env::current_dir()?)
+ .current_dir(cwd)
.output()?;
if !output.status.success() {
return Err("not a git repository".into());