Skip to content

siril9/presentation-skill / plugins/presentation-skill/skills/presentation-skill

presentation-skill

Flagged

Build, edit, redesign, render, and verify content-led, structurally diverse, clean, editable, reproducible PowerPoint `.pptx` decks. Use for scientific, lab, clinical, consulting, board, investor, editorial, policy, and operational presentations where alignment, readability, contrast, and balanced density matter.

FileKindSize
DESIGN.mdmarkdown13.7 KB
DISCOVERY.mdmarkdown6.6 KB
LICENSEother1.0 KB
SKILL.mdskill md14.7 KB
agents/discovery.jsonconfig8.2 KB
agents/openai.yamlconfig309 B
examples/outline.jsonconfig3.4 KB
package-lock.jsonmanifest22.0 KB
package.jsonmanifest1.8 KB
references/agent_picker.mdmarkdown1.9 KB
references/alignment_and_coherence.mdmarkdown2.1 KB
references/assets/visual_references/editorial_chart.jpgbinary53.2 KB
references/assets/visual_references/editorial_decision.jpgbinary100.4 KB
references/assets/visual_references/editorial_focal_metric.jpgbinary45.4 KB
references/assets/visual_references/editorial_pilot.jpgbinary62.0 KB
references/assets/visual_references/lab-native-method.jpgbinary53.9 KB
references/assets/visual_references/lab-residual-panels.jpgbinary64.8 KB
references/assets/visual_references/lab_cover.jpgbinary39.8 KB
references/assets/visual_references/lab_endpoints.jpgbinary70.8 KB
references/assets/visual_references/lab_evidence_gate.jpgbinary67.3 KB
references/assets/visual_references/lab_trend.jpgbinary60.5 KB
references/assets/visual_references/operations_handoffs.jpgbinary87.2 KB
references/assets/visual_references/operations_owner_register.jpgbinary87.2 KB
references/assets/visual_references/operations_queue.jpgbinary81.8 KB
references/assets/visual_references/operations_tradeoff.jpgbinary99.9 KB
references/benchmark_protocol.mdmarkdown12.1 KB
references/codex_guardrails.mdmarkdown10.3 KB
references/composition_grammar_catalog.mdmarkdown4.0 KB
references/deck_creation.mdmarkdown1.4 KB
references/deck_workspace_mode.mdmarkdown34.4 KB
references/design_philosophy.mdmarkdown5.5 KB
references/dynamic_design_and_subagents.mdmarkdown12.3 KB
references/editing.mdmarkdown12.4 KB
references/external_best_practices.mdmarkdown1.7 KB
references/large_style_corpus_sources.jsonconfig22.7 KB
references/model_adaptive_workflow.mdmarkdown6.6 KB
references/outline_schema.mdmarkdown44.8 KB
references/planning_schema.mdmarkdown54.8 KB
references/pptxgenjs.mdmarkdown7.6 KB
references/preview_extension.mdmarkdown1.7 KB
references/reference_script_patterns.mdmarkdown13.5 KB
references/renderer_role_contracts_v2.jsonconfig38.2 KB
references/reproducible_workflow.mdmarkdown5.1 KB
references/speed_and_rendering.mdmarkdown4.6 KB
references/style_grammar_index.jsonconfig364.2 KB
references/style_inspiration_corpus.jsonconfig32.9 KB
references/style_reference_catalog.mdmarkdown23.9 KB
references/style_reference_sources.jsonconfig35.8 KB
references/style_token_atlas.jsonconfig174.7 KB
references/subagent_patterns.mdmarkdown10.2 KB
references/visual_qa_prompt.mdmarkdown4.9 KB
references/visual_reference_catalog.jsonconfig26.6 KB
references/visual_reference_catalog.mdmarkdown6.0 KB
schemas/deck_ir.schema.jsonconfig9.5 KB
schemas/renderer_capabilities_v2.jsonconfig701 B
scripts/accessibility_qa.pyscript24.8 KB
scripts/action_registry.pyscript12.5 KB
scripts/add_slide.pyscript8.6 KB
scripts/advance_delivery.pyscript88.2 KB
scripts/advance_workspace.pyscript150.3 KB
scripts/apply_artifact_manifest_bindings.pyscript54.1 KB
scripts/apply_atom_composition.pyscript8.2 KB
scripts/apply_data_analysis_handoff.pyscript67.0 KB
scripts/apply_deck_intake_answers.pyscript35.6 KB
scripts/apply_design_contract.pyscript71.7 KB
scripts/apply_outline_authoring_handoff.pyscript23.7 KB
scripts/apply_pptx_style_fragment.pyscript19.7 KB
scripts/asset_stage.pyscript24.6 KB
scripts/audition_styles.pyscript8.7 KB
scripts/benchmark_decks.pyexecutablescript45.4 KB
scripts/build_deck.pyexecutablescript173.6 KB
scripts/build_deck_pptxgenjs.jsexecutablescript72.7 KB
scripts/build_large_style_corpus_contact_sheets.pyscript18.1 KB
scripts/build_workspace.pyscript126.2 KB
scripts/clean_unpacked.pyscript12.9 KB
scripts/compact_source_footers.pyscript17.8 KB
scripts/composition_grammar_catalog.pyscript30.3 KB
scripts/deck_benchmark.pyscript71.1 KB
scripts/deck_intake.pyscript6.9 KB
scripts/deck_ir.pyscript47.5 KB
scripts/design_catalog_selector.pyscript17.4 KB
scripts/design_rules_qa.pyscript24.8 KB
scripts/design_tokens.pyscript20.3 KB
scripts/edit_deck.pyscript8.4 KB
scripts/emit_content_research.pyscript4.6 KB
scripts/emit_data_analysis_prompt.pyscript30.1 KB
scripts/emit_deck_intake_prompt.pyexecutablescript19.9 KB
scripts/emit_deck_start_packet.pyscript97.1 KB
scripts/emit_design_contract_prompt.pyscript66.2 KB
scripts/emit_outline_authoring_prompt.pyscript35.4 KB
scripts/emit_outline_critique.pyscript11.6 KB
scripts/emit_style_content_router.pyscript49.6 KB
scripts/extract_outline.pyexecutablescript4.1 KB
scripts/extract_pptx_style.pyscript33.2 KB
scripts/fetch_wikimedia_cc.pyscript8.6 KB
scripts/finalize_quick_deck.pyscript17.6 KB
scripts/generate_openai_image.pyscript5.6 KB
scripts/init_deck_workspace.pyscript74.4 KB
scripts/inspect_artifact_manifest.pyscript29.8 KB
scripts/inventory.pyscript10.6 KB
scripts/iterate_deck.pyexecutablescript10.2 KB
scripts/layout_lint.pyscript40.4 KB
scripts/log_skill_telemetry.pyscript6.9 KB
scripts/model_adaptive_workflow.pyscript28.0 KB
scripts/office_package_hash.pyscript1.6 KB
scripts/pack_pptx.pyscript5.7 KB
scripts/palette_from_topic.pyscript4.1 KB
scripts/plan_research_assets.pyscript13.1 KB
scripts/preflight.pyscript136.9 KB
scripts/present.pyscript9.6 KB
scripts/python_runtime.pyscript787 B
scripts/qa_gate.pyexecutablescript27.4 KB
scripts/qa_visual_gate.pyexecutablescript8.5 KB
scripts/reference_deck.pyscript12.7 KB
scripts/render_cache.pyscript3.9 KB
scripts/render_mermaid.pyscript8.9 KB
scripts/render_slides.pyexecutablescript19.4 KB
scripts/repair_packet.pyscript14.7 KB
scripts/report_delivery_readiness.pyscript107.6 KB
scripts/report_workspace_readiness.pyscript244.6 KB
scripts/requirements-runtime.txtmarkdown472 B
scripts/role_layout_contracts.pyscript10.6 KB
scripts/runtime_doctor.pyscript6.3 KB
scripts/scaffold_figure_artifacts.pyscript92.3 KB
scripts/source_fidelity.pyscript30.5 KB
scripts/structural_diversity_v2.pyscript32.5 KB
scripts/style_atom_router.pyscript14.5 KB
scripts/style_inspiration_corpus.pyscript15.1 KB
scripts/style_reference_catalog.pyscript142.8 KB
scripts/style_reference_sources.pyscript12.7 KB
scripts/style_treatment_profiles.pyscript26.0 KB
scripts/summarize_skill_log.pyscript7.0 KB
scripts/taste_grammar_catalog.pyscript27.0 KB
scripts/test_structural_diversity_v2.pyscript4.9 KB
scripts/text_fit.pyscript23.6 KB
scripts/thumbnail.pyscript9.2 KB
scripts/trim_image_whitespace.pyexecutablescript5.4 KB
scripts/unpack_pptx.pyscript8.3 KB
scripts/upgrade_renderer_role_contracts_v2.pyscript7.3 KB
scripts/validate_planning.pyscript169.2 KB
scripts/verify_narration.pyscript10.6 KB
scripts/visual_qa.pyscript7.7 KB
scripts/visual_review.pyscript41.1 KB
scripts/visual_review_receipt.pyscript8.3 KB
scripts/workflow_atom_context.pyscript17.3 KB
templates/pptxgenjs/README.mdmarkdown8.4 KB
templates/pptxgenjs/presets.jsscript5.6 KB
templates/pptxgenjs/readable_role_layouts.jsscript17.5 KB
templates/pptxgenjs/render_plan.jsscript12.6 KB
templates/pptxgenjs/role_layout_contracts.jsscript4.7 KB
templates/pptxgenjs/slides.jsscript451.0 KB
templates/pptxgenjs/space_allocation.jsscript1.6 KB

