diff --git a/src/stewardship/adoption.py b/src/stewardship/adoption.py index 74d496c..ea2dc42 100644 --- a/src/stewardship/adoption.py +++ b/src/stewardship/adoption.py @@ -387,12 +387,26 @@ def build_plan( confirmed_title: str | None = None, confirmed_owners: list[str] | None = None, confirmed_lifecycle: str = "active", + confirmed_type: str | None = None, strategy: str = "overlay", ) -> dict[str, Any]: if strategy != "overlay": raise ValueError("Only the overlay strategy is implemented; normalize requires an explicit recipe run") baseline = assessment["repository"]["baselineRevision"] + classification = assessment["classification"] + repository_type = confirmed_type or classification["proposedType"] + # assess asks the owner to confirm the type whenever confidence is below + # high, so record which of the two answers the contract is built on. Without + # this a low-confidence guess and a deliberate decision look identical later. + annotations: dict[str, str] = { + "stewardship.corsus.ru/classification": "confirmed" if confirmed_type else "inferred", + "stewardship.corsus.ru/classification-confidence": classification["confidence"], + } + if classification.get("evidence"): + annotations["stewardship.corsus.ru/classification-evidence"] = ", ".join( + classification["evidence"] + ) changes: list[dict[str, Any]] = [] forbidden: list[str] = [] @@ -421,7 +435,7 @@ def build_plan( if not (root / "AGENTS.md").exists(): answers = BootstrapAnswers( name=confirmed_name, title=confirmed_title or confirmed_name, owners=confirmed_owners or [], - repository_type=assessment["classification"]["proposedType"], lifecycle=confirmed_lifecycle, + repository_type=repository_type, lifecycle=confirmed_lifecycle, ) changes.append({"action": "create", "path": "AGENTS.md", "ownership": "shared", "content": render_agents_md(answers)}) else: @@ -464,15 +478,16 @@ def build_plan( "name": confirmed_name, "title": confirmed_title or confirmed_name, "owners": confirmed_owners or [], + "annotations": annotations, }, "spec": { "summary": f"Adopted repository {confirmed_name}", "repository": { - "type": assessment["classification"]["proposedType"], + "type": repository_type, "lifecycle": confirmed_lifecycle, }, "template": { - "id": "repository." + assessment["classification"]["proposedType"].split("-")[0], + "id": "repository." + repository_type.split("-")[0], "version": "0.1.0", "source": "repo:repository-stewardship", "mode": "adopted-overlay", diff --git a/src/stewardship/cli.py b/src/stewardship/cli.py index e8f9af7..a2d813e 100644 --- a/src/stewardship/cli.py +++ b/src/stewardship/cli.py @@ -13,7 +13,7 @@ from pathlib import Path from typing import Any from . import adoption, bootstrap, config, discovery, io -from .constants import CONTRACT_PATH, RESULT_SCHEMA +from .constants import CONTRACT_PATH, REPOSITORY_TYPES, RESULT_SCHEMA from .context import build_context from .paths import find_repository_root from .render import build_envelope, emit @@ -214,6 +214,11 @@ def cmd_adopt(args: argparse.Namespace) -> int: else: answers = {} name = answers.get("name") or repo_path.name.lower() + confirmed_type = args.type or answers.get("repositoryType") + if confirmed_type is not None and confirmed_type not in REPOSITORY_TYPES: + raise CliError( + f"Unknown repository type: {confirmed_type}", EXIT_INVALID_INPUT + ) plan = adoption.build_plan( repo_path, assessment, @@ -221,6 +226,7 @@ def cmd_adopt(args: argparse.Namespace) -> int: confirmed_title=answers.get("title"), confirmed_owners=answers.get("owners"), confirmed_lifecycle=answers.get("lifecycle", "active"), + confirmed_type=confirmed_type, strategy=args.strategy, ) _write(build_envelope("adopt plan", "success", plan, []), args.output) @@ -321,6 +327,12 @@ def build_parser() -> argparse.ArgumentParser: p_adopt.add_argument("--repo", required=True) p_adopt.add_argument("--mode", required=True, choices=["assess", "plan", "apply", "verify"]) p_adopt.add_argument("--answers") + p_adopt.add_argument( + "--type", + dest="type", + choices=sorted(REPOSITORY_TYPES), + help="Confirm the repository type that assess could only propose", + ) p_adopt.add_argument("--strategy", default="overlay", choices=["overlay", "normalize"]) p_adopt.add_argument("--recipe") p_adopt.add_argument("--plan")