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>
This commit is contained in:
76
shakedown_lib/__main__.py
Normal file
76
shakedown_lib/__main__.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""Shakedown runner: run a voyage's workflows on KAB remotely, as the kab-automation identity.
|
||||
|
||||
python3 -m shakedown_lib token-check
|
||||
python3 -m shakedown_lib run capabilities/cp1-agentic-landing-zone/voyages/ENG-CYMBAL-001.yaml --dry-run
|
||||
python3 -m shakedown_lib run <voyage.yaml> [--only f02 f03]
|
||||
python3 -m shakedown_lib run <voyage.yaml> --resume ledger/ENG-CYMBAL-001/<started>
|
||||
|
||||
Environment: KAB_CLIENT_SECRET (required), KAB_CLIENT_ID (kab-automation), KAB_TOKEN_URL, KAB_API, KAB_TENANT,
|
||||
CP1_AGENTS_DIR (the cp1-agents clone, default ../cp1-agents), SHAKEDOWN_LEDGER (default ./ledger).
|
||||
Which projects the runner may decide gates in is set only in config/runner.yaml.
|
||||
|
||||
Exit status: 0 done, 2 configuration or KAB refused, 3 stopped for a fix, 4 nobody decided a review point in time,
|
||||
5 a stage ran too long.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from .auth import AuthError, ClientCredentials
|
||||
from .kab import CP1_TENANT, DEFAULT_API, Kab
|
||||
from .ledger import Ledger, default_root
|
||||
from .runner import EXIT_CONFIG, Runner, Settings
|
||||
from .voyage import VoyageError, load_config, load_voyage
|
||||
|
||||
|
||||
def _claims(token: str) -> dict:
|
||||
try:
|
||||
payload = token.split(".")[1]
|
||||
return json.loads(base64.urlsafe_b64decode(payload + "=" * (-len(payload) % 4)))
|
||||
except (IndexError, ValueError):
|
||||
return {}
|
||||
|
||||
|
||||
def token_check() -> int:
|
||||
tokens = ClientCredentials.from_env()
|
||||
claims = _claims(tokens.token())
|
||||
shown = {k: claims.get(k) for k in ("iss", "azp", "email", "preferred_username", "exp")}
|
||||
print(f"Token issued to {tokens.client_id}, valid for {tokens.expires_in()} s. Claims: {json.dumps(shown)}")
|
||||
return 0
|
||||
|
||||
|
||||
def run(args) -> int:
|
||||
voyage = load_voyage(Path(args.voyage))
|
||||
settings = Settings.from_config(load_config())
|
||||
kab = Kab(ClientCredentials.from_env(), api=os.getenv("KAB_API", DEFAULT_API),
|
||||
tenant=os.getenv("KAB_TENANT", CP1_TENANT), project=voyage.project)
|
||||
ledger = Ledger(Path(args.resume)) if args.resume else Ledger.new(default_root(), voyage.name)
|
||||
return Runner(kab=kab, ledger=ledger, voyage=voyage, settings=settings).run(dry_run=args.dry_run, only=args.only)
|
||||
|
||||
|
||||
def main(argv=None) -> int:
|
||||
parser = argparse.ArgumentParser(prog="shakedown_lib", description=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
commands = parser.add_subparsers(dest="command", required=True)
|
||||
commands.add_parser("token-check", help="get a token as kab-automation and show who it names")
|
||||
start = commands.add_parser("run", help="run a voyage")
|
||||
start.add_argument("voyage")
|
||||
start.add_argument("--dry-run", action="store_true", help="build and check every stage's inputs; start nothing")
|
||||
start.add_argument("--resume", help="a ledger folder of an earlier run of this voyage")
|
||||
start.add_argument("--only", nargs="+", help="run only these stages (earlier ones must be completed)")
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
return token_check() if args.command == "token-check" else run(args)
|
||||
except (AuthError, VoyageError, FileNotFoundError, RuntimeError) as error:
|
||||
print(f"Refused: {error}", file=sys.stderr)
|
||||
return EXIT_CONFIG
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user