scripts/apply_deck_intake_answers.py

View on GitHub
#!/usr/bin/env python3
"""Persist first-turn deck intake answers into workspace planning files.

This helper keeps the question-card step reproducible. It accepts a compact
answers JSON payload, optionally paired with the deck-start packet, then writes
the durable planning layer that agents otherwise have to remember to apply by
hand: design_brief.user_intake, a deterministic style seed, light design
translation hints, source policy, asset posture, audience, and notes.
"""

from __future__ import annotations

import argparse
import hashlib
import json
import sys
from pathlib import Path
from typing import Any


SCRIPT_DIR = Path(__file__).resolve().parent
if str(SCRIPT_DIR) not in sys.path:
    sys.path.insert(0, str(SCRIPT_DIR))

from emit_design_contract_prompt import _stable_id  # noqa: E402


INTAKE_FIELDS = (
    "audience_context",
    "target_outcome",
    "style_direction",
    "density",
    "palette",
    "background_visuals",
    "evidence_assets",
    "source_policy",
    "constraints",
)

COMPRESSED_FIELDS = (
    "style_density",
    "visual_source_policy",
)

NOTE_START = "<!-- deck-intake-answers:start -->"
NOTE_END = "<!-- deck-intake-answers:end -->"

PLACEHOLDER_FRAGMENTS = (
    "replace with",
    "topic-specific opener chosen",
    "large topic-specific title",
    "deck author using the presentation-skill workspace scaffold",
    "prefer primary or source-backed facts. do not fabricate citations.",
)


