tokensafe 4.16.2 → 5.0.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +8 -3
- package/bin/agy-tokens +1 -1
- package/bin/tokensafe +1 -1
- package/bin/tokensafe-acp.js +1 -1
- package/bin/tokensafe-mcp +1 -1
- package/bin/tokensafe.js +1 -1
- package/hooks/claude_code_hook.py +49 -45
- package/hooks/cursor_hook.py +8 -8
- package/hooks/kimi_hook.py +23 -23
- package/hooks/post_tool_use.py +6 -6
- package/hooks/pre_invocation.py +21 -17
- package/hooks/pre_tool_use.py +27 -27
- package/hooks/session_start.py +17 -17
- package/hooks/stop_hook.py +3 -3
- package/hooks/zcode_hook.py +2 -2
- package/kimi.plugin.json +2 -2
- package/mcp_config.json +1 -1
- package/package.json +5 -4
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/__init__.py +9 -5
- package/src/cli.py +11 -2429
- package/src/mcp_server.py +11 -5024
- package/src/proxy.py +11 -1803
- package/tokensafe/__init__.py +6 -0
- package/{src → tokensafe}/acp/__init__.py +2 -2
- package/{src → tokensafe}/acp/server.py +5 -5
- package/{src → tokensafe}/adapter_core.py +42 -17
- package/{src → tokensafe}/agent/__init__.py +1 -1
- package/{src → tokensafe}/agent/context.py +4 -4
- package/{src → tokensafe}/agent/loop.py +4 -4
- package/{src → tokensafe}/agent/providers.py +2 -2
- package/{src → tokensafe}/agent/tools.py +2 -2
- package/{src → tokensafe}/agent_firewall.py +68 -9
- package/{src → tokensafe}/angular_cli.py +4 -4
- package/{src → tokensafe}/auto_inject.py +37 -5
- package/{src → tokensafe}/batch_editor.py +185 -28
- package/tokensafe/batch_search.py +1191 -0
- package/{src → tokensafe}/bench/go_target.py +1 -1
- package/{src → tokensafe}/bench/mechanics.py +1 -1
- package/{src → tokensafe}/bench/react_target.py +1 -1
- package/{src → tokensafe}/bench/runner.py +4 -4
- package/{src → tokensafe}/benchmark.py +12 -12
- package/{src → tokensafe}/benchmark_real.py +18 -18
- package/{src → tokensafe}/build_parsers.py +3 -3
- package/{src → tokensafe}/bundle_probe.py +1 -1
- package/{src → tokensafe}/burn_monitor.py +3 -3
- package/{src → tokensafe}/cache_normalizer.py +1 -1
- package/tokensafe/cli.py +2490 -0
- package/{src → tokensafe}/command_sanitizer.py +94 -26
- package/{src → tokensafe}/compaction_recovery.py +5 -5
- package/{src → tokensafe}/compactor.py +148 -95
- package/{src → tokensafe}/context_index.py +194 -28
- package/{src → tokensafe}/cross_stack.py +2 -2
- package/{src → tokensafe}/dashboard.py +3 -3
- package/{src → tokensafe}/delegation.py +4 -4
- package/{src → tokensafe}/dependency_prefetcher.py +1 -1
- package/{src → tokensafe}/diff_slicer.py +2 -2
- package/{src → tokensafe}/distiller.py +7 -7
- package/{src → tokensafe}/distiller_cache.py +3 -3
- package/{src → tokensafe}/egress_counter.py +1 -1
- package/{src → tokensafe}/environment_auditor.py +7 -7
- package/{src → tokensafe}/file_state.py +2 -2
- package/{src → tokensafe}/format_invariants.py +1 -1
- package/tokensafe/format_parsers/__init__.py +20 -0
- package/{src → tokensafe}/format_parsers/compiler_errors.py +2 -2
- package/{src → tokensafe}/format_parsers/docker_k8s.py +1 -1
- package/{src → tokensafe}/format_parsers/i18n_strings.py +19 -9
- package/{src → tokensafe}/format_parsers/json_log.py +1 -1
- package/{src → tokensafe}/format_parsers/lockfiles.py +4 -4
- package/{src → tokensafe}/format_parsers/tabular.py +1 -1
- package/{src → tokensafe}/fts_index.py +20 -11
- package/{src → tokensafe}/governor.py +143 -31
- package/{src → tokensafe}/graph_engine.py +769 -126
- package/{src → tokensafe}/guard.py +80 -25
- package/{src → tokensafe}/history_compactor.py +407 -133
- package/{src → tokensafe}/i18n_catalog.py +39 -14
- package/{src → tokensafe}/image_downscale.py +1 -1
- package/tokensafe/ingress_staging.py +384 -0
- package/{src → tokensafe}/installer.py +118 -61
- package/{src → tokensafe}/license_manager.py +9 -67
- package/{src → tokensafe}/live_relay.py +2 -2
- package/{src → tokensafe}/loop_detector.py +2 -2
- package/{src → tokensafe}/mcp_config_manager.py +2 -2
- package/{src → tokensafe}/mcp_proxy.py +4 -4
- package/tokensafe/mcp_server.py +5664 -0
- package/{src → tokensafe}/metrics.py +56 -21
- package/{src → tokensafe}/mistakes.py +4 -4
- package/{src → tokensafe}/oumv_brief.py +21 -3
- package/{src → tokensafe}/oumv_gateway.py +146 -49
- package/{src → tokensafe}/oumv_policy.py +1 -1
- package/{src → tokensafe}/paths.py +1 -1
- package/{src → tokensafe}/project_memory.py +4 -4
- package/tokensafe/proxy.py +2075 -0
- package/{src → tokensafe}/quality_score.py +4 -4
- package/tokensafe/read_baseline.py +192 -0
- package/tokensafe/repo_compute.py +332 -0
- package/{src → tokensafe}/result_ledger.py +19 -19
- package/{src → tokensafe}/retrofit.py +6 -6
- package/{src → tokensafe}/savings.py +3 -3
- package/tokensafe/schema_slicer.py +1087 -0
- package/{src → tokensafe}/scoped_search.py +144 -6
- package/{src → tokensafe}/secret_redactor.py +22 -0
- package/{src → tokensafe}/session_brief.py +8 -8
- package/{src → tokensafe}/skeletonizer.py +89 -26
- package/{src → tokensafe}/slicer.py +3 -2
- package/{src → tokensafe}/snapshot.py +1 -1
- package/{src → tokensafe}/stash.py +1 -1
- package/{src → tokensafe}/statusline.py +1 -1
- package/{src → tokensafe}/superseded.py +22 -4
- package/{src → tokensafe}/team_cache.py +3 -3
- package/{src → tokensafe}/telemetry_sync.py +63 -11
- package/{src → tokensafe}/test_parsers.py +3 -3
- package/{src → tokensafe}/thinking_fold.py +3 -3
- package/{src → tokensafe}/tokenizer.py +37 -1
- package/{src → tokensafe}/tool_pruner.py +3 -3
- package/{src → tokensafe}/transcript_analyzer.py +1 -1
- package/{src → tokensafe}/transcript_recall.py +8 -8
- package/{src → tokensafe}/type_slicer.py +3 -3
- package/{src → tokensafe}/usage_ledger.py +4 -4
- package/{src → tokensafe}/version_checker.py +6 -6
- package/{src → tokensafe}/web_reader.py +86 -8
- package/{src → tokensafe}/workspace_roots.py +2 -2
- package/src/batch_search.py +0 -589
- package/src/format_parsers/__init__.py +0 -20
- package/src/schema_slicer.py +0 -578
- /package/{src → tokensafe}/agent/pricing.py +0 -0
- /package/{src → tokensafe}/atomic_io.py +0 -0
- /package/{src → tokensafe}/backend_release.py +0 -0
- /package/{src → tokensafe}/bench/__init__.py +0 -0
- /package/{src → tokensafe}/bench/driver.py +0 -0
- /package/{src → tokensafe}/bench/tokensafe_mcp.py +0 -0
- /package/{src → tokensafe}/bench_scenarios.json +0 -0
- /package/{src → tokensafe}/competitors.py +0 -0
- /package/{src → tokensafe}/format_parsers/ansi.py +0 -0
- /package/{src → tokensafe}/format_parsers/game_assets.py +0 -0
- /package/{src → tokensafe}/globmatch.py +0 -0
- /package/{src → tokensafe}/host_capabilities.py +0 -0
- /package/{src → tokensafe}/json_repair.py +0 -0
- /package/{src → tokensafe}/route_index.py +0 -0
- /package/{src → tokensafe}/scaffold.py +0 -0
- /package/{src → tokensafe}/session_context.py +0 -0
- /package/{src → tokensafe}/ssl_context.py +0 -0
- /package/{src → tokensafe}/stdio_io.py +0 -0
- /package/{src → tokensafe}/syntax_guard.py +0 -0
- /package/{src → tokensafe}/toml_mcp_config.py +0 -0
- /package/{src → tokensafe}/treesitter_backend.py +0 -0
- /package/{src → tokensafe}/win_paths.py +0 -0
|
@@ -69,7 +69,7 @@ class CommandSanitizer:
|
|
|
69
69
|
_GIT_DIFF_LIMIT_RE = re.compile(r"(?:\s-[0-9]+|\s-n\s*\d+|\s--max-count[=\s]\d+)")
|
|
70
70
|
_GIT_SHOW_SHORT_RE = re.compile(r"--stat|--name-only|--name-status|\s-s\b|--oneline")
|
|
71
71
|
_CURL_FILE_RE = re.compile(r"-o\s|-O\b|--output|-F\b|--form|-T\b|--upload-file|-I\b|--head")
|
|
72
|
-
_LS_VERBOSE_RE = re.compile(r"\bls\s+-[
|
|
72
|
+
_LS_VERBOSE_RE = re.compile(r"\bls\s+-([lahA1pF]*l[lahA1pF]*)(?=\s|$)")
|
|
73
73
|
_PKG_MANAGER_TEST_RE = re.compile(r"\b(?:yarn|npm|pnpm|bun)\s+(?:run\s+)?test(?:[:_-][\w.-]+)?\b")
|
|
74
74
|
_NPM_TEST_RE = re.compile(r"\bnpm\s+(?:run\s+)?test[\w:./-]*")
|
|
75
75
|
_CD_RE = re.compile(r'^\s*(?:cd|pushd)\s+(?:--\s+)?(["\']?)(.+?)\1\s*$')
|
|
@@ -263,6 +263,53 @@ class CommandSanitizer:
|
|
|
263
263
|
return True
|
|
264
264
|
return False
|
|
265
265
|
|
|
266
|
+
_FIND_COMPLEX_ARGS = frozenset({
|
|
267
|
+
"-o", "-or", "-exec", "-execdir", "-ok", "-okdir", "-delete", "(", "\\(", "!",
|
|
268
|
+
"-print", "-print0", "-printf", "-fprint", "-fprint0", "-fprintf", "-ls", "-fls",
|
|
269
|
+
"-prune", "-quit",
|
|
270
|
+
})
|
|
271
|
+
_FIND_PRUNE = (
|
|
272
|
+
"-not -path '*/.git' -not -path '*/.git/*' -not -path '*/node_modules/*' "
|
|
273
|
+
"-not -path '*/venv/*' -not -path '*/.venv/*'"
|
|
274
|
+
)
|
|
275
|
+
# git diff modes whose result is an exit status or a list of files: hiding
|
|
276
|
+
# lockfiles there changes the answer (diff --quiet passes on a lock change).
|
|
277
|
+
_GIT_DIFF_FILE_MODES = (
|
|
278
|
+
"--quiet", "--exit-code", "--name-only", "--name-status", "--stat", "--numstat",
|
|
279
|
+
"--shortstat", "--dirstat", "--summary", "--check", "--raw", "--no-patch",
|
|
280
|
+
)
|
|
281
|
+
# curl short options that consume the rest of a clustered flag as their value.
|
|
282
|
+
_CURL_ARG_SHORT = frozenset("AbcCdDeEFHKmoPQrTuUwxXyYz")
|
|
283
|
+
|
|
284
|
+
@classmethod
|
|
285
|
+
def _git_diff_reports_files(cls, arg: str) -> bool:
|
|
286
|
+
return arg == "-s" or any(arg == m or arg.startswith(m + "=") for m in cls._GIT_DIFF_FILE_MODES)
|
|
287
|
+
|
|
288
|
+
@staticmethod
|
|
289
|
+
def _python_module(cmd_args: List[str]) -> str:
|
|
290
|
+
"""Module run by `python -m <module>` (empty when not -m)."""
|
|
291
|
+
for i, a in enumerate(cmd_args):
|
|
292
|
+
if a == "-m":
|
|
293
|
+
return cmd_args[i + 1] if i + 1 < len(cmd_args) else ""
|
|
294
|
+
if a.startswith("-m") and len(a) > 2:
|
|
295
|
+
return a[2:]
|
|
296
|
+
if not a.startswith("-"):
|
|
297
|
+
return ""
|
|
298
|
+
return ""
|
|
299
|
+
|
|
300
|
+
@classmethod
|
|
301
|
+
def _curl_fails_on_http_error(cls, cmd_args: List[str]) -> bool:
|
|
302
|
+
for a in cmd_args:
|
|
303
|
+
if a in ("--fail", "--fail-with-body", "--fail-early"):
|
|
304
|
+
return True
|
|
305
|
+
if a.startswith("-") and not a.startswith("--"):
|
|
306
|
+
for ch in a[1:]:
|
|
307
|
+
if ch == "f":
|
|
308
|
+
return True
|
|
309
|
+
if ch in cls._CURL_ARG_SHORT:
|
|
310
|
+
break
|
|
311
|
+
return False
|
|
312
|
+
|
|
266
313
|
@classmethod
|
|
267
314
|
def _optimize_stage(cls, stage: str, cwd: Optional[str] = None) -> Optional[Tuple[str, int, str, Optional[Tuple[str, int]]]]:
|
|
268
315
|
"""
|
|
@@ -299,7 +346,8 @@ class CommandSanitizer:
|
|
|
299
346
|
|
|
300
347
|
# git diff: exclude lockfiles/bundles when diffing unscoped repository
|
|
301
348
|
if subcmd == "diff":
|
|
302
|
-
if not any(a.startswith(":!") for a in sub_args) and ":!" not in stage
|
|
349
|
+
if not any(a.startswith(":!") for a in sub_args) and ":!" not in stage \
|
|
350
|
+
and not any(cls._git_diff_reports_files(a) for a in sub_args):
|
|
303
351
|
has_path = any(not a.startswith("-") and not cls._GIT_REF_RE.match(a) for a in sub_args)
|
|
304
352
|
if not has_path:
|
|
305
353
|
excludes_str = " ".join(cls.LOCKFILE_EXCLUDES)
|
|
@@ -312,7 +360,15 @@ class CommandSanitizer:
|
|
|
312
360
|
# git log: cap unbounded commit history
|
|
313
361
|
elif subcmd == "log":
|
|
314
362
|
has_limit = bool(cls._GIT_DIFF_LIMIT_RE.search(stage))
|
|
315
|
-
|
|
363
|
+
# -n 10 --reverse prints the 10 NEWEST commits oldest-first, not the
|
|
364
|
+
# first 10; date bounds and A..B ranges are already bounded.
|
|
365
|
+
bounded = any(
|
|
366
|
+
a == "--reverse"
|
|
367
|
+
or a.startswith(("--since", "--after", "--until", "--before"))
|
|
368
|
+
or (".." in a and not a.startswith("-"))
|
|
369
|
+
for a in sub_args
|
|
370
|
+
)
|
|
371
|
+
if not has_limit and not bounded:
|
|
316
372
|
if "--oneline" not in sub_args:
|
|
317
373
|
new_stage = re.sub(r"\b(git(?:\s+-C\s+\S+)?\s+log)\b", r"\1 -n 10 --oneline", stage, count=1)
|
|
318
374
|
else:
|
|
@@ -357,12 +413,12 @@ class CommandSanitizer:
|
|
|
357
413
|
return wrapped, 2500, "Wrapped git commit with tokensafe wrap to compact pre-commit hooks and test output", None
|
|
358
414
|
|
|
359
415
|
# pytest (or python -m pytest): compact quiet traceback
|
|
360
|
-
if cmd_tok == "pytest" or (cmd_tok.startswith("python") and
|
|
416
|
+
if cmd_tok == "pytest" or (cmd_tok.startswith("python") and cls._python_module(cmd_args) == "pytest"):
|
|
361
417
|
if "--tb=" not in stage and "-q" not in cmd_args and "--quiet" not in cmd_args:
|
|
362
418
|
return f"{stage} -q --tb=short", 800, "Applied short traceback to pytest", None
|
|
363
419
|
|
|
364
420
|
# python -m unittest (or python3 -m unittest): wrap with tokensafe wrap to fold test noise
|
|
365
|
-
if cmd_tok.startswith("python") and
|
|
421
|
+
if cmd_tok.startswith("python") and cls._python_module(cmd_args) == "unittest":
|
|
366
422
|
if cls._is_tokensafe_available() and not cls._TOKENSAFE_WRAP_RE.search(stage):
|
|
367
423
|
wrapped = f"tokensafe wrap {shlex.quote(stage)}"
|
|
368
424
|
return wrapped, 2000, "Wrapped python unittest with tokensafe wrap to compact test results into one-line summary", None
|
|
@@ -395,12 +451,14 @@ class CommandSanitizer:
|
|
|
395
451
|
|
|
396
452
|
# find: prune unbounded recursion on simple directory crawls (avoid breaking -o / -exec / -delete expressions)
|
|
397
453
|
if cmd_tok == "find" and "node_modules" not in stage and ".git" not in stage:
|
|
398
|
-
|
|
454
|
+
# An action before the appended tests would run on pruned paths too.
|
|
455
|
+
has_complex = any(a in cls._FIND_COMPLEX_ARGS for a in cmd_args)
|
|
399
456
|
if not has_complex and (
|
|
400
457
|
re.search(r"\bfind\s+(\.|\/|[\w./-]+)\s*$", stage)
|
|
401
458
|
or re.search(r"\bfind\s+\.\s+-name\b", stage)
|
|
402
459
|
):
|
|
403
|
-
|
|
460
|
+
# '*/.*' also hid the dot-files being searched for (find . -name .env).
|
|
461
|
+
new_stage = f"{stage} {cls._FIND_PRUNE}"
|
|
404
462
|
return new_stage, 1500, "Pruned .git, node_modules, and venv from find", None
|
|
405
463
|
|
|
406
464
|
# grep / egrep recursive search: exclude junk dirs and cap output
|
|
@@ -462,12 +520,17 @@ class CommandSanitizer:
|
|
|
462
520
|
|
|
463
521
|
# curl printing to stdout
|
|
464
522
|
if cmd_tok == "curl":
|
|
465
|
-
if not cls._CURL_FILE_RE.search(stage):
|
|
523
|
+
if not cls._CURL_FILE_RE.search(stage) and not cls._curl_fails_on_http_error(cmd_args):
|
|
466
524
|
return stage, 3000, "Capped curl stdout to 4096 bytes", cls._CAP_BYTES_4K
|
|
467
525
|
|
|
468
526
|
# ls: replace verbose flags (-l, -a, -la, -lah) while preserving functional flags like -R, -t, -S
|
|
469
527
|
if cmd_tok == "ls" and cls._LS_VERBOSE_RE.search(stage):
|
|
470
|
-
|
|
528
|
+
# -a/-A select WHICH entries are listed; dropping them hid dotfiles.
|
|
529
|
+
def _compact_ls(m: "re.Match[str]") -> str:
|
|
530
|
+
flags = m.group(1)
|
|
531
|
+
keep = "".join(f for f in "aA" if f in flags)
|
|
532
|
+
return "ls -1 -p" + (f" -{keep}" if keep else "")
|
|
533
|
+
new_stage = cls._LS_VERBOSE_RE.sub(_compact_ls, stage, count=1)
|
|
471
534
|
return new_stage, 380, "Replaced verbose ls flags with compact, secret-safe format (-1 -p)", None
|
|
472
535
|
|
|
473
536
|
return None
|
|
@@ -703,7 +766,7 @@ class CommandSanitizer:
|
|
|
703
766
|
via npx at dev-server start (or fail offline), so the command must stay as-is.
|
|
704
767
|
"""
|
|
705
768
|
try:
|
|
706
|
-
from
|
|
769
|
+
from tokensafe.retrofit import resolve_tokensafe_ui_cli
|
|
707
770
|
return resolve_tokensafe_ui_cli(cwd) is not None
|
|
708
771
|
except Exception:
|
|
709
772
|
return False
|
|
@@ -982,12 +1045,14 @@ class CommandSanitizer:
|
|
|
982
1045
|
return f"PASS: {clean}"
|
|
983
1046
|
|
|
984
1047
|
# 2. unittest check
|
|
1048
|
+
# The verdict line is exactly "OK" or "OK (skipped=N)" and only counts after
|
|
1049
|
+
# a "Ran N tests" line: a bare prefix match took `OKTA_DOMAIN=…` for a pass.
|
|
985
1050
|
ran_line = ""
|
|
986
1051
|
for line in lines:
|
|
987
|
-
if
|
|
1052
|
+
if re.match(r"Ran \d+ tests? in ", line):
|
|
988
1053
|
ran_line = line
|
|
989
|
-
elif
|
|
990
|
-
return f"PASS: {ran_line
|
|
1054
|
+
elif ran_line and re.fullmatch(r"OK(?:\s+\(.*\))?", line):
|
|
1055
|
+
return f"PASS: {ran_line} ({line})"
|
|
991
1056
|
|
|
992
1057
|
# 3. jest / vitest check
|
|
993
1058
|
for line in reversed(lines):
|
|
@@ -1001,9 +1066,10 @@ class CommandSanitizer:
|
|
|
1001
1066
|
if line.startswith("test result: ok."):
|
|
1002
1067
|
return f"PASS: {line}"
|
|
1003
1068
|
|
|
1004
|
-
# 5. go test check
|
|
1069
|
+
# 5. go test check: `go test` prints a lone "PASS" line or "ok \t<pkg>\t<time>";
|
|
1070
|
+
# a prefix match also took `PASSWORD_MIN=8` from `cat .env` for a pass.
|
|
1005
1071
|
for line in reversed(lines):
|
|
1006
|
-
if line.startswith("ok \t") or line
|
|
1072
|
+
if line.startswith("ok \t") or line == "PASS":
|
|
1007
1073
|
return f"PASS: {line}"
|
|
1008
1074
|
|
|
1009
1075
|
# 6. bun test check
|
|
@@ -1015,10 +1081,10 @@ class CommandSanitizer:
|
|
|
1015
1081
|
if re.search(r"^\d+\s+pass\b", line):
|
|
1016
1082
|
return f"PASS: {line} (bun test)"
|
|
1017
1083
|
|
|
1018
|
-
#
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1084
|
+
# No recognised runner summary: this is not test output (`cat`, `ls`, `wc`,
|
|
1085
|
+
# `git diff --stat` …). Return it untouched. The former "first line … last
|
|
1086
|
+
# line (exit code 0)" fallback replaced ordinary output with a fake PASS
|
|
1087
|
+
# verdict and an exit code nobody reported.
|
|
1022
1088
|
return raw
|
|
1023
1089
|
|
|
1024
1090
|
# PostToolUse shell tools whose stdout can be compacted (hook payload tool_name)
|
|
@@ -1076,13 +1142,13 @@ class CommandSanitizer:
|
|
|
1076
1142
|
raw, resolved_exit = cls._extract_tool_stdout(tool_response)
|
|
1077
1143
|
if not raw or len(raw) < 400:
|
|
1078
1144
|
return None
|
|
1079
|
-
from
|
|
1145
|
+
from tokensafe.format_parsers.ansi import strip_ansi
|
|
1080
1146
|
raw = strip_ansi(raw)
|
|
1081
1147
|
|
|
1082
1148
|
# Every replacement passes the format-invariant gate: no inflation, no
|
|
1083
1149
|
# dropped diff/table/declaration lines, and structural lossy output gets
|
|
1084
1150
|
# an exact-recovery anchor. A rejected candidate keeps the raw output.
|
|
1085
|
-
from
|
|
1151
|
+
from tokensafe.format_invariants import gate as _format_gate
|
|
1086
1152
|
|
|
1087
1153
|
def _accept(candidate: Optional[str]) -> Optional[Tuple[str, int, int]]:
|
|
1088
1154
|
if not candidate:
|
|
@@ -1093,7 +1159,9 @@ class CommandSanitizer:
|
|
|
1093
1159
|
if resolved_exit is None:
|
|
1094
1160
|
# Unknown exit status: refuse to mute anything that looks like a failure,
|
|
1095
1161
|
# but allow noise-only stripping (tracebacks stay intact) when it saves >=15%.
|
|
1096
|
-
|
|
1162
|
+
# Case-insensitive "error": tsc (`error TS2322`), gcc/rustc (`error:`) and
|
|
1163
|
+
# npm (`npm error`) print it lower-case and a red run must not read as clean.
|
|
1164
|
+
if re.search(r"Traceback|AssertionError|(?i:\berror\b)|FAILED|exit code [1-9]", raw):
|
|
1097
1165
|
stripped = cls._strip_failure_noise(raw)
|
|
1098
1166
|
if len(stripped) < len(raw) * 0.85:
|
|
1099
1167
|
return _accept(stripped)
|
|
@@ -1101,12 +1169,12 @@ class CommandSanitizer:
|
|
|
1101
1169
|
resolved_exit = 0
|
|
1102
1170
|
elif resolved_exit != 0:
|
|
1103
1171
|
# Check test & compiler error compactor first (tsc error cascades, pytest failures)
|
|
1104
|
-
from
|
|
1172
|
+
from tokensafe.test_parsers import TestOutputParser
|
|
1105
1173
|
compacted_test, was_test = TestOutputParser.compact(raw)
|
|
1106
1174
|
if was_test and len(compacted_test) < len(raw) * 0.85:
|
|
1107
1175
|
return _accept(compacted_test)
|
|
1108
1176
|
|
|
1109
|
-
from
|
|
1177
|
+
from tokensafe.build_parsers import BuildOutputParser
|
|
1110
1178
|
compacted_build, was_build = BuildOutputParser.compact(raw, resolved_exit)
|
|
1111
1179
|
if was_build and len(compacted_build) < len(raw) * 0.85:
|
|
1112
1180
|
return _accept(compacted_build)
|
|
@@ -1118,7 +1186,7 @@ class CommandSanitizer:
|
|
|
1118
1186
|
return None
|
|
1119
1187
|
return _accept(stripped)
|
|
1120
1188
|
# Check build output parser first (vite, next, webpack, cargo, go build)
|
|
1121
|
-
from
|
|
1189
|
+
from tokensafe.build_parsers import BuildOutputParser
|
|
1122
1190
|
compacted_build, was_build = BuildOutputParser.compact(raw, resolved_exit)
|
|
1123
1191
|
if was_build and len(compacted_build) < len(raw) * 0.8:
|
|
1124
1192
|
return _accept(compacted_build)
|
|
@@ -1127,7 +1195,7 @@ class CommandSanitizer:
|
|
|
1127
1195
|
# errors, but only `tokensafe wrap` and the result ledger used it — this path
|
|
1128
1196
|
# rewrote docker output to `| tail -50` and lost the stage structure. Success
|
|
1129
1197
|
# only: a failed build keeps every diagnostic line for the failure branch.
|
|
1130
|
-
from
|
|
1198
|
+
from tokensafe.format_parsers.docker_k8s import ContainerAndK8sReducer
|
|
1131
1199
|
reduced_docker, was_docker = ContainerAndK8sReducer.reduce_docker_build(raw)
|
|
1132
1200
|
if was_docker and len(reduced_docker) < len(raw) * 0.8:
|
|
1133
1201
|
return _accept(reduced_docker)
|
|
@@ -22,7 +22,7 @@ import os
|
|
|
22
22
|
import time
|
|
23
23
|
from typing import Any, Dict, Iterable, List, Optional, Sequence
|
|
24
24
|
|
|
25
|
-
from
|
|
25
|
+
from tokensafe.paths import resolve_data_dir
|
|
26
26
|
|
|
27
27
|
MARKER_TTL_SECONDS = 900
|
|
28
28
|
DEFAULT_MAX_CHARS = 1400
|
|
@@ -49,7 +49,7 @@ def mark_pending(
|
|
|
49
49
|
if not session_id:
|
|
50
50
|
return
|
|
51
51
|
try:
|
|
52
|
-
from
|
|
52
|
+
from tokensafe.atomic_io import write_text_atomic
|
|
53
53
|
|
|
54
54
|
os.makedirs(_marker_dir(), exist_ok=True)
|
|
55
55
|
payload = {
|
|
@@ -180,7 +180,7 @@ def _preserved_ids(boundary: Optional[Dict[str, Any]]) -> set:
|
|
|
180
180
|
def _orientation(records: Sequence[Dict[str, Any]]) -> Dict[str, str]:
|
|
181
181
|
"""Three-line orientation digest from the shared history compactor."""
|
|
182
182
|
try:
|
|
183
|
-
from
|
|
183
|
+
from tokensafe.history_compactor import (
|
|
184
184
|
HistoryCompactor,
|
|
185
185
|
_COMMAND_KEYS,
|
|
186
186
|
_COMMAND_TOOLS,
|
|
@@ -237,7 +237,7 @@ def build_digest(
|
|
|
237
237
|
"""Orientation digest + pointers to the turns the last compaction dropped."""
|
|
238
238
|
if not transcript_path or not os.path.exists(transcript_path):
|
|
239
239
|
return None
|
|
240
|
-
from
|
|
240
|
+
from tokensafe.transcript_recall import read_records, rank_turns, turns_from_records
|
|
241
241
|
|
|
242
242
|
try:
|
|
243
243
|
records = read_records(transcript_path)
|
|
@@ -316,7 +316,7 @@ def consume_digest(
|
|
|
316
316
|
digest = build_digest(path, str((marker or {}).get("agent") or agent or ""))
|
|
317
317
|
if digest:
|
|
318
318
|
try:
|
|
319
|
-
from
|
|
319
|
+
from tokensafe.metrics import MetricsTracker
|
|
320
320
|
|
|
321
321
|
tracker = MetricsTracker()
|
|
322
322
|
tracker.record_event(
|
|
@@ -9,95 +9,148 @@ import os
|
|
|
9
9
|
import json
|
|
10
10
|
import re
|
|
11
11
|
from typing import Dict, List, Optional, Any
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
from
|
|
15
|
-
from
|
|
16
|
-
from
|
|
12
|
+
from tokensafe.tokenizer import count_tokens
|
|
13
|
+
from tokensafe.distiller import UniversalDistiller
|
|
14
|
+
from tokensafe.secret_redactor import SecretRedactor
|
|
15
|
+
from tokensafe.license_manager import LicenseManager
|
|
16
|
+
from tokensafe.paths import resolve_data_dir
|
|
17
17
|
|
|
18
18
|
class PromptCompactor:
|
|
19
19
|
"""Transforms verbose natural language requests into compact Intent IR across major world languages."""
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
21
|
+
# Stop phrases per language. Only English (prompts mix it with code)
|
|
22
|
+
# and the prompt's detected language are stripped: the full union removed
|
|
23
|
+
# English words that are stop words elsewhere (German 'die', 'was', 'will';
|
|
24
|
+
# Spanish/Italian 'con', 'a'; Portuguese 'do', 'e').
|
|
25
|
+
STOP_PHRASES_BY_LANG: Dict[str, List[str]] = {
|
|
26
|
+
"en": [
|
|
27
|
+
# English courtesy, prepositions, fillers & directives
|
|
28
|
+
r"\b(please|kindly|could you please|could you|would you mind|would you|thank you|thanks in advance|thanks)\b",
|
|
29
|
+
r"\b(hello|hi there|hi|hey|good morning|good evening|good afternoon)\b",
|
|
30
|
+
r"\b(listen|look|basically|anyway|actually|to be honest|just)\b",
|
|
31
|
+
r"\b(can you help me with|can you help me|can you|help me to|help me|i want you to|i would like you to|i need to|i want to|we need to|lets|let's)\b",
|
|
32
|
+
r"\b(make sure to|make sure that|tell me how to|show me how to|what is the reason|how can i)\b",
|
|
33
|
+
r"\b(in file|inside file|the function|the method|the class|file|function|method|class|project|code)\b",
|
|
34
|
+
r"\b(add to it|make it|so that it)\b",
|
|
35
|
+
r"\b(and|with|on|at|for|from|to|the|a|an|in|of|is|are|it|its|this|that|these|those)\b",
|
|
36
|
+
],
|
|
37
|
+
"es": [
|
|
38
|
+
# Spanish (Español)
|
|
39
|
+
r"\b(por\s+favor|muchas\s+gracias|gracias|te\s+agradecer[ií]a|agradezco)\b",
|
|
40
|
+
r"\b(hola|buenos\s+d[ií]as|buenas\s+tardes|buenas\s+noches|saludos)\b",
|
|
41
|
+
r"\b(mira|oye|b[aá]sicamente|en\s+realidad|de\s+hecho|a\s+ver)\b",
|
|
42
|
+
r"\b(puedes\s+ayudarme|puedes|podr[ií]as|ay[uú]dame|necesito\s+que|quiero\s+que|vamos\s+a)\b",
|
|
43
|
+
r"\b(aseg[uú]rate\s+de|dime\s+c[oó]mo|mu[eé]strame|cu[aá]l\s+es\s+el\s+problema|c[oó]mo\s+puedo)\b",
|
|
44
|
+
r"\b(en\s+el\s+archivo|del\s+archivo|el\s+archivo|archivo|la\s+funci[oó]n|funci[oó]n|el\s+m[eé]todo|m[eé]todo|la\s+clase|clase|el\s+c[oó]digo|c[oó]digo|proyecto)\b",
|
|
45
|
+
r"\b(para\s+que|de\s+modo\s+que|y|con|en|de|a|el|la|los|las|un|una|unos|unas|este|esta|esto|es|son|por)\b",
|
|
46
|
+
],
|
|
47
|
+
"de": [
|
|
48
|
+
# German (Deutsch)
|
|
49
|
+
r"\b(bitte|vielen\s+dank|danke\s+im\s+voraus|danke\s+schön|danke)\b",
|
|
50
|
+
r"\b(hallo|guten\s+tag|guten\s+morgen|guten\s+abend|grüß\s+gott)\b",
|
|
51
|
+
r"\b(schau\s+mal|eigentlich|im\s+grunde|übrigens|quasi)\b",
|
|
52
|
+
r"\b(kannst\s+du\s+mir\s+helfen|kannst\s+du|könntest\s+du|hilf\s+mir|ich\s+brauche|ich\s+möchte|wir\s+müssen|lass\s+uns)\b",
|
|
53
|
+
r"\b(stelle\s+sicher|sag\s+mir|zeige\s+mir|was\s+ist\s+der\s+grund|wie\s+kann\s+ich)\b",
|
|
54
|
+
r"\b(in\s+der\s+datei|aus\s+der\s+datei|die\s+datei|datei|die\s+funktion|funktion|die\s+methode|methode|die\s+klasse|klasse|der\s+code|code|projekt)\b",
|
|
55
|
+
r"\b(damit|sodass|und|mit|auf|für|von|zu|der|die|das|den|dem|ein|eine|dies|diese|ist|sind)\b",
|
|
56
|
+
],
|
|
57
|
+
"fr": [
|
|
58
|
+
# French (Français)
|
|
59
|
+
r"\b(s'il\s+vous\s+pla[iî]t|s'il\s+te\s+pla[iî]t|svp|stp|merci\s+d'avance|merci\s+beaucoup|merci)\b",
|
|
60
|
+
r"\b(bonjour|bonsoir|salut|coucou|bienvenue)\b",
|
|
61
|
+
r"\b([eé]coute|regarde|en\s+fait|fondamentalement|au\s+fait|bref)\b",
|
|
62
|
+
r"\b(peux-tu\s+m'aider|peux-tu|pourrais-tu|aide-moi|j'ai\s+besoin\s+de|je\s+veux\s+que|il\s+faut\s+que)\b",
|
|
63
|
+
r"\b(assure-toi\s+de|dis-moi\s+comment|montre-moi|quelle\s+est\s+la\s+raison|comment\s+faire)\b",
|
|
64
|
+
r"\b(dans\s+le\s+fichier|du\s+fichier|le\s+fichier|fichier|la\s+fonction|fonction|la\s+m[eé]thode|m[eé]thode|la\s+classe|classe|le\s+code|code|projet)\b",
|
|
65
|
+
r"\b(pour\s+que|afin\s+que|et|avec|sur|dans|pour|de|le|la|les|un|une|des|ce|cette|ces|est|sont)\b",
|
|
66
|
+
],
|
|
67
|
+
"pt": [
|
|
68
|
+
# Portuguese (Português)
|
|
69
|
+
r"\b(por\s+favor|muito\s+obrigado|obrigado|obrigada|valeu|grato)\b",
|
|
70
|
+
r"\b(ol[aá]|bom\s+dia|boa\s+tarde|boa\s+noite|fala|e\s+a[ií])\b",
|
|
71
|
+
r"\b(olha|veja|basicamente|na\s+verdade|ent[aã]o)\b",
|
|
72
|
+
r"\b(voc[eê]\s+pode|poderia|ajude-me|me\s+ajuda|preciso\s+que|quero\s+que|vamos)\b",
|
|
73
|
+
r"\b(certifique-se\s+de|me\s+diga\s+como|me\s+mostre|qual\s+[eé]\s+o\s+motivo|como\s+posso)\b",
|
|
74
|
+
r"\b(no\s+arquivo|do\s+arquivo|o\s+arquivo|arquivo|a\s+funç[aã]o|funç[aã]o|o\s+m[eé]todo|m[eé]todo|a\s+classe|classe|o\s+c[oó]digo|c[oó]digo|projeto)\b",
|
|
75
|
+
r"\b(para\s+que|de\s+modo\s+que|e|com|em|de|a|o|a|os|as|um|uma|este|esta|isso|isto|[eé]|s[aã]o)\b",
|
|
76
|
+
],
|
|
77
|
+
"it": [
|
|
78
|
+
# Italian (Italiano)
|
|
79
|
+
r"\b(per\s+favore|per\s+cortesia|grazie\s+mille|grazie)\b",
|
|
80
|
+
r"\b(ciao|buongiorno|buonasera|salve)\b",
|
|
81
|
+
r"\b(puoi|potresti|aiutami|ho\s+bisogno\s+di|voglio\s+che)\b",
|
|
82
|
+
r"\b(nel\s+file|dal\s+file|il\s+file|file|la\s+funzione|funzione|il\s+metodo|metodo|la\s+classe|classe|il\s+codice|codice|progetto)\b",
|
|
83
|
+
r"\b(in\s+modo\s+che|affinch[eé]|e|con|su|in|di|a|il|lo|la|i|gli|le|un|uno|una|questo|questa|[eè]|sono)\b",
|
|
84
|
+
],
|
|
85
|
+
"ru": [
|
|
86
|
+
# Russian (Русский)
|
|
87
|
+
r"\b(пожалуйста|будь добр|будь любезен|если не трудно|заранее спасибо|спасибо|благодарю)\b",
|
|
88
|
+
r"\b(привет|здравствуй|здравствуйте|добрый день|добрый вечер|доброе утро|хай|салют)\b",
|
|
89
|
+
r"\b(слушай|смотри|короче|кстати|в общем|в общем-то|дело в том что)\b",
|
|
90
|
+
r"\b(можешь ли ты|можешь|не мог бы ты|помоги мне|помоги пожалуйста|мне нужно|я хочу чтобы ты|я хочу|нужно чтобы|надо чтобы|надо|нужно|давай)\b",
|
|
91
|
+
r"\b(подскажи как|подскажи пожалуйста|подскажи|расскажи как|сделай так чтобы|сделай пожалуйста|попробуй|попробуем)\b",
|
|
92
|
+
r"\b(как думаешь|как считаешь|по твоему мнению|в чем проблема|почему|почему падает|не работает)\b",
|
|
93
|
+
r"\b(в файле|из файла|внутри файла|файле|файл|функцию|функция|функции|метод|методе|метода|класс|классе|класса|код|кода|строку|строка|проект|проекта|проекте|описани\w*|пояснени\w*|информаци\w*)\b",
|
|
94
|
+
r"\b(добавь туда|сделай её|сделай его|сделай их|чтобы было|чтобы он|чтобы она|чтобы оно|для этого|для того чтобы)\b",
|
|
95
|
+
# Note: «не» (negation) is deliberately NOT stripped — removing it inverted
|
|
96
|
+
# the meaning of prompts like "не удаляй файл" ("do not delete the file").
|
|
97
|
+
r"\b(и|в|на|с|при|по|к|из|у|о|об|от|под|над|для|бы|ли|же|то|это|этот|эта|эти|он|она|оно|они|ему|ей|им|их|его|ее)\b",
|
|
98
|
+
],
|
|
99
|
+
"zh": [
|
|
100
|
+
# Chinese (中文)
|
|
101
|
+
r"(请|麻烦|谢谢|多谢|你好|您好|早上好|晚上好)",
|
|
102
|
+
r"(你看|其实|基本上|你能|可以帮我|帮我|我需要|我想|我们要|让我们)",
|
|
103
|
+
r"(请问|为什么|怎么做|如何|看一下)",
|
|
104
|
+
r"(在文件|文件里|文件|中的|函数|方法|类|代码|项目)",
|
|
105
|
+
r"(为了|以便|并且|和|与|在|从|把|将|使|让|的|了|是|这|那)",
|
|
106
|
+
],
|
|
107
|
+
"ja": [
|
|
108
|
+
# Japanese (日本語)
|
|
109
|
+
r"(お願いします|お願い|ありがとう|よろしく|こんにちは|おはよう|こんばんは)",
|
|
110
|
+
r"(できますか|手伝って|必要があります|したい|しましょう|教えて|どうやって|なぜ)",
|
|
111
|
+
r"(ファイル内|ファイル|関数|メソッド|クラス|コード|プロジェクト)",
|
|
112
|
+
r"(のために|ように|そして|で|に|を|は|が|の|と|から|へ|これ|それ)",
|
|
113
|
+
],
|
|
114
|
+
}
|
|
115
|
+
STOP_PHRASES = [p for _lang in STOP_PHRASES_BY_LANG.values() for p in _lang]
|
|
116
|
+
|
|
117
|
+
# Distinctive function words per Latin-script language, used only to pick
|
|
118
|
+
# which stop-phrase set applies (see _stop_phrases_for).
|
|
119
|
+
_LANG_MARKERS = {
|
|
120
|
+
"en": re.compile(r"\b(the|and|is|are|to|of|for|with|this|that|it|please|should|does)\b", re.I),
|
|
121
|
+
"es": re.compile(r"\b(el|los|las|que|por|para|con|una|del|est[aá]|qu[eé]|c[oó]mo|puedes|archivo)\b", re.I),
|
|
122
|
+
"de": re.compile(r"\b(der|die|das|und|ist|nicht|mit|ich|bitte|eine|datei|kannst|warum)\b", re.I),
|
|
123
|
+
"fr": re.compile(r"\b(le|les|des|est|pour|avec|une|je|dans|pas|fichier|peux|pourquoi)\b", re.I),
|
|
124
|
+
"pt": re.compile(r"\b(os|n[aã]o|com|uma|para|voc[eê]|est[aá]|do|da|arquivo|pode)\b", re.I),
|
|
125
|
+
"it": re.compile(r"\b(il|lo|gli|che|non|per|una|sono|della|puoi|perch[eé]|codice)\b", re.I),
|
|
126
|
+
}
|
|
127
|
+
_CYRILLIC_RE = re.compile(r"[\u0400-\u04FF]")
|
|
128
|
+
_KANA_RE = re.compile(r"[\u3040-\u30FF]")
|
|
129
|
+
_HAN_RE = re.compile(r"[\u4E00-\u9FFF]")
|
|
130
|
+
|
|
131
|
+
@classmethod
|
|
132
|
+
def detect_language(cls, text: str) -> str:
|
|
133
|
+
"""Best-guess prompt language: en, es, de, fr, pt, it, ru, zh or ja."""
|
|
134
|
+
text = text or ""
|
|
135
|
+
if cls._KANA_RE.search(text):
|
|
136
|
+
return "ja"
|
|
137
|
+
if cls._HAN_RE.search(text):
|
|
138
|
+
return "zh"
|
|
139
|
+
if len(cls._CYRILLIC_RE.findall(text)) >= 3:
|
|
140
|
+
return "ru"
|
|
141
|
+
scores = {lang: len({m.lower() for m in rx.findall(text)}) for lang, rx in cls._LANG_MARKERS.items()}
|
|
142
|
+
best = max((l for l in scores if l != "en"), key=lambda l: scores[l])
|
|
143
|
+
if scores[best] >= 2 and scores[best] > scores["en"]:
|
|
144
|
+
return best
|
|
145
|
+
return "en"
|
|
146
|
+
|
|
147
|
+
@classmethod
|
|
148
|
+
def _stop_phrases_for(cls, text: str) -> List[str]:
|
|
149
|
+
lang = cls.detect_language(text)
|
|
150
|
+
phrases = list(cls.STOP_PHRASES_BY_LANG["en"])
|
|
151
|
+
if lang != "en":
|
|
152
|
+
phrases.extend(cls.STOP_PHRASES_BY_LANG.get(lang, []))
|
|
153
|
+
return phrases
|
|
101
154
|
|
|
102
155
|
ACTION_PATTERNS = [
|
|
103
156
|
("TEST", re.compile(
|
|
@@ -113,17 +166,17 @@ class PromptCompactor:
|
|
|
113
166
|
)),
|
|
114
167
|
("DEPLOY", re.compile(
|
|
115
168
|
r"\b(deploy|release|publish|ship|"
|
|
116
|
-
r"despleg\w*|
|
|
169
|
+
r"despleg\w*|publi(?:car|ca|can|que|quen|cad[oa]s?|caci[oó]n|cou|camos|cando)|lanz\w*|"
|
|
117
170
|
r"bereitstell\w*|veröffentlich\w*|releas\w*|"
|
|
118
171
|
r"déploy\w*|"
|
|
119
|
-
r"implant
|
|
172
|
+
r"implant(?:ar|a|e|em|ação|ado|ada|ou)|"
|
|
120
173
|
r"rilasci\w*|"
|
|
121
174
|
r"выкат\w*|задепло\w*|опублику\w*|релиз\w*)\b|"
|
|
122
175
|
r"(部署|发布|上线|デプロイ|リリース|公開)",
|
|
123
176
|
re.I
|
|
124
177
|
)),
|
|
125
178
|
("BENCHMARK", re.compile(
|
|
126
|
-
r"\b(benchmark|bench|profil
|
|
179
|
+
r"\b(benchmark|bench|profil(?:ing|er|ieren|iere|iert|ar|ando|ado)|"
|
|
127
180
|
r"evaluar|medir\s+rendimiento|"
|
|
128
181
|
r"profiling|leistungsmessung|"
|
|
129
182
|
r"analyser\s+la\s+performance|"
|
|
@@ -143,10 +196,10 @@ class PromptCompactor:
|
|
|
143
196
|
)),
|
|
144
197
|
("CLEAN", re.compile(
|
|
145
198
|
r"\b(clean(?:up)?|remove|delete|prune|vacuum|"
|
|
146
|
-
r"limpi\w*|elimin\w*|borr
|
|
199
|
+
r"limpi\w*|elimin\w*|borr(?:ar|a|e|en|ad[oa]s?|ando)|quit(?:ar|a|en|ad[oa]s?|ando)|"
|
|
147
200
|
r"bereinig\w*|lösch\w*|entfern\w*|aufräum\w*|"
|
|
148
201
|
r"nettoy\w*|supprim\w*|effac\w*|"
|
|
149
|
-
r"remov\w*|exclu
|
|
202
|
+
r"remov\w*|exclu(?:ir|a|i|am|ído|ída|indo)|apag\w*|"
|
|
150
203
|
r"pulir\w*|"
|
|
151
204
|
r"удал\w*|почист\w*|очист\w*|сотри)\b|"
|
|
152
205
|
r"(清理|清除|删除|クリーンアップ|削除|クリーン)",
|
|
@@ -194,8 +247,8 @@ class PromptCompactor:
|
|
|
194
247
|
re.I
|
|
195
248
|
)),
|
|
196
249
|
("DEBUG", re.compile(
|
|
197
|
-
r"\b(fix|debug|resolve|
|
|
198
|
-
r"arregl\w*|correg\w*|repar
|
|
250
|
+
r"\b(fix|fixes|debug|resolve|errors?|bugs?|issues?|broken|fail(?:s|ed|ing|ure)?|crash(?:es|ed|ing)?|build\s*fail\w*|"
|
|
251
|
+
r"arregl\w*|correg\w*|repar(?:ar|a|e|en|ad[oa]s?|ando)|depur\w*|fall(?:a|an|ar|e|en|o|ó|ando|ad[oa]s?|ido)|"
|
|
199
252
|
r"beheb\w*|reparier\w*|fehlschlag\w*|fehler\w*|korrigier\w*|"
|
|
200
253
|
r"corrig\w*|répar\w*|débogu\w*|bogue\w*|"
|
|
201
254
|
r"consert\w*|falha\w*|"
|
|
@@ -206,8 +259,8 @@ class PromptCompactor:
|
|
|
206
259
|
)),
|
|
207
260
|
("CREATE", re.compile(
|
|
208
261
|
r"\b(create|add|implement|build|write|new|generate|"
|
|
209
|
-
r"cre
|
|
210
|
-
r"erstell\w*|hinzufüg\w*|bau
|
|
262
|
+
r"cre(?:ar|a|e|en|ad[oa]s?|amos|ando)|añad\w*|agreg\w*|implement\w*|escrib\w*|gener(?:ar|a|e|en|ad[oa]s?|ando)|"
|
|
263
|
+
r"erstell\w*|hinzufüg\w*|bau(?:e|en|t)|"
|
|
211
264
|
r"cré\w*|ajout\w*|écr\w*|"
|
|
212
265
|
r"adicion\w*|escrev\w*|"
|
|
213
266
|
r"creare|aggiung\w*|"
|
|
@@ -558,7 +611,7 @@ class PromptCompactor:
|
|
|
558
611
|
protected_spans[tok] = extra_f
|
|
559
612
|
delta = delta.replace(extra_f, tok)
|
|
560
613
|
|
|
561
|
-
for pattern in cls.
|
|
614
|
+
for pattern in cls._stop_phrases_for(raw_text):
|
|
562
615
|
delta = re.sub(pattern, " ", delta, flags=re.I)
|
|
563
616
|
|
|
564
617
|
# Strip only the matched primary action word so secondary intents ("Fix error") survive
|