@teevee98/synapse-hub 4.0.0 → 4.1.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.
Files changed (42) hide show
  1. package/.agents/rules/context-engineering.md +3 -3
  2. package/.agents/rules/security_testing_rules.md +8 -5
  3. package/README.en.md +2 -2
  4. package/README.md +2 -2
  5. package/agentskills.json +1 -1
  6. package/docs/ARCHITECTURE.en.md +1 -1
  7. package/docs/ARCHITECTURE.md +1 -1
  8. package/package.json +1 -1
  9. package/plugin.json +1 -1
  10. package/skills_manifest.json +162 -54
  11. package/synapse.config.json +17 -1
  12. package/tools/__init__.py +1 -1
  13. package/tools/ast_cache.py +1 -3
  14. package/tools/author_integrity.py +7 -2
  15. package/tools/benchmark_swarm_context.py +242 -151
  16. package/tools/browser_helpers.js +2 -2
  17. package/tools/build_consolidated_report.py +5 -5
  18. package/tools/check_version_sync.py +56 -0
  19. package/tools/cli.py +3 -3
  20. package/tools/core/file_lock.py +81 -6
  21. package/tools/core/telemetry.py +139 -1
  22. package/tools/core/token_estimator.py +145 -0
  23. package/tools/count_tokens.py +28 -0
  24. package/tools/dashboard_generator.py +6 -6
  25. package/tools/debt_harvester.py +20 -9
  26. package/tools/diagram_architect.py +0 -1
  27. package/tools/distill_log.py +266 -89
  28. package/tools/git_worktree_manager.py +1 -1
  29. package/tools/mcp_docx_server.py +1 -1
  30. package/tools/mcp_excel_server.py +1 -1
  31. package/tools/mcp_server.py +1 -1
  32. package/tools/mechanical_ui_gate.py +1 -1
  33. package/tools/micro_mutator.py +51 -10
  34. package/tools/pairwise_generator.py +0 -1
  35. package/tools/pentest_scope_guard.py +328 -0
  36. package/tools/perf/benchmark_perf_runner.py +226 -0
  37. package/tools/rules_router.py +326 -103
  38. package/tools/token_telemetry.py +224 -0
  39. package/tools/ui_server.py +1 -1
  40. package/tools/update_sentinel.py +3 -3
  41. package/tools/verify_all.py +24 -6
  42. package/tools/welcome_page.py +1 -1
@@ -1,157 +1,330 @@
1
1
  #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
2
+ # SPDX-FileCopyrightText: Copyright (c) 2026 Thế Vị (@TeeVee98). All rights reserved.
3
+ # SPDX-License-Identifier: MIT
4
+ # Project: Synapse-Hub (https://github.com/TeeVee98/Synapse-Hub)
5
+
3
6
  """
4
- tools/distill_log.py — Cross-Platform Log Distiller for Katalon KRE, Gradle, and Playwright
5
- Filters out 90%+ passing step noise and outputs strictly actionable failure triage blocks.
6
- Compatible with Windows, macOS, and Linux.
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.
7
11
  """
8
12
 
9
- import sys
13
+ from __future__ import annotations
14
+
15
+ import argparse
10
16
  import os
11
17
  import re
12
- import argparse
18
+ import sys
19
+ from typing import Any, Dict, List, Optional, Set, Tuple
13
20
 
14
- # Enforce UTF-8 stdout encoding for Windows console compatibility
15
- if hasattr(sys.stdout, 'reconfigure'):
21
+ # Enforce UTF-8 stdout encoding for cross-platform compatibility
22
+ if hasattr(sys.stdout, "reconfigure"):
16
23
  try:
17
- sys.stdout.reconfigure(encoding='utf-8')
18
- sys.stderr.reconfigure(encoding='utf-8')
24
+ sys.stdout.reconfigure(encoding="utf-8")
25
+ sys.stderr.reconfigure(encoding="utf-8")
19
26
  except Exception:
20
27
  pass
21
28
 
