tokensafe 4.9.3 → 4.10.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/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 +3 -3
- package/src/batch_editor.py +53 -0
- package/src/bench/driver.py +38 -0
- package/src/bench/go_target.py +147 -24
- package/src/bench/react_target.py +57 -16
- package/src/mcp_server.py +1 -1
- package/src/session_brief.py +1 -1
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.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.10.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.10.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.10.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.10.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.10.0",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/auto_inject.py
CHANGED
|
@@ -1376,17 +1376,17 @@ def revert_dotnet_patch(workspace: str) -> Dict[str, Any]:
|
|
|
1376
1376
|
# Pinned to the backend release: the sidecars are single files, so the cache is
|
|
1377
1377
|
# content-addressed by SHA-256 and a clean machine downloads the exact bytes the
|
|
1378
1378
|
# release was certified from. Bump both the tag and the hashes together.
|
|
1379
|
-
_SIDECAR_RELEASE_TAG = "v0.
|
|
1379
|
+
_SIDECAR_RELEASE_TAG = "v0.19.0"
|
|
1380
1380
|
_SIDECARS = {
|
|
1381
1381
|
"spring": (
|
|
1382
1382
|
"java/src/dev/tokensafe/oumv/OumvSpring.java",
|
|
1383
1383
|
"OumvSpring.java",
|
|
1384
|
-
"
|
|
1384
|
+
"6319db688fe8bd85b792de9a91e680be7dbdd52924c125257f212957b5ed2618",
|
|
1385
1385
|
),
|
|
1386
1386
|
"php": (
|
|
1387
1387
|
"php/bin/oumv-php",
|
|
1388
1388
|
"oumv-php",
|
|
1389
|
-
"
|
|
1389
|
+
"2bf24b8987dbbda364b3ab8d2c16e74650754cf4abc027bfa3f589b1d6e78b1b",
|
|
1390
1390
|
),
|
|
1391
1391
|
}
|
|
1392
1392
|
|
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,12 +740,34 @@ 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
|
},
|
|
@@ -770,14 +873,24 @@ def registry(ws: GoWorkspace, arm: str) -> Dict[str, Any]:
|
|
|
770
873
|
if arm == "oumv":
|
|
771
874
|
tools.update({
|
|
772
875
|
"oumv_observe": lambda level, target="": ws.oumv("oumv/observe", {"level": level, "target": target}),
|
|
773
|
-
"oumv_getSource": lambda path, symbol=""
|
|
774
|
-
|
|
876
|
+
"oumv_getSource": lambda path, symbol="", startLine=None, endLine=None, ifVersion="": ws.oumv(
|
|
877
|
+
"oumv/getSource",
|
|
878
|
+
{
|
|
879
|
+
"path": path,
|
|
880
|
+
"symbol": symbol,
|
|
881
|
+
**({"startLine": startLine} if startLine is not None else {}),
|
|
882
|
+
**({"endLine": endLine} if endLine is not None else {}),
|
|
883
|
+
**({"ifVersion": ifVersion} if ifVersion else {}),
|
|
884
|
+
},
|
|
885
|
+
),
|
|
886
|
+
"oumv_applyEdit": lambda path, expectedVersion, mode="", replacement="", symbol="", hunks=None, verify=None: ws.apply_edit_scoped(
|
|
775
887
|
path,
|
|
776
888
|
expectedVersion,
|
|
777
889
|
mode=mode,
|
|
778
890
|
replacement=replacement,
|
|
779
891
|
symbol=symbol,
|
|
780
892
|
hunks=hunks,
|
|
893
|
+
verify=verify,
|
|
781
894
|
),
|
|
782
895
|
"oumv_verify": lambda target, payload=None: ws.oumv(
|
|
783
896
|
"oumv/verify", {"target": target, "action": "probe", "payload": payload}
|
|
@@ -813,14 +926,24 @@ SYSTEM_OUMV = (
|
|
|
813
926
|
"The bug report includes a repro; use it to go straight to the right handler instead of guessing payloads. "
|
|
814
927
|
"Use this loop and stop as soon as the oracle passes: (1) oumv_observe L3 with the failing endpoint target "
|
|
815
928
|
"(e.g. \"POST /api/products\") — ONE call returns the handler source, its workspace path, startLine/endLine and "
|
|
816
|
-
"the sha256 OCC version
|
|
817
|
-
"hunks=[{target:
|
|
818
|
-
"
|
|
819
|
-
"
|
|
820
|
-
"
|
|
821
|
-
"the
|
|
822
|
-
"
|
|
823
|
-
"
|
|
929
|
+
"the sha256 OCC version. (2) oumv_applyEdit with that path + expectedVersion and mode=\"patch\", "
|
|
930
|
+
"hunks=[{target: THE EXACT TEXT AS IT APPEARS IN THAT L3 SLICE — the current, broken code, copied verbatim "
|
|
931
|
+
"with its whitespace and indentation; never the fixed code you intend to write, and never text from memory "
|
|
932
|
+
"or from another file, replacement: the fix, startLine: the slice line where that text starts, endLine: the "
|
|
933
|
+
"slice line where it ends}]. Every hunk MUST carry startLine and endLine taken from that slice: they scope "
|
|
934
|
+
"the splice and keep a repeated snippet unique. The file is never re-sent and the edit is rejected on a "
|
|
935
|
+
"stale version. (3) If the result is error -32009 (RESOURCE_NOT_FOUND, target not found), your target does "
|
|
936
|
+
"not match the file: read error.data.nearest or error.data.occurrences, and error.data.suggestedWindow, "
|
|
937
|
+
"rebuild the target from that exact code (or, when the text is hard to copy, retry with mode=\"symbol\" and "
|
|
938
|
+
"symbol=<the declaration name>), and retry ONCE. Do not repeat the same absent text — the expectation you "
|
|
939
|
+
"had is not the code on disk. (4) Verification: if oumv_applyEdit accepts `verify`, pass it in the SAME call "
|
|
940
|
+
"for a stateless task — verify={target: \"POST /api/products\", action: \"probe\", payload: <the JSON body "
|
|
941
|
+
"from the repro>} — so the edit and its verdict arrive together (one call instead of two). If the runtime "
|
|
942
|
+
"does not advertise inline verify, or the task is stateful (two calls in one process, e.g. a duplicate "
|
|
943
|
+
"idempotency key), use run_command with the oracle command and oumv_verify only for a single stateless "
|
|
944
|
+
"request. (5) If the verification fails, read the reported line and repeat (2)-(4). Do not fetch whole files "
|
|
945
|
+
"with getSource and do not use write_file: the patch IS the edit. Do not call list_files/read_file unless "
|
|
946
|
+
"an OUMV tool returns an error. Tests are read-only."
|
|
824
947
|
)
|
|
825
948
|
|
|
826
949
|
|
|
@@ -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}
|
|
@@ -371,10 +386,15 @@ TOKENSAFE_TOOLS: List[Dict[str, Any]] = TOOLS + [
|
|
|
371
386
|
"type": "function",
|
|
372
387
|
"function": {
|
|
373
388
|
"name": "ts_smart_read_file",
|
|
374
|
-
"description": "TokenSafe AST-skeleton reader: a compact symbol view of one file.",
|
|
389
|
+
"description": "TokenSafe AST-skeleton reader: a compact symbol view of one file, or a line range with start_line/end_line.",
|
|
375
390
|
"parameters": {
|
|
376
391
|
"type": "object",
|
|
377
|
-
"properties": {
|
|
392
|
+
"properties": {
|
|
393
|
+
"path": {"type": "string"},
|
|
394
|
+
"symbol": {"type": "string"},
|
|
395
|
+
"start_line": {"type": "integer", "description": "Optional 1-based first line of a range to return"},
|
|
396
|
+
"end_line": {"type": "integer", "description": "Optional 1-based last line of a range to return"},
|
|
397
|
+
},
|
|
378
398
|
"required": ["path"],
|
|
379
399
|
},
|
|
380
400
|
},
|
|
@@ -409,7 +429,8 @@ TOKENSAFE_TOOLS: List[Dict[str, Any]] = TOOLS + [
|
|
|
409
429
|
"name": "ts_apply_edits",
|
|
410
430
|
"description": (
|
|
411
431
|
"TokenSafe surgical editor: replaces exact snippets (hunks of {target, replacement}) "
|
|
412
|
-
|
|
432
|
+
'and runs `verify` after the edit, returning a one-line pass/fail. Pass verify="auto" '
|
|
433
|
+
"to run the project's declared test command — never a shell command of your own."
|
|
413
434
|
),
|
|
414
435
|
"parameters": {
|
|
415
436
|
"type": "object",
|
|
@@ -422,11 +443,23 @@ TOKENSAFE_TOOLS: List[Dict[str, Any]] = TOOLS + [
|
|
|
422
443
|
"properties": {
|
|
423
444
|
"target": {"type": "string", "description": "Exact snippet to replace"},
|
|
424
445
|
"replacement": {"type": "string", "description": "Replacement snippet"},
|
|
446
|
+
"start_line": {
|
|
447
|
+
"type": "integer",
|
|
448
|
+
"description": "1-based first line to search, from the read slice; makes a repeated target unique",
|
|
449
|
+
},
|
|
450
|
+
"end_line": {"type": "integer", "description": "1-based last line to search"},
|
|
451
|
+
"replace_all": {
|
|
452
|
+
"type": "boolean",
|
|
453
|
+
"description": "Replace every occurrence inside the range instead of requiring exactly one",
|
|
454
|
+
},
|
|
425
455
|
},
|
|
426
456
|
"required": ["target", "replacement"],
|
|
427
457
|
},
|
|
428
458
|
},
|
|
429
|
-
"verify": {
|
|
459
|
+
"verify": {
|
|
460
|
+
"type": "string",
|
|
461
|
+
"description": 'Optional verification command; must be the literal "auto"',
|
|
462
|
+
},
|
|
430
463
|
},
|
|
431
464
|
"required": ["path", "edits"],
|
|
432
465
|
},
|
|
@@ -508,15 +541,21 @@ SYSTEM = (
|
|
|
508
541
|
|
|
509
542
|
SYSTEM_TOKENSAFE = (
|
|
510
543
|
"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
|
-
|
|
544
|
+
"Use this loop ONCE per fix and stop as soon as the oracle reports 12: (1) ts_scoped_search for the "
|
|
545
|
+
"behaviour named in the repro to get file:line hits; when the repro already names the symbol you can skip "
|
|
546
|
+
"the search, and you may batch the search and the read in the same turn. (2) ts_smart_read_file with that "
|
|
547
|
+
"path and the identifier from the hit as `symbol` — it returns the enclosing component/handler body (or a "
|
|
548
|
+
"window around the hit) with line numbers, and inlines the body when the identifier is declared in another "
|
|
549
|
+
"file, so one call is enough. (3) ts_apply_edits with one hunk {target: the exact snippet from that slice, "
|
|
550
|
+
"replacement: the fix, start_line: the first line of the snippet in the slice, end_line: the last line} "
|
|
551
|
+
'plus verify="auto" — it edits and verifies in one call. If the hunk target repeats in the file, pass '
|
|
552
|
+
'start_line/end_line from the slice (or replace_all=true) so it is unambiguous. `verify` MUST be the '
|
|
553
|
+
'literal string "auto": it runs the project\'s declared test command, which is the 12-assertion oracle. '
|
|
554
|
+
"Never pass an `npx ...` or any other shell command as verify — the allowlist rejects it and the whole "
|
|
555
|
+
"call is wasted. The slice is exact file text: do not re-read_file to check it. (4) if verify fails, read "
|
|
556
|
+
"the reported line and repeat (2)-(3). ts_repo_map is for an unfamiliar repository; skip it when the repro "
|
|
557
|
+
"already names the component. Prefer these tools over list_files/read_file. Tests and adapter.ts are "
|
|
558
|
+
"read-only. Do not rewrite whole files."
|
|
520
559
|
)
|
|
521
560
|
|
|
522
561
|
SYSTEM_OUMV = (
|
|
@@ -537,6 +576,8 @@ def task_prompt(task_id: str) -> str:
|
|
|
537
576
|
f"The task manager has a regression: {task['symptom']}\n"
|
|
538
577
|
f"Repro: {task['repro']}\n"
|
|
539
578
|
"Find the cause and fix the sandbox source. "
|
|
540
|
-
"Verification: `
|
|
579
|
+
"Verification: the workspace's `npm test` script is `tsx src/bin/oracle-runner.ts`, the 12-assertion "
|
|
580
|
+
"oracle, and it must print {\"passed\":12,\"failed\":[]}. "
|
|
581
|
+
'ts_apply_edits(..., verify="auto") runs exactly that command and returns the verdict in the same call. '
|
|
541
582
|
"Do not modify the oracle, adapter.ts, or the test harness."
|
|
542
583
|
)
|
package/src/mcp_server.py
CHANGED
package/src/session_brief.py
CHANGED
|
@@ -216,7 +216,7 @@ def _activation(workspace: str, stack: Dict[str, Any]) -> List[str]:
|
|
|
216
216
|
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
217
|
elif item.get("provider") == "go":
|
|
218
218
|
hints.append(
|
|
219
|
-
"activate backend: `go get github.com/tokensafe-dev/tokensafe-backend/go@v0.
|
|
219
|
+
"activate backend: `go get github.com/tokensafe-dev/tokensafe-backend/go@v0.19.0` "
|
|
220
220
|
"then `tokensafe inject` (one line, reversible)"
|
|
221
221
|
)
|
|
222
222
|
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.10.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.10.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
|