feat(adopt): let the owner answer the type question assess asks
assess sets confirmationRequired and asks "Confirm repository type" whenever confidence is below high, but there was no way to answer it: --answers read only name, title, owners and lifecycle, and build_plan took the type solely from the classifier's guess. The confirmation boundary in runbook section 9 could not be closed through the tool, and nothing in the resulting contract distinguished a deliberate decision from an unreviewed low-confidence default. - accept the type via --type or a repositoryType answer, validated against the known set rather than written through unchecked - record classification, confidence and evidence in metadata.annotations, which the schema already allows as a free-form object - omit any timestamp so re-planning stays deterministic and planHash stable Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
90bf25c49d
commit
523ef61fe3
@@ -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",
|
||||
|
||||
+13
-1
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user