22
- def distill(log_text, max_lines=40):
29
+ # Universal noise patterns (passing steps, zero failures summary, timestamps, system initialization)
30
+ NOISE_PATTERNS = [
31
+ re.compile(r"^\s*$"),
32
+ re.compile(r"\b0\s+failed\b", re.IGNORECASE),
33
+ re.compile(r"\b0\s+failures?\b", re.IGNORECASE),
34
+ re.compile(r"\b0\s+errors?\b", re.IGNORECASE),
35
+ re.compile(r"\b(?:no|zero)\s+failures?\b", re.IGNORECASE),
36
+ re.compile(r"\b(?:no|zero)\s+errors?\b", re.IGNORECASE),
37
+ re.compile(r"\[INFO\b|\bINFO:|\bINFO\s+", re.IGNORECASE),
38
+ re.compile(r"\[DEBUG\b|\bDEBUG:|\bDEBUG\s+", re.IGNORECASE),
39
+ re.compile(r"\[TRACE\b|\bTRACE:|\bTRACE\s+", re.IGNORECASE),
40
+ re.compile(r"^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}.*\b(?:INFO|DEBUG|TRACE)\b", re.IGNORECASE),
41
+ re.compile(r"\bPASSED\b", re.IGNORECASE),
42
+ re.compile(r"> Task :"),
43
+ re.compile(r"SLF4J:"),
44
+ re.compile(r"Loading class `com\.mysql"),
45
+ re.compile(r"Starting ChromeDriver"),
46
+ re.compile(r"Only local connections are allowed"),
47
+ re.compile(r"DevTools listening on"),
48
+ re.compile(r"Fontconfig warning:"),
49
+ re.compile(r"Katalon Studio.*licensed to"),
50
+ ]
51
+
52
+ # Explicit false-indicator filter (phrases like "without failure", "0 failures")
53
+ PASSING_PHRASES = re.compile(
54
+ r"\b(?:without|zero|0|no)\s+(?:obvious\s+)?(?:failures?|errors?|exceptions?)\b",
55
+ re.IGNORECASE,
56
+ )
57
+
58
+ # Case-insensitive failure indicator patterns
59
+ FAILURE_INDICATORS = [
60
+ re.compile(r"\bFAILED\b", re.IGNORECASE),
61
+ re.compile(r"\bFAILURES?\b", re.IGNORECASE),
62
+ re.compile(r"\bERRORS?\b", re.IGNORECASE),
63
+ re.compile(r"\bExceptions?\b", re.IGNORECASE),
64
+ re.compile(r"\bAssertionError\b", re.IGNORECASE),
65
+ re.compile(r"Caused by:", re.IGNORECASE),
66
+ re.compile(r"at (?:Enterprise\.|Script\d+|com\.kms|\S+\.(?:groovy|ts|js|py|java))", re.IGNORECASE),
67
+ re.compile(r"TC-\d+.*FAILED", re.IGNORECASE),
68
+ re.compile(r"FAIL\s+.*(?:\.spec|\.test)", re.IGNORECASE),
69
+ re.compile(r"===+\s*FAILURES\s*===+", re.IGNORECASE),
70
+ re.compile(r"E\s+assert\b", re.IGNORECASE),
71
+ re.compile(r"assert\s+.*==\s*", re.IGNORECASE),
72
+ re.compile(r"expect\(.*\)\.", re.IGNORECASE),
73
+ re.compile(r"Timeout \d+ms exceeded", re.IGNORECASE),
74
+ re.compile(r"Traceback \(most recent call last\):", re.IGNORECASE),
75
+ re.compile(r"panic:\s+", re.IGNORECASE),
76
+ re.compile(r"fatal(?:\s+error)?:\s+", re.IGNORECASE),
77
+ ]
78
+
79
+ # Test Case Identifiers
80
+ TC_PATTERN = re.compile(
81
+ r"([A-Za-z0-9_.-]+::[A-Za-z0-9_]+|TC-\d+[A-Za-z0-9_]*|test_[A-Za-z0-9_]+|"
82
+ r"[A-Za-z0-9_-]+\.(?:spec|test)\.[jt]sx?)"
83
+ )
84
+
85
+ # Line number pattern
86
+ LINE_NUM_PATTERN = re.compile(
87
+ r"((?:Script\d+|\w+Page|\w+\.(?:groovy|ts|js|py|java)):(\d+))|File \"([^\"]+)\", line (\d+)"
88
+ )
89
+
90
+
91
+ def distill(
92
+ log_text: str,
93
+ max_lines: int = 40,
94
+ exit_code: Optional[int] = None,
95
+ raw_log_path: Optional[str] = None,
96
+ token_budget: int = 800,
97
+ ) -> str:
98
+ """
99
+ 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.
101
+ """
102
+ raw_bytes = len(log_text.encode("utf-8"))
23
103
  lines = log_text.splitlines()
