spaider-cli 0.1.0__tar.gz → 0.1.2__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.0 → spaider_cli-0.1.2}/PKG-INFO +4 -4
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/README.md +3 -3
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/pyproject.toml +1 -1
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/__init__.py +9 -1
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/commands/doctor.py +22 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/commands/init.py +1 -1
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/commands/mcp.py +90 -25
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/lib/mcp.py +141 -1
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli.egg-info/PKG-INFO +4 -4
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/tests/test_mcp.py +94 -11
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/LICENSE +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/setup.cfg +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/commands/__init__.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/commands/agent.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/lib/__init__.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/lib/api.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/lib/docker.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/lib/env.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/lib/llm.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/main.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/skills/__init__.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli/skills/claude_code.md +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli.egg-info/SOURCES.txt +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli.egg-info/dependency_links.txt +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli.egg-info/entry_points.txt +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli.egg-info/requires.txt +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/src/spaider_cli.egg-info/top_level.txt +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/tests/test_agent.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/tests/test_doctor.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/tests/test_env.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/tests/test_init.py +0 -0
- {spaider_cli-0.1.0 → spaider_cli-0.1.2}/tests/test_smoke.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: spaider-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
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
|
|
|
@@ -11,4 +11,12 @@ Implementation lives in ``spaider_cli.commands``; this module only re-exports
|
|
|
11
11
|
the entry-point app so ``[project.scripts]`` resolution stays simple.
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# Single source of truth is pyproject.toml; read it back from the installed
|
|
15
|
+
# package metadata so `spaider --version` can never drift from the wheel.
|
|
16
|
+
from importlib.metadata import PackageNotFoundError
|
|
17
|
+
from importlib.metadata import version as _pkg_version
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
__version__ = _pkg_version("spaider-cli")
|
|
21
|
+
except PackageNotFoundError: # running from a source tree without an install
|
|
22
|
+
__version__ = "0.0.0+source"
|
|
@@ -181,6 +181,27 @@ def check_skill_file(home: Path | None = None) -> CheckResult:
|
|
|
181
181
|
return _ok("~/.claude/skills/spaider.md", "loaded by Claude Code at session start")
|
|
182
182
|
|
|
183
183
|
|
|
184
|
+
def check_opencode_config(home: Path | None = None) -> CheckResult:
|
|
185
|
+
"""OpenCode is an optional target; absent is fine, not a warning."""
|
|
186
|
+
home = home or Path.home()
|
|
187
|
+
path = home / ".config" / "opencode" / "opencode.json"
|
|
188
|
+
if not path.exists():
|
|
189
|
+
return _ok(
|
|
190
|
+
"~/.config/opencode/opencode.json",
|
|
191
|
+
"not configured (optional; `spaider mcp install --for opencode` to add)",
|
|
192
|
+
)
|
|
193
|
+
try:
|
|
194
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
195
|
+
except json.JSONDecodeError as exc:
|
|
196
|
+
return _fail("~/.config/opencode/opencode.json", f"malformed JSON: {exc}")
|
|
197
|
+
if "spaider" not in (data.get("mcp") or {}):
|
|
198
|
+
return _warn(
|
|
199
|
+
"~/.config/opencode/opencode.json",
|
|
200
|
+
"exists but has no SpAIder entry. Run `spaider mcp install --for opencode`.",
|
|
201
|
+
)
|
|
202
|
+
return _ok("~/.config/opencode/opencode.json", "SpAIder entry present")
|
|
203
|
+
|
|
204
|
+
|
|
184
205
|
# ---------------------------------------------------------------------------
|
|
185
206
|
# Entry point
|
|
186
207
|
# ---------------------------------------------------------------------------
|
|
@@ -205,6 +226,7 @@ def run(
|
|
|
205
226
|
results.append(check_embedding_dimensions())
|
|
206
227
|
results.append(check_mcp_config())
|
|
207
228
|
results.append(check_skill_file())
|
|
229
|
+
results.append(check_opencode_config())
|
|
208
230
|
|
|
209
231
|
table = Table(title="SpAIder doctor", header_style="bold cyan")
|
|
210
232
|
table.add_column("Check")
|
|
@@ -200,7 +200,7 @@ def run(
|
|
|
200
200
|
|
|
201
201
|
console.print("\n[bold]Installing MCP into Claude Code[/]")
|
|
202
202
|
report = mcp_lib.install_for_claude_code(
|
|
203
|
-
url="http://localhost:8000/api/v1/mcp
|
|
203
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
204
204
|
api_key=agent_key,
|
|
205
205
|
)
|
|
206
206
|
console.print(f" [green]✓[/] {report.config_path}")
|
|
@@ -13,7 +13,9 @@ 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
|
|
@@ -26,7 +28,7 @@ console = Console()
|
|
|
26
28
|
err_console = Console(stderr=True)
|
|
27
29
|
|
|
28
30
|
|
|
29
|
-
DEFAULT_MCP_URL = "http://localhost:8000/api/v1/mcp
|
|
31
|
+
DEFAULT_MCP_URL = "http://localhost:8000/api/v1/mcp"
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
@app.command("install")
|
|
@@ -57,14 +59,14 @@ def install(
|
|
|
57
59
|
client: str = typer.Option(
|
|
58
60
|
"claude-code",
|
|
59
61
|
"--for",
|
|
60
|
-
help="Which MCP client to install for: claude-code (default) or cursor.",
|
|
62
|
+
help="Which MCP client to install for: claude-code (default), opencode, or cursor.",
|
|
61
63
|
),
|
|
62
64
|
scope: str = typer.Option(
|
|
63
65
|
"user",
|
|
64
66
|
"--scope",
|
|
65
67
|
help=(
|
|
66
|
-
"claude-code only. user = global
|
|
67
|
-
"memory in every repo). project = write
|
|
68
|
+
"claude-code / opencode only. user = global config (default; same "
|
|
69
|
+
"agent memory in every repo). project = write into THIS repo so it "
|
|
68
70
|
"uses its own agent memory, overriding the global one."
|
|
69
71
|
),
|
|
70
72
|
),
|
|
@@ -96,31 +98,25 @@ def install(
|
|
|
96
98
|
)
|
|
97
99
|
raise typer.Exit(code=1)
|
|
98
100
|
|
|
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:
|
|
101
|
+
# Dispatch via the target registry (see _TARGETS at the bottom).
|
|
102
|
+
spec = _TARGETS.get(client)
|
|
103
|
+
if spec is None:
|
|
118
104
|
err_console.print(
|
|
119
105
|
f"[red]✗[/] unsupported --for value '{client}'. "
|
|
120
|
-
"Supported:
|
|
106
|
+
f"Supported: {', '.join(_TARGETS)}."
|
|
107
|
+
)
|
|
108
|
+
raise typer.Exit(code=2)
|
|
109
|
+
if spec.scoped and scope not in ("user", "project"):
|
|
110
|
+
err_console.print(
|
|
111
|
+
f"[red]✗[/] unsupported --scope '{scope}'. Supported: user, project."
|
|
121
112
|
)
|
|
122
113
|
raise typer.Exit(code=2)
|
|
123
114
|
|
|
115
|
+
report = spec.install(
|
|
116
|
+
url=url, api_key=resolved_key, scope=scope, project_root=Path.cwd(),
|
|
117
|
+
)
|
|
118
|
+
spec.report(report=report, agent=resolved_agent, scope=scope)
|
|
119
|
+
|
|
124
120
|
|
|
125
121
|
# ---------------------------------------------------------------------------
|
|
126
122
|
# Helpers
|
|
@@ -180,7 +176,7 @@ def _report_claude_code(
|
|
|
180
176
|
)
|
|
181
177
|
|
|
182
178
|
|
|
183
|
-
def _report_cursor(*, report: mcp_lib.InstallReport, agent: str) -> None:
|
|
179
|
+
def _report_cursor(*, report: mcp_lib.InstallReport, agent: str, scope: str = "user") -> None:
|
|
184
180
|
console.print()
|
|
185
181
|
console.print("[bold green]✓[/] SpAIder rules installed for Cursor")
|
|
186
182
|
console.print(f" agent : [bold]{agent}[/]")
|
|
@@ -191,3 +187,72 @@ def _report_cursor(*, report: mcp_lib.InstallReport, agent: str) -> None:
|
|
|
191
187
|
console.print(
|
|
192
188
|
"[yellow]Reload the Cursor window[/] so it picks up the updated .cursorrules."
|
|
193
189
|
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _report_opencode(
|
|
193
|
+
*, report: mcp_lib.InstallReport, agent: str, scope: str = "user",
|
|
194
|
+
) -> None:
|
|
195
|
+
console.print()
|
|
196
|
+
console.print("[bold green]✓[/] SpAIder MCP installed for OpenCode")
|
|
197
|
+
console.print(f" agent : [bold]{agent}[/]")
|
|
198
|
+
console.print(f" scope : [bold]{scope}[/]" + (
|
|
199
|
+
" [dim](this repo only)[/]" if scope == "project" else " [dim](global)[/]"
|
|
200
|
+
))
|
|
201
|
+
console.print(f" config : {report.config_path}")
|
|
202
|
+
if report.config_backup:
|
|
203
|
+
console.print(f" backup of : [dim]{report.config_backup}[/]")
|
|
204
|
+
if report.skill_path:
|
|
205
|
+
console.print(f" guidance : {report.skill_path} [dim](AGENTS.md)[/]")
|
|
206
|
+
if report.skill_backup:
|
|
207
|
+
console.print(f" backup of : [dim]{report.skill_backup}[/]")
|
|
208
|
+
if scope == "project":
|
|
209
|
+
console.print()
|
|
210
|
+
console.print(
|
|
211
|
+
"[yellow]![/] [bold]opencode.json[/] holds a secret Bearer token; add it "
|
|
212
|
+
"to this repo's [bold].gitignore[/] so it is never committed."
|
|
213
|
+
)
|
|
214
|
+
console.print()
|
|
215
|
+
console.print(
|
|
216
|
+
"[yellow]Restart OpenCode[/] so it picks up the new MCP server. "
|
|
217
|
+
"Tip: OpenCode runs on local models too. Point it at an Ollama model "
|
|
218
|
+
"for a fully self-hosted, no-API-key setup."
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# ---------------------------------------------------------------------------
|
|
223
|
+
# Target registry. Adding an MCP client is one entry here; `scoped` controls
|
|
224
|
+
# whether `--scope user|project` applies; `install` adapts the common kwargs to
|
|
225
|
+
# the target's installer; `report` prints the result.
|
|
226
|
+
# ---------------------------------------------------------------------------
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@dataclass(frozen=True)
|
|
230
|
+
class _TargetSpec:
|
|
231
|
+
scoped: bool
|
|
232
|
+
install: Callable[..., mcp_lib.InstallReport]
|
|
233
|
+
report: Callable[..., None]
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
_TARGETS: dict[str, _TargetSpec] = {
|
|
237
|
+
"claude-code": _TargetSpec(
|
|
238
|
+
scoped=True,
|
|
239
|
+
install=lambda *, url, api_key, scope, project_root: mcp_lib.install_for_claude_code(
|
|
240
|
+
url=url, api_key=api_key, scope=scope, project_root=project_root,
|
|
241
|
+
),
|
|
242
|
+
report=_report_claude_code,
|
|
243
|
+
),
|
|
244
|
+
"opencode": _TargetSpec(
|
|
245
|
+
scoped=True,
|
|
246
|
+
install=lambda *, url, api_key, scope, project_root: mcp_lib.install_for_opencode(
|
|
247
|
+
url=url, api_key=api_key, scope=scope, project_root=project_root,
|
|
248
|
+
),
|
|
249
|
+
report=_report_opencode,
|
|
250
|
+
),
|
|
251
|
+
"cursor": _TargetSpec(
|
|
252
|
+
scoped=False,
|
|
253
|
+
install=lambda *, url, api_key, scope, project_root: mcp_lib.install_for_cursor(
|
|
254
|
+
project_root=project_root, url=url, api_key=api_key,
|
|
255
|
+
),
|
|
256
|
+
report=_report_cursor,
|
|
257
|
+
),
|
|
258
|
+
}
|
|
@@ -65,6 +65,36 @@ def claude_code_paths(
|
|
|
65
65
|
)
|
|
66
66
|
|
|
67
67
|
|
|
68
|
+
def opencode_paths(
|
|
69
|
+
*,
|
|
70
|
+
scope: str = "user",
|
|
71
|
+
home: Path | None = None,
|
|
72
|
+
project_root: Path | None = None,
|
|
73
|
+
) -> ClientPaths:
|
|
74
|
+
"""Paths for OpenCode.
|
|
75
|
+
|
|
76
|
+
OpenCode reads MCP servers from ``opencode.json``: globally at
|
|
77
|
+
``~/.config/opencode/opencode.json`` (``scope="user"``, default) or
|
|
78
|
+
per-project at ``<root>/opencode.json`` (``scope="project"``). Agent
|
|
79
|
+
guidance goes in ``AGENTS.md`` (the project root for project scope, the
|
|
80
|
+
global config dir otherwise).
|
|
81
|
+
"""
|
|
82
|
+
if scope == "project":
|
|
83
|
+
root = project_root or Path.cwd()
|
|
84
|
+
return ClientPaths(
|
|
85
|
+
name="opencode",
|
|
86
|
+
mcp_config=root / "opencode.json",
|
|
87
|
+
skill_file=root / "AGENTS.md",
|
|
88
|
+
)
|
|
89
|
+
home = home or Path.home()
|
|
90
|
+
cfg_dir = home / ".config" / "opencode"
|
|
91
|
+
return ClientPaths(
|
|
92
|
+
name="opencode",
|
|
93
|
+
mcp_config=cfg_dir / "opencode.json",
|
|
94
|
+
skill_file=cfg_dir / "AGENTS.md",
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
68
98
|
def cursor_paths(project_root: Path) -> ClientPaths:
|
|
69
99
|
"""Paths for Cursor (per-project ``.cursorrules``).
|
|
70
100
|
|
|
@@ -96,8 +126,13 @@ def read_packaged_skill(filename: str = "claude_code.md") -> str:
|
|
|
96
126
|
|
|
97
127
|
|
|
98
128
|
def _spaider_server_entry(url: str, api_key: str) -> dict[str, Any]:
|
|
99
|
-
"""The mcpServers block that we add for SpAIder.
|
|
129
|
+
"""The mcpServers block that we add for SpAIder.
|
|
130
|
+
|
|
131
|
+
``type: "http"`` selects the Streamable HTTP transport, the modern MCP
|
|
132
|
+
transport SpAIder's backend serves at ``/api/v1/mcp``.
|
|
133
|
+
"""
|
|
100
134
|
return {
|
|
135
|
+
"type": "http",
|
|
101
136
|
"url": url,
|
|
102
137
|
"headers": {"Authorization": f"Bearer {api_key}"},
|
|
103
138
|
}
|
|
@@ -122,6 +157,36 @@ def merge_mcp_server(
|
|
|
122
157
|
return merged
|
|
123
158
|
|
|
124
159
|
|
|
160
|
+
def _opencode_server_entry(url: str, api_key: str) -> dict[str, Any]:
|
|
161
|
+
"""The ``opencode.json`` ``mcp.<name>`` block for SpAIder.
|
|
162
|
+
|
|
163
|
+
OpenCode uses ``type: "remote"`` for HTTP/Streamable-HTTP MCP servers
|
|
164
|
+
(vs ``"local"`` stdio servers); ``enabled: true`` registers it.
|
|
165
|
+
"""
|
|
166
|
+
return {
|
|
167
|
+
"type": "remote",
|
|
168
|
+
"url": url,
|
|
169
|
+
"enabled": True,
|
|
170
|
+
"headers": {"Authorization": f"Bearer {api_key}"},
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def merge_opencode_server(
|
|
175
|
+
existing: dict[str, Any] | None,
|
|
176
|
+
*,
|
|
177
|
+
server_name: str = "spaider",
|
|
178
|
+
url: str,
|
|
179
|
+
api_key: str,
|
|
180
|
+
) -> dict[str, Any]:
|
|
181
|
+
"""Merge the SpAIder entry into an ``opencode.json`` dict (top-level ``mcp``
|
|
182
|
+
key), preserving every other server and unrelated keys. Pure function."""
|
|
183
|
+
merged: dict[str, Any] = dict(existing or {})
|
|
184
|
+
servers = dict(merged.get("mcp") or {})
|
|
185
|
+
servers[server_name] = _opencode_server_entry(url=url, api_key=api_key)
|
|
186
|
+
merged["mcp"] = servers
|
|
187
|
+
return merged
|
|
188
|
+
|
|
189
|
+
|
|
125
190
|
# ---------------------------------------------------------------------------
|
|
126
191
|
# Atomic write + backup
|
|
127
192
|
# ---------------------------------------------------------------------------
|
|
@@ -283,3 +348,78 @@ def install_for_cursor(
|
|
|
283
348
|
skill_path=None,
|
|
284
349
|
skill_backup=None,
|
|
285
350
|
)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
# ---------------------------------------------------------------------------
|
|
354
|
+
# OpenCode
|
|
355
|
+
# ---------------------------------------------------------------------------
|
|
356
|
+
|
|
357
|
+
_SPAIDER_BLOCK_START = "<!-- spaider:start (managed by `spaider mcp install`) -->"
|
|
358
|
+
_SPAIDER_BLOCK_END = "<!-- spaider:end -->"
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def upsert_marked_block(path: Path, inner: str) -> Path | None:
|
|
362
|
+
"""Idempotently write a SpAIder-delimited block into a markdown file.
|
|
363
|
+
|
|
364
|
+
Missing file → create with just the block. Existing file with our markers →
|
|
365
|
+
replace what's between them (preserving the user's surrounding content).
|
|
366
|
+
Existing file without markers → append. Returns the backup path (or None).
|
|
367
|
+
"""
|
|
368
|
+
block = f"{_SPAIDER_BLOCK_START}\n{inner.rstrip()}\n{_SPAIDER_BLOCK_END}\n"
|
|
369
|
+
if not path.exists():
|
|
370
|
+
atomic_write_text(path, block)
|
|
371
|
+
return None
|
|
372
|
+
existing = path.read_text(encoding="utf-8")
|
|
373
|
+
backup = backup_if_exists(path)
|
|
374
|
+
if _SPAIDER_BLOCK_START in existing and _SPAIDER_BLOCK_END in existing:
|
|
375
|
+
pre = existing.split(_SPAIDER_BLOCK_START, 1)[0].rstrip()
|
|
376
|
+
post = existing.split(_SPAIDER_BLOCK_END, 1)[1].lstrip("\n")
|
|
377
|
+
new = block
|
|
378
|
+
if pre:
|
|
379
|
+
new = pre + "\n\n" + new
|
|
380
|
+
if post.strip():
|
|
381
|
+
new = new + "\n" + post
|
|
382
|
+
else:
|
|
383
|
+
new = existing.rstrip() + "\n\n" + block
|
|
384
|
+
atomic_write_text(path, new)
|
|
385
|
+
return backup
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def install_for_opencode(
|
|
389
|
+
*,
|
|
390
|
+
url: str,
|
|
391
|
+
api_key: str,
|
|
392
|
+
scope: str = "user",
|
|
393
|
+
home: Path | None = None,
|
|
394
|
+
project_root: Path | None = None,
|
|
395
|
+
) -> InstallReport:
|
|
396
|
+
"""Idempotently install SpAIder into OpenCode.
|
|
397
|
+
|
|
398
|
+
Writes two things (see :func:`opencode_paths`):
|
|
399
|
+
1. An ``mcp.spaider`` entry in ``opencode.json`` (Streamable HTTP, Bearer
|
|
400
|
+
auth), non-destructively merged so other servers survive.
|
|
401
|
+
2. A SpAIder guidance block in ``AGENTS.md``, delimited by stable markers so
|
|
402
|
+
re-running replaces it in place rather than duplicating.
|
|
403
|
+
"""
|
|
404
|
+
paths = opencode_paths(scope=scope, home=home, project_root=project_root)
|
|
405
|
+
|
|
406
|
+
existing = read_mcp_config(paths.mcp_config)
|
|
407
|
+
merged = merge_opencode_server(existing, url=url, api_key=api_key)
|
|
408
|
+
config_backup = backup_if_exists(paths.mcp_config)
|
|
409
|
+
atomic_write_json(paths.mcp_config, merged)
|
|
410
|
+
|
|
411
|
+
assert paths.skill_file is not None # opencode always has an AGENTS.md slot
|
|
412
|
+
guidance = (
|
|
413
|
+
"# SpAIder memory\n\n"
|
|
414
|
+
"SpAIder is wired in as the `spaider` MCP server. Use its tools for "
|
|
415
|
+
"durable, queryable memory across sessions.\n\n"
|
|
416
|
+
+ read_packaged_skill("claude_code.md").rstrip()
|
|
417
|
+
)
|
|
418
|
+
skill_backup = upsert_marked_block(paths.skill_file, guidance)
|
|
419
|
+
|
|
420
|
+
return InstallReport(
|
|
421
|
+
config_path=paths.mcp_config,
|
|
422
|
+
config_backup=config_backup,
|
|
423
|
+
skill_path=paths.skill_file,
|
|
424
|
+
skill_backup=skill_backup,
|
|
425
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: spaider-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
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
|
|
|
@@ -28,12 +28,14 @@ class TestMergeMcpServer:
|
|
|
28
28
|
def test_empty_existing_creates_servers_block(self):
|
|
29
29
|
merged = mcp_lib.merge_mcp_server(
|
|
30
30
|
existing={},
|
|
31
|
-
url="http://localhost:8000/api/v1/mcp
|
|
31
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
32
32
|
api_key="sk-test",
|
|
33
33
|
)
|
|
34
34
|
assert "mcpServers" in merged
|
|
35
35
|
assert "spaider" in merged["mcpServers"]
|
|
36
|
-
assert merged["mcpServers"]["spaider"]["url"].endswith("/mcp
|
|
36
|
+
assert merged["mcpServers"]["spaider"]["url"].endswith("/mcp")
|
|
37
|
+
# Streamable HTTP transport: Claude Code reads `type: "http"`.
|
|
38
|
+
assert merged["mcpServers"]["spaider"]["type"] == "http"
|
|
37
39
|
assert merged["mcpServers"]["spaider"]["headers"]["Authorization"] == "Bearer sk-test"
|
|
38
40
|
|
|
39
41
|
def test_preserves_other_servers(self):
|
|
@@ -45,7 +47,7 @@ class TestMergeMcpServer:
|
|
|
45
47
|
}
|
|
46
48
|
merged = mcp_lib.merge_mcp_server(
|
|
47
49
|
existing=existing,
|
|
48
|
-
url="http://localhost:8000/api/v1/mcp
|
|
50
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
49
51
|
api_key="sk-test",
|
|
50
52
|
)
|
|
51
53
|
assert set(merged["mcpServers"]) == {"filesystem", "github", "spaider"}
|
|
@@ -54,17 +56,17 @@ class TestMergeMcpServer:
|
|
|
54
56
|
existing = {"mcpServers": {"spaider": {"url": "stale", "headers": {}}}}
|
|
55
57
|
merged = mcp_lib.merge_mcp_server(
|
|
56
58
|
existing=existing,
|
|
57
|
-
url="http://localhost:8000/api/v1/mcp
|
|
59
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
58
60
|
api_key="sk-new",
|
|
59
61
|
)
|
|
60
|
-
assert merged["mcpServers"]["spaider"]["url"].endswith("/mcp
|
|
62
|
+
assert merged["mcpServers"]["spaider"]["url"].endswith("/mcp")
|
|
61
63
|
assert merged["mcpServers"]["spaider"]["headers"]["Authorization"] == "Bearer sk-new"
|
|
62
64
|
|
|
63
65
|
def test_preserves_top_level_keys(self):
|
|
64
66
|
existing = {"someUnrelatedKey": True, "mcpServers": {}}
|
|
65
67
|
merged = mcp_lib.merge_mcp_server(
|
|
66
68
|
existing=existing,
|
|
67
|
-
url="http://localhost:8000/api/v1/mcp
|
|
69
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
68
70
|
api_key="sk-test",
|
|
69
71
|
)
|
|
70
72
|
assert merged["someUnrelatedKey"] is True
|
|
@@ -119,7 +121,7 @@ class TestReadMcpConfig:
|
|
|
119
121
|
class TestInstallForClaudeCode:
|
|
120
122
|
def test_fresh_install_creates_files(self, tmp_path: Path):
|
|
121
123
|
report = mcp_lib.install_for_claude_code(
|
|
122
|
-
url="http://localhost:8000/api/v1/mcp
|
|
124
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
123
125
|
api_key="sk-fresh",
|
|
124
126
|
home=tmp_path,
|
|
125
127
|
)
|
|
@@ -143,7 +145,7 @@ class TestInstallForClaudeCode:
|
|
|
143
145
|
skill.write_text("OLD SKILL CONTENT")
|
|
144
146
|
|
|
145
147
|
report = mcp_lib.install_for_claude_code(
|
|
146
|
-
url="http://localhost:8000/api/v1/mcp
|
|
148
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
147
149
|
api_key="sk-second",
|
|
148
150
|
home=tmp_path,
|
|
149
151
|
)
|
|
@@ -172,7 +174,7 @@ class TestClaudeCodeScope:
|
|
|
172
174
|
|
|
173
175
|
def test_install_project_scope_writes_repo_files(self, tmp_path: Path):
|
|
174
176
|
report = mcp_lib.install_for_claude_code(
|
|
175
|
-
url="http://localhost:8000/api/v1/mcp
|
|
177
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
176
178
|
api_key="sk-proj",
|
|
177
179
|
scope="project",
|
|
178
180
|
project_root=tmp_path,
|
|
@@ -195,7 +197,7 @@ class TestInstallForCursor:
|
|
|
195
197
|
def test_fresh_install_writes_cursorrules(self, tmp_path: Path):
|
|
196
198
|
report = mcp_lib.install_for_cursor(
|
|
197
199
|
project_root=tmp_path,
|
|
198
|
-
url="http://localhost:8000/api/v1/mcp
|
|
200
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
199
201
|
api_key="sk-cursor",
|
|
200
202
|
)
|
|
201
203
|
assert report.config_backup is None
|
|
@@ -209,7 +211,7 @@ class TestInstallForCursor:
|
|
|
209
211
|
|
|
210
212
|
report = mcp_lib.install_for_cursor(
|
|
211
213
|
project_root=tmp_path,
|
|
212
|
-
url="http://localhost:8000/api/v1/mcp
|
|
214
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
213
215
|
api_key="sk-cursor",
|
|
214
216
|
)
|
|
215
217
|
content = report.config_path.read_text()
|
|
@@ -219,6 +221,74 @@ class TestInstallForCursor:
|
|
|
219
221
|
assert report.config_backup is not None # backup created
|
|
220
222
|
|
|
221
223
|
|
|
224
|
+
# ---------------------------------------------------------------------------
|
|
225
|
+
# install_for_opencode orchestration
|
|
226
|
+
# ---------------------------------------------------------------------------
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
class TestInstallForOpencode:
|
|
230
|
+
def test_fresh_install_writes_opencode_json_and_agents(self, tmp_path: Path):
|
|
231
|
+
report = mcp_lib.install_for_opencode(
|
|
232
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
233
|
+
api_key="sk-oc",
|
|
234
|
+
home=tmp_path,
|
|
235
|
+
)
|
|
236
|
+
# opencode.json under the global config dir, with a remote mcp entry.
|
|
237
|
+
assert report.config_path == tmp_path / ".config" / "opencode" / "opencode.json"
|
|
238
|
+
data = json.loads(report.config_path.read_text())
|
|
239
|
+
entry = data["mcp"]["spaider"]
|
|
240
|
+
assert entry["type"] == "remote"
|
|
241
|
+
assert entry["enabled"] is True
|
|
242
|
+
assert entry["url"].endswith("/mcp")
|
|
243
|
+
assert entry["headers"]["Authorization"] == "Bearer sk-oc"
|
|
244
|
+
# AGENTS.md carries the guidance block.
|
|
245
|
+
assert report.skill_path == tmp_path / ".config" / "opencode" / "AGENTS.md"
|
|
246
|
+
agents = report.skill_path.read_text()
|
|
247
|
+
assert "spaider.query" in agents
|
|
248
|
+
assert "spaider:start" in agents # managed-block marker
|
|
249
|
+
|
|
250
|
+
def test_preserves_other_servers_and_user_agents_content(self, tmp_path: Path):
|
|
251
|
+
cfg_dir = tmp_path / ".config" / "opencode"
|
|
252
|
+
cfg_dir.mkdir(parents=True)
|
|
253
|
+
(cfg_dir / "opencode.json").write_text(
|
|
254
|
+
json.dumps({"mcp": {"other": {"type": "local", "command": ["x"]}}})
|
|
255
|
+
)
|
|
256
|
+
(cfg_dir / "AGENTS.md").write_text("# My project rules\nuse tabs\n")
|
|
257
|
+
|
|
258
|
+
report = mcp_lib.install_for_opencode(
|
|
259
|
+
url="http://localhost:8000/api/v1/mcp", api_key="sk-oc2", home=tmp_path,
|
|
260
|
+
)
|
|
261
|
+
data = json.loads(report.config_path.read_text())
|
|
262
|
+
assert set(data["mcp"]) == {"other", "spaider"} # other server preserved
|
|
263
|
+
agents = report.skill_path.read_text()
|
|
264
|
+
assert "My project rules" in agents # user content preserved
|
|
265
|
+
assert "use tabs" in agents
|
|
266
|
+
assert "spaider.query" in agents
|
|
267
|
+
assert report.config_backup is not None
|
|
268
|
+
|
|
269
|
+
def test_reinstall_is_idempotent_single_block(self, tmp_path: Path):
|
|
270
|
+
for _ in range(2):
|
|
271
|
+
report = mcp_lib.install_for_opencode(
|
|
272
|
+
url="http://localhost:8000/api/v1/mcp", api_key="sk-oc", home=tmp_path,
|
|
273
|
+
)
|
|
274
|
+
agents = report.skill_path.read_text()
|
|
275
|
+
# The managed block must appear exactly once, not duplicated per run.
|
|
276
|
+
assert agents.count("spaider:start") == 1
|
|
277
|
+
# And exactly one spaider server entry.
|
|
278
|
+
data = json.loads(report.config_path.read_text())
|
|
279
|
+
assert list(data["mcp"]) == ["spaider"]
|
|
280
|
+
|
|
281
|
+
def test_project_scope_writes_repo_root_files(self, tmp_path: Path):
|
|
282
|
+
report = mcp_lib.install_for_opencode(
|
|
283
|
+
url="http://localhost:8000/api/v1/mcp",
|
|
284
|
+
api_key="sk-ocp",
|
|
285
|
+
scope="project",
|
|
286
|
+
project_root=tmp_path,
|
|
287
|
+
)
|
|
288
|
+
assert report.config_path == tmp_path / "opencode.json"
|
|
289
|
+
assert report.skill_path == tmp_path / "AGENTS.md"
|
|
290
|
+
|
|
291
|
+
|
|
222
292
|
# ---------------------------------------------------------------------------
|
|
223
293
|
# CLI integration — `spaider mcp install`
|
|
224
294
|
# ---------------------------------------------------------------------------
|
|
@@ -267,6 +337,19 @@ class TestMcpInstallCommand:
|
|
|
267
337
|
assert result.exit_code == 1
|
|
268
338
|
assert "connection refused" in result.output or "could not resolve" in result.output
|
|
269
339
|
|
|
340
|
+
def test_install_for_opencode_writes_config(self, tmp_path: Path, monkeypatch):
|
|
341
|
+
monkeypatch.setenv("HOME", str(tmp_path))
|
|
342
|
+
result = runner.invoke(
|
|
343
|
+
app,
|
|
344
|
+
["mcp", "install", "--api-key", "sk-oc", "--for", "opencode"],
|
|
345
|
+
)
|
|
346
|
+
assert result.exit_code == 0, result.output
|
|
347
|
+
cfg = tmp_path / ".config" / "opencode" / "opencode.json"
|
|
348
|
+
data = json.loads(cfg.read_text())
|
|
349
|
+
assert data["mcp"]["spaider"]["headers"]["Authorization"] == "Bearer sk-oc"
|
|
350
|
+
assert data["mcp"]["spaider"]["type"] == "remote"
|
|
351
|
+
assert "OpenCode" in result.output
|
|
352
|
+
|
|
270
353
|
def test_install_for_unsupported_client_fails(self, tmp_path: Path, monkeypatch):
|
|
271
354
|
monkeypatch.setenv("HOME", str(tmp_path))
|
|
272
355
|
result = runner.invoke(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|