semlith 0.41.0

A fast local vector store for AI agents — index files once, keep it current as you save, and answer questions across all of it in milliseconds without leaving the machine.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
//! Which app is on the other end of an MCP connection.
//!
//! A client names itself in `initialize`, and the name is its own choice:
//! Claude Code says `claude-code`, but Claude Desktop, Zed, Copilot in VS Code
//! and Copilot CLI all say `mcp`, IO CLI says `rmcp`, and the Codex CLI and the
//! ChatGPT desktop app both say `codex-mcp-client`. The ledger and the access
//! report filed four apps under one name. The one fact no client can blur is
//! the process that started `semlith mcp`: the stdio proxy reads its own
//! ancestry once, names the app it finds there, and hands it to the daemon.
//! [`label`] then resolves the two into one of the names `docs/clients.md`
//! uses, whichever transport the client connected by.

use std::sync::OnceLock;

/// The header the stdio proxy carries the host app in.
pub const HEADER: &str = "Semlith-Host";

/// The app that started this process, read once from its ancestors.
pub fn host() -> Option<&'static str> {
    static HOST: OnceLock<Option<String>> = OnceLock::new();
    HOST.get_or_init(|| classify_host(&ancestors())).as_deref()
}

/// Whether a `clientInfo.name` says which app it is. The generic ones name
/// the MCP library the app was built with instead — and then the version
/// beside it is the library's, not the app's, so it is not recorded.
pub fn generic(name: &str) -> bool {
    matches!(
        name.trim().to_ascii_lowercase().as_str(),
        "" | "mcp" | "rmcp" | "client" | "mcp-client" | "mcp client" | "unnamed client"
    )
}

/// The name a ledger row carries for a connection: one of the clients
/// `docs/clients.md` documents where the connection can be told apart, else
/// what the client called itself.
///
/// A specific `clientInfo` name wins over the host, because one host runs
/// several clients: VS Code's extension host runs Cline as well as Copilot. The
/// host decides where the name is generic, and where one name serves two apps.
pub fn label(client_info: Option<&str>, host: Option<&str>) -> String {
    const CHATGPT: &str = "ChatGPT desktop (the Codex app)";
    let info = client_info.map(str::trim).filter(|n| !n.is_empty());
    let lower = info.map(str::to_ascii_lowercase).unwrap_or_default();
    let named = match lower.as_str() {
        "claude-code" => Some("Claude Code"),
        "claude-ai" | "claude desktop" => Some("Claude Desktop"),
        // Claude Desktop's local agent mode starts its own connection.
        l if l.starts_with("local-agent-mode") && host == Some("Claude Desktop") => {
            Some("Claude Desktop")
        }
        "opencode" => Some("OpenCode"),
        "zed" => Some("Zed"),
        "cursor" | "cursor-vscode" => Some("Cursor"),
        "visual studio code" | "vscode" => Some("GitHub Copilot in VS Code"),
        "io" | "io-cli" => Some("IO CLI"),
        "codex-mcp-client" | "codex" => Some(if host == Some(CHATGPT) {
            CHATGPT
        } else {
            "OpenAI Codex"
        }),
        l if l.starts_with("gemini") => Some("Gemini CLI"),
        l if l.contains("cline") => Some("Cline"),
        l if l.contains("copilot") => Some(match host {
            Some("GitHub Copilot in VS Code") => "GitHub Copilot in VS Code",
            _ => "GitHub Copilot CLI",
        }),
        _ => None,
    };
    if let Some(named) = named {
        return named.to_string();
    }
    match (info, host) {
        // A name this does not know, in an app it does: both, so the row says
        // where it came from. VS Code's extension host runs more than Copilot.
        (Some(info), Some(host)) if !generic(info) => format!("{info} ({})", app_of(host)),
        (Some(info), None) if !generic(info) => info.to_string(),
        (_, Some(host)) => host.to_string(),
        (Some(info), None) => info.to_string(),
        (None, None) => "unnamed client".to_string(),
    }
}

