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.
Files changed (99) hide show
  1. wspx/__init__.py +24 -0
  2. wspx/_version.py +1 -0
  3. wspx/addressing.py +415 -0
  4. wspx/auth.py +77 -0
  5. wspx/cli/__init__.py +1 -0
  6. wspx/cli/client.py +124 -0
  7. wspx/cli/config.py +89 -0
  8. wspx/cli/connect.py +88 -0
  9. wspx/cli/main.py +848 -0
  10. wspx/cloud/__init__.py +20 -0
  11. wspx/cloud/app.py +191 -0
  12. wspx/cloud/backend.py +141 -0
  13. wspx/cloud/compose.py +85 -0
  14. wspx/cloud/deploy.py +102 -0
  15. wspx/config.py +189 -0
  16. wspx/control/__init__.py +5 -0
  17. wspx/control/app.py +488 -0
  18. wspx/control/backend.py +244 -0
  19. wspx/control/gateway_client.py +79 -0
  20. wspx/control/mcp_server.py +71 -0
  21. wspx/control/sessions.py +424 -0
  22. wspx/control/tracedb.py +183 -0
  23. wspx/control/ui/assets/index-BJFweZAn.css +1 -0
  24. wspx/control/ui/assets/index-DhUVhWIK.js +10 -0
  25. wspx/control/ui/index.html +13 -0
  26. wspx/control/views.py +180 -0
  27. wspx/diagnostics.py +146 -0
  28. wspx/driver/__init__.py +7 -0
  29. wspx/driver/loop.py +255 -0
  30. wspx/driver/messages.py +62 -0
  31. wspx/driver/providers/__init__.py +84 -0
  32. wspx/driver/providers/anthropic.py +149 -0
  33. wspx/driver/providers/compat.py +115 -0
  34. wspx/driver/providers/google.py +138 -0
  35. wspx/driver/providers/openai.py +125 -0
  36. wspx/driver/run.py +134 -0
  37. wspx/errors.py +69 -0
  38. wspx/gateway/__init__.py +8 -0
  39. wspx/gateway/app.py +626 -0
  40. wspx/gateway/ledger.py +536 -0
  41. wspx/gateway/prices.py +75 -0
  42. wspx/gateway/usage.py +284 -0
  43. wspx/handles.py +117 -0
  44. wspx/integrations/AGENTS.snippet.md +8 -0
  45. wspx/integrations/SKILL.md +52 -0
  46. wspx/integrations/__init__.py +17 -0
  47. wspx/integrations/claude-plugin/.claude-plugin/plugin.json +30 -0
  48. wspx/integrations/claude-plugin/skills/wspx/SKILL.md +52 -0
  49. wspx/integrations/codex-hooks.toml +9 -0
  50. wspx/lab/__init__.py +5 -0
  51. wspx/lab/analysis.py +485 -0
  52. wspx/lab/check.py +489 -0
  53. wspx/lab/evaluate.py +108 -0
  54. wspx/lab/export.py +275 -0
  55. wspx/lab/grep.py +754 -0
  56. wspx/lab/index.py +239 -0
  57. wspx/lab/ir/__init__.py +1 -0
  58. wspx/lab/ir/capture.py +299 -0
  59. wspx/lab/ir/graph.py +148 -0
  60. wspx/lab/ir/model_ir.py +522 -0
  61. wspx/lab/ir/semantics.py +1255 -0
  62. wspx/lab/ir/tape.py +853 -0
  63. wspx/lab/loader.py +204 -0
  64. wspx/lab/merge.py +200 -0
  65. wspx/lab/ops/__init__.py +76 -0
  66. wspx/lab/ops/builtin.py +379 -0
  67. wspx/lab/patch.py +320 -0
  68. wspx/lab/probe.py +206 -0
  69. wspx/lab/results.py +114 -0
  70. wspx/lab/sdk.py +120 -0
  71. wspx/lab/server.py +236 -0
  72. wspx/lab/session.py +1574 -0
  73. wspx/lab/tensors.py +119 -0
  74. wspx/lab/text.py +69 -0
  75. wspx/lab/tree.py +302 -0
  76. wspx/loops.py +127 -0
  77. wspx/project.py +143 -0
  78. wspx/py.typed +0 -0
  79. wspx/safety/__init__.py +15 -0
  80. wspx/safety/kill.py +47 -0
  81. wspx/safety/sweeper.py +68 -0
  82. wspx/store/__init__.py +64 -0
  83. wspx/store/objects.py +130 -0
  84. wspx/store/overlay.py +209 -0
  85. wspx/store/refs.py +150 -0
  86. wspx/testing/__init__.py +21 -0
  87. wspx/testing/api.py +155 -0
  88. wspx/testing/builtin.py +139 -0
  89. wspx/testing/runner.py +257 -0
  90. wspx/tools/__init__.py +17 -0
  91. wspx/tools/dispatch.py +129 -0
  92. wspx/tools/schemas.py +313 -0
  93. wspx/vcs/__init__.py +17 -0
  94. wspx/vcs/repo.py +431 -0
  95. wspx-0.1.0.dev0.dist-info/METADATA +278 -0
  96. wspx-0.1.0.dev0.dist-info/RECORD +99 -0
  97. wspx-0.1.0.dev0.dist-info/WHEEL +4 -0
  98. wspx-0.1.0.dev0.dist-info/entry_points.txt +10 -0
  99. wspx-0.1.0.dev0.dist-info/licenses/LICENSE +201 -0
