Skip to content

dse120071750/m8m-harness-builder / skills/m8m/m8m-task-builder

m8m-task-builder

Verified

Author reusable M8M Task packages for server installation, or persist and manage the current live M8M Task's instructions, progress, waits and final JSON.

scripts/m8m_delivery_common.py

View on GitHub
"""Portable local delivery helpers; no platform checkout or third-party imports."""
from __future__ import annotations

import hashlib
import json
import os
from pathlib import Path, PurePosixPath
import tempfile

MAX_FILES = 10000
MAX_BYTES = 512 * 1024 * 1024
MAX_FILE_BYTES = 64 * 1024 * 1024
SKIP_DIRECTORIES = {".git", ".hg", ".svn", ".codex", ".ssh", "__pycache__", ".pytest_cache", "node_modules"}


def sha256(data: bytes) -> str:
    return "sha256:" + hashlib.sha256(data).hexdigest()


def encoded(value) -> bytes:
    return json.dumps(value, sort_keys=True, separators=(",", ":"),
                      ensure_ascii=False, allow_nan=False).encode("utf-8")


def relative(value: str) -> str:
    if (not isinstance(value, str) or not value or "\\" in value or ":" in value
            or "\x00" in value or len(value) > 512):
        raise ValueError("Use a relative POSIX file path.")
    path = PurePosixPath(value)
    if path.is_absolute() or any(p in {"", ".", ".."} for p in value.split("/")):
        raise ValueError("A file path escapes or aliases its intake.")
    return path.as_posix()


def no_links(path: Path):
    for item in (path, *path.parents):
        if item.is_symlink() or getattr(item, "is_junction", lambda: False)():
            raise ValueError("Delivery paths must not contain links.")


def collect(root):
    """Collect selected context with the server's transport limits and path rules."""
    root = Path(root).absolute()
    no_links(root)
    if not root.exists():
        raise ValueError("The selected intake does not exist.")
    paths = []
    if root.is_dir():
        for directory, dirs, names in os.walk(root, followlinks=False):
            for name in dirs:
                no_links(Path(directory) / name)
            dirs[:] = sorted(d for d in dirs if d not in SKIP_DIRECTORIES)
            paths.extend(Path(directory) / name for name in sorted(names))
    else:
        paths = [root]
    files, total = {}, 0
    for path in sorted(paths):
        no_links(path)
        if path.name in SKIP_DIRECTORIES:
            continue
        if not path.is_file():
            continue
        if (path.name.startswith(".env") or path.name in {"auth.json", "credentials.json"}
                or path.suffix.lower() in {".pem", ".key", ".sqlite3"}):
            raise ValueError("Choose credential-free source/runtime context for delivery.")
        size = path.stat().st_size
        total += size
        if len(files) >= MAX_FILES or size > MAX_FILE_BYTES or total > MAX_BYTES:
            raise ValueError("Intake exceeds the server transport bound.")
        name = path.relative_to(root).as_posix() if root.is_dir() else path.name
        files[relative(name)] = path.read_bytes()
    if not files:
        raise ValueError("Select at least one reusable intake file.")
    return files


def transfer_digest(files):
    return sha256(encoded([{"path": name, "bytes": len(data), "digest": sha256(data)}
                           for name, data in sorted(files.items())]))


def immutable(path: Path, data: bytes):
    """Publish atomically without replacement, including Windows drives without hardlinks."""
    no_links(path)
    path.parent.mkdir(parents=True, exist_ok=True)
    with tempfile.NamedTemporaryFile(dir=path.parent, delete=False) as handle:
        temporary = Path(handle.name)
        handle.write(data)
        handle.flush()
        os.fsync(handle.fileno())
    try:
        try:
            if os.name == "nt":
                os.rename(temporary, path)  # Windows rename refuses an existing destination.
            else:
                os.link(temporary, path)
        except FileExistsError:
            if path.read_bytes() != data:
                raise ValueError("The existing export has different bytes; choose a new output path.")
    finally:
        temporary.unlink(missing_ok=True)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall