use crate::diagnostic::{DOCS, PathSegment, SchemaDiagnostic, Severity};
use crate::tool_policy::DISALLOWED_SPELLINGS;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Scope {
Agent,
Skill,
Package,
Namespace,
}
const RETIRED: &[(Scope, &str, &str)] = &[
(Scope::Agent, "mcp-tools", "agent-mcp-tools"),
(
Scope::Agent,
"model_invocable",
"agent-underscore-spellings",
),
(Scope::Agent, "user_invocable", "agent-underscore-spellings"),
(Scope::Agent, "network_allow", "agent-underscore-spellings"),
(Scope::Agent, "network_deny", "agent-underscore-spellings"),
(Scope::Agent, "permission", "agent-host-keys"),
(Scope::Agent, "resident-rearm-budget", "agent-host-keys"),
(Scope::Agent, "meridian-capabilities", "agent-host-keys"),
(Scope::Agent, "fanout", "agent-fanout"),
(Scope::Agent, "models", "agent-models"),
(Scope::Agent, "autocompact", "agent-autocompact"),
(Scope::Agent, "autocompact_pct", "agent-autocompact"),
(Scope::Skill, "type", "skill-type-and-when_to_use"),
(Scope::Skill, "when_to_use", "skill-type-and-when_to_use"),
(
Scope::Skill,
"model_invocable",
"agent-underscore-spellings",
),
(Scope::Skill, "user_invocable", "agent-underscore-spellings"),
(Scope::Skill, "disable-model-invocation", "skill-invocation"),
(Scope::Skill, "invocation", "skill-invocation"),
(
Scope::Skill,
"allow_implicit_invocation",
"skill-invocation",
),
(Scope::Package, "visibility", "package-visibility"),
(Scope::Namespace, "flow", "host-namespaces"),
(Scope::Namespace, "meridian", "host-namespaces"),
(Scope::Namespace, "cursor", "cursor"),
];
pub struct RetiredTarget {
pub dir: &'static str,
pub anchor: &'static str,
pub mcp_path: &'static str,
pub mcp_section: &'static str,
pub hook_file: &'static str,
pub hook_file_keys: &'static [&'static str],
pub plugin_root_file: &'static str,
pub plugin_catalog_directory: &'static str,
}
pub const RETIRED_TARGETS: &[RetiredTarget] = &[RetiredTarget {
dir: ".cursor",
anchor: "cursor",
mcp_path: ".cursor/mcp.json",
mcp_section: "mcpServers",
hook_file: "hooks.json",
hook_file_keys: &["version"],
plugin_root_file: ".cursor-plugin/marketplace.json",
plugin_catalog_directory: ".cursor-plugin",
}];
pub fn retired_target(name: &str) -> Option<&'static RetiredTarget> {
let name = name
.trim()
.trim_end_matches(['/', '\\'])
.to_ascii_lowercase();
let dir = if name.starts_with('.') {
name
} else {
format!(".{name}")
};
RETIRED_TARGETS.iter().find(|target| target.dir == dir)
}
pub(crate) fn harness_diagnostic(name: &str, path: Vec<PathSegment>) -> Option<SchemaDiagnostic> {
let retired = retired_target(name)?;
let at = path
.iter()
.filter_map(|segment| match segment {
PathSegment::Key(key) => Some(key.as_str()),
PathSegment::Index(_) => None,
})
.collect::<Vec<_>>()
.join(".");
Some(SchemaDiagnostic::new(
"field.retired",
Severity::Warning,
path,
format!(
"`{at}` names `{}`, a harness Mars no longer supports, so naming it has no effect; remove it: {DOCS}/retired-keys.md#{}",
name.trim(),
retired.anchor
),
))
}
pub(crate) fn config_notes(table: &toml::Table) -> Vec<SchemaDiagnostic> {
let key = |part: &str| PathSegment::Key(part.to_owned());
let settings = table.get("settings").and_then(toml::Value::as_table);
let mut diagnostics: Vec<SchemaDiagnostic> = managed_root_note(
settings
.and_then(|settings| settings.get("managed_root"))
.and_then(toml::Value::as_str),
)
.into_iter()
.collect();
let mut check = |value: Option<&toml::Value>, path: Vec<PathSegment>| {
if let Some(name) = value.and_then(toml::Value::as_str) {
diagnostics.extend(harness_diagnostic(name, path));
}
};
check(
settings.and_then(|settings| settings.get("default_harness")),
vec![key("settings"), key("default_harness")],
);
let order = settings
.and_then(|settings| settings.get("harness_order"))
.and_then(toml::Value::as_array);
for (index, name) in order.into_iter().flatten().enumerate() {
check(
Some(name),
vec![
key("settings"),
key("harness_order"),
PathSegment::Index(index),
],
);
}
diagnostics.extend(model_harness_diagnostics(table));
diagnostics
}
pub fn model_harness_diagnostics(table: &toml::Table) -> Vec<SchemaDiagnostic> {
table
.get("models")
.and_then(toml::Value::as_table)
.into_iter()
.flatten()
.filter_map(|(alias, entry)| {
let name = entry.get("harness")?.as_str()?;
let path = ["models", alias, "harness"]
.map(|part| PathSegment::Key(part.to_owned()))
.to_vec();
harness_diagnostic(name, path)
})
.collect()
}
impl RetiredTarget {
pub fn message(&self, unlink: &str) -> String {
format!(
"`{}` is a target Mars no longer writes: nothing is synced to it. Run `{unlink}` to remove what earlier syncs installed there: {DOCS}/retired-keys.md#{}",
self.dir, self.anchor
)
}
}
fn managed_root_note(managed_root: Option<&str>) -> Option<SchemaDiagnostic> {
let managed_root = managed_root?;
Some(SchemaDiagnostic::new(
"field.retired",
Severity::Warning,
vec![
PathSegment::Key("settings".to_owned()),
PathSegment::Key("managed_root".to_owned()),
],
format!(
"`settings.managed_root` is a key Mars no longer reads, so it has no effect, and a sync removes what Mars installed in `{managed_root}` unless `targets` names it. To keep `{managed_root}`, write `targets = [\"{managed_root}\"]` under `[settings]` (`mars link {managed_root}` writes it and installs again) and delete `managed_root`. Without `targets`, routing is no longer limited to the harnesses the project named: {DOCS}/retired-keys.md#managed_root"
),
))
}
fn anchor(scope: Scope, key: &str) -> Option<&'static str> {
let listed = RETIRED
.iter()
.find(|(known_scope, known, _)| *known_scope == scope && *known == key)
.map(|(_, _, anchor)| *anchor);
listed.or_else(|| match scope {
Scope::Agent if DISALLOWED_SPELLINGS.contains(&key) => Some("agent-deny-lists"),
Scope::Skill if crate::skill::tool_keys().any(|known| known == key) => {
Some("skill-tool-policy")
}
_ => None,
})
}
pub(crate) fn diagnostic(
scope: Scope,
key: &str,
path: Vec<PathSegment>,
) -> Option<SchemaDiagnostic> {
let anchor = anchor(scope, key)?;
let name = match scope {
Scope::Package => format!("package.{key}"),
Scope::Namespace => format!("harness-overrides.{key}"),
Scope::Agent | Scope::Skill => key.to_owned(),
};
Some(SchemaDiagnostic::new(
"field.retired",
Severity::Warning,
path,
format!(
"`{name}` is a key Mars no longer reads, so what it set has no effect: {DOCS}/retired-keys.md#{anchor}"
),
).losing())
}