@teevee98/synapse-hub 4.1.1 → 4.1.2

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/tools/__init__.py CHANGED
@@ -14,7 +14,7 @@ Domain Packages:
14
14
  - tools.mcp: Model Context Protocol servers (core QA and Excel manipulation).
15
15
  """
16
16
 
17
- __version__ = "4.1.1"
17
+ __version__ = "4.1.2"
18
18
  __author__ = "Thế Vị (@TeeVee98)"
19
19
 
20
20
  # Expose domain packages
@@ -414,7 +414,10 @@ def format_markdown_report(bench: Dict[str, Any]) -> str:
414
414
  "",
415
415
  "## Track 2: Empirical Reference Suites Benchmark (Real Projects)",
416
416
  "",
417
- "| Reference Project | Detected Stack | Confidence | Catalog Summary Saved | Full Hydration Saved | Avoided Disk Read |",
417
+ "> *Methodology: Dynamically enumerates all 13 rules and 53 skills in repository without static per-skill multiplier assumptions.*",
418
+ "> *Disclosure: 'Avoided Disk Read' measures disk file bytes not read from storage, distinguished from prompt context tokens.*",
419
+ "",
420
+ "| Reference Project | Detected Stack | Confidence | Catalog Summary Saved | Full Hydration Saved | Avoided Disk Read (I/O) |",
418
421
  "|---|---|:---:|:---:|:---:|:---:|",
419
422
  ])
420
423
  for p in emp["results"]:
@@ -13,7 +13,7 @@
13
13
  (function () {
14
14
  'use strict';
15
15
 
16
- if (window.__qa && window.__qa.__version === '4.1.1') {
16
+ if (window.__qa && window.__qa.__version === '4.1.2') {
17
17
  return window.__qa;
18
18
  }
19
19
 
@@ -47,7 +47,7 @@
47
47
  }
48
48
 
49
49
  const qa = {
50
- __version: '4.1.1',
50
+ __version: '4.1.2',
51
51
 
52
52
  /**
53
53
  * 1. Smart Action Batching
package/tools/cli.py CHANGED
@@ -99,7 +99,7 @@ def cmd_set_lang(args):
99
99
  def cmd_version(args):
100
100
  """Displays the current hub version, skill catalog count, and license information."""
101
101
  manifest_path = os.path.join(REPO_ROOT, "skills_manifest.json")
102
- version = "4.1.1"
102
+ version = "4.1.2"
103
103
  if os.path.exists(manifest_path):
104
104
  try:
105
105
  import json
@@ -686,14 +686,14 @@ def cmd_trend(args):
686
686
 
687
687
  def _hub_version():
688
688
  manifest_path = os.path.join(REPO_ROOT, "skills_manifest.json")
689
- version = "4.1.1"
689
+ version = "4.1.2"
690
690
  if os.path.exists(manifest_path):
691
691
  try:
692
692
  import json
693
693
  with open(manifest_path, "r", encoding="utf-8") as f:
694
694
  version = json.load(f).get("version", version)
695
695
  except (OSError, json.JSONDecodeError):
696
- version = "4.1.1"
696
+ version = "4.1.2"
697
697
  return version
698
698
 
699
699
 
@@ -16,10 +16,13 @@ Key Capabilities:
16
16
  - Non-ASCII / Vietnamese diacritics / Unicode: ~1.8 characters/token.
17
17
  2. Optional native BPE tokenization if tiktoken is available in runtime.
18
18
  3. Structured token breakdown (Rules, Catalog Metadata, Full Skill Bodies, System Prefix).
19
+ 4. Real dynamic baseline calculation enumerating 100% of skills & rules without static estimates.
19
20
  """
20
21
 
21
22
  from __future__ import annotations
22
23
 
24
+ import glob
25
+ import json
23
26
  import os
24
27
  import re
25
28
  from typing import Any, Dict, List, Optional
@@ -36,6 +39,21 @@ try:
36
39
  except ImportError:
37
40
  _TIKTOKEN_ENCODER = None
38
41
 
