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/tools/schemas.py
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"""Tool schemas, defined once."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import copy
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any, Literal
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
10
|
+
|
|
11
|
+
Prompt = str | list[int]
|
|
12
|
+
"""A prompt is text, or a list of token ids for models without a tokenizer."""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _Args(BaseModel):
|
|
16
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class InfoArgs(_Args):
|
|
20
|
+
handles: bool = Field(
|
|
21
|
+
False, description="Also list every live handle with a one-line description."
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class LsArgs(_Args):
|
|
26
|
+
scope: str = Field("L*.*", description="Address or glob, e.g. 'L*.mlp.down' or 'L8-12.attn.*'.")
|
|
27
|
+
role: str | None = Field(None, description="Role path such as 'attn.o' (combine with layers).")
|
|
28
|
+
layers: str | None = Field(None, description="Block selection: 'N', 'N-M' or '*'.")
|
|
29
|
+
limit: int = Field(100, ge=1, le=1000)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class GrepArgs(_Args):
|
|
33
|
+
expression: str | None = Field(
|
|
34
|
+
None,
|
|
35
|
+
description="e.g. 'writes(\" Wait\") > 0.3', 'colnorm > 4σ', 'cos(dir:loop) > 0.5', "
|
|
36
|
+
"'nan or absmax > 1e3'. Fields: norm colnorm rownorm absmax mean std kurtosis max min rank nan inf.",
|
|
37
|
+
)
|
|
38
|
+
scope: str | None = Field(None, alias="in", description="Where to search, e.g. 'L*.mlp.down'.")
|
|
39
|
+
axis: Literal["row", "col", "tensor", "elem"] | None = Field(
|
|
40
|
+
None,
|
|
41
|
+
description="Unit of search; default is the role's unit (writers: columns, readers: rows).",
|
|
42
|
+
)
|
|
43
|
+
top: int = Field(20, ge=1, le=200, description="Hits to return (the full ranking is saved).")
|
|
44
|
+
name: str | None = Field(
|
|
45
|
+
None, description="Your name for the result set, shown with its handle."
|
|
46
|
+
)
|
|
47
|
+
fires_on: list[Prompt] | str | None = Field(
|
|
48
|
+
None,
|
|
49
|
+
description="Activation grep: rank writer units by activation on these prompts (or a .jsonl path).",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class ShowArgs(_Args):
|
|
54
|
+
address: str = Field(
|
|
55
|
+
description="e.g. 'L19.mlp.down[:, 8812]', 'embed[\" Wait\"]' or a raw parameter name."
|
|
56
|
+
)
|
|
57
|
+
values: int | None = Field(
|
|
58
|
+
None, ge=0, le=2048, description="Also return up to this many raw values."
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ContrastArgs(_Args):
|
|
63
|
+
positive: list[Prompt] | str = Field(
|
|
64
|
+
description="Prompts showing the behaviour, or a .jsonl path."
|
|
65
|
+
)
|
|
66
|
+
negative: list[Prompt] | str = Field(description="Prompts without it, or a .jsonl path.")
|
|
67
|
+
name: str = Field(description="Direction name; it is saved as dir:<name>.")
|
|
68
|
+
layer: int | None = Field(
|
|
69
|
+
None, ge=0, description="Residual stream after this block (default: middle)."
|
|
70
|
+
)
|
|
71
|
+
position: Literal["last", "mean"] = "last"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class GenerateArgs(_Args):
|
|
75
|
+
prompt: Prompt | list[Prompt]
|
|
76
|
+
max_tokens: int = Field(64, ge=1, le=4096)
|
|
77
|
+
temperature: float = Field(0.0, ge=0.0, le=2.0)
|
|
78
|
+
seed: int = 0
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class TraceArgs(_Args):
|
|
82
|
+
prompt: Prompt
|
|
83
|
+
vs: str | None = Field(None, description="Diff trace against a commit, branch or 'base'.")
|
|
84
|
+
reference: Prompt | None = Field(
|
|
85
|
+
None, description="Attribution trace: a reference input that behaves well."
|
|
86
|
+
)
|
|
87
|
+
target: str | int | None = Field(
|
|
88
|
+
None, description="Attribution objective: this token's log-probability."
|
|
89
|
+
)
|
|
90
|
+
top: int = Field(5, ge=1, le=50)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class EditArgs(_Args):
|
|
94
|
+
op: str = Field(
|
|
95
|
+
description="ablate, set, scale, project_out, bake_steer, rank_one_write, transplant, "
|
|
96
|
+
"orthogonalize, or a plugin op."
|
|
97
|
+
)
|
|
98
|
+
args: dict[str, Any] = Field(
|
|
99
|
+
default_factory=dict,
|
|
100
|
+
description="The op's arguments: targets (addresses), "
|
|
101
|
+
"direction (dir:name), cols (@rN), factor, strength, scale, at, key, value …",
|
|
102
|
+
)
|
|
103
|
+
precision: Literal["merged", "adapter", "promote"] = "merged"
|
|
104
|
+
scope: str | None = Field(None, description="Declared scope: the edit is refused outside it.")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class CheckArgs(_Args):
|
|
108
|
+
patch: str | None = Field(None, description="A patch handle (p_…); default: everything staged.")
|
|
109
|
+
level: Literal["static", "numeric", "smoke"] = "smoke"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class TestArgs(_Args):
|
|
113
|
+
suite: str | None = Field(None, description="Suite name; default: all suites in wtests/.")
|
|
114
|
+
vs: str | None = Field(
|
|
115
|
+
None, description="Paired comparison against a commit, branch or 'base'."
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class JobsArgs(_Args):
|
|
120
|
+
job: str | None = Field(None, description="A job id; default: list jobs.")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class VcsArgs(_Args):
|
|
124
|
+
action: Literal[
|
|
125
|
+
"status",
|
|
126
|
+
"diff",
|
|
127
|
+
"commit",
|
|
128
|
+
"log",
|
|
129
|
+
"checkout",
|
|
130
|
+
"branch",
|
|
131
|
+
"revert",
|
|
132
|
+
"bisect",
|
|
133
|
+
"blame",
|
|
134
|
+
"merge",
|
|
135
|
+
]
|
|
136
|
+
message: str | None = None
|
|
137
|
+
rev: str | None = Field(
|
|
138
|
+
None, description="Revision: HEAD, HEAD~2, a branch, a commit id or 'base'."
|
|
139
|
+
)
|
|
140
|
+
a: str | None = None
|
|
141
|
+
b: str | None = None
|
|
142
|
+
name: str | None = Field(None, description="Branch name (branch) or branch to merge (merge).")
|
|
143
|
+
address: str | None = Field(None, description="For blame.")
|
|
144
|
+
suite: str | None = Field(None, description="For bisect.")
|
|
145
|
+
good: str | None = None
|
|
146
|
+
bad: str | None = None
|
|
147
|
+
strategies: dict[str, str] | None = Field(
|
|
148
|
+
None,
|
|
149
|
+
description="For merge: address → sum | rebase | orthogonalize | ties | pick:ours | pick:theirs.",
|
|
150
|
+
)
|
|
151
|
+
force: bool = False
|
|
152
|
+
n: int = Field(20, ge=1, le=500)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class ExportArgs(_Args):
|
|
156
|
+
kind: Literal["merged", "peft", "gguf", "bundle"]
|
|
157
|
+
path: str
|
|
158
|
+
base_model: str | None = None
|
|
159
|
+
max_rank: int = Field(64, ge=1, le=4096)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class RunArgs(_Args):
|
|
163
|
+
script: str = Field(
|
|
164
|
+
description="Path of a Python file; `import wspx; m = wspx.session()` inside it."
|
|
165
|
+
)
|
|
166
|
+
args: list[str] = Field(default_factory=list)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
@dataclass(frozen=True)
|
|
170
|
+
class ToolSpec:
|
|
171
|
+
name: str
|
|
172
|
+
args: type[_Args]
|
|
173
|
+
description: str
|
|
174
|
+
lab: bool = True
|
|
175
|
+
"""Needs live weights (else it can be served from the store while the lab is cold)."""
|
|
176
|
+
mutates: bool = False
|
|
177
|
+
|
|
178
|
+
def schema(self) -> dict[str, Any]:
|
|
179
|
+
return _inline(self.args.model_json_schema(by_alias=True))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
TOOLS: dict[str, ToolSpec] = {
|
|
183
|
+
spec.name: spec
|
|
184
|
+
for spec in [
|
|
185
|
+
ToolSpec(
|
|
186
|
+
"info",
|
|
187
|
+
InfoArgs,
|
|
188
|
+
"Model outline: blocks, layer types, residual stream, tying, coverage, branch "
|
|
189
|
+
"and HEAD. Start here.",
|
|
190
|
+
lab=False,
|
|
191
|
+
),
|
|
192
|
+
ToolSpec(
|
|
193
|
+
"ls",
|
|
194
|
+
LsArgs,
|
|
195
|
+
"List addresses matching a scope (glob, role, layer range) with shapes.",
|
|
196
|
+
lab=False,
|
|
197
|
+
),
|
|
198
|
+
ToolSpec(
|
|
199
|
+
"grep",
|
|
200
|
+
GrepArgs,
|
|
201
|
+
"Search weights for units matching an expression, or units that fire on "
|
|
202
|
+
"prompts. Returns ranked addresses and saves the full ranking as a result set @rN.",
|
|
203
|
+
),
|
|
204
|
+
ToolSpec(
|
|
205
|
+
"show",
|
|
206
|
+
ShowArgs,
|
|
207
|
+
"Summarise a slice of weights: stats, histogram, spectrum, vocabulary "
|
|
208
|
+
"tokens; raw values only on request (capped).",
|
|
209
|
+
),
|
|
210
|
+
ToolSpec(
|
|
211
|
+
"contrast",
|
|
212
|
+
ContrastArgs,
|
|
213
|
+
"Build a direction from two prompt sets (difference of means of the "
|
|
214
|
+
"residual stream), save it as dir:<name>, and list its top writers.",
|
|
215
|
+
mutates=True,
|
|
216
|
+
),
|
|
217
|
+
ToolSpec("generate", GenerateArgs, "Sample from the current working tree."),
|
|
218
|
+
ToolSpec(
|
|
219
|
+
"trace",
|
|
220
|
+
TraceArgs,
|
|
221
|
+
"Forward trace (logit lens, writers, routes), diff trace (--vs) or "
|
|
222
|
+
"attribution trace (with a reference input). Returns a summary and a trace handle.",
|
|
223
|
+
),
|
|
224
|
+
ToolSpec(
|
|
225
|
+
"edit",
|
|
226
|
+
EditArgs,
|
|
227
|
+
"Stage an op into the working tree. It compiles to concrete deltas, is "
|
|
228
|
+
"checked statically and numerically, and returns a patch handle p_….",
|
|
229
|
+
mutates=True,
|
|
230
|
+
),
|
|
231
|
+
ToolSpec(
|
|
232
|
+
"check",
|
|
233
|
+
CheckArgs,
|
|
234
|
+
"Diagnostics for staged edits: static, numeric and smoke (canary KL, "
|
|
235
|
+
"perplexity, degenerate output). Every diagnostic lists fixes.",
|
|
236
|
+
),
|
|
237
|
+
ToolSpec(
|
|
238
|
+
"test",
|
|
239
|
+
TestArgs,
|
|
240
|
+
"Run suites on the working tree; paired deltas with --vs. Held-out suites "
|
|
241
|
+
"return aggregates only.",
|
|
242
|
+
),
|
|
243
|
+
ToolSpec("jobs", JobsArgs, "Status and results of long-running jobs.", lab=False),
|
|
244
|
+
ToolSpec(
|
|
245
|
+
"vcs",
|
|
246
|
+
VcsArgs,
|
|
247
|
+
"Version control: status, diff, commit, log, checkout, branch, revert, bisect, "
|
|
248
|
+
"blame, merge. Commits run check first.",
|
|
249
|
+
mutates=True,
|
|
250
|
+
),
|
|
251
|
+
ToolSpec(
|
|
252
|
+
"export",
|
|
253
|
+
ExportArgs,
|
|
254
|
+
"Export the working tree: merged checkpoint, PEFT adapter, GGUF or portable bundle.",
|
|
255
|
+
),
|
|
256
|
+
ToolSpec(
|
|
257
|
+
"run",
|
|
258
|
+
RunArgs,
|
|
259
|
+
"Run a Python script in the lab with the SDK preloaded (no network, no "
|
|
260
|
+
"secrets). Output is capped; the full log is saved.",
|
|
261
|
+
mutates=True,
|
|
262
|
+
),
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _inline(schema: dict[str, Any]) -> dict[str, Any]:
|
|
268
|
+
"""Resolve ``$ref``/``$defs`` so every provider accepts the schema."""
|
|
269
|
+
defs = schema.get("$defs", {})
|
|
270
|
+
|
|
271
|
+
def walk(node: Any) -> Any:
|
|
272
|
+
if isinstance(node, dict):
|
|
273
|
+
if "$ref" in node:
|
|
274
|
+
name = node["$ref"].rsplit("/", 1)[-1]
|
|
275
|
+
return walk(copy.deepcopy(defs[name]))
|
|
276
|
+
return {k: walk(v) for k, v in node.items() if k != "$defs"}
|
|
277
|
+
if isinstance(node, list):
|
|
278
|
+
return [walk(v) for v in node]
|
|
279
|
+
return node
|
|
280
|
+
|
|
281
|
+
out: dict[str, Any] = walk(schema)
|
|
282
|
+
out.pop("title", None)
|
|
283
|
+
return out
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def mcp_tools() -> list[dict[str, Any]]:
|
|
287
|
+
return [
|
|
288
|
+
{"name": t.name, "description": t.description, "inputSchema": t.schema()}
|
|
289
|
+
for t in TOOLS.values()
|
|
290
|
+
]
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def anthropic_tools() -> list[dict[str, Any]]:
|
|
294
|
+
return [
|
|
295
|
+
{"name": t.name, "description": t.description, "input_schema": t.schema()}
|
|
296
|
+
for t in TOOLS.values()
|
|
297
|
+
]
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def openai_tools() -> list[dict[str, Any]]:
|
|
301
|
+
"""Responses API function tools."""
|
|
302
|
+
return [
|
|
303
|
+
{"type": "function", "name": t.name, "description": t.description, "parameters": t.schema()}
|
|
304
|
+
for t in TOOLS.values()
|
|
305
|
+
]
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def gemini_tools() -> list[dict[str, Any]]:
|
|
309
|
+
"""google-genai function declarations (full JSON Schema via ``parameters_json_schema``)."""
|
|
310
|
+
return [
|
|
311
|
+
{"name": t.name, "description": t.description, "parameters_json_schema": t.schema()}
|
|
312
|
+
for t in TOOLS.values()
|
|
313
|
+
]
|
wspx/vcs/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Version control of weight edits (§5.5): objects, refs and history walks.
|
|
2
|
+
|
|
3
|
+
This layer is pure data and needs no torch, so the control plane uses it
|
|
4
|
+
directly. Anything that needs weights (materialising, diff magnitudes,
|
|
5
|
+
merges) lives in the lab and calls into it.
|
|
6
|
+
|
|
7
|
+
Objects (content-addressed JSON in the store):
|
|
8
|
+
|
|
9
|
+
``patch`` one staged edit: op name and args, precision, and its delta blobs
|
|
10
|
+
``tree`` what is applied on top of the base, per tensor (``TreeState``)
|
|
11
|
+
``commit`` parents, base, tree, the patches it introduced, result hashes,
|
|
12
|
+
check report, evals, author (driver, session, calls) and message
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from wspx.vcs.repo import Commit, PatchRecord, Repo, normalize_tree, short_id, tree_key
|
|
16
|
+
|
|
17
|
+
__all__ = ["Commit", "PatchRecord", "Repo", "normalize_tree", "short_id", "tree_key"]
|