1use crate::diagnostic::{DOCS, PathSegment, SchemaDiagnostic, Severity};
6use crate::tool_policy::DISALLOWED_SPELLINGS;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub(crate) enum Scope {
11 Agent,
12 Skill,
13 Package,
14 Namespace,
16}
17
18const RETIRED: &[(Scope, &str, &str)] = &[
21 (Scope::Agent, "mcp-tools", "agent-mcp-tools"),
22 (
23 Scope::Agent,
24 "model_invocable",
25 "agent-underscore-spellings",
26 ),
27 (Scope::Agent, "user_invocable", "agent-underscore-spellings"),
28 (Scope::Agent, "network_allow", "agent-underscore-spellings"),
29 (Scope::Agent, "network_deny", "agent-underscore-spellings"),
30 (Scope::Agent, "permission", "agent-host-keys"),
31 (Scope::Agent, "resident-rearm-budget", "agent-host-keys"),
32 (Scope::Agent, "meridian-capabilities", "agent-host-keys"),
33 (Scope::Agent, "fanout", "agent-fanout"),
34 (Scope::Agent, "models", "agent-models"),
35 (Scope::Agent, "autocompact", "agent-autocompact"),
36 (Scope::Agent, "autocompact_pct", "agent-autocompact"),
37 (Scope::Skill, "type", "skill-type-and-when_to_use"),
38 (Scope::Skill, "when_to_use", "skill-type-and-when_to_use"),
39 (
40 Scope::Skill,
41 "model_invocable",
42 "agent-underscore-spellings",
43 ),
44 (Scope::Skill, "user_invocable", "agent-underscore-spellings"),
45 (Scope::Skill, "disable-model-invocation", "skill-invocation"),
46 (Scope::Skill, "invocation", "skill-invocation"),
47 (
48 Scope::Skill,
49 "allow_implicit_invocation",
50 "skill-invocation",
51 ),
52 (Scope::Package, "visibility", "package-visibility"),
53 (Scope::Namespace, "flow", "host-namespaces"),
54 (Scope::Namespace, "meridian", "host-namespaces"),
55 (Scope::Namespace, "cursor", "cursor"),
56];
57
58pub struct RetiredTarget {
62 pub dir: &'static str,
63 pub anchor: &'static str,
65 pub mcp_path: &'static str,
67 pub mcp_section: &'static str,
68 pub hook_file: &'static str,
70 pub hook_file_keys: &'static [&'static str],
73 pub plugin_root_file: &'static str,
76 pub plugin_catalog_directory: &'static str,
77}
78
79pub const RETIRED_TARGETS: &[RetiredTarget] = &[RetiredTarget {
80 dir: ".cursor",
81 anchor: "cursor",
82 mcp_path: ".cursor/mcp.json",
83 mcp_section: "mcpServers",
84 hook_file: "hooks.json",
85 hook_file_keys: &["version"],
86 plugin_root_file: ".cursor-plugin/marketplace.json",
87 plugin_catalog_directory: ".cursor-plugin",
88}];
89
90pub fn retired_target(name: &str) -> Option<&'static RetiredTarget> {
92 let name = name
93 .trim()
94 .trim_end_matches(['/', '\\'])
95 .to_ascii_lowercase();
96 let dir = if name.starts_with('.') {
97 name
98 } else {
99 format!(".{name}")
100 };
101 RETIRED_TARGETS.iter().find(|target| target.dir == dir)
102}
103
104pub(crate) fn harness_diagnostic(name: &str, path: Vec<PathSegment>) -> Option<SchemaDiagnostic> {
107 let retired = retired_target(name)?;
108 let at = path
109 .iter()
110 .filter_map(|segment| match segment {
111 PathSegment::Key(key) => Some(key.as_str()),
112 PathSegment::Index(_) => None,
113 })
114 .collect::<Vec<_>>()
115 .join(".");
116 Some(SchemaDiagnostic::new(
117 "field.retired",
118 Severity::Warning,
119 path,
120 format!(
121 "`{at}` names `{}`, a harness Mars no longer supports, so naming it has no effect; remove it: {DOCS}/retired-keys.md#{}",
122 name.trim(),
123 retired.anchor
124 ),
125 ))
126}
127
128pub(crate) fn config_notes(table: &toml::Table) -> Vec<SchemaDiagnostic> {
132 let key = |part: &str| PathSegment::Key(part.to_owned());
133 let settings = table.get("settings").and_then(toml::Value::as_table);
134 let mut diagnostics: Vec<SchemaDiagnostic> = managed_root_note(
135 settings
136 .and_then(|settings| settings.get("managed_root"))
137 .and_then(toml::Value::as_str),
138 )
139 .into_iter()
140 .collect();
141 let mut check = |value: Option<&toml::Value>, path: Vec<PathSegment>| {
142 if let Some(name) = value.and_then(toml::Value::as_str) {
143 diagnostics.extend(harness_diagnostic(name, path));
144 }
145 };
146 check(
147 settings.and_then(|settings| settings.get("default_harness")),
148 vec![key("settings"), key("default_harness")],
149 );
150 let order = settings
151 .and_then(|settings| settings.get("harness_order"))
152 .and_then(toml::Value::as_array);
153 for (index, name) in order.into_iter().flatten().enumerate() {
154 check(
155 Some(name),
156 vec![
157 key("settings"),
158 key("harness_order"),
159 PathSegment::Index(index),
160 ],
161 );
162 }
163 diagnostics.extend(model_harness_diagnostics(table));
164 diagnostics
165}
166
167pub fn model_harness_diagnostics(table: &toml::Table) -> Vec<SchemaDiagnostic> {
170 table
171 .get("models")
172 .and_then(toml::Value::as_table)
173 .into_iter()
174 .flatten()
175 .filter_map(|(alias, entry)| {
176 let name = entry.get("harness")?.as_str()?;
177 let path = ["models", alias, "harness"]
178 .map(|part| PathSegment::Key(part.to_owned()))
179 .to_vec();
180 harness_diagnostic(name, path)
181 })
182 .collect()
183}
184
185impl RetiredTarget {
186 pub fn message(&self, unlink: &str) -> String {
188 format!(
189 "`{}` 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#{}",
190 self.dir, self.anchor
191 )
192 }
193}
194
195fn managed_root_note(managed_root: Option<&str>) -> Option<SchemaDiagnostic> {
198 let managed_root = managed_root?;
199 Some(SchemaDiagnostic::new(
200 "field.retired",
201 Severity::Warning,
202 vec![
203 PathSegment::Key("settings".to_owned()),
204 PathSegment::Key("managed_root".to_owned()),
205 ],
206 format!(
207 "`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"
208 ),
209 ))
210}
211
212fn anchor(scope: Scope, key: &str) -> Option<&'static str> {
213 let listed = RETIRED
214 .iter()
215 .find(|(known_scope, known, _)| *known_scope == scope && *known == key)
216 .map(|(_, _, anchor)| *anchor);
217 listed.or_else(|| match scope {
218 Scope::Agent if DISALLOWED_SPELLINGS.contains(&key) => Some("agent-deny-lists"),
219 Scope::Skill if crate::skill::tool_keys().any(|known| known == key) => {
220 Some("skill-tool-policy")
221 }
222 _ => None,
223 })
224}
225
226pub(crate) fn diagnostic(
228 scope: Scope,
229 key: &str,
230 path: Vec<PathSegment>,
231) -> Option<SchemaDiagnostic> {
232 let anchor = anchor(scope, key)?;
233 let name = match scope {
234 Scope::Package => format!("package.{key}"),
235 Scope::Namespace => format!("harness-overrides.{key}"),
236 Scope::Agent | Scope::Skill => key.to_owned(),
237 };
238 Some(SchemaDiagnostic::new(
239 "field.retired",
240 Severity::Warning,
241 path,
242 format!(
243 "`{name}` is a key Mars no longer reads, so what it set has no effect: {DOCS}/retired-keys.md#{anchor}"
244 ),
245 ).losing())
246}