diff --git a/crates/aien-cli/src/client.rs b/crates/aien-cli/src/client.rs
index 0ab1f936..9fa54366 100644
--- a/crates/aien-cli/src/client.rs
+++ b/crates/aien-cli/src/client.rs
@@ -1,3 +1,4 @@
+use colored::Colorize;
use futures_util::StreamExt;
use reqwest::Client;
use serde_json::{json, Value};
@@ -81,7 +82,8 @@ pub fn get_system_prompt() -> String {
p.push_str("\n");
p.push_str("{\"name\": \"tool_name\", \"arguments\": {\"arg\": \"val\"}}\n");
p.push_str("\n\n");
- p.push_str("When responding to the operator, output directly without tool tags.\n");
+ p.push_str("When responding to the operator, output directly without tool tags.\n\n");
+ p.push_str(&crate::skills::format_skills_progressive_summary());
p
}
@@ -153,6 +155,7 @@ impl ChatClient {
let mut full_text = String::new();
let mut buffer = String::new();
let mut is_done = false;
+ let mut in_thinking = false;
while let Some(chunk_result) = stream.next().await {
let chunk = chunk_result.map_err(|e| format!("Stream error: {}", e))?;
@@ -173,11 +176,26 @@ impl ChatClient {
if let Some(choices) = val.get("choices").and_then(Value::as_array) {
if let Some(choice) = choices.first() {
if let Some(delta) = choice.get("delta") {
- if let Some(raw_content) =
- delta.get("content").and_then(Value::as_str)
- {
- let sanitized =
- raw_content.replace("—", ", ").replace("–", "-");
+ if let Some(reasoning) = delta.get("reasoning").or_else(|| delta.get("reasoning_content")).and_then(Value::as_str) {
+ let sanitized = reasoning.replace("—", ", ").replace("–", "-");
+ if stream_to_stdout {
+ if !in_thinking {
+ print!("{}", "\n[Thinking] ".magenta().dimmed());
+ in_thinking = true;
+ }
+ print!("{}", sanitized.dimmed());
+ let _ = stdout().flush();
+ }
+ }
+ if let Some(raw_content) = delta.get("content").and_then(Value::as_str) {
+ if in_thinking {
+ if stream_to_stdout {
+ print!("\n\n");
+ let _ = stdout().flush();
+ }
+ in_thinking = false;
+ }
+ let sanitized = raw_content.replace("—", ", ").replace("–", "-");
full_text.push_str(&sanitized);
if stream_to_stdout {
print!("{}", sanitized);
@@ -252,6 +270,22 @@ pub fn extract_tool_calls(text: &str) -> Vec<(String, Value)> {
}
}
}
+ if calls.is_empty() {
+ if let Ok(json_pat) = regex::Regex::new(r#"(?s)```(?:json|tool_call)?\s*(\{\s*"name"\s*:\s*"[^"]+".*?\})\s*```"#) {
+ for caps in json_pat.captures_iter(text) {
+ if let Some(json_match) = caps.get(1) {
+ if let Some(parsed) = parse_tool_call_json(json_match.as_str()) {
+ if let Some(name) = parsed.get("name").and_then(Value::as_str) {
+ if name != "tool_name" {
+ let args = parsed.get("arguments").cloned().unwrap_or(json!({}));
+ calls.push((name.to_string(), args));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
calls
}
diff --git a/crates/aien-cli/src/commands.rs b/crates/aien-cli/src/commands.rs
index 65ccc0b5..e1b45753 100644
--- a/crates/aien-cli/src/commands.rs
+++ b/crates/aien-cli/src/commands.rs
@@ -55,6 +55,7 @@ pub async fn handle_slash_command(cmd: &str) -> bool {
/subagents [list|view|run] Recursive contextual subagents hierarchy
/goal [list|new|done] Manage project goals & milestone lattices"
);
+ println!(" /rules Inspect active repository & directory rules (AGENTS.md, GEMINI.md)");
println!(" /walkthrough [save] Display live architecture map & roadmap (or save to WALKTHROUGH.md)");
println!(" /nest Execute the Agent Nesting Ritual (grounding, threat check, peer wind, scent)");
println!(" /crumb [path] Inspect directory crumb (above, below, and local agent history)");
@@ -355,6 +356,11 @@ pub async fn handle_slash_command(cmd: &str) -> bool {
}
true
}
+ "/rule" | "/rules" => {
+ let cwd = std::env::current_dir().unwrap_or_else(|_| crate::platform::PlatformContext::detect().home_dir);
+ println!("{}", crate::rules::format_rules_tui(&cwd));
+ true
+ }
"/skill" | "/skills" => {
if parts.len() > 1 && parts[1] == "optimize" {
let name = if parts.len() > 2 {
diff --git a/crates/aien-cli/src/main.rs b/crates/aien-cli/src/main.rs
index 87a4af9d..3ac05ffa 100644
--- a/crates/aien-cli/src/main.rs
+++ b/crates/aien-cli/src/main.rs
@@ -8,6 +8,7 @@ mod hive;
pub mod hooks;
mod nesting;
pub mod platform;
+pub mod rules;
mod safety;
pub mod sandbox;
pub mod skills;
@@ -117,6 +118,10 @@ async fn main() {
run_doctor().await;
return;
}
+ if args[1] == "--rules" || args[1] == "rules" {
+ let _ = handle_slash_command("/rules").await;
+ return;
+ }
if args[1] == "--vault" || args[1] == "vault" {
let _ = handle_slash_command("/vault").await;
return;
@@ -208,9 +213,18 @@ async fn main() {
// Mandatory Nesting Ritual: Circle, Check Wind, Leave Scent, Flatten Terrain
let nesting = perform_nesting_ritual(&session_id, true).await;
+ let cwd = std::env::current_dir().unwrap_or_else(|_| platform.home_dir.clone());
+ let rules = crate::rules::discover_rules(&cwd);
+ let rules_prompt = crate::rules::format_rules_for_prompt(&rules);
+
+ let mut full_system_prompt = get_system_prompt();
+ if !rules_prompt.is_empty() {
+ full_system_prompt.push_str(&rules_prompt);
+ }
+
let client = ChatClient::new(None, None);
let mut messages: Vec = vec![
- json!({"role": "system", "content": get_system_prompt()}),
+ json!({"role": "system", "content": full_system_prompt}),
json!({"role": "user", "content": format!("\n{}\n\nPerform your mandatory nesting initiation. Confirm your verified terrain, wind, scent mark, and operational readiness before taking commands.", nesting.grounding_context)}),
];
@@ -355,9 +369,18 @@ async fn run_single_prompt(prompt: &str) {
let hook_registry = crate::hooks::HookRegistry::default_sovereign_registry();
let _ = hook_registry.run_pre_turn(&mut turn_prompt).await;
+ let cwd = std::env::current_dir().unwrap_or_else(|_| platform.home_dir.clone());
+ let rules = crate::rules::discover_rules(&cwd);
+ let rules_prompt = crate::rules::format_rules_for_prompt(&rules);
+
+ let mut full_system_prompt = get_system_prompt();
+ if !rules_prompt.is_empty() {
+ full_system_prompt.push_str(&rules_prompt);
+ }
+
let client = ChatClient::new(None, None);
let mut messages = vec![
- json!({"role": "system", "content": get_system_prompt()}),
+ json!({"role": "system", "content": full_system_prompt}),
json!({"role": "user", "content": format!("\n{}\n\n{}", nesting.grounding_context, turn_prompt)}),
];
diff --git a/crates/aien-cli/src/rules.rs b/crates/aien-cli/src/rules.rs
new file mode 100644
index 00000000..3f268c09
--- /dev/null
+++ b/crates/aien-cli/src/rules.rs
@@ -0,0 +1,141 @@
+use colored::*;
+use std::collections::HashSet;
+use std::fs;
+use std::path::{Path, PathBuf};
+
+#[derive(Debug, Clone)]
+pub struct Rule {
+ pub name: String,
+ pub path: PathBuf,
+ pub content: String,
+}
+
+pub fn discover_rules(cwd: &Path) -> Vec {
+ let mut rules = Vec::new();
+ let mut current = Some(cwd.to_path_buf());
+ let mut seen_paths = HashSet::new();
+
+ while let Some(dir) = current {
+ // 1. Check AGENTS.md
+ let agents_md = dir.join("AGENTS.md");
+ if agents_md.is_file() {
+ if let Ok(canon) = agents_md.canonicalize() {
+ if seen_paths.insert(canon.clone()) {
+ if let Ok(content) = fs::read_to_string(&canon) {
+ rules.push(Rule {
+ name: format!("AGENTS.md ({})", dir.display()),
+ path: canon,
+ content,
+ });
+ }
+ }
+ }
+ }
+
+ // 2. Check GEMINI.md
+ let gemini_md = dir.join("GEMINI.md");
+ if gemini_md.is_file() {
+ if let Ok(canon) = gemini_md.canonicalize() {
+ if seen_paths.insert(canon.clone()) {
+ if let Ok(content) = fs::read_to_string(&canon) {
+ rules.push(Rule {
+ name: format!("GEMINI.md ({})", dir.display()),
+ path: canon,
+ content,
+ });
+ }
+ }
+ }
+ }
+
+ // 3. Check .agents/rules/*.md
+ let rules_dir = dir.join(".agents/rules");
+ if rules_dir.is_dir() {
+ if let Ok(entries) = fs::read_dir(&rules_dir) {
+ for entry in entries.flatten() {
+ let path = entry.path();
+ if path.is_file() && path.extension().and_then(|s| s.to_str()) == Some("md") {
+ if let Ok(canon) = path.canonicalize() {
+ if seen_paths.insert(canon.clone()) {
+ if let Ok(content) = fs::read_to_string(&canon) {
+ let fname = canon
+ .file_name()
+ .map(|n| n.to_string_lossy().to_string())
+ .unwrap_or_else(|| "rule".to_string());
+ rules.push(Rule {
+ name: format!("{} ({})", fname, dir.display()),
+ path: canon,
+ content,
+ });
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Stop ascending if we reached git repository root or root filesystem
+ if dir.join(".git").exists() || dir.parent().is_none() {
+ break;
+ }
+ current = dir.parent().map(|p| p.to_path_buf());
+ }
+
+ rules
+}
+
+pub fn format_rules_for_prompt(rules: &[Rule]) -> String {
+ if rules.is_empty() {
+ return String::new();
+ }
+ let mut out = String::from("
+ACTIVE REPOSITORY & WORKSPACE RULES:
+");
+ for r in rules {
+ out.push_str(&format!("
+[Rule: {}]
+", r.name));
+ out.push_str(&r.content);
+ out.push_str("
+[/Rule]
+");
+ }
+ out
+}
+
+pub fn format_rules_tui(cwd: &Path) -> String {
+ let rules = discover_rules(cwd);
+ let mut out = String::new();
+ out.push_str(&format!(
+ "{}
+",
+ "=== Active Antigravity Repository Rules ===".cyan().bold()
+ ));
+ out.push_str(&format!(
+ "Working Directory: {}
+
+",
+ cwd.display().to_string().dimmed()
+ ));
+
+ if rules.is_empty() {
+ out.push_str(&format!(
+ "{}
+",
+ "No active rules discovered in current working tree.".dimmed()
+ ));
+ return out;
+ }
+
+ for (i, r) in rules.iter().enumerate() {
+ out.push_str(&format!(
+ "{}. {} ({})
+",
+ i + 1,
+ r.name.green().bold(),
+ r.path.display().to_string().dimmed()
+ ));
+ }
+ out
+}
diff --git a/crates/aien-cli/src/skills.rs b/crates/aien-cli/src/skills.rs
index 23a517fa..062a11f8 100644
--- a/crates/aien-cli/src/skills.rs
+++ b/crates/aien-cli/src/skills.rs
@@ -1,8 +1,9 @@
use colored::*;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
+use std::collections::HashSet;
use std::fs;
-use std::path::PathBuf;
+use std::path::Path;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Skill {
@@ -12,12 +13,6 @@ pub struct Skill {
pub has_scripts: bool,
}
-pub fn get_skills_dir() -> PathBuf {
- crate::platform::PlatformContext::detect()
- .home_dir
- .join("skills")
-}
-
fn extract_frontmatter_field(content: &str, field: &str) -> Option {
let mut in_frontmatter = false;
for line in content.lines() {
@@ -32,27 +27,23 @@ fn extract_frontmatter_field(content: &str, field: &str) -> Option {
}
if in_frontmatter {
if let Some(rest) = trimmed.strip_prefix(&format!("{}:", field)) {
- return Some(rest.trim().trim_matches('"').trim_matches('\'').to_string());
+ return Some(rest.trim().trim_matches('"').trim_matches('\x27').to_string());
}
}
}
None
}
-pub fn discover_skills() -> Vec {
- let dir = get_skills_dir();
- let mut skills = Vec::new();
- if !dir.exists() {
- let _ = fs::create_dir_all(&dir);
- return skills;
+fn scan_dir_for_skills(dir: &Path, skills: &mut Vec, seen_names: &mut HashSet) {
+ if !dir.is_dir() {
+ return;
}
-
- if let Ok(entries) = fs::read_dir(&dir) {
+ if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
let skill_md = path.join("SKILL.md");
- if skill_md.exists() {
+ if skill_md.is_file() {
let content = fs::read_to_string(&skill_md).unwrap_or_default();
let name = extract_frontmatter_field(&content, "name").unwrap_or_else(|| {
path.file_name()
@@ -60,36 +51,107 @@ pub fn discover_skills() -> Vec {
.to_string_lossy()
.to_string()
});
- let desc = extract_frontmatter_field(&content, "description")
- .unwrap_or_else(|| "No description provided.".to_string());
- let has_scripts = path.join("scripts").exists();
- skills.push(Skill {
- name,
- description: desc,
- path: skill_md.display().to_string(),
- has_scripts,
- });
+ let norm_name = name.to_lowercase();
+ if seen_names.insert(norm_name) {
+ let desc = extract_frontmatter_field(&content, "description")
+ .unwrap_or_else(|| "No description provided.".to_string());
+ let has_scripts = path.join("scripts").is_dir();
+ skills.push(Skill {
+ name,
+ description: desc,
+ path: skill_md.display().to_string(),
+ has_scripts,
+ });
+ }
+ } else {
+ // Check one level deeper (e.g. modular-skills/benchmark-model)
+ if let Ok(sub_entries) = fs::read_dir(&path) {
+ for sub_entry in sub_entries.flatten() {
+ let sub_path = sub_entry.path();
+ if sub_path.is_dir() {
+ let sub_skill_md = sub_path.join("SKILL.md");
+ if sub_skill_md.is_file() {
+ let content = fs::read_to_string(&sub_skill_md).unwrap_or_default();
+ let name = extract_frontmatter_field(&content, "name").unwrap_or_else(|| {
+ sub_path.file_name()
+ .unwrap_or_default()
+ .to_string_lossy()
+ .to_string()
+ });
+ let norm_name = name.to_lowercase();
+ if seen_names.insert(norm_name) {
+ let desc = extract_frontmatter_field(&content, "description")
+ .unwrap_or_else(|| "No description provided.".to_string());
+ let has_scripts = sub_path.join("scripts").is_dir();
+ skills.push(Skill {
+ name,
+ description: desc,
+ path: sub_skill_md.display().to_string(),
+ has_scripts,
+ });
+ }
+ }
+ }
+ }
+ }
}
}
}
}
+}
+
+pub fn discover_skills() -> Vec {
+ let mut skills = Vec::new();
+ let mut seen_names = HashSet::new();
+ let platform = crate::platform::PlatformContext::detect();
+
+ // Priority 1: Current workspace .agents/skills and skills
+ let cwd = std::env::current_dir().unwrap_or_else(|_| platform.home_dir.clone());
+ scan_dir_for_skills(&cwd.join(".agents/skills"), &mut skills, &mut seen_names);
+ scan_dir_for_skills(&cwd.join("skills"), &mut skills, &mut seen_names);
+
+ // Priority 2: Home skills (~/skills)
+ let home_skills = platform.home_dir.join("skills");
+ scan_dir_for_skills(&home_skills, &mut skills, &mut seen_names);
+
+ // Priority 3: Home .agents/skills (~/.agents/skills)
+ let home_agents_skills = platform.home_dir.join(".agents/skills");
+ scan_dir_for_skills(&home_agents_skills, &mut skills, &mut seen_names);
+
+ // Priority 4: Gemini global config skills (~/.gemini/config/skills)
+ let gemini_skills = platform.home_dir.join(".gemini/config/skills");
+ scan_dir_for_skills(&gemini_skills, &mut skills, &mut seen_names);
+
skills
}
+pub fn format_skills_progressive_summary() -> String {
+ let skills = discover_skills();
+ if skills.is_empty() {
+ return String::new();
+ }
+
+ let mut out = String::from("\nAVAILABLE AGENT SKILLS (Progressive Disclosure):\n");
+ out.push_str("To activate and inspect full instructions for any skill, use the 'skill' tool with {\"action\": \"read\", \"name\": \"\"}.\n");
+ for s in skills {
+ out.push_str(&format!("- {}: {}\n", s.name, s.description));
+ }
+ out
+}
+
pub fn format_skills_tui() -> String {
let skills = discover_skills();
let mut out = String::new();
out.push_str(&format!(
"{}\n",
- "=== AIEN Sovereign Skill Registry ===".cyan().bold()
- ));
- out.push_str(&format!(
- "Directory: {}\n\n",
- get_skills_dir().display().to_string().dimmed()
+ "=== AIEN Antigravity Skill Registry ===".cyan().bold()
));
if skills.is_empty() {
- out.push_str(&format!("{}\n", "No skills currently installed in ~/skills/. Create a folder with SKILL.md to define one.".dimmed()));
+ out.push_str(&format!(
+ "{}\n",
+ "No skills currently discovered. Create a folder with SKILL.md in ~/skills/ or .agents/skills/ to register one.".dimmed()
+ ));
return out;
}
@@ -113,19 +175,15 @@ pub fn format_skills_tui() -> String {
}
pub fn read_skill_content(name: &str) -> Result {
- let dir = get_skills_dir();
- let skill_path = dir.join(name).join("SKILL.md");
- if skill_path.exists() {
- fs::read_to_string(&skill_path).map_err(|e| e.to_string())
- } else {
- // Try searching by name match
- for s in discover_skills() {
- if s.name.to_lowercase() == name.to_lowercase() {
- return fs::read_to_string(&s.path).map_err(|e| e.to_string());
- }
+ let skills = discover_skills();
+ let norm = name.trim().to_lowercase();
+
+ for s in skills {
+ if s.name.to_lowercase() == norm {
+ return fs::read_to_string(&s.path).map_err(|e| e.to_string());
}
- Err(format!("Skill '{}' not found in ~/skills/", name))
}
+ Err(format!("Skill '{}' not found in discovered skill paths", name))
}
pub fn skills_dispatch_tool(args: &Value) -> Value {
@@ -184,7 +242,7 @@ pub fn run_optimize_cli(name: &str) {
println!(
"{}",
format!(
- "Starting Microsoft SkillOpt self-improvement loop for '{}'...",
+ "Starting Microsoft SkillOpt self-improvement loop for {}...",
name
)
.cyan()
diff --git a/crates/aien-cli/src/tools.rs b/crates/aien-cli/src/tools.rs
index d09feb60..47007805 100644
--- a/crates/aien-cli/src/tools.rs
+++ b/crates/aien-cli/src/tools.rs
@@ -1,3 +1,4 @@
+use std::io::Write;
use colored::*;
use serde_json::{json, Value};
use std::fs;
@@ -24,7 +25,9 @@ pub fn dispatch_tool(name: &str, args: &Value) -> Value {
"write_to_file" => args.get("path").and_then(Value::as_str).unwrap_or(""),
"replace_file_content" => args.get("path").and_then(Value::as_str).unwrap_or(""),
"list_dir" => args.get("path").and_then(Value::as_str).unwrap_or(""),
- "grep_search" => args.get("query").and_then(Value::as_str).unwrap_or(""),
+ "grep_search" | "search_directory" => args.get("query").or_else(|| args.get("Query")).and_then(Value::as_str).unwrap_or(""),
+ "find_by_name" | "find_file" => args.get("pattern").or_else(|| args.get("name")).or_else(|| args.get("Pattern")).and_then(Value::as_str).unwrap_or(""),
+ "ask_question" => args.get("question").and_then(Value::as_str).unwrap_or(""),
"create_dir" => args.get("path").and_then(Value::as_str).unwrap_or(""),
"crumb" => args
.get("action")
@@ -93,8 +96,8 @@ pub fn dispatch_tool(name: &str, args: &Value) -> Value {
let (res, success) = match name {
"run_command" => {
- let cmd = args.get("command").and_then(Value::as_str).unwrap_or("");
- let cwd = args.get("cwd").and_then(Value::as_str).unwrap_or(".");
+ let cmd = args.get("command").or_else(|| args.get("CommandLine")).and_then(Value::as_str).unwrap_or("");
+ let cwd = args.get("cwd").or_else(|| args.get("Cwd")).and_then(Value::as_str).unwrap_or(".");
if is_high_risk_command(cmd) {
if !print_safety_prompt(cmd) {
@@ -110,16 +113,17 @@ pub fn dispatch_tool(name: &str, args: &Value) -> Value {
}
}
"view_file" => {
- let path = args.get("path").and_then(Value::as_str).unwrap_or("");
- let start_line = args.get("start_line").and_then(Value::as_u64).unwrap_or(1) as usize;
- let end_line = args.get("end_line").and_then(Value::as_u64).unwrap_or(500) as usize;
+ let path = args.get("path").or_else(|| args.get("AbsolutePath")).and_then(Value::as_str).unwrap_or("");
+ let start_line = args.get("start_line").or_else(|| args.get("StartLine")).and_then(Value::as_u64).unwrap_or(1) as usize;
+ let end_line = args.get("end_line").or_else(|| args.get("EndLine")).and_then(Value::as_u64).unwrap_or(500) as usize;
exec_view_file(path, start_line, end_line)
}
- "write_to_file" => {
- let path = args.get("path").and_then(Value::as_str).unwrap_or("");
- let content = args.get("content").and_then(Value::as_str).unwrap_or("");
+ "write_to_file" | "create_file" => {
+ let path = args.get("path").or_else(|| args.get("target_file")).or_else(|| args.get("TargetFile")).and_then(Value::as_str).unwrap_or("");
+ let content = args.get("content").or_else(|| args.get("CodeContent")).and_then(Value::as_str).unwrap_or("");
let overwrite = args
.get("overwrite")
+ .or_else(|| args.get("Overwrite"))
.and_then(Value::as_bool)
.unwrap_or(false);
let intent = args
@@ -154,11 +158,13 @@ pub fn dispatch_tool(name: &str, args: &Value) -> Value {
exec_write_file(path, content, overwrite, intent, vector)
}
}
- "replace_file_content" => {
- let path = args.get("path").and_then(Value::as_str).unwrap_or("");
- let target = args.get("target").and_then(Value::as_str).unwrap_or("");
+ "replace_file_content" | "edit_file" => {
+ let path = args.get("path").or_else(|| args.get("target_file")).or_else(|| args.get("TargetFile")).and_then(Value::as_str).unwrap_or("");
+ let target = args.get("target").or_else(|| args.get("target_content")).or_else(|| args.get("TargetContent")).and_then(Value::as_str).unwrap_or("");
let replacement = args
.get("replacement")
+ .or_else(|| args.get("replacement_content"))
+ .or_else(|| args.get("ReplacementContent"))
.and_then(Value::as_str)
.unwrap_or("");
let intent = args
@@ -184,15 +190,25 @@ pub fn dispatch_tool(name: &str, args: &Value) -> Value {
exec_replace_file(path, target, replacement, intent, vector)
}
}
- "list_dir" => {
- let path = args.get("path").and_then(Value::as_str).unwrap_or(".");
+ "list_dir" | "list_directory" => {
+ let path = args.get("path").or_else(|| args.get("directory_path")).or_else(|| args.get("DirectoryPath")).and_then(Value::as_str).unwrap_or(".");
exec_list_dir(path)
}
- "grep_search" => {
- let query = args.get("query").and_then(Value::as_str).unwrap_or("");
- let path = args.get("path").and_then(Value::as_str).unwrap_or(".");
+ "grep_search" | "search_directory" => {
+ let query = args.get("query").or_else(|| args.get("Query")).and_then(Value::as_str).unwrap_or("");
+ let path = args.get("path").or_else(|| args.get("search_path")).or_else(|| args.get("SearchPath")).and_then(Value::as_str).unwrap_or(".");
exec_grep_search(query, path)
}
+ "find_by_name" | "find_file" => {
+ let path = args.get("path").or_else(|| args.get("search_directory")).or_else(|| args.get("SearchDirectory")).and_then(Value::as_str).unwrap_or(".");
+ let pattern = args.get("pattern").or_else(|| args.get("name")).or_else(|| args.get("Pattern")).and_then(Value::as_str).unwrap_or("*");
+ exec_find_by_name(path, pattern)
+ }
+ "ask_question" => {
+ let q = args.get("question").and_then(Value::as_str).unwrap_or("");
+ let options = args.get("options").and_then(Value::as_array);
+ exec_ask_question(q, options)
+ }
"create_dir" => {
let path = args.get("path").and_then(Value::as_str).unwrap_or("");
let purpose = args
@@ -978,3 +994,54 @@ mod tests {
.contains("CONFINEMENT DENIAL"));
}
}
+
+fn exec_find_by_name(path: &str, pattern: &str) -> (Value, bool) {
+ if let Err(err) = validate_tool_path(path) {
+ return (
+ json!({"error": format!("CONFINEMENT DENIAL: {}", err)}),
+ false,
+ );
+ }
+ let out = Command::new("find").args([path, "-name", pattern]).output();
+ match out {
+ Ok(output) => {
+ let raw_stdout = String::from_utf8_lossy(&output.stdout).to_string();
+ let redacted = redact_secrets(&raw_stdout);
+ let matches: Vec = redacted.lines().take(50).map(|s| s.to_string()).collect();
+ (
+ json!({
+ "path": path,
+ "pattern": pattern,
+ "matches": matches,
+ "count": matches.len()
+ }),
+ true,
+ )
+ }
+ Err(e) => (json!({"error": e.to_string()}), false),
+ }
+}
+
+fn exec_ask_question(question: &str, options: Option<&Vec>) -> (Value, bool) {
+ println!("\n{}", format!("❓ Question from AIEN: {}", question).yellow().bold());
+ if let Some(opts) = options {
+ for (i, opt) in opts.iter().enumerate() {
+ if let Some(opt_str) = opt.as_str() {
+ println!(" {}. {}", i + 1, opt_str.cyan());
+ }
+ }
+ }
+ print!("{}", "Your Answer ❯ ".cyan().bold());
+ let _ = std::io::stdout().flush();
+ let mut input = String::new();
+ let _ = std::io::stdin().read_line(&mut input);
+ let trimmed = input.trim().to_string();
+ (
+ json!({
+ "status": "answered",
+ "question": question,
+ "answer": trimmed
+ }),
+ true,
+ )
+}