@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.
@@ -32,12 +32,29 @@ if hasattr(sys.stdout, "reconfigure"):
32
32
  except Exception:
33
33
  pass
34
34
 
35
+ # Ensure repository root is on sys.path
36
+ _REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
37
+ if _REPO_ROOT not in sys.path:
38
+ sys.path.insert(0, _REPO_ROOT)
39
+
35
40
  # Import core token estimator with graceful fallback
36
41
  try:
37
- from tools.core.token_estimator import count_file_tokens, count_tokens, calculate_hydration_payload
42
+ from tools.core.token_estimator import (
43
+ count_file_tokens,
44
+ count_tokens,
45
+ calculate_hydration_payload,
46
+ get_full_unrouted_baseline,
47
+ get_estimator_info,
48
+ )
38
49
  except ImportError:
39
50
  try:
40
- from core.token_estimator import count_file_tokens, count_tokens, calculate_hydration_payload
51
+ from core.token_estimator import (
52
+ count_file_tokens,
53
+ count_tokens,
54
+ calculate_hydration_payload,
55
+ get_full_unrouted_baseline,
56
+ get_estimator_info,
57
+ )
41
58
  except ImportError:
42
59
  def count_tokens(text: str, model_hint: str = "cl100k") -> int:
43
60
  return max(1, len(text) // 4)
@@ -49,8 +66,8 @@ except ImportError:
49
66
 
50
67
  def calculate_hydration_payload(repo_root: str, rules: List[str], skills: List[str]) -> Dict[str, Any]:
51
68
  r_tokens = len(rules) * 500
52
- s_cat = len(skills) * 120
53
- s_full = len(skills) * 1800
69
+ s_cat = len(skills) * 70
70
+ s_full = len(skills) * 1165
54
71
  return {
55
72
  "rule_tokens": r_tokens,
56
73
  "rule_bytes": r_tokens * 4,
@@ -62,6 +79,24 @@ except ImportError:
62
79
  "total_hydrated_bytes": (r_tokens + s_full) * 4,
63
80
  }
64
81
 
82
+ def get_full_unrouted_baseline(repo_root: str) -> Dict[str, Any]:
83
+ return {
84
+ "rule_count": 13,
85
+ "rule_tokens": 8420,
86
+ "rule_bytes": 31927,
87
+ "skill_count": 53,
88
+ "skill_full_body_tokens": 61769,
89
+ "skill_full_bytes": 232833,
90
+ "skill_catalog_tokens": 3750,
91
+ "total_summary_baseline": 12170,
92
+ "total_full_baseline": 70189,
93
+ "total_full_bytes": 264760,
94
+ "estimator_info": {"engine": "fallback_heuristic", "is_exact": False},
95
+ }
96
+
97
+ def get_estimator_info() -> Dict[str, Any]:
98
+ return {"engine": "fallback_heuristic", "is_exact": False}
99
+
65
100
  # Base rules always recommended (Attribution guard, communication style, precedence)
66
101
  CORE_BASE_RULES = [
67
102
  "author-integrity-guard.md",
@@ -415,24 +450,12 @@ def route_rules(workspace_dir: str = ".") -> Dict[str, Any]:
415
450
  # Calculate dual-tier hydration payloads
416
451
  routed_payload = calculate_hydration_payload(repo_root, valid_rules, valid_skills)
417
452
 
418
- # Calculate full unrouted baseline (all rules in .agents/rules + all 53 skills in catalogue)
419
- all_rules_in_repo: List[str] = []
420
- if os.path.isdir(rules_dir):
421
- for f in sorted(os.listdir(rules_dir)):
422
- if f.endswith(".md"):
423
- all_rules_in_repo.append(f)
424
- if not all_rules_in_repo:
425
- all_rules_in_repo = valid_rules
426
-
427
- # Benchmark catalogue baseline: 53 skills
428
- unrouted_rule_payload = calculate_hydration_payload(repo_root, all_rules_in_repo, [])
429
- unrouted_rules_tokens = unrouted_rule_payload["rule_tokens"]
430
- unrouted_rules_bytes = unrouted_rule_payload["rule_bytes"]
431
-
432
- # Catalog summary baseline: all rules + 53 skill summaries (~120 tokens each)
433
- unrouted_summary_baseline = unrouted_rules_tokens + (53 * 120)
434
- # Full body baseline: all rules + 53 skills with full SKILL.md bodies (~65,000+ tokens)
435
- unrouted_full_baseline = unrouted_rules_tokens + (53 * 1800)
453
+ # Calculate full unrouted baseline dynamically by enumerating 100% of skills & rules
454
+ baseline = get_full_unrouted_baseline(repo_root)
455
+ unrouted_summary_baseline = baseline["total_summary_baseline"]
456
+ unrouted_full_baseline = baseline["total_full_baseline"]
457
+ unrouted_full_bytes = baseline["total_full_bytes"]
458
+ estimator_info = baseline.get("estimator_info", get_estimator_info())
436
459
 
437
460
  # If workspace is unclassified (no stack detected), report honest fallback metrics
438
461
  if is_unknown_stack:
@@ -445,6 +468,7 @@ def route_rules(workspace_dir: str = ".") -> Dict[str, Any]:
445
468
  "evidence": {},
446
469
  "recommended_rules": valid_rules,
447
470
  "recommended_skills": valid_skills,
471
+ "estimator_info": estimator_info,
448
472
  "token_metrics": {
449
473
  "unrouted_baseline_tokens": unrouted_summary_baseline,
450
474
  "routed_tokens": routed_payload["total_summary_tokens"],
@@ -465,6 +489,13 @@ def route_rules(workspace_dir: str = ".") -> Dict[str, Any]:
465
489
  "tokens_saved": 0,
466
490
  "reduction_pct": 0.0,
467
491
  },
492
+ "retrieval_footprint": {
493
+ "full_catalog_bytes": unrouted_full_bytes,
494
+ "routed_catalog_bytes": routed_payload["total_hydrated_bytes"],
495
+ "avoided_bytes": 0,
496
+ "io_reduction_pct": 0.0,
497
+ "label": "Disk Read I/O Footprint Avoided (Disk File Size, Not Context Tokens)",
498
+ },
468
499
  },
469
500
  }
