argos-cli 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. argos/__init__.py +5 -0
  2. argos/__main__.py +4 -0
  3. argos/adapters/__init__.py +9 -0
  4. argos/adapters/_libreoffice_worker.py +111 -0
  5. argos/adapters/ai.py +1506 -0
  6. argos/adapters/ai_remote.py +654 -0
  7. argos/adapters/attachment_conversion.py +132 -0
  8. argos/adapters/capabilities.py +31 -0
  9. argos/adapters/chart_render.py +72 -0
  10. argos/adapters/docx_pdf.py +2953 -0
  11. argos/adapters/limesurvey.py +1079 -0
  12. argos/adapters/model_call.py +274 -0
  13. argos/adapters/report_publication.py +1530 -0
  14. argos/adapters/url_fetch.py +146 -0
  15. argos/adapters/xlsx.py +454 -0
  16. argos/analytics.py +731 -0
  17. argos/assets.py +257 -0
  18. argos/audit_result.py +369 -0
  19. argos/booleans.py +105 -0
  20. argos/catalog.py +1205 -0
  21. argos/cli.py +606 -0
  22. argos/contracts.py +532 -0
  23. argos/core.py +325 -0
  24. argos/default_skills/README.md +23 -0
  25. argos/default_skills/criar-matriz-planejamento/SKILL.md +200 -0
  26. argos/default_skills/elaborar-survey-limesurvey/SKILL.md +106 -0
  27. argos/default_skills/operar-argos/SKILL.md +74 -0
  28. argos/default_skills/verificar-diretrizes-fiscalizacao/SKILL.md +129 -0
  29. argos/default_skills/verificar-diretrizes-fiscalizacao/assets/relatorio-avaliacao.md +54 -0
  30. argos/default_skills/verificar-diretrizes-fiscalizacao/references/contrato-saidas.md +36 -0
  31. argos/default_skills/verificar-diretrizes-fiscalizacao/references/papeis-das-pastas.md +37 -0
  32. argos/default_skills/verificar-diretrizes-fiscalizacao/references/roteiro-verificacoes.md +27 -0
  33. argos/default_skills/verificar-diretrizes-fiscalizacao/scripts/avaliacao.py +253 -0
  34. argos/engines/__init__.py +3 -0
  35. argos/engines/adjustments.py +571 -0
  36. argos/engines/analytics.py +195 -0
  37. argos/engines/audit.py +2730 -0
  38. argos/engines/evaluation.py +6088 -0
  39. argos/engines/index.py +1683 -0
  40. argos/engines/matrix.py +5736 -0
  41. argos/engines/matrix_html.py +698 -0
  42. argos/engines/model_request.py +201 -0
  43. argos/engines/report_document.py +137 -0
  44. argos/engines/reports.py +1200 -0
  45. argos/engines/survey.py +4445 -0
  46. argos/envfile.py +53 -0
  47. argos/errors.py +29 -0
  48. argos/evidence_staging.py +293 -0
  49. argos/executions.py +565 -0
  50. argos/findings_matrix.py +2549 -0
  51. argos/fingerprints.py +487 -0
  52. argos/index_dsl.py +2100 -0
  53. argos/matrix_markdown.py +475 -0
  54. argos/matrix_widths.py +280 -0
  55. argos/pipeline.py +1745 -0
  56. argos/products.py +220 -0
  57. argos/progress.py +221 -0
  58. argos/project.py +608 -0
  59. argos/report_config.py +158 -0
  60. argos/resources/ESPECIFICACAO_MARKDOWN_MATRIZ_ACHADOS.md +539 -0
  61. argos/resources/ESPECIFICACAO_MARKDOWN_MATRIZ_PLANEJAMENTO.md +1000 -0
  62. argos/resources/ESPECIFICACAO_UNIFICADA_MATRIZES_V1_3.md +1142 -0
  63. argos/resources/anexo-evidencias-base.docx +0 -0
  64. argos/resources/argos-index-dsl-v1.schema.json +539 -0
  65. argos/resources/argos-report-config-v1.schema.json +113 -0
  66. argos/resources/diretrizes-projeto.md +476 -0
  67. argos/resources/env.example +37 -0
  68. argos/resources/exemplos/matriz_achados_boilerplate.md +61 -0
  69. argos/resources/exemplos/matriz_achados_draft.md +106 -0
  70. argos/resources/exemplos/matriz_achados_larguras_v1_3.md +114 -0
  71. argos/resources/exemplos/matriz_achados_v1_3.md +107 -0
  72. argos/resources/exemplos/matriz_planejamento_boilerplate.md +64 -0
  73. argos/resources/exemplos/matriz_planejamento_larguras_v1_3.md +115 -0
  74. argos/resources/exemplos/matriz_planejamento_v1_3.md +108 -0
  75. argos/resources/template-base-estilos-sigiloso.docx +0 -0
  76. argos/resources/template-base-estilos.docx +0 -0
  77. argos/resources/template-matriz-planejamento.docx +0 -0
  78. argos/resources/template-relatorio-consolidado-comum.docx +0 -0
  79. argos/resources/template-relatorio-consolidado-institucional.docx +0 -0
  80. argos/response_profiles.py +856 -0
  81. argos/scheduler.py +142 -0
  82. argos/status.py +367 -0
  83. argos/store.py +1228 -0
  84. argos/survey_collection.py +832 -0
  85. argos/telemetry.py +84 -0
  86. argos/tui.py +1262 -0
  87. argos/tui.tcss +827 -0
  88. argos/tui_models.py +466 -0
  89. argos/tui_path.py +155 -0
  90. argos/tui_widgets.py +482 -0
  91. argos/version.py +3 -0
  92. argos_cli-0.3.1.dist-info/METADATA +570 -0
  93. argos_cli-0.3.1.dist-info/RECORD +96 -0
  94. argos_cli-0.3.1.dist-info/WHEEL +5 -0
  95. argos_cli-0.3.1.dist-info/entry_points.txt +2 -0
  96. argos_cli-0.3.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,195 @@
