Skip to content

amazon-science/ammo / ai_cli_session/.codex/skills/ammo

Profile and optimize GPU kernels for vLLM inference on NVIDIA GPUs. Use when targeting a specific model, hardware, dtype, parallelism, and workload to improve latency.

FileKindSize
RUNTIME.mdmarkdown4.9 KB
SKILL.mdskill md18.5 KB
agents/ammo-auditor.mdmarkdown9.1 KB
agents/ammo-champion.mdmarkdown9.6 KB
agents/ammo-delegate.mdmarkdown3.2 KB
agents/ammo-implementer.mdmarkdown13.8 KB
agents/ammo-investigator.mdmarkdown4.0 KB
agents/ammo-report.mdmarkdown2.9 KB
agents/ammo-researcher.mdmarkdown10.3 KB
agents/ammo-resolver.mdmarkdown4.4 KB
agents/ammo-transcript-monitor.mdmarkdown7.8 KB
agents/openai.yamlexecutablescript313 B
data/ATTRIBUTION.mdmarkdown1.4 KB
data/gsm8k_full.jsonexecutablescript735.5 KB
data/gsm8k_subset.jsonexecutablescript116.8 KB
eval/EVAL-SKILL.mdexecutablescript21.8 KB
eval/agents/transcript_grader.mdexecutablescript18.0 KB
eval/causal/__init__.pyexecutablescript137 B
eval/causal/agents/causal_analyzer.mdexecutablescript10.5 KB
eval/causal/build_dag.pyexecutablescript21.6 KB
eval/causal/diff_versions.pyexecutablescript38.5 KB
eval/causal/extract_events.pyexecutablescript36.3 KB
eval/causal/generate_postmortem.pyexecutablescript17.0 KB
eval/causal/score_nodes.pyexecutablescript21.5 KB
eval/causal/templates/narrative_template.mdexecutablescript472 B
eval/causal/templates/viz_template.htmlexecutablescript9.5 KB
eval/causal/tests/__init__.pyexecutablescript151 B
eval/causal/tests/conftest.pyexecutablescript448 B
eval/causal/tests/fixtures/sample_session.jsonlexecutablescript10.4 KB
eval/causal/tests/fixtures/sample_session_data.jsonexecutablescript3.4 KB
eval/causal/tests/fixtures/sample_snapshot.jsonexecutablescript2.5 KB
eval/causal/tests/test_build_dag.pyexecutablescript2.7 KB
eval/causal/tests/test_diff_versions.pyexecutablescript13.5 KB
eval/causal/tests/test_extract_events.pyexecutablescript3.7 KB
eval/causal/tests/test_generate_postmortem.pyexecutablescript3.1 KB
eval/causal/tests/test_score_nodes.pyexecutablescript3.3 KB
eval/scripts/aggregate_versions.pyexecutablescript15.2 KB
eval/scripts/archive_run.pyexecutablescript9.1 KB
eval/scripts/codex_session.pyexecutablescript10.6 KB
eval/scripts/generate_dashboard.pyexecutablescript5.3 KB
eval/scripts/parse_artifacts.pyexecutablescript48.1 KB
eval/scripts/parse_session_logs.pyexecutablescript51.3 KB
eval/scripts/rescore_archived.pyexecutablescript5.5 KB
eval/scripts/score_campaign.pyexecutablescript43.8 KB
eval/scripts/snapshot_changes.pyexecutablescript11.1 KB
eval/scripts/verify_citations.pyexecutablescript8.8 KB
eval/tests/test_dashboard_bugs.pyexecutablescript8.8 KB
eval/tests/test_parse_session_logs.pyexecutablescript3.9 KB
eval/tests/test_parse_session_logs_round_inference.pyexecutablescript11.0 KB
eval/tests/test_score_campaign_diluted.pyexecutablescript9.4 KB
eval/viewer/dashboard_template.htmlexecutablescript15.1 KB
instrumentation/sitecustomize.pyexecutablescript3.6 KB
orchestration/audit-protocol.mdmarkdown9.3 KB
orchestration/debate-protocol.mdmarkdown11.2 KB
orchestration/integration-logic.mdmarkdown10.3 KB
orchestration/parallel-tracks.mdmarkdown8.9 KB
references/artifact-layout.mdexecutablescript22.4 KB
references/audit-invariants.mdmarkdown10.6 KB
references/champion-common-patterns.mdmarkdown3.4 KB
references/crossover-probing.mdexecutablescript4.7 KB
references/cudagraph-safety.mdmarkdown2.7 KB
references/debate-rules.mdmarkdown4.7 KB
references/debate-scoring-rubric.mdexecutablescript16.7 KB
references/e2e-delta-math.mdexecutablescript17.9 KB
references/e2e-latency-guide.mdexecutablescript9.6 KB
references/fusion-feasibility-heuristics.mdmarkdown5.6 KB
references/gpu-pool.mdexecutablescript5.4 KB
references/impl-track-rules.mdexecutablescript13.8 KB
references/nsys-profiling-guide.mdmarkdown9.8 KB
references/optimization-categories.mdexecutablescript11.0 KB
references/shutdown-protocol.mdexecutablescript3.1 KB
references/technology-selection.mdmarkdown5.0 KB
references/torch-compile-contract.mdmarkdown13.8 KB
references/validation-defaults.mdexecutablescript34.2 KB
references/workload-invocation.mdexecutablescript4.9 KB
references/writing-style.mdexecutablescript6.9 KB
scripts/ammo_state.pyexecutablescript142.0 KB
scripts/artifact_layout.jsonconfig16.3 KB
scripts/check_projection_accuracy.pyexecutablescript11.7 KB
scripts/create_evidence_template.pyexecutablescript9.7 KB
scripts/create_worktree_with_build.shexecutablescript10.2 KB
scripts/generate_validation_report.pyexecutablescript35.7 KB
scripts/gpu_reservation.pyexecutablescript27.1 KB
scripts/hook_cmd_classify.pyscript13.3 KB
scripts/mine_trace.pyscript29.4 KB
scripts/monitor_queue_ack.pyexecutablescript6.1 KB
scripts/ncu_sanity.shexecutablescript5.2 KB
scripts/ncu_sanity_driver.pyexecutablescript8.5 KB
scripts/new_target.pyexecutablescript22.0 KB
scripts/preflight_vllm_api.pyexecutablescript12.3 KB
scripts/reconcile_track_state.pyexecutablescript15.8 KB
scripts/remove_worktree_cleanup.shexecutablescript1.1 KB
scripts/resolve_codex_transcript.pyexecutablescript3.6 KB
scripts/run_vllm_bench_latency_sweep.pyexecutablescript249.6 KB
scripts/transcript_filter.pyexecutablescript38.4 KB
scripts/transitions.jsonexecutablescript1.5 KB
scripts/verify_validation_gates.pyexecutablescript88.8 KB
tests/agents/test-champion.mdexecutablescript20.4 KB
tests/agents/test-impl-champion.mdexecutablescript14.3 KB
tests/agents/test-implementer.mdexecutablescript15.8 KB
tests/agents/test-orchestrator.mdexecutablescript33.8 KB
tests/agents/test-researcher.mdexecutablescript21.0 KB
tests/agents/test-transcript-monitor.mdexecutablescript13.4 KB
tests/fixtures/diluted_pass/legacy_no_phase.golden.mdmarkdown1.1 KB
tests/fixtures/diluted_pass/legacy_no_phase.golden.summary.jsonconfig582 B
tests/fixtures/diluted_pass/legacy_no_phase.jsonconfig400 B
tests/fixtures/diluted_pass/legacy_scalar_phase.golden.mdmarkdown2.0 KB
tests/fixtures/diluted_pass/legacy_scalar_phase.golden.summary.jsonconfig1.0 KB
tests/fixtures/diluted_pass/legacy_scalar_phase.jsonconfig626 B
tests/fixtures/mining/real_campaign_bottleneck_analysis.mdmarkdown20.7 KB
tests/run_all.shexecutablescript1.6 KB
tests/scripts/test_transcript_filter.pyexecutablescript41.1 KB
tests/test_agent_runtime_contracts.pyexecutablescript1.8 KB
tests/test_ammo_state.pyexecutablescript71.7 KB
tests/test_artifact_layout_manifest.pyscript11.6 KB
tests/test_audit_started.pyscript18.2 KB
tests/test_correctness_comparator.pyscript12.6 KB
tests/test_diluted_pass.pyscript24.4 KB
tests/test_drift_compat.pyscript5.1 KB
tests/test_evidence_freshness.pyexecutablescript5.6 KB
tests/test_fail_closed.pyexecutablescript14.7 KB
tests/test_gpu_reservation.pyexecutablescript24.8 KB
tests/test_gpu_reservation_session_id.pyexecutablescript11.2 KB
tests/test_guidance_semantic_contract.pyscript24.9 KB
tests/test_hook_cmd_classify_parity.pyscript11.7 KB
tests/test_hook_semantics.pyexecutablescript95.3 KB
tests/test_mine_trace.pyscript24.2 KB
tests/test_mining_invalidated_schema.pyexecutablescript9.4 KB
tests/test_new_target_dp_ep.pyexecutablescript7.4 KB
tests/test_new_target_v2_scaffold.pyexecutablescript13.1 KB
tests/test_parse_artifacts.pyexecutablescript3.0 KB
tests/test_policy_convergence.pyscript797 B
tests/test_preflight_vllm_api.pyscript13.3 KB
tests/test_projection_accuracy_v2.pyexecutablescript4.1 KB
tests/test_reconcile_track_state.pyexecutablescript18.2 KB
tests/test_resolve_codex_transcript.pyexecutablescript3.1 KB
tests/test_state_schema_semantics.pyexecutablescript7.6 KB
tests/test_status_set_sync.pyexecutablescript9.1 KB
tests/test_sweep_baseline_from_arm.pyscript11.0 KB
tests/test_sweep_decode_capture.pyexecutablescript31.8 KB
tests/test_sweep_dp.pyexecutablescript45.4 KB
tests/test_sweep_fresh_cache.pyscript5.5 KB
tests/test_sweep_profiler_guard.pyscript22.6 KB
tests/test_sweep_real_prompts.pyscript20.1 KB
tests/test_sweep_refactor.pyexecutablescript37.6 KB
tests/test_sweep_round_slot.pyexecutablescript7.4 KB
tests/test_validation_report_phase_triage.pyexecutablescript10.0 KB
tests/test_validation_report_v2.pyexecutablescript6.2 KB
tests/test_verify_validation_gates.pyexecutablescript52.9 KB
tests/test_workload_matrix.pyexecutablescript19.3 KB