def _load_json(path: Path, default: Any) -> Any:
    if not path.exists():
        return default
    try:
        return json.loads(path.read_text(encoding="utf-8"))
    except json.JSONDecodeError as exc:
        raise SystemExit(f"Invalid JSON in {path}: {exc}") from exc


def _write_json_if_changed(path: Path, payload: Any, *, dry_run: bool) -> bool:
    text = json.dumps(payload, indent=2, ensure_ascii=False) + "\n"
    if path.exists() and path.read_text(encoding="utf-8") == text:
        return False
    if not dry_run:
        path.parent.mkdir(parents=True, exist_ok=True)
        path.write_text(text, encoding="utf-8")
    return True


def _write_text_if_changed(path: Path, text: str, *, dry_run: bool) -> bool:
    if path.exists() and path.read_text(encoding="utf-8") == text:
        return False
    if not dry_run:
        path.parent.mkdir(parents=True, exist_ok=True)
        path.write_text(text, encoding="utf-8")
    return True


def _file_sha256(path: Path) -> str:
    digest = hashlib.sha256()
    with path.open("rb") as handle:
        for chunk in iter(lambda: handle.read(1024 * 1024), b""):
            digest.update(chunk)
    return digest.hexdigest()


def _display_path(workspace: Path, path: Path | None) -> str:
    if path is None:
        return ""
    try:
        return str(path.resolve().relative_to(workspace.resolve()))
    except ValueError:
        return str(path.resolve())


def _file_snapshot(workspace: Path, path: Path | None) -> dict[str, Any]:
    snapshot: dict[str, Any] = {
        "path": _display_path(workspace, path),
        "exists": bool(path and path.exists()),
    }
    if path and path.exists() and path.is_file():
        payload = path.read_bytes()
        snapshot["size_bytes"] = len(payload)
        snapshot["sha256"] = hashlib.sha256(payload).hexdigest()
    return snapshot


def _answer_text(value: Any) -> str:
    if value is None:
        return ""
    if isinstance(value, str):
        return value.strip()
    if isinstance(value, (int, float, bool)):
        return str(value).strip()
    if isinstance(value, dict):
        for key in ("answer", "value", "label", "text", "selected", "response"):
            text = _answer_text(value.get(key))
            if text:
                return text
        if "option" in value:
            return _answer_text(value.get("option"))
        return "; ".join(
            f"{key}: {_answer_text(item)}"
            for key, item in value.items()
            if _answer_text(item)
        ).strip()
    if isinstance(value, list):
        return "; ".join(text for text in (_answer_text(item) for item in value) if text)
    return ""


def _as_dict(value: Any) -> dict[str, Any]:
    return value if isinstance(value, dict) else {}


def _extract_answer_items(payload: Any) -> dict[str, str]:
    if not isinstance(payload, dict):
        raise SystemExit("Answers JSON must be an object.")

    candidates: list[Any] = [payload]
    for key in ("answers", "responses", "result", "data"):
        value = payload.get(key)
        if isinstance(value, (dict, list)):
            candidates.append(value)

    answers: dict[str, str] = {}
    known = set(INTAKE_FIELDS) | set(COMPRESSED_FIELDS) | {"answered_by", "unanswered"}

    for candidate in candidates:
        if isinstance(candidate, dict):
            for key, value in candidate.items():
                if key in known:
                    text = _answer_text(value)
                    if text:
                        answers[key] = text
        elif isinstance(candidate, list):
            for item in candidate:
                if not isinstance(item, dict):
                    continue
                key = _answer_text(item.get("id") or item.get("question_id") or item.get("name"))
                if key in known:
                    text = _answer_text(
                        item.get("answer")
                        if "answer" in item
                        else item.get("value")
                        if "value" in item
                        else item.get("label")
                    )
                    if text:
                        answers[key] = text

    return answers


def _packet_question_ids(packet: Any) -> list[str]:
    if not isinstance(packet, dict):
        return []
    request = packet.get("request_user_input")
    questions = request.get("questions") if isinstance(request, dict) else None
    if not isinstance(questions, list):
        return []
    ids: list[str] = []
    for item in questions:
        if isinstance(item, dict):
            qid = str(item.get("id") or "").strip()
            if qid:
                ids.append(qid)
    return ids


def _derive_from_style_density(text: str) -> dict[str, str]:
    lower = text.lower()
    updates: dict[str, str] = {"style_density": text}
    if "figure" in lower or "report" in lower or "leave" in lower:
        updates.setdefault("style_direction", text)
        updates.setdefault("density", "dense report/leave-behind")
        updates["design_dna"] = "lab results dashboard"
        updates["figure_table_treatment"] = "figure-first"
    elif "conference" in lower or "talk" in lower:
        updates.setdefault("style_direction", text)
        updates.setdefault("density", "sparse live-talk / presenter-led")
        updates["design_dna"] = "technical educational"
        updates["figure_table_treatment"] = "image-sidebar"
    elif "editorial" in lower or "premium" in lower:
        updates.setdefault("style_direction", text)
        updates.setdefault("density", "balanced editorial report")
        updates["design_dna"] = "editorial report"
        updates["figure_table_treatment"] = "image-sidebar"
    else:
        updates.setdefault("style_direction", text)
    return updates