wspx/driver/run.py ADDED
@@ -0,0 +1,134 @@
1
+ """Run a session's driver against a control plane and a gateway.
2
+
3
+ The runner holds a runner token (for its session's tool calls and events) and
4
+ an LLM token (for the gateway). It never holds a provider key, never runs
5
+ model-written code and never touches weights.
6
+
7
+ ``python -m wspx.driver.run`` reads ``WSPX_*`` variables (see ``run_from_env``).
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import contextlib
13
+ import os
14
+ from collections.abc import Mapping
15
+ from typing import Any
16
+
17
+ import httpx
18
+
19
+ from wspx.driver.loop import Hooks, Runner, RunnerConfig, RunResult, ToolReply
20
+ from wspx.driver.providers import Provider, make_provider
21
+ from wspx.integrations import skill_text
22
+
23
+
24
+ class ControlHooks:
25
+ def __init__(
26
+ self,
27
+ control_url: str,
28
+ gateway_url: str,
29
+ session: str,
30
+ runner_token: str,
31
+ llm_token: str,
32
+ *,
33
+ transport: httpx.BaseTransport | None = None,
34
+ ) -> None:
35
+ self.session = session
36
+ self.turn = 0
37
+ self.control = httpx.Client(
38
+ base_url=control_url.rstrip("/"),
39
+ timeout=3600.0,
40
+ transport=transport,
41
+ headers={"authorization": f"Bearer {runner_token}"},
42
+ )
43
+ self.gateway = (
44
+ httpx.Client(
45
+ base_url=gateway_url.rstrip("/"),
46
+ timeout=30.0,
47
+ transport=transport,
48
+ headers={"x-api-key": llm_token},
49
+ )
50
+ if gateway_url
51
+ else None
52
+ )
53
+
54
+ def tool(self, name: str, args: dict[str, Any], call_id: str) -> ToolReply:
55
+ r = self.control.post(
56
+ f"/api/sessions/{self.session}/tools/{name}",
57
+ json={"args": args, "call_id": call_id, "turn": self.turn, "source": "driver"},
58
+ )
59
+ if r.status_code >= 400:
60
+ return ToolReply(
61
+ f"{name}: control plane error {r.status_code}: {r.text[:500]}", ok=False
62
+ )
63
+ data = r.json()
64
+ return ToolReply(data.get("summary", ""), bool(data.get("ok", True)))
65
+
66
+ def gateway_state(self) -> dict[str, Any]:
67
+ if self.gateway is None:
68
+ return {}
69
+ try:
70
+ data: dict[str, Any] = self.gateway.get("/v1/session").json()
71
+ return data
72
+ except httpx.HTTPError:
73
+ return {"paused": "the gateway is unreachable; calls stop until it returns"}
74
+
75
+ def commands(self) -> list[dict[str, Any]]:
76
+ data: list[dict[str, Any]] = self.control.get(
77
+ f"/api/sessions/{self.session}/commands"
78
+ ).json()["commands"]
79
+ return data
80
+
81
+ def workspace(self) -> str:
82
+ return str(
83
+ self.control.get(f"/api/sessions/{self.session}/workspace").json().get("workspace", "")
84
+ )
85
+
86
+ def event(self, event: dict[str, Any]) -> None:
87
+ if event.get("type") == "turn":
88
+ self.turn = int(event.get("turn", self.turn))
89
+ # The trace is best-effort; the call log on the control plane is authoritative.
90
+ with contextlib.suppress(httpx.HTTPError):
91
+ self.control.post(f"/api/sessions/{self.session}/events", json=event)
92
+
93
+ def hooks(self) -> Hooks:
94
+ return Hooks(
95
+ tool=self.tool,
96
+ gateway_state=self.gateway_state,
97
+ commands=self.commands,
98
+ workspace=self.workspace,
99
+ event=self.event,
100
+ )
101
+
102
+
103
+ def run_from_env(
104
+ env: Mapping[str, str] | None = None,
105
+ *,
106
+ provider: Provider | None = None,
107
+ transport: httpx.BaseTransport | None = None,
108
+ ) -> RunResult:
109
+ env = env or os.environ
110
+ hooks = ControlHooks(
111
+ env["WSPX_CONTROL_URL"],
112
+ env.get("WSPX_GATEWAY_URL", ""),
113
+ env["WSPX_SESSION"],
114
+ env["WSPX_RUNNER_TOKEN"],
115
+ env["WSPX_LLM_TOKEN"],
116
+ transport=transport,
117
+ )
118
+ if provider is None:
119
+ provider = make_provider(
120
+ env["WSPX_DRIVER"], gateway=env["WSPX_GATEWAY_URL"], token=env["WSPX_LLM_TOKEN"]
121
+ )
122
+ config = RunnerConfig(
123
+ system=skill_text(), task=env.get("WSPX_TASK", ""), effort=env.get("WSPX_EFFORT", "high")
124
+ )
125
+ return Runner(provider, hooks.hooks(), config).run()
126
+
127
+
128
+ def main() -> None:
129
+ result = run_from_env()
130
+ print(f"wspx driver: {result.status} after {result.turns} turn(s): {result.reason}", flush=True)
131
+
132
+
133
+ if __name__ == "__main__":
134
+ main()
wspx/errors.py ADDED
@@ -0,0 +1,69 @@
1
+ """Exception hierarchy shared by every wspx component."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ if TYPE_CHECKING:
8
+ from wspx.diagnostics import Diagnostic
9
+
10
+
11
+ class WspxError(Exception):
12
+ """Base class for all errors raised by wspx."""
13
+
14
+
15
+ class ConfigError(WspxError):
16
+ """A ``wspx.toml`` file or a setting is invalid."""
17
+
18
+
19
+ class AddressError(WspxError):
20
+ """An address is malformed or does not resolve against the Model IR."""
21
+
22
+
23
+ class HandleError(WspxError):
24
+ """A handle is malformed or names nothing that exists."""
25
+
26
+
27
+ class StoreError(WspxError):
28
+ """An object or ref could not be read or written."""
29
+
30
+
31
+ class IntegrityError(StoreError):
32
+ """Content does not match its hash. Never ignored: this means corruption."""
33
+
34
+
35
+ class RefConflict(StoreError):
36
+ """A ref changed between read and update (compare-and-swap failed)."""
37
+
38
+
39
+ class ModelLoadError(WspxError):
40
+ """A model could not be instantiated, bound to its weights or captured."""
41
+
42
+
43
+ class PatchError(WspxError):
44
+ """A patch is malformed or cannot be applied to its base tensor."""
45
+
46
+
47
+ class CheckFailed(WspxError):
48
+ """An edit was blocked by one or more error-level diagnostics."""
49
+
50
+ def __init__(self, diagnostics: list[Diagnostic]) -> None:
51
+ self.diagnostics = diagnostics
52
+ codes = ", ".join(d.code for d in diagnostics) or "no diagnostics"
53
+ super().__init__(f"check failed: {codes}")
54
+
55
+
56
+ class GrepError(WspxError):
57
+ """A grep expression is malformed or cannot be evaluated."""
58
+
59
+
60
+ class VCSError(WspxError):
61
+ """A version-control operation cannot proceed."""
62
+
63
+
64
+ class HeldOutAccess(WspxError):
65
+ """A driver-facing path tried to read held-out items or outputs."""
66
+
67
+
68
+ class LabUnavailable(WspxError):
69
+ """The operation needs a live lab and none is reachable."""
@@ -0,0 +1,8 @@
1
+ """The LLM gateway (§5.14.2): the only holder of provider keys.
2
+
3
+ Every paid model call passes through it. It authenticates sessions, meters
4
+ each call from the provider's usage fields, enforces limits the user has set
5
+ (none by default), detects loops, and honours the global halt flag. It is a
6
+ small proxy for each provider's native API, streaming included, with no
7
+ provider SDKs, so it stays easy to audit.
8
+ """