Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(host): list an agent's global instructions and its full connector commands

leepokai589d7cb53c86
diff --git a/host/src/agent/gear/connectors.rs b/host/src/agent/gear/connectors.rs
index c1fd6cb5..33197902 100644
--- a/host/src/agent/gear/connectors.rs
+++ b/host/src/agent/gear/connectors.rs
@@ -86,37 +86,39 @@ fn command_text(server: &Map<String, Value>) -> String {
keep_public(&parts)
}
-/// A flag named like a credential, the value after it, and a long letter-and-digit run.
+/// Drops a flag or `NAME=value` named like a credential (and the value after such a flag) and a
+/// long letter-and-digit run; a URL keeps only its origin, since a path can carry a key.
fn keep_public(parts: &[String]) -> String {
let mut kept = Vec::new();
let mut skip_value = false;
for part in parts {
- if skip_value {
- skip_value = false;
+ if std::mem::take(&mut skip_value) {
continue;
}
- if credential_flag(part) {
- skip_value = true;
+ let raw = part.trim().trim_matches(['"', '\'']);
+ let (name, value) = raw.split_once('=').map_or((raw, None), |(name, value)| (name, Some(value)));
+ if credential_name(name) {
+ skip_value = raw.starts_with('-') && value.is_none();
continue;
}
- if token_run(part) {
- continue;
+ if let Some(url) = value.filter(|v| v.contains("://")) {
+ kept.push(format!("{name}={}", visible_url(url)));
+ } else if raw.contains("://") {
+ kept.push(visible_url(raw));
+ } else if !token_run(raw) {
+ kept.push(part.clone());
}
- kept.push(part.as_str());
}
+ kept.retain(|part| !part.is_empty());
kept.join(" ")
}
-fn credential_flag(part: &str) -> bool {
- let raw = part.trim().trim_matches(['"', '\'']);
- if !raw.starts_with('-') {
- return false;
- }
- let name = raw.trim_start_matches('-').to_ascii_lowercase().replace('-', "_");
- name.split('_')
- .filter(|seg| !seg.is_empty())
- .any(|seg| matches!(seg, "token" | "secret" | "password" | "authorization" | "apikey" | "auth" | "key"))
- || name.contains("api_key")
+fn credential_name(name: &str) -> bool {
+ let name = name.trim_start_matches('-').to_ascii_lowercase().replace('-', "_");
+ name.contains("api_key")
+ || name
+ .split('_')
+ .any(|seg| matches!(seg, "token" | "secret" | "password" | "authorization" | "apikey" | "auth" | "key"))
}
/// A bare argument that is a long mix of letters and digits, such as an API key.
@@ -143,19 +145,17 @@ fn visible_url(raw: &str) -> String {
fn mcp_toml(text: &str) -> Vec<Named> {
let mut out = Vec::new();
let mut name: Option<String> = None;
- let mut detail = String::new();
- let mut disabled = false;
- let flush = |name: &mut Option<String>, detail: &mut String, disabled: &mut bool, out: &mut Vec<Named>| {
+ let mut server = TomlServer::default();
+ let flush = |name: &mut Option<String>, server: &mut TomlServer, out: &mut Vec<Named>| {
if let Some(name) = name.take()
- && !*disabled
+ && !server.disabled
{
let name = clip(&name, NAME_CHARS);
if !name.is_empty() {
- out.push(Named { name, description: String::new(), detail: clip(detail, TEXT_CHARS) });
+ out.push(Named { name, description: String::new(), detail: clip(&server.detail(), TEXT_CHARS) });
}
}
- detail.clear();
- *disabled = false;
+ *server = TomlServer::default();
};
for line in text.lines() {
let trimmed = line.trim();
@@ -163,7 +163,7 @@ fn mcp_toml(text: &str) -> Vec<Named> {
continue;
}
if let Some(next) = toml_header(trimmed) {
- flush(&mut name, &mut detail, &mut disabled, &mut out);
+ flush(&mut name, &mut server, &mut out);
name = match next {
TomlTable::Server(server) => Some(server),
TomlTable::Other => None,
@@ -174,16 +174,63 @@ fn mcp_toml(text: &str) -> Vec<Named> {
continue;
}
if super::toml_scalar(trimmed, "enabled").as_deref() == Some("false") {
- disabled = true;
+ server.disabled = true;
} else if let Some(url) = super::toml_scalar(trimmed, "url") {
- detail = visible_url(&url);
- } else if detail.is_empty()
- && let Some(command) = super::toml_scalar(trimmed, "command")
- {
- detail = keep_public(&split_command(&command));
+ server.url = Some(url);
+ } else if let Some(command) = super::toml_scalar(trimmed, "command") {
+ server.command = split_command(&command);
+ } else if let Some(args) = super::toml_scalar(trimmed, "args") {
+ server.args = toml_strings(&args);
+ }
+ }
+ flush(&mut name, &mut server, &mut out);
+ out
+}
+
+/// One `[mcp_servers.name]` table as it is read, line by line.
+#[derive(Default)]
+struct TomlServer {
+ disabled: bool,
+ url: Option<String>,
+ command: Vec<String>,
+ args: Vec<String>,
+}
+
+impl TomlServer {
+ fn detail(&self) -> String {
+ if let Some(url) = &self.url {
+ return visible_url(url);
+ }
+ keep_public(&[self.command.as_slice(), self.args.as_slice()].concat())
+ }
+}
+
+/// The strings in a one-line TOML array (`["-y", 'pkg']`). An array split over several
+/// lines reads as empty, so the detail is the command alone.
+fn toml_strings(value: &str) -> Vec<String> {
+ let Some(inner) = value.trim().strip_prefix('[').and_then(|v| v.strip_suffix(']')) else { return Vec::new() };
+ let mut out = Vec::new();
+ let mut current: Option<(char, String)> = None;
+ let mut escaped = false;
+ for c in inner.chars() {
+ match &mut current {
+ Some((quote, text)) => {
+ if escaped {
+ text.push(c);
+ escaped = false;
+ } else if c == '\\' && *quote == '"' {
+ escaped = true;
+ } else if c == *quote {
+ out.push(std::mem::take(text));
+ current = None;
+ } else {
+ text.push(c);
+ }
+ }
+ None if c == '"' || c == '\'' => current = Some((c, String::new())),
+ None => {}
}
}
- flush(&mut name, &mut detail, &mut disabled, &mut out);
out
}
@@ -224,12 +271,12 @@ mod tests {
std::fs::create_dir_all(home.join(".claude")).expect("claude");
let pad = "x".repeat(300 * 1024);
let body = format!(
- r#"{{"history":"{pad}","mcpServers":{{"github":{{"command":"npx","args":["--api-key","abc123","-y","server","sk-abc123def456ghij78"]}},"off":{{"command":"nope","enabled":false}},"zap":{{"url":"https://user:[email protected]/api/mcp/s/secret-token/mcp?token=1"}}}}}}"#
+ r#"{{"history":"{pad}","mcpServers":{{"github":{{"command":"npx","args":["--api-key","abc123","-y","server","sk-abc123def456ghij78","--token=abc123","API_KEY=abc123","https://hooks.zapier.com/api/mcp/s/abc123/mcp"]}},"off":{{"command":"nope","enabled":false}},"zap":{{"url":"https://user:[email protected]/api/mcp/s/secret-token/mcp?token=1"}}}}}}"#
);
std::fs::write(home.join(".claude.json"), body).expect("claude.json");
let connectors = list("claude", &home);
assert_eq!(connectors.iter().map(|c| c.name.as_str()).collect::<Vec<_>>(), ["github", "zap"]);
- assert_eq!(connectors[0].detail, "npx -y server");
+ assert_eq!(connectors[0].detail, "npx -y server https://hooks.zapier.com");
assert_eq!(connectors[1].detail, "https://hooks.zapier.com");
let dumped = format!("{} {}", connectors[0].detail, connectors[1].detail);
assert!(!dumped.contains("abc123") && !dumped.contains("secret"), "{dumped}");
@@ -243,14 +290,15 @@ mod tests {
std::fs::create_dir_all(home.join(".codex")).expect("codex");
std::fs::write(
home.join(".codex/config.toml"),
- "[mcp_servers.github]\ncommand = \"github-mcp\"\nenabled = false # temporarily off\n\n[mcp_servers.docs]\nurl = \"https://alice:[email protected]/mcp?key=xyz\" # kept\n\n[mcp_servers.docs.env]\nTOKEN = \"secret-token\"\n",
+ "[mcp_servers.github]\ncommand = \"github-mcp\"\nenabled = false # temporarily off\n\n[mcp_servers.play]\ncommand = \"npx\"\nargs = [\"-y\", '@playwright/mcp', \"--api-key\", \"abc123\"]\n\n[mcp_servers.docs]\nurl = \"https://alice:[email protected]/mcp?key=xyz\" # kept\n\n[mcp_servers.docs.env]\nTOKEN = \"secret-token\"\n",
)
.expect("toml");
let connectors = list("codex", &home);
- assert_eq!(connectors.len(), 1);
- assert_eq!(connectors[0].name, "docs");
- assert_eq!(connectors[0].detail, "https://example.test");
- assert!(!connectors[0].detail.contains("abc123") && !connectors[0].detail.contains("alice"));
+ assert_eq!(connectors.iter().map(|c| c.name.as_str()).collect::<Vec<_>>(), ["play", "docs"]);
+ assert_eq!(connectors[0].detail, "npx -y @playwright/mcp");
+ assert_eq!(connectors[1].detail, "https://example.test");
+ let dumped = format!("{} {}", connectors[0].detail, connectors[1].detail);
+ assert!(!dumped.contains("abc123") && !dumped.contains("alice"), "{dumped}");
let _ = std::fs::remove_dir_all(root);
}
}
diff --git a/host/src/agent/gear/rules.rs b/host/src/agent/gear/rules.rs
index e5141a1c..bd5c2a15 100644
--- a/host/src/agent/gear/rules.rs
+++ b/host/src/agent/gear/rules.rs
@@ -1,5 +1,6 @@
-//! Instruction files an agent keeps in the user's home. Copilot's file is
-//! `~/.copilot/copilot-instructions.md`, not Claude's rules.
+//! Instruction files an agent keeps in the user's home: its global file (`~/.claude/CLAUDE.md`,
+//! `~/.codex/AGENTS.md`, …) and the rule folders it reads. A rule in a subfolder is named by its
+//! path under the folder, so two `style.mdc` files stay two rows.
use std::path::Path;
@@ -12,18 +13,31 @@ const RULE_BYTES: u64 = 64 * 1024;
pub(super) fn list(backend: &str, home: &Path) -> Vec<Named> {
let mut out = Vec::new();
- for dir in homes(home, dirs(backend)) {
- walk(&dir, 0, &mut out);
- }
for file in homes(home, files(backend)) {
- if let Some(item) = rule_file(&file) {
+ let label = file.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
+ if let Some(item) = rule_file(&file, &label) {
out.push(item);
}
}
+ for dir in homes(home, dirs(backend)) {
+ walk(&dir, &dir, 0, &mut out);
+ }
super::dedupe(&mut out);
out
}
+fn files(backend: &str) -> &'static [&'static str] {
+ match backend {
+ "claude" => &[".claude/CLAUDE.md"],
+ "codex" => &[".codex/AGENTS.md"],
+ "copilot" => &[".copilot/copilot-instructions.md"],
+ "codebuddy" | "workbuddy" => &[".codebuddy/CODEBUDDY.md", ".codebuddy/AGENTS.md"],
+ "gemini" | "antigravity" => &[".gemini/GEMINI.md"],
+ "grok" => &[".grok/AGENTS.md"],
+ _ => &[],
+ }
+}
+
fn dirs(backend: &str) -> &'static [&'static str] {
match backend {
"cursor" => &[".cursor/rules"],
@@ -35,14 +49,7 @@ fn dirs(backend: &str) -> &'static [&'static str] {
}
}
-fn files(backend: &str) -> &'static [&'static str] {
- match backend {
- "copilot" => &[".copilot/copilot-instructions.md"],
- _ => &[],
- }
-}
-
-fn walk(dir: &Path, depth: usize, out: &mut Vec<Named>) {
+fn walk(root: &Path, dir: &Path, depth: usize, out: &mut Vec<Named>) {
if depth > MAX_DEPTH || out.len() >= MAX_ITEMS || !is_dir(dir) {
return;
}
@@ -58,29 +65,77 @@ fn walk(dir: &Path, depth: usize, out: &mut Vec<Named>) {
}
let path = entry.path();
if is_dir(&path) {
- walk(&path, depth + 1, out);
+ walk(root, &path, depth + 1, out);
} else if is_rule(&path)
- && let Some(item) = rule_file(&path)
+ && let Some(item) = rule_file(&path, &relative(root, &path))
{
out.push(item);
}
}
}
+/// `frontend/style.mdc` for a rule under `root`, with `/` on every platform.
+fn relative(root: &Path, path: &Path) -> String {
+ let rel = path.strip_prefix(root).unwrap_or(path);
+ rel.components().map(|c| c.as_os_str().to_string_lossy()).collect::<Vec<_>>().join("/")
+}
+
fn is_rule(path: &Path) -> bool {
matches!(path.extension().and_then(|ext| ext.to_str()), Some("md" | "mdc" | "markdown"))
}
-fn rule_file(path: &Path) -> Option<Named> {
+fn rule_file(path: &Path, label: &str) -> Option<Named> {
if !path.is_file() {
return None;
}
let text = read_limited(path, RULE_BYTES)?;
let (name, description) = front_matter(&text);
- let fallback = path.file_name().and_then(|n| n.to_str()).unwrap_or("rule");
- let name = clip(&name.unwrap_or_else(|| fallback.to_owned()), NAME_CHARS);
+ let name = clip(&name.unwrap_or_else(|| label.to_owned()), NAME_CHARS);
if name.is_empty() {
return None;
}
Some(Named { name, description: clip(&description.unwrap_or_default(), TEXT_CHARS), detail: String::new() })
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn scratch() -> std::path::PathBuf {
+ let dir = std::env::temp_dir().join(format!("codync-gear-rules-{}", uuid::Uuid::new_v4()));
+ std::fs::create_dir_all(&dir).expect("temp dir");
+ dir
+ }
+
+ fn names(rules: &[Named]) -> Vec<&str> {
+ let mut names = rules.iter().map(|r| r.name.as_str()).collect::<Vec<_>>();
+ names.sort_unstable();
+ names
+ }
+
+ #[test]
+ fn claude_lists_its_global_file_and_same_named_rules() {
+ let root = scratch();
+ let home = root.join("home");
+ std::fs::create_dir_all(home.join(".claude/rules/frontend")).expect("frontend");
+ std::fs::create_dir_all(home.join(".claude/rules/backend")).expect("backend");
+ std::fs::write(home.join(".claude/CLAUDE.md"), "# Global\n").expect("global");
+ std::fs::write(home.join(".claude/rules/frontend/style.md"), "# Front\n").expect("front");
+ std::fs::write(home.join(".claude/rules/backend/style.md"), "# Back\n").expect("back");
+ let rules = list("claude", &home);
+ assert_eq!(names(&rules), ["CLAUDE.md", "backend/style.md", "frontend/style.md"]);
+ let _ = std::fs::remove_dir_all(root);
+ }
+
+ #[test]
+ fn codex_lists_its_agents_file() {
+ let root = scratch();
+ let home = root.join("home");
+ std::fs::create_dir_all(home.join(".codex")).expect("codex");
+ std::fs::create_dir_all(home.join(".claude")).expect("claude");
+ std::fs::write(home.join(".codex/AGENTS.md"), "Be brief.\n").expect("agents");
+ std::fs::write(home.join(".claude/CLAUDE.md"), "# Not Codex\n").expect("claude");
+ assert_eq!(names(&list("codex", &home)), ["AGENTS.md"]);
+ let _ = std::fs::remove_dir_all(root);
+ }
+}