def _derive_from_visual_source_policy(text: str) -> dict[str, str]:
    lower = text.lower()
    updates: dict[str, str] = {"visual_source_policy": text}
    if "strict" in lower or "every factual" in lower:
        updates.setdefault("source_policy", "source every factual claim")
        updates.setdefault("palette", "restrained neutral/lab palette")
        updates.setdefault("background_visuals", "clean white report with source-backed evidence visuals")
        updates.setdefault("evidence_assets", "prefer provided, local, or source-backed figures and tables")
    elif "custom" in lower or "user-provided" in lower or "provided" in lower:
        updates.setdefault("source_policy", "use only provided sources until approved")
        updates.setdefault("palette", "wait for user-provided palette or reference deck")
        updates.setdefault("background_visuals", "defer to provided assets and reference style")
        updates.setdefault("evidence_assets", "pause for user-provided figures, logos, screenshots, data, or reference decks")
    else:
        updates.setdefault("source_policy", "cite key claims")
        updates.setdefault("palette", "restrained palette chosen by best judgment")
        updates.setdefault("background_visuals", "clean report with source-backed or generated visuals only when useful")
        updates.setdefault("evidence_assets", "use local/generated figures when data exists; otherwise use source-backed visuals selectively")
    return updates


def _is_replaceable_existing(value: Any, *, overwrite: bool) -> bool:
    if overwrite or value in (None, "", [], {}):
        return True
    if isinstance(value, str):
        lower = value.strip().lower()
        return any(fragment in lower for fragment in PLACEHOLDER_FRAGMENTS)
    return False


def _merge_missing(target: dict[str, Any], updates: dict[str, Any], *, overwrite: bool) -> list[str]:
    changed: list[str] = []
    for key, value in updates.items():
        if value in (None, "", [], {}):
            continue
        if _is_replaceable_existing(target.get(key), overwrite=overwrite):
            if target.get(key) != value:
                target[key] = value
                changed.append(key)
    return changed


def _normalize_unanswered(value: Any) -> list[str]:
    if value is None:
        return []
    if isinstance(value, list):
        return [str(item).strip() for item in value if str(item).strip()]
    text = _answer_text(value)
    if not text:
        return []
    return [part.strip() for part in text.replace("\n", ",").split(",") if part.strip()]


def _build_user_intake(
    *,
    answers: dict[str, str],
    packet: Any,
    answered_by: str,
    stable_prompt_id: str,
) -> dict[str, Any]:
    derived: dict[str, str] = {}
    if answers.get("style_density"):
        derived.update(_derive_from_style_density(answers["style_density"]))
    if answers.get("visual_source_policy"):
        for key, value in _derive_from_visual_source_policy(answers["visual_source_policy"]).items():
            derived.setdefault(key, value)
    for key in INTAKE_FIELDS:
        if answers.get(key):
            derived[key] = answers[key]

    packet_question_ids = _packet_question_ids(packet)
    missing_question_ids = [qid for qid in packet_question_ids if not answers.get(qid)]
    unanswered = _normalize_unanswered(answers.get("unanswered"))
    for qid in missing_question_ids:
        if qid not in unanswered:
            unanswered.append(qid)

    intake: dict[str, Any] = {
        key: derived.get(key, "")
        for key in INTAKE_FIELDS
    }
    intake["answered_by"] = answered_by
    intake["unanswered"] = unanswered
    intake["codex_ui_answers"] = {
        key: answers[key]
        for key in COMPRESSED_FIELDS
        if answers.get(key)
    }
    if stable_prompt_id:
        intake["stable_prompt_id"] = stable_prompt_id
    return intake


def _packet_choice_contract(packet: Any) -> dict[str, Any]:
    if not isinstance(packet, dict):
        return {}
    value = packet.get("choice_resolution_contract")
    return value if isinstance(value, dict) else {}


def _packet_route_ledger(packet: Any) -> dict[str, Any]:
    if not isinstance(packet, dict):
        return {}
    value = packet.get("route_decision_ledger")
    return value if isinstance(value, dict) else {}


def _packet_source_inventory(packet: Any) -> dict[str, Any]:
    if not isinstance(packet, dict):
        return {}
    value = packet.get("workspace_source_inventory")
    return value if isinstance(value, dict) else {}


def _packet_atom_context(packet: Any) -> dict[str, Any]:
    if not isinstance(packet, dict):
        return {}
    candidates = [
        packet.get("atom_workflow_context"),
        _as_dict(packet.get("application_contract")).get("atom_workflow_context"),
    ]
    for value in candidates:
        if isinstance(value, dict) and value.get("schema_version") == "normal_workflow_atom_context_v1":
            return value
    return {}


def _route_ledger_status(route_ledger: dict[str, Any]) -> dict[str, bool]:
    routes = route_ledger.get("routes")
    if not isinstance(routes, list):
        return {}
    return {
        str(item.get("id") or "").strip(): bool(item.get("active"))
        for item in routes
        if isinstance(item, dict) and str(item.get("id") or "").strip()
    }