42
+ _SKILLS_MANIFEST_CACHE: Optional[Dict[str, Dict[str, Any]]] = None
43
+
44
+
45
+ def get_estimator_info() -> Dict[str, Any]:
46
+ """Returns active tokenizer engine metadata, exactness status, and model hint."""
47
+ return {
48
+ "engine": "cl100k_base" if _TIKTOKEN_ENCODER is not None else "heuristic_polyglot",
49
+ "is_exact": _TIKTOKEN_ENCODER is not None,
50
+ "encoding": "cl100k_base",
51
+ "calibrated_ratios": {
52
+ "ascii_chars_per_token": 3.85,
53
+ "non_ascii_chars_per_token": 1.80,
54
+ },
55
+ }
56
+
39
57
 
40
58
  def count_tokens(text: str, model_hint: str = "cl100k") -> int:
41
59
  """
@@ -81,6 +99,38 @@ def count_file_tokens(file_path: str) -> int:
81
99
  return 0
82
100
 
83
101
 
102
+ def _get_skills_manifest(repo_root: str) -> Dict[str, Dict[str, Any]]:
103
+ """Loads and caches skills_manifest.json mapping skill_id to metadata."""
104
+ global _SKILLS_MANIFEST_CACHE
105
+ if _SKILLS_MANIFEST_CACHE is not None:
106
+ return _SKILLS_MANIFEST_CACHE
107
+
108
+ manifest_path = os.path.join(repo_root, "skills_manifest.json")
109
+ _SKILLS_MANIFEST_CACHE = {}
110
+ if os.path.isfile(manifest_path):
111
+ try:
112
+ with open(manifest_path, "r", encoding="utf-8") as f:
113
+ data = json.load(f)
114
+ for s in data.get("skills", []):
115
+ sid = s.get("id")
116
+ if sid:
117
+ _SKILLS_MANIFEST_CACHE[sid] = s
118
+ except (OSError, json.JSONDecodeError) as err:
119
+ _ = err
120
+ return _SKILLS_MANIFEST_CACHE
121
+
122
+
123
+ def serialize_skill_summary(skill_name: str, meta: Optional[Dict[str, Any]] = None) -> str:
124
+ """Formats a concise catalog summary line for a skill."""
125
+ if meta:
126
+ name = meta.get("name", skill_name)
127
+ domain = meta.get("domain", "")
128
+ desc = meta.get("description") or meta.get("summary", "")
129
+ domain_str = f" [{domain}]" if domain else ""
130
+ return f"- {name} ({skill_name}){domain_str}: {desc}"
131
+ return f"- {skill_name}: Enterprise QA Automation Skill"
132
+
133
+
84
134
  def calculate_hydration_payload(
85
135
  repo_root: str,
86
136
  rules: List[str],
@@ -88,11 +138,12 @@ def calculate_hydration_payload(
88
138
  ) -> Dict[str, Any]:
89
139
  """
90
140
  Computes precise dual-tier token metrics for a set of selected rules and skills:
91
- 1. summary: Catalog metadata only (name + summary description ~120 tokens/skill).
141
+ 1. summary: Catalog metadata only (serialized name + domain + description).
92
142
  2. full: Complete SKILL.md body hydrated into context.