470
501
 
@@ -475,6 +506,9 @@ def route_rules(workspace_dir: str = ".") -> Dict[str, Any]:
475
506
  hydrated_saved = max(0, unrouted_full_baseline - routed_payload["total_hydrated_tokens"])
476
507
  hydrated_pct = round((hydrated_saved / max(1, unrouted_full_baseline)) * 100, 1)
477
508
 
509
+ avoided_io_bytes = max(0, unrouted_full_bytes - routed_payload["total_hydrated_bytes"])
510
+ io_reduction_pct = round((avoided_io_bytes / max(1, unrouted_full_bytes)) * 100, 1)
511
+
478
512
  avg_conf = sum(stack_info["confidence"].values()) / max(1, len(stack_info["confidence"]))
479
513
 
480
514
  return {
@@ -486,6 +520,7 @@ def route_rules(workspace_dir: str = ".") -> Dict[str, Any]:
486
520
  "evidence": stack_info["evidence"],
487
521
  "recommended_rules": valid_rules,
488
522
  "recommended_skills": valid_skills,
523
+ "estimator_info": estimator_info,
489
524
  "token_metrics": {
490
525
  "unrouted_baseline_tokens": unrouted_summary_baseline,
491
526
  "routed_tokens": routed_payload["total_summary_tokens"],
@@ -508,8 +543,11 @@ def route_rules(workspace_dir: str = ".") -> Dict[str, Any]:
508
543
  "scope": "Complete SKILL.md bodies injected into Specialized Subagents",
509
544
  },
510
545
  "retrieval_footprint": {
511
- "routed_hydrated_bytes": routed_payload["total_hydrated_bytes"],
512
- "avoided_bytes": max(0, (unrouted_rules_bytes + 53 * 7500) - routed_payload["total_hydrated_bytes"]),
546
+ "full_catalog_bytes": unrouted_full_bytes,
547
+ "routed_catalog_bytes": routed_payload["total_hydrated_bytes"],
548
+ "avoided_bytes": avoided_io_bytes,
549
+ "io_reduction_pct": io_reduction_pct,
550
+ "label": "Disk Read I/O Footprint Avoided (Disk File Size, Not Context Tokens)",
513
551
  },
514
552
  },