def _choice_ledger_by_id(choice_contract: dict[str, Any]) -> dict[str, dict[str, Any]]:
    ledger = choice_contract.get("choice_ledger")
    if not isinstance(ledger, list):
        return {}
    by_id: dict[str, dict[str, Any]] = {}
    for item in ledger:
        if not isinstance(item, dict):
            continue
        choice_id = str(item.get("id") or "").strip()
        if choice_id:
            by_id[choice_id] = item
    return by_id


def _route_decisions_from(packet: Any, choice_contract: dict[str, Any]) -> list[dict[str, Any]]:
    route_items = choice_contract.get("route_decisions")
    if isinstance(route_items, list):
        routes: list[dict[str, Any]] = []
        for item in route_items:
            if not isinstance(item, dict):
                continue
            route_id = str(item.get("id") or "").strip()
            if not route_id:
                continue
            copied = dict(item)
            copied["id"] = route_id
            if "active" in copied:
                copied["active"] = bool(copied.get("active"))
            routes.append(copied)
        if routes:
            return routes

    application_contract = (
        packet.get("application_contract") if isinstance(packet, dict) else {}
    )
    if not isinstance(application_contract, dict):
        return []
    return [
        {
            "id": "data_artifacts",
            "active": bool(application_contract.get("data_artifacts_likely")),
            "trigger_evidence": "copied from deck_start_packet.application_contract.data_artifacts_likely",
        },
        {
            "id": "pptx_style_import",
            "active": bool(application_contract.get("pptx_style_likely")),
            "trigger_evidence": "copied from deck_start_packet.application_contract.pptx_style_likely",
        },
    ]


def _build_choice_resolution_seed(
    *,
    user_intake: dict[str, Any],
    packet: Any,
    stable_prompt_id: str,
) -> dict[str, Any]:
    choice_contract = _packet_choice_contract(packet)
    route_ledger = _packet_route_ledger(packet)
    source_inventory = _packet_source_inventory(packet)
    atom_context = _packet_atom_context(packet)
    route_ledger_status = _route_ledger_status(route_ledger)
    ledger_by_id = _choice_ledger_by_id(choice_contract)
    compressed = (
        user_intake.get("codex_ui_answers")
        if isinstance(user_intake.get("codex_ui_answers"), dict)
        else {}
    )
    choice_specs = [
        (
            "audience_context",
            _answer_text(user_intake.get("audience_context")),
            [
                "design_brief.user_intake",
                "content_plan.audience",
                "readability_contract",
            ],
        ),
        (
            "style_density",
            _answer_text(compressed.get("style_density"))
            or _answer_text(user_intake.get("style_direction"))
            or _answer_text(user_intake.get("density")),
            [
                "design_modulation",
                "style_system.style_mix_matrix",
                "structure_blueprint.slide_variant_mix",
            ],
        ),
        (
            "visual_source_policy",
            _answer_text(compressed.get("visual_source_policy"))
            or _answer_text(user_intake.get("source_policy")),
            [
                "evidence_plan.source_policy",
                "asset_posture",
                "analysis_artifact_plan",
                "figure_export_contract",
            ],
        ),
    ]
    resolved_choices: list[dict[str, Any]] = []
    for choice_id, answer, fallback_fields in choice_specs:
        if not answer:
            continue
        ledger = ledger_by_id.get(choice_id, {})
        resolved_choices.append(
            {
                "id": choice_id,
                "answer": answer,
                "locks": ledger.get("locks", []),
                "source_fields": ledger.get("source_fields", fallback_fields),
                "contract_fields": ledger.get("contract_fields", fallback_fields),
            }
        )

    if not resolved_choices and not choice_contract and not route_ledger:
        return {}

    requirements = (
        choice_contract.get("contract_requirements")
        if isinstance(choice_contract.get("contract_requirements"), dict)
        else {}
    )
    seed = {
        "contract_version": "deck_choice_resolution_v1",
        "seed_kind": "resolved_intake_answers",
        "source_contract_version": choice_contract.get("contract_version", ""),
        "stable_prompt_id": stable_prompt_id,
        "answered_by": user_intake.get("answered_by", ""),
        "resolved_choices": resolved_choices,
        "route_decisions": _route_decisions_from(packet, choice_contract),
        "design_fields_locked": requirements.get(
            "design_contract_fields",
            [
                "choice_resolution",
                "style_system.style_mix_matrix",
                "readability_contract",
                "evidence_plan.source_policy",
                "analysis_artifact_plan",
                "figure_export_contract",
            ],
        ),
        "replay_inputs": {
            "answers": "intake_answers.json",
            "packet": "deck_start_packet.json",
            "applied_to": "design_brief.choice_resolution_seed",
        },
    }
    if route_ledger:
        seed["route_decision_ledger"] = route_ledger
        seed["route_ledger_version"] = str(route_ledger.get("ledger_version") or "")
        seed["route_ledger_active_routes"] = sorted(
            route_id for route_id, active in route_ledger_status.items() if active
        )
        seed["replay_inputs"]["route_decision_ledger"] = "deck_start_packet.json:route_decision_ledger"
    if source_inventory:
        seed["workspace_source_inventory"] = source_inventory
        seed["replay_inputs"]["workspace_source_inventory"] = "deck_start_packet.json:workspace_source_inventory"
    if atom_context:
        seed["atom_composition"] = {
            "schema_version": atom_context.get("schema_version"),
            "route_id": "atom_composition",
            "decision": "seeded_optional_accept_refine_or_skip",
            "target_family": atom_context.get("target_family"),
            "selection_basis": atom_context.get("selection_basis"),
            "preferred_variants": atom_context.get("preferred_variants") or [],
            "narrative_arc": atom_context.get("narrative_arc") or [],
            "style_atom_composition": atom_context.get("style_atom_composition") or {},
            "deck_style_delta": atom_context.get("deck_style_delta") or {},
            "normal_workflow_contract": atom_context.get("normal_workflow_contract") or {},
            "source": "deck_start_packet.atom_workflow_context",
        }
        seed["replay_inputs"]["atom_workflow_context"] = "deck_start_packet.json:atom_workflow_context"
    return seed