/// The app a host label names, for an unknown client running inside it.
fn app_of(host: &str) -> &str {
    match host {
        "GitHub Copilot in VS Code" => "VS Code",
        "ChatGPT desktop (the Codex app)" => "ChatGPT desktop",
        other => other,
    }
}

/// The documented client an ancestor chain belongs to, nearest ancestor
/// first. An app bundle or install directory is matched before an executable's
/// name, because Copilot in VS Code runs its proxy under a `copilot` binary
/// that lives inside VS Code.
pub fn classify_host(ancestors: &[String]) -> Option<String> {
    for line in ancestors {
        let l = line.to_ascii_lowercase().replace('\\', "/");
        let bundles: [(&str, &[&str]); 5] = [
            (
                "Claude Desktop",
                &[
                    "/claude.app/",
                    "/anthropicclaude/",
                    "/claude_pzs8sxrjxfjjc/",
                    "/claude-desktop",
                ],
            ),
            (
                "ChatGPT desktop (the Codex app)",
                &[
                    "/chatgpt.app/",
                    "/openai.codex",
                    "/usr/lib/chatgpt/",
                    "/openai/codex/bin/",
                ],
            ),
            (
                "Cursor",
                &["/cursor.app/", "/programs/cursor/", "/cursor/cursor"],
            ),
            (
                "GitHub Copilot in VS Code",
                &[
                    "/visual studio code.app/",
                    "/microsoft vs code/",
                    "/usr/share/code/",
                ],
            ),
            (
                "Zed",
                &["/zed.app/", "/zed/zed.exe", "/zed-editor", "/zeditor"],
            ),
        ];
        if let Some((name, _)) = bundles
            .iter()
            .find(|(_, marks)| marks.iter().any(|m| l.contains(m)))
        {
            return Some((*name).to_string());
        }
        let name_of = |word: &str| {
            word.rsplit('/')
                .next()
                .unwrap_or("")
                .trim_end_matches(".exe")
                .trim_end_matches(".cmd")
                .trim_end_matches(".js")
                .to_string()
        };
        let mut words = l.split_whitespace();
        let mut base = name_of(words.next().unwrap_or(""));
        // A CLI npm installed runs as `node <script>`: the script names it.
        if matches!(
            base.as_str(),
            "node" | "bun" | "deno" | "npx" | "python" | "python3"
        ) {
            base = name_of(words.next().unwrap_or(""));
        }
        let base = base.as_str();
        let packages: [(&str, &[&str]); 3] = [
            ("GitHub Copilot CLI", &["@github/copilot"]),
            ("Gemini CLI", &["@google/gemini-cli"]),
            ("OpenAI Codex", &["@openai/codex"]),
        ];
        if let Some((name, _)) = packages
            .iter()
            .find(|(_, marks)| marks.iter().any(|m| l.contains(m)))
        {
            return Some((*name).to_string());
        }
        let by_name = match base {
            "claude" => Some("Claude Code"),
            "codex" => Some("OpenAI Codex"),
            "copilot" => Some("GitHub Copilot CLI"),
            "gemini" => Some("Gemini CLI"),
            "opencode" => Some("OpenCode"),
            "io" => Some("IO CLI"),
            "cline" | ".cline" => Some("Cline"),
            "zed" => Some("Zed"),
            "cursor" => Some("Cursor"),
            _ => None,
        };
        if let Some(name) = by_name {
            return Some(name.to_string());
        }
    }
    None
}

/// The command lines of this process's ancestors, nearest first, at most
/// eight: enough to climb through a shell, `npx` or an editor's helper to the
/// app. Empty when the platform will not say.
fn ancestors() -> Vec<String> {
    platform_ancestors(std::process::id()).unwrap_or_default()
}