tests/test_guidance_semantic_contract.py

View on GitHub
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: CC-BY-NC-4.0
"""Semantic-preservation checks for the concise AMMO guidance layout.

These tests intentionally assert topology, authority, and machine-facing
contracts rather than duplicated prose sentences.
"""

from __future__ import annotations

import copy
import importlib.util
import json
import re
import sys
import tomllib
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
REPO = ROOT.parents[2]
SKILL = (ROOT / "SKILL.md").read_text(encoding="utf-8")


def _text(relative: str) -> str:
    return (ROOT / relative).read_text(encoding="utf-8")


def _words(path: Path) -> int:
    return len(path.read_text(encoding="utf-8").split())


def _state_engine():
    path = ROOT / "scripts" / "ammo_state.py"
    spec = importlib.util.spec_from_file_location("ammo_state_contract", path)
    assert spec and spec.loader
    module = importlib.util.module_from_spec(spec)
    sys.modules[spec.name] = module
    spec.loader.exec_module(module)
    return module


def _minimal_runtime_state(stage="1_baseline", status="active") -> dict:
    return {
        "campaign": {
            "schema_version": "4.1",
            "status": status,
            "current_round": 1,
            "current_stage": stage,
            "config": {},
            "rounds": [
                {
                    "status": "IN_PROGRESS",
                    "audit": {},
                    "parallel_tracks": {"tracks": {}},
                    "integration": {"status": "pending"},
                    "debate": {"selected_candidates": []},
                    "bottleneck_mining": {},
                }
            ],
        }
    }