def _style_seed_from(packet: Any, user_prompt: str) -> str:
    if isinstance(packet, dict):
        for key in ("recommended_style_seed", "stable_prompt_id"):
            value = str(packet.get(key) or "").strip()
            if value:
                return value
    if user_prompt.strip():
        return _stable_id(user_prompt.strip())
    return ""


def _replace_notes_section(existing: str, section: str) -> str:
    if NOTE_START in existing and NOTE_END in existing:
        before = existing.split(NOTE_START, 1)[0].rstrip()
        after = existing.split(NOTE_END, 1)[1].lstrip()
        parts = [part for part in (before, section.rstrip(), after.rstrip()) if part]
        return "\n\n".join(parts) + "\n"
    prefix = existing.rstrip()
    return (prefix + "\n\n" if prefix else "") + section.rstrip() + "\n"


def _notes_section(
    user_intake: dict[str, Any],
    *,
    style_seed: str,
    choice_resolution_seed: dict[str, Any],
) -> str:
    lines = [
        NOTE_START,
        "## Deck Intake Answers",
        "",
    ]
    if style_seed:
        lines.append(f"- Stable style seed: `{style_seed}`")
    lines.append(f"- Answered by: {user_intake.get('answered_by', '')}")
    unanswered = user_intake.get("unanswered")
    if unanswered:
        lines.append(f"- Unanswered: {', '.join(str(item) for item in unanswered)}")
    else:
        lines.append("- Unanswered: none")
    lines.extend(["", "### Persisted Answers"])
    for key in INTAKE_FIELDS:
        value = _answer_text(user_intake.get(key))
        if value:
            lines.append(f"- {key}: {value}")
    compressed = user_intake.get("codex_ui_answers")
    if isinstance(compressed, dict) and compressed:
        lines.extend(["", "### Question Card Answers"])
        for key in COMPRESSED_FIELDS:
            value = _answer_text(compressed.get(key))
            if value:
                lines.append(f"- {key}: {value}")
    if choice_resolution_seed:
        lines.extend(["", "### Choice Resolution Seed"])
        version = _answer_text(choice_resolution_seed.get("contract_version"))
        if version:
            lines.append(f"- Choice contract: {version}")
        choices = []
        for item in choice_resolution_seed.get("resolved_choices", []):
            if isinstance(item, dict):
                choice_id = _answer_text(item.get("id"))
                answer = _answer_text(item.get("answer"))
                if choice_id and answer:
                    choices.append(f"{choice_id}: {answer}")
        if choices:
            lines.append(f"- Resolved choices: {', '.join(choices)}")
        routes = []
        for item in choice_resolution_seed.get("route_decisions", []):
            if not isinstance(item, dict):
                continue
            route_id = _answer_text(item.get("id"))
            if not route_id:
                continue
            active = item.get("active")
            if isinstance(active, bool):
                routes.append(f"{route_id}={'active' if active else 'inactive'}")
            else:
                routes.append(route_id)
        if routes:
            lines.append(f"- Route decisions: {', '.join(routes)}")
        route_ledger = choice_resolution_seed.get("route_decision_ledger")
        route_status = _route_ledger_status(route_ledger if isinstance(route_ledger, dict) else {})
        if route_status:
            route_summary = [
                f"{route_id}={'active' if active else 'inactive'}"
                for route_id, active in sorted(route_status.items())
            ]
            lines.append(f"- Route ledger: {', '.join(route_summary)}")
        atom_composition = choice_resolution_seed.get("atom_composition")
        if isinstance(atom_composition, dict):
            target_family = _answer_text(atom_composition.get("target_family"))
            variants = atom_composition.get("preferred_variants")
            variant_text = _answer_text(variants[:5] if isinstance(variants, list) else variants)
            summary = ", ".join(part for part in (target_family, variant_text) if part)
            if summary:
                lines.append(f"- Atom composition seed: {summary}")
        source_inventory = choice_resolution_seed.get("workspace_source_inventory")
        if isinstance(source_inventory, dict):
            data_count = int(source_inventory.get("data_file_count") or 0)
            pptx_count = int(source_inventory.get("reference_pptx_count") or 0)
            ledger_count = int(source_inventory.get("artifact_ledger_count") or 0)
            lines.append(
                "- Source inventory: "
                f"data_files={data_count}, reference_pptx={pptx_count}, "
                f"artifact_ledgers={ledger_count}"
            )
    lines.append(NOTE_END)
    return "\n".join(lines) + "\n"


