Skip to content

Lucasuiii/modeling-workbench / .agents/skills/cumcm-workflow

cumcm-workflow

Verified

Build or resume mathematical-modeling competition work, including CUMCM, MCM/ICM, graduate and regional contests, data challenges, and open-topic statistical modeling. Guide problem framing, modeling, computation, validation, Chinese or English LaTeX writing, and reviewed PDF/source delivery using current official requirements. Not for ordinary paper polishing.

FileKindSize
SKILL.mdskill md9.0 KB
agents/openai.yamlconfig427 B
assets/latex-template/generic-ctex/macros.texother859 B
assets/latex-template/generic-ctex/main.tex.tmplother2.5 KB
assets/latex-template/generic-ctex/metadata.tex.tmplother272 B
assets/latex-template/generic-ctex/planned-section.tex.tmplother1.0 KB
assets/latex-template/generic-ctex/references.bibother155 B
assets/latex-template/generic-ctex/sections/00_abstract.texother935 B
assets/latex-template/generic-ctex/sections/98_references.texother221 B
assets/latex-template/generic-ctex/sections/99_appendix.texother264 B
assets/latex-template/generic-ctex/template.jsonconfig304 B
assets/latex-template/generic-en/macros.texother868 B
assets/latex-template/generic-en/main.tex.tmplother2.2 KB
assets/latex-template/generic-en/metadata.tex.tmplother278 B
assets/latex-template/generic-en/planned-section.tex.tmplother1013 B
assets/latex-template/generic-en/references.bibother155 B
assets/latex-template/generic-en/sections/00_abstract.texother454 B
assets/latex-template/generic-en/sections/98_references.texother201 B
assets/latex-template/generic-en/sections/99_appendix.texother240 B
assets/latex-template/generic-en/template.jsonconfig249 B
assets/latex-template/huawei-ctex/main.tex.tmplother3.3 KB
assets/latex-template/huawei-ctex/template.jsonconfig276 B
assets/plot-style/cumcm.mplstyleother953 B
references/01-intake.mdmarkdown3.9 KB
references/02-problem-analysis.mdmarkdown2.8 KB
references/03-model-design.mdmarkdown7.6 KB
references/04-computation.mdmarkdown13.4 KB
references/05-validation.mdmarkdown5.9 KB
references/06-paper-writing.mdmarkdown14.3 KB
references/07-compile-delivery.mdmarkdown6.1 KB
references/artifact-contracts.mdmarkdown3.1 KB
references/competition-adaptation.mdmarkdown6.8 KB
references/competition-writing.mdmarkdown5.6 KB
references/diagnostics.mdmarkdown4.5 KB
references/evidence-rules.mdmarkdown1.6 KB
references/handoffs.mdmarkdown3.5 KB
references/huawei-delivery.mdmarkdown10.1 KB
references/latex-template.mdmarkdown6.2 KB
references/mechanism-validation.mdmarkdown11.6 KB
references/open-topic-research.mdmarkdown4.9 KB
references/task-driven-modeling.mdmarkdown7.2 KB
schemas/claim-ledger.schema.jsonconfig5.5 KB
schemas/common.schema.jsonconfig2.5 KB
schemas/compile-receipt.schema.jsonconfig3.7 KB
schemas/cross-question-ledger.schema.jsonconfig1.3 KB
schemas/delivery-manifest.schema.jsonconfig7.9 KB
schemas/figure-manifest.schema.jsonconfig1.9 KB
schemas/handoff.schema.jsonconfig2.1 KB
schemas/independent-review-package.schema.jsonconfig3.4 KB
schemas/independent-review-result.schema.jsonconfig4.0 KB
schemas/latex-template-manifest.schema.jsonconfig2.4 KB
schemas/model-contract.schema.jsonconfig5.0 KB
schemas/paper-plan.schema.jsonconfig3.3 KB
schemas/paper-quality-report.schema.jsonconfig5.7 KB
schemas/paper-revision-log.schema.jsonconfig2.2 KB
schemas/paper-visible-text-report.schema.jsonconfig1.6 KB
schemas/problem-facts.schema.jsonconfig1.7 KB
schemas/results-index.schema.jsonconfig1.4 KB
schemas/run-manifest.schema.jsonconfig7.1 KB
schemas/source-manifest.schema.jsonconfig1.9 KB
schemas/task-capabilities.schema.jsonconfig3.9 KB
schemas/workflow-state.schema.jsonconfig2.4 KB
scripts/backend_selection.pyscript6.3 KB
scripts/build_handoff.pyscript20.4 KB
scripts/build_independent_review_package.pyscript14.9 KB
scripts/canonical_evidence.pyscript8.4 KB
scripts/compile_sources.pyscript2.4 KB
scripts/cumcm_check.pyscript2.9 KB
scripts/delivery_archives.pyscript7.0 KB
scripts/doctor.pyscript7.5 KB
scripts/index_result.pyscript10.9 KB
scripts/init_latex_paper.pyscript17.2 KB
scripts/init_project.pyscript11.1 KB
scripts/inventory_artifacts.pyscript4.1 KB
scripts/json_pointer.pyscript1.0 KB
scripts/official_materials.pyscript3.0 KB
scripts/paper_visible_text_check.pyscript5.4 KB
scripts/plan_redo.pyscript18.8 KB
scripts/project_status.pyscript5.8 KB
scripts/provenance.pyscript2.2 KB
scripts/record_compile.pyscript13.2 KB
scripts/record_decision.pyscript12.0 KB
scripts/record_run.pyscript28.1 KB
scripts/refresh_evidence.pyscript4.7 KB
scripts/set_mode.pyscript2.0 KB
scripts/submission_check.pyscript10.6 KB
scripts/workflow_checks.pyscript146.0 KB