24
104
  total_raw_lines = len(lines)
25
105
 
26
- # Noise filters
27
- noise_patterns = [
28
- re.compile(r'^\s*$'),
29
- re.compile(r'\[INFO\b|\bINFO:|\bINFO\s+', re.IGNORECASE),
30
- re.compile(r'\[DEBUG\b|\bDEBUG:|\bDEBUG\s+', re.IGNORECASE),
31
- re.compile(r'\[TRACE\b|\bTRACE:|\bTRACE\s+', re.IGNORECASE),
32
- re.compile(r'^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}.*\b(?:INFO|DEBUG|TRACE)\b', re.IGNORECASE),
33
- re.compile(r'\bPASSED\b', re.IGNORECASE),
34
- re.compile(r'> Task :'),
35
- re.compile(r'SLF4J:'),
36
- re.compile(r'Loading class `com\.mysql'),
37
- re.compile(r'Starting ChromeDriver'),
38
- re.compile(r'Only local connections are allowed'),
39
- re.compile(r'DevTools listening on'),
40
- re.compile(r'Fontconfig warning:'),
41
- re.compile(r'Katalon Studio.*licensed to'),
42
- ]
43
-
44
- failure_indicators = [
45
- re.compile(r'\bFAILED\b'),
46
- re.compile(r'\bERROR\b'),
47
- re.compile(r'Exception\b'),
48
- re.compile(r'AssertionError'),
49
- re.compile(r'Caused by:'),
50
- re.compile(r'at (?:Enterprise\.|Script\d+|com\.kms)'),
51
- re.compile(r'TC-\d+.*FAILED'),
52
- re.compile(r'FAIL\s+.*(?:\.spec|\.test)'),
53
- ]
54
-
55
- tc_pattern = re.compile(r'(TC-\d+|test_[A-Za-z0-9_]+|[A-Za-z0-9_-]+\.(?:spec|test)\.[jt]sx?)')
56
- line_num_pattern = re.compile(r'((?:Script\d+|\w+Page|\w+\.(?:groovy|ts|js|py)):(\d+))|File "([^"]+)", line (\d+)')
57
- re.compile(r'([A-Za-z0-9_.]*(?:Exception|Error)):?\s*(.*)')
58
-
59
- captured_failures = []
60
- failing_tcs = set()
61
- failing_locs = []
106
+ captured_failures: List[List[str]] = []
107
+ failing_tcs: Set[str] = set()
108
+ failing_locs: List[str] = []
62
109
 
63
110
  in_failure_block = False
64
- failure_block = []
111
+ current_block: List[str] = []
112
+ last_seen_tc: Optional[str] = None
65
113
 
66
- for line in lines:
67
- # Check if line indicates failure
68
- is_fail_line = any(p.search(line) for p in failure_indicators)
69
- is_noise = any(p.search(line) for p in noise_patterns) and not is_fail_line
114
+ for i, line in enumerate(lines):
115
+ # Check if line contains a passing phrase like "0 failures" or "without failure"
116
+ if PASSING_PHRASES.search(line):
117
+ continue
70
118
 