def apply_answers(
    *,
    workspace: Path,
    answers_path: Path,
    packet_path: Path | None,
    user_prompt: str,
    answered_by_override: str | None,
    overwrite_translations: bool,
    dry_run: bool,
) -> dict[str, Any]:
    answers_payload = _load_json(answers_path, {})
    answers = _extract_answer_items(answers_payload)
    packet = _load_json(packet_path, {}) if packet_path is not None else {}
    style_seed = _style_seed_from(packet, user_prompt)
    answered_by = (
        answered_by_override
        or answers.get("answered_by")
        or _answer_text(answers_payload.get("answered_by") if isinstance(answers_payload, dict) else None)
        or "user"
    )
    if answered_by not in {"user", "inferred", "best_judgment"}:
        answered_by = "user"

    user_intake = _build_user_intake(
        answers=answers,
        packet=packet,
        answered_by=answered_by,
        stable_prompt_id=style_seed,
    )
    choice_resolution_seed = _build_choice_resolution_seed(
        user_intake=user_intake,
        packet=packet,
        stable_prompt_id=style_seed,
    )
    atom_context = _packet_atom_context(packet)

    changed_files: list[str] = []
    touched_fields: dict[str, list[str]] = {}

    design_path = workspace / "design_brief.json"
    design = _load_json(design_path, {})
    if not isinstance(design, dict):
        raise SystemExit(f"{design_path} must contain a JSON object.")
    design["user_intake"] = user_intake
    if choice_resolution_seed:
        design["choice_resolution_seed"] = choice_resolution_seed
        touched_fields.setdefault("design_brief.json", []).append("choice_resolution_seed")
    if style_seed or atom_context:
        style_system = design.get("style_system")
        if not isinstance(style_system, dict):
            style_system = {}
            design["style_system"] = style_system
    else:
        style_system = {}
    if style_seed:
        if style_system.get("style_seed") != style_seed:
            style_system["style_seed"] = style_seed
            touched_fields.setdefault("design_brief.json", []).append("style_system.style_seed")
    if atom_context:
        style_atom_updates = {
            "style_atom_context": atom_context,
            "style_atom_composition": atom_context.get("style_atom_composition") or {},
            "style_atom_preferred_variants": atom_context.get("preferred_variants") or [],
            "style_atom_narrative_arc": atom_context.get("narrative_arc") or [],
        }
        changed = _merge_missing(style_system, style_atom_updates, overwrite=overwrite_translations)
        if changed:
            touched_fields.setdefault("design_brief.json", []).extend(
                f"style_system.{key}" for key in changed
            )
        changed = _merge_missing(
            design,
            {"style_atom_composition": atom_context.get("style_atom_composition") or {}},
            overwrite=overwrite_translations,
        )
        if changed:
            touched_fields.setdefault("design_brief.json", []).extend(changed)

    style_direction = _answer_text(user_intake.get("style_direction"))
    density = _answer_text(user_intake.get("density"))
    palette = _answer_text(user_intake.get("palette"))
    background = _answer_text(user_intake.get("background_visuals"))
    source_policy = _answer_text(user_intake.get("source_policy"))
    evidence_assets = _answer_text(user_intake.get("evidence_assets"))

    design_modulation = design.get("design_modulation")
    if not isinstance(design_modulation, dict):
        design_modulation = {}
        design["design_modulation"] = design_modulation
    modulation_updates = {
        "change_intensity": "subtle",
        "density_strategy": density,
        "accent_strategy": palette,
        "figure_table_treatment": "figure-first"
        if "figure" in style_direction.lower() or "report" in style_direction.lower()
        else "",
        "container_strategy": "evidence-first layouts before generic cards"
        if evidence_assets or "report" in style_direction.lower()
        else "",
    }
    changed = _merge_missing(design_modulation, modulation_updates, overwrite=overwrite_translations)
    if changed:
        touched_fields.setdefault("design_brief.json", []).extend(f"design_modulation.{key}" for key in changed)

    visual_system = design.get("visual_system")
    if not isinstance(visual_system, dict):
        visual_system = {}
        design["visual_system"] = visual_system
    visual_updates = {
        "palette_direction": palette,
        "background_visuals": background,
        "source_policy": source_policy,
        "evidence_assets": evidence_assets,
    }
    changed = _merge_missing(visual_system, visual_updates, overwrite=overwrite_translations)
    if changed:
        touched_fields.setdefault("design_brief.json", []).extend(f"visual_system.{key}" for key in changed)

    title_page = design.get("title_page_concept")
    if not isinstance(title_page, dict):
        title_page = {}
        design["title_page_concept"] = title_page
    title_updates = {
        "chosen_archetype": "lab-plate" if "figure" in style_direction.lower() or "report" in style_direction.lower() else "editorial masthead",
        "dominant_element": style_direction or "topic-specific opening idea",
        "supporting_element": background or evidence_assets or "audience-specific context",
    }
    changed = _merge_missing(title_page, title_updates, overwrite=overwrite_translations)
    if changed:
        touched_fields.setdefault("design_brief.json", []).extend(f"title_page_concept.{key}" for key in changed)

    renderer = design.get("renderer_treatments")
    if not isinstance(renderer, dict):
        renderer = {}
        design["renderer_treatments"] = renderer
    renderer_updates = {
        "header_mode": "lab-clean" if "figure" in style_direction.lower() or "report" in style_direction.lower() else "",
        "header_variant": "auto" if "figure" in style_direction.lower() or "report" in style_direction.lower() else "",
        "footer_mode": "source-line" if source_policy else "",
        "figure_table_treatment": "figure-first" if "figure" in style_direction.lower() or "report" in style_direction.lower() else "",
    }
    changed = _merge_missing(renderer, renderer_updates, overwrite=overwrite_translations)
    if changed:
        touched_fields.setdefault("design_brief.json", []).extend(f"renderer_treatments.{key}" for key in changed)

    if _write_json_if_changed(design_path, design, dry_run=dry_run):
        changed_files.append(str(design_path))

    content_path = workspace / "content_plan.json"
    content = _load_json(content_path, {})
    if not isinstance(content, dict):
        raise SystemExit(f"{content_path} must contain a JSON object.")
    content_updates = {
        "audience": _answer_text(user_intake.get("audience_context")),
        "decision_target": _answer_text(user_intake.get("target_outcome")),
    }
    changed = _merge_missing(content, content_updates, overwrite=overwrite_translations)
    if changed:
        touched_fields["content_plan.json"] = changed
    if _write_json_if_changed(content_path, content, dry_run=dry_run):
        changed_files.append(str(content_path))

    evidence_path = workspace / "evidence_plan.json"
    evidence = _load_json(evidence_path, {})
    if not isinstance(evidence, dict):
        raise SystemExit(f"{evidence_path} must contain a JSON object.")
    changed = _merge_missing(evidence, {"source_policy": source_policy}, overwrite=overwrite_translations)
    if changed:
        touched_fields["evidence_plan.json"] = changed
    if _write_json_if_changed(evidence_path, evidence, dry_run=dry_run):
        changed_files.append(str(evidence_path))

    asset_path = workspace / "asset_plan.json"
    asset = _load_json(asset_path, {})
    if not isinstance(asset, dict):
        raise SystemExit(f"{asset_path} must contain a JSON object.")
    asset_posture = asset.get("asset_posture")
    if not isinstance(asset_posture, dict):
        asset_posture = {}
        asset["asset_posture"] = asset_posture
    asset_updates = {
        "palette": palette,
        "background_visuals": background,
        "evidence_assets": evidence_assets,
        "source_policy": source_policy,
    }
    changed = _merge_missing(asset_posture, asset_updates, overwrite=overwrite_translations)
    if changed:
        touched_fields["asset_plan.json"] = [f"asset_posture.{key}" for key in changed]
    if _write_json_if_changed(asset_path, asset, dry_run=dry_run):
        changed_files.append(str(asset_path))

    notes_path = workspace / "notes.md"
    existing_notes = notes_path.read_text(encoding="utf-8") if notes_path.exists() else ""
    new_notes = _replace_notes_section(
        existing_notes,
        _notes_section(
            user_intake,
            style_seed=style_seed,
            choice_resolution_seed=choice_resolution_seed,
        ),
    )
    if _write_text_if_changed(notes_path, new_notes, dry_run=dry_run):
        changed_files.append(str(notes_path))

    return {
        "workflow": "deck_intake_answers_apply_v1",
        "workspace": str(workspace),
        "answers_path": str(answers_path),
        "packet_path": str(packet_path) if packet_path is not None else None,
        "answers_sha256": _file_sha256(answers_path) if answers_path.exists() else "",
        "packet_sha256": _file_sha256(packet_path) if packet_path is not None and packet_path.exists() else "",
        "answers_snapshot": _file_snapshot(workspace, answers_path),
        "packet_snapshot": _file_snapshot(workspace, packet_path),
        "stable_prompt_id": style_seed,
        "answered_by": answered_by,
        "user_intake": user_intake,
        "choice_resolution_seed": choice_resolution_seed,
        "choice_resolution_seed_applied": bool(choice_resolution_seed),
        "changed_files": changed_files,
        "changed_file_count": len(changed_files),
        "touched_fields": touched_fields,
        "dry_run": dry_run,
    }