93
143
  """
94
144
  rules_dir = os.path.join(repo_root, ".agents", "rules")
95
145
  skills_root = os.path.join(repo_root, ".agents", "skills")
146
+ manifest = _get_skills_manifest(repo_root)
96
147
 
97
148
  rule_tokens = 0
98
149
  rule_bytes = 0
@@ -105,12 +156,15 @@ def calculate_hydration_payload(
105
156
  rule_tokens += 500 # Default estimate for virtual rule
106
157
  rule_bytes += 2000
107
158
 
108
- catalog_skill_tokens = len(skills) * 120
159
+ catalog_lines = []
109
160
  full_skill_tokens = 0
110
161
  full_skill_bytes = 0
111
162
 
112
163
  # Locate each skill directory in .agents/skills
113
164
  for skill_name in skills:
165
+ meta = manifest.get(skill_name)
166
+ catalog_lines.append(serialize_skill_summary(skill_name, meta))
167
+
114
168
  skill_file = _find_skill_file(skills_root, skill_name)
115
169
  if skill_file and os.path.isfile(skill_file):
116
170
  tokens = count_file_tokens(skill_file)
@@ -118,9 +172,11 @@ def calculate_hydration_payload(
118
172
  full_skill_tokens += tokens
119
173
  full_skill_bytes += size
120
174
  else:
121
- # Fallback average skill size (~1,800 tokens, 7.5 KB)
122
- full_skill_tokens += 1800
123
- full_skill_bytes += 7500
175
+ # Fallback average skill size if file missing
176
+ full_skill_tokens += 1200
177
+ full_skill_bytes += 4500
178
+
179
+ catalog_skill_tokens = count_tokens("\n".join(catalog_lines)) if catalog_lines else 0
124
180
 
125
181
  return {
126
182
  "rule_tokens": rule_tokens,
@@ -134,6 +190,65 @@ def calculate_hydration_payload(
134
190
  }
135
191
 
136
192
 
193
+ def get_full_unrouted_baseline(repo_root: str) -> Dict[str, Any]:
194
+ """
195
+ Enumerates and calculates actual token and byte counts for 100% of all rules in .agents/rules
196
+ and 100% of all skills in .agents/skills.
197
+ Guarantees zero static assumptions (replaces 53 * 1800 and 53 * 120 with exact file token counts).
198
+ """
199
+ rules_dir = os.path.join(repo_root, ".agents", "rules")
200
+ skills_root = os.path.join(repo_root, ".agents", "skills")
201
+ manifest = _get_skills_manifest(repo_root)
202
+
203
+ # 1. Enumerate all rule files
204
+ all_rule_files: List[str] = []
205
+ if os.path.isdir(rules_dir):
206
+ all_rule_files = sorted([f for f in os.listdir(rules_dir) if f.endswith(".md")])
207
+
208
+ total_rule_tokens = 0
209
+ total_rule_bytes = 0
210
+ for rf in all_rule_files:
211
+ p = os.path.join(rules_dir, rf)
212
+ total_rule_tokens += count_file_tokens(p)
213
+ total_rule_bytes += os.path.getsize(p)
214
+
215
+ # 2. Enumerate all 53 SKILL.md files
216
+ skill_files = sorted(glob.glob(os.path.join(skills_root, "*", "*", "SKILL.md")))
217
+ total_skill_tokens = 0
218
+ total_skill_bytes = 0
219
+ all_skill_ids: List[str] = []
220
+
221
+ for sf in skill_files:
222
+ total_skill_tokens += count_file_tokens(sf)
223
+ total_skill_bytes += os.path.getsize(sf)
224
+ skill_id = os.path.basename(os.path.dirname(sf))
225
+ all_skill_ids.append(skill_id)
226
+
227
+ # 3. Dynamic Catalog Summary tokens across all skills
228
+ catalog_lines = []
229
+ for sid in all_skill_ids:
230
+ meta = manifest.get(sid)
231
+ catalog_lines.append(serialize_skill_summary(sid, meta))
232
+
233
+ total_cat_tokens = count_tokens("\n".join(catalog_lines)) if catalog_lines else 0
234
+
235
+ return {
236
+ "rule_count": len(all_rule_files),
237
+ "rule_tokens": total_rule_tokens,
238
+ "rule_bytes": total_rule_bytes,
239
+ "skill_count": len(skill_files),
240
+ "skill_full_body_tokens": total_skill_tokens,
241
+ "skill_full_bytes": total_skill_bytes,
242
+ "skill_catalog_tokens": total_cat_tokens,
243
+ "total_summary_baseline": total_rule_tokens + total_cat_tokens,
244
+ "total_full_baseline": total_rule_tokens + total_skill_tokens,
245
+ "total_full_bytes": total_rule_bytes + total_skill_bytes,
246
+ "all_rules": all_rule_files,
247
+ "all_skills": all_skill_ids,
248
+ "estimator_info": get_estimator_info(),
249
+ }
250
+
251
+
137
252
  def _find_skill_file(skills_root: str, skill_name: str) -> Optional[str]:
138
253
  """Finds SKILL.md for a given skill name across tiered category folders."""
139
254
  if not os.path.isdir(skills_root):
@@ -1348,7 +1348,7 @@ def _build_target_translations(
1348
1348
  "th_step_status": "Trạng Thái",
1349
1349
  "th_step_details": "Chi Tiết Kỹ Thuật (OTel & AST)",
1350
1350
 
1351
- "footer_text": "Báo cáo được khởi tạo tự động bởi Synapse-Hub v4.1.1 • Bản quyền © Thế Vị (@TeeVee98) • Chuẩn Clean POM & Kiểm Thử Tự Chủ",
1351
+ "footer_text": "Báo cáo được khởi tạo tự động bởi Synapse-Hub v4.1.2 • Bản quyền © Thế Vị (@TeeVee98) • Chuẩn Clean POM & Kiểm Thử Tự Chủ",
1352
1352
  }
1353
1353
 
1354
1354
  translations_en = {
@@ -1426,7 +1426,7 @@ def _build_target_translations(
1426
1426
  "th_step_status": "Status",
1427
1427
  "th_step_details": "Technical Details (OTel & AST)",
1428
1428
 
1429
- "footer_text": "Generated automatically by Synapse-Hub v4.1.1 • Copyright © Thế Vị (@TeeVee98) • Clean POM & Autonomous Testing",
1429
+ "footer_text": "Generated automatically by Synapse-Hub v4.1.2 • Copyright © Thế Vị (@TeeVee98) • Clean POM & Autonomous Testing",
1430
1430
  }
1431
1431
 
1432
1432
  _inject_gate_translations(translations_vi, translations_en, gates)
@@ -1915,7 +1915,7 @@ def _build_hub_translations(
1915
1915
  """Builds bilingual dictionaries for Hub Dashboard."""
1916
1916
  translations_vi = {
1917
1917
  "header_title": "Bảng Điều Hành Chất Lượng Doanh Nghiệp",
1918
- "header_subtitle": "Synapse-Hub v4.1.1 • Hệ Sinh Thái Kiểm Thử AI Agent Tự Chủ",
1918
+ "header_subtitle": "Synapse-Hub v4.1.2 • Hệ Sinh Thái Kiểm Thử AI Agent Tự Chủ",
1919
1919
  "nav_welcome": "Giới Thiệu",
1920
1920
  "meta_mode": "🏷️ Chế độ: <strong>HỆ SINH THÁI QA HUB</strong>",
1921
1921
  "meta_gen": f"🕒 Khởi tạo: <strong>{now_str}</strong>",
@@ -1985,12 +1985,12 @@ def _build_hub_translations(
1985
1985
  "th_sk_ver": "Phiên Bản",
1986
1986
  "th_sk_cap": "Khả Năng Nghiệp Vụ Cốt Lõi",
1987
1987
 
1988
- "footer_text": "Bảng Điều Hành Chất Lượng Doanh Nghiệp &bull; Synapse-Hub v4.1.1 &bull; Bản quyền &copy; Thế Vị (@TeeVee98) &bull; Hệ Thống Kiểm Thử AI Agent Tự Chủ",
1988
+ "footer_text": "Bảng Điều Hành Chất Lượng Doanh Nghiệp &bull; Synapse-Hub v4.1.2 &bull; Bản quyền &copy; Thế Vị (@TeeVee98) &bull; Hệ Thống Kiểm Thử AI Agent Tự Chủ",
1989
1989
  }
1990
1990
 
1991
1991
  translations_en = {
1992
1992
  "header_title": "Enterprise QA Executive Dashboard",
1993
- "header_subtitle": "Synapse-Hub v4.1.1 &bull; Autonomous AI Agent Testing Ecosystem",
1993
+ "header_subtitle": "Synapse-Hub v4.1.2 &bull; Autonomous AI Agent Testing Ecosystem",
1994
1994
  "nav_welcome": "Welcome",
1995
1995
  "meta_mode": "🏷️ Mode: <strong>QA HUB ECOSYSTEM</strong>",
1996
1996
  "meta_gen": f"🕒 Generated: <strong>{now_str}</strong>",
@@ -2060,7 +2060,7 @@ def _build_hub_translations(
2060
2060
  "th_sk_ver": "Version",
2061
2061
  "th_sk_cap": "Core Capabilities",
2062
2062
 
2063
- "footer_text": "Enterprise QA Executive Dashboard &bull; Synapse-Hub v4.1.1 &bull; Copyright &copy; Thế Vị (@TeeVee98) &bull; Autonomous AI Agent Testing Ecosystem",
2063
+ "footer_text": "Enterprise QA Executive Dashboard &bull; Synapse-Hub v4.1.2 &bull; Copyright &copy; Thế Vị (@TeeVee98) &bull; Autonomous AI Agent Testing Ecosystem",
2064
2064
  }
2065
2065
 
2066
2066
  _inject_gate_translations(translations_vi, translations_en, gates)
@@ -5,9 +5,18 @@
5
5
 
6
6
  """