#[cfg(unix)]
fn platform_ancestors(pid: u32) -> Option<Vec<String>> {
    let ps = |pid: u32| -> Option<(u32, String)> {
        let out = std::process::Command::new("ps")
            .args(["-o", "ppid=", "-o", "args=", "-p", &pid.to_string()])
            .output()
            .ok()?;
        let text = String::from_utf8_lossy(&out.stdout).trim().to_string();
        let (ppid, args) = text.split_once(char::is_whitespace)?;
        Some((ppid.trim().parse().ok()?, args.trim().to_string()))
    };
    let (mut next, _) = ps(pid)?;
    let mut out = Vec::new();
    while next > 1 && out.len() < 8 {
        let Some((ppid, args)) = ps(next) else { break };
        out.push(args);
        next = ppid;
    }
    Some(out)
}

#[cfg(windows)]
fn platform_ancestors(pid: u32) -> Option<Vec<String>> {
    // One PowerShell for the whole chain, once per proxy: a CIM query per
    // level from Rust would be eight processes where one does.
    let script = format!(
        "$id={pid}; for($i=0;$i -lt 9;$i++){{ \
           $p=Get-CimInstance Win32_Process -Filter \"ProcessId=$id\"; if(!$p){{break}}; \
           if($i -gt 0){{ Write-Output ((\"\" + $p.ExecutablePath + ' ' + $p.CommandLine).Trim()) }}; \
           $id=$p.ParentProcessId; if($id -le 4){{break}} }}"
    );
    let out = std::process::Command::new("powershell")
        .args(["-NoProfile", "-NonInteractive", "-Command", &script])
        .output()
        .ok()?;
    Some(
        String::from_utf8_lossy(&out.stdout)
            .lines()
            .map(str::trim)
            .filter(|l| !l.is_empty())
            .map(str::to_string)
            .collect(),
    )
}

#[cfg(not(any(unix, windows)))]
fn platform_ancestors(_pid: u32) -> Option<Vec<String>> {
    None
}

#[cfg(test)]
mod tests {
    use super::*;

    fn chain(lines: &[&str]) -> Vec<String> {
        lines.iter().map(|s| s.to_string()).collect()
    }

    /// Ancestries read from real `semlith mcp` proxies on 2026-09-30, and
    /// the documented install paths on Linux and Windows.
    #[test]
    fn every_documented_host_is_told_apart_by_its_ancestry() {
        let cases: &[(&[&str], &str)] = &[
            (
                &[
                    "/Applications/Visual Studio Code.app/Contents/Resources/app/node_modules.asar.unpacked/@github/copilot-sdk-darwin-arm64/prebuilds/darwin-arm64/copilot",
                    "/Applications/Visual Studio Code.app/Contents/MacOS/Code",
                ],
                "GitHub Copilot in VS Code",
            ),
            (
                &[
                    "/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --type=utility",
                ],
                "GitHub Copilot in VS Code",
            ),
            (
                &[
                    "claude --dangerously-skip-permissions",
                    "/bin/zsh -l",
                    "/Applications/WezTerm.app/Contents/MacOS/wezterm-gui",
                ],
                "Claude Code",
            ),
            (
                &[
                    "/Applications/Claude.app/Contents/Frameworks/Claude Helper.app/Contents/MacOS/Claude Helper",
                    "/Applications/Claude.app/Contents/MacOS/Claude",
                ],
                "Claude Desktop",
            ),
            (
                &[
                    "/Applications/ChatGPT.app/Contents/Resources/codex app-server",
                    "/Applications/ChatGPT.app/Contents/MacOS/ChatGPT",
                ],
                "ChatGPT desktop (the Codex app)",
            ),
            (&["/Applications/Zed.app/Contents/MacOS/zed"], "Zed"),
            (
                &[
                    "/Applications/Cursor.app/Contents/Frameworks/Cursor Helper (Plugin).app/Contents/MacOS/Cursor Helper (Plugin)",
                ],
                "Cursor",
            ),
            (
                &[
                    "node /usr/local/lib/node_modules/@github/copilot/npm-loader.js -p hi",
                    "zsh",
                ],
                "GitHub Copilot CLI",
            ),
            (
                &["node /home/me/.nvm/versions/node/v24/bin/gemini -p hi"],
                "Gemini CLI",
            ),
            (&["/home/me/.local/bin/io exec --json hi"], "IO CLI"),
            (&["/home/me/.opencode/bin/opencode run hi"], "OpenCode"),
            (
                &["/home/me/.nvm/versions/node/v24/lib/node_modules/cline/bin/.cline --yolo"],
                "Cline",
            ),
            (
                &["/usr/share/code/code --type=utility"],
                "GitHub Copilot in VS Code",
            ),
            (
                &["/usr/lib/chatgpt/chatgpt"],
                "ChatGPT desktop (the Codex app)",
            ),
            (
                &[r"C:\Users\me\AppData\Local\Programs\Microsoft VS Code\Code.exe --type=utility"],
                "GitHub Copilot in VS Code",
            ),
            (
                &[r"C:\Users\me\AppData\Local\AnthropicClaude\app-1.0\claude.exe"],
                "Claude Desktop",
            ),
            (&[r"C:\Users\me\AppData\Local\Programs\Zed\zed.exe"], "Zed"),
            (
                &[
                    r"C:\Program Files\WindowsApps\OpenAI.Codex_1.2.3_x64__2p2nqsd0c76g0\app\ChatGPT.exe",
                ],
                "ChatGPT desktop (the Codex app)",
            ),
            (
                &[
                    r"C:\Users\me\AppData\Roaming\npm\node_modules\@google\gemini-cli\bundle\gemini.js",
                ],
                "Gemini CLI",
            ),
        ];
        for (lines, want) in cases {
            assert_eq!(
                classify_host(&chain(lines)).as_deref(),
                Some(*want),
                "{lines:?}"
            );
        }
        assert_eq!(
            classify_host(&chain(&["/bin/zsh -l", "/sbin/launchd"])),
            None
        );
    }