def test_stage_graph_and_all_roles_are_preserved() -> None:
    stages = [
        "1_baseline",
        "2_bottleneck_mining",
        "3_debate",
        "4_5_parallel_tracks",
        "6_integration",
        "7_campaign_eval",
        "7b_report",
    ]
    positions = [SKILL.index(stage) for stage in stages]
    assert positions == sorted(positions)

    roles = {
        "ammo-auditor",
        "ammo-champion",
        "ammo-delegate",
        "ammo-implementer",
        "ammo-investigator",
        "ammo-researcher",
        "ammo-resolver",
        "ammo-transcript-monitor",
        "ammo-report",
    }
    for role in roles:
        assert role in SKILL
        assert (ROOT / "agents" / f"{role}.md").is_file()
        assert (REPO / ".codex" / "agents" / f"{role}.toml").is_file()
    assert "ammo-impl-champion" in SKILL
    assert "ammo-report-writer" in SKILL

    for path in sorted((REPO / ".codex" / "agents").glob("ammo-*.toml")):
        bootstrap = tomllib.loads(path.read_text(encoding="utf-8"))[
            "developer_instructions"
        ]
        assert ".codex/skills/ammo/SKILL.md" in bootstrap
        assert "Claude AMMO is the policy source of truth" not in bootstrap


def test_agent_judgment_is_not_replaced_by_deterministic_code() -> None:
    assert "Preserve agent judgment" in SKILL
    assert "mechanical invariants" in SKILL
    assert "never substitutes for an agent's technical review" in SKILL
    assert "You are the lead orchestrator" in SKILL
    assert "you never implement" in SKILL


