79 lines
3.1 KiB
Python
79 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Import existing routed Web capabilities into the implementation receipt ledger."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from collections import defaultdict
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
from implementation_first import REGISTRY_PATH, load_registry
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
CAPABILITIES = ROOT / "docs/current/feature-capability-registry.json"
|
|
|
|
|
|
def main() -> int:
|
|
capabilities = json.loads(CAPABILITIES.read_text(encoding="utf-8"))
|
|
registry = load_registry()
|
|
batches = registry.setdefault("batches", {})
|
|
record_state = registry.setdefault("records", {})
|
|
by_module: dict[str, list[dict]] = defaultdict(list)
|
|
for row in capabilities.get("records", []):
|
|
if isinstance(row, dict) and row.get("implementationStatus") == "routed" and row.get("artifactReady") is True:
|
|
by_module[str(row.get("module"))].append(row)
|
|
now = datetime.now(timezone.utc).isoformat()
|
|
imported = 0
|
|
for module, rows in sorted(by_module.items()):
|
|
batch_id = f"baseline:{module}"
|
|
record_ids = [str(row["id"]) for row in rows]
|
|
if isinstance(batches, dict):
|
|
batches.setdefault(
|
|
batch_id,
|
|
{
|
|
"batchId": batch_id,
|
|
"module": module,
|
|
"tier": "feature-workflow",
|
|
"family": "registered-command",
|
|
"recordIds": record_ids,
|
|
"recordCount": len(record_ids),
|
|
"status": "implemented_pending_use",
|
|
"validation": "deferred_until_runtime_issue_or_explicit_full_validation",
|
|
"artifacts": ["web/public/modules/manifest.json"],
|
|
"source": "existing-routes-and-module-artifacts",
|
|
"updatedAt": now,
|
|
},
|
|
)
|
|
if isinstance(record_state, dict):
|
|
for row in rows:
|
|
record_id = str(row["id"])
|
|
if record_id in record_state:
|
|
continue
|
|
record_state[record_id] = {
|
|
"batchId": batch_id,
|
|
"module": module,
|
|
"family": row.get("category"),
|
|
"status": "implemented_pending_use",
|
|
"uiStatus": row.get("uiStatus"),
|
|
"updatedAt": now,
|
|
}
|
|
imported += 1
|
|
registry["updatedAt"] = now
|
|
registry["baseline"] = {
|
|
"source": "docs/current/feature-capability-registry.json",
|
|
"meaning": "route and artifact exist; runtime validation is deferred",
|
|
"modules": len(by_module),
|
|
"records": sum(len(rows) for rows in by_module.values()),
|
|
}
|
|
temporary = REGISTRY_PATH.with_suffix(".tmp")
|
|
temporary.write_text(json.dumps(registry, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
temporary.replace(REGISTRY_PATH)
|
|
print(json.dumps({"status": "bootstrapped", "modules": len(by_module), "records": len(record_state), "imported": imported}, ensure_ascii=False))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|
|
|