feat: fundar plataforma mais humana
This commit is contained in:
158
src/mais_humana/cli.py
Normal file
158
src/mais_humana/cli.py
Normal file
@@ -0,0 +1,158 @@
|
||||
"""Command line interface for the Mais Humana platform."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from .models import as_plain_data
|
||||
from .matrix import build_global_recommendations, build_matrix, build_platform_reports
|
||||
from .operational_dossier import build_execution_round_dossier
|
||||
from .governance_engine import build_governance_portfolio, compact_governance_payload
|
||||
from .human_readiness_registry import build_readiness_registry
|
||||
from .runtime_budget import build_round_line_budget
|
||||
from .orders import build_exit_orders
|
||||
from .reports import generate
|
||||
from .scanner import environment_summary, scan_ecosystem
|
||||
from .storage import table_counts
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(prog="mais-humana", description="Generate human-centered ecosystem reports.")
|
||||
sub = parser.add_subparsers(dest="command", required=True)
|
||||
scan = sub.add_parser("scan", help="Scan ecosystem repositories and print compact JSON summary.")
|
||||
scan.add_argument("--ecosystem-root", default="G:/_codex-git")
|
||||
gen = sub.add_parser("generate", help="Generate DOCX, SVG, JSON, matrices, and service orders.")
|
||||
gen.add_argument("--ecosystem-root", default="G:/_codex-git")
|
||||
gen.add_argument("--project-root", default="G:/_codex-git/tudo-para-ia-mais-humana")
|
||||
gen.add_argument("--central-platform-folder", default="")
|
||||
gen.add_argument("--push-status", default="")
|
||||
sql = sub.add_parser("sql-counts", help="Print semantic SQLite table counts.")
|
||||
sql.add_argument("--sqlite", required=True)
|
||||
env = sub.add_parser("env", help="Print local environment summary.")
|
||||
env.add_argument("--ecosystem-root", default="G:/_codex-git")
|
||||
dossier = sub.add_parser("dossier", help="Print operational dossier JSON without writing artifacts.")
|
||||
dossier.add_argument("--ecosystem-root", default="G:/_codex-git")
|
||||
dossier.add_argument("--project-root", default="G:/_codex-git/tudo-para-ia-mais-humana")
|
||||
governance = sub.add_parser("governance", help="Print compact governance portfolio JSON.")
|
||||
governance.add_argument("--ecosystem-root", default="G:/_codex-git")
|
||||
governance.add_argument("--project-root", default="G:/_codex-git/tudo-para-ia-mais-humana")
|
||||
budget = sub.add_parser("line-budget", help="Print round line-budget JSON.")
|
||||
budget.add_argument("--ecosystem-root", default="G:/_codex-git")
|
||||
budget.add_argument("--project-root", default="G:/_codex-git/tudo-para-ia-mais-humana")
|
||||
return parser
|
||||
|
||||
|
||||
def command_scan(args: argparse.Namespace) -> int:
|
||||
root = Path(args.ecosystem_root)
|
||||
scans = scan_ecosystem(root)
|
||||
payload = {
|
||||
"platforms": [
|
||||
{
|
||||
"platform_id": scan.platform.platform_id,
|
||||
"exists": scan.exists,
|
||||
"git_present": scan.git_present,
|
||||
"code_lines": scan.code_lines,
|
||||
"evidence": len(scan.evidence),
|
||||
"warnings": scan.warnings,
|
||||
}
|
||||
for scan in scans
|
||||
],
|
||||
"total_code_lines": sum(scan.code_lines for scan in scans),
|
||||
"total_evidence": sum(len(scan.evidence) for scan in scans),
|
||||
}
|
||||
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
def command_generate(args: argparse.Namespace) -> int:
|
||||
central = Path(args.central_platform_folder) if args.central_platform_folder else None
|
||||
bundle = generate(
|
||||
ecosystem_root=Path(args.ecosystem_root),
|
||||
project_root=Path(args.project_root),
|
||||
central_platform_folder=central,
|
||||
push_status=args.push_status or None,
|
||||
)
|
||||
print(json.dumps(as_plain_data(bundle), ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
def command_sql_counts(args: argparse.Namespace) -> int:
|
||||
print(json.dumps(table_counts(Path(args.sqlite)), ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
def command_env(args: argparse.Namespace) -> int:
|
||||
print(json.dumps(environment_summary(Path(args.ecosystem_root)), ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
def command_dossier(args: argparse.Namespace) -> int:
|
||||
scans = scan_ecosystem(Path(args.ecosystem_root))
|
||||
cells = build_matrix(scans)
|
||||
reports = build_platform_reports(scans, cells)
|
||||
recommendations = build_global_recommendations(reports)
|
||||
orders = build_exit_orders(recommendations)
|
||||
dossier = build_execution_round_dossier(
|
||||
project_root=Path(args.project_root),
|
||||
platform_reports=reports,
|
||||
recommendations=recommendations,
|
||||
output_orders=orders,
|
||||
total_code_lines_analyzed=sum(scan.code_lines for scan in scans),
|
||||
)
|
||||
print(json.dumps(as_plain_data(dossier), ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
def command_governance(args: argparse.Namespace) -> int:
|
||||
scans = scan_ecosystem(Path(args.ecosystem_root))
|
||||
cells = build_matrix(scans)
|
||||
reports = build_platform_reports(scans, cells)
|
||||
recommendations = build_global_recommendations(reports)
|
||||
orders = build_exit_orders(recommendations)
|
||||
dossier = build_execution_round_dossier(
|
||||
project_root=Path(args.project_root),
|
||||
platform_reports=reports,
|
||||
recommendations=recommendations,
|
||||
output_orders=orders,
|
||||
total_code_lines_analyzed=sum(scan.code_lines for scan in scans),
|
||||
)
|
||||
portfolio = build_governance_portfolio(reports, recommendations=recommendations, round_dossier=dossier)
|
||||
registry = build_readiness_registry(reports, portfolio)
|
||||
payload = compact_governance_payload(portfolio)
|
||||
payload["readiness_entries"] = len(registry.entries)
|
||||
payload["weak_readiness_entries"] = len(registry.weak_entries)
|
||||
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
def command_line_budget(args: argparse.Namespace) -> int:
|
||||
budget = build_round_line_budget(Path(args.ecosystem_root), Path(args.project_root))
|
||||
print(json.dumps(as_plain_data(budget), ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
parser = build_parser()
|
||||
args = parser.parse_args(argv)
|
||||
if args.command == "scan":
|
||||
return command_scan(args)
|
||||
if args.command == "generate":
|
||||
return command_generate(args)
|
||||
if args.command == "sql-counts":
|
||||
return command_sql_counts(args)
|
||||
if args.command == "env":
|
||||
return command_env(args)
|
||||
if args.command == "dossier":
|
||||
return command_dossier(args)
|
||||
if args.command == "governance":
|
||||
return command_governance(args)
|
||||
if args.command == "line-budget":
|
||||
return command_line_budget(args)
|
||||
parser.error(f"unknown command: {args.command}")
|
||||
return 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user