def test_stage1_clean_timing_and_profiling_remain_separate() -> None:
    researcher = _text("agents/ammo-researcher.md")
    assert "exactly two separate sweep invocations" in researcher
    assert "clean authoritative E2E timing" in researcher
    assert "bounded attribution profiling" in researcher
    assert "Never use profiler-run latency as official timing" in researcher
    assert "## Technology Landscape" in researcher
    assert "top three addressable kernel opportunities by `f_e2e × removable_fraction`" in researcher
    assert "`f_decode` as a diagnostic column" in researcher
    assert "## Workload Dilution (per BS)" in researcher
    assert "## Top Components (by f_e2e)" in researcher


def test_stage3_multi_champion_debate_and_scope_challenge_remain() -> None:
    champion = _text("agents/ammo-champion.md")
    debate = _text("orchestration/debate-protocol.md")
    assert "2-4 `ammo-champion`" in SKILL
    assert "2-3" in champion
    assert "Analyze every component" in champion
    assert "do not recapture or broaden it in Stage 3" in champion
    assert "Bounded, claim-driven single-kernel Nsys/NCU evidence remains allowed" in champion
    for marker in (
        "Technology Selection",
        "Category block",
        "Precision Classification",
        "## Open Items Declaration",
        "critique",
        "rebuttal",
    ):
        assert marker in champion
    assert "cannot self-close a boundary-scope objection" in champion
    assert "only by the lead or critic" in SKILL
    assert "## Convergence Criteria" in debate
    assert "## Winner Selection" in debate


def test_evidence_scope_and_projection_authorities_are_preserved() -> None:
    rules = _text("references/debate-rules.md")
    math = _text("references/e2e-delta-math.md")
    scoring = _text("references/debate-scoring-rubric.md")
    assert "## Evidence-Scope Ladder" in rules
    assert "`proxy`" in rules
    assert "`production_boundary`" in rules
    assert "clean_e2e" in rules
    assert "proxy-scope" in scoring or "proxy" in scoring
    assert "f_e2e = f_decode × decode_busy × decode_share_of_e2e" in math
    assert "T_component_old / T_component_new" in math
    assert "T_component_new / T_component" not in math
    assert "**Non-overlap rule.**" in math


def test_implementation_gates_slots_and_fallback_remain() -> None:
    implementer = _text("agents/ammo-implementer.md")
    validation = _text("references/validation-defaults.md")
    protocol = _text("orchestration/debate-protocol.md")
    for gate in ("Gate 5.1a", "Gate 5.1b", "Gate 5.2", "Gate 5.3a", "Gate 5.3b"):
        assert gate in implementer
    for slot in ("opt_correctness/{op_id}", "opt_profiling/{op_id}", "opt/{op_id}"):
        assert slot in implementer
        assert slot in validation
    assert "claim-appropriate profiler evidence" in implementer
    assert "Nsys is normally sufficient" in implementer
    assert "complete blocking validation contract" in implementer
    assert "complete blocking validation contract" in protocol
    assert "Proposal prose may recommend" in implementer
    assert "clean timing vs the Stage 1 baseline" in implementer
    assert "never re-run a baseline arm from the worktree" in implementer
    assert "pure inter-kernel host/dispatch" in implementer
    assert "Gate 5.1b remains mandatory" in implementer
    assert "PASS -> GATED_PASS -> GATING_REQUIRED -> RETRY_WITH_CONTINGENCY -> FAIL" in implementer
    assert "DILUTED_PASS" in implementer
    assert "ammo-investigator" in implementer


def test_monitor_is_continuous_read_only_and_machine_compatible() -> None:
    monitor = _text("agents/ammo-transcript-monitor.md")
    assert "read-only" in monitor
    assert "event-driven reads" in monitor
    assert "bounded adaptive" in monitor
    assert "full-lifetime coverage" in monitor
    assert "transcript_offsets.json" in monitor
    assert "target_session_id" in monitor
    assert "target_rollout_id" in monitor
    assert '"emitter":"ammo-transcript-monitor"' in monitor
    assert "summary" in monitor and "poll count" in monitor
    assert "never edit source, tests, gate results, `state.json`" in monitor
    assert "does not author" in monitor or "authors the verdict" in monitor
    assert "Accuracy-Failure Persistence" in monitor
    assert "unreadable-target, collision" in monitor
    dispatch = _text("orchestration/parallel-tracks.md")
    assert "op_id: `{op_id}`" in dispatch
    assert "worktree_branch: `{worktree_branch}`" in dispatch
    assert "absolute worktree path" in dispatch


