Skip to main content

mars_schema/
retired.rs

1//! Keys and target directories Mars moved off, each with the page that says how to fix it. A
2//! reader that meets a key warns once (`field.retired`) and does not read it. Delete this module and every key here
3//! falls back to the ordinary `field.unknown`.
4
5use crate::diagnostic::{DOCS, PathSegment, SchemaDiagnostic, Severity};
6use crate::tool_policy::DISALLOWED_SPELLINGS;
7
8/// The table a retired key sat in.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub(crate) enum Scope {
11    Agent,
12    Skill,
13    Package,
14    /// A name under `harness-overrides`.
15    Namespace,
16}
17
18/// (scope, key, the anchor on `retired-keys.md`). The tool-policy keys are not listed: they come
19/// from [`anchor`], which reads the spellings the translators already name.
20const 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, "autocompact", "agent-autocompact"),
35    (Scope::Agent, "autocompact_pct", "agent-autocompact"),
36    (Scope::Skill, "type", "skill-type-and-when_to_use"),
37    (Scope::Skill, "when_to_use", "skill-type-and-when_to_use"),
38    (
39        Scope::Skill,
40        "model_invocable",
41        "agent-underscore-spellings",
42    ),
43    (Scope::Skill, "user_invocable", "agent-underscore-spellings"),
44    (Scope::Skill, "disable-model-invocation", "skill-invocation"),
45    (Scope::Skill, "invocation", "skill-invocation"),
46    (
47        Scope::Skill,
48        "allow_implicit_invocation",
49        "skill-invocation",
50    ),
51    (Scope::Package, "visibility", "package-visibility"),
52    (Scope::Namespace, "flow", "host-namespaces"),
53    (Scope::Namespace, "meridian", "host-namespaces"),
54    (Scope::Namespace, "cursor", "cursor"),
55];
56
57/// A target directory Mars no longer writes. Sync leaves it and what it recorded there alone;
58/// `mars unlink` removes what the lock records, which for the config files below is the
59/// entries Mars added, not the files.
60pub struct RetiredTarget {
61    pub dir: &'static str,
62    /// The anchor on `retired-keys.md`.
63    pub anchor: &'static str,
64    /// The JSON file, from the project root, that held MCP servers, and the object in it.
65    pub mcp_path: &'static str,
66    pub mcp_section: &'static str,
67    /// The file under `dir` that held hook entries, under a `hooks` object.
68    pub hook_file: &'static str,
69    /// Keys Mars wrote beside `hooks`; a file holding only these is empty and `mars unlink`
70    /// deletes it.
71    pub hook_file_keys: &'static [&'static str],
72    /// The marketplace file and its directory, from the package root, that a plugin build
73    /// generated. A sentinel an older Mars wrote still records them; a rebuild deletes them.
74    pub plugin_root_file: &'static str,
75    pub plugin_catalog_directory: &'static str,
76}
77
78pub const RETIRED_TARGETS: &[RetiredTarget] = &[RetiredTarget {
79    dir: ".cursor",
80    anchor: "cursor",
81    mcp_path: ".cursor/mcp.json",
82    mcp_section: "mcpServers",
83    hook_file: "hooks.json",
84    hook_file_keys: &["version"],
85    plugin_root_file: ".cursor-plugin/marketplace.json",
86    plugin_catalog_directory: ".cursor-plugin",
87}];
88
89/// The retired target `name` (`cursor`, `.Cursor`) names, if any.
90pub fn retired_target(name: &str) -> Option<&'static RetiredTarget> {
91    let name = name
92        .trim()
93        .trim_end_matches(['/', '\\'])
94        .to_ascii_lowercase();
95    let dir = if name.starts_with('.') {
96        name
97    } else {
98        format!(".{name}")
99    };
100    RETIRED_TARGETS.iter().find(|target| target.dir == dir)
101}
102
103/// The warning for a harness name at `path` when `name` is a harness Mars retired; naming it
104/// has no effect.
105pub(crate) fn harness_diagnostic(name: &str, path: Vec<PathSegment>) -> Option<SchemaDiagnostic> {
106    let retired = retired_target(name)?;
107    let at = path
108        .iter()
109        .filter_map(|segment| match segment {
110            PathSegment::Key(key) => Some(key.as_str()),
111            PathSegment::Index(_) => None,
112        })
113        .collect::<Vec<_>>()
114        .join(".");
115    Some(SchemaDiagnostic::new(
116        "field.retired",
117        Severity::Warning,
118        path,
119        format!(
120            "`{at}` names `{}`, a harness Mars no longer supports, so naming it has no effect; remove it: {DOCS}/retired-keys.md#{}",
121            name.trim(),
122            retired.anchor
123        ),
124    ))
125}
126
127/// The warnings a config file earns for what Mars retired: `settings.managed_root`, and a retired
128/// harness named in `settings.default_harness`, `settings.harness_order` or a
129/// `[models.<alias>] harness`. The one place the CLI and the WASM reader find them.
130pub(crate) fn config_notes(table: &toml::Table) -> Vec<SchemaDiagnostic> {
131    let key = |part: &str| PathSegment::Key(part.to_owned());
132    let settings = table.get("settings").and_then(toml::Value::as_table);
133    let mut diagnostics: Vec<SchemaDiagnostic> = managed_root_note(
134        settings
135            .and_then(|settings| settings.get("managed_root"))
136            .and_then(toml::Value::as_str),
137    )
138    .into_iter()
139    .collect();
140    let mut check = |value: Option<&toml::Value>, path: Vec<PathSegment>| {
141        if let Some(name) = value.and_then(toml::Value::as_str) {
142            diagnostics.extend(harness_diagnostic(name, path));
143        }
144    };
145    check(
146        settings.and_then(|settings| settings.get("default_harness")),
147        vec![key("settings"), key("default_harness")],
148    );
149    let order = settings
150        .and_then(|settings| settings.get("harness_order"))
151        .and_then(toml::Value::as_array);
152    for (index, name) in order.into_iter().flatten().enumerate() {
153        check(
154            Some(name),
155            vec![
156                key("settings"),
157                key("harness_order"),
158                PathSegment::Index(index),
159            ],
160        );
161    }
162    diagnostics.extend(model_harness_diagnostics(table));
163    diagnostics
164}
165
166/// The warnings for a retired harness a `[models.<alias>] harness` names: the one place a
167/// dependent reads a package's harness choice.
168pub fn model_harness_diagnostics(table: &toml::Table) -> Vec<SchemaDiagnostic> {
169    table
170        .get("models")
171        .and_then(toml::Value::as_table)
172        .into_iter()
173        .flatten()
174        .filter_map(|(alias, entry)| {
175            let name = entry.get("harness")?.as_str()?;
176            let path = ["models", alias, "harness"]
177                .map(|part| PathSegment::Key(part.to_owned()))
178                .to_vec();
179            harness_diagnostic(name, path)
180        })
181        .collect()
182}
183
184impl RetiredTarget {
185    /// What a project that links this target is told; `unlink` is the command that removes it.
186    pub fn message(&self, unlink: &str) -> String {
187        format!(
188            "`{}` 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#{}",
189            self.dir, self.anchor
190        )
191    }
192}
193
194/// The `field.retired` note for a file's `managed_root`, which Mars no longer reads. It is built
195/// from the file alone, so the CLI and the WASM reader say the same thing.
196fn managed_root_note(managed_root: Option<&str>) -> Option<SchemaDiagnostic> {
197    let managed_root = managed_root?;
198    Some(SchemaDiagnostic::new(
199        "field.retired",
200        Severity::Warning,
201        vec![
202            PathSegment::Key("settings".to_owned()),
203            PathSegment::Key("managed_root".to_owned()),
204        ],
205        format!(
206            "`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"
207        ),
208    ))
209}
210
211fn anchor(scope: Scope, key: &str) -> Option<&'static str> {
212    let listed = RETIRED
213        .iter()
214        .find(|(known_scope, known, _)| *known_scope == scope && *known == key)
215        .map(|(_, _, anchor)| *anchor);
216    listed.or_else(|| match scope {
217        Scope::Agent if DISALLOWED_SPELLINGS.contains(&key) => Some("agent-deny-lists"),
218        Scope::Skill if crate::skill::tool_keys().any(|known| known == key) => {
219            Some("skill-tool-policy")
220        }
221        _ => None,
222    })
223}
224
225/// The warning for `key` of `scope` at `path`, when Mars retired it.
226pub(crate) fn diagnostic(
227    scope: Scope,
228    key: &str,
229    path: Vec<PathSegment>,
230) -> Option<SchemaDiagnostic> {
231    let anchor = anchor(scope, key)?;
232    let name = match scope {
233        Scope::Package => format!("package.{key}"),
234        Scope::Namespace => format!("harness-overrides.{key}"),
235        Scope::Agent | Scope::Skill => key.to_owned(),
236    };
237    Some(SchemaDiagnostic::new(
238        "field.retired",
239        Severity::Warning,
240        path,
241        format!(
242            "`{name}` is a key Mars no longer reads, so what it set has no effect: {DOCS}/retired-keys.md#{anchor}"
243        ),
244    ).losing())
245}