def main() -> int:
    parser = argparse.ArgumentParser(
        description="Persist deck intake answers into reusable workspace planning files."
    )
    parser.add_argument("--workspace", required=True, help="Deck workspace directory")
    parser.add_argument("--answers", required=True, help="JSON file with question-card answers")
    parser.add_argument("--packet", help="Optional deck_start_packet.json from emit_deck_start_packet.py")
    parser.add_argument("--user-prompt", default="", help="Original user request, used only if no packet seed exists")
    parser.add_argument(
        "--answered-by",
        choices=["user", "inferred", "best_judgment"],
        help="Override answer provenance stored in design_brief.user_intake",
    )
    parser.add_argument(
        "--overwrite-translations",
        action="store_true",
        help="Overwrite existing derived design/evidence/asset fields instead of only filling blanks.",
    )
    parser.add_argument("--dry-run", action="store_true", help="Emit report without writing files")
    parser.add_argument("--report", help="Optional path for JSON report")
    args = parser.parse_args()

    workspace = Path(args.workspace).expanduser().resolve()
    answers_path = Path(args.answers).expanduser().resolve()
    packet_path = Path(args.packet).expanduser().resolve() if args.packet else None

    report = apply_answers(
        workspace=workspace,
        answers_path=answers_path,
        packet_path=packet_path,
        user_prompt=args.user_prompt,
        answered_by_override=args.answered_by,
        overwrite_translations=args.overwrite_translations,
        dry_run=args.dry_run,
    )
    text = json.dumps(report, indent=2, ensure_ascii=False) + "\n"
    if args.report:
        report_path = Path(args.report).expanduser().resolve()
        report_path.parent.mkdir(parents=True, exist_ok=True)
        report_path.write_text(text, encoding="utf-8")
    else:
        print(text, end="")
    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