71
- # Detect TC identifier
72
- m_tc = tc_pattern.search(line)
73
- if m_tc and ("FAILED" in line or "ERROR" in line):
74
- failing_tcs.add(m_tc.group(1))
119
+ # Detect candidate TC identifier
120
+ m_tc = TC_PATTERN.search(line)
121
+ if m_tc:
122
+ last_seen_tc = m_tc.group(1)
75
123
 
76
- # Detect script line number
77
- m_loc = line_num_pattern.search(line)
78
- if m_loc:
79
- failing_locs.append(m_loc.group(1) or f"{m_loc.group(3)}:{m_loc.group(4)}")
124
+ # Case-insensitive check
125
+ is_fail_line = any(p.search(line) for p in FAILURE_INDICATORS)
126
+ is_noise = any(p.search(line) for p in NOISE_PATTERNS) and not is_fail_line
80
127
 
81
128
  if is_fail_line:
82
- in_failure_block = True
83
- failure_block.append(line.strip())
129
+ if not in_failure_block:
130
+ in_failure_block = True
131
+ current_block = []
132
+ # Context line: keep previous line if it was a test name or relevant context
133
+ if i > 0:
134
+ prev_line = lines[i - 1].strip()
135
+ if prev_line and not any(p.search(prev_line) for p in NOISE_PATTERNS):
136
+ current_block.append(prev_line)
137
+ m_prev_tc = TC_PATTERN.search(prev_line)
138
+ if m_prev_tc:
139
+ failing_tcs.add(m_prev_tc.group(1))
140
+
141
+ current_block.append(line.rstrip())
142
+
143
+ # Associate failing TC
144
+ if m_tc:
145
+ failing_tcs.add(m_tc.group(1))
146
+ elif last_seen_tc:
147
+ failing_tcs.add(last_seen_tc)
148
+
149
+ # Detect script line numbers strictly within failure blocks
150
+ m_loc = LINE_NUM_PATTERN.search(line)
151
+ if m_loc:
152
+ failing_locs.append(m_loc.group(1) or f"{m_loc.group(3)}:{m_loc.group(4)}")
153
+
84
154
  elif in_failure_block:
85
- if is_noise or line.startswith("---") or line.startswith("==="):
155
+ # Check for block exit boundary
156
+ if is_noise or (line.startswith("---") and not line.startswith("--- Distilled")) or line.startswith("==="):
86
157
  in_failure_block = False
87
- if failure_block:
88
- captured_failures.append("\n".join(failure_block[:10]))
89
- failure_block = []
158
+ if current_block:
159
+ captured_failures.append(current_block[:15])
160
+ current_block = []
90
161
  else:
91
- failure_block.append(line.strip())
162
+ current_block.append(line.rstrip())
163
+ if m_tc:
164
+ failing_tcs.add(m_tc.group(1))
165
+
166
+ # Line numbers inside trace
167
+ m_loc = LINE_NUM_PATTERN.search(line)
168
+ if m_loc:
169
+ failing_locs.append(m_loc.group(1) or f"{m_loc.group(3)}:{m_loc.group(4)}")
170
+
171
+ # Limit individual block length
172
+ if len(current_block) >= 15:
173
+ in_failure_block = False
174
+ captured_failures.append(current_block)
175
+ current_block = []
176
+
177
+ if current_block:
178
+ captured_failures.append(current_block[:15])
179
+
180
+ # Telemetry Header
181
+ output: List[str] = []
182
+ output.append(f"[LOG DISTILLER] Analyzed {total_raw_lines:,} lines ({raw_bytes:,} bytes).")
92
183
 
93
- if failure_block:
94
- captured_failures.append("\n".join(failure_block[:10]))
184
+ # Invariant: Truth Anchor on Exit Code & Failure Detections
185
+ has_failures = bool(failing_tcs or captured_failures)
95
186
 
