tokensafe 4.9.3 → 4.11.0
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.
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +32 -30
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/auto_inject.py +16 -6
- package/src/backend_release.py +17 -0
- package/src/batch_editor.py +53 -0
- package/src/bench/driver.py +38 -0
- package/src/bench/go_target.py +147 -58
- package/src/bench/react_target.py +103 -27
- package/src/mcp_server.py +1 -1
- package/src/retrofit.py +41 -1
- package/src/session_brief.py +3 -1
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/README.md
CHANGED
|
@@ -249,42 +249,44 @@ Full matrix and details: [docs/OUMV.md](docs/OUMV.md).
|
|
|
249
249
|
|
|
250
250
|
## Benchmarks
|
|
251
251
|
|
|
252
|
-
### Measured agent matrix
|
|
252
|
+
### Measured agent matrix v7 (Go + React, DeepSeek — 3 tasks × 5 runs × 3 arms)
|
|
253
253
|
|
|
254
254
|
Real 12-assertion oracle re-run after every step; tokens and cost from the provider's `usage`
|
|
255
255
|
payload. `baseline` = file/search/command tools, `tokensafe` = this product's MCP server
|
|
256
256
|
(`smart_read_file(endpoint="POST /api/…")` in one call → `apply_edits` with the hunk and inline
|
|
257
|
-
`verify="auto"`), `oumv` = the OUMV
|
|
258
|
-
`applyEdit mode=patch`
|
|
259
|
-
|
|
257
|
+
`verify="auto"`), `oumv` = the OUMV runtime on wire 1.7.0 (`observe L3` returns the handler, its
|
|
258
|
+
version and the same-package callees; `applyEdit mode=patch` carries an inline `verify` probe and
|
|
259
|
+
an actionable `-32009`). The Go sandbox is the benchmark module plus **200 generated service
|
|
260
|
+
files**; the React sandbox is a TaskManager store + component whose declared `npm test` is the
|
|
261
|
+
oracle.
|
|
260
262
|
|
|
261
263
|
| Arm | Solved | Mean steps | Mean input | Mean output | Cost/run |
|
|
262
264
|
| :--- | ---: | ---: | ---: | ---: | ---: |
|
|
263
|
-
| `baseline` | 15/15 | 5.
|
|
264
|
-
| `tokensafe` | 15/15 |
|
|
265
|
-
| `oumv` | 15/15 |
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
`
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
265
|
+
| `baseline` — Go | 15/15 | 5.9 | 32,231 | 1,712 | $0.0051 |
|
|
266
|
+
| `tokensafe` — Go | 15/15 | 3.1 | 8,240 | 401 | $0.0012 |
|
|
267
|
+
| `oumv` — Go | 15/15 | **2.7** | **6,712** | 433 | **$0.0011** |
|
|
268
|
+
| `baseline` — React | 15/15 | 4.9 | 18,396 | 1,591 | $0.0033 |
|
|
269
|
+
| `tokensafe` — React | 15/15 | 4.3 | 11,971 | 507 | $0.0017 |
|
|
270
|
+
| `oumv` — React | 15/15 | **4.2** | **9,814** | 642 | $0.0016 |
|
|
271
|
+
|
|
272
|
+
**vs baseline — Go: `oumv` -79.2% input, -77.8% cost,
|
|
273
|
+
-55.1% steps; `tokensafe` -74.4%,
|
|
274
|
+
-76.4%, -48.3%.** **React: `oumv`
|
|
275
|
+
-46.7% input, -52.7% cost, -14.9%
|
|
276
|
+
steps; `tokensafe` -34.9%, -50.4%,
|
|
277
|
+
-12.2%.** Every session in both matrices solved — the v6 max-steps
|
|
278
|
+
flounder on `product-validation` is gone. On Go the protocol arm creates the fix in 2.0 calls
|
|
279
|
+
against the product arm's 3.2 and ties it on the other two tasks; on React a component has no
|
|
280
|
+
endpoint for a route slice, so the protocol arm's `getSource → patch` path wins there as well.
|
|
281
|
+
|
|
282
|
+
Full method, per-task tables, both targets, the min–max spread and the limits (one model, alias
|
|
283
|
+
drift between dates, cache-hit share):
|
|
284
|
+
[`OUMV_AGENT_MATRIX_V7.md`](https://github.com/tokensafe-dev/tokensafe-backend/blob/main/go/benchmark/OUMV_AGENT_MATRIX_V7.md)
|
|
285
|
+
in the backend repo, generated from the run JSON by `go/benchmark/render_agent_matrix.py`. The
|
|
286
|
+
previous measured run is
|
|
287
|
+
[`OUMV_AGENT_MATRIX_V5.md`](https://github.com/tokensafe-dev/tokensafe-backend/blob/main/go/benchmark/OUMV_AGENT_MATRIX_V5.md).
|
|
288
|
+
|
|
289
|
+
--- | :--- | :--- | :---: | :---: | :---: | :---: |
|
|
288
290
|
| **Frontend (UI)** | `tokensafe-ui` | React 18/19 vs. TokenSafe UI | **21.0x** | **-95%** (1.5k vs 32.5k) | **1 vs 6 turns** | Zero reactive stale closures |
|
|
289
291
|
| **Backend (Python)** | `tokensafe-python` | Vanilla FastAPI vs. TokenSafe UARP | **23.5x** | **-96%** (1.4k vs 33.3k) | **1 vs 6 turns** | 0 DB pollution (automatic rollback) |
|
|
290
292
|
| **Backend (Go)** | `tokensafe-backend` | Vanilla Gin vs. TokenSafe Backend | **24.6x** | **-96%** (1.3k vs 33.9k) | **1 vs 6 turns** | 0 DB pollution + in-memory compiler guard |
|
|
@@ -372,7 +374,7 @@ No modeling: fifteen popular repositories across 10 languages (Python, TypeScrip
|
|
|
372
374
|
| flask (Py) | Full-suite pytest output | 6,402 | 6,191 | **-3.3%** | PASS |
|
|
373
375
|
| fastapi (Py) | Git diff churn -> slice | 416 | 393 | **-5.5%** | PASS |
|
|
374
376
|
|
|
375
|
-
Aggregate: **~25.7M measured tokens saved** per traced pass over all 15 repositories in 10 languages (
|
|
377
|
+
Aggregate: **~25.7M measured tokens saved** per traced pass over all 15 repositories in 10 languages (186 gated-OK rows; input at `$3/M`, output axis at `$15/M`, KV-cache hits billed at `$0.30/M`). Clean pytest suites honestly score ~0-3% — savings are never invented. **17 gate-FAILs and 21 skips are published with reasons** on the live page (e.g. fastapi's test-output: strict warning filters escalate a `pytest-asyncio` deprecation into a pytest `INTERNALERROR`; whole-repo API surfaces bigger than hub crawls for fastapi/httpie; httpie's `core.py` refuses skeletonization — one function is most of the file). Full table + raw JSON: [docs/BENCHMARK_REAL.md](docs/BENCHMARK_REAL.md) · live page: <https://tokensafe.dev/bench> · methodology post: <https://tokensafe.dev/blog/real-repo-benchmark-5-repos>. Reproduce:
|
|
376
378
|
|
|
377
379
|
```bash
|
|
378
380
|
tokensafe bench --real # all 15 pre-registered repos
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
|
|
5
5
|
"homepage": "https://tokensafe.dev",
|
|
6
6
|
"license": "Apache-2.0",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"mcpName": "dev.tokensafe/tokensafe",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.11.0",
|
|
5
5
|
"description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
|
|
6
6
|
"main": "bin/tokensafe.js",
|
|
7
7
|
"bin": {
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"displayName": "TokenSafe",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.11.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
|
|
7
7
|
"logo": "assets/logo.png",
|
package/server.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "dev.tokensafe/tokensafe",
|
|
4
4
|
"title": "TokenSafe",
|
|
5
5
|
"description": "Your AI agent is smart enough to code all day. Local firewall & zero-loss runtime.",
|
|
6
|
-
"version": "4.
|
|
6
|
+
"version": "4.11.0",
|
|
7
7
|
"websiteUrl": "https://tokensafe.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"url": "https://github.com/tokensafe-dev/tokensafe",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"registryType": "npm",
|
|
24
24
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
25
25
|
"identifier": "tokensafe",
|
|
26
|
-
"version": "4.
|
|
26
|
+
"version": "4.11.0",
|
|
27
27
|
"runtimeHint": "npx",
|
|
28
28
|
"transport": {
|
|
29
29
|
"type": "stdio"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"registryType": "pypi",
|
|
40
40
|
"registryBaseUrl": "https://pypi.org",
|
|
41
41
|
"identifier": "tokensafe",
|
|
42
|
-
"version": "4.
|
|
42
|
+
"version": "4.11.0",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/auto_inject.py
CHANGED
|
@@ -28,6 +28,7 @@ import subprocess
|
|
|
28
28
|
from typing import Any, Dict, List, Optional, Tuple
|
|
29
29
|
|
|
30
30
|
from src import oumv_policy
|
|
31
|
+
from src.backend_release import BACKEND_RELEASE_TAG
|
|
31
32
|
from src.retrofit import detect_project_stack, generate_config, get_adapters_catalog
|
|
32
33
|
|
|
33
34
|
_PYHOOKS_DIRNAME = "pyhooks"
|
|
@@ -293,7 +294,7 @@ def go_patch_state(workspace: str) -> Dict[str, Any]:
|
|
|
293
294
|
_GO_MODULE = "github.com/tokensafe-dev/tokensafe-backend/go"
|
|
294
295
|
# Keep in step with the backend release tag (go/vX.Y.Z): injection must never
|
|
295
296
|
# downgrade an adapter that is already newer than this pin.
|
|
296
|
-
_GO_MODULE_VERSION =
|
|
297
|
+
_GO_MODULE_VERSION = BACKEND_RELEASE_TAG
|
|
297
298
|
|
|
298
299
|
|
|
299
300
|
def _version_tuple(tag: str):
|
|
@@ -1376,17 +1377,17 @@ def revert_dotnet_patch(workspace: str) -> Dict[str, Any]:
|
|
|
1376
1377
|
# Pinned to the backend release: the sidecars are single files, so the cache is
|
|
1377
1378
|
# content-addressed by SHA-256 and a clean machine downloads the exact bytes the
|
|
1378
1379
|
# release was certified from. Bump both the tag and the hashes together.
|
|
1379
|
-
_SIDECAR_RELEASE_TAG =
|
|
1380
|
+
_SIDECAR_RELEASE_TAG = BACKEND_RELEASE_TAG
|
|
1380
1381
|
_SIDECARS = {
|
|
1381
1382
|
"spring": (
|
|
1382
1383
|
"java/src/dev/tokensafe/oumv/OumvSpring.java",
|
|
1383
1384
|
"OumvSpring.java",
|
|
1384
|
-
"
|
|
1385
|
+
"7d228f3eedd4d401cbbef9b0722a9d215083f926ed1ef8e083c58456205595c4",
|
|
1385
1386
|
),
|
|
1386
1387
|
"php": (
|
|
1387
1388
|
"php/bin/oumv-php",
|
|
1388
1389
|
"oumv-php",
|
|
1389
|
-
"
|
|
1390
|
+
"7f2939cf909d91dbbe6cf92295e5db0141f8b3533127a7bbc59bfad3d388b8b3",
|
|
1390
1391
|
),
|
|
1391
1392
|
}
|
|
1392
1393
|
|
|
@@ -1410,10 +1411,19 @@ def sidecar_run_command(kind: str, sidecar_path: str, workspace: str) -> Optiona
|
|
|
1410
1411
|
# dispatch and observe L4 into recorded traces (wire 1.6.0).
|
|
1411
1412
|
app_url = (os.environ.get("TOKENSAFE_OUMV_APP_URL") or "").strip().rstrip("/")
|
|
1412
1413
|
dispatch = f" --app-url {app_url}" if app_url else ""
|
|
1414
|
+
# §14.2: a DSN turns on the read-only query surface; without one the sidecar
|
|
1415
|
+
# answers -32006 and never advertises the capability.
|
|
1416
|
+
db_dsn = (os.environ.get("TOKENSAFE_OUMV_DB") or "").strip()
|
|
1417
|
+
query_flag = f" --db {db_dsn}" if db_dsn else ""
|
|
1418
|
+
if (os.environ.get("TOKENSAFE_OUMV_PERMISSIONS_QUERY") or "").strip().lower() in {"false", "0", "no", "off"}:
|
|
1419
|
+
query_flag += " --no-query"
|
|
1413
1420
|
if kind == "spring":
|
|
1414
|
-
return
|
|
1421
|
+
return (
|
|
1422
|
+
f"tokensafe run-backend java {sidecar_path} --root {workspace} --port 7331"
|
|
1423
|
+
f"{read_only}{dispatch}{query_flag}"
|
|
1424
|
+
)
|
|
1415
1425
|
if kind == "php":
|
|
1416
|
-
return f"tokensafe run-backend php -S 127.0.0.1:7332 {sidecar_path} --root {workspace}"
|
|
1426
|
+
return f"tokensafe run-backend php -S 127.0.0.1:7332 {sidecar_path} --root {workspace}{query_flag}"
|
|
1417
1427
|
return None
|
|
1418
1428
|
|
|
1419
1429
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""The backend release the engine ships against.
|
|
2
|
+
|
|
3
|
+
Every place that names a backend artifact — the `go get` pin for the Go adapter,
|
|
4
|
+
the `~/.tokensafe/sidecars` content hashes, and the brief that tells an agent how
|
|
5
|
+
to activate a backend — reads this tag, so a release bumps one string instead of
|
|
6
|
+
chasing literals that silently point at an older certified build.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
# Backend tag (`vX.Y.Z`); the Go module resolves against the matching `go/vX.Y.Z`,
|
|
12
|
+
# which the backend release workflow creates alongside it.
|
|
13
|
+
BACKEND_RELEASE_TAG = "v0.20.0"
|
|
14
|
+
|
|
15
|
+
# Wire version that tag speaks. Printed in briefs so an agent never mixes a
|
|
16
|
+
# backend release with an older protocol line.
|
|
17
|
+
BACKEND_WIRE_VERSION = "1.8.0"
|
package/src/batch_editor.py
CHANGED
|
@@ -63,6 +63,7 @@ _VERIFY_SUBCOMMAND_ALLOWLIST = {
|
|
|
63
63
|
_VERIFY_FORBIDDEN_FLAGS = frozenset({
|
|
64
64
|
"-c", "-e", "--eval", "-p", "--print", "-r", "--require",
|
|
65
65
|
"--import", "--loader", "-exec", "--exec", "-toolexec",
|
|
66
|
+
"--yes", "--package", "--registry",
|
|
66
67
|
})
|
|
67
68
|
_DISALLOWED_SYSTEM_DIRS = frozenset({"/etc", "/usr", "/bin", "/sbin", "/System", "/private/etc"})
|
|
68
69
|
|
|
@@ -197,6 +198,49 @@ def validate_verify_command(
|
|
|
197
198
|
if exe in _VERIFY_SIMPLE_RUNNERS:
|
|
198
199
|
return argv, None, None
|
|
199
200
|
|
|
201
|
+
if exe == "npx":
|
|
202
|
+
# `npx <bin>` is how Node projects run their locally installed test tools
|
|
203
|
+
# (`npx tsx src/bin/oracle-runner.ts`, `npx vitest run`). Only a binary that
|
|
204
|
+
# already exists in this project's node_modules/.bin is allowed: that proves
|
|
205
|
+
# no package download, and the resolved path is never taken from the model —
|
|
206
|
+
# the path-qualified check above still bans `./node_modules/.bin/...`.
|
|
207
|
+
# `--no-install` is npm's "never fetch" switch, so it is allowed as a prefix.
|
|
208
|
+
rest = list(args_rest)
|
|
209
|
+
while rest and rest[0] in ("--no-install", "--no"):
|
|
210
|
+
rest.pop(0)
|
|
211
|
+
if any(
|
|
212
|
+
a in ("-y", "--call") or a.startswith(("--yes", "--package", "--registry"))
|
|
213
|
+
for a in rest
|
|
214
|
+
):
|
|
215
|
+
return (
|
|
216
|
+
None,
|
|
217
|
+
"'npx' verify commands may not install packages (--yes/--package/--registry/--call are disallowed).",
|
|
218
|
+
"VERIFY_COMMAND_BLOCKED",
|
|
219
|
+
)
|
|
220
|
+
bin_name = rest[0] if rest else ""
|
|
221
|
+
if not bin_name or bin_name.startswith("-") or "/" in bin_name or "\\" in bin_name:
|
|
222
|
+
return (
|
|
223
|
+
None,
|
|
224
|
+
"'npx' verify commands must name a locally installed binary: npx <bin> [args].",
|
|
225
|
+
"VERIFY_COMMAND_BLOCKED",
|
|
226
|
+
)
|
|
227
|
+
project = os.path.realpath(base_dir) if base_dir else ""
|
|
228
|
+
local_bin = os.path.join(project, "node_modules", ".bin", bin_name) if project else ""
|
|
229
|
+
inside = False
|
|
230
|
+
if local_bin:
|
|
231
|
+
try:
|
|
232
|
+
inside = os.path.commonpath([os.path.realpath(local_bin), project]) == project
|
|
233
|
+
except ValueError:
|
|
234
|
+
inside = False
|
|
235
|
+
if not inside or not os.path.isfile(local_bin):
|
|
236
|
+
return (
|
|
237
|
+
None,
|
|
238
|
+
f"'{bin_name}' is not installed in this project's node_modules/.bin; "
|
|
239
|
+
"npx cannot fetch packages for apply_edits.verify.",
|
|
240
|
+
"VERIFY_COMMAND_BLOCKED",
|
|
241
|
+
)
|
|
242
|
+
return argv, None, None
|
|
243
|
+
|
|
200
244
|
return (
|
|
201
245
|
None,
|
|
202
246
|
f"Executable '{raw_exe}' is not in the allowlisted verification runners for apply_edits.verify.",
|
|
@@ -423,6 +467,15 @@ def detect_verify_command(base_dir: str, files: Optional[List[str]] = None) -> O
|
|
|
423
467
|
with open(pkg, "r", encoding="utf-8") as f:
|
|
424
468
|
scripts = (_json.load(f) or {}).get("scripts") or {}
|
|
425
469
|
if isinstance(scripts, dict) and scripts.get("test"):
|
|
470
|
+
# Run the project's own script through the package manager that owns
|
|
471
|
+
# the lockfile: `npm test` on a bun/pnpm/yarn checkout fails before it
|
|
472
|
+
# ever reaches the test script (and would roll a good edit back).
|
|
473
|
+
if has("bun.lock") or has("bun.lockb"):
|
|
474
|
+
return ["bun", "run", "test"]
|
|
475
|
+
if has("pnpm-lock.yaml"):
|
|
476
|
+
return ["pnpm", "test"]
|
|
477
|
+
if has("yarn.lock"):
|
|
478
|
+
return ["yarn", "test"]
|
|
426
479
|
return ["npm", "test", "--silent"]
|
|
427
480
|
except (OSError, ValueError):
|
|
428
481
|
pass
|
package/src/bench/driver.py
CHANGED
|
@@ -153,12 +153,44 @@ class DeepSeekClient:
|
|
|
153
153
|
|
|
154
154
|
ToolFn = Callable[..., Any]
|
|
155
155
|
|
|
156
|
+
# Bound on the per-call evidence kept in the artifact: enough to recognise a
|
|
157
|
+
# repeated/abandoned call, small enough that 14 steps × a few calls stay tiny.
|
|
158
|
+
ARGS_PREVIEW_CHARS = 160
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _args_preview(args: Dict[str, Any]) -> str:
|
|
162
|
+
try:
|
|
163
|
+
return json.dumps(args, ensure_ascii=False)[:ARGS_PREVIEW_CHARS]
|
|
164
|
+
except (TypeError, ValueError):
|
|
165
|
+
return ""
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _error_code(result: Any) -> Optional[str]:
|
|
169
|
+
"""The tool error code, or a short string when the result is not coded.
|
|
170
|
+
|
|
171
|
+
Matrix v6 could not tell an abandoned OUMV loop from a slow one: `-32009` and
|
|
172
|
+
the npx runner rejection were only visible inside the model's context. Keeping
|
|
173
|
+
the code (not the whole payload) makes that visible in the artifact.
|
|
174
|
+
"""
|
|
175
|
+
if not isinstance(result, dict) or "error" not in result:
|
|
176
|
+
return None
|
|
177
|
+
error = result.get("error")
|
|
178
|
+
if isinstance(error, dict):
|
|
179
|
+
code = error.get("code")
|
|
180
|
+
if code is not None:
|
|
181
|
+
return str(code)[:40]
|
|
182
|
+
message = error.get("message") or error.get("reason")
|
|
183
|
+
return str(message)[:80] if message is not None else "error"
|
|
184
|
+
return str(error)[:80]
|
|
185
|
+
|
|
156
186
|
|
|
157
187
|
@dataclass
|
|
158
188
|
class StepRecord:
|
|
159
189
|
index: int
|
|
160
190
|
tool_calls: List[str] = field(default_factory=list)
|
|
161
191
|
result_chars: List[int] = field(default_factory=list)
|
|
192
|
+
tool_args: List[str] = field(default_factory=list)
|
|
193
|
+
error_codes: List[Optional[str]] = field(default_factory=list)
|
|
162
194
|
duration_ms: float = 0.0
|
|
163
195
|
oracle_passed: Optional[int] = None
|
|
164
196
|
oracle_failed: List[str] = field(default_factory=list)
|
|
@@ -206,6 +238,8 @@ def run_agent(
|
|
|
206
238
|
args = json.loads(call["function"].get("arguments") or "{}")
|
|
207
239
|
except json.JSONDecodeError:
|
|
208
240
|
args = {}
|
|
241
|
+
if not isinstance(args, dict):
|
|
242
|
+
args = {}
|
|
209
243
|
fn = registry.get(name)
|
|
210
244
|
try:
|
|
211
245
|
result = fn(**args) if fn else {"error": f"unknown tool {name}"}
|
|
@@ -215,6 +249,8 @@ def run_agent(
|
|
|
215
249
|
tool_counts[name] = tool_counts.get(name, 0) + 1
|
|
216
250
|
tool_chars[name] = tool_chars.get(name, 0) + len(content)
|
|
217
251
|
record.result_chars.append(len(content))
|
|
252
|
+
record.tool_args.append(_args_preview(args))
|
|
253
|
+
record.error_codes.append(_error_code(result))
|
|
218
254
|
messages.append({
|
|
219
255
|
"role": "tool",
|
|
220
256
|
"tool_call_id": call.get("id", ""),
|
|
@@ -252,6 +288,8 @@ def run_agent(
|
|
|
252
288
|
"index": s.index,
|
|
253
289
|
"tools": s.tool_calls,
|
|
254
290
|
"result_chars": s.result_chars,
|
|
291
|
+
"tool_args": s.tool_args,
|
|
292
|
+
"error_codes": s.error_codes,
|
|
255
293
|
"oracle_passed": s.oracle_passed,
|
|
256
294
|
"oracle_failed": s.oracle_failed,
|
|
257
295
|
"note": s.note,
|
package/src/bench/go_target.py
CHANGED
|
@@ -159,6 +159,56 @@ def choose_scoped_hunk(
|
|
|
159
159
|
return scoped, {"hunk": index, "startLine": scope_start, "endLine": scope_end}
|
|
160
160
|
|
|
161
161
|
|
|
162
|
+
def fill_missing_hunk_windows(
|
|
163
|
+
hunks: Optional[List[Dict[str, Any]]],
|
|
164
|
+
window: Optional[Tuple[int, int]],
|
|
165
|
+
) -> Tuple[List[Dict[str, Any]], List[Dict[str, int]]]:
|
|
166
|
+
"""Pre-fills a missing startLine/endLine from the window the agent just read.
|
|
167
|
+
|
|
168
|
+
The measured matrix v6 failure was the opposite of -32011: the model built the
|
|
169
|
+
hunk from the code it expected, so the text was absent and -32009 had nothing
|
|
170
|
+
to scope. A hunk that omits its bounds still means "the lines I just read", so
|
|
171
|
+
borrowing the last observe L3 / getSource window is deterministic and costs no
|
|
172
|
+
extra call. Hunks that already carry both bounds are left untouched, and the
|
|
173
|
+
caller's list is never mutated.
|
|
174
|
+
"""
|
|
175
|
+
if not isinstance(hunks, list) or not hunks or not window:
|
|
176
|
+
return (hunks if isinstance(hunks, list) else []), []
|
|
177
|
+
try:
|
|
178
|
+
win_start, win_end = int(window[0]), int(window[1])
|
|
179
|
+
except (TypeError, ValueError):
|
|
180
|
+
return hunks, []
|
|
181
|
+
if win_end < win_start:
|
|
182
|
+
return hunks, []
|
|
183
|
+
|
|
184
|
+
def _bound(value: Any) -> Optional[int]:
|
|
185
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
186
|
+
return None
|
|
187
|
+
return int(value)
|
|
188
|
+
|
|
189
|
+
filled: List[Dict[str, Any]] = []
|
|
190
|
+
notes: List[Dict[str, int]] = []
|
|
191
|
+
for index, hunk in enumerate(hunks):
|
|
192
|
+
if not isinstance(hunk, dict):
|
|
193
|
+
filled.append(hunk)
|
|
194
|
+
continue
|
|
195
|
+
start, end = _bound(hunk.get("startLine")), _bound(hunk.get("endLine"))
|
|
196
|
+
if start is not None and end is not None:
|
|
197
|
+
filled.append(hunk)
|
|
198
|
+
continue
|
|
199
|
+
span = str(hunk.get("target") or "").count("\n") + 1
|
|
200
|
+
new_start = start if start is not None else win_start
|
|
201
|
+
new_end = end if end is not None else win_end
|
|
202
|
+
if new_end < new_start:
|
|
203
|
+
new_end = new_start + span - 1
|
|
204
|
+
clone = dict(hunk)
|
|
205
|
+
clone["startLine"] = new_start
|
|
206
|
+
clone["endLine"] = new_end
|
|
207
|
+
filled.append(clone)
|
|
208
|
+
notes.append({"hunk": index, "startLine": new_start, "endLine": new_end})
|
|
209
|
+
return filled, notes
|
|
210
|
+
|
|
211
|
+
|
|
162
212
|
class GoWorkspace:
|
|
163
213
|
def __init__(self, task_id: str, files: int = 0):
|
|
164
214
|
if task_id not in TASKS:
|
|
@@ -382,30 +432,50 @@ class GoWorkspace:
|
|
|
382
432
|
replacement: str = "",
|
|
383
433
|
symbol: str = "",
|
|
384
434
|
hunks: Optional[List[Dict[str, Any]]] = None,
|
|
435
|
+
verify: Optional[Dict[str, Any]] = None,
|
|
385
436
|
) -> Any:
|
|
386
|
-
"""applyEdit with
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
437
|
+
"""applyEdit with deterministic window filling and one -32011 recovery.
|
|
438
|
+
|
|
439
|
+
Before the first attempt a hunk that omits startLine/endLine inherits the
|
|
440
|
+
window this agent just read (observe L3 / getSource): the model means those
|
|
441
|
+
lines even when it does not say so, and a scoped hunk is what `-32009
|
|
442
|
+
target_not_found` cannot help with — the text itself was wrong, so that
|
|
443
|
+
error is never retried here.
|
|
444
|
+
|
|
445
|
+
If the target genuinely repeats, the runtime answers `-32011 target_not_unique`
|
|
446
|
+
with the occurrence lines. When exactly one of them lies inside the window,
|
|
447
|
+
retry with that window. Two candidates are never resolved by guessing: the
|
|
448
|
+
error goes back to the model instead.
|
|
392
449
|
"""
|
|
450
|
+
effective_hunks = hunks
|
|
451
|
+
prefilled: List[Dict[str, int]] = []
|
|
452
|
+
window = self._read_windows.get(self._window_key(path))
|
|
453
|
+
if mode == "patch" and hunks and window:
|
|
454
|
+
effective_hunks, prefilled = fill_missing_hunk_windows(hunks, window)
|
|
455
|
+
if not prefilled:
|
|
456
|
+
effective_hunks = hunks
|
|
393
457
|
params: Dict[str, Any] = {
|
|
394
458
|
"path": path,
|
|
395
459
|
"expectedVersion": expected_version,
|
|
396
460
|
**({"mode": mode} if mode else {}),
|
|
397
461
|
**({"replacement": replacement} if replacement else {}),
|
|
398
462
|
**({"symbol": symbol} if symbol else {}),
|
|
399
|
-
**({"hunks":
|
|
463
|
+
**({"hunks": effective_hunks} if effective_hunks else {}),
|
|
464
|
+
**({"verify": verify} if verify else {}),
|
|
400
465
|
}
|
|
401
466
|
result = self.oumv("oumv/applyEdit", params)
|
|
467
|
+
if prefilled and isinstance(result, dict) and not result.get("error"):
|
|
468
|
+
result = dict(result)
|
|
469
|
+
result["prefilledWindows"] = {
|
|
470
|
+
"source": "last observe L3 / getSource window",
|
|
471
|
+
"hunks": prefilled,
|
|
472
|
+
}
|
|
402
473
|
error = result.get("error") if isinstance(result, dict) else None
|
|
403
474
|
if mode == "patch" and isinstance(error, dict) and error.get("code") == -32011:
|
|
404
475
|
data = dict(error.get("data") or {})
|
|
405
476
|
if not data.get("reason") and "not_unique" in str(error.get("message", "")):
|
|
406
477
|
data["reason"] = "target_not_unique"
|
|
407
|
-
|
|
408
|
-
chosen = choose_scoped_hunk(hunks, data, window)
|
|
478
|
+
chosen = choose_scoped_hunk(effective_hunks, data, window)
|
|
409
479
|
if chosen is not None:
|
|
410
480
|
scoped_hunks, scope = chosen
|
|
411
481
|
retry = self.oumv("oumv/applyEdit", {**params, "hunks": scoped_hunks})
|
|
@@ -619,10 +689,19 @@ OUMV_TOOLS: List[Dict[str, Any]] = BASE_TOOLS + [
|
|
|
619
689
|
"type": "function",
|
|
620
690
|
"function": {
|
|
621
691
|
"name": "oumv_getSource",
|
|
622
|
-
"description": "OUMV source read with the sha256 OCC version token.",
|
|
692
|
+
"description": "OUMV source read with the sha256 OCC version token. Optional startLine/endLine read one line range; ifVersion returns the token unchanged when it still matches (a cheap freshness check).",
|
|
623
693
|
"parameters": {
|
|
624
694
|
"type": "object",
|
|
625
|
-
"properties": {
|
|
695
|
+
"properties": {
|
|
696
|
+
"path": {"type": "string"},
|
|
697
|
+
"symbol": {"type": "string"},
|
|
698
|
+
"startLine": {"type": "integer", "description": "1-based first line of the range to return"},
|
|
699
|
+
"endLine": {"type": "integer", "description": "1-based last line of the range to return"},
|
|
700
|
+
"ifVersion": {
|
|
701
|
+
"type": "string",
|
|
702
|
+
"description": "Version you already hold; the runtime can answer 'unchanged' instead of re-sending bytes",
|
|
703
|
+
},
|
|
704
|
+
},
|
|
626
705
|
"required": ["path"],
|
|
627
706
|
},
|
|
628
707
|
},
|
|
@@ -645,9 +724,11 @@ OUMV_TOOLS: List[Dict[str, Any]] = BASE_TOOLS + [
|
|
|
645
724
|
"hunks": {
|
|
646
725
|
"type": "array",
|
|
647
726
|
"description": (
|
|
648
|
-
"mode='patch': exact snippets to splice, applied in order.
|
|
649
|
-
"from the L3 slice
|
|
650
|
-
"
|
|
727
|
+
"mode='patch': exact snippets to splice, applied in order. `target` must be copied "
|
|
728
|
+
"verbatim from the observe L3 slice (the current, broken code). Every hunk should "
|
|
729
|
+
"carry startLine/endLine from that slice: without them a snippet that occurs more "
|
|
730
|
+
"than once is rejected with -32011 (the error carries the occurrence lines and a "
|
|
731
|
+
"scoped retry)."
|
|
651
732
|
),
|
|
652
733
|
"items": {
|
|
653
734
|
"type": "object",
|
|
@@ -659,47 +740,39 @@ OUMV_TOOLS: List[Dict[str, Any]] = BASE_TOOLS + [
|
|
|
659
740
|
"description": "1-based first line to search, from observe L3; makes a repeated target unique",
|
|
660
741
|
},
|
|
661
742
|
"endLine": {"type": "integer", "description": "1-based last line to search"},
|
|
743
|
+
"replaceAll": {
|
|
744
|
+
"type": "boolean",
|
|
745
|
+
"description": "Replace every occurrence of the target inside the window instead of requiring one",
|
|
746
|
+
},
|
|
662
747
|
},
|
|
663
748
|
"required": ["target", "replacement"],
|
|
664
749
|
},
|
|
665
750
|
},
|
|
666
751
|
"replacement": {"type": "string", "description": "New content, or the new declaration body for mode='symbol'"},
|
|
667
752
|
"symbol": {"type": "string", "description": "Declaration to replace when mode='symbol'"},
|
|
753
|
+
"verify": {
|
|
754
|
+
"type": "object",
|
|
755
|
+
"description": (
|
|
756
|
+
"Run this verify request in the same call after the edit (needs runtime capability "
|
|
757
|
+
"mutate.inlineVerify): one call returns the edit and its verdict."
|
|
758
|
+
),
|
|
759
|
+
"properties": {
|
|
760
|
+
"target": {"type": "string", "description": "Endpoint to probe, e.g. 'POST /api/products'"},
|
|
761
|
+
"action": {"type": "string", "description": "Verify action label, e.g. 'probe'"},
|
|
762
|
+
"payload": {"type": "object", "description": "JSON body, copied from the repro"},
|
|
763
|
+
"sandbox": {
|
|
764
|
+
"type": "object",
|
|
765
|
+
"description": "Optional transactional dry run; mode='rollback' runs the request and rolls the database back",
|
|
766
|
+
"properties": {"mode": {"type": "string", "enum": ["rollback"]}},
|
|
767
|
+
},
|
|
768
|
+
},
|
|
769
|
+
"required": ["target"],
|
|
770
|
+
},
|
|
668
771
|
},
|
|
669
772
|
"required": ["path", "expectedVersion"],
|
|
670
773
|
},
|
|
671
774
|
},
|
|
672
775
|
},
|
|
673
|
-
{
|
|
674
|
-
"type": "function",
|
|
675
|
-
"function": {
|
|
676
|
-
"name": "oumv_verify",
|
|
677
|
-
"description": "OUMV verify: dispatch a request (optionally with a JSON body) in-process and see status/body without starting a server.",
|
|
678
|
-
"parameters": {
|
|
679
|
-
"type": "object",
|
|
680
|
-
"properties": {
|
|
681
|
-
"target": {"type": "string", "description": "e.g. 'GET /api/products' or 'POST /api/orders'"},
|
|
682
|
-
"payload": {"type": "object", "description": "JSON body for POST/PUT targets"},
|
|
683
|
-
},
|
|
684
|
-
"required": ["target"],
|
|
685
|
-
},
|
|
686
|
-
},
|
|
687
|
-
},
|
|
688
|
-
{
|
|
689
|
-
"type": "function",
|
|
690
|
-
"function": {
|
|
691
|
-
"name": "oumv_understand",
|
|
692
|
-
"description": "OUMV understand: impact analysis for an endpoint target.",
|
|
693
|
-
"parameters": {
|
|
694
|
-
"type": "object",
|
|
695
|
-
"properties": {
|
|
696
|
-
"query": {"type": "string", "enum": ["impact", "causality"]},
|
|
697
|
-
"target": {"type": "string"},
|
|
698
|
-
},
|
|
699
|
-
"required": ["query", "target"],
|
|
700
|
-
},
|
|
701
|
-
},
|
|
702
|
-
},
|
|
703
776
|
]
|
|
704
777
|
|
|
705
778
|
|
|
@@ -770,14 +843,24 @@ def registry(ws: GoWorkspace, arm: str) -> Dict[str, Any]:
|
|
|
770
843
|
if arm == "oumv":
|
|
771
844
|
tools.update({
|
|
772
845
|
"oumv_observe": lambda level, target="": ws.oumv("oumv/observe", {"level": level, "target": target}),
|
|
773
|
-
"oumv_getSource": lambda path, symbol=""
|
|
774
|
-
|
|
846
|
+
"oumv_getSource": lambda path, symbol="", startLine=None, endLine=None, ifVersion="": ws.oumv(
|
|
847
|
+
"oumv/getSource",
|
|
848
|
+
{
|
|
849
|
+
"path": path,
|
|
850
|
+
"symbol": symbol,
|
|
851
|
+
**({"startLine": startLine} if startLine is not None else {}),
|
|
852
|
+
**({"endLine": endLine} if endLine is not None else {}),
|
|
853
|
+
**({"ifVersion": ifVersion} if ifVersion else {}),
|
|
854
|
+
},
|
|
855
|
+
),
|
|
856
|
+
"oumv_applyEdit": lambda path, expectedVersion, mode="", replacement="", symbol="", hunks=None, verify=None: ws.apply_edit_scoped(
|
|
775
857
|
path,
|
|
776
858
|
expectedVersion,
|
|
777
859
|
mode=mode,
|
|
778
860
|
replacement=replacement,
|
|
779
861
|
symbol=symbol,
|
|
780
862
|
hunks=hunks,
|
|
863
|
+
verify=verify,
|
|
781
864
|
),
|
|
782
865
|
"oumv_verify": lambda target, payload=None: ws.oumv(
|
|
783
866
|
"oumv/verify", {"target": target, "action": "probe", "payload": payload}
|
|
@@ -809,18 +892,24 @@ SYSTEM_TOKENSAFE = (
|
|
|
809
892
|
)
|
|
810
893
|
|
|
811
894
|
SYSTEM_OUMV = (
|
|
812
|
-
"You are a senior Go engineer
|
|
813
|
-
"The
|
|
814
|
-
"
|
|
815
|
-
"
|
|
816
|
-
"
|
|
817
|
-
"
|
|
818
|
-
"
|
|
819
|
-
"
|
|
820
|
-
"
|
|
821
|
-
"
|
|
822
|
-
"
|
|
823
|
-
"
|
|
895
|
+
"You are a senior Go engineer in a small Go module that exposes the OUMV runtime. "
|
|
896
|
+
"The repro names the endpoint; go straight to its handler and stop when the oracle passes. "
|
|
897
|
+
"(1) oumv_observe L3 with the endpoint (\"POST /api/products\"), one call, never L2: the payload has the "
|
|
898
|
+
"handler source, its path, startLine/endLine, the OCC version, and `calls`: [{name, file, line}] for "
|
|
899
|
+
"same-package declarations it calls. "
|
|
900
|
+
"(2) If the fix is in a callee, read it once: oumv_getSource(path=<file from calls>, symbol=<name>). Use "
|
|
901
|
+
"paths exactly as the payload prints them; never strip a directory. Do not search for a name the payload "
|
|
902
|
+
"already located, and do not read the oracle or the tests. "
|
|
903
|
+
"(3) oumv_applyEdit with that path, expectedVersion, mode=\"patch\" and hunks=[{target: THE EXACT TEXT AS IT "
|
|
904
|
+
"APPEARS IN THE SLICE, the current, broken code copied verbatim with its whitespace, never the fixed code; "
|
|
905
|
+
"replacement; startLine and endLine from the slice}]. Every hunk MUST carry startLine and endLine. "
|
|
906
|
+
"(4) On -32009 the target is absent: rebuild it from error.data.nearest, error.data.occurrences or "
|
|
907
|
+
"error.data.suggestedWindow (or mode=\"symbol\" + symbol) and retry once. "
|
|
908
|
+
"(5) Verify in the same call ONLY for a stateless task: oumv_applyEdit(verify={target: <endpoint>, action: "
|
|
909
|
+
"\"probe\", payload: <from the repro>}). A task whose repro needs a second request in the same process (a "
|
|
910
|
+
"duplicate key, a retry after the first call) is stateful: inline verify probes one request and would "
|
|
911
|
+
"report a false failure there, so run the oracle with run_command instead. "
|
|
912
|
+
"Do not fetch whole files, do not use write_file, and avoid list_files/read_file. Tests are read-only."
|
|
824
913
|
)
|
|
825
914
|
|
|
826
915
|
|
|
@@ -145,6 +145,15 @@ class ReactWorkspace:
|
|
|
145
145
|
# copying them: the temp dir lives inside the repo, so a symlink is enough.
|
|
146
146
|
if (PACKAGE / "node_modules").is_dir():
|
|
147
147
|
os.symlink(PACKAGE / "node_modules", self.dir / "node_modules")
|
|
148
|
+
# `apply_edits(verify="auto")` runs the project's own declared test command,
|
|
149
|
+
# which here is `npm test --silent`. Point that script at the 12-assertion
|
|
150
|
+
# oracle so the verdict the agent sees is the one the harness scores; leaving
|
|
151
|
+
# `vitest run` would run the package's own unit suite instead. Only the
|
|
152
|
+
# throwaway copy is rewritten — the checked-in package.json is untouched.
|
|
153
|
+
package_json = self.dir / "package.json"
|
|
154
|
+
manifest = json.loads(package_json.read_text(encoding="utf-8"))
|
|
155
|
+
manifest.setdefault("scripts", {})["test"] = "tsx src/bin/oracle-runner.ts"
|
|
156
|
+
package_json.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
148
157
|
for rel, old, new in TASKS[task_id]["breaks"]:
|
|
149
158
|
path = self.dir / rel
|
|
150
159
|
text = path.read_text(encoding="utf-8")
|
|
@@ -339,8 +348,14 @@ def registry(ws: ReactWorkspace, arm: str = "baseline") -> Dict[str, Any]:
|
|
|
339
348
|
}
|
|
340
349
|
if arm == "tokensafe":
|
|
341
350
|
tools.update({
|
|
342
|
-
"ts_smart_read_file": lambda path, symbol="": ws.tokensafe(
|
|
343
|
-
"smart_read_file",
|
|
351
|
+
"ts_smart_read_file": lambda path, symbol="", start_line=None, end_line=None: ws.tokensafe(
|
|
352
|
+
"smart_read_file",
|
|
353
|
+
{
|
|
354
|
+
"path": path,
|
|
355
|
+
**({"symbol": symbol} if symbol else {}),
|
|
356
|
+
**({"start_line": start_line} if start_line is not None else {}),
|
|
357
|
+
**({"end_line": end_line} if end_line is not None else {}),
|
|
358
|
+
},
|
|
344
359
|
),
|
|
345
360
|
"ts_scoped_search": lambda query, path="sandboxes": ws.tokensafe(
|
|
346
361
|
"scoped_search", {"query": query, "path": path, "max_results": 20}
|
|
@@ -358,8 +373,15 @@ def registry(ws: ReactWorkspace, arm: str = "baseline") -> Dict[str, Any]:
|
|
|
358
373
|
tools.update({
|
|
359
374
|
"oumv_observe": lambda level, target="": ws.oumv("oumv/observe", {"level": level, "target": target}),
|
|
360
375
|
"oumv_getSource": lambda path, symbol="": ws.oumv("oumv/getSource", {"path": path, "symbol": symbol}),
|
|
361
|
-
"oumv_applyEdit": lambda path, replacement,
|
|
362
|
-
"oumv/applyEdit",
|
|
376
|
+
"oumv_applyEdit": lambda path, expectedVersion, mode="", replacement="", hunks=None: ws.oumv(
|
|
377
|
+
"oumv/applyEdit",
|
|
378
|
+
{
|
|
379
|
+
"path": path,
|
|
380
|
+
"expectedVersion": expectedVersion,
|
|
381
|
+
**({"mode": mode} if mode else {}),
|
|
382
|
+
**({"replacement": replacement} if replacement else {}),
|
|
383
|
+
**({"hunks": hunks} if hunks else {}),
|
|
384
|
+
},
|
|
363
385
|
),
|
|
364
386
|
"oumv_understand": lambda query, target: ws.oumv("oumv/understand", {"query": query, "target": target}),
|
|
365
387
|
})
|
|
@@ -371,10 +393,15 @@ TOKENSAFE_TOOLS: List[Dict[str, Any]] = TOOLS + [
|
|
|
371
393
|
"type": "function",
|
|
372
394
|
"function": {
|
|
373
395
|
"name": "ts_smart_read_file",
|
|
374
|
-
"description": "TokenSafe AST-skeleton reader: a compact symbol view of one file.",
|
|
396
|
+
"description": "TokenSafe AST-skeleton reader: a compact symbol view of one file, or a line range with start_line/end_line.",
|
|
375
397
|
"parameters": {
|
|
376
398
|
"type": "object",
|
|
377
|
-
"properties": {
|
|
399
|
+
"properties": {
|
|
400
|
+
"path": {"type": "string"},
|
|
401
|
+
"symbol": {"type": "string"},
|
|
402
|
+
"start_line": {"type": "integer", "description": "Optional 1-based first line of a range to return"},
|
|
403
|
+
"end_line": {"type": "integer", "description": "Optional 1-based last line of a range to return"},
|
|
404
|
+
},
|
|
378
405
|
"required": ["path"],
|
|
379
406
|
},
|
|
380
407
|
},
|
|
@@ -409,7 +436,8 @@ TOKENSAFE_TOOLS: List[Dict[str, Any]] = TOOLS + [
|
|
|
409
436
|
"name": "ts_apply_edits",
|
|
410
437
|
"description": (
|
|
411
438
|
"TokenSafe surgical editor: replaces exact snippets (hunks of {target, replacement}) "
|
|
412
|
-
|
|
439
|
+
'and runs `verify` after the edit, returning a one-line pass/fail. Pass verify="auto" '
|
|
440
|
+
"to run the project's declared test command — never a shell command of your own."
|
|
413
441
|
),
|
|
414
442
|
"parameters": {
|
|
415
443
|
"type": "object",
|
|
@@ -422,11 +450,23 @@ TOKENSAFE_TOOLS: List[Dict[str, Any]] = TOOLS + [
|
|
|
422
450
|
"properties": {
|
|
423
451
|
"target": {"type": "string", "description": "Exact snippet to replace"},
|
|
424
452
|
"replacement": {"type": "string", "description": "Replacement snippet"},
|
|
453
|
+
"start_line": {
|
|
454
|
+
"type": "integer",
|
|
455
|
+
"description": "1-based first line to search, from the read slice; makes a repeated target unique",
|
|
456
|
+
},
|
|
457
|
+
"end_line": {"type": "integer", "description": "1-based last line to search"},
|
|
458
|
+
"replace_all": {
|
|
459
|
+
"type": "boolean",
|
|
460
|
+
"description": "Replace every occurrence inside the range instead of requiring exactly one",
|
|
461
|
+
},
|
|
425
462
|
},
|
|
426
463
|
"required": ["target", "replacement"],
|
|
427
464
|
},
|
|
428
465
|
},
|
|
429
|
-
"verify": {
|
|
466
|
+
"verify": {
|
|
467
|
+
"type": "string",
|
|
468
|
+
"description": 'Optional verification command; must be the literal "auto"',
|
|
469
|
+
},
|
|
430
470
|
},
|
|
431
471
|
"required": ["path", "edits"],
|
|
432
472
|
},
|
|
@@ -469,15 +509,40 @@ OUMV_TOOLS: List[Dict[str, Any]] = TOOLS + [
|
|
|
469
509
|
"type": "function",
|
|
470
510
|
"function": {
|
|
471
511
|
"name": "oumv_applyEdit",
|
|
472
|
-
"description":
|
|
512
|
+
"description": (
|
|
513
|
+
"OUMV guarded edit: applies only if `expectedVersion` from getSource matches the file on disk. "
|
|
514
|
+
"mode='patch' splices hunks (cheapest; the whole file is never re-sent); mode='symbol' replaces "
|
|
515
|
+
"one declaration; mode='replace' rewrites the whole file."
|
|
516
|
+
),
|
|
473
517
|
"parameters": {
|
|
474
518
|
"type": "object",
|
|
475
519
|
"properties": {
|
|
476
520
|
"path": {"type": "string"},
|
|
477
|
-
"replacement": {"type": "string"},
|
|
478
521
|
"expectedVersion": {"type": "string", "description": "sha256 version from getSource"},
|
|
522
|
+
"mode": {"type": "string", "enum": ["patch", "symbol", "replace"]},
|
|
523
|
+
"hunks": {
|
|
524
|
+
"type": "array",
|
|
525
|
+
"description": (
|
|
526
|
+
"mode='patch': exact snippets from the getSource output, applied in order. Copy "
|
|
527
|
+
"startLine/endLine from that output; without them a repeated target is -32011 and "
|
|
528
|
+
"the error carries the occurrence lines."
|
|
529
|
+
),
|
|
530
|
+
"items": {
|
|
531
|
+
"type": "object",
|
|
532
|
+
"properties": {
|
|
533
|
+
"target": {"type": "string", "description": "Exact snippet from the source on disk"},
|
|
534
|
+
"replacement": {"type": "string"},
|
|
535
|
+
"startLine": {"type": "integer", "description": "1-based first line to search, from getSource"},
|
|
536
|
+
"endLine": {"type": "integer", "description": "1-based last line to search"},
|
|
537
|
+
"replaceAll": {"type": "boolean"},
|
|
538
|
+
},
|
|
539
|
+
"required": ["target", "replacement"],
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
"replacement": {"type": "string", "description": "New content, or the declaration body for mode='symbol'"},
|
|
543
|
+
"symbol": {"type": "string", "description": "Declaration to replace when mode='symbol'"},
|
|
479
544
|
},
|
|
480
|
-
"required": ["path", "
|
|
545
|
+
"required": ["path", "expectedVersion"],
|
|
481
546
|
},
|
|
482
547
|
},
|
|
483
548
|
},
|
|
@@ -508,26 +573,35 @@ SYSTEM = (
|
|
|
508
573
|
|
|
509
574
|
SYSTEM_TOKENSAFE = (
|
|
510
575
|
"You are a senior React engineer working in a small sandbox. The workspace has TokenSafe tools. "
|
|
511
|
-
"Use this loop and stop as soon as the oracle reports 12: (1) ts_scoped_search for the
|
|
512
|
-
"in the repro to get file:line hits;
|
|
513
|
-
"
|
|
514
|
-
"
|
|
515
|
-
"
|
|
516
|
-
|
|
517
|
-
"
|
|
518
|
-
"
|
|
519
|
-
|
|
576
|
+
"Use this loop ONCE per fix and stop as soon as the oracle reports 12: (1) ts_scoped_search for the "
|
|
577
|
+
"behaviour named in the repro to get file:line hits; when the repro already names the symbol you can skip "
|
|
578
|
+
"the search, and you may batch the search and the read in the same turn. (2) ts_smart_read_file with that "
|
|
579
|
+
"path and the identifier from the hit as `symbol` — it returns the enclosing component/handler body (or a "
|
|
580
|
+
"window around the hit) with line numbers, and inlines the body when the identifier is declared in another "
|
|
581
|
+
"file, so one call is enough. (3) ts_apply_edits with one hunk {target: the exact snippet from that slice, "
|
|
582
|
+
"replacement: the fix, start_line: the first line of the snippet in the slice, end_line: the last line} "
|
|
583
|
+
'plus verify="auto" — it edits and verifies in one call. If the hunk target repeats in the file, pass '
|
|
584
|
+
'start_line/end_line from the slice (or replace_all=true) so it is unambiguous. `verify` MUST be the '
|
|
585
|
+
'literal string "auto": it runs the project\'s declared test command, which is the 12-assertion oracle. '
|
|
586
|
+
"Never pass an `npx ...` or any other shell command as verify — the allowlist rejects it and the whole "
|
|
587
|
+
"call is wasted. The slice is exact file text: do not re-read_file to check it. (4) if verify fails, read "
|
|
588
|
+
"the reported line and repeat (2)-(3). ts_repo_map is for an unfamiliar repository; skip it when the repro "
|
|
589
|
+
"already names the component. Prefer these tools over list_files/read_file. Tests and adapter.ts are "
|
|
590
|
+
"read-only. Do not rewrite whole files."
|
|
520
591
|
)
|
|
521
592
|
|
|
522
593
|
SYSTEM_OUMV = (
|
|
523
594
|
"You are a senior React engineer working in a small sandbox that exposes the OUMV runtime. "
|
|
524
595
|
"Use this loop and stop as soon as the oracle reports 12: (1) search_files ONCE for the behaviour named in "
|
|
525
|
-
"the repro
|
|
526
|
-
"
|
|
527
|
-
"
|
|
528
|
-
"
|
|
529
|
-
"
|
|
530
|
-
"
|
|
596
|
+
"the repro (skip it when the repro names the store or component). (2) oumv_getSource ONCE with `symbol` for "
|
|
597
|
+
"the function or method you change: it returns that body, its startLine/endLine and the sha256 OCC version. "
|
|
598
|
+
"(3) oumv_applyEdit with that path, the version and mode=\"patch\": hunks=[{target: the exact text as it "
|
|
599
|
+
"appears in that output (the current, broken code copied verbatim, never the fixed code), replacement: the "
|
|
600
|
+
"fix, startLine/endLine: the lines the target occupies in that output}]. Every hunk carries the window. "
|
|
601
|
+
"(4) On -32009 the target is absent: rebuild it from error.data.nearest, error.data.occurrences or "
|
|
602
|
+
"error.data.suggestedWindow and retry once. (5) run_command to run the oracle. Do not re-read a file you "
|
|
603
|
+
"already have in context, do not send the whole file, and do not use write_file unless an OUMV tool returns "
|
|
604
|
+
"an error. Tests and adapter.ts are read-only."
|
|
531
605
|
)
|
|
532
606
|
|
|
533
607
|
|
|
@@ -537,6 +611,8 @@ def task_prompt(task_id: str) -> str:
|
|
|
537
611
|
f"The task manager has a regression: {task['symptom']}\n"
|
|
538
612
|
f"Repro: {task['repro']}\n"
|
|
539
613
|
"Find the cause and fix the sandbox source. "
|
|
540
|
-
"Verification: `
|
|
614
|
+
"Verification: the workspace's `npm test` script is `tsx src/bin/oracle-runner.ts`, the 12-assertion "
|
|
615
|
+
"oracle, and it must print {\"passed\":12,\"failed\":[]}. "
|
|
616
|
+
'ts_apply_edits(..., verify="auto") runs exactly that command and returns the verdict in the same call. '
|
|
541
617
|
"Do not modify the oracle, adapter.ts, or the test harness."
|
|
542
618
|
)
|
package/src/mcp_server.py
CHANGED
package/src/retrofit.py
CHANGED
|
@@ -682,7 +682,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
|
682
682
|
"repo": "tokensafe-backend/python",
|
|
683
683
|
"mode": "hybrid",
|
|
684
684
|
"status": "ready",
|
|
685
|
-
"description": "Duck-typed Starlette binding: introspects Route/WebSocketRoute, serves HTTP/SSE/WebSocket from the same runtime as the FastAPI adapter, discovers a DB engine from app.state. Certified Level 3
|
|
685
|
+
"description": "Duck-typed Starlette binding: introspects Route/WebSocketRoute, serves HTTP/SSE/WebSocket from the same runtime as the FastAPI adapter, discovers a DB engine from app.state. Certified Level 3 50/50 over HTTP, 51/51 over WS and 54/54 over SSE on fixtures v19; the read-only profile certifies 29/29.",
|
|
686
686
|
"technology": {
|
|
687
687
|
"language": "python",
|
|
688
688
|
"framework": "starlette",
|
|
@@ -695,6 +695,46 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
|
695
695
|
{"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
696
696
|
],
|
|
697
697
|
},
|
|
698
|
+
{
|
|
699
|
+
"id": "backend/flask",
|
|
700
|
+
"name": "Python Flask Adapter (WSGI)",
|
|
701
|
+
"profile": "backend",
|
|
702
|
+
"profiles": ["backend"],
|
|
703
|
+
"repo": "tokensafe-backend/python",
|
|
704
|
+
"mode": "hybrid",
|
|
705
|
+
"status": "ready",
|
|
706
|
+
"description": "WSGI binding: wraps app.wsgi_app with POST /__oumv/rpc, discovers app.url_map routes, dispatches verify through the Flask test client and adopts a Flask-SQLAlchemy engine. HTTP only (no server-push channel). Certified Level 3 50/50 on fixtures v19; the read-only profile certifies 29/29 and the query policy 50/50.",
|
|
707
|
+
"technology": {
|
|
708
|
+
"language": "python",
|
|
709
|
+
"framework": "flask",
|
|
710
|
+
"package": {"manager": "pip", "name": "tokensafe-backend-python", "install": 'pip install "tokensafe-backend-python[flask] @ git+https://github.com/tokensafe-dev/tokensafe-backend.git#subdirectory=python"'},
|
|
711
|
+
},
|
|
712
|
+
"capabilities": [
|
|
713
|
+
{"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
714
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
|
|
715
|
+
{"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
716
|
+
],
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
"id": "backend/django",
|
|
720
|
+
"name": "Python Django Adapter (WSGI)",
|
|
721
|
+
"profile": "backend",
|
|
722
|
+
"profiles": ["backend"],
|
|
723
|
+
"repo": "tokensafe-backend/python",
|
|
724
|
+
"mode": "hybrid",
|
|
725
|
+
"status": "ready",
|
|
726
|
+
"description": "WSGI binding: wraps the Django WSGI application, walks get_resolver() for routes (GET/POST unless the view restricts them), dispatches verify through django.test.Client, and takes an explicitly passed SQLAlchemy engine. HTTP only (no server-push channel). Certified Level 3 50/50 on fixtures v19; the read-only profile certifies 29/29 and the query policy 50/50.",
|
|
727
|
+
"technology": {
|
|
728
|
+
"language": "python",
|
|
729
|
+
"framework": "django",
|
|
730
|
+
"package": {"manager": "pip", "name": "tokensafe-backend-python", "install": 'pip install "tokensafe-backend-python[django] @ git+https://github.com/tokensafe-dev/tokensafe-backend.git#subdirectory=python"'},
|
|
731
|
+
},
|
|
732
|
+
"capabilities": [
|
|
733
|
+
{"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
734
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
|
|
735
|
+
{"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
736
|
+
],
|
|
737
|
+
},
|
|
698
738
|
{
|
|
699
739
|
"id": "backend/node",
|
|
700
740
|
"name": "Node.js Backend Adapter (Express, Fastify)",
|
package/src/session_brief.py
CHANGED
|
@@ -16,6 +16,8 @@ import json
|
|
|
16
16
|
import os
|
|
17
17
|
from typing import Any, Dict, List, Optional
|
|
18
18
|
|
|
19
|
+
from src.backend_release import BACKEND_RELEASE_TAG
|
|
20
|
+
|
|
19
21
|
MAX_BRIEF_CHARS = 1200
|
|
20
22
|
|
|
21
23
|
_FRONTEND_LINES = {
|
|
@@ -216,7 +218,7 @@ def _activation(workspace: str, stack: Dict[str, Any]) -> List[str]:
|
|
|
216
218
|
hints.append('activate backend: `pip install "tokensafe-backend-python @ git+https://github.com/tokensafe-dev/tokensafe-backend.git#subdirectory=python"` then run the server via `tokensafe run-backend ...`')
|
|
217
219
|
elif item.get("provider") == "go":
|
|
218
220
|
hints.append(
|
|
219
|
-
"activate backend: `go get github.com/tokensafe-dev/tokensafe-backend/go@
|
|
221
|
+
f"activate backend: `go get github.com/tokensafe-dev/tokensafe-backend/go@{BACKEND_RELEASE_TAG}` "
|
|
220
222
|
"then `tokensafe inject` (one line, reversible)"
|
|
221
223
|
)
|
|
222
224
|
if not hints and not readiness:
|
package/src/telemetry_sync.py
CHANGED
|
@@ -311,7 +311,7 @@ class TelemetrySync:
|
|
|
311
311
|
current_last_id = last_id
|
|
312
312
|
headers = {
|
|
313
313
|
"Content-Type": "application/json",
|
|
314
|
-
"User-Agent": "TokenSafe-Sync/4.
|
|
314
|
+
"User-Agent": "TokenSafe-Sync/4.11.0"
|
|
315
315
|
}
|
|
316
316
|
if active_key:
|
|
317
317
|
headers["Authorization"] = f"Bearer {active_key}"
|
package/src/version_checker.py
CHANGED
|
@@ -17,7 +17,7 @@ import urllib.request
|
|
|
17
17
|
import urllib.error
|
|
18
18
|
from typing import Dict, Any, Optional, Tuple
|
|
19
19
|
|
|
20
|
-
CURRENT_VERSION = "4.
|
|
20
|
+
CURRENT_VERSION = "4.11.0"
|
|
21
21
|
CACHE_TTL = 86400 # 24 hours
|
|
22
22
|
# When the cloud is unreachable we must NOT cache the synthesized "up to date"
|
|
23
23
|
# answer for a full day — otherwise an update released right after an outage
|