scripts/record_decision.py

View on GitHub
#!/usr/bin/env python3
"""Append a file-version-bound human decision to .cumcm/decisions.jsonl.

An `accepted` decision derives the stage snapshot and advances state. A `revision_requested` decision
is the reopen primitive: it invalidates this stage and every downstream stage so
that iteration never requires hand-editing .cumcm/state.json."""

from __future__ import annotations

import argparse
import errno
import json
import os
import tempfile
import time
from contextlib import contextmanager
from datetime import datetime, timezone
from pathlib import Path

from workflow_checks import STAGES, safe_project_path, sha256, stage_scope_paths
from provenance import digest_records


def load_events(path: Path) -> list[dict]:
    if not path.exists():
        return []
    events: list[dict] = []
    seen: set[str] = set()
    for line_number, raw in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
        if not raw.strip():
            continue
        event = json.loads(raw)
        if not isinstance(event, dict):
            raise ValueError(f"line {line_number} is not an object")
        decision_id = event.get("decision_id")
        if not isinstance(decision_id, str) or not decision_id or decision_id in seen:
            raise ValueError(f"line {line_number} has a missing or duplicate decision_id")
        seen.add(decision_id)
        events.append(event)
    return events


def write_json_atomic(path: Path, payload: dict) -> None:
    path.parent.mkdir(parents=True, exist_ok=True)
    with tempfile.NamedTemporaryFile("wb", dir=path.parent, delete=False) as stream:
        stream.write((json.dumps(payload, ensure_ascii=False, indent=2) + "\n").encode("utf-8"))
        temp_name = stream.name
    os.replace(temp_name, path)


CHECKPOINT_PATHS = {"model-design": ("model/MODEL_CONTRACT.json", "selection_check"),
                    "validation": ("validation/CLAIM_LEDGER.json", "conclusion_check"),
                    "delivery": ("delivery/DELIVERY_MANIFEST.json", "final_check")}


@contextmanager
def decision_lock(path: Path):
    """Hold the same cross-process lock through all decision writes."""
    with path.open("a+b") as stream:
        if os.name == "nt":
            import msvcrt

            # msvcrt.locking locks from the current file position. A real byte
            # is required; two creators may append it concurrently, but both
            # still lock byte zero and never truncate the lock file.
            stream.seek(0, os.SEEK_END)
            if stream.tell() == 0:
                stream.write(b"\0")
                stream.flush()
            while True:
                stream.seek(0)
                try:
                    msvcrt.locking(stream.fileno(), msvcrt.LK_NBLCK, 1)
                    break
                except OSError as exc:
                    if exc.errno not in (errno.EACCES, errno.EAGAIN):
                        raise
                    time.sleep(0.05)
            try:
                yield
            finally:
                stream.seek(0)
                msvcrt.locking(stream.fileno(), msvcrt.LK_UNLCK, 1)
        else:
            import fcntl

            fcntl.flock(stream, fcntl.LOCK_EX)
            try:
                yield
            finally:
                fcntl.flock(stream, fcntl.LOCK_UN)


