auto-sync: tudo-para-ia-mais-humana 2026-05-02 05:20:04
This commit is contained in:
@@ -136,6 +136,8 @@ class CentralMaterializationReport:
|
||||
summary: tuple[str, ...]
|
||||
blockers: tuple[str, ...]
|
||||
generated_files: tuple[str, ...] = ()
|
||||
fallback_order_files: tuple[str, ...] = ()
|
||||
local_semantic_write: SemanticWriteResult | None = None
|
||||
|
||||
@property
|
||||
def status(self) -> MaterializationStatus:
|
||||
@@ -485,6 +487,10 @@ def _target_path(central_platform_folder: Path, spec: MaterializedOrderSpec) ->
|
||||
return central_platform_folder / "orders" / spec.subfolder / spec.filename
|
||||
|
||||
|
||||
def _fallback_order_path(project_root: Path, spec: MaterializedOrderSpec) -> Path:
|
||||
return project_root / "os-orientadoras" / "central-materialization-fallback" / spec.subfolder / spec.filename
|
||||
|
||||
|
||||
def _write_order(central_platform_folder: Path, spec: MaterializedOrderSpec, *, overwrite: bool = False) -> MaterializedOrderAction:
|
||||
path = _target_path(central_platform_folder, spec)
|
||||
if path.exists() and not overwrite:
|
||||
@@ -509,6 +515,51 @@ def _write_order(central_platform_folder: Path, spec: MaterializedOrderSpec, *,
|
||||
)
|
||||
|
||||
|
||||
def _write_fallback_order(
|
||||
project_root: Path,
|
||||
central_platform_folder: Path,
|
||||
spec: MaterializedOrderSpec,
|
||||
*,
|
||||
overwrite: bool = True,
|
||||
) -> MaterializedOrderAction:
|
||||
path = _fallback_order_path(project_root, spec)
|
||||
if path.exists() and not overwrite:
|
||||
return MaterializedOrderAction(spec.order_id, spec.role, str(path), MaterializationStatus.EXISTS)
|
||||
try:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
before = path.exists()
|
||||
content = order_markdown(spec.to_order(), str(central_platform_folder), REAL_REPO)
|
||||
content = (
|
||||
content.rstrip()
|
||||
+ "\n\n## Espelho operacional de contingencia\n\n"
|
||||
+ "Esta copia foi gravada no projeto real porque a pasta central ou o SQLite central estavam bloqueados para escrita nesta rodada.\n"
|
||||
+ "O caminho oficial da ordem continua sendo a central da plataforma 15; este arquivo preserva execucao, rastreabilidade e retomada.\n"
|
||||
)
|
||||
path.write_text(content, encoding="utf-8")
|
||||
return MaterializedOrderAction(
|
||||
spec.order_id,
|
||||
spec.role,
|
||||
str(path),
|
||||
MaterializationStatus.UPDATED if before else MaterializationStatus.CREATED,
|
||||
)
|
||||
except OSError as exc:
|
||||
return MaterializedOrderAction(
|
||||
spec.order_id,
|
||||
spec.role,
|
||||
str(path),
|
||||
MaterializationStatus.FAILED,
|
||||
f"{type(exc).__name__}: {exc}",
|
||||
)
|
||||
|
||||
|
||||
def _write_fallback_orders(
|
||||
project_root: Path,
|
||||
central_platform_folder: Path,
|
||||
specs: Sequence[MaterializedOrderSpec],
|
||||
) -> tuple[MaterializedOrderAction, ...]:
|
||||
return tuple(_write_fallback_order(project_root, central_platform_folder, spec) for spec in specs)
|
||||
|
||||
|
||||
def _report_markdown(report: CentralMaterializationReport) -> str:
|
||||
lines = [
|
||||
"# EXECUTADO - Central Materialization",
|
||||
@@ -543,6 +594,19 @@ def _report_markdown(report: CentralMaterializationReport) -> str:
|
||||
lines.append(f"- orders_count: `{report.semantic_write.orders_count}`")
|
||||
if report.semantic_write.error:
|
||||
lines.append(f"- error: `{report.semantic_write.error}`")
|
||||
if report.local_semantic_write:
|
||||
lines.extend(["", "## SQLite Semantico Local", ""])
|
||||
lines.append(f"- attempted: `{report.local_semantic_write.attempted}`")
|
||||
lines.append(f"- ok: `{report.local_semantic_write.ok}`")
|
||||
lines.append(f"- sqlite_path: `{report.local_semantic_write.sqlite_path}`")
|
||||
lines.append(f"- files_count: `{report.local_semantic_write.files_count}`")
|
||||
lines.append(f"- orders_count: `{report.local_semantic_write.orders_count}`")
|
||||
if report.local_semantic_write.error:
|
||||
lines.append(f"- error: `{report.local_semantic_write.error}`")
|
||||
if report.fallback_order_files:
|
||||
lines.extend(["", "## Ordens Espelhadas no Projeto Real", ""])
|
||||
for path in report.fallback_order_files:
|
||||
lines.append(f"- `{path}`")
|
||||
lines.extend(["", "## Blockers", ""])
|
||||
if report.blockers:
|
||||
lines.extend(f"- `{item}`" for item in report.blockers)
|
||||
@@ -589,6 +653,8 @@ def _audit_markdown(report: CentralMaterializationReport) -> str:
|
||||
f"- Ordens ja existentes: `{existing}`.",
|
||||
f"- Falhas de escrita: `{failed}`.",
|
||||
f"- SQLite central atualizado: `{report.semantic_write.ok}`.",
|
||||
f"- Ordens espelhadas no projeto real: `{len(report.fallback_order_files)}`.",
|
||||
f"- SQLite semantico local atualizado: `{bool(report.local_semantic_write and report.local_semantic_write.ok)}`.",
|
||||
"",
|
||||
"## Parcial ou bloqueado",
|
||||
"",
|
||||
@@ -603,6 +669,7 @@ def _audit_markdown(report: CentralMaterializationReport) -> str:
|
||||
"## Leitura gerencial",
|
||||
"",
|
||||
"- A pasta central agora possui arquivos fisicos para as ordens citadas pela fila.",
|
||||
"- Quando a central bloqueia escrita, o projeto real preserva espelhos operacionais das ordens e SQL semantico local.",
|
||||
"- As proximas ordens de saida se limitam a publicacao live, credenciais, runner, ACL, nome canonico e Docs.",
|
||||
]
|
||||
)
|
||||
@@ -652,6 +719,8 @@ def _state_markdown(report: CentralMaterializationReport) -> str:
|
||||
f"- active_input_orders: `{len(report.active_input_orders)}`",
|
||||
f"- next_output_orders: `{len(report.next_output_orders)}`",
|
||||
f"- semantic_sql_ok: `{report.semantic_write.ok}`",
|
||||
f"- local_semantic_sql_ok: `{bool(report.local_semantic_write and report.local_semantic_write.ok)}`",
|
||||
f"- fallback_order_files: `{len(report.fallback_order_files)}`",
|
||||
f"- project_root: `{report.project_root}`",
|
||||
f"- central_platform_folder: `{report.central_platform_folder}`",
|
||||
"",
|
||||
@@ -727,6 +796,19 @@ def _generated_records(report: CentralMaterializationReport, central_platform_fo
|
||||
relation_to_order=action.order_id,
|
||||
)
|
||||
)
|
||||
for path in report.fallback_order_files:
|
||||
order_id = Path(path).stem
|
||||
records.append(
|
||||
GeneratedFile(
|
||||
path=path,
|
||||
description="Espelho operacional de ordem de servico gravado no projeto real por bloqueio de escrita central.",
|
||||
function="fallback service order file",
|
||||
file_type="markdown",
|
||||
changed_by="mais_humana.central_materialization",
|
||||
change_summary=f"Preservada copia de contingencia da ordem {order_id}.",
|
||||
relation_to_order=order_id,
|
||||
)
|
||||
)
|
||||
return tuple(records)
|
||||
|
||||
|
||||
@@ -800,6 +882,14 @@ def run_central_materialization(
|
||||
records = _generated_records(report, central_platform_folder)
|
||||
semantic = _write_semantic(central_platform_folder / "controle-semantico.sqlite", records, specs)
|
||||
blockers = merge_unique((*blockers, *(("semantic_sql:" + semantic.error,) if semantic.error else ())))
|
||||
fallback_actions: tuple[MaterializedOrderAction, ...] = ()
|
||||
fallback_files: tuple[str, ...] = ()
|
||||
local_semantic: SemanticWriteResult | None = None
|
||||
if any(action.status == MaterializationStatus.FAILED for action in actions) or not semantic.ok:
|
||||
fallback_actions = _write_fallback_orders(project_root, central_platform_folder, specs)
|
||||
fallback_files = tuple(action.path for action in fallback_actions if action.status != MaterializationStatus.FAILED)
|
||||
fallback_errors = tuple(f"{action.order_id}:{action.error}" for action in fallback_actions if action.status == MaterializationStatus.FAILED)
|
||||
blockers = merge_unique((*blockers, *(f"fallback_order:{item}" for item in fallback_errors)))
|
||||
report = CentralMaterializationReport(
|
||||
report_id=report.report_id,
|
||||
generated_at=report.generated_at,
|
||||
@@ -812,7 +902,28 @@ def run_central_materialization(
|
||||
semantic_write=semantic,
|
||||
summary=report.summary,
|
||||
blockers=blockers,
|
||||
fallback_order_files=fallback_files,
|
||||
)
|
||||
if fallback_files:
|
||||
local_records = _generated_records(report, central_platform_folder)
|
||||
local_semantic = _write_semantic(project_root / "controle-semantico.sqlite", local_records, specs)
|
||||
if local_semantic.error:
|
||||
blockers = merge_unique((*blockers, "local_semantic_sql:" + local_semantic.error))
|
||||
report = CentralMaterializationReport(
|
||||
report_id=report.report_id,
|
||||
generated_at=report.generated_at,
|
||||
project_id=report.project_id,
|
||||
central_platform_folder=report.central_platform_folder,
|
||||
project_root=report.project_root,
|
||||
active_input_orders=report.active_input_orders,
|
||||
next_output_orders=report.next_output_orders,
|
||||
actions=report.actions,
|
||||
semantic_write=report.semantic_write,
|
||||
summary=report.summary,
|
||||
blockers=blockers,
|
||||
fallback_order_files=report.fallback_order_files,
|
||||
local_semantic_write=local_semantic,
|
||||
)
|
||||
artifact_targets = (
|
||||
(central_platform_folder / "reports" / "EXECUTADO__rodada-015-central-materialization-2026-05-02.md", _report_markdown(report)),
|
||||
(central_platform_folder / "reports" / "PENDENCIAS-CODEX__rodada-015-central-materialization-2026-05-02.md", _pending_markdown(report)),
|
||||
@@ -856,7 +967,9 @@ def run_central_materialization(
|
||||
semantic_write=report.semantic_write,
|
||||
summary=report.summary,
|
||||
blockers=blockers,
|
||||
generated_files=tuple(generated_files),
|
||||
generated_files=tuple((*generated_files, *report.fallback_order_files)),
|
||||
fallback_order_files=report.fallback_order_files,
|
||||
local_semantic_write=report.local_semantic_write,
|
||||
)
|
||||
for path, _content in fallback_targets:
|
||||
if path.exists():
|
||||
|
||||
Reference in New Issue
Block a user