spaider-cli 0.1.0__py3-none-any.whl
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/__init__.py +14 -0
- spaider_cli/commands/__init__.py +6 -0
- spaider_cli/commands/agent.py +178 -0
- spaider_cli/commands/doctor.py +231 -0
- spaider_cli/commands/init.py +405 -0
- spaider_cli/commands/mcp.py +193 -0
- spaider_cli/lib/__init__.py +10 -0
- spaider_cli/lib/api.py +160 -0
- spaider_cli/lib/docker.py +117 -0
- spaider_cli/lib/env.py +135 -0
- spaider_cli/lib/llm.py +87 -0
- spaider_cli/lib/mcp.py +285 -0
- spaider_cli/main.py +71 -0
- spaider_cli/skills/__init__.py +8 -0
- spaider_cli/skills/claude_code.md +151 -0
- spaider_cli-0.1.0.dist-info/METADATA +121 -0
- spaider_cli-0.1.0.dist-info/RECORD +21 -0
- spaider_cli-0.1.0.dist-info/WHEEL +5 -0
- spaider_cli-0.1.0.dist-info/entry_points.txt +2 -0
- spaider_cli-0.1.0.dist-info/licenses/LICENSE +201 -0
- spaider_cli-0.1.0.dist-info/top_level.txt +1 -0
spaider_cli/lib/mcp.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"""MCP client config + skill file management for ``spaider mcp install``.
|
|
2
|
+
|
|
3
|
+
Writes two things side-by-side for the chosen client:
|
|
4
|
+
|
|
5
|
+
1. The MCP server config (e.g. ``~/.claude/.mcp.json``) — non-destructive
|
|
6
|
+
merge that preserves any other servers the user already has.
|
|
7
|
+
2. The skill file (e.g. ``~/.claude/skills/spaider.md``) — the agent-side
|
|
8
|
+
instruction set lifted from this package's ``skills/claude_code.md``.
|
|
9
|
+
|
|
10
|
+
Both writes are atomic (temp file + rename) and any pre-existing file is
|
|
11
|
+
backed up with a timestamp suffix so the user can recover.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import importlib.resources
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import shutil
|
|
19
|
+
import tempfile
|
|
20
|
+
from dataclasses import dataclass
|
|
21
|
+
from datetime import datetime, timezone
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
# ---------------------------------------------------------------------------
|
|
26
|
+
# Client config locations
|
|
27
|
+
# ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class ClientPaths:
|
|
32
|
+
"""Resolved filesystem locations for one MCP client install."""
|
|
33
|
+
|
|
34
|
+
name: str
|
|
35
|
+
mcp_config: Path
|
|
36
|
+
skill_file: Path | None # None means no skill-file slot for this client
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def claude_code_paths(
|
|
40
|
+
*,
|
|
41
|
+
scope: str = "user",
|
|
42
|
+
home: Path | None = None,
|
|
43
|
+
project_root: Path | None = None,
|
|
44
|
+
) -> ClientPaths:
|
|
45
|
+
"""Paths for the Claude Code MCP client.
|
|
46
|
+
|
|
47
|
+
``scope="user"`` (default) targets the global ``~/.claude`` config that
|
|
48
|
+
every project sees — one agent memory everywhere. ``scope="project"``
|
|
49
|
+
targets the current repo so it can use its own agent memory, overriding the
|
|
50
|
+
global one: ``<root>/.mcp.json`` plus a project-level skill at
|
|
51
|
+
``<root>/.claude/skills/spaider.md``.
|
|
52
|
+
"""
|
|
53
|
+
if scope == "project":
|
|
54
|
+
root = project_root or Path.cwd()
|
|
55
|
+
return ClientPaths(
|
|
56
|
+
name="claude-code",
|
|
57
|
+
mcp_config=root / ".mcp.json",
|
|
58
|
+
skill_file=root / ".claude" / "skills" / "spaider.md",
|
|
59
|
+
)
|
|
60
|
+
home = home or Path.home()
|
|
61
|
+
return ClientPaths(
|
|
62
|
+
name="claude-code",
|
|
63
|
+
mcp_config=home / ".claude" / ".mcp.json",
|
|
64
|
+
skill_file=home / ".claude" / "skills" / "spaider.md",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def cursor_paths(project_root: Path) -> ClientPaths:
|
|
69
|
+
"""Paths for Cursor (per-project ``.cursorrules``).
|
|
70
|
+
|
|
71
|
+
Cursor's MCP support is project-scoped via ``.cursorrules``; we treat that
|
|
72
|
+
file as both the "config" surface and the "skill" surface — they're not
|
|
73
|
+
separate concepts in Cursor's mental model.
|
|
74
|
+
"""
|
|
75
|
+
return ClientPaths(
|
|
76
|
+
name="cursor",
|
|
77
|
+
mcp_config=project_root / ".cursorrules",
|
|
78
|
+
skill_file=None, # the same file carries the rules; no second file
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# ---------------------------------------------------------------------------
|
|
83
|
+
# Skill content
|
|
84
|
+
# ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def read_packaged_skill(filename: str = "claude_code.md") -> str:
|
|
88
|
+
"""Load a skill file shipped inside the wheel as package data."""
|
|
89
|
+
skill = importlib.resources.files("spaider_cli.skills").joinpath(filename)
|
|
90
|
+
return skill.read_text(encoding="utf-8")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# ---------------------------------------------------------------------------
|
|
94
|
+
# MCP config merge
|
|
95
|
+
# ---------------------------------------------------------------------------
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _spaider_server_entry(url: str, api_key: str) -> dict[str, Any]:
|
|
99
|
+
"""The mcpServers block that we add for SpAIder."""
|
|
100
|
+
return {
|
|
101
|
+
"url": url,
|
|
102
|
+
"headers": {"Authorization": f"Bearer {api_key}"},
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def merge_mcp_server(
|
|
107
|
+
existing: dict[str, Any] | None,
|
|
108
|
+
*,
|
|
109
|
+
server_name: str = "spaider",
|
|
110
|
+
url: str,
|
|
111
|
+
api_key: str,
|
|
112
|
+
) -> dict[str, Any]:
|
|
113
|
+
"""Return a new dict with the spaider mcpServers entry merged in.
|
|
114
|
+
|
|
115
|
+
Pure function — does not touch the filesystem. Preserves every other
|
|
116
|
+
server the user already has and any unrelated top-level keys.
|
|
117
|
+
"""
|
|
118
|
+
merged: dict[str, Any] = dict(existing or {})
|
|
119
|
+
servers = dict(merged.get("mcpServers") or {})
|
|
120
|
+
servers[server_name] = _spaider_server_entry(url=url, api_key=api_key)
|
|
121
|
+
merged["mcpServers"] = servers
|
|
122
|
+
return merged
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# ---------------------------------------------------------------------------
|
|
126
|
+
# Atomic write + backup
|
|
127
|
+
# ---------------------------------------------------------------------------
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _timestamp_suffix() -> str:
|
|
131
|
+
return datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def backup_if_exists(path: Path) -> Path | None:
|
|
135
|
+
"""If ``path`` exists, copy it to ``path.<timestamp>.bak``. Returns the backup path."""
|
|
136
|
+
if not path.exists():
|
|
137
|
+
return None
|
|
138
|
+
backup = path.with_name(f"{path.name}.{_timestamp_suffix()}.bak")
|
|
139
|
+
shutil.copy2(path, backup)
|
|
140
|
+
return backup
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def atomic_write_text(path: Path, content: str) -> None:
|
|
144
|
+
"""Write ``content`` to ``path`` via temp-file + rename so readers never see partial state."""
|
|
145
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
146
|
+
fd, tmp_path = tempfile.mkstemp(
|
|
147
|
+
dir=path.parent,
|
|
148
|
+
prefix=f".{path.name}.",
|
|
149
|
+
suffix=".tmp",
|
|
150
|
+
)
|
|
151
|
+
try:
|
|
152
|
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
153
|
+
f.write(content)
|
|
154
|
+
os.replace(tmp_path, path)
|
|
155
|
+
except Exception:
|
|
156
|
+
try:
|
|
157
|
+
os.unlink(tmp_path)
|
|
158
|
+
except OSError:
|
|
159
|
+
pass
|
|
160
|
+
raise
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def atomic_write_json(path: Path, data: dict[str, Any]) -> None:
|
|
164
|
+
"""Atomic JSON write with stable 2-space indent + trailing newline."""
|
|
165
|
+
atomic_write_text(path, json.dumps(data, indent=2, sort_keys=False) + "\n")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# ---------------------------------------------------------------------------
|
|
169
|
+
# Read existing config (forgiving)
|
|
170
|
+
# ---------------------------------------------------------------------------
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class MalformedConfigError(RuntimeError):
|
|
174
|
+
"""Raised when an existing .mcp.json file can't be parsed."""
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def read_mcp_config(path: Path) -> dict[str, Any]:
|
|
178
|
+
"""Read an existing .mcp.json. Returns ``{}`` if missing; raises if malformed."""
|
|
179
|
+
if not path.exists():
|
|
180
|
+
return {}
|
|
181
|
+
try:
|
|
182
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
183
|
+
except json.JSONDecodeError as exc:
|
|
184
|
+
raise MalformedConfigError(
|
|
185
|
+
f"existing {path} is not valid JSON: {exc}. "
|
|
186
|
+
"Move it aside (or delete it) and re-run."
|
|
187
|
+
) from exc
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
# ---------------------------------------------------------------------------
|
|
191
|
+
# High-level orchestration — used by the mcp.install command
|
|
192
|
+
# ---------------------------------------------------------------------------
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@dataclass
|
|
196
|
+
class InstallReport:
|
|
197
|
+
"""What ``install_for_claude_code`` actually did (for UI / tests)."""
|
|
198
|
+
config_path: Path
|
|
199
|
+
config_backup: Path | None
|
|
200
|
+
skill_path: Path | None
|
|
201
|
+
skill_backup: Path | None
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def install_for_claude_code(
|
|
205
|
+
*,
|
|
206
|
+
url: str,
|
|
207
|
+
api_key: str,
|
|
208
|
+
scope: str = "user",
|
|
209
|
+
home: Path | None = None,
|
|
210
|
+
project_root: Path | None = None,
|
|
211
|
+
) -> InstallReport:
|
|
212
|
+
"""Idempotently install SpAIder into Claude Code on this machine.
|
|
213
|
+
|
|
214
|
+
Steps (paths depend on ``scope`` — see :func:`claude_code_paths`):
|
|
215
|
+
1. Read the target ``.mcp.json`` (treat missing as empty).
|
|
216
|
+
2. Merge a ``mcpServers.spaider`` entry pointing at ``url`` with the
|
|
217
|
+
Bearer ``api_key`` header.
|
|
218
|
+
3. Back up the existing file (if any), then atomic-write the merged JSON.
|
|
219
|
+
4. Back up + atomic-write the bundled skill file alongside it.
|
|
220
|
+
"""
|
|
221
|
+
paths = claude_code_paths(scope=scope, home=home, project_root=project_root)
|
|
222
|
+
|
|
223
|
+
existing = read_mcp_config(paths.mcp_config)
|
|
224
|
+
merged = merge_mcp_server(existing, url=url, api_key=api_key)
|
|
225
|
+
|
|
226
|
+
config_backup = backup_if_exists(paths.mcp_config)
|
|
227
|
+
atomic_write_json(paths.mcp_config, merged)
|
|
228
|
+
|
|
229
|
+
assert paths.skill_file is not None # claude-code always has a skill slot
|
|
230
|
+
skill_backup = backup_if_exists(paths.skill_file)
|
|
231
|
+
atomic_write_text(paths.skill_file, read_packaged_skill("claude_code.md"))
|
|
232
|
+
|
|
233
|
+
return InstallReport(
|
|
234
|
+
config_path=paths.mcp_config,
|
|
235
|
+
config_backup=config_backup,
|
|
236
|
+
skill_path=paths.skill_file,
|
|
237
|
+
skill_backup=skill_backup,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def install_for_cursor(
|
|
242
|
+
*,
|
|
243
|
+
project_root: Path,
|
|
244
|
+
url: str,
|
|
245
|
+
api_key: str,
|
|
246
|
+
) -> InstallReport:
|
|
247
|
+
"""Install SpAIder's usage rules into a Cursor project as .cursorrules.
|
|
248
|
+
|
|
249
|
+
Cursor's MCP support is per-project: the rules + server entry live in
|
|
250
|
+
``.cursorrules`` at the project root. If a rules file already exists, we
|
|
251
|
+
append a clearly-delimited SpAIder block (preserving the user's existing
|
|
252
|
+
rules) rather than overwriting.
|
|
253
|
+
"""
|
|
254
|
+
paths = cursor_paths(project_root)
|
|
255
|
+
skill_content = read_packaged_skill("claude_code.md") # same source for now
|
|
256
|
+
|
|
257
|
+
# Compose: a banner with the MCP server URL + key, followed by the skill.
|
|
258
|
+
banner = (
|
|
259
|
+
"# ── SpAIder MCP — auto-installed by `spaider mcp install --for cursor` ──\n"
|
|
260
|
+
f"# MCP endpoint: {url}\n"
|
|
261
|
+
f"# Bearer token: {api_key}\n"
|
|
262
|
+
"# Edit above if needed; the skill content below is portable.\n\n"
|
|
263
|
+
)
|
|
264
|
+
payload = banner + skill_content
|
|
265
|
+
|
|
266
|
+
if paths.mcp_config.exists():
|
|
267
|
+
existing = paths.mcp_config.read_text(encoding="utf-8")
|
|
268
|
+
if "spaider mcp install" in existing:
|
|
269
|
+
# Already installed — back up and replace the spaider block.
|
|
270
|
+
config_backup = backup_if_exists(paths.mcp_config)
|
|
271
|
+
atomic_write_text(paths.mcp_config, payload)
|
|
272
|
+
else:
|
|
273
|
+
# Append, preserving user's prior rules.
|
|
274
|
+
config_backup = backup_if_exists(paths.mcp_config)
|
|
275
|
+
atomic_write_text(paths.mcp_config, existing.rstrip() + "\n\n" + payload)
|
|
276
|
+
else:
|
|
277
|
+
config_backup = None
|
|
278
|
+
atomic_write_text(paths.mcp_config, payload)
|
|
279
|
+
|
|
280
|
+
return InstallReport(
|
|
281
|
+
config_path=paths.mcp_config,
|
|
282
|
+
config_backup=config_backup,
|
|
283
|
+
skill_path=None,
|
|
284
|
+
skill_backup=None,
|
|
285
|
+
)
|
spaider_cli/main.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""SpAIder CLI entry point.
|
|
2
|
+
|
|
3
|
+
Registers the top-level ``spaider`` command and its subcommands via Typer.
|
|
4
|
+
The actual implementation of each subcommand lives in ``spaider_cli.commands.*``
|
|
5
|
+
modules; this file only wires the app together so ``[project.scripts]``
|
|
6
|
+
resolution stays trivial.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
|
|
12
|
+
from spaider_cli import __version__
|
|
13
|
+
from spaider_cli.commands import agent as agent_cmd
|
|
14
|
+
from spaider_cli.commands import doctor as doctor_cmd
|
|
15
|
+
from spaider_cli.commands import init as init_cmd
|
|
16
|
+
from spaider_cli.commands import mcp as mcp_cmd
|
|
17
|
+
|
|
18
|
+
app = typer.Typer(
|
|
19
|
+
name="spaider",
|
|
20
|
+
help=(
|
|
21
|
+
"SpAIder install wizard, agent management, and AI-agent skill "
|
|
22
|
+
"installer. Run `spaider init` to set up a new SpAIder stack and "
|
|
23
|
+
"wire it into Claude Code in under 5 minutes."
|
|
24
|
+
),
|
|
25
|
+
rich_markup_mode="rich",
|
|
26
|
+
no_args_is_help=True,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _version_callback(value: bool) -> None:
|
|
31
|
+
if value:
|
|
32
|
+
typer.echo(f"spaider-cli {__version__}")
|
|
33
|
+
raise typer.Exit()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@app.callback()
|
|
37
|
+
def _root(
|
|
38
|
+
version: bool = typer.Option(
|
|
39
|
+
False,
|
|
40
|
+
"--version",
|
|
41
|
+
"-V",
|
|
42
|
+
callback=_version_callback,
|
|
43
|
+
is_eager=True,
|
|
44
|
+
help="Print the spaider-cli version and exit.",
|
|
45
|
+
),
|
|
46
|
+
) -> None:
|
|
47
|
+
"""SpAIder CLI — durable AI memory in one command."""
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# ---------------------------------------------------------------------------
|
|
52
|
+
# Top-level commands (single-purpose, no sub-tree).
|
|
53
|
+
# ---------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
app.command("init", help="First-time install wizard — sets up SpAIder end-to-end.")(
|
|
56
|
+
init_cmd.run
|
|
57
|
+
)
|
|
58
|
+
app.command("doctor", help="Self-check current install + offer repairs.")(
|
|
59
|
+
doctor_cmd.run
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# ---------------------------------------------------------------------------
|
|
63
|
+
# Nested command groups.
|
|
64
|
+
# ---------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
app.add_typer(agent_cmd.app, name="agent", help="Create / list / rotate-key / delete agents.")
|
|
67
|
+
app.add_typer(mcp_cmd.app, name="mcp", help="Install SpAIder into Claude Code / Cursor as an MCP server.")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
app()
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Packaged skill files shipped alongside the CLI.
|
|
2
|
+
|
|
3
|
+
These are read at install time by ``spaider mcp install`` and written to the
|
|
4
|
+
target MCP client's skill directory (e.g. ``~/.claude/skills/spaider.md``).
|
|
5
|
+
|
|
6
|
+
Files in this directory are included in the wheel via the
|
|
7
|
+
``[tool.setuptools.package-data]`` block in ``pyproject.toml``.
|
|
8
|
+
"""
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spaider
|
|
3
|
+
description: |
|
|
4
|
+
Use SpAIder MCP tools for durable, queryable memory across sessions.
|
|
5
|
+
Trigger whenever the user references prior conversations, decisions, preferences,
|
|
6
|
+
or facts from past work, and to persist non-obvious learnings worth carrying
|
|
7
|
+
into future sessions. Skip on trivial one-off requests where the tool round-trip
|
|
8
|
+
costs more than the value.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# SpAIder: durable memory for AI agents
|
|
12
|
+
|
|
13
|
+
SpAIder is an MCP server that gives every AI session a persistent, queryable
|
|
14
|
+
knowledge graph. Four tools are exposed:
|
|
15
|
+
|
|
16
|
+
| Tool | Purpose |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `spaider.query(question, top_k?)` | Natural-language question against the calling agent's graph; returns LLM-synthesised answer + supporting nodes + a `Node IDs (for feedback): ...` trailer |
|
|
19
|
+
| `spaider.list_recent(limit?)` | The N most recently created nodes for the calling agent; the fastest "what was I just doing?" probe |
|
|
20
|
+
| `spaider.ingest_fact(text, source?, metadata?)` | Write a fact through the standard extraction pipeline |
|
|
21
|
+
| `spaider.feedback(used_node_ids, success, rationale?)` | Apply Hebbian +0.1 / −0.1 reinforcement to the RELATION edges between the named nodes; shapes which paths future queries see |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## When to call which tool
|
|
26
|
+
|
|
27
|
+
### Session start
|
|
28
|
+
|
|
29
|
+
If the user's request looks like it could be informed by prior context (they
|
|
30
|
+
reference "the project", "what we agreed", a feature in flight), open with one
|
|
31
|
+
or both:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
spaider.list_recent(limit=20) # snapshot of what's fresh
|
|
35
|
+
spaider.query("user preferences for <topic>") # if topic is obvious
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The returned facts inform the rest of the session, so don't repeat questions
|
|
39
|
+
whose answers are already in the graph.
|
|
40
|
+
|
|
41
|
+
**Skip this for trivial requests** (one-line bug fix, simple file rename).
|
|
42
|
+
The tool round-trip costs more than the value.
|
|
43
|
+
|
|
44
|
+
### During the session
|
|
45
|
+
|
|
46
|
+
Call `spaider.query` instead of asking the user something they've already
|
|
47
|
+
answered. Examples that should hit the graph first:
|
|
48
|
+
|
|
49
|
+
- "What's the preferred merge style?"
|
|
50
|
+
- "Which test framework does this repo use?"
|
|
51
|
+
- "Did we decide yes or no on adding the X dependency?"
|
|
52
|
+
|
|
53
|
+
If the answer comes back with low confidence, treat it as a hint, not a fact,
|
|
54
|
+
and confirm with the user.
|
|
55
|
+
|
|
56
|
+
### Session end
|
|
57
|
+
|
|
58
|
+
Capture **non-obvious** learnings via `spaider.ingest_fact`. The bar is "would
|
|
59
|
+
a future session save real time if it knew this?", not a diary. Examples
|
|
60
|
+
worth writing:
|
|
61
|
+
|
|
62
|
+
- A user preference I had to ask about: *"User prefers merge commits over
|
|
63
|
+
squash for this repo. Reason: keeps PR boundary visible in main."*
|
|
64
|
+
- A repo-specific gotcha: *"The scheduler runs on a different asyncio loop
|
|
65
|
+
than the API; don't share Redis pools across them."*
|
|
66
|
+
- A decision that was made: *"Decided NOT to add OpenAI as a fallback LLM
|
|
67
|
+
provider; cost model doesn't fit the agent budget."*
|
|
68
|
+
|
|
69
|
+
**Don't** write:
|
|
70
|
+
|
|
71
|
+
- Secrets, API keys, raw user PII.
|
|
72
|
+
- Verbatim code (use git blame / search instead).
|
|
73
|
+
- The summary of what you just did this session; that's already in the PR description.
|
|
74
|
+
- Anything you wouldn't want a colleague to read out loud at a standup.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Feedback protocol: `spaider.feedback`
|
|
79
|
+
|
|
80
|
+
When `spaider.query` returns useful (or actively misleading) supporting nodes,
|
|
81
|
+
echo that judgment back to the graph via `spaider.feedback`. Hebbian rules:
|
|
82
|
+
every RELATION edge between the named nodes gets ±0.1 (capped to [0.1, 2.0]).
|
|
83
|
+
The engine prunes weak edges over time; your feedback shapes which paths
|
|
84
|
+
future queries see.
|
|
85
|
+
|
|
86
|
+
### Decision rule: high vs low confidence
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
After a spaider.query result informs my next step:
|
|
90
|
+
|
|
91
|
+
Confident outcome (clearly helped or clearly didn't)?
|
|
92
|
+
→ POST feedback immediately
|
|
93
|
+
spaider.feedback(used_node_ids=[...from trailer], success=True/False)
|
|
94
|
+
|
|
95
|
+
Uncertain outcome?
|
|
96
|
+
→ Ask the user "👍 was that useful? (y/N within 10s)"
|
|
97
|
+
├─ y → POST success=true
|
|
98
|
+
├─ N → POST success=false
|
|
99
|
+
└─ silence (10s timeout) → no POST
|
|
100
|
+
(neutral; we don't fake either signal)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**When you have high confidence**: the query gave you the exact fact you
|
|
104
|
+
needed (e.g. you asked for the user's preferred branch convention and got
|
|
105
|
+
`feature/issue-NN-...`), or it gave you something demonstrably wrong (it
|
|
106
|
+
returned five entity names with no relevance to the question). Fire feedback
|
|
107
|
+
unprompted.
|
|
108
|
+
|
|
109
|
+
**When you have low confidence**: the supporting nodes were related but not
|
|
110
|
+
directly useful, or your subsequent answer was generated mostly from training-set
|
|
111
|
+
knowledge rather than the retrieved context. Prompt the user; if they don't
|
|
112
|
+
respond in ~10 seconds, skip the POST. Silence is *not* neutral if you encode
|
|
113
|
+
it as either success or failure; it pollutes the graph more than no signal.
|
|
114
|
+
|
|
115
|
+
**Don't fire feedback when**:
|
|
116
|
+
|
|
117
|
+
- The query failed to return any supporting nodes (no edges to update).
|
|
118
|
+
- You can't tell which nodes informed your answer (don't guess; skip).
|
|
119
|
+
- The answer's correctness depended on user-supplied context, not retrieval.
|
|
120
|
+
|
|
121
|
+
**Operational note**: the `Node IDs (for feedback): id1, id2, ...` trailer
|
|
122
|
+
that `spaider.query` appends is the canonical source for `used_node_ids`.
|
|
123
|
+
Don't fabricate IDs from labels.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Failure modes (graceful degradation)
|
|
128
|
+
|
|
129
|
+
The MCP server can be unreachable for several real reasons:
|
|
130
|
+
|
|
131
|
+
- The local stack is starting up or being rebuilt.
|
|
132
|
+
- The user hasn't completed setup yet, or hasn't restarted their MCP client.
|
|
133
|
+
- Network or auth issue.
|
|
134
|
+
|
|
135
|
+
In all cases: **continue the session from conversation context**. Do not block
|
|
136
|
+
on the tool. Do not fail loudly to the user; mention only if the failure
|
|
137
|
+
prevents you from doing something they explicitly asked for. The brain not
|
|
138
|
+
being there is not the same as the user not being there.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Quality bar
|
|
143
|
+
|
|
144
|
+
This skill is intentionally narrow: SpAIder is *one form of memory among
|
|
145
|
+
many*. Use it for things that benefit from being remembered across sessions
|
|
146
|
+
and shared across multiple AI tools that connect to the same SpAIder agent.
|
|
147
|
+
Don't use it as a replacement for `Read` / `Edit` / `Bash` / `git`; those
|
|
148
|
+
remain authoritative for the current state of code and the file system.
|
|
149
|
+
|
|
150
|
+
Two facts per session is plenty. Quality over quantity: the warm
|
|
151
|
+
`spaider.list_recent` call that opens the next session has limited room.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spaider-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SpAIder install wizard, agent management, and Claude Code skill installer
|
|
5
|
+
Author: SpAIder Studio
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Spaider-studio/spaider
|
|
8
|
+
Project-URL: Documentation, https://github.com/Spaider-studio/spaider/blob/main/README.md
|
|
9
|
+
Project-URL: Repository, https://github.com/Spaider-studio/spaider
|
|
10
|
+
Project-URL: Issues, https://github.com/Spaider-studio/spaider/issues
|
|
11
|
+
Keywords: spaider,mcp,knowledge-graph,ai-agents,memory
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: typer>=0.12.0
|
|
25
|
+
Requires-Dist: rich>=13.7.0
|
|
26
|
+
Requires-Dist: httpx>=0.27.0
|
|
27
|
+
Requires-Dist: pydantic>=2.5.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy>=1.10.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# spaider-cli
|
|
36
|
+
|
|
37
|
+
The official command-line interface for [SpAIder](https://github.com/Spaider-studio/spaider), the memory infrastructure for AI agents.
|
|
38
|
+
|
|
39
|
+
`spaider-cli` is the recommended way to install, manage, and integrate SpAIder with your AI coding tools (Claude Code, Cursor, and others). It takes you from "never heard of SpAIder" to "working Studio + MCP-integrated Claude Code with a memory skill loaded" in one command.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pipx install spaider-cli
|
|
43
|
+
spaider init
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Status
|
|
47
|
+
|
|
48
|
+
**v0.1.0**. All commands implemented and working.
|
|
49
|
+
|
|
50
|
+
| Command | Status |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `spaider --version` / `--help` | ✅ |
|
|
53
|
+
| `spaider init` | ✅ One-shot setup wizard |
|
|
54
|
+
| `spaider doctor` | ✅ Read-only health audit |
|
|
55
|
+
| `spaider agent create / list / rotate-key / delete` | ✅ |
|
|
56
|
+
| `spaider mcp install` | ✅ Claude Code + Cursor |
|
|
57
|
+
|
|
58
|
+
## What it does
|
|
59
|
+
|
|
60
|
+
1. **`spaider init`**: one command from clone to a working, MCP-integrated stack:
|
|
61
|
+
- Detect Docker (CLI + daemon).
|
|
62
|
+
- Prompt for the LLM provider (OpenAI / Anthropic / Ollama) and **validate the key** with a live probe.
|
|
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
|
+
- Start the Docker stack and wait for `/health`.
|
|
65
|
+
- Provision a `dev-${USER}` agent (or `--agent <name>`) and capture its key.
|
|
66
|
+
- Install the MCP server + skill into `~/.claude/` (idempotent merge).
|
|
67
|
+
|
|
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, and the `~/.claude` MCP + skill wiring. Exit 0 when all green/warn, 1 on a blocking failure.
|
|
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.
|
|
72
|
+
|
|
73
|
+
## The skill file
|
|
74
|
+
|
|
75
|
+
A key part of the value: `spaider mcp install` ships not just the MCP server config but a **skill file** (`~/.claude/skills/spaider.md`) 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
|
+
Source content is at `src/spaider_cli/skills/claude_code.md` (Apache 2.0); copy and adapt for your own tools if useful.
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
git clone https://github.com/Spaider-studio/spaider.git
|
|
83
|
+
cd spaider/cli
|
|
84
|
+
pip install -e ".[dev]"
|
|
85
|
+
pytest
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or from the SpAIder monorepo root:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
make cli-dev # editable install of the CLI
|
|
92
|
+
make cli-test # run cli/tests/
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Release (maintainers only)
|
|
96
|
+
|
|
97
|
+
CI runs as the `cli-tests` job of `.github/workflows/ci.yml` (every PR + push to main that touches `cli/`); releases run from `.github/workflows/cli-release.yml` on tag push.
|
|
98
|
+
|
|
99
|
+
One-time setup before the first PyPI release:
|
|
100
|
+
|
|
101
|
+
1. Create a [PyPI account](https://pypi.org/account/register/) for the project.
|
|
102
|
+
2. Register a Trusted Publisher (pending publisher) for `spaider-cli`:
|
|
103
|
+
|
|
104
|
+
- PyPI Project → Publishing → Add a new pending publisher.
|
|
105
|
+
- Owner: `Spaider-studio`, repo: `spaider`, workflow: `cli-release.yml`, environment: `pypi`.
|
|
106
|
+
- GitHub: Settings → Environments → Create environment named `pypi` (no protection rules needed for the first release).
|
|
107
|
+
|
|
108
|
+
3. Tag and push (CLI releases use namespaced `cli/v*` tags; plain `v*` tags release the container images instead):
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
git tag cli/v0.1.0
|
|
112
|
+
git push origin cli/v0.1.0
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The workflow builds sdist + wheel, runs `twine check`, then publishes via the OIDC trusted-publisher flow (no API tokens stored in the repo).
|
|
116
|
+
|
|
117
|
+
To rehearse without publishing, use the manual `workflow_dispatch` trigger with `dry_run: true`: it builds the artifacts but skips PyPI.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
Apache 2.0. See [LICENSE](https://github.com/Spaider-studio/spaider/blob/main/LICENSE).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
spaider_cli/__init__.py,sha256=XYWAw82cZf1A8tR22cIUDH0PPLWEnNKYNKY31Rwsvdk,524
|
|
2
|
+
spaider_cli/main.py,sha256=jg85Y4uKqIRLSjUlFQ5TRjkrE6FN3vu_o1dLHSupmyg,2189
|
|
3
|
+
spaider_cli/commands/__init__.py,sha256=PLytWSVritawe0DlM726U0kyG07HlNUtOoqtLri41Vk,231
|
|
4
|
+
spaider_cli/commands/agent.py,sha256=gYXjvri78CZCrJv4OS7qGoni5p-1ceyni2WDDOmDAL4,6206
|
|
5
|
+
spaider_cli/commands/doctor.py,sha256=BVVqmccGcrZd8kpV-Hb-Zjcb7bgCDoLgaa0RXHTkhvw,8178
|
|
6
|
+
spaider_cli/commands/init.py,sha256=4vNmAvZix8e9Zp70C1zwZ7DjyLJkViNr3qeqS2vqCcs,15366
|
|
7
|
+
spaider_cli/commands/mcp.py,sha256=DdR91V8oWxOuJu2CCsJUIFGKn8HTjN2a-O_qz4OFW-s,6891
|
|
8
|
+
spaider_cli/lib/__init__.py,sha256=-hF1PKPVSqSKrobNrzC0qNB6PUBx7cWB597tUuFhrN0,391
|
|
9
|
+
spaider_cli/lib/api.py,sha256=P5YRyRv49nkhorzrMpxGIJj_VXaOknCKYVvgmDPrfR8,5260
|
|
10
|
+
spaider_cli/lib/docker.py,sha256=erNgu5Ptop42Y5JhCnr3EASUdnrmONwH55SwZx1mZBo,3843
|
|
11
|
+
spaider_cli/lib/env.py,sha256=28O1Sw4zy2cceqcgvb9hpzX7eBaqYcpRZ6pj7LuwqZI,4747
|
|
12
|
+
spaider_cli/lib/llm.py,sha256=XQM-J1mnCSzQXKE8icQt_6qRMLgV7A7rwcgXv4qMS8I,3253
|
|
13
|
+
spaider_cli/lib/mcp.py,sha256=nSU4Qae4iYCdm5S-9wF_NtShDCihatgjJNbcEBF5R4k,9849
|
|
14
|
+
spaider_cli/skills/__init__.py,sha256=se-4qxqXiQNOoO4JTZF-j8bGMlbDVpyxmr4cTxjccqQ,332
|
|
15
|
+
spaider_cli/skills/claude_code.md,sha256=xCM8h6iTVUkSO8Z4-pFRBK4gvbApDVTgiV4psQA5h-g,6162
|
|
16
|
+
spaider_cli-0.1.0.dist-info/licenses/LICENSE,sha256=63rhQJzSFS0iULBxyyJGHeBhJ1d0OcKi7o24_BfmDpA,11311
|
|
17
|
+
spaider_cli-0.1.0.dist-info/METADATA,sha256=D4_32HFynmblK14z72j2u3N80n4q3bhxV2yt2N9q6_c,5637
|
|
18
|
+
spaider_cli-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
19
|
+
spaider_cli-0.1.0.dist-info/entry_points.txt,sha256=XiuN0IzzVFvFxDHE28MtiJhHrc8KpVPsm-kBz9-zhqo,49
|
|
20
|
+
spaider_cli-0.1.0.dist-info/top_level.txt,sha256=gKdA8M-roEdUV-fWw1tmqqgPumGVzOVil3n7ufgSCNg,12
|
|
21
|
+
spaider_cli-0.1.0.dist-info/RECORD,,
|