def reopen(root: Path, stage: str) -> None:
    """Invalidate this stage and everything downstream of it."""
    index = STAGES.index(stage)
    for later in STAGES[index:]:
        (root / ".cumcm" / "snapshots" / f"{later}.json").unlink(missing_ok=True)
        if later in CHECKPOINT_PATHS:
            rel, key = CHECKPOINT_PATHS[later]
            path = root / rel
            if path.is_file():
                data = json.loads(path.read_text(encoding="utf-8"))
                if isinstance(data.get(key), dict):
                    data[key]["decision"] = "unreviewed"
                    write_json_atomic(path, data)
    state_path = root / ".cumcm" / "state.json"
    state = json.loads(state_path.read_text(encoding="utf-8"))
    stages = state.get("stages")
    if not isinstance(stages, dict):
        return
    stages[stage] = "needs_revision"
    for later in STAGES[index + 1 :]:
        if stages.get(later) == "passed":
            stages[later] = "needs_revision"
    state["current_stage"] = stage
    write_json_atomic(state_path, state)


def main() -> int:
    parser = argparse.ArgumentParser(description="Record an append-only, artifact-bound workflow decision")
    parser.add_argument("--project", required=True, type=Path)
    parser.add_argument("--stage", required=True, choices=STAGES)
    parser.add_argument("--decision", required=True, choices=("accepted", "revision_requested"))
    parser.add_argument("--decision-id", help="optional; otherwise allocated from the existing decision log")
    parser.add_argument("--reviewer", default="agent")
    parser.add_argument("--task-turn-ref", required=True)
    parser.add_argument("--summary", required=True, dest="user_visible_summary")
    parser.add_argument("--confirm-human", action="store_true", help="only after the user explicitly accepted ALL currently presented material; fills the existing checkpoint fields")
    parser.add_argument("--scope", action="append", default=[], help="project-relative file; repeat to override the stage defaults")
    args = parser.parse_args()

    root = args.project.resolve()
    if not root.is_dir():
        parser.error(f"project is not a directory: {root}")
    log_path = root / ".cumcm" / "decisions.jsonl"
    log_path.parent.mkdir(parents=True, exist_ok=True)
    # Include allocation and checkpoint validation in the same transaction as
    # the append-only log, snapshot, and state writes.
    with decision_lock(root / ".cumcm" / "decisions.lock"):
        return _record_decision(args, root, parser, log_path)


