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, "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
58/// A target directory Mars no longer writes. Sync leaves it and what it recorded there alone;
59/// `mars unlink` removes what the lock records, which for the config files below is the
60/// entries Mars added, not the files.
61pub struct RetiredTarget {
62    pub dir: &'static str,
63    /// The anchor on `retired-keys.md`.
64    pub anchor: &'static str,
65    /// The JSON file, from the project root, that held MCP servers, and the object in it.
66    pub mcp_path: &'static str,
67    pub mcp_section: &'static str,
68    /// The file under `dir` that held hook entries, under a `hooks` object.
69    pub hook_file: &'static str,
70    /// Keys Mars wrote beside `hooks`; a file holding only these is empty and `mars unlink`
71    /// deletes it.
72    pub hook_file_keys: &'static [&'static str],
73}
74
75pub const RETIRED_TARGETS: &[RetiredTarget] = &[RetiredTarget {
76    dir: ".cursor",
77    anchor: "cursor",
78    mcp_path: ".cursor/mcp.json",
79    mcp_section: "mcpServers",
80    hook_file: "hooks.json",
81    hook_file_keys: &["version"],
82}];
83
84/// The retired target `name` (`cursor`, `.Cursor`) names, if any.
85pub fn retired_target(name: &str) -> Option<&'static RetiredTarget> {
86    let name = name
87        .trim()
88        .trim_end_matches(['/', '\\'])
89        .to_ascii_lowercase();
90    let dir = if name.starts_with('.') {
91        name
92    } else {
93        format!(".{name}")
94    };
95    RETIRED_TARGETS.iter().find(|target| target.dir == dir)
96}
97
98/// The warning for a harness name at `path` when `name` is a harness Mars retired; naming it
99/// has no effect.
100pub(crate) fn harness_diagnostic(name: &str, path: Vec<PathSegment>) -> Option<SchemaDiagnostic> {
101    let retired = retired_target(name)?;
102    let at = path
103        .iter()
104        .filter_map(|segment| match segment {
105            PathSegment::Key(key) => Some(key.as_str()),
106            PathSegment::Index(_) => None,
107        })
108        .collect::<Vec<_>>()
109        .join(".");
110    Some(SchemaDiagnostic::new(
111        "field.retired",
112        Severity::Warning,
113        path,
114        format!(
115            "`{at}` names `{}`, a harness Mars no longer supports, so naming it has no effect; remove it: {DOCS}/retired-keys.md#{}",
116            name.trim(),
117            retired.anchor
118        ),
119    ))
120}
121
122/// The warnings a config file earns for what Mars retired: `settings.managed_root`, and a retired
123/// harness named in `settings.default_harness`, `settings.harness_order` or a
124/// `[models.<alias>] harness`. The one place the CLI and the WASM reader find them.
125pub(crate) fn config_notes(table: &toml::Table) -> Vec<SchemaDiagnostic> {
126    let key = |part: &str| PathSegment::Key(part.to_owned());
127    let settings = table.get("settings").and_then(toml::Value::as_table);
128    let mut diagnostics: Vec<SchemaDiagnostic> = managed_root_note(
129        settings
130            .and_then(|settings| settings.get("managed_root"))
131            .and_then(toml::Value::as_str),
132    )
133    .into_iter()
134    .collect();
135    let mut check = |value: Option<&toml::Value>, path: Vec<PathSegment>| {
136        if let Some(name) = value.and_then(toml::Value::as_str) {
137            diagnostics.extend(harness_diagnostic(name, path));
138        }
139    };
140    check(
141        settings.and_then(|settings| settings.get("default_harness")),
142        vec![key("settings"), key("default_harness")],
143    );
144    let order = settings
145        .and_then(|settings| settings.get("harness_order"))
146        .and_then(toml::Value::as_array);
147    for (index, name) in order.into_iter().flatten().enumerate() {
148        check(
149            Some(name),
150            vec![
151                key("settings"),
152                key("harness_order"),
153                PathSegment::Index(index),
154            ],
155        );
156    }
157    diagnostics.extend(model_harness_diagnostics(table));
158    diagnostics
159}
160
161/// The warnings for a retired harness a `[models.<alias>] harness` names: the one place a
162/// dependent reads a package's harness choice.
163pub fn model_harness_diagnostics(table: &toml::Table) -> Vec<SchemaDiagnostic> {
164    table
165        .get("models")
166        .and_then(toml::Value::as_table)
167        .into_iter()
168        .flatten()
169        .filter_map(|(alias, entry)| {
170            let name = entry.get("harness")?.as_str()?;
171            let path = ["models", alias, "harness"]
172                .map(|part| PathSegment::Key(part.to_owned()))
173                .to_vec();
174            harness_diagnostic(name, path)
175        })
176        .collect()
177}
178
179impl RetiredTarget {
180    /// What a project that links this target is told; `unlink` is the command that removes it.
181    pub fn message(&self, unlink: &str) -> String {
182        format!(
183            "`{}` 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#{}",
184            self.dir, self.anchor
185        )
186    }
187}
188
189/// The `field.retired` note for a file's `managed_root`, which Mars no longer reads. It is built
190/// from the file alone, so the CLI and the WASM reader say the same thing.
191fn managed_root_note(managed_root: Option<&str>) -> Option<SchemaDiagnostic> {
192    let managed_root = managed_root?;
193    Some(SchemaDiagnostic::new(
194        "field.retired",
195        Severity::Warning,
196        vec![
197            PathSegment::Key("settings".to_owned()),
198            PathSegment::Key("managed_root".to_owned()),
199        ],
200        format!(
201            "`settings.managed_root` is a key Mars no longer reads, so it has no effect. Write `targets = [\"{managed_root}\"]` under `[settings]` if you still want `{managed_root}`, and delete `managed_root`. Without `targets`, routing is no longer limited to the harnesses the project named: {DOCS}/retired-keys.md#managed_root"
202        ),
203    ))
204}
205
206fn anchor(scope: Scope, key: &str) -> Option<&'static str> {
207    let listed = RETIRED
208        .iter()
209        .find(|(known_scope, known, _)| *known_scope == scope && *known == key)
210        .map(|(_, _, anchor)| *anchor);
211    listed.or_else(|| match scope {
212        Scope::Agent if DISALLOWED_SPELLINGS.contains(&key) => Some("agent-deny-lists"),
213        Scope::Skill if crate::skill::tool_keys().any(|known| known == key) => {
214            Some("skill-tool-policy")
215        }
216        _ => None,
217    })
218}
219
220/// The warning for `key` of `scope` at `path`, when Mars retired it.
221pub(crate) fn diagnostic(
222    scope: Scope,
223    key: &str,
224    path: Vec<PathSegment>,
225) -> Option<SchemaDiagnostic> {
226    let anchor = anchor(scope, key)?;
227    let name = match scope {
228        Scope::Package => format!("package.{key}"),
229        Scope::Namespace => format!("harness-overrides.{key}"),
230        Scope::Agent | Scope::Skill => key.to_owned(),
231    };
232    Some(SchemaDiagnostic::new(
233        "field.retired",
234        Severity::Warning,
235        path,
236        format!(
237            "`{name}` is a key Mars no longer reads, so what it set has no effect: {DOCS}/retired-keys.md#{anchor}"
238        ),
239    ))
240}