    /// The names the twelve clients sent on 2026-09-30, with the host each ran
    /// under: every one lands on its documented name.
    #[test]
    fn each_client_is_filed_under_its_own_name() {
        let cases = [
            (Some("claude-code"), Some("Claude Code"), "Claude Code"),
            (
                Some("codex-mcp-client"),
                Some("OpenAI Codex"),
                "OpenAI Codex",
            ),
            (
                Some("codex-mcp-client"),
                Some("ChatGPT desktop (the Codex app)"),
                "ChatGPT desktop (the Codex app)",
            ),
            (Some("opencode"), None, "OpenCode"),
            (Some("rmcp"), Some("IO CLI"), "IO CLI"),
            (
                Some("mcp"),
                Some("GitHub Copilot CLI"),
                "GitHub Copilot CLI",
            ),
            (Some("gemini-cli-mcp-client"), None, "Gemini CLI"),
            (
                Some("mcp"),
                Some("GitHub Copilot in VS Code"),
                "GitHub Copilot in VS Code",
            ),
            (Some("mcp"), Some("Cursor"), "Cursor"),
            (Some("mcp"), Some("Zed"), "Zed"),
            (
                Some("@cline/core"),
                Some("GitHub Copilot in VS Code"),
                "Cline",
            ),
            (Some("mcp"), Some("Claude Desktop"), "Claude Desktop"),
            // Nothing to go on is said as such, not invented.
            (Some("mcp"), None, "mcp"),
            (None, None, "unnamed client"),
            (Some("some-new-agent"), Some("Zed"), "some-new-agent (Zed)"),
            (
                Some("some-extension"),
                Some("GitHub Copilot in VS Code"),
                "some-extension (VS Code)",
            ),
            (Some("some-new-agent"), None, "some-new-agent"),
            (
                Some("local-agent-mode-semlith"),
                Some("Claude Desktop"),
                "Claude Desktop",
            ),
            (Some("Cline"), Some("GitHub Copilot in VS Code"), "Cline"),
        ];
        for (info, host, want) in cases {
            assert_eq!(label(info, host), want, "{info:?} under {host:?}");
        }
    }
}