@teevee98/synapse-hub 3.10.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 (199) hide show
  1. package/.agents/rules/context-engineering.md +3 -3
  2. package/.agents/rules/mandatory-playwright-live.md +18 -4
  3. package/.agents/rules/security_testing_rules.md +8 -5
  4. package/.agents/rules/stack-auto-router.md +11 -4
  5. package/.agents/skills/{playwright-webapp-testing → 01-web-automation/playwright-webapp-testing}/SKILL.md +18 -1
  6. package/.agents/skills/05-security-and-compliance/wcag-audit-patterns/SKILL.md +116 -0
  7. package/.agents/workflows/generate_manual_testcases_rbt.md +1 -1
  8. package/Dockerfile +14 -6
  9. package/README.en.md +2 -2
  10. package/README.md +2 -2
  11. package/agentskills.json +16 -2
  12. package/docs/ARCHITECTURE.en.md +1 -1
  13. package/docs/ARCHITECTURE.md +1 -1
  14. package/package.json +1 -1
  15. package/plugin.json +1 -1
  16. package/skills_manifest.json +505 -394
  17. package/synapse.config.json +17 -1
  18. package/tools/__init__.py +1 -1
  19. package/tools/ast_cache.py +171 -0
  20. package/tools/author_integrity.py +7 -2
  21. package/tools/benchmark_swarm_context.py +242 -151
  22. package/tools/browser_helpers.js +2 -2
  23. package/tools/build_consolidated_report.py +6 -6
  24. package/tools/cache_resolver.py +11 -6
  25. package/tools/check_version_sync.py +56 -0
  26. package/tools/cli.py +16 -3
  27. package/tools/core/file_lock.py +187 -14
  28. package/tools/core/process_supervisor.py +25 -0
  29. package/tools/core/telemetry.py +139 -1
  30. package/tools/core/token_estimator.py +145 -0
  31. package/tools/count_tokens.py +28 -0
  32. package/tools/dashboard_generator.py +6 -6
  33. package/tools/debt_harvester.py +20 -9
  34. package/tools/diagram_architect.py +0 -1
  35. package/tools/distill_log.py +266 -89
  36. package/tools/git_pre_commit_guard.py +6 -4
  37. package/tools/git_worktree_manager.py +1 -1
  38. package/tools/infer_linter.py +2 -2
  39. package/tools/lint_ai_docs.py +19 -5
  40. package/tools/mcp_docx_server.py +1 -1
  41. package/tools/mcp_excel_server.py +1 -1
  42. package/tools/mcp_server.py +1 -1
  43. package/tools/mechanical_ui_gate.py +1 -1
  44. package/tools/micro_mutator.py +51 -10
  45. package/tools/pairwise_generator.py +0 -1
  46. package/tools/pentest_scope_guard.py +328 -0
  47. package/tools/perf/benchmark_perf_runner.py +226 -0
  48. package/tools/pinpoint_failure.py +14 -2
  49. package/tools/rules_router.py +596 -0
  50. package/tools/token_telemetry.py +224 -0
  51. package/tools/ui_server.py +1 -1
  52. package/tools/update_sentinel.py +3 -3
  53. package/tools/verify_all.py +67 -7
  54. package/tools/wcag_audit.py +1 -1
  55. package/tools/welcome_page.py +1 -1
  56. package/.agents/skills/wcag-audit-patterns/SKILL.md +0 -77
  57. /package/.agents/skills/{auth-session-and-cookie-manager → 01-web-automation/auth-session-and-cookie-manager}/SKILL.md +0 -0
  58. /package/.agents/skills/{auth-session-and-cookie-manager → 01-web-automation/auth-session-and-cookie-manager}/examples/multi_role_auth_matrix.md +0 -0
  59. /package/.agents/skills/{auth-session-and-cookie-manager → 01-web-automation/auth-session-and-cookie-manager}/examples/storage_state_sample.json +0 -0
  60. /package/.agents/skills/{bats-testing-patterns → 01-web-automation/bats-testing-patterns}/SKILL.md +0 -0
  61. /package/.agents/skills/{bats-testing-patterns → 01-web-automation/bats-testing-patterns}/examples/cli_runner_test.bats +0 -0
  62. /package/.agents/skills/{bats-testing-patterns → 01-web-automation/bats-testing-patterns}/resources/implementation-playbook.md +0 -0
  63. /package/.agents/skills/{clean-pom-crafter → 01-web-automation/clean-pom-crafter}/SKILL.md +0 -0
  64. /package/.agents/skills/{clean-pom-crafter → 01-web-automation/clean-pom-crafter}/examples/standard_test_case.groovy +0 -0
  65. /package/.agents/skills/{clean-pom-crafter → 01-web-automation/clean-pom-crafter}/references/pom_patterns.groovy +0 -0
  66. /package/.agents/skills/{e2e-testing-patterns → 01-web-automation/e2e-testing-patterns}/SKILL.md +0 -0
  67. /package/.agents/skills/{e2e-testing-patterns → 01-web-automation/e2e-testing-patterns}/examples/playwright_sharded_config.ts +0 -0
  68. /package/.agents/skills/{e2e-testing-patterns → 01-web-automation/e2e-testing-patterns}/resources/implementation-playbook.md +0 -0
  69. /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/SKILL.md +0 -0
  70. /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/examples/headless_kre_exec.sh +0 -0
  71. /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/references/groovy-patterns.md +0 -0
  72. /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/references/katalon-api.md +0 -0
  73. /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/references/runner_commands.md +0 -0
  74. /package/.agents/skills/{lam-script-generator → 01-web-automation/lam-script-generator}/SKILL.md +0 -0
  75. /package/.agents/skills/{lam-script-generator → 01-web-automation/lam-script-generator}/examples/user_story_sample.md +0 -0
  76. /package/.agents/skills/{mobile-appium-som → 01-web-automation/mobile-appium-som}/SKILL.md +0 -0
  77. /package/.agents/skills/{mobile-appium-som → 01-web-automation/mobile-appium-som}/examples/BaseScreen.java +0 -0
  78. /package/.agents/skills/{mobile-appium-som → 01-web-automation/mobile-appium-som}/examples/LoginScreen.java +0 -0
  79. /package/.agents/skills/{mobile-appium-som → 01-web-automation/mobile-appium-som}/examples/TC_MobileLogin.java +0 -0
  80. /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/SKILL.md +0 -0
  81. /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/examples/live_probe_script.js +0 -0
  82. /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/references/advanced_superpowers.md +0 -0
  83. /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/references/compact_accessibility_snapshots.md +0 -0
  84. /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/references/recipes.md +0 -0
  85. /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/references/swarm_orchestration.md +0 -0
  86. /package/.agents/skills/{playwright-webapp-testing → 01-web-automation/playwright-webapp-testing}/examples/server_lifecycle_playwright.py +0 -0
  87. /package/.agents/skills/{web-agent-gym-benchmarking → 01-web-automation/web-agent-gym-benchmarking}/SKILL.md +0 -0
  88. /package/.agents/skills/{web-agent-gym-benchmarking → 01-web-automation/web-agent-gym-benchmarking}/examples/benchmark_report_sample.json +0 -0
  89. /package/.agents/skills/{web-agent-gym-benchmarking → 01-web-automation/web-agent-gym-benchmarking}/examples/enterprise_tasks_suite.json +0 -0
  90. /package/.agents/skills/{architecture-decision-records → 02-test-design/architecture-decision-records}/SKILL.md +0 -0
  91. /package/.agents/skills/{architecture-decision-records → 02-test-design/architecture-decision-records}/examples/0001-record-architecture-decisions.md +0 -0
  92. /package/.agents/skills/{gherkin-to-suite → 02-test-design/gherkin-to-suite}/SKILL.md +0 -0
  93. /package/.agents/skills/{gherkin-to-suite → 02-test-design/gherkin-to-suite}/examples/checkout.feature +0 -0
  94. /package/.agents/skills/{gherkin-to-suite → 02-test-design/gherkin-to-suite}/examples/suite_report_sample.json +0 -0
  95. /package/.agents/skills/{rbt-manual-testing → 02-test-design/rbt-manual-testing}/SKILL.md +0 -0
  96. /package/.agents/skills/{rbt-manual-testing → 02-test-design/rbt-manual-testing}/examples/checkout_rbt_manual_suite.md +0 -0
  97. /package/.agents/skills/{rbt-manual-testing → 02-test-design/rbt-manual-testing}/references/field_validation_checklist.md +0 -0
  98. /package/.agents/skills/{review-spec → 02-test-design/review-spec}/SKILL.md +0 -0
  99. /package/.agents/skills/{review-spec → 02-test-design/review-spec}/examples/pocock_grilling_decision_rubric.md +0 -0
  100. /package/.agents/skills/{review-spec → 02-test-design/review-spec}/examples/sample_spec_review.md +0 -0
  101. /package/.agents/skills/{tot-exploratory-testing → 02-test-design/tot-exploratory-testing}/SKILL.md +0 -0
  102. /package/.agents/skills/{tot-exploratory-testing → 02-test-design/tot-exploratory-testing}/examples/payment_gateway_tot_tree.json +0 -0
  103. /package/.agents/skills/{tot-exploratory-testing → 02-test-design/tot-exploratory-testing}/examples/tot_graph_sample.json +0 -0
  104. /package/.agents/skills/{api-network-mocking-interception → 03-api-and-contracts/api-network-mocking-interception}/SKILL.md +0 -0
  105. /package/.agents/skills/{api-network-mocking-interception → 03-api-and-contracts/api-network-mocking-interception}/examples/network_route_stub.json +0 -0
  106. /package/.agents/skills/{api-spec-to-e2e-matrix → 03-api-and-contracts/api-spec-to-e2e-matrix}/SKILL.md +0 -0
  107. /package/.agents/skills/{api-spec-to-e2e-matrix → 03-api-and-contracts/api-spec-to-e2e-matrix}/examples/sample_openapi.json +0 -0
  108. /package/.agents/skills/{consumer-driven-contract-testing → 03-api-and-contracts/consumer-driven-contract-testing}/SKILL.md +0 -0
  109. /package/.agents/skills/{consumer-driven-contract-testing → 03-api-and-contracts/consumer-driven-contract-testing}/examples/order_service_pact.json +0 -0
  110. /package/.agents/skills/{backend-load-and-stress-patterns → 04-performance-and-load/backend-load-and-stress-patterns}/SKILL.md +0 -0
  111. /package/.agents/skills/{backend-load-and-stress-patterns → 04-performance-and-load/backend-load-and-stress-patterns}/examples/k6_load_test_sample.js +0 -0
  112. /package/.agents/skills/{backend-load-and-stress-patterns → 04-performance-and-load/backend-load-and-stress-patterns}/references/k6_load_template.js +0 -0
  113. /package/.agents/skills/{lean-impact-scoreboard → 04-performance-and-load/lean-impact-scoreboard}/SKILL.md +0 -0
  114. /package/.agents/skills/{lean-impact-scoreboard → 04-performance-and-load/lean-impact-scoreboard}/examples/sample_benchmark_gain.md +0 -0
  115. /package/.agents/skills/{lean-impact-scoreboard → 04-performance-and-load/lean-impact-scoreboard}/examples/sample_scoreboard.md +0 -0
  116. /package/.agents/skills/{web-vitals-and-performance-profiler → 04-performance-and-load/web-vitals-and-performance-profiler}/SKILL.md +0 -0
  117. /package/.agents/skills/{web-vitals-and-performance-profiler → 04-performance-and-load/web-vitals-and-performance-profiler}/examples/cwv_budget_policy.json +0 -0
  118. /package/.agents/skills/{web-vitals-and-performance-profiler → 04-performance-and-load/web-vitals-and-performance-profiler}/examples/playwright_cwv_profiler_fixture.ts +0 -0
  119. /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/SKILL.md +0 -0
  120. /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/examples/dast_scan_config.json +0 -0
  121. /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/references/AI-AND-LLM.md +0 -0
  122. /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/references/ATTACK-CLASSES.md +0 -0
  123. /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/references/dast_recipes.ts +0 -0
  124. /package/.agents/skills/{skillspector-security-guard → 05-security-and-compliance/skillspector-security-guard}/SKILL.md +0 -0
  125. /package/.agents/skills/{skillspector-security-guard → 05-security-and-compliance/skillspector-security-guard}/examples/audit_threat_vectors_report.json +0 -0
  126. /package/.agents/skills/{skillspector-security-guard → 05-security-and-compliance/skillspector-security-guard}/examples/safe_mcp_config.json +0 -0
  127. /package/.agents/skills/{wcag-audit-patterns → 05-security-and-compliance/wcag-audit-patterns}/examples/wcag_compliance_checklist.json +0 -0
  128. /package/.agents/skills/{wcag-audit-patterns → 05-security-and-compliance/wcag-audit-patterns}/resources/implementation-playbook.md +0 -0
  129. /package/.agents/skills/{agentless-qa-repair → 06-healing-and-resilience/agentless-qa-repair}/SKILL.md +0 -0
  130. /package/.agents/skills/{agentless-qa-repair → 06-healing-and-resilience/agentless-qa-repair}/examples/healing_report_sample.json +0 -0
  131. /package/.agents/skills/{agentless-qa-repair → 06-healing-and-resilience/agentless-qa-repair}/examples/three_phase_repair_workflow.md +0 -0
  132. /package/.agents/skills/{antigravity-test-sentinel → 06-healing-and-resilience/antigravity-test-sentinel}/SKILL.md +0 -0
  133. /package/.agents/skills/{antigravity-test-sentinel → 06-healing-and-resilience/antigravity-test-sentinel}/examples/dod_gate_policy.json +0 -0
  134. /package/.agents/skills/{antigravity-test-sentinel → 06-healing-and-resilience/antigravity-test-sentinel}/examples/sprint_dod_enforcement.md +0 -0
  135. /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/SKILL.md +0 -0
  136. /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/examples/closed_loop_healing_walkthrough.md +0 -0
  137. /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/examples/sample_junit_failure.xml +0 -0
  138. /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/references/healing_matrix.md +0 -0
  139. /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/references/qa_investigation_protocol.md +0 -0
  140. /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/scripts/triage_failures.sh +0 -0
  141. /package/.agents/skills/{flaky-test-sentinel-and-quarantine → 06-healing-and-resilience/flaky-test-sentinel-and-quarantine}/SKILL.md +0 -0
  142. /package/.agents/skills/{flaky-test-sentinel-and-quarantine → 06-healing-and-resilience/flaky-test-sentinel-and-quarantine}/examples/quarantine_registry.json +0 -0
  143. /package/.agents/skills/{self-healing-locator → 06-healing-and-resilience/self-healing-locator}/SKILL.md +0 -0
  144. /package/.agents/skills/{self-healing-locator → 06-healing-and-resilience/self-healing-locator}/examples/aom_diff_sample.json +0 -0
  145. /package/.agents/skills/{systematic-debugging → 06-healing-and-resilience/systematic-debugging}/SKILL.md +0 -0
  146. /package/.agents/skills/{systematic-debugging → 06-healing-and-resilience/systematic-debugging}/examples/four_phase_case.md +0 -0
  147. /package/.agents/skills/{test-driven-development → 06-healing-and-resilience/test-driven-development}/SKILL.md +0 -0
  148. /package/.agents/skills/{test-driven-development → 06-healing-and-resilience/test-driven-development}/examples/red_green_refactor_qa.md +0 -0
  149. /package/.agents/skills/{verification-before-completion → 06-healing-and-resilience/verification-before-completion}/SKILL.md +0 -0
  150. /package/.agents/skills/{verification-before-completion → 06-healing-and-resilience/verification-before-completion}/examples/evidence_log_example.md +0 -0
  151. /package/.agents/skills/{visual-regression-sentinel → 06-healing-and-resilience/visual-regression-sentinel}/SKILL.md +0 -0
  152. /package/.agents/skills/{visual-regression-sentinel → 06-healing-and-resilience/visual-regression-sentinel}/examples/visual_mask_rules.json +0 -0
  153. /package/.agents/skills/{db-state-verifier-and-seeder → 07-data-and-state/db-state-verifier-and-seeder}/SKILL.md +0 -0
  154. /package/.agents/skills/{db-state-verifier-and-seeder → 07-data-and-state/db-state-verifier-and-seeder}/examples/db_fixture_seed.json +0 -0
  155. /package/.agents/skills/{file-and-report-validator → 07-data-and-state/file-and-report-validator}/SKILL.md +0 -0
  156. /package/.agents/skills/{file-and-report-validator → 07-data-and-state/file-and-report-validator}/examples/sample_export_schema.json +0 -0
  157. /package/.agents/skills/{synthetic-test-data-generator → 07-data-and-state/synthetic-test-data-generator}/SKILL.md +0 -0
  158. /package/.agents/skills/{synthetic-test-data-generator → 07-data-and-state/synthetic-test-data-generator}/examples/idempotent_data_recipe.json +0 -0
  159. /package/.agents/skills/{code-refactoring-refactor-clean → 08-code-quality/code-refactoring-refactor-clean}/SKILL.md +0 -0
  160. /package/.agents/skills/{code-refactoring-refactor-clean → 08-code-quality/code-refactoring-refactor-clean}/examples/refactored_page_sample.groovy +0 -0
  161. /package/.agents/skills/{code-refactoring-refactor-clean → 08-code-quality/code-refactoring-refactor-clean}/examples/refactored_playwright_pom.ts +0 -0
  162. /package/.agents/skills/{code-refactoring-refactor-clean → 08-code-quality/code-refactoring-refactor-clean}/resources/implementation-playbook.md +0 -0
  163. /package/.agents/skills/{graphify-impact-analyzer → 08-code-quality/graphify-impact-analyzer}/SKILL.md +0 -0
  164. /package/.agents/skills/{graphify-impact-analyzer → 08-code-quality/graphify-impact-analyzer}/examples/dependency_blast_radius.json +0 -0
  165. /package/.agents/skills/{lean-code-ladder → 08-code-quality/lean-code-ladder}/SKILL.md +0 -0
  166. /package/.agents/skills/{lean-code-ladder → 08-code-quality/lean-code-ladder}/examples/ladder_walkthrough.md +0 -0
  167. /package/.agents/skills/{repo-quality-audit → 08-code-quality/repo-quality-audit}/SKILL.md +0 -0
  168. /package/.agents/skills/{repo-quality-audit → 08-code-quality/repo-quality-audit}/examples/sample_audit_walkthrough.md +0 -0
  169. /package/.agents/skills/{repo-quality-audit → 08-code-quality/repo-quality-audit}/examples/sample_repo_audit.md +0 -0
  170. /package/.agents/skills/{senior-code-review → 08-code-quality/senior-code-review}/SKILL.md +0 -0
  171. /package/.agents/skills/{senior-code-review → 08-code-quality/senior-code-review}/examples/sample_review_walkthrough.md +0 -0
  172. /package/.agents/skills/{surgical-coding-principles → 08-code-quality/surgical-coding-principles}/SKILL.md +0 -0
  173. /package/.agents/skills/{surgical-coding-principles → 08-code-quality/surgical-coding-principles}/examples/surgical_vs_scope_creep.md +0 -0
  174. /package/.agents/skills/{technical-debt-harvester → 08-code-quality/technical-debt-harvester}/SKILL.md +0 -0
  175. /package/.agents/skills/{technical-debt-harvester → 08-code-quality/technical-debt-harvester}/examples/sample_debt_ledger.md +0 -0
  176. /package/.agents/skills/{technical-debt-harvester → 08-code-quality/technical-debt-harvester}/examples/sample_ledger_output.md +0 -0
  177. /package/.agents/skills/{github-actions-templates → 09-ci-and-devops/github-actions-templates}/SKILL.md +0 -0
  178. /package/.agents/skills/{github-actions-templates → 09-ci-and-devops/github-actions-templates}/examples/matrix_test_pipeline.yml +0 -0
  179. /package/.agents/skills/{actor-qa-swarm → 10-agent-orchestration/actor-qa-swarm}/SKILL.md +0 -0
  180. /package/.agents/skills/{actor-qa-swarm → 10-agent-orchestration/actor-qa-swarm}/examples/broker_sharding_sample.json +0 -0
  181. /package/.agents/skills/{agent-orchestration-multi-agent-optimize → 10-agent-orchestration/agent-orchestration-multi-agent-optimize}/SKILL.md +0 -0
  182. /package/.agents/skills/{agent-orchestration-multi-agent-optimize → 10-agent-orchestration/agent-orchestration-multi-agent-optimize}/examples/swarm_workload_config.json +0 -0
  183. /package/.agents/skills/{event-stream-qa-orchestrator → 10-agent-orchestration/event-stream-qa-orchestrator}/SKILL.md +0 -0
  184. /package/.agents/skills/{event-stream-qa-orchestrator → 10-agent-orchestration/event-stream-qa-orchestrator}/examples/timeline_sample.jsonl +0 -0
  185. /package/.agents/skills/{persistent-planning-files → 10-agent-orchestration/persistent-planning-files}/SKILL.md +0 -0
  186. /package/.agents/skills/{persistent-planning-files → 10-agent-orchestration/persistent-planning-files}/examples/task_plan_example.md +0 -0
  187. /package/.agents/skills/{qa-memory-os → 10-agent-orchestration/qa-memory-os}/SKILL.md +0 -0
  188. /package/.agents/skills/{qa-memory-os → 10-agent-orchestration/qa-memory-os}/examples/archival_memory_sample.json +0 -0
  189. /package/.agents/skills/{meta-prompt-crafter → 11-ai-and-prompting/meta-prompt-crafter}/SKILL.md +0 -0
  190. /package/.agents/skills/{meta-prompt-crafter → 11-ai-and-prompting/meta-prompt-crafter}/examples/qa_prompt_template.md +0 -0
  191. /package/.agents/skills/{mipro-prompt-compiler → 11-ai-and-prompting/mipro-prompt-compiler}/SKILL.md +0 -0
  192. /package/.agents/skills/{mipro-prompt-compiler → 11-ai-and-prompting/mipro-prompt-compiler}/examples/compiled_module_sample.json +0 -0
  193. /package/.agents/skills/{mipro-prompt-compiler → 11-ai-and-prompting/mipro-prompt-compiler}/examples/dspy_assertion_optimizer_case.md +0 -0
  194. /package/.agents/skills/{qa-aci-interface → 11-ai-and-prompting/qa-aci-interface}/SKILL.md +0 -0
  195. /package/.agents/skills/{qa-aci-interface → 11-ai-and-prompting/qa-aci-interface}/examples/surgical_code_window_walkthrough.md +0 -0
  196. /package/.agents/skills/{qa-aci-interface → 11-ai-and-prompting/qa-aci-interface}/examples/surgical_edit_sample.json +0 -0
  197. /package/.agents/skills/{token-and-context-optimizer → 11-ai-and-prompting/token-and-context-optimizer}/SKILL.md +0 -0
  198. /package/.agents/skills/{token-and-context-optimizer → 11-ai-and-prompting/token-and-context-optimizer}/examples/distilled_log_sample.txt +0 -0
  199. /package/.agents/skills/{token-and-context-optimizer → 11-ai-and-prompting/token-and-context-optimizer}/references/context_engineering_guide.md +0 -0