def test_four_independent_audits_and_two_phase_order_remain() -> None:
    auditor = _text("agents/ammo-auditor.md")
    protocol = _text("orchestration/audit-protocol.md")
    for trigger in ("T_AUDIT_S1", "T_AUDIT_S2", "T_AUDIT_S45", "T_AUDIT_S67"):
        assert trigger in SKILL
        assert trigger in protocol
    assert auditor.index("## Phase 1 - Independent Reconstruction") < auditor.index(
        "## Phase 2 - Checklist Verification"
    )
    assert "Do **not** read `references/audit-invariants.md` at spawn" in auditor
    assert "{stage}_cycle_{N}.md" in auditor
    assert "stage_67.md" in auditor
    assert "ammo-delegate" in auditor
    assert "not blocking by itself" in auditor


def test_investigator_resolver_and_report_review_remain() -> None:
    investigator = _text("agents/ammo-investigator.md")
    resolver = _text("agents/ammo-resolver.md")
    report = _text("agents/ammo-report.md")
    assert "read-only" in investigator
    assert "decision_support" in investigator
    assert "ROOT CAUSE IDENTIFIED" in investigator
    assert "fresh, independent DA reviewer" in resolver
    assert "Post-Merge Testing" in resolver
    assert "fresh `ammo-delegate` fact-checker" in report
    assert "report_fact_check.json" in report
    assert "`ok:true`" in report
    assert "report_sha256" in report
    report_authority = _text("report/SKILL.md")
    for path in (
        "rounds/{N}/constraints.md",
        "rounds/{N}/mining/bottleneck_analysis.md",
        "rounds/{N}/sweeps/opt_profiling/{op_id}/",
        "rounds/{N}/sweeps/opt_correctness/{op_id}/",
        "rounds/{N}/sweeps/opt/{op_id}/",
    ):
        assert path in report_authority
    assert "highest version" not in report_authority


def test_integration_and_campaign_loop_semantics_remain() -> None:
    integration = _text("orchestration/integration-logic.md")
    assert "## Single-Track Short-Circuit" in integration
    assert "## Combined Validation Workflow" in integration
    assert "ammo-resolver" in integration
    assert "direct" in SKILL and "never multiply round deltas" in SKILL
    assert "stop iff" in SKILL
    assert "top_addressable_e2e_pct" in SKILL
    assert "After SHIP" in SKILL and "After EXHAUSTED" in SKILL
    assert "mining_invalidated:true" in SKILL
    assert "exhausted_technologies" in SKILL
    assert "integration_profiling" in integration
    assert "use `campaign_complete` after a SHIP" in SKILL
    assert "`campaign_exhausted` after an EXHAUSTED" in SKILL


def test_schema_and_transition_enums_stay_authoritative() -> None:
    schema = json.loads((REPO / ".codex" / "schemas" / "state.schema.json").read_text())
    transitions = json.loads((ROOT / "scripts" / "transitions.json").read_text())
    stages = [
        "1_baseline",
        "2_bottleneck_mining",
        "3_debate",
        "4_5_parallel_tracks",
        "6_integration",
        "7_campaign_eval",
        "7b_report",
    ]
    assert schema["properties"]["campaign"]["properties"]["current_stage"][
        "enum"
    ] == stages
    assert transitions["stage_ladder"] == stages
    track = schema["properties"]["campaign"]["properties"]["rounds"]["items"][
        "properties"
    ]["parallel_tracks"]["properties"]["tracks"]["additionalProperties"]
    terminal = {"PASS", "GATED_PASS", "FAIL"}
    assert set(transitions["track_terminal_statuses"]) == terminal
    assert terminal <= set(track["properties"]["status"]["enum"])
    selected = schema["properties"]["campaign"]["properties"]["rounds"][
        "items"
    ]["properties"]["debate"]["properties"]["selected_candidates"]["items"]
    assert "proposal_file" in selected["required"]
    assert "SKIPPED" in track["properties"]["gate_5_1a"]["enum"]
    assert "gate_5_1a_skip_reason" in track["properties"]
    schema_text = json.dumps(schema, sort_keys=True)
    for status in ("IN_PROGRESS", "PASS", "GATING_REQUIRED", "GATED_PASS", "FAIL", "GPU_BLOCKED"):
        assert status in schema_text


def test_retired_hook_names_and_bare_python3_are_absent_from_active_guidance() -> None:
    active = [ROOT / "SKILL.md"]
    active += sorted((ROOT / "agents").glob("*.md"))
    active += sorted((ROOT / "orchestration").glob("*.md"))
    active += sorted((ROOT / "references").glob("*.md"))
    text = "\n".join(path.read_text(encoding="utf-8") for path in active)
    for retired in (
        "ammo-state-validate.sh",
        "ammo-next-step-reminder.sh",
        "ammo-pretool-guard.sh",
        "ammo-artifact-layout-warn.sh",
    ):
        assert retired not in text
    assert not re.search(r"(?m)^\s*python3?\b", text)
    for dead in ("kernel-benchmark-template.py", "ammo-validate-researcher-dilution.sh"):
        assert dead not in text


