Files
cp1-shakedown/shakedown_lib/cp1_agents.py
Jonathan Boniface 099f9a87e8 Runner: run a voyage remotely as the kab-automation identity
- shakedown_lib: runs F01 -> F02 -> F03 for one engagement on KAB with no
  personal token. Signs in as the kab-automation client (client credentials,
  provisioned by Stellwerk from crucible-platform-deploy) and renews the token
  itself.
- Each stage checks its workflow id against the registered sub-agent name,
  builds inputs from the case and upstream stages, starts the run, follows it
  and judges it with cp1-agents evaluate_case.py.
- Gates (plan 5b): in config/runner.yaml gate_projects only, continue on a
  critic pass with no failed step and a note saying the system decided.
  Never on a fail. Elsewhere, wait for a person and record who decided.
  gate_projects is empty for now.
- Ledger per voyage run, with --resume; nothing secret is written.
- Cymbal voyage ENG-CYMBAL-001; workflow registry; Dockerfile and an
  unapplied Job template; 15 tests against a fake KAB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 05:08:31 +00:00

60 lines
1.9 KiB
Python

"""The cp1-agents scripts Shakedown reuses, imported by path from a clone (plan §3: no change to cp1-agents).
`kab_run_workflow.py` gives the run-context helpers (load_context, new_ids, context_uploads, upload_type,
customer_problem, with_run_metadata, check_engagement) and `evaluate_case.py` judges a run against a case. The clone's
commit is recorded with every run, so a result can be reproduced.
"""
from __future__ import annotations
import importlib.util
import os
import subprocess
import sys
from pathlib import Path
from types import ModuleType
DEFAULT_DIR = Path(__file__).resolve().parents[2] / "cp1-agents"
def clone_dir() -> Path:
path = Path(os.getenv("CP1_AGENTS_DIR") or DEFAULT_DIR)
if not (path / "scripts" / "kab_run_workflow.py").is_file():
raise RuntimeError(f"no cp1-agents clone at {path}: set CP1_AGENTS_DIR")
return path
def _load(name: str) -> ModuleType:
scripts = clone_dir() / "scripts"
if str(scripts) not in sys.path:
sys.path.insert(0, str(scripts)) # evaluate_case imports check_data_contract beside it
spec = importlib.util.spec_from_file_location(f"cp1_agents_{name}", scripts / f"{name}.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
_cache: dict[str, ModuleType] = {}
def module(name: str) -> ModuleType:
if name not in _cache:
_cache[name] = _load(name)
return _cache[name]
def run_workflow() -> ModuleType:
return module("kab_run_workflow")
def evaluate_case() -> ModuleType:
return module("evaluate_case")
def commit() -> str | None:
try:
return subprocess.run(["git", "-C", str(clone_dir()), "rev-parse", "HEAD"], capture_output=True, text=True,
check=True).stdout.strip()
except (subprocess.CalledProcessError, FileNotFoundError, RuntimeError):
return None