@@ -216,6 +216,56 @@ def check_sync(repo_root: str, expected_version: Optional[str] = None) -> Tuple[
216
216
  return True, versions, target_ver
217
217
 
218
218
 
219
+ def validate_lockfile_integrity(repo_root: str) -> Tuple[bool, str]:
220
+ """
221
+ Validates canonical lockfile (skills-lock.json), synchronizes .skill-lock.json,
222
+ and verifies SHA-256 integrity hash for all registered skills.
223
+ """
224
+ canonical_lock = os.path.join(repo_root, "skills-lock.json")
225
+ secondary_lock = os.path.join(repo_root, ".skill-lock.json")
226
+
227
+ if not os.path.exists(canonical_lock):
228
+ return False, "Canonical lockfile skills-lock.json is missing!"
229
+
230
+ try:
231
+ with open(canonical_lock, "r", encoding="utf-8") as f:
232
+ lock_data = json.load(f)
233
+ except Exception as e:
234
+ return False, f"skills-lock.json malformed JSON: {e}"
235
+
236
+ skills = lock_data.get("skills", {})
237
+ if len(skills) != 53:
238
+ return False, f"Expected 53 skills in skills-lock.json, found {len(skills)}"
239
+
240
+ for s_name, s_meta in skills.items():
241
+ s_path = s_meta.get("skillPath")
242
+ if not s_path:
243
+ return False, f"Skill '{s_name}' missing skillPath"
244
+ full_path = os.path.join(repo_root, s_path)
245
+ if not os.path.exists(full_path):
246
+ return False, f"Skill '{s_name}' path not found: {s_path}"
247
+ s_hash = s_meta.get("skillFolderHash")
248
+ if not s_hash or len(s_hash) != 64 or not all(c in "0123456789abcdefABCDEF" for c in s_hash):
249
+ return False, f"Skill '{s_name}' has invalid SHA-256 hash: {s_hash}"
250
+
251
+ # Auto-sync secondary lockfile .skill-lock.json to maintain atomic parity
252
+ try:
253
+ with open(canonical_lock, "rb") as cf:
254
+ content_bytes = cf.read()
255
+ needs_write = True
256
+ if os.path.exists(secondary_lock):
257
+ with open(secondary_lock, "rb") as sf:
258
+ if sf.read() == content_bytes:
259
+ needs_write = False
260
+ if needs_write:
261
+ with open(secondary_lock, "wb") as sf:
262
+ sf.write(content_bytes)
263
+ except Exception as e:
264
+ return False, f"Failed to sync .skill-lock.json: {e}"
265
+
266
+ return True, f"53/53 skills verified with valid paths & SHA-256 hashes (auto-synced .skill-lock.json)"
267
+
268
+
219
269
  def main() -> int:
220
270
  parser = argparse.ArgumentParser(description="Verify universal version sync across Synapse Hub files")
221
271
  parser.add_argument("--expected-version", "-e", help="Expected version string (e.g. from git tag)", default=None)
@@ -243,6 +293,12 @@ def main() -> int:
243
293
  all_matched = False
244
294
  print(f" {status:<11} {file_path:<26} -> {ver}")
245
295
 
296
+ lock_ok, lock_msg = validate_lockfile_integrity(args.repo_root)
297
+ lock_status = "[MATCH]" if lock_ok else "[MISMATCH]"
298
+ print(f" {lock_status:<11} {'skills-lock.json (SHA-256)':<26} -> {lock_msg}")
299
+ if not lock_ok:
300
+ all_matched = False
301
+
246
302
  print("======================================================================")
247
303
  if is_synced and all_matched:
248
304
  print(f"[PASS] 100% Version synchronization verified across all {len(versions)} targets.")
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 = "3.10.0"
102
+ version = "4.1.0"
103
103
  if os.path.exists(manifest_path):
104
104
  try:
105
105
  import json
@@ -552,6 +552,12 @@ def cmd_wcag_audit(args):
552
552
  sys.exit(wcag_main())
553
553
 
554
554
 
555
+ def cmd_rules_router(args):
556
+ from rules_router import main as router_main
557
+ sys.argv = _forward_subcommand_args(args)
558
+ sys.exit(router_main())
559
+
560
+
555
561
  def cmd_lookup_tc(args):
556
562
  from lookup_tc import main as tc_main
557
563
  sys.argv = _forward_subcommand_args(args)
@@ -680,14 +686,14 @@ def cmd_trend(args):
680
686
 
681
687
  def _hub_version():
682
688
  manifest_path = os.path.join(REPO_ROOT, "skills_manifest.json")
683
- version = "3.10.0"
689
+ version = "4.1.0"
684
690
  if os.path.exists(manifest_path):
685
691
  try:
686
692
  import json
687
693
  with open(manifest_path, "r", encoding="utf-8") as f:
688
694
  version = json.load(f).get("version", version)
689
695
  except (OSError, json.JSONDecodeError):
690
- version = "3.10.0"
696
+ version = "4.1.0"
691
697
  return version
692
698
 
693
699
 
@@ -1189,6 +1195,13 @@ def _register_audit_and_inspection_commands(subparsers, lang: Optional[str] = No
1189
1195
  p_wcag.add_argument("target", nargs="?", default=".", help=_lh("Target HTML file or directory to audit", "Tệp HTML hoặc thư mục cần kiểm toán WCAG", lang))
1190
1196
  p_wcag.set_defaults(func=cmd_wcag_audit)
1191
1197
 
1198
+ # rules-router (Boost B2)
1199
+ p_router = subparsers.add_parser("rules-router", aliases=["route-rules"], help=_lh("Progressive Rules Router & Token Optimizer", "Định tuyến quy tắc thông minh & tối ưu token", lang))
1200
+ p_router.add_argument("workspace", nargs="?", default=".", help=_lh("Target workspace directory to inspect", "Thư mục dự án cần phân tích stack", lang))
1201
+ p_router.add_argument("--json", action="store_true", help=_lh("Output machine-readable JSON format", "Xuất định dạng JSON cho máy đọc", lang))
1202
+ p_router.add_argument("--summary", action="store_true", help=_lh("Output concise 1-line summary", "Xuất tóm tắt 1 dòng ngắn gọn", lang))
1203
+ p_router.set_defaults(func=cmd_rules_router)
1204
+
1192
1205
  # impact
1193
1206
  p_impact = subparsers.add_parser("impact", help=t("cmd_impact", lang=lang))
1194
1207
  p_impact.set_defaults(func=cmd_impact)
@@ -28,7 +28,133 @@ from typing import Any, Optional
28
28
  if sys.platform != "win32":
29
29
  import fcntl
30
30
  else:
31
- import msvcrt # type: ignore
31
+ pass # type: ignore
32
+
33
+ # Win32 Native Locking Constants (Boost B1)
34
+ LOCKFILE_FAIL_IMMEDIATELY = 0x00000001
35
+ LOCKFILE_EXCLUSIVE_LOCK = 0x00000002
36
+
37
+ try:
38
+ import ctypes
39
+ from ctypes import wintypes
40
+ _HAS_CTYPES = True
41
+ except ImportError:
42
+ ctypes = None # type: ignore
43
+ wintypes = None # type: ignore
44
+ _HAS_CTYPES = False
45
+
46
+ if _HAS_CTYPES:
47
+ class _OVERLAPPED(ctypes.Structure):
48
+ _fields_ = [
49
+ ("Internal", getattr(wintypes, "ULONG_PTR", ctypes.c_size_t)),
50
+ ("InternalHigh", getattr(wintypes, "ULONG_PTR", ctypes.c_size_t)),
51
+ ("Offset", getattr(wintypes, "DWORD", ctypes.c_ulong)),
52
+ ("OffsetHigh", getattr(wintypes, "DWORD", ctypes.c_ulong)),
53
+ ("hEvent", getattr(wintypes, "HANDLE", ctypes.c_void_p)),
54
+ ]
55
+ else:
56
+ _OVERLAPPED = None # type: ignore
57
+
58
+
59
+ def _win32_lock(fd: int, shared: bool = False) -> bool:
60
+ """
61
+ Acquires an advisory file lock on Windows using native Win32 LockFileEx via ctypes.
62
+ Provides genuine shared (LOCKFILE_FAIL_IMMEDIATELY) and exclusive
63
+ (LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY) locks with an OVERLAPPED structure.
64
+ Gracefully falls back to msvcrt.locking if ctypes or LockFileEx is unavailable.
65
+ """
66
+ msvcrt_mod = sys.modules.get("msvcrt")
67
+ use_ctypes = _HAS_CTYPES and hasattr(ctypes, "windll") and hasattr(ctypes.windll, "kernel32")
68
+ if use_ctypes:
69
+ try:
70
+ handle = msvcrt_mod.get_osfhandle(fd) if msvcrt_mod and hasattr(msvcrt_mod, "get_osfhandle") else fd
71
+ flags = LOCKFILE_FAIL_IMMEDIATELY
72
+ if not shared:
73
+ flags |= LOCKFILE_EXCLUSIVE_LOCK
74
+ overlapped = _OVERLAPPED()
75
+ res = ctypes.windll.kernel32.LockFileEx(
76
+ ctypes.c_void_p(handle),
77
+ ctypes.c_ulong(flags),
78
+ ctypes.c_ulong(0),
79
+ ctypes.c_ulong(1),
80
+ ctypes.c_ulong(0),
81
+ ctypes.byref(overlapped),
82
+ )
83
+ if not res:
84
+ get_last_error = getattr(ctypes, "GetLastError", lambda: 0)
85
+ err = get_last_error()
86
+ raise OSError(err, f"LockFileEx failed with error code {err}")
87
+ return True
88
+ except (AttributeError, TypeError, ValueError) as exc:
89
+ # Fall through to msvcrt fallback if ctypes kernel32 LockFileEx is missing or incompatible
90
+ _ = exc
91
+
92
+ # Graceful fallback to msvcrt.locking (exclusive lock only)
93
+ if msvcrt_mod is not None:
94
+ os.lseek(fd, 0, os.SEEK_SET)
95
+ msvcrt_mod.locking(fd, msvcrt_mod.LK_NBLCK, 1)
96
+ return True
97
+ raise OSError("Neither Win32 ctypes nor msvcrt is available for file locking.")
98
+
99
+
100
+ def _win32_unlock(fd: int) -> bool:
101
+ """
102
+ Releases an advisory file lock on Windows using native Win32 UnlockFileEx via ctypes.
103
+ Falls back to msvcrt.locking with LK_UNLCK if ctypes is unavailable.
104
+ """
105
+ msvcrt_mod = sys.modules.get("msvcrt")
106
+ use_ctypes = _HAS_CTYPES and hasattr(ctypes, "windll") and hasattr(ctypes.windll, "kernel32")
107
+ if use_ctypes:
108
+ try:
109
+ handle = msvcrt_mod.get_osfhandle(fd) if msvcrt_mod and hasattr(msvcrt_mod, "get_osfhandle") else fd
110
+ overlapped = _OVERLAPPED()
111
+ res = ctypes.windll.kernel32.UnlockFileEx(
112
+ ctypes.c_void_p(handle),
113
+ ctypes.c_ulong(0),
114
+ ctypes.c_ulong(1),
115
+ ctypes.c_ulong(0),
116
+ ctypes.byref(overlapped),
117
+ )
118
+ return bool(res)
119
+ except (AttributeError, TypeError, ValueError) as exc:
120
+ _ = exc
121
+
122
+ # Graceful fallback to msvcrt.locking
123
+ if msvcrt_mod is not None:
124
+ try:
125
+ os.lseek(fd, 0, os.SEEK_SET)
126
+ msvcrt_mod.locking(fd, msvcrt_mod.LK_UNLCK, 1)
127
+ return True
128
+ except OSError:
129
+ return False
130
+ return False
131
+
132
+
133
+ def _is_process_alive(pid: int) -> bool:
134
+ """Checks whether a process with the given PID is currently active."""
135
+ if pid <= 0:
136
+ return False
137
+ if sys.platform != "win32":
138
+ try:
139
+ os.kill(pid, 0)
140
+ return True
141
+ except OSError:
142
+ return False
143
+ else:
144
+ try:
145
+ if _HAS_CTYPES and hasattr(ctypes, "windll") and hasattr(ctypes.windll, "kernel32"):
146
+ PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
147
+ SYNCHRONIZE = 0x00100000
148
+ handle = ctypes.windll.kernel32.OpenProcess(
149
+ PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, False, pid
150
+ )
151
+ if handle:
152
+ ctypes.windll.kernel32.CloseHandle(handle)
153
+ return True
154
+ return False
155
+ except Exception as err:
156
+ _ = err
157
+ return True
32
158
 
33
159
 
34
160
  class FileLockTimeoutError(TimeoutError):
@@ -38,7 +164,7 @@ class FileLockTimeoutError(TimeoutError):
38
164
 
39
165
  class FileLock:
40
166
  """
41
- Cross-platform advisory file lock context manager.
167
+ Cross-platform advisory file lock context manager with stale lock auto-reclamation.
42
168
  """
43
169
 
44
170
  def __init__(
@@ -55,10 +181,27 @@ class FileLock:
55
181
  self.poll_interval = poll_interval
56
182
  self._fd: Optional[int] = None
57
183
 
184
+ def _read_lock_pid(self) -> Optional[int]:
185
+ """Reads lock metadata (pid:timestamp) from the lock file if present."""
186
+ try:
187
+ if os.path.exists(self.lock_path):
188
+ with open(self.lock_path, "r", encoding="utf-8", errors="replace") as f:
189
+ content = f.read(64).strip()
190
+ if ":" in content:
191
+ pid_str = content.split(":", 1)[0]
192
+ if pid_str.isdigit():
193
+ return int(pid_str)
194
+ elif content.isdigit():
195
+ return int(content)
196
+ except Exception as err:
197
+ _ = err
198
+ return None
199
+
58
200
  def acquire(self) -> FileLock:
59
- """Acquires the advisory lock, polling until timeout."""
201
+ """Acquires the advisory lock, polling until timeout with stale-lock reclamation."""
60
202
  os.makedirs(os.path.dirname(self.lock_path), exist_ok=True)
61
203
  start = time.time()
204
+ stale_reclaimed = False
62
205
  while True:
63
206
  try:
64
207
  if self._fd is None:
@@ -69,10 +212,21 @@ class FileLock:
69
212
  fcntl.flock(self._fd, mode | fcntl.LOCK_NB)
70
213
  else:
71
214
  # Ensure at least 1 byte exists to lock on Windows
72
- if os.path.getsize(self.lock_path) == 0:
73
- os.write(self._fd, b"\x00")
215
+ try:
216
+ if os.fstat(self._fd).st_size == 0:
217
+ os.write(self._fd, b"\x00")
218
+ except (OSError, PermissionError) as err:
219
+ _ = err
74
220
  os.lseek(self._fd, 0, os.SEEK_SET)
75
- msvcrt.locking(self._fd, msvcrt.LK_NBLCK, 1)
221
+ _win32_lock(self._fd, shared=self.shared)
222
+
223
+ # Write PID into lock file metadata for stale lock tracking if exclusive
224
+ if not self.shared and self._fd is not None:
225
+ try:
226
+ os.lseek(self._fd, 0, os.SEEK_SET)
227
+ os.write(self._fd, f"{os.getpid()}:{int(time.time())}\n".encode("utf-8"))
228
+ except OSError as err:
229
+ _ = err
76
230
  return self
77
231
  except (BlockingIOError, OSError, PermissionError):
78
232
  if self._fd is not None:
@@ -81,7 +235,22 @@ class FileLock:
81
235
  except OSError as err:
82
236
  _ = err
83
237
  self._fd = None
84
- if time.time() - start >= self.timeout:
238
+
239
+ elapsed = time.time() - start
240
+ if elapsed >= self.timeout:
241
+ # Attempt stale lock reclamation if holder PID is dead
242
+ if not stale_reclaimed:
243
+ holder_pid = self._read_lock_pid()
244
+ if holder_pid and not _is_process_alive(holder_pid):
245
+ try:
246
+ if os.path.exists(self.lock_path):
247
+ os.remove(self.lock_path)
248
+ stale_reclaimed = True
249
+ time.sleep(0.02)
250
+ continue
251
+ except OSError as err:
252
+ _ = err
253
+
85
254
  raise FileLockTimeoutError(
86
255
  f"Timed out after {self.timeout}s waiting for lock on {self.lock_path}"
87
256
  )
@@ -94,11 +263,7 @@ class FileLock:
94
263
  if sys.platform != "win32":
95
264
  fcntl.flock(self._fd, fcntl.LOCK_UN)
96
265
  else:
97
- try:
98
- os.lseek(self._fd, 0, os.SEEK_SET)
99
- msvcrt.locking(self._fd, msvcrt.LK_UNLCK, 1)
100
- except OSError as err:
101
- _ = err
266
+ _win32_unlock(self._fd)
102
267
  os.close(self._fd)
103
268
  except OSError as err:
104
269
  _ = err
@@ -122,7 +287,7 @@ def locked_read(file_path: str, timeout: float = 10.0) -> str:
122
287
  def locked_write(file_path: str, content: str, timeout: float = 10.0, atomic: bool = True) -> None:
123
288
  """
124
289
  Safely writes content to a file while holding an exclusive lock.
125
- When atomic=True, writes to a temporary file first, then atomically replaces.
290
+ When atomic=True, writes to a temporary file first, then atomically replaces with Windows retry.
126
291
  """
127
292
  os.makedirs(os.path.dirname(os.path.abspath(file_path)), exist_ok=True)
128
293
  with FileLock(file_path, timeout=timeout, shared=False):
@@ -133,7 +298,15 @@ def locked_write(file_path: str, content: str, timeout: float = 10.0, atomic: bo
133
298
  f.write(content)
134
299
  f.flush()
135
300
  os.fsync(f.fileno())
136
- os.replace(temp_path, file_path)
301
+ # Resilient atomic replace with retry backoff for Windows NTFS file lock latency
302
+ for attempt in range(5):
303
+ try:
304
+ os.replace(temp_path, file_path)
305
+ break
306
+ except (PermissionError, OSError) as err:
307
+ if attempt == 4:
308
+ raise
309
+ time.sleep(0.01 * (attempt + 1))
137
310
  finally:
138
311
  if os.path.exists(temp_path):
139
312
  try:
@@ -369,3 +369,28 @@ class ProcessSupervisor:
369
369
 
370
370
  def __exit__(self, exc_type, exc_val, exc_tb):
371
371
  self.cleanup_all()
372
+
373
+
374
+ def run_supervised(
375
+ cmd: List[str],
376
+ timeout: float = 60.0,
377
+ cwd: Optional[str] = None,
378
+ env: Optional[Dict[str, str]] = None,
379
+ capture_output: bool = True,
380
+ text: bool = True,
381
+ input_data: Optional[str] = None,
382
+ ) -> SupervisedResult:
383
+ """
384
+ Convenience function to execute a command under a governed ProcessSupervisor session.
385
+ Guarantees strict execution timeout, process group isolation, and zombie process cleanup (Boost B4).
386
+ """
387
+ with ProcessSupervisor(default_timeout=timeout) as supervisor:
388
+ return supervisor.run(
389
+ cmd=cmd,
390
+ timeout=timeout,
391
+ cwd=cwd,
392
+ env=env,
393
+ capture_output=capture_output,
394
+ text=text,
395
+ input_data=input_data,
396
+ )
@@ -31,7 +31,7 @@ import logging
31
31
  import contextvars
32
32
  from datetime import datetime, timezone
33
33
  from dataclasses import dataclass
34
- from typing import Dict, Any, Optional, Generator
34
+ from typing import Dict, Any, Optional, Generator, List
35
35
  from contextlib import contextmanager
36
36
 
37
37
  # W3C Constants
@@ -356,3 +356,141 @@ def trace_span(
356
356
  **extra
357
357
  )
358
358
  set_current_trace_context(parent_ctx)
359
+
360
+
361
+ # ---------------------------------------------------------------------------
362
+ # Session Token & MTTR Telemetry Ledger (Closed-Loop Quality & Efficiency)
363
+ # ---------------------------------------------------------------------------
364
+
365
+ DEFAULT_SESSION_LEDGER = os.path.join(
366
+ os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
367
+ "reports",
368
+ "session_telemetry_ledger.json",
369
+ )
370
+
371
+
372
+ @dataclass
373
+ class SessionTelemetryRecord:
374
+ session_id: str
375
+ timestamp: str
376
+ model: str
377
+ platform: str
378
+ task_type: str
379
+ stack: str
380
+ turns: int
381
+ input_tokens: int
382
+ output_tokens: int
383
+ cached_tokens: int
384
+ cache_hit_ratio: float
385
+ raw_log_bytes: int
386
+ distilled_log_bytes: int
387
+ distillation_reduction_pct: float
388
+ test_outcome: str
389
+ bug_resolved: bool
390
+ tokens_per_bug: int
391
+ elapsed_seconds: float
392
+
393
+ def to_dict(self) -> Dict[str, Any]:
394
+ return {
395
+ "session_id": self.session_id,
396
+ "timestamp": self.timestamp,
397
+ "model": self.model,
398
+ "platform": self.platform,
399
+ "task_type": self.task_type,
400
+ "stack": self.stack,
401
+ "turns": self.turns,
402
+ "input_tokens": self.input_tokens,
403
+ "output_tokens": self.output_tokens,
404
+ "cached_tokens": self.cached_tokens,
405
+ "cache_hit_ratio": self.cache_hit_ratio,
406
+ "raw_log_bytes": self.raw_log_bytes,
407
+ "distilled_log_bytes": self.distilled_log_bytes,
408
+ "distillation_reduction_pct": self.distillation_reduction_pct,
409
+ "test_outcome": self.test_outcome,
410
+ "bug_resolved": self.bug_resolved,
411
+ "tokens_per_bug": self.tokens_per_bug,
412
+ "elapsed_seconds": self.elapsed_seconds,
413
+ }
414
+
415
+
416
+ def record_session_telemetry(
417
+ record: SessionTelemetryRecord,
418
+ ledger_file: Optional[str] = None,
419
+ ) -> None:
420
+ """Appends a closed-loop session telemetry record to the JSON ledger with file locking."""
421
+ target_path = ledger_file or DEFAULT_SESSION_LEDGER
422
+ os.makedirs(os.path.dirname(os.path.abspath(target_path)), exist_ok=True)
423
+
424
+ records: List[Dict[str, Any]] = []
425
+ if os.path.exists(target_path):
426
+ try:
427
+ with open(target_path, "r", encoding="utf-8") as f:
428
+ records = json.load(f)
429
+ except (OSError, json.JSONDecodeError):
430
+ records = []
431
+
432
+ records.append(record.to_dict())
433
+ with open(target_path, "w", encoding="utf-8") as f:
434
+ json.dump(records, f, indent=2, ensure_ascii=False)
435
+
436
+
437
+ def get_telemetry_summary(ledger_file: Optional[str] = None) -> Dict[str, Any]:
438
+ """Computes median/P90 tokens per resolved bug, MTTR, and compression statistics."""
439
+ target_path = ledger_file or DEFAULT_SESSION_LEDGER
440
+ if not os.path.exists(target_path):
441
+ return {
442
+ "sample_size": 0,
443
+ "resolved_bugs": 0,
444
+ "median_tokens_per_bug": 0,
445
+ "p90_tokens_per_bug": 0,
446
+ "mttr_seconds": 0.0,
447
+ "avg_cache_hit_ratio": 0.0,
448
+ "avg_distillation_reduction_pct": 0.0,
449
+ }
450
+
451
+ try:
452
+ with open(target_path, "r", encoding="utf-8") as f:
453
+ records: List[Dict[str, Any]] = json.load(f)
454
+ except (OSError, json.JSONDecodeError):
455
+ records = []
456
+
457
+ if not records:
458
+ return {
459
+ "sample_size": 0,
460
+ "resolved_bugs": 0,
461
+ "median_tokens_per_bug": 0,
462
+ "p90_tokens_per_bug": 0,
463
+ "mttr_seconds": 0.0,
464
+ "avg_cache_hit_ratio": 0.0,
465
+ "avg_distillation_reduction_pct": 0.0,
466
+ }
467
+
468
+ resolved = [r for r in records if r.get("bug_resolved")]
469
+ tokens_per_bug = sorted([r.get("tokens_per_bug", 0) for r in resolved])
470
+ durations = [r.get("elapsed_seconds", 0.0) for r in resolved]
471
+ cache_ratios = [r.get("cache_hit_ratio", 0.0) for r in records]
472
+ distill_pcts = [r.get("distillation_reduction_pct", 0.0) for r in records]
473
+
474
+ def _median(vals: List[float]) -> float:
475
+ if not vals:
476
+ return 0.0
477
+ n = len(vals)
478
+ mid = n // 2
479
+ return (vals[mid] if n % 2 != 0 else (vals[mid - 1] + vals[mid]) / 2.0)
480
+
481
+ def _p90(vals: List[float]) -> float:
482
+ if not vals:
483
+ return 0.0
484
+ idx = int(len(vals) * 0.90)
485
+ return vals[min(idx, len(vals) - 1)]
486
+
487
+ return {
488
+ "sample_size": len(records),
489
+ "resolved_bugs": len(resolved),
490
+ "median_tokens_per_bug": int(_median(tokens_per_bug)),
491
+ "p90_tokens_per_bug": int(_p90(tokens_per_bug)),
492
+ "mttr_seconds": round(sum(durations) / max(1, len(durations)), 2),
493
+ "avg_cache_hit_ratio": round(sum(cache_ratios) / max(1, len(cache_ratios)), 3),
494
+ "avg_distillation_reduction_pct": round(sum(distill_pcts) / max(1, len(distill_pcts)), 2),
495
+ }
496
+