def test_progressive_disclosure_reduces_hot_path_without_deleting_roles() -> None:
    assert _words(ROOT / "SKILL.md") < 2500
    role_words = sum(_words(path) for path in (ROOT / "agents").glob("*.md"))
    assert role_words < 9000
    assert not (ROOT / "README.md").exists()


def test_changed_markdown_fences_are_balanced() -> None:
    for path in ROOT.rglob("*.md"):
        assert path.read_text(encoding="utf-8").count("```") % 2 == 0, path


def test_active_relative_markdown_links_resolve() -> None:
    docs = [ROOT / "SKILL.md", ROOT / "report" / "SKILL.md"]
    docs += sorted((ROOT / "agents").glob("*.md"))
    docs += sorted((ROOT / "orchestration").glob("*.md"))
    docs += sorted((ROOT / "references").glob("*.md"))
    pattern = re.compile(r"`((?:agents|orchestration|references)/[^`*]+\.md)`")
    for doc in docs:
        for relative in pattern.findall(doc.read_text(encoding="utf-8")):
            assert (ROOT / relative).is_file(), f"{doc}: {relative}"


def test_terminal_report_stop_guard_requires_accepted_fact_check() -> None:
    guard = (REPO / ".codex" / "hooks" / "stop_gate_guard.py").read_text()
    assert "report_fact_check.json" in guard
    assert 'fact.get("ok") is True' in guard
    assert 'fact.get("report_sha256") == report_sha256' in guard
    assert "Terminal report integrity is never one-shot" in guard


def test_runtime_guidance_dependencies_are_registered() -> None:
    layout = _text("references/artifact-layout.md")
    runner = _text("scripts/run_vllm_bench_latency_sweep.py")
    for slot in (
        "opt/{op_id}",
        "opt_correctness/{op_id}",
        "opt_profiling/{op_id}",
    ):
        assert slot in layout
    assert "def _is_gate_slot" in runner
    assert 'slot.startswith("opt/")' in runner
    assert 'slot.startswith("opt_correctness/")' in runner
    assert 'slot.startswith("opt_profiling/")' in runner
    state_engine = _text("scripts/ammo_state.py")
    assert '"audit": {}' in state_engine
    post_hook = (REPO / ".codex" / "hooks" / "post_tool_use_guard.py").read_text()
    assert '"_partial_" not in path.name' in post_hook


def test_runtime_fail_closed_policy_invariants_bind() -> None:
    engine = _state_engine()
    transitions = engine.load_transitions()

    previous = _minimal_runtime_state()
    jumped = copy.deepcopy(previous)
    jumped["campaign"]["current_stage"] = "7b_report"
    assert "not adjacent" in engine.gate_violation(jumped, transitions, previous)

    selection = copy.deepcopy(previous)
    selection["campaign"]["rounds"][0]["debate"]["selected_candidates"] = [
        {"op_id": "OP-X", "score_breakdown": {}}
    ]
    assert "no category token" in engine.gate_violation(
        selection, transitions, previous
    )
    selection["campaign"]["rounds"][0]["debate"]["selected_candidates"][0][
        "category"
    ] = "kernel_replacement"
    assert "no score_breakdown.evidence_scope" in engine.gate_violation(
        selection, transitions, previous
    )

    terminal = _minimal_runtime_state("7_campaign_eval", "campaign_exhausted")
    terminal_round = terminal["campaign"]["rounds"][0]
    terminal_round["audit"] = {"stage_67": {"passed_at": "now"}}
    terminal["campaign"]["config"]["min_e2e_improvement_pct"] = 0.5
    terminal_round["bottleneck_mining"]["top_f_e2e_pct"] = 10.0
    terminal_round["bottleneck_mining"]["top_addressable_e2e_pct"] = 0.49
    assert "requires integration status exhausted or failed" in engine.gate_violation(
        terminal, transitions
    )
    terminal_round["integration"]["status"] = "exhausted"
    assert engine.gate_violation(terminal, transitions) is None

    for value in (None, 0.5, 0.6):
        blocked = copy.deepcopy(terminal)
        blocked["campaign"]["rounds"][0]["bottleneck_mining"][
            "top_addressable_e2e_pct"
        ] = value
        assert "Terminal-status violation" in engine.gate_violation(
            blocked, transitions
        )

    shipped = copy.deepcopy(terminal)
    shipped["campaign"]["status"] = "campaign_complete"
    shipped["campaign"]["rounds"][0]["integration"]["status"] = "combined"
    assert engine.gate_violation(shipped, transitions) is None

    parsed = engine.parse_mining_md(
        "| Component | f_e2e | f_e2e x (1-1/ceiling) |\n"
        "|---|---|---|\n| moe | 0.30 | 0.0049 |"
    )
    assert parsed["top_f_e2e_pct"] == 30.0
    assert parsed["top_addressable_e2e_pct"] == 0.49
    assert parsed["top_f_decode_pct"] is None

    reused = copy.deepcopy(terminal)
    reused["campaign"]["rounds"].append(
        {
            "bottleneck_mining": {},
            "audit": {"stage_67": {"passed_at": "now"}},
            "integration": {"status": "exhausted"},
        }
    )
    reused["campaign"]["current_round"] = 2
    assert engine.gate_violation(reused, transitions) is None


