spaider-cli 0.2.0__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.0 → spaider_cli-0.3.0}/PKG-INFO +7 -5
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/README.md +6 -4
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/pyproject.toml +2 -2
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/__init__.py +1 -1
- spaider_cli-0.3.0/src/spaider_cli/commands/doctor.py +422 -0
- spaider_cli-0.3.0/src/spaider_cli/commands/mcp.py +329 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/lib/__init__.py +1 -1
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/lib/api.py +10 -0
- 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.0 → spaider_cli-0.3.0}/src/spaider_cli/lib/stack.py +1 -1
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/skills/__init__.py +1 -1
- spaider_cli-0.2.0/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.0 → spaider_cli-0.3.0}/src/spaider_cli/stack/.env.example +11 -1
- spaider_cli-0.3.0/src/spaider_cli/stack/clickhouse/system-logs.xml +35 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/stack/docker-compose.yml +7 -1
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/PKG-INFO +7 -5
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/SOURCES.txt +10 -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.0 → spaider_cli-0.3.0}/tests/test_commands.py +22 -13
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/tests/test_doctor.py +20 -20
- spaider_cli-0.3.0/tests/test_doctor_clients.py +113 -0
- spaider_cli-0.3.0/tests/test_doctor_health.py +46 -0
- {spaider_cli-0.2.0 → 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.0 → spaider_cli-0.3.0}/tests/test_smoke.py +1 -1
- spaider_cli-0.2.0/src/spaider_cli/commands/doctor.py +0 -274
- spaider_cli-0.2.0/src/spaider_cli/commands/mcp.py +0 -288
- spaider_cli-0.2.0/src/spaider_cli/lib/clients.py +0 -97
- spaider_cli-0.2.0/src/spaider_cli/lib/mcp.py +0 -425
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/LICENSE +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/setup.cfg +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/commands/__init__.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/commands/agent.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/commands/governance.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/commands/init.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/commands/memory.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/commands/ops.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/lib/client.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/lib/config.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/lib/docker.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/lib/env.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/lib/llm.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/main.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli/stack/gateway/kong.yml +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/dependency_links.txt +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/entry_points.txt +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/requires.txt +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/src/spaider_cli.egg-info/top_level.txt +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/tests/test_agent.py +0 -0
- {spaider_cli-0.2.0 → spaider_cli-0.3.0}/tests/test_env.py +0 -0
- {spaider_cli-0.2.0 → 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.
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
"""``spaider doctor`` — read-only self-check.
|
|
2
|
+
|
|
3
|
+
Inspects everything ``spaider init`` set up, prints a status table, and exits
|
|
4
|
+
non-zero if any red items remain. The actual repair flow (offering one-click
|
|
5
|
+
fixes for each red item) is v0.2 — keeping doctor read-only in v0.1.0 means
|
|
6
|
+
running it is always safe to share with support.
|
|
7
|
+
|
|
8
|
+
Checks (in order, fail-fast for the ones that block later checks):
|
|
9
|
+
|
|
10
|
+
1. ``docker`` CLI present.
|
|
11
|
+
2. Docker daemon running.
|
|
12
|
+
3. ``.env`` file present at the repo root.
|
|
13
|
+
4. ``LLM_API_KEY`` set and accepted by OpenAI (1-token probe).
|
|
14
|
+
5. Backend ``/health`` returns healthy.
|
|
15
|
+
6. Stored embeddings all match ``EMBEDDING_DIMENSIONS`` (no silent vector-index
|
|
16
|
+
degradation from mixing providers/dimensions).
|
|
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
|
+
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.
|
|
22
|
+
"""
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import json
|
|
26
|
+
import tomllib
|
|
27
|
+
from dataclasses import dataclass
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
import httpx
|
|
31
|
+
import typer
|
|
32
|
+
from rich.console import Console
|
|
33
|
+
from rich.table import Table
|
|
34
|
+
|
|
35
|
+
from spaider_cli.lib import api as api_client
|
|
36
|
+
from spaider_cli.lib import clients as clients_lib
|
|
37
|
+
from spaider_cli.lib import config as config_lib
|
|
38
|
+
from spaider_cli.lib import docker as docker_lib
|
|
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
|
|
42
|
+
from spaider_cli.lib.client import headers as client_headers
|
|
43
|
+
|
|
44
|
+
console = Console()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass
|
|
48
|
+
class CheckResult:
|
|
49
|
+
name: str
|
|
50
|
+
status: str # "ok" | "warn" | "fail"
|
|
51
|
+
detail: str # short hint shown alongside the status
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _ok(name: str, detail: str = "") -> CheckResult:
|
|
55
|
+
return CheckResult(name=name, status="ok", detail=detail)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _warn(name: str, detail: str) -> CheckResult:
|
|
59
|
+
return CheckResult(name=name, status="warn", detail=detail)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _fail(name: str, detail: str) -> CheckResult:
|
|
63
|
+
return CheckResult(name=name, status="fail", detail=detail)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# ---------------------------------------------------------------------------
|
|
67
|
+
# Individual checks
|
|
68
|
+
# ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def check_docker() -> tuple[CheckResult, CheckResult]:
|
|
72
|
+
status = docker_lib.check_docker_available()
|
|
73
|
+
cli = (
|
|
74
|
+
_ok("docker CLI")
|
|
75
|
+
if status.cli_present
|
|
76
|
+
else _fail("docker CLI", "not on PATH. Install Docker Desktop.")
|
|
77
|
+
)
|
|
78
|
+
if not status.cli_present:
|
|
79
|
+
return cli, _fail("docker daemon", "skipped: docker CLI missing.")
|
|
80
|
+
daemon = (
|
|
81
|
+
_ok("docker daemon")
|
|
82
|
+
if status.daemon_running
|
|
83
|
+
else _fail("docker daemon", f"not running. {(status.error or '')[:80]}")
|
|
84
|
+
)
|
|
85
|
+
return cli, daemon
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def check_env_file(repo: Path) -> CheckResult:
|
|
89
|
+
env_path = repo / ".env"
|
|
90
|
+
if not env_path.exists():
|
|
91
|
+
return _fail(
|
|
92
|
+
".env file",
|
|
93
|
+
f"missing at {env_path}. Run `spaider init` or `cp .env.example .env`.",
|
|
94
|
+
)
|
|
95
|
+
return _ok(".env file", str(env_path))
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def check_llm_key(repo: Path) -> CheckResult:
|
|
99
|
+
env_path = repo / ".env"
|
|
100
|
+
if not env_path.exists():
|
|
101
|
+
return _warn("LLM_API_KEY", "skipped: .env not present yet.")
|
|
102
|
+
from spaider_cli.lib import env as env_lib
|
|
103
|
+
|
|
104
|
+
parsed = env_lib.parse_env_text(env_path.read_text(encoding="utf-8"))
|
|
105
|
+
key = parsed.get("LLM_API_KEY", "").strip().strip('"').strip("'")
|
|
106
|
+
if not key or key == "sk-your-key-here":
|
|
107
|
+
return _fail(
|
|
108
|
+
"LLM_API_KEY",
|
|
109
|
+
"still set to the .env.example placeholder. Set a real OpenAI key.",
|
|
110
|
+
)
|
|
111
|
+
result = llm_lib.validate_openai_key(key)
|
|
112
|
+
if not result.ok:
|
|
113
|
+
return _fail("LLM_API_KEY", result.detail)
|
|
114
|
+
return _ok("LLM_API_KEY", "OpenAI accepts the key")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def check_backend_health() -> CheckResult:
|
|
118
|
+
report = api_client.health_report()
|
|
119
|
+
if report is None:
|
|
120
|
+
return _fail(
|
|
121
|
+
"backend /health",
|
|
122
|
+
"not reachable. Run `make dev` or `docker compose up -d backend-api`.",
|
|
123
|
+
)
|
|
124
|
+
# "disabled" means switched off on purpose (the Lite profile). Only a
|
|
125
|
+
# service that is switched on and does not answer is a problem.
|
|
126
|
+
broken = sorted(name for name, state in report.get("services", {}).items() if state == "unavailable")
|
|
127
|
+
if report.get("healthy") is False:
|
|
128
|
+
return _fail("backend /health", "not healthy: " + (", ".join(broken) or "see /health"))
|
|
129
|
+
if broken:
|
|
130
|
+
return _warn("backend /health", "answers, but not available: " + ", ".join(broken))
|
|
131
|
+
return _ok("backend /health", "healthy on :8000")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def check_login() -> CheckResult:
|
|
135
|
+
"""Auth is always on since 0.5, so a working key is part of a working install."""
|
|
136
|
+
if not config_lib.api_key():
|
|
137
|
+
return _warn("API key", "not logged in. Run `spaider login`.")
|
|
138
|
+
try:
|
|
139
|
+
response = httpx.get(f"{config_lib.api_base()}/auth/whoami", headers=client_headers(), timeout=5)
|
|
140
|
+
except httpx.HTTPError as exc:
|
|
141
|
+
return _warn("API key", f"could not check it: {type(exc).__name__}")
|
|
142
|
+
if response.status_code != 200:
|
|
143
|
+
return _fail("API key", "rejected by the server. Run `spaider login` with a current key.")
|
|
144
|
+
who = response.json()
|
|
145
|
+
return _ok("API key", f"{who.get('name') or who.get('id')} ({who.get('org_role')})")
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def check_embedding_dimensions() -> CheckResult:
|
|
149
|
+
"""Flag a graph whose vectors don't match EMBEDDING_DIMENSIONS.
|
|
150
|
+
|
|
151
|
+
A mismatch (e.g. 768-dim Ollama data left behind after switching to a
|
|
152
|
+
1536-dim OpenAI model) can't live in the vector index and silently degrades
|
|
153
|
+
semantic search — so it's a failure, not a warning.
|
|
154
|
+
"""
|
|
155
|
+
report = api_client.embedding_health()
|
|
156
|
+
if report is None:
|
|
157
|
+
return _warn("embedding dimensions", "skipped: backend not reachable.")
|
|
158
|
+
if report.get("error"):
|
|
159
|
+
return _warn("embedding dimensions", f"could not check: {report['error']}")
|
|
160
|
+
expected = report.get("expected_dims")
|
|
161
|
+
present = report.get("present_dims") or []
|
|
162
|
+
if not present:
|
|
163
|
+
return _ok("embedding dimensions", f"no embeddings yet; will use {expected}-dim.")
|
|
164
|
+
if report.get("consistent"):
|
|
165
|
+
return _ok(
|
|
166
|
+
"embedding dimensions",
|
|
167
|
+
f"all {expected}-dim — matches EMBEDDING_DIMENSIONS.",
|
|
168
|
+
)
|
|
169
|
+
return _fail(
|
|
170
|
+
"embedding dimensions",
|
|
171
|
+
f"graph has {present}-dim vectors but EMBEDDING_DIMENSIONS={expected}; "
|
|
172
|
+
f"vector search degrades. Re-seed the agent(s) at {expected}-dim, or "
|
|
173
|
+
f"revert EMBEDDING_DIMENSIONS.",
|
|
174
|
+
)
|
|
175
|
+
|
|
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
|
+
|
|
187
|
+
def check_mcp_config(home: Path | None = None) -> CheckResult:
|
|
188
|
+
home = home or Path.home()
|
|
189
|
+
path = home / ".claude.json"
|
|
190
|
+
stale = _legacy_server_names(home)
|
|
191
|
+
if not path.exists():
|
|
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`.")
|
|
199
|
+
try:
|
|
200
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
201
|
+
except json.JSONDecodeError as exc:
|
|
202
|
+
return _fail("~/.claude.json", f"malformed JSON: {exc}")
|
|
203
|
+
servers = (data.get("mcpServers") or {}) if isinstance(data, dict) else {}
|
|
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:
|
|
219
|
+
return _warn(
|
|
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`.",
|
|
223
|
+
)
|
|
224
|
+
return _ok("~/.claude.json", "SpAIder entry present")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def check_skill_file(home: Path | None = None) -> CheckResult:
|
|
228
|
+
home = home or Path.home()
|
|
229
|
+
label = "~/.claude/skills/spaider/SKILL.md"
|
|
230
|
+
path = home / ".claude" / "skills" / "spaider" / "SKILL.md"
|
|
231
|
+
if not path.exists():
|
|
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`.")
|
|
239
|
+
body = path.read_text(encoding="utf-8")
|
|
240
|
+
missing_tools = [
|
|
241
|
+
t for t in ("spaider.query", "spaider.feedback", "spaider.recall", "spaider.remember") if t not in body
|
|
242
|
+
]
|
|
243
|
+
if missing_tools:
|
|
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)})"
|
|
315
|
+
|
|
316
|
+
|
|
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."""
|
|
321
|
+
home = home or Path.home()
|
|
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:
|
|
364
|
+
return _warn(
|
|
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`.",
|
|
368
|
+
)
|
|
369
|
+
return _ok("keys in the repo", "no literal SpAIder key in the client files of this repo")
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
# ---------------------------------------------------------------------------
|
|
373
|
+
# Entry point
|
|
374
|
+
# ---------------------------------------------------------------------------
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def run(
|
|
378
|
+
repo: Path = typer.Option(
|
|
379
|
+
Path.cwd(),
|
|
380
|
+
"--repo",
|
|
381
|
+
help="Path to the SpAIder checkout. Defaults to the current directory.",
|
|
382
|
+
),
|
|
383
|
+
) -> None:
|
|
384
|
+
"""Run every check and print a status table."""
|
|
385
|
+
results: list[CheckResult] = []
|
|
386
|
+
|
|
387
|
+
docker_cli, docker_daemon = check_docker()
|
|
388
|
+
results.append(docker_cli)
|
|
389
|
+
results.append(docker_daemon)
|
|
390
|
+
results.append(check_env_file(repo))
|
|
391
|
+
results.append(check_llm_key(repo))
|
|
392
|
+
results.append(check_backend_health())
|
|
393
|
+
results.append(check_login())
|
|
394
|
+
results.append(check_embedding_dimensions())
|
|
395
|
+
results.append(check_mcp_config())
|
|
396
|
+
results.append(check_skill_file())
|
|
397
|
+
results.extend(check_clients(repo=repo))
|
|
398
|
+
results.append(check_repo_keys(repo))
|
|
399
|
+
|
|
400
|
+
table = Table(title="SpAIder doctor", header_style="bold cyan")
|
|
401
|
+
table.add_column("Check")
|
|
402
|
+
table.add_column("Status", justify="center")
|
|
403
|
+
table.add_column("Detail", overflow="fold")
|
|
404
|
+
icon = {"ok": "[green]✓[/]", "warn": "[yellow]⚠[/]", "fail": "[red]✗[/]"}
|
|
405
|
+
for r in results:
|
|
406
|
+
table.add_row(r.name, icon[r.status], r.detail)
|
|
407
|
+
console.print(table)
|
|
408
|
+
|
|
409
|
+
failures = [r for r in results if r.status == "fail"]
|
|
410
|
+
warnings = [r for r in results if r.status == "warn"]
|
|
411
|
+
if failures:
|
|
412
|
+
console.print(
|
|
413
|
+
f"\n[red]{len(failures)} failure(s)[/] — fix the rows above and re-run "
|
|
414
|
+
"[bold]spaider doctor[/]."
|
|
415
|
+
)
|
|
416
|
+
raise typer.Exit(code=1)
|
|
417
|
+
if warnings:
|
|
418
|
+
console.print(
|
|
419
|
+
f"\n[yellow]{len(warnings)} warning(s)[/] — non-blocking, but worth addressing."
|
|
420
|
+
)
|
|
421
|
+
raise typer.Exit(code=0)
|
|
422
|
+
console.print("\n[bold green]All clear.[/] SpAIder is ready.")
|