7
7
  tools/distill_log.py — Enterprise Multi-Framework Log Distiller (Token & Failure Sentinel)
8
- Filters out 90%+ passing step noise and outputs strictly actionable, evidence-backed
9
- failure triage blocks without false passes or dropped assertion diffs.
10
- Supports Pytest, Playwright, Jest/Vitest, Katalon KRE, Gradle, and Python/Node/JVM logs.
8
+ ------------------------------------------------------------------------------------------
9
+ Distills massive, repetitive execution logs (Katalon Studio, Gradle, Playwright, Jest, Pytest)
10
+ down to exact failure triage blocks without false passes, false failures on info logs, or dropped assertion diffs.
11
+
12
+ Key Guarantees:
13
+ 1. Case-insensitive failure keyword scanning.
14
+ 2. Exit code Truth Anchor (nonzero -> RUNNER_NONZERO_EXIT; missing -> NO_FAILURE_SIGNATURE_DETECTED;
15
+ clean 0 with failure text -> CONFLICTING_SIGNALS).
16
+ 3. Informational logging filter ([INFO], [DEBUG]) preventing false-positive assertion detection.
17
+ 4. Genuine token_budget enforcement via calibrated tokenizer (default: 800 tokens).
18
+ 5. 15-line block bounding and noise suppression, compressing 95% of log volume.
19
+ 6. Provenance retention: points back to raw log file for forensic tracing.
11
20
  """
12
21
 
13
22
  from __future__ import annotations
@@ -26,6 +35,20 @@ if hasattr(sys.stdout, "reconfigure"):
26
35
  except Exception:
27
36
  pass
28
37
 
38
+ # Ensure repository root is on sys.path
39
+ _REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
40
+ if _REPO_ROOT not in sys.path:
41
+ sys.path.insert(0, _REPO_ROOT)
42
+
43
+ try:
44
+ from tools.core.token_estimator import count_tokens
45
+ except ImportError:
46
+ try:
47
+ from core.token_estimator import count_tokens
48
+ except ImportError:
49
+ def count_tokens(text: str, model_hint: str = "cl100k") -> int:
50
+ return max(1, len(text) // 4)
51
+
29
52
  # Universal noise patterns (passing steps, zero failures summary, timestamps, system initialization)
30
53
  NOISE_PATTERNS = [
31
54
  re.compile(r"^\s*$"),
@@ -49,6 +72,12 @@ NOISE_PATTERNS = [
49
72
  re.compile(r"Katalon Studio.*licensed to"),
50
73
  ]
51
74
 
75
+ # Informational logging prefix pattern (prevents informational lines from initiating failure blocks)
76
+ INFO_LOG_LINE = re.compile(
77
+ r"^\s*(?:\[?(?:INFO|DEBUG|NOTICE|TRACE|VERBOSE|LOG)\]?|\d{4}-\d{2}-\d{2}[T\s]\S+\s+\[?(?:INFO|DEBUG|NOTICE|TRACE|VERBOSE|LOG)\]?)\b",
78
+ re.IGNORECASE,
79
+ )
80
+
52
81
  # Explicit false-indicator filter (phrases like "without failure", "0 failures")
53
82
  PASSING_PHRASES = re.compile(
54
83
  r"\b(?:without|zero|0|no)\s+(?:obvious\s+)?(?:failures?|errors?|exceptions?)\b",
@@ -68,7 +97,7 @@ FAILURE_INDICATORS = [
68
97
  re.compile(r"FAIL\s+.*(?:\.spec|\.test)", re.IGNORECASE),
69
98
  re.compile(r"===+\s*FAILURES\s*===+", re.IGNORECASE),
70
99
  re.compile(r"E\s+assert\b", re.IGNORECASE),
71
- re.compile(r"assert\s+.*==\s*", re.IGNORECASE),
100
+ re.compile(r"(?:^|\s)(?:E\s+|>\s+|AssertionError:\s*)assert\s+.*==\s*", re.IGNORECASE),
72
101
  re.compile(r"expect\(.*\)\.", re.IGNORECASE),
73
102
  re.compile(r"Timeout \d+ms exceeded", re.IGNORECASE),
74
103
  re.compile(r"Traceback \(most recent call last\):", re.IGNORECASE),
@@ -97,7 +126,7 @@ def distill(
97
126
  ) -> str:
98
127
  """