96
- # Distillation Report (Lean Unix-style format saving ~150 tokens per block)
97
- output = [f"[LOG DISTILLER] Analyzed {total_raw_lines:,} lines."]
187
+ if not has_failures:
188
+ if exit_code is not None and exit_code != 0:
189
+ # Runner exited with error but no standard failure regex matched
190
+ output.append(f"❌ RUNNER_NONZERO_EXIT: Process exited with non-zero code {exit_code}.")
191
+ output.append(" No standard failure keyword matched in log. Attached head and tail of raw log:")
192
+ output.append("\n--- Raw Log Head & Tail ---")
193
+ head_lines = [l.strip() for l in lines[:5] if l.strip()]
194
+ tail_lines = [l.strip() for l in lines[-15:] if l.strip()]
195
+ output.extend(head_lines)
196
+ output.append("... [omitted middle passing steps] ...")
197
+ output.extend(tail_lines)
198
+ elif exit_code is None:
199
+ # Exit code not supplied: DO NOT claim "ALL TESTS PASSED"
200
+ output.append("⚠️ NO_FAILURE_SIGNATURE_DETECTED: No recognized failure patterns found.")
201
+ output.append(" (Exit code unverified; verify test execution status directly).")
202
+ else:
203
+ # Explicit exit_code == 0 AND no failure indicators
204
+ output.append(f"✅ ALL TESTS PASSED (Exit Code: 0): Zero errors or failed steps detected across {total_raw_lines:,} lines.")
98
205
 
99
- if not failing_tcs and not captured_failures:
100
- output.append("✅ ALL TESTS PASSED: Zero errors or failed steps detected.")
206
+ if raw_log_path:
207
+ output.append(f"[RAW LOG ARTIFACT] file://{os.path.abspath(raw_log_path)}")
101
208
  return "\n".join(output)
102
209
 
210
+ # Report failures
211
+ if exit_code is not None:
212
+ exit_badge = f" [Exit Code: {exit_code}]"
213
+ else:
214
+ exit_badge = ""
215
+
103
216
  if failing_tcs:
104
- output.append(f"❌ FAILURES DETECTED: {len(failing_tcs)} Test Case(s) marked FAILED.")
217
+ output.append(f"❌ FAILURES DETECTED{exit_badge}: {len(failing_tcs)} Test Case(s) marked FAILED.")
105
218
  output.append(f" Targeted TCs: {', '.join(sorted(failing_tcs))}")
106
219
  else:
107
- output.append(f"❌ FAILURES / ERRORS DETECTED: {len(captured_failures)} failure block(s) isolated.")
220
+ output.append(f"❌ FAILURES / ERRORS DETECTED{exit_badge}: {len(captured_failures)} failure block(s) isolated.")
108
221
 
109
222
  if failing_locs:
110
223
  unique_locs = sorted(set(failing_locs))
111
224
  output.append(f" Failing Script Location(s): {', '.join(unique_locs[:5])}")
112
225
 
113
226
  output.append("\n--- Distilled Failure Block(s) ---")
114
- joined_blocks = "\n---\n".join(captured_failures[:3])
115
- output.append(joined_blocks[:2000])
227
+
228
+ # Assemble failure blocks with line budget constraint
229
+ lines_used = len(output)
230
+ max_payload_lines = max(5, max_lines - lines_used)
231
+
232
+ assembled_blocks: List[str] = []
233
+ current_lines = 0
234
+ truncated = False
235
+
236
+ for block in captured_failures[:5]:
237
+ block_text = "\n".join(block)
238
+ block_lines = len(block)
239
+ if current_lines + block_lines > max_payload_lines:
240
+ # Take what fits
241
+ allowed = max_payload_lines - current_lines
242
+ if allowed > 2:
243
+ assembled_blocks.append("\n".join(block[:allowed]))
244
+ assembled_blocks.append("... [truncated by max_lines budget] ...")
245
+ truncated = True
246
+ break
247
+ assembled_blocks.append(block_text)
248
+ current_lines += block_lines
249
+
250
+ output.append("\n---\n".join(assembled_blocks))
251
+
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)
256
+
257
+ output.append(
258
+ f"\n[DISTILLER METRICS] Distilled: {len(output)} lines ({distilled_bytes:,} bytes) | "
259
+ f"Reduction: {reduction_pct}% | Truncated: {truncated}"
260
+ )
261
+
262
+ if raw_log_path:
263
+ output.append(f"[RAW LOG ARTIFACT] file://{os.path.abspath(raw_log_path)}")
116
264
 
