spaider-cli 0.1.1__tar.gz → 0.2.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.1.1 → spaider_cli-0.2.0}/PKG-INFO +4 -4
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/README.md +3 -3
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/pyproject.toml +2 -2
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/commands/doctor.py +46 -3
- spaider_cli-0.2.0/src/spaider_cli/commands/governance.py +133 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/commands/init.py +22 -9
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/commands/mcp.py +120 -25
- spaider_cli-0.2.0/src/spaider_cli/commands/memory.py +95 -0
- spaider_cli-0.2.0/src/spaider_cli/commands/ops.py +61 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/lib/api.py +25 -8
- spaider_cli-0.2.0/src/spaider_cli/lib/client.py +61 -0
- spaider_cli-0.2.0/src/spaider_cli/lib/clients.py +97 -0
- spaider_cli-0.2.0/src/spaider_cli/lib/config.py +51 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/lib/docker.py +15 -10
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/lib/env.py +1 -1
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/lib/mcp.py +141 -1
- spaider_cli-0.2.0/src/spaider_cli/lib/stack.py +43 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/main.py +11 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/skills/claude_code.md +14 -1
- spaider_cli-0.2.0/src/spaider_cli/stack/.env.example +199 -0
- spaider_cli-0.2.0/src/spaider_cli/stack/docker-compose.yml +322 -0
- spaider_cli-0.2.0/src/spaider_cli/stack/gateway/kong.yml +46 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli.egg-info/PKG-INFO +4 -4
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli.egg-info/SOURCES.txt +11 -0
- spaider_cli-0.2.0/tests/test_commands.py +257 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/tests/test_doctor.py +10 -2
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/tests/test_env.py +4 -4
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/tests/test_init.py +4 -4
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/tests/test_mcp.py +94 -11
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/LICENSE +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/setup.cfg +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/__init__.py +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/commands/__init__.py +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/commands/agent.py +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/lib/__init__.py +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/lib/llm.py +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli/skills/__init__.py +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli.egg-info/dependency_links.txt +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli.egg-info/entry_points.txt +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli.egg-info/requires.txt +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/src/spaider_cli.egg-info/top_level.txt +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/tests/test_agent.py +0 -0
- {spaider_cli-0.1.1 → spaider_cli-0.2.0}/tests/test_smoke.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: spaider-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.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,13 +53,13 @@ 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 + Cursor |
|
|
56
|
+
| `spaider mcp install` | ✅ Claude Code + OpenCode + Cursor |
|
|
57
57
|
|
|
58
58
|
## What it does
|
|
59
59
|
|
|
60
60
|
1. **`spaider init`**: one command from clone to a working, MCP-integrated stack:
|
|
61
61
|
- Detect Docker (CLI + daemon).
|
|
62
|
-
- Prompt for the LLM provider (OpenAI / Anthropic / Ollama) and **validate the
|
|
62
|
+
- Prompt for the LLM provider (OpenAI / Anthropic / Ollama) and **validate the credentials** with a live probe (Ollama needs no key; it checks the daemon is reachable). Choosing Ollama configures local embeddings too, for a no-API-key stack.
|
|
63
63
|
- Generate the secrets you shouldn't have to type (JWT, connector key, Neo4j password) and write `.env`. **Re-run safe**: existing secrets are preserved, never regenerated, so re-running never locks the stack out of its own database.
|
|
64
64
|
- Start the Docker stack and wait for `/health`.
|
|
65
65
|
- Provision a `dev-${USER}` agent (or `--agent <name>`) and capture its key.
|
|
@@ -68,7 +68,7 @@ spaider init
|
|
|
68
68
|
Flags: `--provider`, `--llm-key`, `--llm-base-url`, `--skip-docker`, `--skip-mcp`, `--agent`.
|
|
69
69
|
2. **`spaider doctor`**: read-only audit covering Docker, `.env`, LLM key, backend `/health`, embedding-dimension consistency, and the `~/.claude` MCP + skill wiring. 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 your MCP client config (`--for claude-code` | `cursor`, `--scope user` | `project`); also writes the agent-side skill file so LLMs reflexively know when to call SpAIder.
|
|
71
|
+
4. **`spaider mcp install`**: non-destructively merge SpAIder into your MCP client config (`--for claude-code` | `opencode` | `cursor`, `--scope user` | `project`); also writes the agent-side skill/guidance file so LLMs reflexively know when to call SpAIder. Targets the modern Streamable HTTP endpoint (`/api/v1/mcp`).
|
|
72
72
|
|
|
73
73
|
## The skill file
|
|
74
74
|
|
|
@@ -19,13 +19,13 @@ 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 + Cursor |
|
|
22
|
+
| `spaider mcp install` | ✅ Claude Code + OpenCode + Cursor |
|
|
23
23
|
|
|
24
24
|
## What it does
|
|
25
25
|
|
|
26
26
|
1. **`spaider init`**: one command from clone to a working, MCP-integrated stack:
|
|
27
27
|
- Detect Docker (CLI + daemon).
|
|
28
|
-
- Prompt for the LLM provider (OpenAI / Anthropic / Ollama) and **validate the
|
|
28
|
+
- Prompt for the LLM provider (OpenAI / Anthropic / Ollama) and **validate the credentials** with a live probe (Ollama needs no key; it checks the daemon is reachable). Choosing Ollama configures local embeddings too, for a no-API-key stack.
|
|
29
29
|
- Generate the secrets you shouldn't have to type (JWT, connector key, Neo4j password) and write `.env`. **Re-run safe**: existing secrets are preserved, never regenerated, so re-running never locks the stack out of its own database.
|
|
30
30
|
- Start the Docker stack and wait for `/health`.
|
|
31
31
|
- Provision a `dev-${USER}` agent (or `--agent <name>`) and capture its key.
|
|
@@ -34,7 +34,7 @@ spaider init
|
|
|
34
34
|
Flags: `--provider`, `--llm-key`, `--llm-base-url`, `--skip-docker`, `--skip-mcp`, `--agent`.
|
|
35
35
|
2. **`spaider doctor`**: read-only audit covering Docker, `.env`, LLM key, backend `/health`, embedding-dimension consistency, and the `~/.claude` MCP + skill wiring. 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 your MCP client config (`--for claude-code` | `cursor`, `--scope user` | `project`); also writes the agent-side skill file so LLMs reflexively know when to call SpAIder.
|
|
37
|
+
4. **`spaider mcp install`**: non-destructively merge SpAIder into your MCP client config (`--for claude-code` | `opencode` | `cursor`, `--scope user` | `project`); also writes the agent-side skill/guidance file so LLMs reflexively know when to call SpAIder. Targets the modern Streamable HTTP endpoint (`/api/v1/mcp`).
|
|
38
38
|
|
|
39
39
|
## The skill file
|
|
40
40
|
|
|
@@ -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.2.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/*.md"]
|
|
53
|
+
"spaider_cli" = ["skills/*.md", "stack/docker-compose.yml", "stack/.env.example", "stack/gateway/*"]
|
|
54
54
|
|
|
55
55
|
[tool.ruff]
|
|
56
56
|
line-length = 120
|
|
@@ -15,7 +15,8 @@ Checks (in order, fail-fast for the ones that block later checks):
|
|
|
15
15
|
6. Stored embeddings all match ``EMBEDDING_DIMENSIONS`` (no silent vector-index
|
|
16
16
|
degradation from mixing providers/dimensions).
|
|
17
17
|
7. ``~/.claude/.mcp.json`` has a SpAIder MCP entry.
|
|
18
|
-
8. ``~/.claude/skills/spaider.md`` exists and
|
|
18
|
+
8. ``~/.claude/skills/spaider.md`` exists and describes the current MCP tools.
|
|
19
|
+
9. The saved API key is accepted by the server.
|
|
19
20
|
"""
|
|
20
21
|
from __future__ import annotations
|
|
21
22
|
|
|
@@ -23,13 +24,16 @@ import json
|
|
|
23
24
|
from dataclasses import dataclass
|
|
24
25
|
from pathlib import Path
|
|
25
26
|
|
|
27
|
+
import httpx
|
|
26
28
|
import typer
|
|
27
29
|
from rich.console import Console
|
|
28
30
|
from rich.table import Table
|
|
29
31
|
|
|
30
32
|
from spaider_cli.lib import api as api_client
|
|
33
|
+
from spaider_cli.lib import config as config_lib
|
|
31
34
|
from spaider_cli.lib import docker as docker_lib
|
|
32
35
|
from spaider_cli.lib import llm as llm_lib
|
|
36
|
+
from spaider_cli.lib.client import headers as client_headers
|
|
33
37
|
|
|
34
38
|
console = Console()
|
|
35
39
|
|
|
@@ -113,6 +117,20 @@ def check_backend_health() -> CheckResult:
|
|
|
113
117
|
)
|
|
114
118
|
|
|
115
119
|
|
|
120
|
+
def check_login() -> CheckResult:
|
|
121
|
+
"""Auth is always on since 0.5, so a working key is part of a working install."""
|
|
122
|
+
if not config_lib.api_key():
|
|
123
|
+
return _warn("API key", "not logged in. Run `spaider login`.")
|
|
124
|
+
try:
|
|
125
|
+
response = httpx.get(f"{config_lib.api_base()}/auth/whoami", headers=client_headers(), timeout=5)
|
|
126
|
+
except httpx.HTTPError as exc:
|
|
127
|
+
return _warn("API key", f"could not check it: {type(exc).__name__}")
|
|
128
|
+
if response.status_code != 200:
|
|
129
|
+
return _fail("API key", "rejected by the server. Run `spaider login` with a current key.")
|
|
130
|
+
who = response.json()
|
|
131
|
+
return _ok("API key", f"{who.get('name') or who.get('id')} ({who.get('org_role')})")
|
|
132
|
+
|
|
133
|
+
|
|
116
134
|
def check_embedding_dimensions() -> CheckResult:
|
|
117
135
|
"""Flag a graph whose vectors don't match EMBEDDING_DIMENSIONS.
|
|
118
136
|
|
|
@@ -172,15 +190,38 @@ def check_skill_file(home: Path | None = None) -> CheckResult:
|
|
|
172
190
|
"skill not installed. Run `spaider mcp install`.",
|
|
173
191
|
)
|
|
174
192
|
body = path.read_text(encoding="utf-8")
|
|
175
|
-
missing_tools = [
|
|
193
|
+
missing_tools = [
|
|
194
|
+
t for t in ("spaider.query", "spaider.feedback", "spaider.recall", "spaider.remember") if t not in body
|
|
195
|
+
]
|
|
176
196
|
if missing_tools:
|
|
177
197
|
return _warn(
|
|
178
198
|
"~/.claude/skills/spaider.md",
|
|
179
|
-
f"
|
|
199
|
+
f"out of date (no {', '.join(missing_tools)}). Run `spaider mcp skill`.",
|
|
180
200
|
)
|
|
181
201
|
return _ok("~/.claude/skills/spaider.md", "loaded by Claude Code at session start")
|
|
182
202
|
|
|
183
203
|
|
|
204
|
+
def check_opencode_config(home: Path | None = None) -> CheckResult:
|
|
205
|
+
"""OpenCode is an optional target; absent is fine, not a warning."""
|
|
206
|
+
home = home or Path.home()
|
|
207
|
+
path = home / ".config" / "opencode" / "opencode.json"
|
|
208
|
+
if not path.exists():
|
|
209
|
+
return _ok(
|
|
210
|
+
"~/.config/opencode/opencode.json",
|
|
211
|
+
"not configured (optional; `spaider mcp install --for opencode` to add)",
|
|
212
|
+
)
|
|
213
|
+
try:
|
|
214
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
215
|
+
except json.JSONDecodeError as exc:
|
|
216
|
+
return _fail("~/.config/opencode/opencode.json", f"malformed JSON: {exc}")
|
|
217
|
+
if "spaider" not in (data.get("mcp") or {}):
|
|
218
|
+
return _warn(
|
|
219
|
+
"~/.config/opencode/opencode.json",
|
|
220
|
+
"exists but has no SpAIder entry. Run `spaider mcp install --for opencode`.",
|
|
221
|
+
)
|
|
222
|
+
return _ok("~/.config/opencode/opencode.json", "SpAIder entry present")
|
|
223
|
+
|
|
224
|
+
|
|
184
225
|
# ---------------------------------------------------------------------------
|
|
185
226
|
# Entry point
|
|
186
227
|
# ---------------------------------------------------------------------------
|
|
@@ -202,9 +243,11 @@ def run(
|
|
|
202
243
|
results.append(check_env_file(repo))
|
|
203
244
|
results.append(check_llm_key(repo))
|
|
204
245
|
results.append(check_backend_health())
|
|
246
|
+
results.append(check_login())
|
|
205
247
|
results.append(check_embedding_dimensions())
|
|
206
248
|
results.append(check_mcp_config())
|
|
207
249
|
results.append(check_skill_file())
|
|
250
|
+
results.append(check_opencode_config())
|
|
208
251
|
|
|
209
252
|
table = Table(title="SpAIder doctor", header_style="bold cyan")
|
|
210
253
|
table.add_column("Check")
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Federation grants, Knowledge PRs and fine-tuning."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
from rich.console import Console
|
|
10
|
+
|
|
11
|
+
from spaider_cli.lib import client
|
|
12
|
+
|
|
13
|
+
console = Console()
|
|
14
|
+
grant = typer.Typer(help="Share one knowledge base with another.", no_args_is_help=True)
|
|
15
|
+
kpr = typer.Typer(help="Propose merging knowledge between KBs.", no_args_is_help=True)
|
|
16
|
+
finetune = typer.Typer(help="Train a model on a KB's data with an external provider.", no_args_is_help=True)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _show(value) -> None:
|
|
20
|
+
console.print_json(json.dumps(value))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@grant.command("request")
|
|
24
|
+
def grant_request(
|
|
25
|
+
source: str = typer.Argument(..., help="KB being read."),
|
|
26
|
+
target: str = typer.Argument(..., help="KB that will read it."),
|
|
27
|
+
node_type: Optional[list[str]] = typer.Option(None, "--node-type"),
|
|
28
|
+
relation: Optional[list[str]] = typer.Option(None, "--relation"),
|
|
29
|
+
max_clearance: int = typer.Option(1, "--max-clearance"),
|
|
30
|
+
expires_at: Optional[str] = typer.Option(None, "--expires-at", help="ISO 8601."),
|
|
31
|
+
) -> None:
|
|
32
|
+
body = {
|
|
33
|
+
"source_kb": source, "target_kb": target, "node_types": node_type or None,
|
|
34
|
+
"relation_types": relation or None, "max_clearance": max_clearance, "expires_at": expires_at,
|
|
35
|
+
}
|
|
36
|
+
_show(client.request("POST", "/federation/grants", json=body))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@grant.command("list")
|
|
40
|
+
def grant_list() -> None:
|
|
41
|
+
_show(client.request("GET", "/federation/grants"))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@grant.command("approve")
|
|
45
|
+
def grant_approve(grant_id: str) -> None:
|
|
46
|
+
_show(client.request("POST", f"/federation/grants/{grant_id}/approve", json={}))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@grant.command("deny")
|
|
50
|
+
def grant_deny(grant_id: str) -> None:
|
|
51
|
+
_show(client.request("POST", f"/federation/grants/{grant_id}/deny"))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@grant.command("revoke")
|
|
55
|
+
def grant_revoke(grant_id: str) -> None:
|
|
56
|
+
_show(client.request("DELETE", f"/federation/grants/{grant_id}"))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@kpr.command("create")
|
|
60
|
+
def kpr_create(
|
|
61
|
+
source: str,
|
|
62
|
+
target: str,
|
|
63
|
+
node_ids: list[str] = typer.Argument(...),
|
|
64
|
+
title: str = typer.Option(..., "--title"),
|
|
65
|
+
) -> None:
|
|
66
|
+
body = {"source_kb": source, "target_kb": target, "node_ids": node_ids, "title": title}
|
|
67
|
+
_show(client.request("POST", "/federation/kpr", json=body))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@kpr.command("list")
|
|
71
|
+
def kpr_list(target: str) -> None:
|
|
72
|
+
_show(client.request("GET", "/federation/kpr", params={"target_kb": target}))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@kpr.command("show")
|
|
76
|
+
def kpr_show(kpr_id: str) -> None:
|
|
77
|
+
_show(client.request("GET", f"/federation/kpr/{kpr_id}"))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@kpr.command("approve")
|
|
81
|
+
def kpr_approve(kpr_id: str) -> None:
|
|
82
|
+
_show(client.request("POST", f"/federation/kpr/{kpr_id}/approve"))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@kpr.command("reject")
|
|
86
|
+
def kpr_reject(kpr_id: str) -> None:
|
|
87
|
+
_show(client.request("POST", f"/federation/kpr/{kpr_id}/reject"))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@kpr.command("revert")
|
|
91
|
+
def kpr_revert(kpr_id: str) -> None:
|
|
92
|
+
_show(client.request("POST", f"/federation/kpr/{kpr_id}/revert"))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@finetune.command("create")
|
|
96
|
+
def finetune_create(
|
|
97
|
+
agent: str,
|
|
98
|
+
provider: str = typer.Option(..., "--provider", help="openai, together or tinker."),
|
|
99
|
+
base_model: str = typer.Option(..., "--base-model"),
|
|
100
|
+
data_clearance: int = typer.Option(1, "--data-clearance"),
|
|
101
|
+
) -> None:
|
|
102
|
+
"""Submit a job. Training data is sent to the provider."""
|
|
103
|
+
body = {"agent_id": agent, "provider": provider, "base_model": base_model, "data_clearance": data_clearance}
|
|
104
|
+
_show(client.request("POST", "/finetune/jobs", json=body, timeout=600))
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@finetune.command("list")
|
|
108
|
+
def finetune_list(agent: str) -> None:
|
|
109
|
+
_show(client.request("GET", "/finetune/jobs", params={"agent_id": agent}))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@finetune.command("status")
|
|
113
|
+
def finetune_status(version_id: str) -> None:
|
|
114
|
+
_show(client.request("GET", f"/finetune/jobs/{version_id}"))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@finetune.command("evaluate")
|
|
118
|
+
def finetune_evaluate(
|
|
119
|
+
version_id: str,
|
|
120
|
+
items: Path = typer.Argument(..., exists=True, help='JSON list of {"question", "expected"}.'),
|
|
121
|
+
) -> None:
|
|
122
|
+
body = {"items": json.loads(items.read_text(encoding="utf-8"))}
|
|
123
|
+
_show(client.request("POST", f"/finetune/jobs/{version_id}/evaluate", json=body, timeout=3600))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@finetune.command("promote")
|
|
127
|
+
def finetune_promote(version_id: str) -> None:
|
|
128
|
+
_show(client.request("POST", f"/finetune/jobs/{version_id}/promote"))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@finetune.command("rollback")
|
|
132
|
+
def finetune_rollback(agent: str) -> None:
|
|
133
|
+
_show(client.request("POST", "/finetune/rollback", params={"agent_id": agent}))
|
|
@@ -12,7 +12,7 @@ Order of operations:
|
|
|
12
12
|
Neo4j password).
|
|
13
13
|
4. Merge the values into the ``.env`` file (creating from ``.env.example`` if
|
|
14
14
|
needed, preserving any user-set keys, backing up any prior version).
|
|
15
|
-
5. ``docker compose up
|
|
15
|
+
5. Build and start the stack with ``docker compose up``; wait for ``/health``.
|
|
16
16
|
6. Provision a dev agent named ``dev-${USER}`` (or rotate it if it already
|
|
17
17
|
exists).
|
|
18
18
|
7. Install the MCP server entry + skill file into ``~/.claude/`` (skip with
|
|
@@ -29,6 +29,7 @@ from rich.panel import Panel
|
|
|
29
29
|
from rich.prompt import Prompt
|
|
30
30
|
|
|
31
31
|
from spaider_cli.lib import api as api_client
|
|
32
|
+
from spaider_cli.lib import config as config_lib
|
|
32
33
|
from spaider_cli.lib import docker as docker_lib
|
|
33
34
|
from spaider_cli.lib import env as env_lib
|
|
34
35
|
from spaider_cli.lib import llm as llm_lib
|
|
@@ -112,7 +113,7 @@ def run(
|
|
|
112
113
|
# Re-run safety: NEVER regenerate a secret that already exists in .env.
|
|
113
114
|
# The running Neo4j container is created with whatever NEO4J_PASSWORD was in
|
|
114
115
|
# .env at first boot; rewriting it on a re-run would lock the backend out of
|
|
115
|
-
# its own database (and
|
|
116
|
+
# its own database (and make connector ciphertext unreadable).
|
|
116
117
|
# So generate only the secrets that are missing/empty, and preserve the rest.
|
|
117
118
|
console.print("\n[bold][3/6] Generating secrets[/]")
|
|
118
119
|
env_path = repo / ".env"
|
|
@@ -126,19 +127,19 @@ def run(
|
|
|
126
127
|
current = existing.get(key, "").strip()
|
|
127
128
|
return (current, True) if current else (generator(), False)
|
|
128
129
|
|
|
129
|
-
|
|
130
|
+
bootstrap_token, bootstrap_kept = _keep_or_generate("SPAIDER_BOOTSTRAP_TOKEN", env_lib.generate_bootstrap_token)
|
|
130
131
|
connector_key, ck_kept = _keep_or_generate("CONNECTOR_SECRET_KEY", env_lib.generate_connector_key)
|
|
131
132
|
neo4j_pw, neo_kept = _keep_or_generate("NEO4J_PASSWORD", env_lib.generate_neo4j_password)
|
|
132
|
-
if
|
|
133
|
+
if bootstrap_kept or ck_kept or neo_kept:
|
|
133
134
|
console.print(" [green]✓[/] Reused existing secrets where present (re-run safe)")
|
|
134
135
|
else:
|
|
135
|
-
console.print(" [green]✓[/]
|
|
136
|
+
console.print(" [green]✓[/] Bootstrap token, connector encryption key, Neo4j password")
|
|
136
137
|
|
|
137
138
|
# 4. .env
|
|
138
139
|
console.print("\n[bold][4/6] Writing .env[/]")
|
|
139
140
|
overrides = {
|
|
140
141
|
**provider_overrides,
|
|
141
|
-
"
|
|
142
|
+
"SPAIDER_BOOTSTRAP_TOKEN": bootstrap_token,
|
|
142
143
|
"CONNECTOR_SECRET_KEY": connector_key,
|
|
143
144
|
"NEO4J_PASSWORD": neo4j_pw,
|
|
144
145
|
}
|
|
@@ -159,7 +160,10 @@ def run(
|
|
|
159
160
|
if skip_docker:
|
|
160
161
|
console.print("\n[bold][5/6] Stack startup[/] [dim](skipped via --skip-docker)[/]")
|
|
161
162
|
else:
|
|
162
|
-
console.print(
|
|
163
|
+
console.print(
|
|
164
|
+
"\n[bold][5/6] Building and starting the stack[/] "
|
|
165
|
+
"[dim](the first build takes several minutes)[/]"
|
|
166
|
+
)
|
|
163
167
|
compose = docker_lib.compose_up(repo)
|
|
164
168
|
if not compose.ok:
|
|
165
169
|
err_console.print(
|
|
@@ -167,7 +171,7 @@ def run(
|
|
|
167
171
|
f" {compose.stderr.strip()[:400]}"
|
|
168
172
|
)
|
|
169
173
|
raise typer.Exit(code=1)
|
|
170
|
-
console.print(" Containers
|
|
174
|
+
console.print(" Containers started")
|
|
171
175
|
if not docker_lib.wait_for_backend():
|
|
172
176
|
err_console.print(
|
|
173
177
|
" [red]✗[/] backend-api did not become healthy within 120s. "
|
|
@@ -176,6 +180,14 @@ def run(
|
|
|
176
180
|
raise typer.Exit(code=1)
|
|
177
181
|
console.print(" [green]✓[/] backend-api healthy on :8000")
|
|
178
182
|
|
|
183
|
+
if not skip_docker and not config_lib.api_key():
|
|
184
|
+
try:
|
|
185
|
+
owner = api_client.bootstrap(bootstrap_token, "SpAIder", _default_agent_name())
|
|
186
|
+
config_lib.save(api_key=owner["api_key"])
|
|
187
|
+
console.print(" [green]✓[/] Owner key saved to your SpAIder config")
|
|
188
|
+
except api_client.SpaiderApiError as exc:
|
|
189
|
+
err_console.print(f" [yellow]![/] Could not create the owner: {exc}. Run [bold]spaider login[/].")
|
|
190
|
+
|
|
179
191
|
# 6. Agent + MCP
|
|
180
192
|
resolved_agent = agent_name or _default_agent_name()
|
|
181
193
|
console.print(f"\n[bold][6/6] Provisioning agent '{resolved_agent}'[/]")
|
|
@@ -192,6 +204,7 @@ def run(
|
|
|
192
204
|
err_console.print(f" [red]✗[/] agent provisioning failed: {exc}")
|
|
193
205
|
raise typer.Exit(code=1)
|
|
194
206
|
console.print(f" [green]✓[/] agent ready (id={agent_id})")
|
|
207
|
+
config_lib.save(agent_id=agent_id)
|
|
195
208
|
|
|
196
209
|
if skip_mcp:
|
|
197
210
|
console.print("\n[dim]Skipping MCP install (--skip-mcp).[/]")
|
|
@@ -200,7 +213,7 @@ def run(
|
|
|
200
213
|
|
|
201
214
|
console.print("\n[bold]Installing MCP into Claude Code[/]")
|
|
202
215
|
report = mcp_lib.install_for_claude_code(
|
|
203
|
-
url="http://localhost:8000/api/v1/mcp
|
|
216
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
204
217
|
api_key=agent_key,
|
|
205
218
|
)
|
|
206
219
|
console.print(f" [green]✓[/] {report.config_path}")
|
|
@@ -13,12 +13,16 @@ failure-mode etiquette.
|
|
|
13
13
|
"""
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
|
+
from dataclasses import dataclass
|
|
16
17
|
from pathlib import Path
|
|
18
|
+
from typing import Callable
|
|
17
19
|
|
|
18
20
|
import typer
|
|
19
21
|
from rich.console import Console
|
|
20
22
|
|
|
21
23
|
from spaider_cli.lib import api as api_client
|
|
24
|
+
from spaider_cli.lib import client as http_client
|
|
25
|
+
from spaider_cli.lib import clients as clients_lib
|
|
22
26
|
from spaider_cli.lib import mcp as mcp_lib
|
|
23
27
|
|
|
24
28
|
app = typer.Typer(no_args_is_help=True)
|
|
@@ -26,7 +30,7 @@ console = Console()
|
|
|
26
30
|
err_console = Console(stderr=True)
|
|
27
31
|
|
|
28
32
|
|
|
29
|
-
DEFAULT_MCP_URL = "http://localhost:8000/api/v1/mcp
|
|
33
|
+
DEFAULT_MCP_URL = "http://localhost:8000/api/v1/mcp"
|
|
30
34
|
|
|
31
35
|
|
|
32
36
|
@app.command("install")
|
|
@@ -57,14 +61,14 @@ def install(
|
|
|
57
61
|
client: str = typer.Option(
|
|
58
62
|
"claude-code",
|
|
59
63
|
"--for",
|
|
60
|
-
help="Which MCP client to install for: claude-code (default) or cursor.",
|
|
64
|
+
help="Which MCP client to install for: claude-code (default), opencode, or cursor.",
|
|
61
65
|
),
|
|
62
66
|
scope: str = typer.Option(
|
|
63
67
|
"user",
|
|
64
68
|
"--scope",
|
|
65
69
|
help=(
|
|
66
|
-
"claude-code only. user = global
|
|
67
|
-
"memory in every repo). project = write
|
|
70
|
+
"claude-code / opencode only. user = global config (default; same "
|
|
71
|
+
"agent memory in every repo). project = write into THIS repo so it "
|
|
68
72
|
"uses its own agent memory, overriding the global one."
|
|
69
73
|
),
|
|
70
74
|
),
|
|
@@ -96,37 +100,59 @@ def install(
|
|
|
96
100
|
)
|
|
97
101
|
raise typer.Exit(code=1)
|
|
98
102
|
|
|
99
|
-
# Dispatch
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
err_console.print(
|
|
103
|
-
f"[red]✗[/] unsupported --scope '{scope}'. Supported: user, project."
|
|
104
|
-
)
|
|
105
|
-
raise typer.Exit(code=2)
|
|
106
|
-
report = mcp_lib.install_for_claude_code(
|
|
107
|
-
url=url, api_key=resolved_key, scope=scope, project_root=Path.cwd(),
|
|
108
|
-
)
|
|
109
|
-
_report_claude_code(report=report, agent=resolved_agent, scope=scope)
|
|
110
|
-
elif client == "cursor":
|
|
111
|
-
report = mcp_lib.install_for_cursor(
|
|
112
|
-
project_root=Path.cwd(),
|
|
113
|
-
url=url,
|
|
114
|
-
api_key=resolved_key,
|
|
115
|
-
)
|
|
116
|
-
_report_cursor(report=report, agent=resolved_agent)
|
|
117
|
-
else:
|
|
103
|
+
# Dispatch via the target registry (see _TARGETS at the bottom).
|
|
104
|
+
spec = _TARGETS.get(client)
|
|
105
|
+
if spec is None:
|
|
118
106
|
err_console.print(
|
|
119
107
|
f"[red]✗[/] unsupported --for value '{client}'. "
|
|
120
|
-
"Supported:
|
|
108
|
+
f"Supported: {', '.join(_TARGETS)}."
|
|
109
|
+
)
|
|
110
|
+
raise typer.Exit(code=2)
|
|
111
|
+
if spec.scoped and scope not in ("user", "project"):
|
|
112
|
+
err_console.print(
|
|
113
|
+
f"[red]✗[/] unsupported --scope '{scope}'. Supported: user, project."
|
|
121
114
|
)
|
|
122
115
|
raise typer.Exit(code=2)
|
|
123
116
|
|
|
117
|
+
report = spec.install(
|
|
118
|
+
url=url, api_key=resolved_key, scope=scope, project_root=Path.cwd(),
|
|
119
|
+
)
|
|
120
|
+
spec.report(report=report, agent=resolved_agent, scope=scope)
|
|
121
|
+
|
|
124
122
|
|
|
125
123
|
# ---------------------------------------------------------------------------
|
|
126
124
|
# Helpers
|
|
127
125
|
# ---------------------------------------------------------------------------
|
|
128
126
|
|
|
129
127
|
|
|
128
|
+
@app.command("skill")
|
|
129
|
+
def skill() -> None:
|
|
130
|
+
"""Refresh the Claude Code skill file. Keys and MCP entries are not touched."""
|
|
131
|
+
path = mcp_lib.claude_code_paths().skill_file
|
|
132
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
133
|
+
mcp_lib.backup_if_exists(path)
|
|
134
|
+
mcp_lib.atomic_write_text(path, mcp_lib.read_packaged_skill())
|
|
135
|
+
console.print(f"[green]✓[/] {path}")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@app.command("add")
|
|
139
|
+
def add(
|
|
140
|
+
client: str = typer.Argument(..., help=f"One of: {', '.join(clients_lib.SUPPORTED)}."),
|
|
141
|
+
agent: str | None = typer.Option(None, "--agent", help="Knowledge base id."),
|
|
142
|
+
url: str = typer.Option(DEFAULT_MCP_URL, "--url"),
|
|
143
|
+
) -> None:
|
|
144
|
+
"""Connect one client, with its own key that can be revoked separately."""
|
|
145
|
+
if client not in clients_lib.SUPPORTED:
|
|
146
|
+
console.print(f"[red]✗[/] Unknown client. Choose from: {', '.join(clients_lib.SUPPORTED)}")
|
|
147
|
+
raise typer.Exit(code=1)
|
|
148
|
+
kb = http_client.agent_or_exit(agent)
|
|
149
|
+
account = http_client.request(
|
|
150
|
+
"POST", f"/agents/{kb}/service-accounts", json={"name": f"mcp-{client}", "role": "contributor"}
|
|
151
|
+
)
|
|
152
|
+
path = clients_lib.install(client, url, account["api_key"])
|
|
153
|
+
console.print(f"[green]✓[/] {client} connected ({path})")
|
|
154
|
+
|
|
155
|
+
|
|
130
156
|
def _default_agent_name() -> str:
|
|
131
157
|
"""Return ``dev-${USER}`` (falling back to ``dev-user`` on no $USER)."""
|
|
132
158
|
import os
|
|
@@ -180,7 +206,7 @@ def _report_claude_code(
|
|
|
180
206
|
)
|
|
181
207
|
|
|
182
208
|
|
|
183
|
-
def _report_cursor(*, report: mcp_lib.InstallReport, agent: str) -> None:
|
|
209
|
+
def _report_cursor(*, report: mcp_lib.InstallReport, agent: str, scope: str = "user") -> None:
|
|
184
210
|
console.print()
|
|
185
211
|
console.print("[bold green]✓[/] SpAIder rules installed for Cursor")
|
|
186
212
|
console.print(f" agent : [bold]{agent}[/]")
|
|
@@ -191,3 +217,72 @@ def _report_cursor(*, report: mcp_lib.InstallReport, agent: str) -> None:
|
|
|
191
217
|
console.print(
|
|
192
218
|
"[yellow]Reload the Cursor window[/] so it picks up the updated .cursorrules."
|
|
193
219
|
)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _report_opencode(
|
|
223
|
+
*, report: mcp_lib.InstallReport, agent: str, scope: str = "user",
|
|
224
|
+
) -> None:
|
|
225
|
+
console.print()
|
|
226
|
+
console.print("[bold green]✓[/] SpAIder MCP installed for OpenCode")
|
|
227
|
+
console.print(f" agent : [bold]{agent}[/]")
|
|
228
|
+
console.print(f" scope : [bold]{scope}[/]" + (
|
|
229
|
+
" [dim](this repo only)[/]" if scope == "project" else " [dim](global)[/]"
|
|
230
|
+
))
|
|
231
|
+
console.print(f" config : {report.config_path}")
|
|
232
|
+
if report.config_backup:
|
|
233
|
+
console.print(f" backup of : [dim]{report.config_backup}[/]")
|
|
234
|
+
if report.skill_path:
|
|
235
|
+
console.print(f" guidance : {report.skill_path} [dim](AGENTS.md)[/]")
|
|
236
|
+
if report.skill_backup:
|
|
237
|
+
console.print(f" backup of : [dim]{report.skill_backup}[/]")
|
|
238
|
+
if scope == "project":
|
|
239
|
+
console.print()
|
|
240
|
+
console.print(
|
|
241
|
+
"[yellow]![/] [bold]opencode.json[/] holds a secret Bearer token; add it "
|
|
242
|
+
"to this repo's [bold].gitignore[/] so it is never committed."
|
|
243
|
+
)
|
|
244
|
+
console.print()
|
|
245
|
+
console.print(
|
|
246
|
+
"[yellow]Restart OpenCode[/] so it picks up the new MCP server. "
|
|
247
|
+
"Tip: OpenCode runs on local models too. Point it at an Ollama model "
|
|
248
|
+
"for a fully self-hosted, no-API-key setup."
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
# ---------------------------------------------------------------------------
|
|
253
|
+
# Target registry. Adding an MCP client is one entry here; `scoped` controls
|
|
254
|
+
# whether `--scope user|project` applies; `install` adapts the common kwargs to
|
|
255
|
+
# the target's installer; `report` prints the result.
|
|
256
|
+
# ---------------------------------------------------------------------------
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
@dataclass(frozen=True)
|
|
260
|
+
class _TargetSpec:
|
|
261
|
+
scoped: bool
|
|
262
|
+
install: Callable[..., mcp_lib.InstallReport]
|
|
263
|
+
report: Callable[..., None]
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
_TARGETS: dict[str, _TargetSpec] = {
|
|
267
|
+
"claude-code": _TargetSpec(
|
|
268
|
+
scoped=True,
|
|
269
|
+
install=lambda *, url, api_key, scope, project_root: mcp_lib.install_for_claude_code(
|
|
270
|
+
url=url, api_key=api_key, scope=scope, project_root=project_root,
|
|
271
|
+
),
|
|
272
|
+
report=_report_claude_code,
|
|
273
|
+
),
|
|
274
|
+
"opencode": _TargetSpec(
|
|
275
|
+
scoped=True,
|
|
276
|
+
install=lambda *, url, api_key, scope, project_root: mcp_lib.install_for_opencode(
|
|
277
|
+
url=url, api_key=api_key, scope=scope, project_root=project_root,
|
|
278
|
+
),
|
|
279
|
+
report=_report_opencode,
|
|
280
|
+
),
|
|
281
|
+
"cursor": _TargetSpec(
|
|
282
|
+
scoped=False,
|
|
283
|
+
install=lambda *, url, api_key, scope, project_root: mcp_lib.install_for_cursor(
|
|
284
|
+
project_root=project_root, url=url, api_key=api_key,
|
|
285
|
+
),
|
|
286
|
+
report=_report_cursor,
|
|
287
|
+
),
|
|
288
|
+
}
|