Files
awoooi/scripts/agents/agent-market-discovery-classify.py
ogt 210d7db338
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled
feat(agents): schedule mainstream agent version governance
2026-07-10 10:51:22 +08:00

96 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""
Classify market discovery repositories using supplied primary-source metadata.
The command is read-only. It does not add watch-registry entries, install SDKs,
call LLMs, approve paid provider use, enter replay, or change production.
Under the GitHub account-safety freeze it does not fetch GitHub metadata; callers
must provide sanitized metadata explicitly, or drafts are marked policy-blocked
for offline review.
"""
from __future__ import annotations
import argparse
import importlib.util
import json
import sys
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parents[2]
SERVICE_PATH = ROOT / "apps" / "api" / "src" / "services" / "agent_market_discovery_classifier.py"
def main() -> int:
parser = argparse.ArgumentParser(description="Classify AWOOOI Agent discovery candidates.")
parser.add_argument("--discovery-review", required=True, help="agent_market_discovery_review_v1 JSON")
parser.add_argument("--metadata", help="optional repository metadata JSON keyed by repository_full_name")
parser.add_argument("--output", help="classification output JSON")
parser.add_argument("--timeout-seconds", type=int, default=12)
args = parser.parse_args()
discovery_review = _read_json(Path(args.discovery_review))
metadata = (
_read_json(Path(args.metadata))
if args.metadata
else _policy_blocked_repository_metadata(discovery_review)
)
service = _load_service()
report = service.run_agent_market_discovery_classification(
discovery_review=discovery_review,
repository_metadata=metadata,
)
rendered = json.dumps(report, ensure_ascii=False, indent=2, sort_keys=True)
if args.output:
Path(args.output).write_text(rendered + "\n", encoding="utf-8")
else:
print(rendered)
print(json.dumps(report["summary"], ensure_ascii=False, sort_keys=True))
return 0
def _policy_blocked_repository_metadata(
discovery_review: dict[str, Any],
) -> dict[str, dict[str, Any]]:
metadata: dict[str, dict[str, Any]] = {}
for draft in discovery_review.get("candidate_drafts") or []:
if draft.get("status") != "needs_primary_source_classification":
continue
repo = str(draft.get("repository_full_name", ""))
if not repo:
continue
metadata[repo] = {
"full_name": repo,
"html_url": draft.get("html_url"),
"description": None,
"topics": [],
"stargazers_count": draft.get("stargazers_count_max"),
"policy_blocker": "github_global_freeze_metadata_must_be_supplied_offline",
}
return metadata
def _read_json(path: Path) -> dict[str, Any]:
with path.open(encoding="utf-8") as handle:
payload = json.load(handle)
if not isinstance(payload, dict):
raise SystemExit(f"{path}: expected JSON object")
return payload
def _load_service() -> Any:
module_name = "awoooi_agent_market_discovery_classifier_service"
spec = importlib.util.spec_from_file_location(module_name, SERVICE_PATH)
if spec is None or spec.loader is None:
raise SystemExit(f"cannot load discovery classifier service from {SERVICE_PATH}")
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
return module
if __name__ == "__main__":
raise SystemExit(main())