Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

raea hook: the open's arguments read in one loop, the program's name and the patch's headers matched without copying other code's closures (dupes)

shinyobjectzeff11d8778f1
diff --git a/apps/check/src/hook.rs b/apps/check/src/hook.rs
index 7a3da0d3..d5a83d4a 100644
--- a/apps/check/src/hook.rs
+++ b/apps/check/src/hook.rs
@@ -62,17 +62,27 @@ pub fn opened_media(cmd: &str) -> Vec<String> {
for seg in cmd.split(['\n', ';', '|', '&']) {
let w = words(seg);
let mut it = w.iter().skip_while(|t| t.contains('=') && !t.starts_with('-') || ["command", "exec", "nohup", "env"].contains(&t.as_str()));
- let Some(tool) = it.next().map(|t| t.rsplit('/').next().unwrap_or(t).to_string()) else { continue };
- if !["open", "xdg-open", "qlmanage"].contains(&tool.as_str()) {
+ let Some(tool) = it.next() else { continue };
+ if !["open", "xdg-open", "qlmanage"].contains(&tool.rsplit_once('/').map_or(tool.as_str(), |(_, name)| name)) {
continue;
}
- let rest: Vec<&String> = it.collect();
- let app = rest.windows(2).find(|p| p[0] == "-a" || p[0] == "-b").map(|p| p[1].to_lowercase());
- if app.is_some_and(|a| a.contains("raea")) || rest.iter().any(|t| *t == "-R") {
- continue;
+ // the files it names, apart from the app an -a or -b names; one naming raea, or Finder's -R, opens nothing here
+ let (mut files, mut app, mut ours) = (Vec::new(), false, false);
+ for t in it {
+ if app {
+ ours |= t.to_lowercase().contains("raea");
+ app = false;
+ } else if t == "-a" || t == "-b" {
+ app = true;
+ } else if t == "-R" {
+ ours = true;
+ } else if !t.starts_with('-') && !t.contains("://") && t.rsplit_once('.').is_some_and(|(_, e)| MEDIA.contains(&e.to_lowercase().as_str())) {
+ files.push(t.clone());
+ }
+ }
+ if !ours {
+ found.extend(files);
}
- let args = rest.iter().enumerate().filter(|(i, t)| !t.starts_with('-') && !(*i > 0 && ["-a", "-b"].contains(&rest[i - 1].as_str())));
- found.extend(args.map(|(_, t)| t.to_string()).filter(|t| !t.contains("://") && t.rsplit_once('.').is_some_and(|(_, e)| MEDIA.contains(&e.to_lowercase().as_str()))));
}
found
}
@@ -110,7 +120,7 @@ fn saved(v: &Value) -> Vec<String> {
return vec![p.to_string()];
}
let patch = i["command"].as_str().or(i["input"].as_str()).unwrap_or("");
- patch.lines().filter_map(|l| l.strip_prefix("*** Add File: ").or(l.strip_prefix("*** Update File: "))).map(|p| p.trim().to_string()).collect()
+ patch.lines().filter_map(|l| ["*** Add File: ", "*** Update File: "].iter().find_map(|head| l.strip_prefix(head))).map(str::trim).map(String::from).collect()
}
/// Findings for the agent in the shape its harness reads after a tool: Gemini CLI's AfterTool context, Kimi Code's
diff --git a/apps/tools/src/agent_hooks.rs b/apps/tools/src/agent_hooks.rs
index 1cfb42ef..36be2ef9 100644
--- a/apps/tools/src/agent_hooks.rs
+++ b/apps/tools/src/agent_hooks.rs
@@ -27,15 +27,19 @@ fn hooks(agent: &str) -> R<[Hook; 2]> {
})
}
+/// The folder an environment variable names, else the one given.
+fn named_dir(var: &str, or: PathBuf) -> PathBuf {
+ std::env::var_os(var).filter(|v| !v.is_empty()).map_or(or, PathBuf::from)
+}
+
/// Where the harness keeps its hooks.
fn file(agent: &str) -> R<PathBuf> {
let home = user_home()?;
- let env = |k: &str| std::env::var_os(k).filter(|v| !v.is_empty()).map(PathBuf::from);
Ok(match agent {
"claude" => home.join(".claude/settings.json"),
- "codex" => env("CODEX_HOME").unwrap_or_else(|| home.join(".codex")).join("hooks.json"),
+ "codex" => named_dir("CODEX_HOME", home.join(".codex")).join("hooks.json"),
"gemini" => home.join(".gemini/settings.json"),
- _ => env("KIMI_CODE_HOME").unwrap_or_else(|| home.join(".kimi-code")).join("config.toml"),
+ _ => named_dir("KIMI_CODE_HOME", home.join(".kimi-code")).join("config.toml"),
})
}