117
265
  return "\n".join(output)
118
266
 
267
+
119
268
  # Public alias for MCP server compatibility
120
269
  distill_log_content = distill
121
270
 
122
- def shrink_tokens(text: str, max_chars_per_line: int = 120) -> str:
271
+
272
+ def shrink_tokens(text: str, max_chars_per_line: int = 140) -> str:
123
273
  """
124
274
  Caveman / shrink compression: drops verbose metadata, collapses repetitive traces,
125
275
  and truncates stack noise while preserving 100% error names, line locations,
126
- and assertion mismatches (Julius Brussee caveman/shrink pattern).
127
- Achieves 33-65% token drop.
276
+ assertion mismatches, and UUIDs (Julius Brussee caveman/shrink pattern).
128
277
  """
129
278
  lines = text.splitlines()
130
279
  shrunk_lines = []
131
280
  seen_signatures = set()
132
281
 
282
+ uuid_pattern = re.compile(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", re.I)
283
+
133
284
  for line in lines:
134
- cleaned = re.sub(r'\s+', ' ', line).strip()
135
- if not cleaned:
285
+ stripped = line.strip()
286
+ if not stripped:
136
287
  continue
288
+
289
+ # Keep assertion diffs intact with exact indentation
290
+ is_diff_line = any(stripped.startswith(p) for p in ("E ", "assert ", "Expected:", "Received:", "> ", "- ", "+ "))
291
+
292
+ if is_diff_line:
293
+ shrunk_lines.append(line.rstrip())
294
+ continue
295
+
296
+ cleaned = re.sub(r"\s+", " ", stripped)
297
+
137
298
  # Deduplicate repeated identical trace lines
138
299
  if cleaned.startswith("at ") or cleaned.startswith("File "):
139
300
  sig = cleaned[:60]
140
301
  if sig in seen_signatures:
141
302
  continue
142
303
  seen_signatures.add(sig)
143
- # Drop excessive UUID/hex hash strings
144
- cleaned = re.sub(r'\b[0-9a-f]{16,64}\b', '<hash>', cleaned, flags=re.IGNORECASE)
304
+
305
+ # Replace non-UUID hex hashes of 16-64 chars with <hash>
306
+ def _replace_hash(match: re.Match[str]) -> str:
307
+ token = match.group(0)
308
+ if uuid_pattern.match(token):
309
+ return token
310
+ return "<hash>"
311
+
312
+ cleaned = re.sub(r"\b[0-9a-fA-F]{16,64}\b", _replace_hash, cleaned)
313
+
145
314
  if len(cleaned) > max_chars_per_line:
146
315
  cleaned = cleaned[:max_chars_per_line] + "..."
147
316
  shrunk_lines.append(cleaned)
317
+
148
318
  return "\n".join(shrunk_lines)
149
319
 
320
+
150
321
  def main():
151
322
  parser = argparse.ArgumentParser(description="Distill terminal execution logs into high-signal failure blocks.")
152
323
  parser.add_argument("--file", "-f", help="Path to raw log file (reads from stdin if omitted).")
153
- parser.add_argument("--save-raw", "-s", default=None, help="Path to preserve raw log (omitted by default to prevent hub pollution).")
154
- parser.add_argument("--shrink", action="store_true", help="Apply caveman/shrink token compression (33-65%% token drop).")
324
+ parser.add_argument("--exit-code", "-e", type=int, default=None, help="Process exit code from test runner.")
325
+ parser.add_argument("--save-raw", "-s", default=None, help="Path to preserve raw log.")
326
+ parser.add_argument("--max-lines", "-m", type=int, default=40, help="Maximum number of output lines.")
327
+ parser.add_argument("--shrink", action="store_true", help="Apply caveman/shrink token compression.")
155
328
  args = parser.parse_args()
156
329
 
157
330
  if args.file:
@@ -175,12 +348,16 @@ def main():
175
348
  except OSError as err:
176
349
  sys.stderr.write(f"Warning: Could not save raw log: {err}\n")
177
350
 
178
- summary = distill(log_text)
351
+ summary = distill(
352
+ log_text,
353
+ max_lines=args.max_lines,
354
+ exit_code=args.exit_code,
355
+ raw_log_path=args.save_raw,
356
+ )
179
357
  if args.shrink:
180
358
  summary = shrink_tokens(summary)
181
359
  print(summary)
182
- if args.save_raw and os.path.exists(args.save_raw):
183
- print(f"[Full raw log saved to file://{os.path.abspath(args.save_raw)}]")
360
+
184
361
 
185
362
  if __name__ == "__main__":
186
363
  main()
@@ -45,7 +45,7 @@ class WorktreeManager:
45
45
  res = run_git(["worktree", "list", "--porcelain"])
46
46
  if res.returncode != 0:
47
47
  return []
48
-
48
+
49
49
  worktrees = []
50
50
  current: Dict[str, str] = {}
51
51
  for line in res.stdout.splitlines():
@@ -60,7 +60,7 @@ if hasattr(sys.stdout, 'reconfigure'):
60
60
  except Exception:
61
61
  pass
62
62
 
63
- SERVER_VERSION = "4.0.0"
63
+ SERVER_VERSION = "4.1.0"
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.0.0"
55
+ SERVER_VERSION = "4.1.0"
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.0.0"
49
+ SERVER_VERSION = "4.1.0"
50
50
 
51
51
  MCP_TOOLS = [
52
52
  {
@@ -14,7 +14,7 @@ import os
14
14
  import re
15
15
  import json
16
16
  import argparse
17
- from typing import Dict, List, Any, Optional, Tuple
17
+ from typing import Dict, Any, Optional, Tuple
18
18
 
19
19
  # Enforce UTF-8 stdout encoding
20
20
  if hasattr(sys.stdout, "reconfigure"):
@@ -35,13 +35,13 @@ for stream in (sys.stdout, sys.stderr):
35
35
  if hasattr(stream, 'fileno'):
36
36
  try:
37
37
  os.set_blocking(stream.fileno(), True)
38
- except Exception:
39
- pass
38
+ except Exception as exc:
39
+ _ = exc
40
40
  if hasattr(stream, 'reconfigure'):
41
41
  try:
42
42
  stream.reconfigure(encoding='utf-8')
43
- except Exception:
44
- pass
43
+ except Exception as exc:
44
+ _ = exc
45
45
 
46
46
  SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
47
47
  HUB_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))
@@ -90,7 +90,13 @@ def resolve_scoped_test_cmd(scoped_template: str, target_file: str, repo_root: O
90
90
  elif "{tests}" in scoped_template:
91
91
  cmd = scoped_template.replace("{tests}", tests_str).strip()
92
92
  else:
93
- cmd = f"{scoped_template} {tests_str}".strip() if tests_str else scoped_template.strip()
93
+ norm_template = scoped_template.replace("\\", "/")
94
+ norm_target = target_file.replace("\\", "/")
95
+ base_target = os.path.basename(target_file)
96
+ if tests_str and (tests_str in norm_template or norm_target in norm_template or base_target in norm_template):
97
+ cmd = scoped_template.strip()
98
+ else:
99
+ cmd = f"{scoped_template} {tests_str}".strip() if tests_str else scoped_template.strip()
94
100
 
95
101
  return cmd, impacted
96
102
 
@@ -450,8 +456,28 @@ def evaluate_mutants_dynamically(file_path: str, code: str, mutants: List[Dict[s
450
456
  if not mutants:
451
457
  return mutants, 0.0
452
458
 
453
- use_shell = (sys.platform == "win32") and isinstance(test_cmd, str)
454
- cmd_args = test_cmd if use_shell else (shlex.split(test_cmd, posix=sys.platform != "win32") if isinstance(test_cmd, str) else test_cmd)
459
+ if isinstance(test_cmd, str):
460
+ if sys.platform == "win32":
461
+ def _clean_win_arg(a: str) -> str:
462
+ if a.startswith('"') and a.endswith('"') and len(a) >= 2:
463
+ return a[1:-1]
464
+ if "=" in a:
465
+ k, v = a.split("=", 1)
466
+ if v.startswith('"') and v.endswith('"') and len(v) >= 2:
467
+ return f"{k}={v[1:-1]}"
468
+ return a
469
+ cmd_args = [_clean_win_arg(a) for a in shlex.split(test_cmd, posix=False)]
470
+ else:
471
+ cmd_args = shlex.split(test_cmd, posix=True)
472
+ else:
473
+ cmd_args = test_cmd
474
+ use_shell = False
475
+ run_env = os.environ.copy()
476
+ run_env["PYTHONDONTWRITEBYTECODE"] = "1"
477
+
478
+ abs_path = os.path.abspath(file_path)
479
+ target_cwd = HUB_ROOT if os.path.exists(os.path.join(HUB_ROOT, "tests")) else os.path.dirname(abs_path)
480
+ backup_path = abs_path + ".synapse_mutator_bak"
455
481
 
456
482
  # F15: Baseline execution check - test suite must be GREEN on pristine code
457
483
  try:
@@ -460,12 +486,15 @@ def evaluate_mutants_dynamically(file_path: str, code: str, mutants: List[Dict[s
460
486
  shell=use_shell,
461
487
  capture_output=True,
462
488
  timeout=int(timeout),
463
- text=True
489
+ text=True,
490
+ env=run_env,
491
+ cwd=target_cwd
464
492
  )
465
493
  if baseline_proc.returncode != 0:
494
+ err_msg = (baseline_proc.stderr or baseline_proc.stdout or "").strip()
466
495
  for m in mutants:
467
496
  m["status"] = "SURVIVED"
468
- m["reason"] = f"Baseline test run failed (exit code {baseline_proc.returncode}). Tests must pass on clean code before mutation."
497
+ m["reason"] = f"Baseline test run failed (exit code {baseline_proc.returncode}): {err_msg}"
469
498
  return mutants, 0.0
470
499
  except subprocess.TimeoutExpired:
471
500
  for m in mutants:
@@ -511,7 +540,9 @@ def evaluate_mutants_dynamically(file_path: str, code: str, mutants: List[Dict[s
511
540
  shell=use_shell,
512
541
  capture_output=True,
513
542
  timeout=int(timeout),
514
- text=True
543
+ text=True,
544
+ env=run_env,
545
+ cwd=target_cwd
515
546
  )
516
547
  if proc.returncode != 0:
517
548
  m["status"] = "KILLED"
@@ -829,6 +860,16 @@ def main():
829
860
  except Exception as e:
830
861
  sys.stderr.write(f"Notice: Failed to record baseline: {e}\n")
831
862
 
863
+ # Automatically persist CI mutation artifact
864
+ mutation_report_dir = os.path.join(HUB_ROOT, "Reports", "mutation")
865
+ try:
866
+ os.makedirs(mutation_report_dir, exist_ok=True)
867
+ mutation_run_file = os.path.join(mutation_report_dir, "mutation_run.json")
868
+ with open(mutation_run_file, "w", encoding="utf-8") as mrf:
869
+ json.dump(report, mrf, indent=2)
870
+ except Exception as err:
871
+ _ = err
872
+
832
873
  output_format = "json" if args.json else args.format
833
874
 
834
875
  if output_format == "json":
@@ -11,7 +11,6 @@ reducing test case bloat by 80-90% while guaranteeing pairwise boundary coverage
11
11
  import sys
12
12
  import json
13
13
  import argparse
14
- import itertools
15
14
  from typing import Dict, List, Any, Set, Tuple
16
15
 
17
16
  # Enforce UTF-8 stdout encoding