def test_selected_cohort_and_monitor_pairing_fail_closed() -> None:
    engine = _state_engine()
    transitions = engine.load_transitions()
    empty = _minimal_runtime_state("6_integration")
    empty["campaign"]["schema_version"] = "4.2"
    empty["campaign"]["rounds"][0]["audit"] = {
        "stage_45": {"passed_at": "now", "started_at": "then", "cycle": 1}
    }
    assert "2-3 unique winner ids" in engine.gate_violation(empty, transitions)

    state = _minimal_runtime_state("6_integration")
    state["campaign"]["schema_version"] = "4.2"
    rnd = state["campaign"]["rounds"][0]
    rnd["debate"] = {
        "completed_at": "now",
        "selected_winners": ["OP-X", "OP-Y"],
        "selected_candidates": [
            {"op_id": "OP-X", "selection_mode": "contingent_host_spike"},
            {"op_id": "OP-Y", "selection_mode": "ordinary"},
        ],
    }
    rnd["audit"] = {
        "stage_45": {"passed_at": "now", "started_at": "then", "cycle": 1}
    }

    assert "Cohort violation" in engine.gate_violation(state, transitions)

    rnd["parallel_tracks"]["tracks"] = {
        "OP-X": {"status": "PASS"},
        "OP-Y": {"status": "FAIL"},
    }
    reason = engine.gate_violation(state, transitions)
    assert "pairing evidence" in reason

    for op_id in ("OP-X", "OP-Y"):
        rnd["parallel_tracks"]["tracks"][op_id].update(
            {
                "implementer_agent": f"/root/impl_{op_id}",
                "implementer_rollout_id": f"rollout_{op_id}",
                "monitor_agent": f"/root/monitor_{op_id}",
                "monitor_evidence_path": (
                    f"rounds/1/tracks/{op_id}/monitor_audits/obs.md"
                ),
                "monitor_offsets_path": (
                    f"rounds/1/tracks/{op_id}/monitor_audits/offsets.json"
                ),
                "monitor_summary_path": (
                    f"rounds/1/tracks/{op_id}/monitor_audits/summary.json"
                ),
            }
        )
    rnd["parallel_tracks"]["tracks"]["OP-X"].update(
        {
            "gate_5_2": "PASS",
            "gate_5_2_boundary": {
                "baseline_duration_us": 100.0,
                "optimized_duration_us": 90.0,
                "occurrence_count": 1000,
                "baseline_e2e_us": 2_000_000.0,
                "e2e_equivalent_improvement_pct": 0.5,
                "campaign_floor_pct": 0.5,
                "meets_floor": True,
            },
        }
    )
    state["campaign"]["config"]["min_e2e_improvement_pct"] = 0.5
    assert engine.gate_violation(state, transitions) is None

    duplicate = copy.deepcopy(state)
    duplicate["campaign"]["current_stage"] = "6_integration"
    duplicate["campaign"]["rounds"][0]["debate"]["selected_winners"] = [
        "OP-X", "OP-X"
    ]
    assert "unique winner ids" in engine.gate_violation(duplicate, transitions)

    legacy_prev = _minimal_runtime_state("3_debate")
    legacy_prev_rnd = legacy_prev["campaign"]["rounds"][0]
    legacy_prev_rnd["debate"]["selected_winners"] = ["OP-LEGACY"]
    legacy_prev_rnd["debate"]["selected_candidates"] = [
        {"op_id": "OP-LEGACY"}
    ]
    legacy = copy.deepcopy(legacy_prev)
    legacy["campaign"]["current_stage"] = "4_5_parallel_tracks"
    legacy_rnd = legacy["campaign"]["rounds"][0]
    legacy_rnd["parallel_tracks"]["tracks"] = {
        "OP-LEGACY": {"status": "IN_PROGRESS"}
    }
    assert engine.gate_violation(legacy, transitions, legacy_prev) is None


