Skip to content

dse120071750/m8m-harness-builder / skills/m8m/m8m-schedule-builder

m8m-schedule-builder

Verified

Author reusable M8M schedule packages for server installation, or create and manage schedules and reminders inside the current live M8M Task room.

scripts/m8m_deploy.py

View on GitHub
"""Local submission/status/continuation client for the durable server installer."""
import argparse
from io import BytesIO
import json
from pathlib import Path
import shlex
import subprocess
import sys
import uuid
import zipfile

sys.path.insert(0, str(Path(__file__).resolve().parent))
from m8m_delivery_common import collect, encoded, no_links, transfer_digest


def remote(target, *args, payload=None):
    argv = target["remote_entrypoint"] + list(args)
    if not isinstance(argv, list) or any(not isinstance(x, str) or "\x00" in x for x in argv):
        raise ValueError("Invalid configured server installer entry point.")
    result = subprocess.run(["ssh", "-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=yes", target["ssh_alias"], shlex.join(argv)],
                            input=payload, capture_output=True, timeout=300 if payload else 60)
    if result.returncode:
        raise RuntimeError("Server installer entry failed: " + result.stderr[-4000:].decode(errors="replace"))
    return json.loads(result.stdout)


def main(argv=None):
    if hasattr(sys.stdout, "reconfigure"):
        sys.stdout.reconfigure(encoding="utf-8")
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog='Configured target JSON (values come from the approved server configuration):\n'
               '{"schema":"m8m.installer_target.v1","ssh_alias":"<approved alias>",\n'
               ' "tenant_id":"<canonical tenant>","environment":"<configured environment>",\n'
               ' "installation_owner":"<approved owner>",\n'
               ' "remote_entrypoint":["<trusted preconfigured tenant installer launcher>"]}\n'
               'The launcher supplies the tenant OS identity, environment and server settings.\n'
               'Target labels do not establish installation authority.')
    parser.add_argument("--target", type=Path, required=True, help="Local server alias/environment/tenant/entry-point configuration")
    commands = parser.add_subparsers(dest="command", required=True)
    submit = commands.add_parser("submit")
    submit.add_argument("--intake", type=Path, required=True)
    submit.add_argument("--brief", type=Path, required=True)
    submit.add_argument("--owner", help="Override the configured installation owner")
    submit.add_argument("--operation-id", required=True)
    submit.add_argument("--model", default="gpt-6-sol")
    submit.add_argument("--reasoning-effort", default="xhigh")
    status = commands.add_parser("status")
    status.add_argument("--operation-id", required=True)
    followup = commands.add_parser("continue")
    followup.add_argument("--operation-id", required=True)
    followup.add_argument("--message-id", required=True)
    followup.add_argument("--text", type=Path, required=True)
    args = parser.parse_args(argv)
    target = json.loads(args.target.read_bytes())
    if (not isinstance(target, dict) or not {"schema", "ssh_alias", "tenant_id", "environment", "remote_entrypoint"} <= set(target)
            or set(target) - {"schema", "ssh_alias", "tenant_id", "environment", "remote_entrypoint", "incoming_root", "installation_owner"}
            or target["schema"] != "m8m.installer_target.v1"):
        raise ValueError("Select an explicit configured server, environment and canonical tenant.")
    if (any(not isinstance(target[key], str) or not target[key] or "\x00" in target[key]
            for key in ("ssh_alias", "tenant_id", "environment"))
            or target["ssh_alias"].startswith("-")
            or not isinstance(target["remote_entrypoint"], list) or not target["remote_entrypoint"]
            or any(not isinstance(value, str) or not value or "\x00" in value for value in target["remote_entrypoint"])):
        raise ValueError("The configured target must contain an SSH alias and an argument-list entry point.")
    # The server resolves this target against its private policy. Client target
    # labels never establish tenant/application authority.
    if args.command == "status":
        result = remote(target, "status", "--operation-id", args.operation_id)
    elif args.command == "submit":
        uuid.UUID(args.operation_id)
        files = collect(args.intake)
        no_links(args.brief.absolute())
        owner = args.owner or target.get("installation_owner")
        if not isinstance(owner, str) or not owner:
            raise ValueError("Provide --owner or configure installation_owner in the target.")
        header = {"owner": owner, "client_operation_id": args.operation_id,
                  "brief": args.brief.read_text(encoding="utf-8"), "transfer_digest": transfer_digest(files),
                  "model": args.model, "reasoning_effort": args.reasoning_effort}
        archive = BytesIO()
        with zipfile.ZipFile(archive, "w", compression=zipfile.ZIP_DEFLATED) as transport:
            for name, data in files.items():
                transport.writestr(name, data)
        # SSH stdin carries the transfer directly to the authenticated server
        # entry point. It writes private staging as the installer identity.
        result = remote(target, "submit-stdin", payload=encoded(header) + b"\n" + archive.getvalue())
    else:
        uuid.UUID(args.message_id)
        no_links(args.text.absolute())
        result = remote(target, "continue-stdin", payload=encoded({"operation_id": args.operation_id,
            "client_message_id": args.message_id, "text": args.text.read_text(encoding="utf-8")}))
    if result["tenant_id"] != target["tenant_id"]:
        raise RuntimeError("The server installer receipt does not match the selected canonical tenant.")
    print(encoded(result).decode())
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
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