Platform scripts, MCP servers, deployment and docs for the KAB runs
- Scripts to run workflows from a YAML context or run inputs (kab_run_workflow.py, with --input name=@file), store per-project discovery connections, bootstrap agent MCP keys, refresh the KAB token, publish reports and build estate snapshots. - Hyperscaler discovery servers extended in place; cloud-knowledge folded into them. - deploy/crucible-kab-dev.yaml: the Discovery package agent and the Assessment agents. - Platform issue write-ups and current-wiring notes under docs/platform-issues/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,11 +18,14 @@ Usage (from the repository root; quote the Feature folder, its name has spaces):
|
||||
python3 scripts/kab_import_workflow.py "sub-agents/ALZ-F01: Discovery Workflow Agent" --project-id <id> # validate only
|
||||
python3 scripts/kab_import_workflow.py "<Feature folder>" --project-id <id> --apply # import as a draft
|
||||
python3 scripts/kab_import_workflow.py "<Feature folder>" --project-id <id> --artifact-id <id> --apply # with an Artifacts step
|
||||
python3 scripts/kab_import_workflow.py "<Feature folder>" --project-id <id> --apply --update <workflow id> \\
|
||||
--rollback-file <file> # replace an imported workflow in place
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import inspect
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
@@ -32,6 +35,7 @@ import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
DEFAULT_API = "https://api.kab-dev.kyndemo.live"
|
||||
CP1_TENANT = "6ae37d13999438461a529409"
|
||||
|
||||
|
||||
def _token(path: Path) -> str:
|
||||
@@ -57,10 +61,10 @@ def _builder(feature: Path):
|
||||
return module.build
|
||||
|
||||
|
||||
def _post(api: str, path: str, token: str, body: dict) -> dict:
|
||||
def _post(api: str, path: str, token: str, body, method: str = "POST") -> dict:
|
||||
request = urllib.request.Request(
|
||||
f"{api.rstrip('/')}{path}", data=json.dumps(body).encode("utf-8"), method="POST",
|
||||
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"})
|
||||
f"{api.rstrip('/')}{path}", data=None if body is None else json.dumps(body).encode("utf-8"), method=method,
|
||||
headers={"Authorization": f"Bearer {token}", "X-Tenant-ID": CP1_TENANT, "Content-Type": "application/json"})
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=60) as response:
|
||||
return json.loads(response.read() or b"{}")
|
||||
@@ -71,6 +75,32 @@ def _post(api: str, path: str, token: str, body: dict) -> dict:
|
||||
raise SystemExit(f"{path}: HTTP {error.code} {hint}\n{detail}")
|
||||
|
||||
|
||||
def _step_key(step: dict) -> str:
|
||||
"""A step's agent, with the two Format for UI steps told apart by what they format."""
|
||||
sources = list(((step.get("inputs") or {}).get("from_steps") or {}).values())
|
||||
return step.get("agent", "") + (":" + sources[0].split(".", 1)[-1] if step.get("agent") == "format_for_ui" and sources else "")
|
||||
|
||||
|
||||
def _keep_ids(new: dict, current: dict) -> dict:
|
||||
"""The new template with the step ids KAB gave the current one on import, matched by agent, so the stored
|
||||
workflow keeps the ids its runs and history use. A step with no counterpart keeps the export's id."""
|
||||
ids = {_step_key(s): s["id"] for s in current.get("steps") or []}
|
||||
rename = {s["id"]: ids.get(_step_key(s), s["id"]) for s in new["steps"]}
|
||||
if len(set(rename.values())) != len(rename):
|
||||
raise SystemExit("--update: the current workflow's steps can't be matched one to one; import it instead")
|
||||
ref = lambda value: rename.get(value.split(".")[0], value.split(".")[0]) + "." + value.split(".", 1)[1]
|
||||
out = json.loads(json.dumps(new))
|
||||
for step in out["steps"]:
|
||||
step["id"] = rename[step["id"]]
|
||||
step["depends_on"] = [rename.get(d, d) for d in step.get("depends_on") or []]
|
||||
inputs = step.get("inputs") or {}
|
||||
if inputs.get("from_steps"):
|
||||
inputs["from_steps"] = {k: ref(v) for k, v in inputs["from_steps"].items()}
|
||||
out["connections"] = [{"source": rename.get(c["source"], c["source"]), "target": rename.get(c["target"], c["target"])}
|
||||
for c in out.get("connections") or []]
|
||||
return out
|
||||
|
||||
|
||||
def main(argv=None) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("feature", type=Path, help="the Feature folder whose workflow is imported")
|
||||
@@ -83,9 +113,18 @@ def main(argv=None) -> int:
|
||||
parser.add_argument("--published", action="store_true", help="import as published (default: draft)")
|
||||
parser.add_argument("--apply", action="store_true", help="import; without it the export is only validated")
|
||||
parser.add_argument("--save", type=Path, help="also write the export to this file")
|
||||
parser.add_argument("--update", metavar="WORKFLOW_ID",
|
||||
help="with --apply: replace this existing workflow's template in place (its id is kept) "
|
||||
"instead of importing a new workflow")
|
||||
parser.add_argument("--rollback-file", type=Path,
|
||||
help="with --update: where the workflow's current template is saved first (required)")
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
export = _builder(args.feature)(not args.no_upload, args.artifact_id)
|
||||
build = _builder(args.feature)
|
||||
# Discovery's build takes (with_upload, artifact_ids); Assessment's, whose upload is always the rate card, takes
|
||||
# only artifact_ids.
|
||||
params = inspect.signature(build).parameters
|
||||
export = build(not args.no_upload, args.artifact_id) if len(params) >= 2 else build(args.artifact_id)
|
||||
if args.save:
|
||||
args.save.write_text(json.dumps(export, indent=2) + "\n")
|
||||
steps = export["template"]["steps"]
|
||||
@@ -107,6 +146,20 @@ def main(argv=None) -> int:
|
||||
print("validated only; add --apply to import")
|
||||
return 0
|
||||
|
||||
if args.update:
|
||||
if not args.rollback_file:
|
||||
raise SystemExit("--update needs --rollback-file: the current template is saved there before it is replaced")
|
||||
path = f"/api/v1/workflow-catalog/workflows/{args.update}"
|
||||
current = _post(args.api, path, token, None, "GET")
|
||||
current = current.get("workflow", current)
|
||||
args.rollback_file.write_text(json.dumps({"workflow_id": args.update, "template": current.get("template")},
|
||||
indent=2) + "\n")
|
||||
print(f"saved the current template to {args.rollback_file}")
|
||||
template = _keep_ids(export["template"], current.get("template") or {})
|
||||
result = _post(args.api, path, token, {"template": template}, "PUT")
|
||||
print(f"updated: workflow_id={args.update} success={result.get('success')}")
|
||||
return 0 if result.get("success") else 1
|
||||
|
||||
mappings = [{"source_name": a["name"], "target_url": a["source_url"]} for a in export["dependencies"]["agents"]]
|
||||
result = _post(args.api, "/api/workflows/import", token, {
|
||||
"export_data": export, "agent_mappings": mappings, "import_as_draft": not args.published,
|
||||
|
||||
Reference in New Issue
Block a user