@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.
- package/.agents/rules/context-engineering.md +3 -3
- package/.agents/rules/mandatory-playwright-live.md +18 -4
- package/.agents/rules/security_testing_rules.md +8 -5
- package/.agents/rules/stack-auto-router.md +11 -4
- package/.agents/skills/{playwright-webapp-testing → 01-web-automation/playwright-webapp-testing}/SKILL.md +18 -1
- package/.agents/skills/05-security-and-compliance/wcag-audit-patterns/SKILL.md +116 -0
- package/.agents/workflows/generate_manual_testcases_rbt.md +1 -1
- package/Dockerfile +14 -6
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/agentskills.json +16 -2
- package/docs/ARCHITECTURE.en.md +1 -1
- package/docs/ARCHITECTURE.md +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skills_manifest.json +505 -394
- package/synapse.config.json +17 -1
- package/tools/__init__.py +1 -1
- package/tools/ast_cache.py +171 -0
- package/tools/author_integrity.py +7 -2
- package/tools/benchmark_swarm_context.py +242 -151
- package/tools/browser_helpers.js +2 -2
- package/tools/build_consolidated_report.py +6 -6
- package/tools/cache_resolver.py +11 -6
- package/tools/check_version_sync.py +56 -0
- package/tools/cli.py +16 -3
- package/tools/core/file_lock.py +187 -14
- package/tools/core/process_supervisor.py +25 -0
- package/tools/core/telemetry.py +139 -1
- package/tools/core/token_estimator.py +145 -0
- package/tools/count_tokens.py +28 -0
- package/tools/dashboard_generator.py +6 -6
- package/tools/debt_harvester.py +20 -9
- package/tools/diagram_architect.py +0 -1
- package/tools/distill_log.py +266 -89
- package/tools/git_pre_commit_guard.py +6 -4
- package/tools/git_worktree_manager.py +1 -1
- package/tools/infer_linter.py +2 -2
- package/tools/lint_ai_docs.py +19 -5
- package/tools/mcp_docx_server.py +1 -1
- package/tools/mcp_excel_server.py +1 -1
- package/tools/mcp_server.py +1 -1
- package/tools/mechanical_ui_gate.py +1 -1
- package/tools/micro_mutator.py +51 -10
- package/tools/pairwise_generator.py +0 -1
- package/tools/pentest_scope_guard.py +328 -0
- package/tools/perf/benchmark_perf_runner.py +226 -0
- package/tools/pinpoint_failure.py +14 -2
- package/tools/rules_router.py +596 -0
- package/tools/token_telemetry.py +224 -0
- package/tools/ui_server.py +1 -1
- package/tools/update_sentinel.py +3 -3
- package/tools/verify_all.py +67 -7
- package/tools/wcag_audit.py +1 -1
- package/tools/welcome_page.py +1 -1
- package/.agents/skills/wcag-audit-patterns/SKILL.md +0 -77
- /package/.agents/skills/{auth-session-and-cookie-manager → 01-web-automation/auth-session-and-cookie-manager}/SKILL.md +0 -0
- /package/.agents/skills/{auth-session-and-cookie-manager → 01-web-automation/auth-session-and-cookie-manager}/examples/multi_role_auth_matrix.md +0 -0
- /package/.agents/skills/{auth-session-and-cookie-manager → 01-web-automation/auth-session-and-cookie-manager}/examples/storage_state_sample.json +0 -0
- /package/.agents/skills/{bats-testing-patterns → 01-web-automation/bats-testing-patterns}/SKILL.md +0 -0
- /package/.agents/skills/{bats-testing-patterns → 01-web-automation/bats-testing-patterns}/examples/cli_runner_test.bats +0 -0
- /package/.agents/skills/{bats-testing-patterns → 01-web-automation/bats-testing-patterns}/resources/implementation-playbook.md +0 -0
- /package/.agents/skills/{clean-pom-crafter → 01-web-automation/clean-pom-crafter}/SKILL.md +0 -0
- /package/.agents/skills/{clean-pom-crafter → 01-web-automation/clean-pom-crafter}/examples/standard_test_case.groovy +0 -0
- /package/.agents/skills/{clean-pom-crafter → 01-web-automation/clean-pom-crafter}/references/pom_patterns.groovy +0 -0
- /package/.agents/skills/{e2e-testing-patterns → 01-web-automation/e2e-testing-patterns}/SKILL.md +0 -0
- /package/.agents/skills/{e2e-testing-patterns → 01-web-automation/e2e-testing-patterns}/examples/playwright_sharded_config.ts +0 -0
- /package/.agents/skills/{e2e-testing-patterns → 01-web-automation/e2e-testing-patterns}/resources/implementation-playbook.md +0 -0
- /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/SKILL.md +0 -0
- /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/examples/headless_kre_exec.sh +0 -0
- /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/references/groovy-patterns.md +0 -0
- /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/references/katalon-api.md +0 -0
- /package/.agents/skills/{katalon-cli-runner → 01-web-automation/katalon-cli-runner}/references/runner_commands.md +0 -0
- /package/.agents/skills/{lam-script-generator → 01-web-automation/lam-script-generator}/SKILL.md +0 -0
- /package/.agents/skills/{lam-script-generator → 01-web-automation/lam-script-generator}/examples/user_story_sample.md +0 -0
- /package/.agents/skills/{mobile-appium-som → 01-web-automation/mobile-appium-som}/SKILL.md +0 -0
- /package/.agents/skills/{mobile-appium-som → 01-web-automation/mobile-appium-som}/examples/BaseScreen.java +0 -0
- /package/.agents/skills/{mobile-appium-som → 01-web-automation/mobile-appium-som}/examples/LoginScreen.java +0 -0
- /package/.agents/skills/{mobile-appium-som → 01-web-automation/mobile-appium-som}/examples/TC_MobileLogin.java +0 -0
- /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/SKILL.md +0 -0
- /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/examples/live_probe_script.js +0 -0
- /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/references/advanced_superpowers.md +0 -0
- /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/references/compact_accessibility_snapshots.md +0 -0
- /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/references/recipes.md +0 -0
- /package/.agents/skills/{playwright-live-interaction → 01-web-automation/playwright-live-interaction}/references/swarm_orchestration.md +0 -0
- /package/.agents/skills/{playwright-webapp-testing → 01-web-automation/playwright-webapp-testing}/examples/server_lifecycle_playwright.py +0 -0
- /package/.agents/skills/{web-agent-gym-benchmarking → 01-web-automation/web-agent-gym-benchmarking}/SKILL.md +0 -0
- /package/.agents/skills/{web-agent-gym-benchmarking → 01-web-automation/web-agent-gym-benchmarking}/examples/benchmark_report_sample.json +0 -0
- /package/.agents/skills/{web-agent-gym-benchmarking → 01-web-automation/web-agent-gym-benchmarking}/examples/enterprise_tasks_suite.json +0 -0
- /package/.agents/skills/{architecture-decision-records → 02-test-design/architecture-decision-records}/SKILL.md +0 -0
- /package/.agents/skills/{architecture-decision-records → 02-test-design/architecture-decision-records}/examples/0001-record-architecture-decisions.md +0 -0
- /package/.agents/skills/{gherkin-to-suite → 02-test-design/gherkin-to-suite}/SKILL.md +0 -0
- /package/.agents/skills/{gherkin-to-suite → 02-test-design/gherkin-to-suite}/examples/checkout.feature +0 -0
- /package/.agents/skills/{gherkin-to-suite → 02-test-design/gherkin-to-suite}/examples/suite_report_sample.json +0 -0
- /package/.agents/skills/{rbt-manual-testing → 02-test-design/rbt-manual-testing}/SKILL.md +0 -0
- /package/.agents/skills/{rbt-manual-testing → 02-test-design/rbt-manual-testing}/examples/checkout_rbt_manual_suite.md +0 -0
- /package/.agents/skills/{rbt-manual-testing → 02-test-design/rbt-manual-testing}/references/field_validation_checklist.md +0 -0
- /package/.agents/skills/{review-spec → 02-test-design/review-spec}/SKILL.md +0 -0
- /package/.agents/skills/{review-spec → 02-test-design/review-spec}/examples/pocock_grilling_decision_rubric.md +0 -0
- /package/.agents/skills/{review-spec → 02-test-design/review-spec}/examples/sample_spec_review.md +0 -0
- /package/.agents/skills/{tot-exploratory-testing → 02-test-design/tot-exploratory-testing}/SKILL.md +0 -0
- /package/.agents/skills/{tot-exploratory-testing → 02-test-design/tot-exploratory-testing}/examples/payment_gateway_tot_tree.json +0 -0
- /package/.agents/skills/{tot-exploratory-testing → 02-test-design/tot-exploratory-testing}/examples/tot_graph_sample.json +0 -0
- /package/.agents/skills/{api-network-mocking-interception → 03-api-and-contracts/api-network-mocking-interception}/SKILL.md +0 -0
- /package/.agents/skills/{api-network-mocking-interception → 03-api-and-contracts/api-network-mocking-interception}/examples/network_route_stub.json +0 -0
- /package/.agents/skills/{api-spec-to-e2e-matrix → 03-api-and-contracts/api-spec-to-e2e-matrix}/SKILL.md +0 -0
- /package/.agents/skills/{api-spec-to-e2e-matrix → 03-api-and-contracts/api-spec-to-e2e-matrix}/examples/sample_openapi.json +0 -0
- /package/.agents/skills/{consumer-driven-contract-testing → 03-api-and-contracts/consumer-driven-contract-testing}/SKILL.md +0 -0
- /package/.agents/skills/{consumer-driven-contract-testing → 03-api-and-contracts/consumer-driven-contract-testing}/examples/order_service_pact.json +0 -0
- /package/.agents/skills/{backend-load-and-stress-patterns → 04-performance-and-load/backend-load-and-stress-patterns}/SKILL.md +0 -0
- /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
- /package/.agents/skills/{backend-load-and-stress-patterns → 04-performance-and-load/backend-load-and-stress-patterns}/references/k6_load_template.js +0 -0
- /package/.agents/skills/{lean-impact-scoreboard → 04-performance-and-load/lean-impact-scoreboard}/SKILL.md +0 -0
- /package/.agents/skills/{lean-impact-scoreboard → 04-performance-and-load/lean-impact-scoreboard}/examples/sample_benchmark_gain.md +0 -0
- /package/.agents/skills/{lean-impact-scoreboard → 04-performance-and-load/lean-impact-scoreboard}/examples/sample_scoreboard.md +0 -0
- /package/.agents/skills/{web-vitals-and-performance-profiler → 04-performance-and-load/web-vitals-and-performance-profiler}/SKILL.md +0 -0
- /package/.agents/skills/{web-vitals-and-performance-profiler → 04-performance-and-load/web-vitals-and-performance-profiler}/examples/cwv_budget_policy.json +0 -0
- /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
- /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/SKILL.md +0 -0
- /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/examples/dast_scan_config.json +0 -0
- /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/references/AI-AND-LLM.md +0 -0
- /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/references/ATTACK-CLASSES.md +0 -0
- /package/.agents/skills/{security-dast-sentinel → 05-security-and-compliance/security-dast-sentinel}/references/dast_recipes.ts +0 -0
- /package/.agents/skills/{skillspector-security-guard → 05-security-and-compliance/skillspector-security-guard}/SKILL.md +0 -0
- /package/.agents/skills/{skillspector-security-guard → 05-security-and-compliance/skillspector-security-guard}/examples/audit_threat_vectors_report.json +0 -0
- /package/.agents/skills/{skillspector-security-guard → 05-security-and-compliance/skillspector-security-guard}/examples/safe_mcp_config.json +0 -0
- /package/.agents/skills/{wcag-audit-patterns → 05-security-and-compliance/wcag-audit-patterns}/examples/wcag_compliance_checklist.json +0 -0
- /package/.agents/skills/{wcag-audit-patterns → 05-security-and-compliance/wcag-audit-patterns}/resources/implementation-playbook.md +0 -0
- /package/.agents/skills/{agentless-qa-repair → 06-healing-and-resilience/agentless-qa-repair}/SKILL.md +0 -0
- /package/.agents/skills/{agentless-qa-repair → 06-healing-and-resilience/agentless-qa-repair}/examples/healing_report_sample.json +0 -0
- /package/.agents/skills/{agentless-qa-repair → 06-healing-and-resilience/agentless-qa-repair}/examples/three_phase_repair_workflow.md +0 -0
- /package/.agents/skills/{antigravity-test-sentinel → 06-healing-and-resilience/antigravity-test-sentinel}/SKILL.md +0 -0
- /package/.agents/skills/{antigravity-test-sentinel → 06-healing-and-resilience/antigravity-test-sentinel}/examples/dod_gate_policy.json +0 -0
- /package/.agents/skills/{antigravity-test-sentinel → 06-healing-and-resilience/antigravity-test-sentinel}/examples/sprint_dod_enforcement.md +0 -0
- /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/SKILL.md +0 -0
- /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/examples/closed_loop_healing_walkthrough.md +0 -0
- /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/examples/sample_junit_failure.xml +0 -0
- /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/references/healing_matrix.md +0 -0
- /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/references/qa_investigation_protocol.md +0 -0
- /package/.agents/skills/{failure-autopsy-and-healing → 06-healing-and-resilience/failure-autopsy-and-healing}/scripts/triage_failures.sh +0 -0
- /package/.agents/skills/{flaky-test-sentinel-and-quarantine → 06-healing-and-resilience/flaky-test-sentinel-and-quarantine}/SKILL.md +0 -0
- /package/.agents/skills/{flaky-test-sentinel-and-quarantine → 06-healing-and-resilience/flaky-test-sentinel-and-quarantine}/examples/quarantine_registry.json +0 -0
- /package/.agents/skills/{self-healing-locator → 06-healing-and-resilience/self-healing-locator}/SKILL.md +0 -0
- /package/.agents/skills/{self-healing-locator → 06-healing-and-resilience/self-healing-locator}/examples/aom_diff_sample.json +0 -0
- /package/.agents/skills/{systematic-debugging → 06-healing-and-resilience/systematic-debugging}/SKILL.md +0 -0
- /package/.agents/skills/{systematic-debugging → 06-healing-and-resilience/systematic-debugging}/examples/four_phase_case.md +0 -0
- /package/.agents/skills/{test-driven-development → 06-healing-and-resilience/test-driven-development}/SKILL.md +0 -0
- /package/.agents/skills/{test-driven-development → 06-healing-and-resilience/test-driven-development}/examples/red_green_refactor_qa.md +0 -0
- /package/.agents/skills/{verification-before-completion → 06-healing-and-resilience/verification-before-completion}/SKILL.md +0 -0
- /package/.agents/skills/{verification-before-completion → 06-healing-and-resilience/verification-before-completion}/examples/evidence_log_example.md +0 -0
- /package/.agents/skills/{visual-regression-sentinel → 06-healing-and-resilience/visual-regression-sentinel}/SKILL.md +0 -0
- /package/.agents/skills/{visual-regression-sentinel → 06-healing-and-resilience/visual-regression-sentinel}/examples/visual_mask_rules.json +0 -0
- /package/.agents/skills/{db-state-verifier-and-seeder → 07-data-and-state/db-state-verifier-and-seeder}/SKILL.md +0 -0
- /package/.agents/skills/{db-state-verifier-and-seeder → 07-data-and-state/db-state-verifier-and-seeder}/examples/db_fixture_seed.json +0 -0
- /package/.agents/skills/{file-and-report-validator → 07-data-and-state/file-and-report-validator}/SKILL.md +0 -0
- /package/.agents/skills/{file-and-report-validator → 07-data-and-state/file-and-report-validator}/examples/sample_export_schema.json +0 -0
- /package/.agents/skills/{synthetic-test-data-generator → 07-data-and-state/synthetic-test-data-generator}/SKILL.md +0 -0
- /package/.agents/skills/{synthetic-test-data-generator → 07-data-and-state/synthetic-test-data-generator}/examples/idempotent_data_recipe.json +0 -0
- /package/.agents/skills/{code-refactoring-refactor-clean → 08-code-quality/code-refactoring-refactor-clean}/SKILL.md +0 -0
- /package/.agents/skills/{code-refactoring-refactor-clean → 08-code-quality/code-refactoring-refactor-clean}/examples/refactored_page_sample.groovy +0 -0
- /package/.agents/skills/{code-refactoring-refactor-clean → 08-code-quality/code-refactoring-refactor-clean}/examples/refactored_playwright_pom.ts +0 -0
- /package/.agents/skills/{code-refactoring-refactor-clean → 08-code-quality/code-refactoring-refactor-clean}/resources/implementation-playbook.md +0 -0
- /package/.agents/skills/{graphify-impact-analyzer → 08-code-quality/graphify-impact-analyzer}/SKILL.md +0 -0
- /package/.agents/skills/{graphify-impact-analyzer → 08-code-quality/graphify-impact-analyzer}/examples/dependency_blast_radius.json +0 -0
- /package/.agents/skills/{lean-code-ladder → 08-code-quality/lean-code-ladder}/SKILL.md +0 -0
- /package/.agents/skills/{lean-code-ladder → 08-code-quality/lean-code-ladder}/examples/ladder_walkthrough.md +0 -0
- /package/.agents/skills/{repo-quality-audit → 08-code-quality/repo-quality-audit}/SKILL.md +0 -0
- /package/.agents/skills/{repo-quality-audit → 08-code-quality/repo-quality-audit}/examples/sample_audit_walkthrough.md +0 -0
- /package/.agents/skills/{repo-quality-audit → 08-code-quality/repo-quality-audit}/examples/sample_repo_audit.md +0 -0
- /package/.agents/skills/{senior-code-review → 08-code-quality/senior-code-review}/SKILL.md +0 -0
- /package/.agents/skills/{senior-code-review → 08-code-quality/senior-code-review}/examples/sample_review_walkthrough.md +0 -0
- /package/.agents/skills/{surgical-coding-principles → 08-code-quality/surgical-coding-principles}/SKILL.md +0 -0
- /package/.agents/skills/{surgical-coding-principles → 08-code-quality/surgical-coding-principles}/examples/surgical_vs_scope_creep.md +0 -0
- /package/.agents/skills/{technical-debt-harvester → 08-code-quality/technical-debt-harvester}/SKILL.md +0 -0
- /package/.agents/skills/{technical-debt-harvester → 08-code-quality/technical-debt-harvester}/examples/sample_debt_ledger.md +0 -0
- /package/.agents/skills/{technical-debt-harvester → 08-code-quality/technical-debt-harvester}/examples/sample_ledger_output.md +0 -0
- /package/.agents/skills/{github-actions-templates → 09-ci-and-devops/github-actions-templates}/SKILL.md +0 -0
- /package/.agents/skills/{github-actions-templates → 09-ci-and-devops/github-actions-templates}/examples/matrix_test_pipeline.yml +0 -0
- /package/.agents/skills/{actor-qa-swarm → 10-agent-orchestration/actor-qa-swarm}/SKILL.md +0 -0
- /package/.agents/skills/{actor-qa-swarm → 10-agent-orchestration/actor-qa-swarm}/examples/broker_sharding_sample.json +0 -0
- /package/.agents/skills/{agent-orchestration-multi-agent-optimize → 10-agent-orchestration/agent-orchestration-multi-agent-optimize}/SKILL.md +0 -0
- /package/.agents/skills/{agent-orchestration-multi-agent-optimize → 10-agent-orchestration/agent-orchestration-multi-agent-optimize}/examples/swarm_workload_config.json +0 -0
- /package/.agents/skills/{event-stream-qa-orchestrator → 10-agent-orchestration/event-stream-qa-orchestrator}/SKILL.md +0 -0
- /package/.agents/skills/{event-stream-qa-orchestrator → 10-agent-orchestration/event-stream-qa-orchestrator}/examples/timeline_sample.jsonl +0 -0
- /package/.agents/skills/{persistent-planning-files → 10-agent-orchestration/persistent-planning-files}/SKILL.md +0 -0
- /package/.agents/skills/{persistent-planning-files → 10-agent-orchestration/persistent-planning-files}/examples/task_plan_example.md +0 -0
- /package/.agents/skills/{qa-memory-os → 10-agent-orchestration/qa-memory-os}/SKILL.md +0 -0
- /package/.agents/skills/{qa-memory-os → 10-agent-orchestration/qa-memory-os}/examples/archival_memory_sample.json +0 -0
- /package/.agents/skills/{meta-prompt-crafter → 11-ai-and-prompting/meta-prompt-crafter}/SKILL.md +0 -0
- /package/.agents/skills/{meta-prompt-crafter → 11-ai-and-prompting/meta-prompt-crafter}/examples/qa_prompt_template.md +0 -0
- /package/.agents/skills/{mipro-prompt-compiler → 11-ai-and-prompting/mipro-prompt-compiler}/SKILL.md +0 -0
- /package/.agents/skills/{mipro-prompt-compiler → 11-ai-and-prompting/mipro-prompt-compiler}/examples/compiled_module_sample.json +0 -0
- /package/.agents/skills/{mipro-prompt-compiler → 11-ai-and-prompting/mipro-prompt-compiler}/examples/dspy_assertion_optimizer_case.md +0 -0
- /package/.agents/skills/{qa-aci-interface → 11-ai-and-prompting/qa-aci-interface}/SKILL.md +0 -0
- /package/.agents/skills/{qa-aci-interface → 11-ai-and-prompting/qa-aci-interface}/examples/surgical_code_window_walkthrough.md +0 -0
- /package/.agents/skills/{qa-aci-interface → 11-ai-and-prompting/qa-aci-interface}/examples/surgical_edit_sample.json +0 -0
- /package/.agents/skills/{token-and-context-optimizer → 11-ai-and-prompting/token-and-context-optimizer}/SKILL.md +0 -0
- /package/.agents/skills/{token-and-context-optimizer → 11-ai-and-prompting/token-and-context-optimizer}/examples/distilled_log_sample.txt +0 -0
- /package/.agents/skills/{token-and-context-optimizer → 11-ai-and-prompting/token-and-context-optimizer}/references/context_engineering_guide.md +0 -0
|
@@ -15,6 +15,15 @@ import glob
|
|
|
15
15
|
import xml.etree.ElementTree as ET
|
|
16
16
|
import re
|
|
17
17
|
|
|
18
|
+
try:
|
|
19
|
+
from cache_resolver import compute_error_fingerprint
|
|
20
|
+
except ImportError:
|
|
21
|
+
try:
|
|
22
|
+
from tools.cache_resolver import compute_error_fingerprint
|
|
23
|
+
except ImportError:
|
|
24
|
+
def compute_error_fingerprint(t, m, a=""):
|
|
25
|
+
return f"fp_fallback_{hash((t, m, a)) & 0xffffffff:08x}"
|
|
26
|
+
|
|
18
27
|
if hasattr(sys.stdout, 'reconfigure'):
|
|
19
28
|
try:
|
|
20
29
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
@@ -144,13 +153,16 @@ def parse_failures(xml_path):
|
|
|
144
153
|
except (ValueError, TypeError):
|
|
145
154
|
formatted_time = "0.0s"
|
|
146
155
|
|
|
156
|
+
tc_short = tc_name.split("/")[-1]
|
|
157
|
+
fp = compute_error_fingerprint(tc_short, reason.split("\n")[0], f"{f_file}:{f_line}")
|
|
147
158
|
failures.append({
|
|
148
|
-
"tc":
|
|
159
|
+
"tc": tc_short,
|
|
149
160
|
"time": formatted_time,
|
|
150
161
|
"reason": reason.split("\n")[0][:180],
|
|
151
162
|
"failed_at": failed_locs[:2] if failed_locs else ["See JUnit report"],
|
|
152
163
|
"file": f_file,
|
|
153
|
-
"line": f_line
|
|
164
|
+
"line": f_line,
|
|
165
|
+
"fingerprint": fp,
|
|
154
166
|
})
|
|
155
167
|
|
|
156
168
|
return failures
|
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
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
|
+
|
|
6
|
+
"""
|
|
7
|
+
tools/rules_router.py — Progressive Rules Router & Context Optimizer (Boost B2)
|
|
8
|
+
--------------------------------------------------------------------------------
|
|
9
|
+
Dynamically inspects workspace markers (Playwright, Cypress, Katalon, Pytest-API,
|
|
10
|
+
Selenium, Appium, K6, Security, Monorepo) to route and emit ONLY the minimal
|
|
11
|
+
necessary rule files and skill subset.
|
|
12
|
+
|
|
13
|
+
Guarantees:
|
|
14
|
+
1. High-accuracy multi-stack detection (depth 2 + monorepo subpackages).
|
|
15
|
+
2. Truth Anchor confidence scoring (no fake 86% savings on unknown stacks).
|
|
16
|
+
3. Dual-tier Token Hydration reporting (Catalog Summary vs Full Body Hydration).
|
|
17
|
+
4. Byte retrieval vs Prompt token distinction.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import argparse
|
|
23
|
+
import json
|
|
24
|
+
import os
|
|
25
|
+
import sys
|
|
26
|
+
from typing import Any, Dict, List, Optional, Set, Tuple
|
|
27
|
+
|
|
28
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
29
|
+
try:
|
|
30
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
31
|
+
sys.stderr.reconfigure(encoding="utf-8")
|
|
32
|
+
except Exception:
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
# Import core token estimator with graceful fallback
|
|
36
|
+
try:
|
|
37
|
+
from tools.core.token_estimator import count_file_tokens, count_tokens, calculate_hydration_payload
|
|
38
|
+
except ImportError:
|
|
39
|
+
try:
|
|
40
|
+
from core.token_estimator import count_file_tokens, count_tokens, calculate_hydration_payload
|
|
41
|
+
except ImportError:
|
|
42
|
+
def count_tokens(text: str, model_hint: str = "cl100k") -> int:
|
|
43
|
+
return max(1, len(text) // 4)
|
|
44
|
+
|
|
45
|
+
def count_file_tokens(path: str) -> int:
|
|
46
|
+
if not os.path.isfile(path):
|
|
47
|
+
return 0
|
|
48
|
+
return max(1, os.path.getsize(path) // 4)
|
|
49
|
+
|
|
50
|
+
def calculate_hydration_payload(repo_root: str, rules: List[str], skills: List[str]) -> Dict[str, Any]:
|
|
51
|
+
r_tokens = len(rules) * 500
|
|
52
|
+
s_cat = len(skills) * 120
|
|
53
|
+
s_full = len(skills) * 1800
|
|
54
|
+
return {
|
|
55
|
+
"rule_tokens": r_tokens,
|
|
56
|
+
"rule_bytes": r_tokens * 4,
|
|
57
|
+
"skill_catalog_tokens": s_cat,
|
|
58
|
+
"skill_full_body_tokens": s_full,
|
|
59
|
+
"skill_full_bytes": s_full * 4,
|
|
60
|
+
"total_summary_tokens": r_tokens + s_cat,
|
|
61
|
+
"total_hydrated_tokens": r_tokens + s_full,
|
|
62
|
+
"total_hydrated_bytes": (r_tokens + s_full) * 4,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# Base rules always recommended (Attribution guard, communication style, precedence)
|
|
66
|
+
CORE_BASE_RULES = [
|
|
67
|
+
"author-integrity-guard.md",
|
|
68
|
+
"communication-style.md",
|
|
69
|
+
"skill-precedence.md",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
# Stack-to-Rule mappings
|
|
73
|
+
STACK_RULE_MAPPINGS = {
|
|
74
|
+
"playwright": ["mandatory-playwright-live.md", "systematic-debugging.md"],
|
|
75
|
+
"cypress": ["systematic-debugging.md"],
|
|
76
|
+
"mobile": ["mobile_appium_rules.md", "systematic-debugging.md"],
|
|
77
|
+
"katalon": ["systematic-debugging.md"],
|
|
78
|
+
"selenium": ["systematic-debugging.md"],
|
|
79
|
+
"performance": ["performance_testing_rules.md"],
|
|
80
|
+
"security": ["security_testing_rules.md"],
|
|
81
|
+
"api": ["systematic-debugging.md"],
|
|
82
|
+
"git": ["git-push-protocol.md"],
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
# Stack-to-Skill mappings (scoped down to essential skills per domain)
|
|
86
|
+
STACK_SKILL_MAPPINGS = {
|
|
87
|
+
"playwright": [
|
|
88
|
+
"playwright-webapp-testing",
|
|
89
|
+
"playwright-live-interaction",
|
|
90
|
+
"clean-pom-crafter",
|
|
91
|
+
"api-network-mocking-interception",
|
|
92
|
+
"self-healing-locator",
|
|
93
|
+
],
|
|
94
|
+
"cypress": [
|
|
95
|
+
"clean-pom-crafter",
|
|
96
|
+
"api-network-mocking-interception",
|
|
97
|
+
"self-healing-locator",
|
|
98
|
+
],
|
|
99
|
+
"mobile": [
|
|
100
|
+
"mobile-appium-som",
|
|
101
|
+
"clean-pom-crafter",
|
|
102
|
+
],
|
|
103
|
+
"katalon": [
|
|
104
|
+
"clean-pom-crafter",
|
|
105
|
+
"failure-autopsy-and-healing",
|
|
106
|
+
"verification-before-completion",
|
|
107
|
+
],
|
|
108
|
+
"selenium": [
|
|
109
|
+
"clean-pom-crafter",
|
|
110
|
+
"self-healing-locator",
|
|
111
|
+
"verification-before-completion",
|
|
112
|
+
],
|
|
113
|
+
"performance": [
|
|
114
|
+
"backend-load-and-stress-patterns",
|
|
115
|
+
],
|
|
116
|
+
"security": [
|
|
117
|
+
"security-dast-sentinel",
|
|
118
|
+
"skillspector-security-guard",
|
|
119
|
+
],
|
|
120
|
+
"api": [
|
|
121
|
+
"api-spec-to-e2e-matrix",
|
|
122
|
+
"consumer-driven-contract-testing",
|
|
123
|
+
"api-network-mocking-interception",
|
|
124
|
+
],
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
DEFAULT_CORE_SKILLS = [
|
|
128
|
+
"clean-pom-crafter",
|
|
129
|
+
"verification-before-completion",
|
|
130
|
+
"systematic-debugging",
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _find_repo_root() -> str:
|
|
135
|
+
"""Finds the root of Synapse-Hub repository."""
|
|
136
|
+
curr = os.path.abspath(os.path.dirname(__file__))
|
|
137
|
+
while curr != os.path.dirname(curr):
|
|
138
|
+
if os.path.exists(os.path.join(curr, "AGENTS.md")) and os.path.exists(os.path.join(curr, ".agents")):
|
|
139
|
+
return curr
|
|
140
|
+
curr = os.path.dirname(curr)
|
|
141
|
+
return os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _scan_directory_markers(target_dir: str, prefix: str = "") -> Tuple[Dict[str, List[str]], Dict[str, float]]:
|
|
145
|
+
"""Scans a single directory level up to depth 2 for testing markers."""
|
|
146
|
+
detected: Dict[str, List[str]] = {
|
|
147
|
+
"playwright": [],
|
|
148
|
+
"cypress": [],
|
|
149
|
+
"mobile": [],
|
|
150
|
+
"katalon": [],
|
|
151
|
+
"selenium": [],
|
|
152
|
+
"performance": [],
|
|
153
|
+
"security": [],
|
|
154
|
+
"api": [],
|
|
155
|
+
"git": [],
|
|
156
|
+
}
|
|
157
|
+
confidence: Dict[str, float] = {k: 0.0 for k in detected}
|
|
158
|
+
|
|
159
|
+
if not os.path.isdir(target_dir):
|
|
160
|
+
return detected, confidence
|
|
161
|
+
|
|
162
|
+
# Git marker
|
|
163
|
+
if os.path.isdir(os.path.join(target_dir, ".git")):
|
|
164
|
+
ev = f"{prefix}.git directory" if prefix else ".git directory"
|
|
165
|
+
detected["git"].append(ev)
|
|
166
|
+
confidence["git"] = max(confidence["git"], 1.0)
|
|
167
|
+
|
|
168
|
+
# 1. Inspect package.json
|
|
169
|
+
pkg_json = os.path.join(target_dir, "package.json")
|
|
170
|
+
if os.path.isfile(pkg_json):
|
|
171
|
+
try:
|
|
172
|
+
with open(pkg_json, "r", encoding="utf-8", errors="ignore") as f:
|
|
173
|
+
content = f.read().lower()
|
|
174
|
+
if "playwright" in content or "@playwright/test" in content:
|
|
175
|
+
detected["playwright"].append(f"{prefix}package.json (playwright)")
|
|
176
|
+
confidence["playwright"] = max(confidence["playwright"], 0.90)
|
|
177
|
+
if "cypress" in content:
|
|
178
|
+
detected["cypress"].append(f"{prefix}package.json (cypress)")
|
|
179
|
+
confidence["cypress"] = max(confidence["cypress"], 0.90)
|
|
180
|
+
if "appium" in content:
|
|
181
|
+
detected["mobile"].append(f"{prefix}package.json (appium)")
|
|
182
|
+
confidence["mobile"] = max(confidence["mobile"], 0.90)
|
|
183
|
+
if "selenium-webdriver" in content or "webdriverio" in content or "@wdio/" in content:
|
|
184
|
+
detected["selenium"].append(f"{prefix}package.json (selenium/wdio)")
|
|
185
|
+
confidence["selenium"] = max(confidence["selenium"], 0.90)
|
|
186
|
+
if "supertest" in content or "axios" in content or "pact" in content:
|
|
187
|
+
detected["api"].append(f"{prefix}package.json (api/contract)")
|
|
188
|
+
confidence["api"] = max(confidence["api"], 0.70)
|
|
189
|
+
if "k6" in content or "artillery" in content:
|
|
190
|
+
detected["performance"].append(f"{prefix}package.json (perf)")
|
|
191
|
+
confidence["performance"] = max(confidence["performance"], 0.90)
|
|
192
|
+
except Exception as err:
|
|
193
|
+
_ = err
|
|
194
|
+
|
|
195
|
+
# 2. Inspect Python requirements / pyproject / Pipfile
|
|
196
|
+
for py_cfg_name in ("requirements.txt", "requirements-dev.txt", "pyproject.toml", "Pipfile", "setup.py"):
|
|
197
|
+
py_cfg = os.path.join(target_dir, py_cfg_name)
|
|
198
|
+
if os.path.isfile(py_cfg):
|
|
199
|
+
try:
|
|
200
|
+
with open(py_cfg, "r", encoding="utf-8", errors="ignore") as f:
|
|
201
|
+
content = f.read().lower()
|
|
202
|
+
if "pytest-playwright" in content or "playwright" in content:
|
|
203
|
+
detected["playwright"].append(f"{prefix}{py_cfg_name} (playwright)")
|
|
204
|
+
confidence["playwright"] = max(confidence["playwright"], 0.90)
|
|
205
|
+
if "selenium" in content or "pytest-selenium" in content:
|
|
206
|
+
detected["selenium"].append(f"{prefix}{py_cfg_name} (selenium)")
|
|
207
|
+
confidence["selenium"] = max(confidence["selenium"], 0.90)
|
|
208
|
+
if "appium" in content:
|
|
209
|
+
detected["mobile"].append(f"{prefix}{py_cfg_name} (appium)")
|
|
210
|
+
confidence["mobile"] = max(confidence["mobile"], 0.90)
|
|
211
|
+
if any(pkg in content for pkg in ("requests", "httpx", "aiohttp", "fastapi", "pact-python")):
|
|
212
|
+
detected["api"].append(f"{prefix}{py_cfg_name} (api clients)")
|
|
213
|
+
confidence["api"] = max(confidence["api"], 0.80)
|
|
214
|
+
if "locust" in content or "k6" in content:
|
|
215
|
+
detected["performance"].append(f"{prefix}{py_cfg_name} (perf)")
|
|
216
|
+
confidence["performance"] = max(confidence["performance"], 0.85)
|
|
217
|
+
if "bandit" in content or "semgrep" in content:
|
|
218
|
+
detected["security"].append(f"{prefix}{py_cfg_name} (security)")
|
|
219
|
+
confidence["security"] = max(confidence["security"], 0.80)
|
|
220
|
+
except Exception as err:
|
|
221
|
+
_ = err
|
|
222
|
+
|
|
223
|
+
# 3. Inspect JVM build markers (build.gradle, pom.xml)
|
|
224
|
+
for jvm_cfg_name in ("build.gradle", "build.gradle.kts", "pom.xml"):
|
|
225
|
+
jvm_cfg = os.path.join(target_dir, jvm_cfg_name)
|
|
226
|
+
if os.path.isfile(jvm_cfg):
|
|
227
|
+
try:
|
|
228
|
+
with open(jvm_cfg, "r", encoding="utf-8", errors="ignore") as f:
|
|
229
|
+
content = f.read().lower()
|
|
230
|
+
if "playwright" in content:
|
|
231
|
+
detected["playwright"].append(f"{prefix}{jvm_cfg_name} (playwright)")
|
|
232
|
+
confidence["playwright"] = max(confidence["playwright"], 0.90)
|
|
233
|
+
if "selenium" in content:
|
|
234
|
+
detected["selenium"].append(f"{prefix}{jvm_cfg_name} (selenium)")
|
|
235
|
+
confidence["selenium"] = max(confidence["selenium"], 0.90)
|
|
236
|
+
if "appium" in content:
|
|
237
|
+
detected["mobile"].append(f"{prefix}{jvm_cfg_name} (appium)")
|
|
238
|
+
confidence["mobile"] = max(confidence["mobile"], 0.90)
|
|
239
|
+
if "rest-assured" in content or "pact" in content:
|
|
240
|
+
detected["api"].append(f"{prefix}{jvm_cfg_name} (api)")
|
|
241
|
+
confidence["api"] = max(confidence["api"], 0.85)
|
|
242
|
+
if "jmeter" in content or "gatling" in content:
|
|
243
|
+
detected["performance"].append(f"{prefix}{jvm_cfg_name} (perf)")
|
|
244
|
+
confidence["performance"] = max(confidence["performance"], 0.85)
|
|
245
|
+
except Exception as err:
|
|
246
|
+
_ = err
|
|
247
|
+
|
|
248
|
+
# 4. Walk directory structure up to depth 2
|
|
249
|
+
ignored = {".git", "node_modules", ".venv", "venv", "__pycache__", "dist", "build", "target", ".gradle"}
|
|
250
|
+
for root, dirs, files in os.walk(target_dir):
|
|
251
|
+
rel = os.path.relpath(root, target_dir)
|
|
252
|
+
depth = 0 if rel == "." else len(rel.split(os.sep))
|
|
253
|
+
if depth >= 2:
|
|
254
|
+
dirs.clear()
|
|
255
|
+
continue
|
|
256
|
+
dirs[:] = [d for d in dirs if d not in ignored]
|
|
257
|
+
|
|
258
|
+
for file_name in files:
|
|
259
|
+
f_lower = file_name.lower()
|
|
260
|
+
rel_file = os.path.join(rel, file_name) if rel != "." else file_name
|
|
261
|
+
full_evidence_path = f"{prefix}{rel_file}" if prefix else rel_file
|
|
262
|
+
|
|
263
|
+
# Katalon markers
|
|
264
|
+
if f_lower.endswith(".prj") or f_lower == "katalon_suite.prj":
|
|
265
|
+
detected["katalon"].append(full_evidence_path)
|
|
266
|
+
confidence["katalon"] = max(confidence["katalon"], 1.0)
|
|
267
|
+
|
|
268
|
+
# Playwright markers
|
|
269
|
+
if f_lower.startswith("playwright.config."):
|
|
270
|
+
detected["playwright"].append(full_evidence_path)
|
|
271
|
+
confidence["playwright"] = max(confidence["playwright"], 1.0)
|
|
272
|
+
|
|
273
|
+
# Cypress markers
|
|
274
|
+
if f_lower.startswith("cypress.config.") or f_lower == "cypress.json":
|
|
275
|
+
detected["cypress"].append(full_evidence_path)
|
|
276
|
+
confidence["cypress"] = max(confidence["cypress"], 1.0)
|
|
277
|
+
|
|
278
|
+
# Selenium markers
|
|
279
|
+
if f_lower.startswith("wdio.conf.") or f_lower in ("selenium.json", "pytest.ini"):
|
|
280
|
+
# If pytest.ini, inspect content for selenium
|
|
281
|
+
if f_lower == "pytest.ini":
|
|
282
|
+
try:
|
|
283
|
+
with open(os.path.join(root, file_name), "r", encoding="utf-8", errors="ignore") as pf:
|
|
284
|
+
if "selenium" in pf.read().lower():
|
|
285
|
+
detected["selenium"].append(full_evidence_path)
|
|
286
|
+
confidence["selenium"] = max(confidence["selenium"], 0.80)
|
|
287
|
+
except Exception as err:
|
|
288
|
+
_ = err
|
|
289
|
+
else:
|
|
290
|
+
detected["selenium"].append(full_evidence_path)
|
|
291
|
+
confidence["selenium"] = max(confidence["selenium"], 0.95)
|
|
292
|
+
|
|
293
|
+
# Mobile markers
|
|
294
|
+
if f_lower in ("caps.json", "androidmanifest.xml") or f_lower.endswith(".xcodeproj"):
|
|
295
|
+
detected["mobile"].append(full_evidence_path)
|
|
296
|
+
confidence["mobile"] = max(confidence["mobile"], 0.95)
|
|
297
|
+
|
|
298
|
+
# Performance markers
|
|
299
|
+
if f_lower.endswith(".jmx") or f_lower == "locustfile.py" or ".k6." in f_lower or f_lower == "k6.js":
|
|
300
|
+
detected["performance"].append(full_evidence_path)
|
|
301
|
+
confidence["performance"] = max(confidence["performance"], 1.0)
|
|
302
|
+
|
|
303
|
+
# Security markers
|
|
304
|
+
if any(k in f_lower for k in ("zap", "burp", "nuclei", "semgrep.yml")):
|
|
305
|
+
detected["security"].append(full_evidence_path)
|
|
306
|
+
confidence["security"] = max(confidence["security"], 0.90)
|
|
307
|
+
|
|
308
|
+
# API markers
|
|
309
|
+
if f_lower in ("openapi.json", "openapi.yaml", "swagger.json", "swagger.yaml") or f_lower.endswith(".pact.json"):
|
|
310
|
+
detected["api"].append(full_evidence_path)
|
|
311
|
+
confidence["api"] = max(confidence["api"], 1.0)
|
|
312
|
+
|
|
313
|
+
# conftest.py check for api / selenium fixtures
|
|
314
|
+
if f_lower == "conftest.py":
|
|
315
|
+
try:
|
|
316
|
+
with open(os.path.join(root, file_name), "r", encoding="utf-8", errors="ignore") as cf:
|
|
317
|
+
ct = cf.read().lower()
|
|
318
|
+
if "requests" in ct or "client" in ct or "base_url" in ct or "api" in ct:
|
|
319
|
+
detected["api"].append(full_evidence_path)
|
|
320
|
+
confidence["api"] = max(confidence["api"], 0.75)
|
|
321
|
+
if "selenium" in ct or "webdriver" in ct:
|
|
322
|
+
detected["selenium"].append(full_evidence_path)
|
|
323
|
+
confidence["selenium"] = max(confidence["selenium"], 0.80)
|
|
324
|
+
except Exception as err:
|
|
325
|
+
_ = err
|
|
326
|
+
|
|
327
|
+
# Directory-level markers (Katalon Keywords/Profiles)
|
|
328
|
+
for d in dirs:
|
|
329
|
+
if d.lower() in ("keywords", "profiles", "object repository"):
|
|
330
|
+
detected["katalon"].append(f"{prefix}{os.path.join(rel, d) if rel != '.' else d}/")
|
|
331
|
+
confidence["katalon"] = max(confidence["katalon"], 0.85)
|
|
332
|
+
|
|
333
|
+
return detected, confidence
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def detect_workspace_stacks(workspace_dir: str) -> Dict[str, Any]:
|
|
337
|
+
"""
|
|
338
|
+
Inspects target workspace directory, supporting standalone projects and Monorepos.
|
|
339
|
+
Calculates confidence scores for detected testing stacks.
|
|
340
|
+
"""
|
|
341
|
+
workspace = os.path.abspath(workspace_dir)
|
|
342
|
+
detected, confidence = _scan_directory_markers(workspace)
|
|
343
|
+
|
|
344
|
+
# Monorepo check at root
|
|
345
|
+
monorepo_markers = ["pnpm-workspace.yaml", "lerna.json", "nx.json", "turbo.json"]
|
|
346
|
+
is_monorepo = any(os.path.isfile(os.path.join(workspace, m)) for m in monorepo_markers)
|
|
347
|
+
|
|
348
|
+
if not is_monorepo:
|
|
349
|
+
# Check settings.gradle for multi-project include
|
|
350
|
+
sg = os.path.join(workspace, "settings.gradle")
|
|
351
|
+
if os.path.isfile(sg):
|
|
352
|
+
try:
|
|
353
|
+
with open(sg, "r", encoding="utf-8", errors="ignore") as f:
|
|
354
|
+
if "include" in f.read().lower():
|
|
355
|
+
is_monorepo = True
|
|
356
|
+
except Exception as err:
|
|
357
|
+
_ = err
|
|
358
|
+
|
|
359
|
+
if is_monorepo:
|
|
360
|
+
# Traverse subpackages in packages/, apps/, services/, modules/
|
|
361
|
+
for sub_parent in ("packages", "apps", "services", "modules"):
|
|
362
|
+
parent_dir = os.path.join(workspace, sub_parent)
|
|
363
|
+
if os.path.isdir(parent_dir):
|
|
364
|
+
try:
|
|
365
|
+
for child in os.listdir(parent_dir):
|
|
366
|
+
child_dir = os.path.join(parent_dir, child)
|
|
367
|
+
if os.path.isdir(child_dir) and not child.startswith("."):
|
|
368
|
+
prefix = f"[{sub_parent}/{child}] "
|
|
369
|
+
sub_det, sub_conf = _scan_directory_markers(child_dir, prefix=prefix)
|
|
370
|
+
for stack, evs in sub_det.items():
|
|
371
|
+
detected[stack].extend(evs)
|
|
372
|
+
confidence[stack] = max(confidence[stack], sub_conf[stack])
|
|
373
|
+
except OSError as err:
|
|
374
|
+
_ = err
|
|
375
|
+
|
|
376
|
+
# Filter active stacks where confidence >= 0.50
|
|
377
|
+
active_stacks = [s for s, evs in detected.items() if evs and confidence[s] >= 0.50]
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
"detected_stacks": active_stacks,
|
|
381
|
+
"is_monorepo": is_monorepo,
|
|
382
|
+
"confidence": {k: round(confidence[k], 2) for k in active_stacks},
|
|
383
|
+
"evidence": {k: detected[k] for k in active_stacks},
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def route_rules(workspace_dir: str = ".") -> Dict[str, Any]:
|
|
388
|
+
"""
|
|
389
|
+
Determines minimal rules and skills for target workspace, with dual-tier token hydration
|
|
390
|
+
accounting and strict truth-anchoring for unknown stacks.
|
|
391
|
+
"""
|
|
392
|
+
repo_root = _find_repo_root()
|
|
393
|
+
stack_info = detect_workspace_stacks(workspace_dir)
|
|
394
|
+
active_stacks = stack_info["detected_stacks"]
|
|
395
|
+
|
|
396
|
+
is_unknown_stack = len(active_stacks) == 0
|
|
397
|
+
|
|
398
|
+
# Compile rules
|
|
399
|
+
rules_set: Set[str] = set(CORE_BASE_RULES)
|
|
400
|
+
for stack in active_stacks:
|
|
401
|
+
for r in STACK_RULE_MAPPINGS.get(stack, []):
|
|
402
|
+
rules_set.add(r)
|
|
403
|
+
|
|
404
|
+
# Compile skills
|
|
405
|
+
skills_set: Set[str] = set(DEFAULT_CORE_SKILLS)
|
|
406
|
+
for stack in active_stacks:
|
|
407
|
+
for s in STACK_SKILL_MAPPINGS.get(stack, []):
|
|
408
|
+
skills_set.add(s)
|
|
409
|
+
|
|
410
|
+
# Resolve rules directory
|
|
411
|
+
rules_dir = os.path.join(repo_root, ".agents", "rules")
|
|
412
|
+
valid_rules = sorted(rules_set)
|
|
413
|
+
valid_skills = sorted(skills_set)
|
|
414
|
+
|
|
415
|
+
# Calculate dual-tier hydration payloads
|
|
416
|
+
routed_payload = calculate_hydration_payload(repo_root, valid_rules, valid_skills)
|
|
417
|
+
|
|
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)
|
|
436
|
+
|
|
437
|
+
# If workspace is unclassified (no stack detected), report honest fallback metrics
|
|
438
|
+
if is_unknown_stack:
|
|
439
|
+
return {
|
|
440
|
+
"workspace": os.path.abspath(workspace_dir),
|
|
441
|
+
"status": "UNCLASSIFIED_WORKSPACE",
|
|
442
|
+
"detected_stacks": ["unknown"],
|
|
443
|
+
"classification": "UNCLASSIFIED_WORKSPACE (Fallback Core Base Rules)",
|
|
444
|
+
"confidence_score": 0.0,
|
|
445
|
+
"evidence": {},
|
|
446
|
+
"recommended_rules": valid_rules,
|
|
447
|
+
"recommended_skills": valid_skills,
|
|
448
|
+
"token_metrics": {
|
|
449
|
+
"unrouted_baseline_tokens": unrouted_summary_baseline,
|
|
450
|
+
"routed_tokens": routed_payload["total_summary_tokens"],
|
|
451
|
+
"tokens_saved": 0,
|
|
452
|
+
"reduction_percentage": 0.0,
|
|
453
|
+
"note": "Stack unclassified; routed to core base profile without claiming workload-specific token reduction.",
|
|
454
|
+
},
|
|
455
|
+
"hydration_contracts": {
|
|
456
|
+
"catalog_summary": {
|
|
457
|
+
"baseline_tokens": unrouted_summary_baseline,
|
|
458
|
+
"routed_tokens": routed_payload["total_summary_tokens"],
|
|
459
|
+
"tokens_saved": 0,
|
|
460
|
+
"reduction_pct": 0.0,
|
|
461
|
+
},
|
|
462
|
+
"full_hydration": {
|
|
463
|
+
"baseline_tokens": unrouted_full_baseline,
|
|
464
|
+
"routed_tokens": routed_payload["total_hydrated_tokens"],
|
|
465
|
+
"tokens_saved": 0,
|
|
466
|
+
"reduction_pct": 0.0,
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
# Classified stacks: compute honest savings for both tiers
|
|
472
|
+
summary_saved = max(0, unrouted_summary_baseline - routed_payload["total_summary_tokens"])
|
|
473
|
+
summary_pct = round((summary_saved / max(1, unrouted_summary_baseline)) * 100, 1)
|
|
474
|
+
|
|
475
|
+
hydrated_saved = max(0, unrouted_full_baseline - routed_payload["total_hydrated_tokens"])
|
|
476
|
+
hydrated_pct = round((hydrated_saved / max(1, unrouted_full_baseline)) * 100, 1)
|
|
477
|
+
|
|
478
|
+
avg_conf = sum(stack_info["confidence"].values()) / max(1, len(stack_info["confidence"]))
|
|
479
|
+
|
|
480
|
+
return {
|
|
481
|
+
"workspace": os.path.abspath(workspace_dir),
|
|
482
|
+
"status": "CLASSIFIED",
|
|
483
|
+
"detected_stacks": active_stacks,
|
|
484
|
+
"classification": f"CLASSIFIED ({', '.join(active_stacks)})",
|
|
485
|
+
"confidence_score": round(avg_conf, 2),
|
|
486
|
+
"evidence": stack_info["evidence"],
|
|
487
|
+
"recommended_rules": valid_rules,
|
|
488
|
+
"recommended_skills": valid_skills,
|
|
489
|
+
"token_metrics": {
|
|
490
|
+
"unrouted_baseline_tokens": unrouted_summary_baseline,
|
|
491
|
+
"routed_tokens": routed_payload["total_summary_tokens"],
|
|
492
|
+
"tokens_saved": summary_saved,
|
|
493
|
+
"reduction_percentage": summary_pct,
|
|
494
|
+
},
|
|
495
|
+
"hydration_contracts": {
|
|
496
|
+
"catalog_summary": {
|
|
497
|
+
"baseline_tokens": unrouted_summary_baseline,
|
|
498
|
+
"routed_tokens": routed_payload["total_summary_tokens"],
|
|
499
|
+
"tokens_saved": summary_saved,
|
|
500
|
+
"reduction_pct": summary_pct,
|
|
501
|
+
"scope": "Skill registry metadata for Front-Door Orchestrator",
|
|
502
|
+
},
|
|
503
|
+
"full_hydration": {
|
|
504
|
+
"baseline_tokens": unrouted_full_baseline,
|
|
505
|
+
"routed_tokens": routed_payload["total_hydrated_tokens"],
|
|
506
|
+
"tokens_saved": hydrated_saved,
|
|
507
|
+
"reduction_pct": hydrated_pct,
|
|
508
|
+
"scope": "Complete SKILL.md bodies injected into Specialized Subagents",
|
|
509
|
+
},
|
|
510
|
+
"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"]),
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def format_routing_report(result: Dict[str, Any], fmt: str = "text") -> str:
|
|
519
|
+
"""Formats the routing outcome into human-readable text or JSON."""
|
|
520
|
+
if fmt == "json":
|
|
521
|
+
return json.dumps(result, indent=2, ensure_ascii=False)
|
|
522
|
+
|
|
523
|
+
metrics = result["token_metrics"]
|
|
524
|
+
stacks_str = ", ".join(result["detected_stacks"]) if result["detected_stacks"] else "unknown"
|
|
525
|
+
conf = result.get("confidence_score", 0.0)
|
|
526
|
+
|
|
527
|
+
lines = [
|
|
528
|
+
"╔══════════════════════════════════════════════════════════════════╗",
|
|
529
|
+
"║ SYNAPSE HUB — PROGRESSIVE RULES ROUTER (BOOST B2) ║",
|
|
530
|
+
"╚══════════════════════════════════════════════════════════════════╝",
|
|
531
|
+
f"Target Workspace: {result['workspace']}",
|
|
532
|
+
f"Active Stacks : {stacks_str} (Confidence: {conf})",
|
|
533
|
+
f"Status : {result['status']}",
|
|
534
|
+
"",
|
|
535
|
+
"─── Minimal Recommended Rules ───",
|
|
536
|
+
]
|
|
537
|
+
for r in result["recommended_rules"]:
|
|
538
|
+
lines.append(f" ✓ .agents/rules/{r}")
|
|
539
|
+
|
|
540
|
+
lines.append("")
|
|
541
|
+
lines.append("─── Minimal Recommended Skills ───")
|
|
542
|
+
for s in result["recommended_skills"]:
|
|
543
|
+
lines.append(f" ⚡ {s}")
|
|
544
|
+
|
|
545
|
+
lines.append("")
|
|
546
|
+
lines.append("─── Dual-Tier Token Optimization Metrics ───")
|
|
547
|
+
if "hydration_contracts" in result:
|
|
548
|
+
cat = result["hydration_contracts"]["catalog_summary"]
|
|
549
|
+
hyd = result["hydration_contracts"]["full_hydration"]
|
|
550
|
+
lines.append(f" [Tier 1 - Catalog Summary] Baseline: {cat['baseline_tokens']:,} | Routed: {cat['routed_tokens']:,} | Saved: {cat['tokens_saved']:,} ({cat['reduction_pct']}%)")
|
|
551
|
+
lines.append(f" [Tier 2 - Full Hydration ] Baseline: {hyd['baseline_tokens']:,} | Routed: {hyd['routed_tokens']:,} | Saved: {hyd['tokens_saved']:,} ({hyd['reduction_pct']}%)")
|
|
552
|
+
else:
|
|
553
|
+
lines.append(f" Unrouted Baseline : {metrics['unrouted_baseline_tokens']:,} tokens")
|
|
554
|
+
lines.append(f" Progressive Routed: {metrics['routed_tokens']:,} tokens")
|
|
555
|
+
lines.append(f" Tokens Saved/Turn : {metrics['tokens_saved']:,} tokens ({metrics['reduction_percentage']}%)")
|
|
556
|
+
lines.append("════════════════════════════════════════════════════════════════════")
|
|
557
|
+
|
|
558
|
+
return "\n".join(lines)
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def main():
|
|
562
|
+
parser = argparse.ArgumentParser(
|
|
563
|
+
description="Progressive Rules Router & Context Optimizer (Boost B2)"
|
|
564
|
+
)
|
|
565
|
+
parser.add_argument(
|
|
566
|
+
"workspace",
|
|
567
|
+
nargs="?",
|
|
568
|
+
default=".",
|
|
569
|
+
help="Target workspace directory to inspect (default: .)",
|
|
570
|
+
)
|
|
571
|
+
parser.add_argument(
|
|
572
|
+
"--json",
|
|
573
|
+
action="store_true",
|
|
574
|
+
help="Output raw JSON data instead of text format",
|
|
575
|
+
)
|
|
576
|
+
parser.add_argument(
|
|
577
|
+
"--summary",
|
|
578
|
+
action="store_true",
|
|
579
|
+
help="Print single-line summary of routed rules and tokens saved",
|
|
580
|
+
)
|
|
581
|
+
args = parser.parse_args()
|
|
582
|
+
|
|
583
|
+
result = route_rules(args.workspace)
|
|
584
|
+
|
|
585
|
+
if args.json:
|
|
586
|
+
print(format_routing_report(result, fmt="json"))
|
|
587
|
+
elif args.summary:
|
|
588
|
+
m = result["token_metrics"]
|
|
589
|
+
stacks = ",".join(result["detected_stacks"]) or "base"
|
|
590
|
+
print(f"[RULES-ROUTER] Stacks: {stacks} | Rules: {len(result['recommended_rules'])} | Saved: {m['tokens_saved']:,} tokens/turn ({m['reduction_percentage']}%)")
|
|
591
|
+
else:
|
|
592
|
+
print(format_routing_report(result, fmt="text"))
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
if __name__ == "__main__":
|
|
596
|
+
main()
|