@teevee98/synapse-hub 4.1.4 → 4.2.1
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/git-push-protocol.md +2 -2
- package/.agents/skills/01-web-automation/auth-session-and-cookie-manager/SKILL.md +52 -3
- package/.agents/skills/01-web-automation/bats-testing-patterns/SKILL.md +55 -5
- package/.agents/skills/01-web-automation/clean-pom-crafter/SKILL.md +62 -67
- package/.agents/skills/01-web-automation/e2e-testing-patterns/SKILL.md +54 -4
- package/.agents/skills/01-web-automation/katalon-cli-runner/SKILL.md +62 -12
- package/.agents/skills/01-web-automation/lam-script-generator/SKILL.md +55 -8
- package/.agents/skills/01-web-automation/mobile-appium-som/SKILL.md +60 -12
- package/.agents/skills/01-web-automation/mobile-appium-som/examples/BaseScreen.java +2 -2
- package/.agents/skills/01-web-automation/mobile-appium-som/examples/LoginScreen.java +2 -2
- package/.agents/skills/01-web-automation/mobile-appium-som/examples/TC_MobileLogin.java +2 -2
- package/.agents/skills/01-web-automation/playwright-live-interaction/SKILL.md +54 -91
- package/.agents/skills/01-web-automation/playwright-webapp-testing/SKILL.md +59 -11
- package/.agents/skills/01-web-automation/web-agent-gym-benchmarking/SKILL.md +50 -4
- package/.agents/skills/02-test-design/architecture-decision-records/SKILL.md +55 -9
- package/.agents/skills/02-test-design/gherkin-to-suite/SKILL.md +55 -9
- package/.agents/skills/02-test-design/rbt-manual-testing/SKILL.md +55 -8
- package/.agents/skills/02-test-design/review-spec/SKILL.md +50 -6
- package/.agents/skills/02-test-design/tot-exploratory-testing/SKILL.md +50 -4
- package/.agents/skills/03-api-and-contracts/api-network-mocking-interception/SKILL.md +56 -5
- package/.agents/skills/03-api-and-contracts/api-spec-to-e2e-matrix/SKILL.md +53 -7
- package/.agents/skills/03-api-and-contracts/consumer-driven-contract-testing/SKILL.md +86 -36
- package/.agents/skills/04-performance-and-load/backend-load-and-stress-patterns/SKILL.md +54 -6
- package/.agents/skills/04-performance-and-load/lean-impact-scoreboard/SKILL.md +50 -6
- package/.agents/skills/04-performance-and-load/web-vitals-and-performance-profiler/SKILL.md +50 -3
- package/.agents/skills/05-security-and-compliance/security-dast-sentinel/SKILL.md +63 -14
- package/.agents/skills/05-security-and-compliance/skillspector-security-guard/SKILL.md +51 -5
- package/.agents/skills/05-security-and-compliance/wcag-audit-patterns/SKILL.md +54 -4
- package/.agents/skills/06-healing-and-resilience/agentless-qa-repair/SKILL.md +51 -5
- package/.agents/skills/06-healing-and-resilience/antigravity-test-sentinel/SKILL.md +53 -6
- package/.agents/skills/06-healing-and-resilience/failure-autopsy-and-healing/SKILL.md +54 -8
- package/.agents/skills/06-healing-and-resilience/flaky-test-sentinel-and-quarantine/SKILL.md +60 -24
- package/.agents/skills/06-healing-and-resilience/self-healing-locator/SKILL.md +52 -6
- package/.agents/skills/06-healing-and-resilience/systematic-debugging/SKILL.md +56 -10
- package/.agents/skills/06-healing-and-resilience/test-driven-development/SKILL.md +58 -12
- package/.agents/skills/06-healing-and-resilience/verification-before-completion/SKILL.md +58 -12
- package/.agents/skills/06-healing-and-resilience/visual-regression-sentinel/SKILL.md +53 -5
- package/.agents/skills/07-data-and-state/db-state-verifier-and-seeder/SKILL.md +56 -5
- package/.agents/skills/07-data-and-state/file-and-report-validator/SKILL.md +53 -4
- package/.agents/skills/07-data-and-state/synthetic-test-data-generator/SKILL.md +58 -5
- package/.agents/skills/08-code-quality/code-refactoring-refactor-clean/SKILL.md +57 -11
- package/.agents/skills/08-code-quality/graphify-impact-analyzer/SKILL.md +83 -34
- package/.agents/skills/08-code-quality/graphify-impact-analyzer/examples/dependency_blast_radius.json +3 -4
- package/.agents/skills/08-code-quality/lean-code-ladder/SKILL.md +55 -10
- package/.agents/skills/08-code-quality/repo-quality-audit/SKILL.md +49 -6
- package/.agents/skills/08-code-quality/senior-code-review/SKILL.md +52 -7
- package/.agents/skills/08-code-quality/surgical-coding-principles/SKILL.md +55 -10
- package/.agents/skills/08-code-quality/technical-debt-harvester/SKILL.md +51 -5
- package/.agents/skills/09-ci-and-devops/github-actions-templates/SKILL.md +54 -17
- package/.agents/skills/09-ci-and-devops/github-actions-templates/examples/matrix_test_pipeline.yml +2 -1
- package/.agents/skills/10-agent-orchestration/actor-qa-swarm/SKILL.md +50 -4
- package/.agents/skills/10-agent-orchestration/agent-orchestration-multi-agent-optimize/SKILL.md +53 -7
- package/.agents/skills/10-agent-orchestration/event-stream-qa-orchestrator/SKILL.md +50 -4
- package/.agents/skills/10-agent-orchestration/persistent-planning-files/SKILL.md +58 -13
- package/.agents/skills/10-agent-orchestration/qa-memory-os/SKILL.md +51 -5
- package/.agents/skills/11-ai-and-prompting/meta-prompt-crafter/SKILL.md +57 -10
- package/.agents/skills/11-ai-and-prompting/mipro-prompt-compiler/SKILL.md +50 -4
- package/.agents/skills/11-ai-and-prompting/qa-aci-interface/SKILL.md +50 -4
- package/.agents/skills/11-ai-and-prompting/token-and-context-optimizer/SKILL.md +55 -9
- package/.cursor/rules/synapse-qa.mdc +20 -7
- package/.cursorrules +19 -5
- package/.windsurfrules +18 -3
- package/AGENTS.md +51 -59
- package/CLAUDE.md +38 -24
- package/LICENSE +5 -5
- package/NOTICE +1 -1
- package/README.en.md +4 -4
- package/README.md +4 -4
- package/agentskills.json +1 -1
- package/docs/ARCHITECTURE.en.md +2 -2
- package/docs/ARCHITECTURE.md +11 -2
- package/docs/CLIENT_SUPPORT_MATRIX.md +44 -0
- package/docs/CLI_REFERENCE.en.md +6 -4
- package/docs/CLI_REFERENCE.md +1 -1
- package/docs/CONTRIBUTING.en.md +1 -1
- package/docs/CONTRIBUTING.md +2 -2
- package/docs/SIDE_EFFECTING_TOOLS_INVENTORY.md +233 -0
- package/docs/TOOL_CATALOG.md +6 -2
- package/docs/research/agent_skill_training_analysis.md +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skills_manifest.json +320 -55
- package/synapse.config.json +1 -1
- package/templates/ai_bridges/CLAUDE.md +29 -26
- package/templates/ai_bridges/copilot-instructions.md +14 -5
- package/templates/ai_bridges/cursor_synapse_qa.mdc +16 -7
- package/templates/ai_bridges/windsurfrules +14 -3
- package/templates/ui/index.html +2 -2
- package/tools/TOOLS_RUNBOOK.md +1 -1
- package/tools/TOOL_CATALOG.json +63 -3
- package/tools/__init__.py +1 -1
- package/tools/api_fuzzer.py +447 -132
- package/tools/author_integrity.py +121 -11
- package/tools/benchmark_swarm_context.py +130 -22
- package/tools/break_ui_generator.py +233 -0
- package/tools/browser_helpers.js +2 -2
- package/tools/check_version_sync.py +18 -50
- package/tools/cli.py +110 -19
- package/tools/core/bm25_retriever.py +218 -0
- package/tools/core/i18n.py +5 -5
- package/tools/core/provider_usage_adapter.py +383 -0
- package/tools/core/token_estimator.py +81 -15
- package/tools/count_tokens.py +7 -2
- package/tools/coverage_reporter.py +245 -0
- package/tools/dashboard_generator.py +8 -8
- package/tools/db_sandbox.py +290 -9
- package/tools/distill_log.py +1 -1
- package/tools/distill_skill.py +206 -0
- package/tools/git_pre_commit_guard.py +202 -1
- package/tools/humanize_linter.py +3 -0
- package/tools/mcp_docx_server.py +1 -1
- package/tools/mcp_excel_server.py +1 -1
- package/tools/mcp_server.py +104 -16
- package/tools/micro_mutator.py +114 -15
- package/tools/pentest_scope_guard.py +674 -58
- package/tools/perf/benchmark_perf_runner.py +42 -0
- package/tools/project_state.py +29 -5
- package/tools/reversible_sandbox.py +58 -13
- package/tools/rules_router.py +473 -60
- package/tools/security_scanner.py +80 -0
- package/tools/senior_code_review.py +14 -0
- package/tools/skill_canonical_digest.py +302 -0
- package/tools/skill_profiles.py +77 -7
- package/tools/slide_deck_exporter.py +477 -0
- package/tools/sync_agent_rules.py +187 -61
- package/tools/sync_skills_manifest.py +166 -0
- package/tools/task_memory_manager.py +275 -0
- package/tools/ui_server.py +3 -1
- package/tools/update_sentinel.py +3 -3
- package/tools/validate_host_interop.py +485 -0
- package/tools/validate_skills_schema.py +575 -0
- package/tools/verify_all.py +668 -44
- package/tools/welcome_page.py +2 -2
package/tools/db_sandbox.py
CHANGED
|
@@ -34,12 +34,21 @@ import json
|
|
|
34
34
|
import shutil
|
|
35
35
|
import socket
|
|
36
36
|
import sqlite3
|
|
37
|
+
import tempfile
|
|
37
38
|
import argparse
|
|
38
39
|
import subprocess
|
|
39
40
|
import urllib.request
|
|
40
41
|
import urllib.error
|
|
41
42
|
from typing import Dict, Any, List, Tuple, Optional
|
|
42
43
|
|
|
44
|
+
from pentest_scope_guard import (
|
|
45
|
+
resolve_contained_path,
|
|
46
|
+
PathContainmentError,
|
|
47
|
+
create_consent_grant,
|
|
48
|
+
verify_granular_grant,
|
|
49
|
+
is_consent_grant,
|
|
50
|
+
)
|
|
51
|
+
|
|
43
52
|
# Enforce UTF-8 stdout encoding for Windows console compatibility
|
|
44
53
|
if hasattr(sys.stdout, 'reconfigure'):
|
|
45
54
|
try:
|
|
@@ -71,7 +80,13 @@ SNAPSHOT_DIR = _resolve_snapshot_dir()
|
|
|
71
80
|
class DBSandbox:
|
|
72
81
|
"""Zero-pollution ephemeral database management."""
|
|
73
82
|
|
|
74
|
-
def __init__(
|
|
83
|
+
def __init__(
|
|
84
|
+
self,
|
|
85
|
+
db_type: str = "sqlite",
|
|
86
|
+
db_path: str = "",
|
|
87
|
+
snapshot_dir: Optional[str] = None,
|
|
88
|
+
sandbox_root: Optional[str] = None
|
|
89
|
+
):
|
|
75
90
|
clean_path = (db_path or "").strip()
|
|
76
91
|
lowered_path = clean_path.lower()
|
|
77
92
|
if lowered_path.startswith(("postgresql://", "postgres://")):
|
|
@@ -82,12 +97,11 @@ class DBSandbox:
|
|
|
82
97
|
self.db_type = "oracle"
|
|
83
98
|
else:
|
|
84
99
|
self.db_type = db_type.lower().strip() or "sqlite"
|
|
85
|
-
|
|
100
|
+
|
|
86
101
|
self.snapshot_dir = snapshot_dir if snapshot_dir is not None else _resolve_snapshot_dir()
|
|
87
102
|
try:
|
|
88
103
|
os.makedirs(self.snapshot_dir, exist_ok=True)
|
|
89
104
|
except OSError as err:
|
|
90
|
-
import tempfile
|
|
91
105
|
sys.stderr.write(f"Notice: Snapshot dir creation fallback: {err}\n")
|
|
92
106
|
self.snapshot_dir = os.path.join(tempfile.gettempdir(), ".synapse", "snapshots")
|
|
93
107
|
try:
|
|
@@ -95,6 +109,43 @@ class DBSandbox:
|
|
|
95
109
|
except OSError as ferr:
|
|
96
110
|
sys.stderr.write(f"Notice: Snapshot dir fallback failed: {ferr}\n")
|
|
97
111
|
|
|
112
|
+
# Determine sandbox root containment
|
|
113
|
+
if sandbox_root:
|
|
114
|
+
self.sandbox_root = os.path.realpath(os.path.abspath(sandbox_root))
|
|
115
|
+
else:
|
|
116
|
+
self.sandbox_root = os.path.realpath(os.path.abspath(self.snapshot_dir))
|
|
117
|
+
|
|
118
|
+
# Path containment validation for SQLite database file paths
|
|
119
|
+
if self.db_type == "sqlite" and clean_path and not clean_path.startswith(":memory:"):
|
|
120
|
+
allowed_roots = [self.sandbox_root]
|
|
121
|
+
if not sandbox_root:
|
|
122
|
+
allowed_roots.extend([
|
|
123
|
+
os.path.realpath(os.path.abspath(os.path.dirname(self.snapshot_dir))),
|
|
124
|
+
os.path.realpath(os.path.abspath(os.getcwd())),
|
|
125
|
+
os.path.realpath(os.path.abspath(QA_HUB_ROOT)),
|
|
126
|
+
os.path.realpath(os.path.abspath(tempfile.gettempdir())),
|
|
127
|
+
])
|
|
128
|
+
|
|
129
|
+
contained = None
|
|
130
|
+
last_err = None
|
|
131
|
+
if not os.path.isabs(clean_path):
|
|
132
|
+
# Relative path: strictly resolve and contain against self.sandbox_root
|
|
133
|
+
contained = resolve_contained_path(self.sandbox_root, clean_path)
|
|
134
|
+
else:
|
|
135
|
+
for root in allowed_roots:
|
|
136
|
+
try:
|
|
137
|
+
contained = resolve_contained_path(root, clean_path)
|
|
138
|
+
break
|
|
139
|
+
except PathContainmentError as pce:
|
|
140
|
+
last_err = pce
|
|
141
|
+
continue
|
|
142
|
+
|
|
143
|
+
if contained is None:
|
|
144
|
+
raise last_err or PathContainmentError(f"Database path '{clean_path}' escapes sandbox root containment.")
|
|
145
|
+
self.db_path = contained
|
|
146
|
+
else:
|
|
147
|
+
self.db_path = clean_path
|
|
148
|
+
|
|
98
149
|
# -------------------------------------------------------------------------
|
|
99
150
|
# 1. SNAPSHOT & RAPID RESTORE
|
|
100
151
|
# -------------------------------------------------------------------------
|
|
@@ -194,9 +245,16 @@ class DBSandbox:
|
|
|
194
245
|
|
|
195
246
|
return metadata
|
|
196
247
|
|
|
197
|
-
def restore_snapshot(
|
|
248
|
+
def restore_snapshot(
|
|
249
|
+
self,
|
|
250
|
+
snapshot_id: str = "pristine_baseline",
|
|
251
|
+
consent: Any = False,
|
|
252
|
+
dry_run: bool = False
|
|
253
|
+
) -> Dict[str, Any]:
|
|
198
254
|
"""
|
|
199
255
|
Restores database to pristine baseline, wiping 100% of test data junk.
|
|
256
|
+
Requires explicit consent when dry_run=False. Consent can be a boolean or a
|
|
257
|
+
scoped dictionary bound to target_sandbox.
|
|
200
258
|
"""
|
|
201
259
|
start_time = time.perf_counter()
|
|
202
260
|
try:
|
|
@@ -204,6 +262,94 @@ class DBSandbox:
|
|
|
204
262
|
except ValueError as e:
|
|
205
263
|
return {"status": "ERROR", "message": str(e)}
|
|
206
264
|
|
|
265
|
+
target_path = self.db_path or os.path.join(self.snapshot_dir, "active_test.db")
|
|
266
|
+
|
|
267
|
+
# 1. Dry run preview (Default-safe, zero side effects)
|
|
268
|
+
if dry_run:
|
|
269
|
+
return {
|
|
270
|
+
"status": "dry_run_preview",
|
|
271
|
+
"action": "restore",
|
|
272
|
+
"snapshot_id": clean_id,
|
|
273
|
+
"target_db": target_path,
|
|
274
|
+
"dry_run": True,
|
|
275
|
+
"message": f"DRY-RUN PREVIEW: Would restore database snapshot '{clean_id}' to '{target_path}'. Pass dry_run=False and a valid ConsentGrant (or --confirm on CLI) to execute."
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
# 2. Authorization / Consent enforcement at action execution boundary
|
|
279
|
+
# Generic boolean consent (consent=True) and shared environment variables are strictly eliminated.
|
|
280
|
+
if consent is None or isinstance(consent, bool) or not consent:
|
|
281
|
+
return {
|
|
282
|
+
"status": "ERROR",
|
|
283
|
+
"message": "Destructive database restore requires explicit consent bound to target sandbox. Generic boolean consent and shared environment variables are rejected.",
|
|
284
|
+
"snapshot_id": clean_id,
|
|
285
|
+
"target_db": target_path,
|
|
286
|
+
"zero_pollution_guaranteed": False
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
# Granular consent verification: ensure consent is bound to target and operation
|
|
290
|
+
if is_consent_grant(consent) or isinstance(consent, dict):
|
|
291
|
+
c_target = (
|
|
292
|
+
consent.target if is_consent_grant(consent)
|
|
293
|
+
else (consent.get("target_sandbox") or consent.get("target_db") or consent.get("target"))
|
|
294
|
+
)
|
|
295
|
+
if not c_target or not str(c_target).strip():
|
|
296
|
+
return {
|
|
297
|
+
"status": "ERROR",
|
|
298
|
+
"message": "Consent grant missing required target sandbox binding.",
|
|
299
|
+
"snapshot_id": clean_id,
|
|
300
|
+
"target_db": target_path,
|
|
301
|
+
"zero_pollution_guaranteed": False
|
|
302
|
+
}
|
|
303
|
+
try:
|
|
304
|
+
norm_c = os.path.realpath(os.path.abspath(c_target)).lower()
|
|
305
|
+
norm_target = os.path.realpath(os.path.abspath(target_path)).lower()
|
|
306
|
+
if norm_c != norm_target:
|
|
307
|
+
return {
|
|
308
|
+
"status": "ERROR",
|
|
309
|
+
"message": f"Consent target sandbox mismatch: consent granted for '{c_target}', but target is '{target_path}'.",
|
|
310
|
+
"snapshot_id": clean_id,
|
|
311
|
+
"target_db": target_path,
|
|
312
|
+
"zero_pollution_guaranteed": False
|
|
313
|
+
}
|
|
314
|
+
except Exception as p_err:
|
|
315
|
+
return {
|
|
316
|
+
"status": "ERROR",
|
|
317
|
+
"message": f"Consent target resolution error: {p_err}",
|
|
318
|
+
"snapshot_id": clean_id,
|
|
319
|
+
"target_db": target_path,
|
|
320
|
+
"zero_pollution_guaranteed": False
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
c_action = (
|
|
324
|
+
consent.action if is_consent_grant(consent)
|
|
325
|
+
else (consent.get("operation") or consent.get("action"))
|
|
326
|
+
)
|
|
327
|
+
if c_action and str(c_action).lower() not in ("restore", "db:restore"):
|
|
328
|
+
return {
|
|
329
|
+
"status": "ERROR",
|
|
330
|
+
"message": f"Consent operation mismatch: consent granted for '{c_action}', but requested operation is 'restore'.",
|
|
331
|
+
"snapshot_id": clean_id,
|
|
332
|
+
"target_db": target_path,
|
|
333
|
+
"zero_pollution_guaranteed": False
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if not verify_granular_grant(consent, expected_action="db:restore", expected_target=target_path):
|
|
337
|
+
return {
|
|
338
|
+
"status": "ERROR",
|
|
339
|
+
"message": "Consent grant validation failed: grant is invalid, expired, or replayed.",
|
|
340
|
+
"snapshot_id": clean_id,
|
|
341
|
+
"target_db": target_path,
|
|
342
|
+
"zero_pollution_guaranteed": False
|
|
343
|
+
}
|
|
344
|
+
else:
|
|
345
|
+
return {
|
|
346
|
+
"status": "ERROR",
|
|
347
|
+
"message": "Destructive database restore requires explicit consent bound to target sandbox. Invalid consent grant.",
|
|
348
|
+
"snapshot_id": clean_id,
|
|
349
|
+
"target_db": target_path,
|
|
350
|
+
"zero_pollution_guaranteed": False
|
|
351
|
+
}
|
|
352
|
+
|
|
207
353
|
if os.path.exists(meta_file):
|
|
208
354
|
try:
|
|
209
355
|
with open(meta_file, "r", encoding="utf-8") as f:
|
|
@@ -388,13 +534,104 @@ class DBSandbox:
|
|
|
388
534
|
def audit_and_purge_pollution(
|
|
389
535
|
self,
|
|
390
536
|
known_test_prefixes: Tuple[str, ...] = ("AUTO_", "TEST_", "TEMP_"),
|
|
391
|
-
dry_run: bool = True
|
|
537
|
+
dry_run: bool = True,
|
|
538
|
+
consent: Any = False
|
|
392
539
|
) -> Dict[str, Any]:
|
|
393
540
|
"""
|
|
394
541
|
Scans all tables for orphan records carrying test prefixes and purges them.
|
|
395
542
|
Properly escapes SQL LIKE wildcards ('_' and '%') with an explicit ESCAPE clause
|
|
396
543
|
to avoid deleting real business data (e.g. 'Automotive', 'Tester', 'Tempest').
|
|
544
|
+
Requires explicit consent bound to target sandbox when dry_run=False.
|
|
397
545
|
"""
|
|
546
|
+
target_path = self.db_path or os.path.join(self.snapshot_dir, "active_test.db")
|
|
547
|
+
if not dry_run:
|
|
548
|
+
# 1. Reject missing or generic boolean consent
|
|
549
|
+
if consent is None or isinstance(consent, bool) or not consent:
|
|
550
|
+
return {
|
|
551
|
+
"status": "ERROR",
|
|
552
|
+
"message": "Destructive database purge requires explicit consent bound to target sandbox. Generic boolean consent and shared environment variables are rejected.",
|
|
553
|
+
"tables_audited": 0,
|
|
554
|
+
"total_purged_rows": 0,
|
|
555
|
+
"purge_details": [],
|
|
556
|
+
"zero_pollution_achieved": False,
|
|
557
|
+
"dry_run": False
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
# 2. Granular consent verification: ensure consent is bound to target and operation
|
|
561
|
+
if is_consent_grant(consent) or isinstance(consent, dict):
|
|
562
|
+
c_target = (
|
|
563
|
+
consent.target if is_consent_grant(consent)
|
|
564
|
+
else (consent.get("target_sandbox") or consent.get("target_db") or consent.get("target"))
|
|
565
|
+
)
|
|
566
|
+
if not c_target or not str(c_target).strip():
|
|
567
|
+
return {
|
|
568
|
+
"status": "ERROR",
|
|
569
|
+
"message": "Consent grant missing required target sandbox binding.",
|
|
570
|
+
"tables_audited": 0,
|
|
571
|
+
"total_purged_rows": 0,
|
|
572
|
+
"purge_details": [],
|
|
573
|
+
"zero_pollution_achieved": False,
|
|
574
|
+
"dry_run": False
|
|
575
|
+
}
|
|
576
|
+
try:
|
|
577
|
+
norm_c = os.path.realpath(os.path.abspath(c_target)).lower()
|
|
578
|
+
norm_target = os.path.realpath(os.path.abspath(target_path)).lower()
|
|
579
|
+
if norm_c != norm_target:
|
|
580
|
+
return {
|
|
581
|
+
"status": "ERROR",
|
|
582
|
+
"message": f"Consent target sandbox mismatch: consent granted for '{c_target}', but target is '{target_path}'.",
|
|
583
|
+
"tables_audited": 0,
|
|
584
|
+
"total_purged_rows": 0,
|
|
585
|
+
"purge_details": [],
|
|
586
|
+
"zero_pollution_achieved": False,
|
|
587
|
+
"dry_run": False
|
|
588
|
+
}
|
|
589
|
+
except Exception as p_err:
|
|
590
|
+
return {
|
|
591
|
+
"status": "ERROR",
|
|
592
|
+
"message": f"Consent target resolution error: {p_err}",
|
|
593
|
+
"tables_audited": 0,
|
|
594
|
+
"total_purged_rows": 0,
|
|
595
|
+
"purge_details": [],
|
|
596
|
+
"zero_pollution_achieved": False,
|
|
597
|
+
"dry_run": False
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
c_action = (
|
|
601
|
+
consent.action if is_consent_grant(consent)
|
|
602
|
+
else (consent.get("operation") or consent.get("action"))
|
|
603
|
+
)
|
|
604
|
+
if c_action and str(c_action).lower() not in ("purge", "db:purge", "audit_and_purge"):
|
|
605
|
+
return {
|
|
606
|
+
"status": "ERROR",
|
|
607
|
+
"message": f"Consent operation mismatch: consent granted for '{c_action}', but requested operation is 'purge'.",
|
|
608
|
+
"tables_audited": 0,
|
|
609
|
+
"total_purged_rows": 0,
|
|
610
|
+
"purge_details": [],
|
|
611
|
+
"zero_pollution_achieved": False,
|
|
612
|
+
"dry_run": False
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if not verify_granular_grant(consent, expected_action="db:purge", expected_target=target_path):
|
|
616
|
+
return {
|
|
617
|
+
"status": "ERROR",
|
|
618
|
+
"message": "Consent grant validation failed: grant is invalid, expired, or replayed.",
|
|
619
|
+
"tables_audited": 0,
|
|
620
|
+
"total_purged_rows": 0,
|
|
621
|
+
"purge_details": [],
|
|
622
|
+
"zero_pollution_achieved": False,
|
|
623
|
+
"dry_run": False
|
|
624
|
+
}
|
|
625
|
+
else:
|
|
626
|
+
return {
|
|
627
|
+
"status": "ERROR",
|
|
628
|
+
"message": "Destructive database purge requires explicit consent bound to target sandbox. Invalid consent grant.",
|
|
629
|
+
"tables_audited": 0,
|
|
630
|
+
"total_purged_rows": 0,
|
|
631
|
+
"purge_details": [],
|
|
632
|
+
"zero_pollution_achieved": False,
|
|
633
|
+
"dry_run": False
|
|
634
|
+
}
|
|
398
635
|
if not self.db_path:
|
|
399
636
|
candidate = os.path.join(self.snapshot_dir, "active_test.db")
|
|
400
637
|
if os.path.exists(candidate):
|
|
@@ -601,6 +838,8 @@ def main():
|
|
|
601
838
|
help="Preview test records to purge without deleting (default: True)")
|
|
602
839
|
aud_p.add_argument("--apply", "--force", dest="apply", action="store_true", default=False,
|
|
603
840
|
help="Explicitly apply destructive purge to delete matching test records")
|
|
841
|
+
aud_p.add_argument("--confirm", action="store_true", default=False,
|
|
842
|
+
help="Explicit confirmation for destructive purge operation")
|
|
604
843
|
aud_p.add_argument("--json", action="store_true", help="Output JSON format")
|
|
605
844
|
|
|
606
845
|
# Command: wait-ready (Testcontainers-style readiness gate)
|
|
@@ -650,10 +889,10 @@ def main():
|
|
|
650
889
|
return 0 if res.get("status") != "ERROR" else 1
|
|
651
890
|
|
|
652
891
|
elif args.command == "restore":
|
|
653
|
-
if not args.confirm
|
|
892
|
+
if not args.confirm:
|
|
654
893
|
err_msg = (
|
|
655
894
|
"Refusing to execute destructive database restore without explicit confirmation. "
|
|
656
|
-
"Pass --confirm
|
|
895
|
+
"Pass --confirm if target is an isolated sandbox."
|
|
657
896
|
)
|
|
658
897
|
res = {
|
|
659
898
|
"status": "ERROR",
|
|
@@ -668,7 +907,14 @@ def main():
|
|
|
668
907
|
print(f"❌ [DB RESTORE BLOCKED] ID: {args.id}")
|
|
669
908
|
print(f" Error: {err_msg}")
|
|
670
909
|
return 1
|
|
671
|
-
|
|
910
|
+
grant = create_consent_grant(
|
|
911
|
+
action="db:restore",
|
|
912
|
+
target=sandbox.db_path,
|
|
913
|
+
caller_session=f"cli_{os.getpid()}",
|
|
914
|
+
db_identity=sandbox.db_path,
|
|
915
|
+
ttl_seconds=300
|
|
916
|
+
)
|
|
917
|
+
res = sandbox.restore_snapshot(args.id, consent=grant)
|
|
672
918
|
if args.json:
|
|
673
919
|
print(json.dumps(res, indent=2))
|
|
674
920
|
else:
|
|
@@ -700,10 +946,45 @@ def main():
|
|
|
700
946
|
effective_dry_run = True if args.dry_run is None else args.dry_run
|
|
701
947
|
if args.apply:
|
|
702
948
|
effective_dry_run = False
|
|
703
|
-
|
|
949
|
+
|
|
950
|
+
grant = None
|
|
951
|
+
if not effective_dry_run:
|
|
952
|
+
if not args.confirm:
|
|
953
|
+
err_msg = (
|
|
954
|
+
"Refusing to execute destructive database purge without explicit confirmation. "
|
|
955
|
+
"Pass --confirm if target is an isolated sandbox."
|
|
956
|
+
)
|
|
957
|
+
res = {
|
|
958
|
+
"status": "ERROR",
|
|
959
|
+
"message": err_msg,
|
|
960
|
+
"tables_audited": 0,
|
|
961
|
+
"total_purged_rows": 0,
|
|
962
|
+
"purge_details": [],
|
|
963
|
+
"zero_pollution_achieved": False,
|
|
964
|
+
"dry_run": False
|
|
965
|
+
}
|
|
966
|
+
if args.json:
|
|
967
|
+
print(json.dumps(res, indent=2))
|
|
968
|
+
else:
|
|
969
|
+
print("❌ [DB PURGE BLOCKED]")
|
|
970
|
+
print(f" Error: {err_msg}")
|
|
971
|
+
return 1
|
|
972
|
+
grant = create_consent_grant(
|
|
973
|
+
action="db:purge",
|
|
974
|
+
target=sandbox.db_path,
|
|
975
|
+
caller_session=f"cli_{os.getpid()}",
|
|
976
|
+
db_identity=sandbox.db_path,
|
|
977
|
+
ttl_seconds=300
|
|
978
|
+
)
|
|
979
|
+
|
|
980
|
+
res = sandbox.audit_and_purge_pollution(dry_run=effective_dry_run, consent=grant)
|
|
704
981
|
if args.json:
|
|
705
982
|
print(json.dumps(res, indent=2))
|
|
706
983
|
else:
|
|
984
|
+
if res.get("status") == "ERROR":
|
|
985
|
+
print("❌ [DB PURGE FAILED]")
|
|
986
|
+
print(f" Error: {res.get('message')}")
|
|
987
|
+
return 1
|
|
707
988
|
action_label = "Previewed" if effective_dry_run else "Purged"
|
|
708
989
|
print(f"🧹 [TAINT POLLUTION AUDIT] {action_label} {res['total_purged_rows']} orphan test records.")
|
|
709
990
|
for detail in res.get("purge_details", []):
|
package/tools/distill_log.py
CHANGED
|
@@ -15,7 +15,7 @@ Key Guarantees:
|
|
|
15
15
|
clean 0 with failure text -> CONFLICTING_SIGNALS).
|
|
16
16
|
3. Informational logging filter ([INFO], [DEBUG]) preventing false-positive assertion detection.
|
|
17
17
|
4. Genuine token_budget enforcement via calibrated tokenizer (default: 800 tokens).
|
|
18
|
-
5. 15-line block bounding and noise suppression, compressing
|
|
18
|
+
5. 15-line block bounding and noise suppression, compressing repetitive log volume.
|
|
19
19
|
6. Provenance retention: points back to raw log file for forensic tracing.
|
|
20
20
|
"""
|
|
21
21
|
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# SPDX-FileCopyrightText: © 2026 Thế Vị (@TeeVee98) <https://github.com/TeeVee98/Synapse-Hub>
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
# -*- coding: utf-8 -*-
|
|
6
|
+
"""
|
|
7
|
+
tools/distill_skill.py — Dual-Skill Distillation Engine
|
|
8
|
+
Inspired by titanwings/distilly (26.6k ⭐).
|
|
9
|
+
|
|
10
|
+
Distills unified agent skills and guidelines into two decoupled artifacts:
|
|
11
|
+
1. work_skill.md: Concrete procedures, CLI commands, step sequences, and DoD gates.
|
|
12
|
+
2. persona_skill.md: Cognitive heuristics, identity, communication style, and invariants.
|
|
13
|
+
|
|
14
|
+
Prevents persona drift and execution ambiguity across multi-agent swarms.
|
|
15
|
+
100% Python Standard Library (zero external dependencies).
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import os
|
|
20
|
+
import re
|
|
21
|
+
import sys
|
|
22
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
from tools.validate_skills_schema import parse_yaml_frontmatter
|
|
26
|
+
except ImportError:
|
|
27
|
+
try:
|
|
28
|
+
from validate_skills_schema import parse_yaml_frontmatter
|
|
29
|
+
except ImportError:
|
|
30
|
+
parse_yaml_frontmatter = None
|
|
31
|
+
|
|
32
|
+
PERSONA_KEYWORDS = {
|
|
33
|
+
"identity", "role", "tone", "communication", "telemetry", "badge",
|
|
34
|
+
"heuristic", "ruling", "philosophy", "senior dev", "protocol",
|
|
35
|
+
"style", "mindset", "falsification", "anti-pattern", "blacklist",
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
PROCEDURE_KEYWORDS = {
|
|
39
|
+
"command", "cli", "run", "step", "execute", "workflow", "script",
|
|
40
|
+
"verification", "dod", "gate", "curl", "test", "matrix", "schema",
|
|
41
|
+
"setup", "install", "teardown", "mutation", "assertion",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def parse_frontmatter(content: str) -> Tuple[Dict[str, Any], str]:
|
|
46
|
+
"""Extracts YAML frontmatter if present and returns (frontmatter_dict, remaining_body)."""
|
|
47
|
+
if parse_yaml_frontmatter is not None:
|
|
48
|
+
data, body, _ = parse_yaml_frontmatter(content)
|
|
49
|
+
if data is not None:
|
|
50
|
+
return data, body
|
|
51
|
+
if not content.startswith("---"):
|
|
52
|
+
return {}, content
|
|
53
|
+
|
|
54
|
+
match = re.match(r"^---\s*\n(.*?)\n---\s*\n(.*)$", content, re.DOTALL)
|
|
55
|
+
if not match:
|
|
56
|
+
return {}, content
|
|
57
|
+
|
|
58
|
+
raw_yaml = match.group(1)
|
|
59
|
+
body = match.group(2)
|
|
60
|
+
meta = {}
|
|
61
|
+
for line in raw_yaml.splitlines():
|
|
62
|
+
if ":" in line:
|
|
63
|
+
key, val = line.split(":", 1)
|
|
64
|
+
meta[key.strip()] = val.strip().strip("\"'")
|
|
65
|
+
return meta, body
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def split_markdown_sections(body: str) -> List[Tuple[str, str]]:
|
|
69
|
+
"""Splits markdown content into a list of (heading_title, section_text)."""
|
|
70
|
+
lines = body.splitlines()
|
|
71
|
+
sections: List[Tuple[str, str]] = []
|
|
72
|
+
current_title = "Introduction"
|
|
73
|
+
current_lines: List[str] = []
|
|
74
|
+
in_code_block = False
|
|
75
|
+
|
|
76
|
+
for line in lines:
|
|
77
|
+
stripped = line.strip()
|
|
78
|
+
if stripped.startswith("```"):
|
|
79
|
+
in_code_block = not in_code_block
|
|
80
|
+
|
|
81
|
+
heading_match = re.match(r"^(#{1,3})\s+(.*)$", line)
|
|
82
|
+
if heading_match and not in_code_block:
|
|
83
|
+
if current_lines:
|
|
84
|
+
sections.append((current_title, "\n".join(current_lines)))
|
|
85
|
+
current_lines = []
|
|
86
|
+
current_title = heading_match.group(2).strip()
|
|
87
|
+
current_lines.append(line)
|
|
88
|
+
else:
|
|
89
|
+
current_lines.append(line)
|
|
90
|
+
|
|
91
|
+
if current_lines:
|
|
92
|
+
sections.append((current_title, "\n".join(current_lines)))
|
|
93
|
+
|
|
94
|
+
return sections
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def classify_section(title: str, text: str) -> str:
|
|
98
|
+
"""Classifies a section as 'work', 'persona', or 'shared'."""
|
|
99
|
+
lower_title = title.lower()
|
|
100
|
+
lower_text = text.lower()
|
|
101
|
+
|
|
102
|
+
persona_score = sum(1 for kw in PERSONA_KEYWORDS if kw in lower_title) * 3
|
|
103
|
+
persona_score += sum(1 for kw in PERSONA_KEYWORDS if kw in lower_text)
|
|
104
|
+
|
|
105
|
+
proc_score = sum(1 for kw in PROCEDURE_KEYWORDS if kw in lower_title) * 3
|
|
106
|
+
proc_score += sum(1 for kw in PROCEDURE_KEYWORDS if kw in lower_text)
|
|
107
|
+
|
|
108
|
+
# Code blocks strongly indicate procedural work
|
|
109
|
+
code_blocks = len(re.findall(r"```[a-zA-Z0-9_-]*", text))
|
|
110
|
+
proc_score += code_blocks * 2
|
|
111
|
+
|
|
112
|
+
if persona_score > proc_score * 1.5:
|
|
113
|
+
return "persona"
|
|
114
|
+
if proc_score > persona_score * 1.2:
|
|
115
|
+
return "work"
|
|
116
|
+
return "shared"
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def distill_skill(content: str, base_name: str = "agent-skill") -> Tuple[str, str]:
|
|
120
|
+
"""
|
|
121
|
+
Distills skill content into (work_skill_markdown, persona_skill_markdown).
|
|
122
|
+
"""
|
|
123
|
+
meta, body = parse_frontmatter(content)
|
|
124
|
+
sections = split_markdown_sections(body)
|
|
125
|
+
|
|
126
|
+
work_sections: List[str] = []
|
|
127
|
+
persona_sections: List[str] = []
|
|
128
|
+
|
|
129
|
+
for title, text in sections:
|
|
130
|
+
classification = classify_section(title, text)
|
|
131
|
+
if classification == "persona":
|
|
132
|
+
persona_sections.append(text)
|
|
133
|
+
elif classification == "work":
|
|
134
|
+
work_sections.append(text)
|
|
135
|
+
else:
|
|
136
|
+
# Shared: include in both if relevant
|
|
137
|
+
work_sections.append(text)
|
|
138
|
+
persona_sections.append(text)
|
|
139
|
+
|
|
140
|
+
skill_title = meta.get("name", base_name)
|
|
141
|
+
skill_desc = meta.get("description", "Distilled Agent Skill")
|
|
142
|
+
|
|
143
|
+
work_skill_md = (
|
|
144
|
+
f"---\n"
|
|
145
|
+
f"name: {skill_title}-work\n"
|
|
146
|
+
f"description: \"Procedural execution guide for {skill_desc}\"\n"
|
|
147
|
+
f"type: procedural_work_skill\n"
|
|
148
|
+
f"---\n\n"
|
|
149
|
+
f"# {skill_title} — Procedural Work Skill\n\n"
|
|
150
|
+
+ "\n\n".join(work_sections).strip() + "\n"
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
persona_skill_md = (
|
|
154
|
+
f"---\n"
|
|
155
|
+
f"name: {skill_title}-persona\n"
|
|
156
|
+
f"description: \"Cognitive heuristics, persona invariants and communication for {skill_desc}\"\n"
|
|
157
|
+
f"type: cognitive_persona_skill\n"
|
|
158
|
+
f"---\n\n"
|
|
159
|
+
f"# {skill_title} — Cognitive Persona Skill\n\n"
|
|
160
|
+
+ "\n\n".join(persona_sections).strip() + "\n"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
return work_skill_md, persona_skill_md
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def distill_file(input_path: str, output_dir: Optional[str] = None) -> Tuple[str, str]:
|
|
167
|
+
"""Reads a file, distills it, and writes work_skill.md & persona_skill.md."""
|
|
168
|
+
if not os.path.isfile(input_path):
|
|
169
|
+
raise FileNotFoundError(f"Input skill file not found: {input_path}")
|
|
170
|
+
|
|
171
|
+
with open(input_path, "r", encoding="utf-8") as f:
|
|
172
|
+
content = f.read()
|
|
173
|
+
|
|
174
|
+
base_name = os.path.splitext(os.path.basename(input_path))[0]
|
|
175
|
+
out_dir = output_dir or os.path.dirname(os.path.abspath(input_path))
|
|
176
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
177
|
+
|
|
178
|
+
work_md, persona_md = distill_skill(content, base_name=base_name)
|
|
179
|
+
|
|
180
|
+
work_path = os.path.join(out_dir, "work_skill.md")
|
|
181
|
+
persona_path = os.path.join(out_dir, "persona_skill.md")
|
|
182
|
+
|
|
183
|
+
with open(work_path, "w", encoding="utf-8") as f:
|
|
184
|
+
f.write(work_md)
|
|
185
|
+
|
|
186
|
+
with open(persona_path, "w", encoding="utf-8") as f:
|
|
187
|
+
f.write(persona_md)
|
|
188
|
+
|
|
189
|
+
return work_path, persona_path
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def main() -> int:
|
|
193
|
+
parser = argparse.ArgumentParser(description="Dual-Skill Distillation Engine (titanwings/distilly pattern)")
|
|
194
|
+
parser.add_argument("input", help="Path to input SKILL.md or guideline file")
|
|
195
|
+
parser.add_argument("--out-dir", default=None, help="Output directory for work_skill.md and persona_skill.md")
|
|
196
|
+
args = parser.parse_args()
|
|
197
|
+
|
|
198
|
+
work_p, persona_p = distill_file(args.input, args.out_dir)
|
|
199
|
+
print("✅ Successfully distilled dual skills:")
|
|
200
|
+
print(f" - Procedural Work Skill: {work_p}")
|
|
201
|
+
print(f" - Cognitive Persona: {persona_p}")
|
|
202
|
+
return 0
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
if __name__ == "__main__":
|
|
206
|
+
sys.exit(main())
|