def test_material_ship_requires_fresh_remine_before_terminal() -> None:
    engine = _state_engine()
    transitions = engine.load_transitions()
    shipped = _minimal_runtime_state("7_campaign_eval", "campaign_complete")
    campaign = shipped["campaign"]
    campaign["config"]["min_e2e_improvement_pct"] = 0.5
    rnd = campaign["rounds"][0]
    rnd["status"] = "SHIPPED"
    rnd["shipped"] = ["OP-X"]
    rnd["parallel_tracks"]["tracks"] = {"OP-X": {"status": "PASS"}}
    rnd["integration"]["status"] = "combined"
    rnd["audit"] = {"stage_67": {"passed_at": "now"}}
    rnd["bottleneck_mining"]["top_addressable_e2e_pct"] = 0.1
    assert "fresh post-promotion" in engine.gate_violation(shipped, transitions)

    post_ship = copy.deepcopy(shipped)
    post_ship["campaign"]["status"] = "active"
    post_ship, new_stage = engine.advance(post_ship, "SHIP", transitions)
    assert new_stage == "2_bottleneck_mining"
    current = post_ship["campaign"]["rounds"][1]
    current["bottleneck_mining"] = {
        "completed_at": "now",
        "top_component": "none",
        "top_bottleneck_share_pct": 0.1,
        "top_f_e2e_pct": 0.1,
        "top_addressable_e2e_pct": 0.1,
        "amdahl_ceiling": 1.001,
        "decode_frac": 0.5,
        "component_breakdown": [],
    }
    current["audit"] = {"stage_2": {"passed_at": "now"}}
    before_eval = copy.deepcopy(post_ship)
    post_ship["campaign"]["current_stage"] = "7_campaign_eval"
    assert engine.gate_violation(post_ship, transitions, before_eval) is None
    post_ship["campaign"]["status"] = "campaign_complete"
    assert engine.gate_violation(post_ship, transitions) is None


def test_all_diluted_ship_and_legacy_backfill_contracts_remain() -> None:
    engine = _state_engine()
    transitions = engine.load_transitions()

    state = _minimal_runtime_state("7_campaign_eval")
    current = state["campaign"]["rounds"][0]
    current["shipped"] = ["OP-X"]
    current["parallel_tracks"]["tracks"] = {
        "OP-X": {"status": "PASS", "diluted": True}
    }
    _, next_stage = engine.advance(state, "SHIP", transitions)
    assert next_stage == "3_debate"

    legacy = _minimal_runtime_state()
    candidate = {
        "op_id": "OP-X",
        "cited_evidence": ["rounds/1/debate/proposals/x_proposal.md"],
        "score_breakdown": {},
    }
    legacy["campaign"]["rounds"][0]["debate"]["selected_candidates"] = [candidate]
    before = copy.deepcopy(legacy)
    engine.backfill(legacy, REPO / "unused", transitions)
    assert candidate["proposal_file"] == "rounds/1/debate/proposals/x_proposal.md"
    assert engine.gate_violation(legacy, transitions, before) is None


def test_removed_authority_headings_are_not_referenced() -> None:
    docs = [ROOT / "SKILL.md"]
    docs += sorted((ROOT / "agents").glob("*.md"))
    docs += sorted((ROOT / "orchestration").glob("*.md"))
    docs += sorted((ROOT / "references").glob("*.md"))
    # Agent-read prose also lives in the engine prompts and the role test packs.
    docs += sorted((ROOT / "scripts").glob("*.py"))
    docs += sorted((ROOT / "tests" / "agents").glob("*.md"))
    for stale in (
        "SKILL.md § Non-Negotiables",
        "SKILL.md § Resume Protocol",
        "SKILL.md § Campaign Loop",
        "Non-Negotiable #",
    ):
        offenders = [
            str(path.relative_to(ROOT))
            for path in docs
            if stale in path.read_text(encoding="utf-8")
        ]
        assert not offenders, "stale authority pointer %r in %s" % (stale, offenders)


def test_progressive_disclosure_pointers_resolve_to_current_headings() -> None:
    pointers = (
        ("orchestration/debate-protocol.md", "## Phase 0: Independent Proposals"),
        ("orchestration/debate-protocol.md", "### Eligibility, revision, and elimination"),
        ("orchestration/debate-protocol.md", "## Debate Sub-Rounds"),
        ("orchestration/parallel-tracks.md", "## Reconciliation and Cohort Barrier"),
        ("orchestration/audit-protocol.md", "## Optional Early S45 Evidence"),
        ("references/champion-common-patterns.md", "## Worktree Environment"),
    )
    for relative, heading in pointers:
        assert heading in _text(relative), f"missing pointer target: {relative} § {heading}"


def test_debate_critique_assignments_remain_independent_under_churn() -> None:
    debate = _text("orchestration/debate-protocol.md")
    assert "never critiqued by" in debate and "champion who proposed it" in debate
    assert "fewer than two distinct champion owners" in debate
    assert "repair every affected cross-owner assignment" in debate
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