wspx 0.1.0.dev0__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.
- wspx/__init__.py +24 -0
- wspx/_version.py +1 -0
- wspx/addressing.py +415 -0
- wspx/auth.py +77 -0
- wspx/cli/__init__.py +1 -0
- wspx/cli/client.py +124 -0
- wspx/cli/config.py +89 -0
- wspx/cli/connect.py +88 -0
- wspx/cli/main.py +848 -0
- wspx/cloud/__init__.py +20 -0
- wspx/cloud/app.py +191 -0
- wspx/cloud/backend.py +141 -0
- wspx/cloud/compose.py +85 -0
- wspx/cloud/deploy.py +102 -0
- wspx/config.py +189 -0
- wspx/control/__init__.py +5 -0
- wspx/control/app.py +488 -0
- wspx/control/backend.py +244 -0
- wspx/control/gateway_client.py +79 -0
- wspx/control/mcp_server.py +71 -0
- wspx/control/sessions.py +424 -0
- wspx/control/tracedb.py +183 -0
- wspx/control/ui/assets/index-BJFweZAn.css +1 -0
- wspx/control/ui/assets/index-DhUVhWIK.js +10 -0
- wspx/control/ui/index.html +13 -0
- wspx/control/views.py +180 -0
- wspx/diagnostics.py +146 -0
- wspx/driver/__init__.py +7 -0
- wspx/driver/loop.py +255 -0
- wspx/driver/messages.py +62 -0
- wspx/driver/providers/__init__.py +84 -0
- wspx/driver/providers/anthropic.py +149 -0
- wspx/driver/providers/compat.py +115 -0
- wspx/driver/providers/google.py +138 -0
- wspx/driver/providers/openai.py +125 -0
- wspx/driver/run.py +134 -0
- wspx/errors.py +69 -0
- wspx/gateway/__init__.py +8 -0
- wspx/gateway/app.py +626 -0
- wspx/gateway/ledger.py +536 -0
- wspx/gateway/prices.py +75 -0
- wspx/gateway/usage.py +284 -0
- wspx/handles.py +117 -0
- wspx/integrations/AGENTS.snippet.md +8 -0
- wspx/integrations/SKILL.md +52 -0
- wspx/integrations/__init__.py +17 -0
- wspx/integrations/claude-plugin/.claude-plugin/plugin.json +30 -0
- wspx/integrations/claude-plugin/skills/wspx/SKILL.md +52 -0
- wspx/integrations/codex-hooks.toml +9 -0
- wspx/lab/__init__.py +5 -0
- wspx/lab/analysis.py +485 -0
- wspx/lab/check.py +489 -0
- wspx/lab/evaluate.py +108 -0
- wspx/lab/export.py +275 -0
- wspx/lab/grep.py +754 -0
- wspx/lab/index.py +239 -0
- wspx/lab/ir/__init__.py +1 -0
- wspx/lab/ir/capture.py +299 -0
- wspx/lab/ir/graph.py +148 -0
- wspx/lab/ir/model_ir.py +522 -0
- wspx/lab/ir/semantics.py +1255 -0
- wspx/lab/ir/tape.py +853 -0
- wspx/lab/loader.py +204 -0
- wspx/lab/merge.py +200 -0
- wspx/lab/ops/__init__.py +76 -0
- wspx/lab/ops/builtin.py +379 -0
- wspx/lab/patch.py +320 -0
- wspx/lab/probe.py +206 -0
- wspx/lab/results.py +114 -0
- wspx/lab/sdk.py +120 -0
- wspx/lab/server.py +236 -0
- wspx/lab/session.py +1574 -0
- wspx/lab/tensors.py +119 -0
- wspx/lab/text.py +69 -0
- wspx/lab/tree.py +302 -0
- wspx/loops.py +127 -0
- wspx/project.py +143 -0
- wspx/py.typed +0 -0
- wspx/safety/__init__.py +15 -0
- wspx/safety/kill.py +47 -0
- wspx/safety/sweeper.py +68 -0
- wspx/store/__init__.py +64 -0
- wspx/store/objects.py +130 -0
- wspx/store/overlay.py +209 -0
- wspx/store/refs.py +150 -0
- wspx/testing/__init__.py +21 -0
- wspx/testing/api.py +155 -0
- wspx/testing/builtin.py +139 -0
- wspx/testing/runner.py +257 -0
- wspx/tools/__init__.py +17 -0
- wspx/tools/dispatch.py +129 -0
- wspx/tools/schemas.py +313 -0
- wspx/vcs/__init__.py +17 -0
- wspx/vcs/repo.py +431 -0
- wspx-0.1.0.dev0.dist-info/METADATA +278 -0
- wspx-0.1.0.dev0.dist-info/RECORD +99 -0
- wspx-0.1.0.dev0.dist-info/WHEEL +4 -0
- wspx-0.1.0.dev0.dist-info/entry_points.txt +10 -0
- wspx-0.1.0.dev0.dist-info/licenses/LICENSE +201 -0
wspx/cli/config.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""The CLI's own state: ``~/.config/wspx/config.toml``.
|
|
2
|
+
|
|
3
|
+
It holds where the deployed control plane is and which session each project
|
|
4
|
+
(and the shell outside any project) is working on. ``WSPX_URL``, ``WSPX_TOKEN``
|
|
5
|
+
and ``WSPX_SESSION`` override it.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import tomllib
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from wspx.errors import ConfigError
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def path() -> Path:
|
|
19
|
+
base = os.environ.get("XDG_CONFIG_HOME") or str(Path.home() / ".config")
|
|
20
|
+
return Path(base) / "wspx" / "config.toml"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class CliConfig:
|
|
25
|
+
url: str = ""
|
|
26
|
+
token: str = ""
|
|
27
|
+
session: str = ""
|
|
28
|
+
"""The current session outside any project."""
|
|
29
|
+
projects: dict[str, str] = field(default_factory=dict)
|
|
30
|
+
"""Project root → that project's current session."""
|
|
31
|
+
|
|
32
|
+
def current(self, root: str = "") -> str:
|
|
33
|
+
"""The session tool commands use in project ``root`` ("" outside any project)."""
|
|
34
|
+
return os.environ.get("WSPX_SESSION") or (
|
|
35
|
+
self.projects.get(root, "") if root else self.session
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def set_current(self, root: str, session: str) -> None:
|
|
39
|
+
if root:
|
|
40
|
+
self.projects[root] = session
|
|
41
|
+
else:
|
|
42
|
+
self.session = session
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def load() -> CliConfig:
|
|
46
|
+
cfg = CliConfig()
|
|
47
|
+
p = path()
|
|
48
|
+
if p.exists():
|
|
49
|
+
data = tomllib.loads(p.read_text())
|
|
50
|
+
cloud = data.get("cloud", {})
|
|
51
|
+
cfg = CliConfig(
|
|
52
|
+
cloud.get("url", ""),
|
|
53
|
+
cloud.get("token", ""),
|
|
54
|
+
data.get("session", ""),
|
|
55
|
+
{str(k): str(v) for k, v in data.get("projects", {}).items()},
|
|
56
|
+
)
|
|
57
|
+
cfg.url = os.environ.get("WSPX_URL", cfg.url)
|
|
58
|
+
cfg.token = os.environ.get("WSPX_TOKEN", cfg.token)
|
|
59
|
+
return cfg
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def save(cfg: CliConfig) -> Path:
|
|
63
|
+
p = path()
|
|
64
|
+
p.parent.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
|
|
66
|
+
def q(text: str) -> str:
|
|
67
|
+
return '"' + text.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
|
68
|
+
|
|
69
|
+
lines = [
|
|
70
|
+
f"session = {q(cfg.session)}",
|
|
71
|
+
"",
|
|
72
|
+
"[cloud]",
|
|
73
|
+
f"url = {q(cfg.url)}",
|
|
74
|
+
f"token = {q(cfg.token)}",
|
|
75
|
+
"",
|
|
76
|
+
]
|
|
77
|
+
if cfg.projects:
|
|
78
|
+
lines += ["[projects]", *(f"{q(k)} = {q(v)}" for k, v in sorted(cfg.projects.items())), ""]
|
|
79
|
+
p.write_text("\n".join(lines))
|
|
80
|
+
p.chmod(0o600)
|
|
81
|
+
return p
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def require(cfg: CliConfig) -> CliConfig:
|
|
85
|
+
if not cfg.url or not cfg.token:
|
|
86
|
+
raise ConfigError(
|
|
87
|
+
"not connected to a wspx deployment; run `wspx deploy` (or set WSPX_URL and WSPX_TOKEN)"
|
|
88
|
+
)
|
|
89
|
+
return cfg
|
wspx/cli/connect.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""``wspx connect claude|codex``: point a local agent at the hosted MCP endpoint (§5.10)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from wspx.errors import WspxError
|
|
12
|
+
from wspx.integrations import read
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def claude(url: str, token: str, session: str, *, project: Path) -> list[str]:
|
|
16
|
+
"""Register the MCP server, add HTTP hooks for the trace, and install the skill."""
|
|
17
|
+
done = []
|
|
18
|
+
if shutil.which("claude") is None:
|
|
19
|
+
raise WspxError("the `claude` CLI is not on PATH; install Claude Code first")
|
|
20
|
+
cmd = [
|
|
21
|
+
"claude",
|
|
22
|
+
"mcp",
|
|
23
|
+
"add",
|
|
24
|
+
"--transport",
|
|
25
|
+
"http",
|
|
26
|
+
"wspx",
|
|
27
|
+
f"{url.rstrip('/')}/mcp/",
|
|
28
|
+
"--header",
|
|
29
|
+
f"Authorization: Bearer {token}",
|
|
30
|
+
"--header",
|
|
31
|
+
f"X-Wspx-Session: {session}",
|
|
32
|
+
]
|
|
33
|
+
proc = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
|
34
|
+
if proc.returncode != 0 and "already exists" not in proc.stderr:
|
|
35
|
+
raise WspxError(f"claude mcp add failed: {proc.stderr.strip()}")
|
|
36
|
+
done.append("registered the wspx MCP server")
|
|
37
|
+
settings = project / ".claude" / "settings.json"
|
|
38
|
+
data = json.loads(settings.read_text()) if settings.exists() else {}
|
|
39
|
+
hook: dict[str, Any] = {
|
|
40
|
+
"type": "http",
|
|
41
|
+
"url": f"{url.rstrip('/')}/api/ingest/claude-code?session={session}",
|
|
42
|
+
"headers": {"Authorization": f"Bearer {token}"},
|
|
43
|
+
}
|
|
44
|
+
hooks = data.setdefault("hooks", {})
|
|
45
|
+
for event in ("PreToolUse", "PostToolUse", "UserPromptSubmit", "Stop"):
|
|
46
|
+
entries = hooks.setdefault(event, [])
|
|
47
|
+
if not any(
|
|
48
|
+
h.get("hooks", [{}])[0].get("url", "").startswith(hook["url"].split("?")[0])
|
|
49
|
+
for h in entries
|
|
50
|
+
):
|
|
51
|
+
entries.append({"matcher": "*", "hooks": [hook]})
|
|
52
|
+
settings.parent.mkdir(parents=True, exist_ok=True)
|
|
53
|
+
settings.write_text(json.dumps(data, indent=2) + "\n")
|
|
54
|
+
done.append(f"added trace hooks to {settings}")
|
|
55
|
+
skill = project / ".claude" / "skills" / "wspx" / "SKILL.md"
|
|
56
|
+
skill.parent.mkdir(parents=True, exist_ok=True)
|
|
57
|
+
skill.write_text(read("SKILL.md"))
|
|
58
|
+
done.append(f"installed the skill at {skill}")
|
|
59
|
+
return done
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def codex(url: str, token: str, session: str, *, project: Path) -> list[str]:
|
|
63
|
+
"""Add the local stdio MCP proxy and command hooks to ``.codex/config.toml``; install the skill."""
|
|
64
|
+
done = []
|
|
65
|
+
config = project / ".codex" / "config.toml"
|
|
66
|
+
config.parent.mkdir(parents=True, exist_ok=True)
|
|
67
|
+
text = config.read_text() if config.exists() else ""
|
|
68
|
+
if "[mcp_servers.wspx]" not in text:
|
|
69
|
+
text += (
|
|
70
|
+
"\n[mcp_servers.wspx]\n"
|
|
71
|
+
'command = "wspx"\n'
|
|
72
|
+
'args = ["mcp"]\n'
|
|
73
|
+
f'env = {{ WSPX_URL = "{url}", WSPX_TOKEN = "{token}", WSPX_SESSION = "{session}" }}\n'
|
|
74
|
+
)
|
|
75
|
+
if "wspx hook codex" not in text:
|
|
76
|
+
text += read("codex-hooks.toml")
|
|
77
|
+
config.write_text(text)
|
|
78
|
+
done.append(f"configured {config}")
|
|
79
|
+
skill = project / ".codex" / "skills" / "wspx" / "SKILL.md"
|
|
80
|
+
skill.parent.mkdir(parents=True, exist_ok=True)
|
|
81
|
+
skill.write_text(read("SKILL.md"))
|
|
82
|
+
agents = project / "AGENTS.md"
|
|
83
|
+
snippet = read("AGENTS.snippet.md")
|
|
84
|
+
if not agents.exists() or "wspx" not in agents.read_text():
|
|
85
|
+
agents.write_text((agents.read_text() + "\n" if agents.exists() else "") + snippet)
|
|
86
|
+
done.append("added the wspx section to AGENTS.md")
|
|
87
|
+
done.append(f"installed the skill at {skill}")
|
|
88
|
+
return done
|