spaider-cli 0.2.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/PKG-INFO +7 -5
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/README.md +6 -4
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/pyproject.toml +2 -2
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/__init__.py +1 -1
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/commands/doctor.py +179 -39
- spaider_cli-0.3.0/src/spaider_cli/commands/mcp.py +329 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/lib/__init__.py +1 -1
- spaider_cli-0.3.0/src/spaider_cli/lib/clientkeys.py +72 -0
- spaider_cli-0.3.0/src/spaider_cli/lib/clients.py +496 -0
- spaider_cli-0.3.0/src/spaider_cli/lib/mcp.py +626 -0
- spaider_cli-0.3.0/src/spaider_cli/lib/skills.py +191 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/skills/__init__.py +1 -1
- spaider_cli-0.2.1/src/spaider_cli/skills/claude_code.md → spaider_cli-0.3.0/src/spaider_cli/skills/spaider/SKILL.md +4 -7
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/PKG-INFO +7 -5
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/SOURCES.txt +8 -1
- spaider_cli-0.3.0/tests/test_claude_code_install.py +625 -0
- spaider_cli-0.3.0/tests/test_client_keys.py +114 -0
- spaider_cli-0.3.0/tests/test_client_registry.py +268 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/tests/test_commands.py +7 -13
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/tests/test_doctor.py +4 -4
- spaider_cli-0.3.0/tests/test_doctor_clients.py +113 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/tests/test_mcp.py +65 -135
- spaider_cli-0.3.0/tests/test_skills.py +243 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/tests/test_smoke.py +1 -1
- spaider_cli-0.2.1/src/spaider_cli/commands/mcp.py +0 -288
- spaider_cli-0.2.1/src/spaider_cli/lib/clients.py +0 -97
- spaider_cli-0.2.1/src/spaider_cli/lib/mcp.py +0 -425
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/LICENSE +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/setup.cfg +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/commands/__init__.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/commands/agent.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/commands/governance.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/commands/init.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/commands/memory.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/commands/ops.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/lib/api.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/lib/client.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/lib/config.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/lib/docker.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/lib/env.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/lib/llm.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/lib/stack.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/main.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/stack/.env.example +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/stack/clickhouse/system-logs.xml +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/stack/docker-compose.yml +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli/stack/gateway/kong.yml +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/dependency_links.txt +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/entry_points.txt +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/requires.txt +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/top_level.txt +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/tests/test_agent.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/tests/test_doctor_health.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/tests/test_env.py +0 -0
- {spaider_cli-0.2.1 → spaider_cli-0.3.0}/tests/test_init.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: spaider-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: SpAIder install wizard, agent management, and Claude Code skill installer
|
|
5
5
|
Author: SpAIder Studio
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -53,7 +53,7 @@ spaider init
|
|
|
53
53
|
| `spaider init` | ✅ One-shot setup wizard |
|
|
54
54
|
| `spaider doctor` | ✅ Read-only health audit |
|
|
55
55
|
| `spaider agent create / list / rotate-key / delete` | ✅ |
|
|
56
|
-
| `spaider mcp install` | ✅ Claude Code
|
|
56
|
+
| `spaider mcp install` | ✅ Claude Code, Cursor, opencode, Codex, VS Code, Gemini CLI, Claude Desktop (Windsurf and Zed: printed snippet) |
|
|
57
57
|
|
|
58
58
|
## What it does
|
|
59
59
|
|
|
@@ -66,13 +66,15 @@ spaider init
|
|
|
66
66
|
- Install the MCP server + skill into `~/.claude/` (idempotent merge).
|
|
67
67
|
|
|
68
68
|
Flags: `--provider`, `--llm-key`, `--llm-base-url`, `--skip-docker`, `--skip-mcp`, `--agent`.
|
|
69
|
-
2. **`spaider doctor`**: read-only audit covering Docker, `.env`, LLM key, backend `/health`, embedding-dimension consistency,
|
|
69
|
+
2. **`spaider doctor`**: read-only audit covering Docker, `.env`, LLM key, backend `/health`, embedding-dimension consistency, the MCP + skill wiring of every client that has a SpAIder entry, and a warning for a literal key in a repo file. Exit 0 when all green/warn, 1 on a blocking failure.
|
|
70
70
|
3. **`spaider agent ...`**: create / list / rotate-key / delete agents against the REST API (resolves agents by name).
|
|
71
|
-
4. **`spaider mcp install`**: non-destructively merge SpAIder into
|
|
71
|
+
4. **`spaider mcp install`**: non-destructively merge SpAIder into the MCP config of one or more clients (`--for` can be repeated: `claude-code`, `cursor`, `opencode`, `codex`, `vscode`, `gemini`, `claude-desktop`, `windsurf`, `zed`; `--scope user` | `project`); each client gets its own key (a service account `mcp-<client>`, reused on later runs), a literal key only ever goes into a private file in your home folder, and the standard `spaider` skill is installed so LLMs reflexively know when to call SpAIder. `spaider mcp add <client>` writes only the MCP entry. Targets the modern Streamable HTTP endpoint (`/api/v1/mcp`).
|
|
72
72
|
|
|
73
73
|
## The skill file
|
|
74
74
|
|
|
75
|
-
A key part of the value: `spaider mcp install` ships not just the MCP server config but a **skill
|
|
75
|
+
A key part of the value: `spaider mcp install` ships not just the MCP server config but a **skill** (`~/.claude/skills/spaider/SKILL.md`, the only layout Claude Code loads) that tells the LLM *when* and *why* to use SpAIder's tools. Without it, MCP tools sit unused. With it, the LLM proactively reaches for SpAIder when the conversation warrants, exactly like `Read`/`Edit`/`Bash` are reflexive in Claude Code today.
|
|
76
|
+
|
|
77
|
+
If an older version installed SpAIder for Claude Code, its files sit where Claude Code never looked (`~/.claude/.mcp.json` and `~/.claude/skills/spaider.md`). `spaider mcp migrate` moves them to `~/.claude.json` and `skills/spaider/SKILL.md`, backing up every file it changes and keeping your keys as they are (`--dry-run` shows what would move). `spaider mcp install` does the same first. Claude Code servers are added with `claude mcp add-json`, the entry passed on stdin so the key never appears on a command line, when the `claude` binary exists and the command is not run inside a Claude Code session; otherwise, or with `--no-claude-cli`, `~/.claude.json` is edited directly. `--scope project` stores the server in Claude Code's private local scope for that repo, so the key is never in a repo file; SpAIder entries an older version put into the repo's `.mcp.json` move there, and if that file was ever in git you are told to rotate the key. `--name spaider-uni` adds a second knowledge base next to the first.
|
|
76
78
|
|
|
77
79
|
Source content is at `src/spaider_cli/skills/claude_code.md` (Apache 2.0); copy and adapt for your own tools if useful.
|
|
78
80
|
|
|
@@ -19,7 +19,7 @@ spaider init
|
|
|
19
19
|
| `spaider init` | ✅ One-shot setup wizard |
|
|
20
20
|
| `spaider doctor` | ✅ Read-only health audit |
|
|
21
21
|
| `spaider agent create / list / rotate-key / delete` | ✅ |
|
|
22
|
-
| `spaider mcp install` | ✅ Claude Code
|
|
22
|
+
| `spaider mcp install` | ✅ Claude Code, Cursor, opencode, Codex, VS Code, Gemini CLI, Claude Desktop (Windsurf and Zed: printed snippet) |
|
|
23
23
|
|
|
24
24
|
## What it does
|
|
25
25
|
|
|
@@ -32,13 +32,15 @@ spaider init
|
|
|
32
32
|
- Install the MCP server + skill into `~/.claude/` (idempotent merge).
|
|
33
33
|
|
|
34
34
|
Flags: `--provider`, `--llm-key`, `--llm-base-url`, `--skip-docker`, `--skip-mcp`, `--agent`.
|
|
35
|
-
2. **`spaider doctor`**: read-only audit covering Docker, `.env`, LLM key, backend `/health`, embedding-dimension consistency,
|
|
35
|
+
2. **`spaider doctor`**: read-only audit covering Docker, `.env`, LLM key, backend `/health`, embedding-dimension consistency, the MCP + skill wiring of every client that has a SpAIder entry, and a warning for a literal key in a repo file. Exit 0 when all green/warn, 1 on a blocking failure.
|
|
36
36
|
3. **`spaider agent ...`**: create / list / rotate-key / delete agents against the REST API (resolves agents by name).
|
|
37
|
-
4. **`spaider mcp install`**: non-destructively merge SpAIder into
|
|
37
|
+
4. **`spaider mcp install`**: non-destructively merge SpAIder into the MCP config of one or more clients (`--for` can be repeated: `claude-code`, `cursor`, `opencode`, `codex`, `vscode`, `gemini`, `claude-desktop`, `windsurf`, `zed`; `--scope user` | `project`); each client gets its own key (a service account `mcp-<client>`, reused on later runs), a literal key only ever goes into a private file in your home folder, and the standard `spaider` skill is installed so LLMs reflexively know when to call SpAIder. `spaider mcp add <client>` writes only the MCP entry. Targets the modern Streamable HTTP endpoint (`/api/v1/mcp`).
|
|
38
38
|
|
|
39
39
|
## The skill file
|
|
40
40
|
|
|
41
|
-
A key part of the value: `spaider mcp install` ships not just the MCP server config but a **skill
|
|
41
|
+
A key part of the value: `spaider mcp install` ships not just the MCP server config but a **skill** (`~/.claude/skills/spaider/SKILL.md`, the only layout Claude Code loads) that tells the LLM *when* and *why* to use SpAIder's tools. Without it, MCP tools sit unused. With it, the LLM proactively reaches for SpAIder when the conversation warrants, exactly like `Read`/`Edit`/`Bash` are reflexive in Claude Code today.
|
|
42
|
+
|
|
43
|
+
If an older version installed SpAIder for Claude Code, its files sit where Claude Code never looked (`~/.claude/.mcp.json` and `~/.claude/skills/spaider.md`). `spaider mcp migrate` moves them to `~/.claude.json` and `skills/spaider/SKILL.md`, backing up every file it changes and keeping your keys as they are (`--dry-run` shows what would move). `spaider mcp install` does the same first. Claude Code servers are added with `claude mcp add-json`, the entry passed on stdin so the key never appears on a command line, when the `claude` binary exists and the command is not run inside a Claude Code session; otherwise, or with `--no-claude-cli`, `~/.claude.json` is edited directly. `--scope project` stores the server in Claude Code's private local scope for that repo, so the key is never in a repo file; SpAIder entries an older version put into the repo's `.mcp.json` move there, and if that file was ever in git you are told to rotate the key. `--name spaider-uni` adds a second knowledge base next to the first.
|
|
42
44
|
|
|
43
45
|
Source content is at `src/spaider_cli/skills/claude_code.md` (Apache 2.0); copy and adapt for your own tools if useful.
|
|
44
46
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "spaider-cli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "SpAIder install wizard, agent management, and Claude Code skill installer"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -50,7 +50,7 @@ spaider = "spaider_cli.main:app"
|
|
|
50
50
|
where = ["src"]
|
|
51
51
|
|
|
52
52
|
[tool.setuptools.package-data]
|
|
53
|
-
"spaider_cli" = ["skills
|
|
53
|
+
"spaider_cli" = ["skills/*/SKILL.md", "stack/docker-compose.yml", "stack/.env.example", "stack/gateway/*", "stack/clickhouse/*"]
|
|
54
54
|
|
|
55
55
|
[tool.ruff]
|
|
56
56
|
line-length = 120
|
|
@@ -5,7 +5,7 @@ Public surface:
|
|
|
5
5
|
spaider init # one-shot first-time wizard
|
|
6
6
|
spaider doctor # self-check + repair
|
|
7
7
|
spaider agent ... # create / list / rotate-key / delete
|
|
8
|
-
spaider mcp install #
|
|
8
|
+
spaider mcp install # add the MCP server to ~/.claude.json + the skill
|
|
9
9
|
|
|
10
10
|
Implementation lives in ``spaider_cli.commands``; this module only re-exports
|
|
11
11
|
the entry-point app so ``[project.scripts]`` resolution stays simple.
|
|
@@ -14,13 +14,16 @@ Checks (in order, fail-fast for the ones that block later checks):
|
|
|
14
14
|
5. Backend ``/health`` returns healthy.
|
|
15
15
|
6. Stored embeddings all match ``EMBEDDING_DIMENSIONS`` (no silent vector-index
|
|
16
16
|
degradation from mixing providers/dimensions).
|
|
17
|
-
7. ``~/.claude
|
|
18
|
-
8. ``~/.claude/skills/spaider.md`` exists and describes the current MCP tools.
|
|
17
|
+
7. ``~/.claude.json`` (user scope) has a SpAIder MCP entry.
|
|
18
|
+
8. ``~/.claude/skills/spaider/SKILL.md`` exists and describes the current MCP tools.
|
|
19
19
|
9. The saved API key is accepted by the server.
|
|
20
|
+
10. Every other client with a SpAIder entry or skill: where it points, how it holds the key, and a current
|
|
21
|
+
skill. A literal key in a repo file is a warning.
|
|
20
22
|
"""
|
|
21
23
|
from __future__ import annotations
|
|
22
24
|
|
|
23
25
|
import json
|
|
26
|
+
import tomllib
|
|
24
27
|
from dataclasses import dataclass
|
|
25
28
|
from pathlib import Path
|
|
26
29
|
|
|
@@ -30,9 +33,12 @@ from rich.console import Console
|
|
|
30
33
|
from rich.table import Table
|
|
31
34
|
|
|
32
35
|
from spaider_cli.lib import api as api_client
|
|
36
|
+
from spaider_cli.lib import clients as clients_lib
|
|
33
37
|
from spaider_cli.lib import config as config_lib
|
|
34
38
|
from spaider_cli.lib import docker as docker_lib
|
|
35
39
|
from spaider_cli.lib import llm as llm_lib
|
|
40
|
+
from spaider_cli.lib import mcp as mcp_lib
|
|
41
|
+
from spaider_cli.lib import skills as skills_lib
|
|
36
42
|
from spaider_cli.lib.client import headers as client_headers
|
|
37
43
|
|
|
38
44
|
console = Console()
|
|
@@ -168,66 +174,199 @@ def check_embedding_dimensions() -> CheckResult:
|
|
|
168
174
|
)
|
|
169
175
|
|
|
170
176
|
|
|
177
|
+
def _legacy_server_names(home: Path) -> list[str]:
|
|
178
|
+
"""Servers in ~/.claude/.mcp.json, a file older versions wrote and Claude Code never reads."""
|
|
179
|
+
path = home / ".claude" / ".mcp.json"
|
|
180
|
+
try:
|
|
181
|
+
servers = json.loads(path.read_text(encoding="utf-8")).get("mcpServers") or {}
|
|
182
|
+
except (OSError, ValueError, AttributeError):
|
|
183
|
+
return []
|
|
184
|
+
return sorted(servers) if isinstance(servers, dict) else []
|
|
185
|
+
|
|
186
|
+
|
|
171
187
|
def check_mcp_config(home: Path | None = None) -> CheckResult:
|
|
172
188
|
home = home or Path.home()
|
|
173
|
-
path = home / ".claude
|
|
189
|
+
path = home / ".claude.json"
|
|
190
|
+
stale = _legacy_server_names(home)
|
|
174
191
|
if not path.exists():
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
192
|
+
if stale:
|
|
193
|
+
return _warn(
|
|
194
|
+
"~/.claude.json",
|
|
195
|
+
f"no user-scope servers, and {len(stale)} entries sit in ~/.claude/.mcp.json, which Claude "
|
|
196
|
+
"Code does not read. Run `spaider mcp migrate`.",
|
|
197
|
+
)
|
|
198
|
+
return _warn("~/.claude.json", "no Claude Code MCP config yet. Run `spaider mcp install`.")
|
|
179
199
|
try:
|
|
180
200
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
181
201
|
except json.JSONDecodeError as exc:
|
|
182
|
-
return _fail("~/.claude
|
|
183
|
-
servers = (data.get("mcpServers") or {})
|
|
202
|
+
return _fail("~/.claude.json", f"malformed JSON: {exc}")
|
|
203
|
+
servers = (data.get("mcpServers") or {}) if isinstance(data, dict) else {}
|
|
184
204
|
if "spaider" not in servers:
|
|
205
|
+
if "spaider" in stale:
|
|
206
|
+
return _warn(
|
|
207
|
+
"~/.claude.json",
|
|
208
|
+
"the SpAIder entry is in ~/.claude/.mcp.json, which Claude Code does not read. "
|
|
209
|
+
"Run `spaider mcp migrate`.",
|
|
210
|
+
)
|
|
211
|
+
return _warn("~/.claude.json", "no SpAIder user-scope entry. Run `spaider mcp install`.")
|
|
212
|
+
entry = servers.get("spaider")
|
|
213
|
+
if isinstance(entry, dict) and "type" not in entry and "url" in entry:
|
|
214
|
+
return _warn(
|
|
215
|
+
"~/.claude.json",
|
|
216
|
+
"the SpAIder entry has a url but no type, so Claude Code skips it. Run `spaider mcp migrate`.",
|
|
217
|
+
)
|
|
218
|
+
if stale:
|
|
185
219
|
return _warn(
|
|
186
|
-
"~/.claude
|
|
187
|
-
"
|
|
220
|
+
"~/.claude.json",
|
|
221
|
+
f"SpAIder entry present, but ~/.claude/.mcp.json still holds {len(stale)} entries that Claude Code "
|
|
222
|
+
"does not read. Run `spaider mcp migrate`.",
|
|
188
223
|
)
|
|
189
|
-
return _ok("~/.claude
|
|
224
|
+
return _ok("~/.claude.json", "SpAIder entry present")
|
|
190
225
|
|
|
191
226
|
|
|
192
227
|
def check_skill_file(home: Path | None = None) -> CheckResult:
|
|
193
228
|
home = home or Path.home()
|
|
194
|
-
|
|
229
|
+
label = "~/.claude/skills/spaider/SKILL.md"
|
|
230
|
+
path = home / ".claude" / "skills" / "spaider" / "SKILL.md"
|
|
195
231
|
if not path.exists():
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
232
|
+
if (home / ".claude" / "skills" / "spaider.md").exists():
|
|
233
|
+
return _warn(
|
|
234
|
+
label,
|
|
235
|
+
"the skill is at ~/.claude/skills/spaider.md, a path Claude Code does not load. "
|
|
236
|
+
"Run `spaider mcp migrate`.",
|
|
237
|
+
)
|
|
238
|
+
return _warn(label, "skill not installed. Run `spaider mcp install`.")
|
|
200
239
|
body = path.read_text(encoding="utf-8")
|
|
201
240
|
missing_tools = [
|
|
202
241
|
t for t in ("spaider.query", "spaider.feedback", "spaider.recall", "spaider.remember") if t not in body
|
|
203
242
|
]
|
|
204
243
|
if missing_tools:
|
|
205
|
-
return _warn(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
244
|
+
return _warn(label, f"out of date (no {', '.join(missing_tools)}). Run `spaider mcp skill`.")
|
|
245
|
+
return _ok(label, "loaded by Claude Code at session start")
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
# Files in a repo that older versions, or a hand edit, may have put a literal key into.
|
|
249
|
+
_REPO_FILES = (
|
|
250
|
+
".mcp.json",
|
|
251
|
+
".cursor/mcp.json",
|
|
252
|
+
".vscode/mcp.json",
|
|
253
|
+
"opencode.json",
|
|
254
|
+
"opencode.jsonc",
|
|
255
|
+
".codex/config.toml",
|
|
256
|
+
".gemini/settings.json",
|
|
257
|
+
".cursorrules",
|
|
258
|
+
"AGENTS.md",
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _entry_of(path: Path, target: clients_lib.Target) -> dict | None:
|
|
263
|
+
"""SpAIder's entry in ``path``, or None. Comments are fine: this only reads."""
|
|
264
|
+
try:
|
|
265
|
+
if target.fmt == "toml":
|
|
266
|
+
return (tomllib.loads(path.read_text(encoding="utf-8")).get("mcp_servers") or {}).get("spaider")
|
|
267
|
+
data, _ = clients_lib.load_json_config(path)
|
|
268
|
+
except (OSError, ValueError, mcp_lib.MalformedConfigError):
|
|
269
|
+
return None
|
|
270
|
+
return (data.get(target.container) or {}).get("spaider")
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def _key_kind(entry: dict) -> str:
|
|
274
|
+
text = json.dumps(entry)
|
|
275
|
+
if clients_lib.holds_key(text):
|
|
276
|
+
return "literal key"
|
|
277
|
+
if "bearer_token_env_var" in entry or "${env:" in text or "{env:" in text:
|
|
278
|
+
return "env reference"
|
|
279
|
+
if "${input:" in text:
|
|
280
|
+
return "password prompt"
|
|
281
|
+
return "no key found"
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _url_of(entry: dict) -> str:
|
|
285
|
+
for field in ("url", "httpUrl", "serverUrl"):
|
|
286
|
+
if isinstance(entry.get(field), str):
|
|
287
|
+
return entry[field]
|
|
288
|
+
return next((a for a in entry.get("args", []) if isinstance(a, str) and a.startswith("http")), "?")
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _shown(path: Path, home: Path, root: Path) -> Path:
|
|
292
|
+
if root in path.parents:
|
|
293
|
+
return path.relative_to(root)
|
|
294
|
+
return Path("~") / path.relative_to(home) if home in path.parents else path
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _skill_row(spec: clients_lib.ClientSpec, name: str, home: Path, root: Path) -> tuple[str, str] | None:
|
|
298
|
+
"""``(status, detail)`` for the skill of a connected client, or None when it has no skills folder."""
|
|
299
|
+
base_of = {"user": home, "project": root}
|
|
300
|
+
reads = {"user": spec.skill_user, "project": spec.skill_project}
|
|
301
|
+
if not any(reads.values()):
|
|
302
|
+
return None
|
|
303
|
+
packaged = mcp_lib.read_packaged_skill()
|
|
304
|
+
found = [
|
|
305
|
+
skills_lib.skill_path(base_of[scope], folder)
|
|
306
|
+
for scope in ("user", "project")
|
|
307
|
+
for folder in reads[scope]
|
|
308
|
+
if skills_lib.skill_path(base_of[scope], folder).exists()
|
|
309
|
+
]
|
|
310
|
+
if not found:
|
|
311
|
+
return "warn", f"skill: missing, run `spaider mcp install --for {name}`"
|
|
312
|
+
if any(path.read_text(encoding="utf-8") != packaged for path in found):
|
|
313
|
+
return "warn", "skill: out of date, run `spaider mcp skill`"
|
|
314
|
+
return "ok", f"skill: current ({_shown(found[0].parent.parent, home, root)})"
|
|
210
315
|
|
|
211
316
|
|
|
212
|
-
def
|
|
213
|
-
"""
|
|
317
|
+
def check_clients(home: Path | None = None, repo: Path | None = None) -> list[CheckResult]:
|
|
318
|
+
"""One row per client other than Claude Code that has a SpAIder entry: where it points, how it holds the
|
|
319
|
+
key, and whether its skill is there and current. A literal key in a repo file is a warning. A client that is
|
|
320
|
+
installed but not connected gets an informational row."""
|
|
214
321
|
home = home or Path.home()
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
322
|
+
root = mcp_lib.project_roots(repo or Path.cwd())[0]
|
|
323
|
+
present = clients_lib.detected(home)
|
|
324
|
+
results: list[CheckResult] = []
|
|
325
|
+
for name, spec in clients_lib.REGISTRY.items():
|
|
326
|
+
if name == "claude-code": # has its own rows above
|
|
327
|
+
continue
|
|
328
|
+
parts: list[str] = []
|
|
329
|
+
status = "ok"
|
|
330
|
+
for scope, target in (("user", spec.user), ("project", spec.project)):
|
|
331
|
+
path = target.path(home, root) if target else None
|
|
332
|
+
entry = _entry_of(path, target) if path and path.exists() else None
|
|
333
|
+
if entry is None:
|
|
334
|
+
continue
|
|
335
|
+
kind = _key_kind(entry)
|
|
336
|
+
parts.append(f"{scope}: {_shown(path, home, root)} -> {_url_of(entry)} ({kind})")
|
|
337
|
+
if kind == "literal key" and root in path.parents:
|
|
338
|
+
status = "warn"
|
|
339
|
+
parts.append("a literal key in a repo file: run `spaider mcp install --scope project` and rotate it")
|
|
340
|
+
if not parts:
|
|
341
|
+
if name in present:
|
|
342
|
+
results.append(_ok(spec.label, f"installed, not connected (optional: `spaider mcp add {name}`)"))
|
|
343
|
+
continue
|
|
344
|
+
skill = _skill_row(spec, name, home, root)
|
|
345
|
+
if skill is not None:
|
|
346
|
+
parts.append(skill[1])
|
|
347
|
+
status = "warn" if "warn" in (status, skill[0]) else "ok"
|
|
348
|
+
results.append(CheckResult(spec.label, status, "; ".join(parts)))
|
|
349
|
+
return results
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def check_repo_keys(repo: Path | None = None) -> CheckResult:
|
|
353
|
+
"""A literal SpAIder key anywhere in the repo's client files. Names only, never the key."""
|
|
354
|
+
root = mcp_lib.project_roots(repo or Path.cwd())[0]
|
|
355
|
+
leaks = []
|
|
356
|
+
for relative in _REPO_FILES:
|
|
357
|
+
path = root / relative
|
|
358
|
+
try:
|
|
359
|
+
if path.is_file() and clients_lib.holds_key(path.read_text(encoding="utf-8", errors="replace")):
|
|
360
|
+
leaks.append(relative)
|
|
361
|
+
except OSError:
|
|
362
|
+
continue
|
|
363
|
+
if leaks:
|
|
226
364
|
return _warn(
|
|
227
|
-
"
|
|
228
|
-
"
|
|
365
|
+
"keys in the repo",
|
|
366
|
+
f"a literal SpAIder key is in {', '.join(leaks)}. Move it with `spaider mcp install --scope project`, "
|
|
367
|
+
"then rotate it with `spaider mcp install --rotate-key`.",
|
|
229
368
|
)
|
|
230
|
-
return _ok("
|
|
369
|
+
return _ok("keys in the repo", "no literal SpAIder key in the client files of this repo")
|
|
231
370
|
|
|
232
371
|
|
|
233
372
|
# ---------------------------------------------------------------------------
|
|
@@ -255,7 +394,8 @@ def run(
|
|
|
255
394
|
results.append(check_embedding_dimensions())
|
|
256
395
|
results.append(check_mcp_config())
|
|
257
396
|
results.append(check_skill_file())
|
|
258
|
-
results.
|
|
397
|
+
results.extend(check_clients(repo=repo))
|
|
398
|
+
results.append(check_repo_keys(repo))
|
|
259
399
|
|
|
260
400
|
table = Table(title="SpAIder doctor", header_style="bold cyan")
|
|
261
401
|
table.add_column("Check")
|