#!/usr/bin/env python3 """Constructed Skill update example; standard library only, synthetic data only. This is not an agent client, Skill loader, malware scanner, or sandbox test. All fixture writes are confined by construction to a temporary directory beside this file. The child programs are explicitly authored and launched here; they are never fetched from a third party. No network operations are implemented. """ from __future__ import annotations import hashlib import json import os from pathlib import Path import platform import subprocess import sys import tempfile from datetime import datetime, timezone SKILL = """--- name: synthetic-report description: Write a short report from synthetic example records. --- # Synthetic report Use the bundled `scripts/report.py` to summarize the supplied example records. Run it with the input JSON path and an output directory. Return `report.txt`. """ HELPER_V1 = '''import json from pathlib import Path import sys input_path = Path(sys.argv[1]) output_directory = Path(sys.argv[2]) records = json.loads(input_path.read_text(encoding="utf-8")) passed = sum(record["passed"] for record in records) report = f"Records: {len(records)}\\nPassed: {passed}\\n" (output_directory / "report.txt").write_text(report, encoding="utf-8") ''' HELPER_V2 = HELPER_V1 + ''' # Deliberately added, harmless local side effect in this constructed update. # These records are synthetic. There is no network transmission. (output_directory / "diagnostic-copy.json").write_text( json.dumps(records, indent=2) + "\\n", encoding="utf-8" ) ''' RECORDS = [ {"example": "alpha", "passed": True}, {"example": "beta", "passed": False}, {"example": "gamma", "passed": True}, ] def digest(data: bytes) -> str: return hashlib.sha256(data).hexdigest() def inventory(root: Path) -> dict[str, str]: """Inventory our own known regular-file fixture, not an untrusted tree.""" return { path.relative_to(root).as_posix(): digest(path.read_bytes()) for path in sorted(root.rglob("*")) if path.is_file() } def inventory_digest(files: dict[str, str]) -> str: canonical = json.dumps(files, sort_keys=True, separators=(",", ":")) return digest(canonical.encode("utf-8")) def main() -> None: started = datetime.now(timezone.utc).isoformat(timespec="seconds") parent = Path(__file__).resolve().parent source_hash = digest(Path(__file__).read_bytes()) outcomes: dict[str, dict] = {} # The temporary workspace is created beneath this script's directory. # It is removed on normal completion or an exception. with tempfile.TemporaryDirectory(prefix="skill-update-fixture-", dir=parent) as tmp: workspace = Path(tmp) input_file = workspace / "synthetic-input.json" input_file.write_text(json.dumps(RECORDS, indent=2) + "\n", encoding="utf-8") for version, helper in (("v1", HELPER_V1), ("v2", HELPER_V2)): skill_root = workspace / version / "synthetic-report" output_directory = workspace / version / "output" (skill_root / "scripts").mkdir(parents=True) output_directory.mkdir(parents=True) (skill_root / "SKILL.md").write_text(SKILL, encoding="utf-8") (skill_root / "scripts" / "report.py").write_text(helper, encoding="utf-8") before = inventory(skill_root) completed = subprocess.run( [ sys.executable, "-I", "-S", "scripts/report.py", str(input_file), str(output_directory), ], cwd=skill_root, env={}, capture_output=True, text=True, timeout=10, check=True, ) after = inventory(skill_root) if before != after: raise AssertionError("The helper unexpectedly changed its Skill files") if completed.stdout or completed.stderr: raise AssertionError("The helper produced unexpected console output") diagnostic = output_directory / "diagnostic-copy.json" outcomes[version] = { "skill_files_sha256": before, "skill_inventory_sha256": inventory_digest(before), "child_return_code": completed.returncode, "output_files_sha256": inventory(output_directory), "report_text": (output_directory / "report.txt").read_text(encoding="utf-8"), "diagnostic_copy_matches_synthetic_input": ( json.loads(diagnostic.read_text(encoding="utf-8")) == RECORDS if diagnostic.exists() else None ), } first = outcomes["v1"] second = outcomes["v2"] first_files = first["skill_files_sha256"] second_files = second["skill_files_sha256"] changed_paths = sorted( path for path in first_files.keys() | second_files.keys() if first_files.get(path) != second_files.get(path) ) assertions = { "skill_md_bytes_unchanged": first_files["SKILL.md"] == second_files["SKILL.md"], "only_bundled_helper_changed": changed_paths == ["scripts/report.py"], "whole_inventory_changed": first["skill_inventory_sha256"] != second["skill_inventory_sha256"], "primary_report_bytes_unchanged": first["output_files_sha256"]["report.txt"] == second["output_files_sha256"]["report.txt"], "v1_wrote_only_report": sorted(first["output_files_sha256"]) == ["report.txt"], "v2_wrote_report_and_local_copy": sorted(second["output_files_sha256"]) == ["diagnostic-copy.json", "report.txt"], "v2_copy_contains_only_expected_synthetic_records": second["diagnostic_copy_matches_synthetic_input"] is True, } if not all(assertions.values()): raise AssertionError(json.dumps(assertions, sort_keys=True)) result = { "experiment": "Constructed Skill update review example", "run_started_utc": started, "source_sha256": source_hash, "runtime": { "python": platform.python_version(), "system": platform.system(), "machine": platform.machine(), "uid": os.getuid() if hasattr(os, "getuid") else None, "euid": os.geteuid() if hasattr(os, "geteuid") else None, "child_environment": "empty mapping; Python invoked with -I -S", }, "scope": { "fixture_authored_for_this_example": True, "third_party_skill_executed": False, "agent_client_or_model_used": False, "synthetic_input_records": len(RECORDS), "network_operations_implemented": False, "network_isolation_tested": False, "sandbox_enforcement_tested": False, }, "versions": outcomes, "changed_skill_paths": changed_paths, "assertions": assertions, "passed": all(assertions.values()), "limitations": [ "A constructed illustration, not a prevalence study or a security benchmark.", "The example explicitly runs both authored Python helpers. It does not load a Skill in Claude Code or another agent host.", "It does not establish what any agent host executes when discovering, loading, or activating a Skill.", "The extra file is a harmless local copy of synthetic input. No exfiltration or real credential use was tested.", "Hashes detect byte changes in the inventoried regular files; they do not determine whether a file is safe.", "The fixture contains no symlinks, remote resources, package installs, or third-party dependencies. The inventory helper is not a general-purpose untrusted-package auditing tool.", ], } print(json.dumps(result, indent=2, sort_keys=True)) if __name__ == "__main__": main()