def _record_decision(args, root: Path, parser: argparse.ArgumentParser, log_path: Path) -> int:
    events = load_events(log_path)
    if not args.decision_id:
        used = {event["decision_id"] for event in events}
        number = len(events) + 1
        while f"DEC-{number:03d}" in used:
            number += 1
        args.decision_id = f"DEC-{number:03d}"
    if args.decision_id in {event["decision_id"] for event in events}:
        parser.error(f"decision_id already exists: {args.decision_id}")

    # Fill the existing checkpoint once; the agent need not copy ids or timestamps.
    checkpoint_paths = CHECKPOINT_PATHS
    checkpoint_data = None
    checkpoint_path = None
    if args.confirm_human:
        if args.decision != "accepted" or args.stage not in checkpoint_paths:
            parser.error("--confirm-human applies only to acceptance at the three human checkpoints")
        rel, key = checkpoint_paths[args.stage]
        checkpoint_path = root / rel
        data = json.loads(checkpoint_path.read_bytes())
        if args.stage == "model-design":
            presented_key = "presented_candidate_ids"
            presented = [c["candidate_id"] for component in data.get("components", [])
                         for c in component.get("candidates", [])]
        elif args.stage == "validation":
            presented_key = "presented_claim_ids"
            presented = [c["claim_id"] for c in data.get("claims", [])]
        else:
            presented_key = "presented_pages"
            presented = list(range(1, data.get("compile", {}).get("page_count", 0) + 1))
        if not presented:
            parser.error("no material to confirm; prepare and show it first")
        if args.reviewer == "agent":
            args.reviewer = "user"
        data[key] = {"decision": "accepted", "reviewer": args.reviewer,
                     "reviewer_kind": "human_user", "reviewed_at": datetime.now(timezone.utc).isoformat(),
                     presented_key: presented, "notes": args.user_visible_summary}
        checkpoint_data = data
    if args.decision == "accepted" and args.stage in checkpoint_paths:
        from workflow_checks import check_selection_check, check_conclusion_check, check_final_check, require_human_checkpoint
        if not args.confirm_human:
            try:
                require_human_checkpoint(root, args.stage)
            except ValueError as exc:
                parser.error(str(exc))
        rel, key = checkpoint_paths[args.stage]
        data = checkpoint_data or json.loads((root / rel).read_text(encoding="utf-8"))
        checks = {"model-design": lambda: check_selection_check(data, rel),
                  "validation": lambda: check_conclusion_check(data, rel),
                  "delivery": lambda: check_final_check(data, rel, data.get("compile"))}
        if args.stage == "model-design":
            from workflow_checks import require_resolved_model
            try:
                require_resolved_model(data)
            except ValueError as exc:
                parser.error(str(exc))
        errors = checks[args.stage]()
        if errors:
            parser.error(errors[0].message + "; show the material, then use --confirm-human after the user's reply")

    scope_paths = args.scope or stage_scope_paths(root, args.stage)
    if args.decision == "accepted" and args.stage in checkpoint_paths:
        rel, _ = checkpoint_paths[args.stage]
        scope_paths = list(dict.fromkeys([*scope_paths, rel]))
    if ".cumcm/state.json" in scope_paths:
        parser.error("workflow state is mutable and must not be included in a decision scope")
    scope = []
    checkpoint_scope = None
    for rel in scope_paths:
        artifact = safe_project_path(root, rel)
        if artifact is None or not artifact.is_file():
            parser.error(f"scope file is missing or unsafe: {rel}")
        is_checkpoint = checkpoint_data is not None and artifact == checkpoint_path
        item = {"path": rel, "sha256": None if is_checkpoint else sha256(artifact)}
        if is_checkpoint:
            checkpoint_scope = item
        scope.append(item)

    event = {
        "decision_id": args.decision_id,
        "stage": args.stage,
        "decision": args.decision,
        "scope": scope,
        "reviewer": args.reviewer,
        "task_turn_ref": args.task_turn_ref,
        "user_visible_summary": args.user_visible_summary,
        "decided_at": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
    }
    if checkpoint_data is not None:
        write_json_atomic(checkpoint_path, checkpoint_data)
        if checkpoint_scope is not None:
            checkpoint_scope["sha256"] = sha256(checkpoint_path)
    with log_path.open("a", encoding="utf-8") as stream:
        stream.write(json.dumps(event, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + "\n")
    snapshot_path = root / ".cumcm" / "snapshots" / f"{args.stage}.json"
    if args.decision == "accepted":
        snapshot = {
            "snapshot_version": "0.6.0",
            "project_id": json.loads((root / ".cumcm" / "state.json").read_text(encoding="utf-8")).get("project_id"),
            "stage": args.stage,
            "decision_id": args.decision_id,
            "decision": args.decision,
            "created_at": event["decided_at"],
            "artifacts": scope,
            "snapshot_digest": digest_records(scope),
        }
        write_json_atomic(snapshot_path, snapshot)
        state_path = root / ".cumcm" / "state.json"
        state = json.loads(state_path.read_text(encoding="utf-8"))
        state["stages"][args.stage] = "passed"
        pending = [stage for stage in STAGES if state["stages"].get(stage) != "passed"]
        next_stage = pending[0] if pending else STAGES[-1]
        if state["stages"].get(next_stage) == "not_started":
            state["stages"][next_stage] = "in_progress"
        state["current_stage"] = next_stage
        write_json_atomic(state_path, state)
        print(f"{args.stage}: passed; next: {next_stage}")
    else:
        reopen(root, args.stage)
    print(f"recorded {args.decision_id} for {args.stage}; {len(scope)} artifact(s) bound")
    if args.decision == "revision_requested":
        print(f"reopened {args.stage}; downstream stages are now needs_revision")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall