generated from coulomb/repo-seed
Add validation indexes and generated views
This commit is contained in:
@@ -3,10 +3,12 @@ from __future__ import annotations
|
||||
from collections import Counter
|
||||
from dataclasses import asdict, dataclass
|
||||
from pathlib import Path
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
from . import generation
|
||||
from .bench import (
|
||||
Infospace,
|
||||
KnowledgeArtifact,
|
||||
@@ -15,6 +17,7 @@ from .bench import (
|
||||
relationship_summary,
|
||||
run_collection_checks,
|
||||
)
|
||||
from .validation import structural_checks
|
||||
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
@@ -121,6 +124,7 @@ def list_standards(root: Path | str | None = None) -> dict[str, Any]:
|
||||
def validate_canon(root: Path | str | None = None) -> dict[str, Any]:
|
||||
context = load_context(root)
|
||||
errors: list[dict[str, Any]] = []
|
||||
warnings: list[dict[str, Any]] = []
|
||||
|
||||
artifact_ids = {artifact.id for artifact in context.infospace.artifacts}
|
||||
for artifact in context.infospace.artifacts:
|
||||
@@ -161,15 +165,31 @@ def validate_canon(root: Path | str | None = None) -> dict[str, Any]:
|
||||
context.infospace.config.viability,
|
||||
)
|
||||
errors.extend(threshold_errors)
|
||||
structural = structural_checks(context)
|
||||
errors.extend(structural["errors"])
|
||||
warnings.extend(structural["warnings"])
|
||||
|
||||
return {
|
||||
"ok": not errors,
|
||||
"errors": errors,
|
||||
"warnings": warnings,
|
||||
"metrics": checks.metrics,
|
||||
"details": checks.details,
|
||||
}
|
||||
|
||||
|
||||
def write_validation_report(
|
||||
destination: Path | str,
|
||||
root: Path | str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
payload = validate_canon(root)
|
||||
path = Path(destination)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
||||
payload["report_path"] = str(path)
|
||||
return payload
|
||||
|
||||
|
||||
def artifact_graph(
|
||||
root: Path | str | None = None,
|
||||
*,
|
||||
@@ -221,6 +241,39 @@ def profile_inspect(
|
||||
return {"ok": True, "profile": data, "path": str(profile_path)}
|
||||
|
||||
|
||||
def generate_indexes(root: Path | str | None = None) -> dict[str, Any]:
|
||||
return generation.generate_indexes(load_context(root))
|
||||
|
||||
|
||||
def generate_tree(root: Path | str | None = None) -> dict[str, Any]:
|
||||
return generation.generate_tree(load_context(root))
|
||||
|
||||
|
||||
def generate_agent_briefs(root: Path | str | None = None) -> dict[str, Any]:
|
||||
return generation.generate_agent_briefs(load_context(root))
|
||||
|
||||
|
||||
def list_views(root: Path | str | None = None) -> dict[str, Any]:
|
||||
return generation.list_generated_views(load_context(root))
|
||||
|
||||
|
||||
def read_view(name: str, root: Path | str | None = None) -> dict[str, Any]:
|
||||
try:
|
||||
return generation.read_generated_view(load_context(root), name)
|
||||
except FileNotFoundError as exc:
|
||||
raise CanonServiceError(
|
||||
"missing_view",
|
||||
f"View not found: {name}",
|
||||
{"view": name},
|
||||
) from exc
|
||||
except ValueError as exc:
|
||||
raise CanonServiceError(
|
||||
"invalid_view_name",
|
||||
str(exc),
|
||||
{"view": name},
|
||||
) from exc
|
||||
|
||||
|
||||
def _artifact_to_dict(
|
||||
artifact: KnowledgeArtifact,
|
||||
infospace_root: Path,
|
||||
|
||||
Reference in New Issue
Block a user