Adds the repository-stewardship Python package (src/stewardship) with: - JSON Schemas (Draft 2020-12) for RepositoryContract, KnowledgeBase, CatalogIndex, ContextBundle, BootstrapPlan, AdoptionAssessment/Plan/Report, user config and the repoctl-result envelope. - Safe YAML I/O, path confinement, deterministic clock and canonical-JSON hashing. - validate: schema, ID uniqueness, path safety, KDB references, freshness, secret-shaped fields, shell-string detection, and Markdown frontmatter/fence/link checks. - discover/CatalogIndex with deterministic sorting and duplicate-name detection. - describe (contract-only) and context (intent-scoped ContextBundle with budgeted materialization and --strict truncation). - init: plan-then-apply bootstrap with SHA-256 plan-hash approval, no fake domain artifacts, bundled Claude skills. - adopt: assess/plan/apply/verify overlay workflow per docs/adoption-runbook.md, preserving legacy content roots and KDB, with baseline-hash re-check and rollback. - argparse-based `repoctl` CLI with human/yaml/json output and spec exit codes. - pytest suite (39 tests) covering positive/negative fixtures, discovery, context, bootstrap and adoption (including LXD- and Antivirus-shaped legacy layouts). Managed with uv (.venv), ruff clean, mypy --strict clean. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""Render the `stewardship/repoctl-result@0.1` envelope as human, YAML or JSON output."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
from .constants import RESULT_SCHEMA
|
|
from .io import dump_json, yaml_text
|
|
from .types import Finding
|
|
|
|
|
|
def build_envelope(command: str, outcome: str, data: Any, findings: list[Finding]) -> dict[str, Any]:
|
|
return {
|
|
"schema": RESULT_SCHEMA,
|
|
"command": command,
|
|
"outcome": outcome,
|
|
"data": data,
|
|
"findings": [f.to_dict() for f in findings],
|
|
}
|
|
|
|
|
|
def print_findings_human(findings: list[Finding]) -> None:
|
|
for finding in findings:
|
|
location = f" [{finding.resource}]" if finding.resource else ""
|
|
path = f" ({finding.path})" if finding.path else ""
|
|
print(f"{finding.severity.upper()} {finding.code}{location}{path}: {finding.message}", file=sys.stderr)
|
|
|
|
|
|
def emit(
|
|
envelope: dict[str, Any],
|
|
output: str,
|
|
human_renderer: Callable[[dict[str, Any]], None] | None = None,
|
|
) -> None:
|
|
if output == "json":
|
|
sys.stdout.write(dump_json(envelope))
|
|
elif output == "yaml":
|
|
sys.stdout.write(yaml_text(envelope))
|
|
else:
|
|
for finding in envelope["findings"]:
|
|
location = f" [{finding['resource']}]" if finding.get("resource") else ""
|
|
path = f" ({finding['path']})" if finding.get("path") else ""
|
|
print(f"{finding['severity'].upper()} {finding['code']}{location}{path}: {finding['message']}", file=sys.stderr)
|
|
if human_renderer is not None:
|
|
human_renderer(envelope)
|
|
else:
|
|
print(f"{envelope['command']}: {envelope['outcome']}")
|