99
128
  Distills raw execution logs down to high-signal failure blocks while guaranteeing
100
- zero false passes and preserving critical assertion diffs, cause chains, and locations.
129
+ zero false passes, zero false-positive assertions on info logs, and enforcing token budgets.
101
130
  """
102
131
  raw_bytes = len(log_text.encode("utf-8"))
103
132
  lines = log_text.splitlines()
@@ -121,11 +150,14 @@ def distill(
121
150
  if m_tc:
122
151
  last_seen_tc = m_tc.group(1)
123
152
 
124
- # Case-insensitive check
125
- is_fail_line = any(p.search(line) for p in FAILURE_INDICATORS)
153
+ # Informational log lines cannot initiate failure blocks
154
+ is_info = bool(INFO_LOG_LINE.search(line))
155
+
156
+ # Case-insensitive failure check
157
+ is_fail_line = (not is_info or in_failure_block) and any(p.search(line) for p in FAILURE_INDICATORS)
126
158
  is_noise = any(p.search(line) for p in NOISE_PATTERNS) and not is_fail_line
127
159
 
128
- if is_fail_line:
160
+ if is_fail_line and not is_info:
129
161
  if not in_failure_block:
130
162
  in_failure_block = True
131
163
  current_block = []
@@ -207,18 +239,24 @@ def distill(
207
239
  output.append(f"[RAW LOG ARTIFACT] file://{os.path.abspath(raw_log_path)}")
208
240
  return "\n".join(output)
209
241
 
210
- # Report failures
211
- if exit_code is not None:
242
+ # Invariant: Conflicting Signals Handling when exit_code == 0 but failure keywords present
243
+ if exit_code == 0:
244
+ output.append("⚠️ CONFLICTING_SIGNALS [Exit Code: 0]: Test runner exited with code 0, but failure indicators were detected in log.")
245
+ output.append(" (Check whether failures were swallowed by an outer test harness, or if informational text matched failure patterns).")
246
+ elif exit_code is not None:
212
247
  exit_badge = f" [Exit Code: {exit_code}]"
248
+ if failing_tcs:
249
+ output.append(f"❌ FAILURES DETECTED{exit_badge}: {len(failing_tcs)} Test Case(s) marked FAILED.")
250
+ else:
251
+ output.append(f"❌ FAILURES / ERRORS DETECTED{exit_badge}: {len(captured_failures)} failure block(s) isolated.")
213
252
  else:
214
- exit_badge = ""
253
+ if failing_tcs:
254
+ output.append(f"❌ FAILURES DETECTED: {len(failing_tcs)} Test Case(s) marked FAILED.")
255
+ else:
256
+ output.append(f"❌ FAILURES / ERRORS DETECTED: {len(captured_failures)} failure block(s) isolated.")
215
257
 
216
258
  if failing_tcs:
217
- output.append(f"❌ FAILURES DETECTED{exit_badge}: {len(failing_tcs)} Test Case(s) marked FAILED.")
218
259
  output.append(f" Targeted TCs: {', '.join(sorted(failing_tcs))}")
219
- else:
220
- output.append(f"❌ FAILURES / ERRORS DETECTED{exit_badge}: {len(captured_failures)} failure block(s) isolated.")
221
-
222
260
  if failing_locs:
223
261
  unique_locs = sorted(set(failing_locs))
224
262
  output.append(f" Failing Script Location(s): {', '.join(unique_locs[:5])}")
@@ -237,7 +275,6 @@ def distill(
237
275
  block_text = "\n".join(block)
238
276
  block_lines = len(block)
239
277
  if current_lines + block_lines > max_payload_lines:
240
- # Take what fits
241
278
  allowed = max_payload_lines - current_lines
242
279
  if allowed > 2:
243
280
  assembled_blocks.append("\n".join(block[:allowed]))
@@ -249,14 +286,26 @@ def distill(
249
286
 
250
287
  output.append("\n---\n".join(assembled_blocks))
251
288
 
252
- # Append provenance and compression telemetry
253
- distilled_text = "\n".join(output)
254
- distilled_bytes = len(distilled_text.encode("utf-8"))
255
- reduction_pct = round(((raw_bytes - distilled_bytes) / max(1, raw_bytes)) * 100, 1)
289
+ # Genuine Token Budget Constraint Enforcement
290
+ if token_budget > 0:
291
+ current_tokens = count_tokens("\n".join(output))
292
+ if current_tokens > token_budget:
293
+ truncated = True
294
+ # Pop lines from the end of the output body until within token budget
295
+ while len(output) > 4 and count_tokens("\n".join(output)) > max(20, token_budget - 25):
296
+ output.pop()
297
+ output.append(f"... [truncated: constrained by token_budget={token_budget} tokens] ...")
298
+
299
+ # Measure distilled body before appending metadata footer
300
+ body_lines = len(output)
301
+ distilled_body_text = "\n".join(output)
302
+ distilled_body_bytes = len(distilled_body_text.encode("utf-8"))
303
+ distilled_tokens = count_tokens(distilled_body_text)
304
+ reduction_pct = round(((raw_bytes - distilled_body_bytes) / max(1, raw_bytes)) * 100, 1)
256
305
 
257
306
  output.append(
258
- f"\n[DISTILLER METRICS] Distilled: {len(output)} lines ({distilled_bytes:,} bytes) | "
259
- f"Reduction: {reduction_pct}% | Truncated: {truncated}"
307
+ f"\n[DISTILLER METRICS] Distilled Body: {body_lines} lines ({distilled_body_bytes:,} bytes, ~{distilled_tokens} tokens) | "
308
+ f"Reduction: {reduction_pct}% | Truncated: {truncated} | Token Budget: {token_budget}"
260
309
  )
261
310
 
262
311
  if raw_log_path:
@@ -324,6 +373,7 @@ def main():
324
373
  parser.add_argument("--exit-code", "-e", type=int, default=None, help="Process exit code from test runner.")
325
374
  parser.add_argument("--save-raw", "-s", default=None, help="Path to preserve raw log.")
326
375
  parser.add_argument("--max-lines", "-m", type=int, default=40, help="Maximum number of output lines.")
376
+ parser.add_argument("--token-budget", "-b", type=int, default=800, help="Maximum token budget for distilled output.")
327
377
  parser.add_argument("--shrink", action="store_true", help="Apply caveman/shrink token compression.")
328
378
  args = parser.parse_args()
329
379
 
@@ -353,6 +403,7 @@ def main():
353
403
  max_lines=args.max_lines,
354
404
  exit_code=args.exit_code,
355
405
  raw_log_path=args.save_raw,
406
+ token_budget=args.token_budget,
356
407
  )
357
408
  if args.shrink:
358
409
  summary = shrink_tokens(summary)
@@ -86,11 +86,12 @@ ASSERTION_PATTERN = re.compile(
86
86
  )
87
87
 
88
88
  # Rule L1 & L5: Empty catch / swallowed exceptions across JS/TS/Groovy/Java and Python
89
- # Also catches try/catch that only console.log/logger.error or promise .catch(() => {})
89
+ # Also catches try/catch that only console.log/logger.error, promise .catch(() => {}),
90
+ # or dummy assignment bypasses like `_ = err`, `_ = e`, `_ = False`, `const _ = err;`
90
91
  EMPTY_CATCH_PATTERN = re.compile(
91
- r'(?:catch\s*(?:\([^\)]*\))?\s*\{\s*(?:(?:console|logger|log)\.(?:log|warn|error|info)\([^)]*\);?\s*)?\}'
92
- r'|\.catch\s*\(\s*(?:\([^)]*\)|[a-zA-Z0-9_]+)?\s*=>\s*\{\s*(?:(?:console|logger|log)\.(?:log|warn|error|info)\([^)]*\);?\s*)?\}\s*\)'
93
- r'|\bexcept(?:\s+[^:]*)?:\s*(?:pass|\.\.\.)(?:\s*$|\s*#))',
92
+ r'(?:catch\s*(?:\([^\)]*\))?\s*\{\s*(?:(?:console|logger|log)\.(?:log|warn|error|info)\([^)]*\);?\s*|(?:const|let|var|def)?\s*_\s*=\s*[^;]+;?\s*)?\}'
93
+ r'|\.catch\s*\(\s*(?:\([^)]*\)|[a-zA-Z0-9_]+)?\s*=>\s*\{\s*(?:(?:console|logger|log)\.(?:log|warn|error|info)\([^)]*\);?\s*|(?:const|let|var|def)?\s*_\s*=\s*[^;]+;?\s*)?\}\s*\)'
94
+ r'|\bexcept(?:\s+[^:]*)?:\s*(?:pass|\.\.\.|_\s*=\s*[^#\n;]+)(?:\s*$|\s*#))',
94
95
  re.MULTILINE
95
96
  )
96
97
 
@@ -426,7 +427,7 @@ def analyze_script(file_path, baseline_set=None, disabled_rules=None):
426
427
  "type": "SWALLOWED_EXCEPTION",
427
428
  "severity": "CRITICAL",
428
429
  "line": line_no,
429
- "message": "Empty catch block detected. Swallowed exceptions cause false-pass test runs."
430
+ "message": "Empty catch block or dummy suppression (_ = err) detected. Swallowed exceptions cause false-pass test runs."
430
431
  })
431
432
 
432
433
  # Rule 3: Flaky Static Delays (Playwright, Cypress, Pytest, Katalon, Java/Groovy)
@@ -60,7 +60,7 @@ if hasattr(sys.stdout, 'reconfigure'):
60
60
  except Exception:
61
61
  pass
62
62
 
63
- SERVER_VERSION = "4.1.1"
63
+ SERVER_VERSION = "4.1.2"
64
64
  MAX_DOCX_SIZE = 50 * 1024 * 1024 # 50 MB
65
65
  MAX_UNCOMPRESSED_SIZE = 200 * 1024 * 1024 # 200 MB
66
66
  MAX_RATIO = 100 # 100:1 compression ratio limit
@@ -52,7 +52,7 @@ if hasattr(sys.stdout, 'reconfigure'):
52
52
  except Exception:
53
53
  pass
54
54
 
55
- SERVER_VERSION = "4.1.1"
55
+ SERVER_VERSION = "4.1.2"
56
56
  MAX_XLSX_SIZE = 50 * 1024 * 1024 # 50 MB
57
57
  MAX_UNCOMPRESSED_SIZE = 200 * 1024 * 1024 # 200 MB
58
58
  MAX_RATIO = 100 # 100:1 compression ratio limit
@@ -46,7 +46,7 @@ import gherkin_suite
46
46
  import api_fuzzer
47
47
 
48
48
  SERVER_NAME = "enterprise-agent-qa"
49
- SERVER_VERSION = "4.1.1"
49
+ SERVER_VERSION = "4.1.2"
50
50
 
51
51
  MCP_TOOLS = [
52
52
  {