1
+ """Orquestração de analytics: tabelas, gráficos, manifesto e staging."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+ from typing import Any, Mapping, Sequence
8
+
9
+ from ..analytics import (
10
+ DEFAULT_SPECS,
11
+ AnalyticsConfig,
12
+ ChartSpec,
13
+ compute_measures,
14
+ extract_audit_facts,
15
+ extract_evaluation_facts,
16
+ extract_impact_facts,
17
+ join_tables,
18
+ _slug,
19
+ load_analytics_config,
20
+ measure_series,
21
+ table_csv,
22
+ tables_json,
23
+ validate_spec,
24
+ )
25
+ from ..assets import load_manifest, validate_manifest
26
+ from ..contracts import OperationResult, ProductDraft, sha256_bytes
27
+ from ..core import OperationContext
28
+ from ..errors import InputValidationError, MissingInputError
29
+ from ..adapters.chart_render import render_chart
30
+
31
+
32
+ def _load_json(context: OperationContext, value: Any, label: str) -> Any:
33
+ if isinstance(value, Mapping):
34
+ return dict(value)
35
+ if value in (None, ""):
36
+ raise MissingInputError(f"{label} não informado")
37
+ path = context.path(value)
38
+ if not path.is_file():
39
+ raise MissingInputError(f"{label} não encontrado: {path}")
40
+ try:
41
+ return json.loads(path.read_text(encoding="utf-8"))
42
+ except (OSError, UnicodeError, json.JSONDecodeError) as exc:
43
+ raise InputValidationError(f"{label} ilegível: {exc}") from exc
44
+
45
+
46
+ def _formats(value: Any) -> tuple[str, ...]:
47
+ if value in (None, ""):
48
+ return ("csv", "json", "png")
49
+ if isinstance(value, str):
50
+ values = [item.strip() for item in value.split(",") if item.strip()]
51
+ elif isinstance(value, Sequence):
52
+ values = [str(item).strip() for item in value]
53
+ else:
54
+ raise InputValidationError("formatos deve ser csv, json ou png")
55
+ allowed = {"csv", "json", "png"}
56
+ if not values or any(item not in allowed for item in values):
57
+ raise InputValidationError("formatos deve conter csv, json ou png")
58
+ return tuple(dict.fromkeys(values))
59
+
60
+
61
+ def run_graficos(context: OperationContext) -> OperationResult:
62
+ """`graficos`: tabelas, gráficos PNG e manifesto de ativos do resultado da auditoria."""
63
+ params = context.params
64
+ avaliacoes = params.get("avaliacoes") or []
65
+ if isinstance(avaliacoes, (str, Path)):
66
+ avaliacoes = [avaliacoes]
67
+ return run_analytics(
68
+ context,
69
+ resultado_auditoria=params["resultado_auditoria"],
70
+ avaliacoes=avaliacoes,
71
+ impactos=params.get("impactos"),
72
+ config=params.get("config"),
73
+ output_dir=params.get("output_dir"),
74
+ formatos=params.get("formatos"),
75
+ )
76
+
77
+
78
+ def run_analytics(
79
+ context: OperationContext,
80
+ *,
81
+ resultado_auditoria: Any,
82
+ avaliacoes: Sequence[Any] = (),
83
+ impactos: Any = None,
84
+ config: Any = None,
85
+ output_dir: Any = None,
86
+ formatos: Any = None,
87
+ ) -> OperationResult:
88
+ """Executa a analítica sem escrever nos caminhos finais do projeto."""
89
+ warnings: list[str] = []
90
+ audit = _load_json(context, resultado_auditoria, "resultado_auditoria")
91
+ audit_tables, audit_warnings = extract_audit_facts(audit)
92
+ warnings.extend(audit_warnings)
93
+ tables: dict[str, list[dict[str, Any]]] = dict(audit_tables)
94
+ loaded_evaluations = [_load_json(context, item, "avaliação") for item in avaliacoes]
95
+ if loaded_evaluations:
96
+ eval_tables, eval_warnings = extract_evaluation_facts(loaded_evaluations)
97
+ warnings.extend(eval_warnings)
98
+ if eval_tables["evidence_outcomes"]:
99
+ tables["evidence_outcomes"] = eval_tables["evidence_outcomes"]
100
+ if eval_tables["contradiction_outcomes"]:
101
+ tables["contradiction_outcomes"] = eval_tables["contradiction_outcomes"]
102
+ if impactos not in (None, ""):
103
+ impact_tables, impact_warnings = extract_impact_facts(_load_json(context, impactos, "impactos"))
104
+ warnings.extend(impact_warnings)
105
+ if impact_tables:
106
+ tables["scenario_impacts"] = impact_tables
107
+ analytics_config: AnalyticsConfig
108
+ if config not in (None, ""):
109
+ analytics_config = load_analytics_config(context.path(config))
110
+ else:
111
+ analytics_config = AnalyticsConfig(specs=DEFAULT_SPECS)
112
+ if not analytics_config.include_planned:
113
+ tables["findings"] = [row for row in tables.get("findings") or [] if not row.get("planejado")]
114
+ tables, join_warnings = join_tables(tables)
115
+ warnings.extend(join_warnings)
116
+ measures = compute_measures(tables, denominator=analytics_config.denominator)
117
+ specs: tuple[ChartSpec, ...] = analytics_config.specs
118
+ formats_set = set(_formats(formatos if formatos not in (None, "", []) else analytics_config.formats))
119
+ target = context.path(output_dir or "analises")
120
+ products: list[ProductDraft] = []
121
+ tables_payload = tables_json(tables)
122
+ products.append(ProductDraft("analytics-tables", target / "tables.json", tables_payload, "application/json"))
123
+ for name, rows in tables.items():
124
+ if not rows:
125
+ continue
126
+ products.append(
127
+ ProductDraft(
128
+ "analytics-tables",
129
+ target / f"{name}.csv",
130
+ table_csv(rows),
131
+ "text/csv",
132
+ )
133
+ )
134
+ manifest_assets: list[dict[str, Any]] = []
135
+ staged_manifest_assets: list[dict[str, Any]] = []
136
+ chart_ids: list[str] = []
137
+ for spec in specs:
138
+ validate_spec(spec)
139
+ if spec.table not in tables or not tables[spec.table]:
140
+ warnings.append(f"analysis_skipped: tabela ausente {spec.table} para {spec.id}")
141
+ continue
142
+ chart = measure_series(tables, spec, measures)
143
+ if not chart.labels:
144
+ warnings.append(f"analysis_skipped: sem dados para {spec.id}")
145
+ continue
146
+ if "png" not in formats_set:
147
+ continue
148
+ requested = spec.filename or f"{spec.id}.png"
149
+ if Path(requested).is_absolute() or ".." in Path(requested).parts:
150
+ raise InputValidationError(f"filename inválido para {spec.id}: {requested}")
151
+ filename = f"{_slug(Path(requested).stem) or spec.id}.png"
152
+ data = render_chart(spec, chart)
153
+ staged = context.stage_file(".png")
154
+ staged.write_bytes(data)
155
+ final_path = target / filename
156
+ products.append(ProductDraft(f"analytics-chart:{spec.id}", final_path, data, "image/png", {"slot_id": spec.id, "caption": spec.title}))
157
+ chart_ids.append(spec.id)
158
+ entry = {
159
+ "slot_id": spec.id,
160
+ "kind": "asset:chart",
161
+ "path": filename,
162
+ "media_type": "image/png",
163
+ "sha256": sha256_bytes(data),
164
+ "caption": spec.title,
165
+ "scope": "consolidated",
166
+ }
167
+ manifest_assets.append(entry)
168
+ staged_manifest_assets.append({**entry, "path": staged.name})
169
+ manifest_path: Path | None = None
170
+ if manifest_assets:
171
+ stage_manifest = context.stage_file(".json")
172
+ stage_manifest.write_text(
173
+ json.dumps({"schema_version": "argos.asset-manifest/v1", "assets": staged_manifest_assets}, ensure_ascii=False, sort_keys=True),
174
+ encoding="utf-8",
175
+ )
176
+ parsed = load_manifest(stage_manifest)
177
+ validate_manifest(parsed, output_root=stage_manifest.parent)
178
+ manifest_payload = {"schema_version": "argos.asset-manifest/v1", "assets": manifest_assets}
179
+ manifest_path = target / "manifest.json"
180
+ products.append(ProductDraft("analytics-manifest", manifest_path, manifest_payload, "application/json"))
181
+ else:
182
+ warnings.append("analytics-manifest não emitido: nenhum PNG gerado")
183
+ summary = {
184
+ "tables": {name: len(rows) for name, rows in tables.items()},
185
+ "measures": measures,
186
+ "charts": chart_ids,
187
+ "manifest": str(manifest_path) if manifest_path else "",
188
+ "formats": sorted(formats_set),
189
+ "warnings": warnings,
190
+ }
191
+ return OperationResult(
192
+ summary={"analytics": summary},
193
+ products=tuple(products),
194
+ warnings=tuple(warnings),
195
+ )