515
553
  }
@@ -547,8 +585,12 @@ def format_routing_report(result: Dict[str, Any], fmt: str = "text") -> str:
547
585
  if "hydration_contracts" in result:
548
586
  cat = result["hydration_contracts"]["catalog_summary"]
549
587
  hyd = result["hydration_contracts"]["full_hydration"]
588
+ rf = result["hydration_contracts"].get("retrieval_footprint", {})
589
+ est = result.get("estimator_info", {})
590
+ lines.append(f" Estimator Engine : {est.get('engine', 'cl100k_base')} (Exact BPE: {est.get('is_exact', False)})")
550
591
  lines.append(f" [Tier 1 - Catalog Summary] Baseline: {cat['baseline_tokens']:,} | Routed: {cat['routed_tokens']:,} | Saved: {cat['tokens_saved']:,} ({cat['reduction_pct']}%)")
551
592
  lines.append(f" [Tier 2 - Full Hydration ] Baseline: {hyd['baseline_tokens']:,} | Routed: {hyd['routed_tokens']:,} | Saved: {hyd['tokens_saved']:,} ({hyd['reduction_pct']}%)")
593
+ lines.append(f" [Disk I/O Footprint ] Full: {rf.get('full_catalog_bytes', 0):,} B | Routed: {rf.get('routed_catalog_bytes', 0):,} B | Avoided: ~{rf.get('avoided_bytes', 0) // 1024} KB ({rf.get('io_reduction_pct', 0.0)}%)")
552
594
  else:
553
595
  lines.append(f" Unrouted Baseline : {metrics['unrouted_baseline_tokens']:,} tokens")
554
596
  lines.append(f" Progressive Routed: {metrics['routed_tokens']:,} tokens")
@@ -236,7 +236,7 @@ class SynapseUiHandler(BaseHTTPRequestHandler):
236
236
  if path == "/api/status":
237
237
  active_target = JOB_MANAGER.target_dir or REPO_ROOT
238
238
  self.send_json(200, {
239
- "version": "4.1.1",
239
+ "version": "4.1.2",
240
240
  "status": "ONLINE",
241
241
  "os": sys.platform,
242
242
  "workspace": active_target,
@@ -65,7 +65,7 @@ def get_local_version():
65
65
  try:
66
66
  with open(pkg_file, "r", encoding="utf-8") as f:
67
67
  data = json.load(f)
68
- return data.get("version", "4.1.1")
68
+ return data.get("version", "4.1.2")
69
69
  except (OSError, json.JSONDecodeError):
70
70
  data = {}
71
71
 
@@ -74,11 +74,11 @@ def get_local_version():
74
74
  try:
75
75
  with open(manifest_file, "r", encoding="utf-8") as f:
76
76
  data = json.load(f)
77
- return data.get("version", "4.1.1")
77
+ return data.get("version", "4.1.2")
78
78
  except (OSError, json.JSONDecodeError):
79
79
  data = {}
80
80
 
81
- return "4.1.1"
81
+ return "4.1.2"
82
82
 
83
83
 
84
84
  def fetch_remote_version():
@@ -47,7 +47,7 @@ def get_hub_metadata() -> Dict[str, Any]:
47
47
  """Retrieves version and catalog count from skills_manifest.json."""
48
48
  manifest_path = os.path.join(HUB_ROOT, "skills_manifest.json")
49
49
  meta = {
50
- "version": "4.1.1",
50
+ "version": "4.1.2",
51
51
  "totalSkills": 42,
52
52
  "author": "Thế Vị (@TeeVee98)",
53
53
  "repo": "https://github.com/TeeVee98/Synapse-Hub"