Skip to content

feat: fundação cívica (eventos/evidências/fluxos) + bot anti-vazamento - #36

Merged
pmarcura merged 2 commits into
mainfrom
codex/fundacao-civica-eventos
May 30, 2026
Merged

feat: fundação cívica (eventos/evidências/fluxos) + bot anti-vazamento#36
pmarcura merged 2 commits into
mainfrom
codex/fundacao-civica-eventos

Conversation

@pmarcura

Copy link
Copy Markdown
Owner

O que muda

Duas entregas que vão juntas para o main:

🛡️ Bot anti-vazamento de segredos (3 camadas)

  • .githooks/pre-commit — bloqueia segredos na máquina, antes do push
  • .gitleaks.toml + job secrets no CI — varre cada PR (regra custom da chave do Portal da Transparência)
  • GitHub secret scanning + push protection (já ativos no repo)

🏛️ Fundação cívica (modelo canônico de transparência)

  • DB: civic_events, evidence, entity_relationships, money_flows, source_coverage + enums; migration 0004
  • PNCP: payload real → 578 contratos com eventos/evidências/fluxos/vínculos
  • TCE-SP: API oficial → 124.795 despesas + 4.074 receitas → 128.865 eventos/evidências
  • Diário/átomos: segmentação + território; 273 eventos auditáveis
  • Cobertura: 12 fontes registradas em source_coverage
  • Linguagem: sai "família no poder", entra "vínculos documentados"

Validação

Codex validou local com Docker/Postgres: migrate, seed, check, typecheck, lint, build.

Pendências conhecidas (próximos PRs)

  • PNCP licitações partial (exige modalidade no endpoint)
  • Câmara precisa mapeadores dedicados
  • TSE é bulk ZIP (download/filtro focado)
  • CEIS/CNEP: rodada completa precisa job com rate limit

Tipo

  • 🗂️ Coleta de dados / modelo canônico
  • 🔧 Infra / segurança

pmarcura and others added 2 commits May 30, 2026 13:56
Protege a chave da API do Portal da Transparência (e qualquer segredo) de
vazar pro GitHub, em três camadas:

1. .githooks/pre-commit — bloqueia na máquina, antes do push (zero dependência)
2. .gitleaks.toml + job 'secrets' no CI — varre todo PR; regra custom da chave
   do Portal + regras padrão (AWS, GitHub, etc); bloqueia o merge se achar
3. (já ativo no repo) GitHub secret scanning + push protection

CONTRIBUTING documenta `git config core.hooksPath .githooks`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Modelo canônico de transparência (codex/fundacao-civica-eventos):
- db: civic_events, evidence, entity_relationships, money_flows,
  source_coverage + enums; migration 0004; sources inclui camara-americana
- PNCP: transform com type guard compra/contrato; mapper no payload real
  (niFornecedor, numeroControlePNCP); 578 contratos → eventos/evidências/fluxos
- TCE-SP: adapter na API oficial atual (despesas/receitas), ingestMany em lote;
  124.795 despesas + 4.074 receitas → 128.865 eventos/evidências; PF comum não
  vira entidade pública (só CNPJ completo)
- Diário/átomos: segmentação indefinido + extração de território; 273 eventos
- source_coverage: 12 linhas (PNCP, TCE-SP, Diário, Querido Diário,
  Transparência, Câmara, CEIS/CNEP, BrasilAPI/QSA, TSE)
- Linguagem pública: sai "família no poder", entra "vínculos documentados"

Validado local com Docker/Postgres: migrate, seed, check, typecheck, lint, build.

Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread .github/workflows/ci.yml
Comment on lines +46 to +59
name: secrets
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # histórico completo para o gitleaks varrer todos os commits

- name: Gitleaks (varredura de segredos)
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Grátis para repositórios públicos e pessoais (não precisa de licença).
GITLEAKS_CONFIG: .gitleaks.toml

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 389b4919ee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +204 to +207
eq(sanctions.sourceId, "cgu-transparencia"),
eq(sanctions.cadastro, cadastro.toUpperCase()),
eq(sanctions.documento, doc),
eq(sanctions.tipoSancao, it.tipoSancao?.descricaoResumida ?? ""),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve distinct sanctions with the full key

When a supplier has multiple CEIS/CNEP sanctions in the same cadastro with the same tipoSancao but different start dates or sanctioning bodies, this coarse existence check treats the later records as duplicates and skips inserting them into sanctions. The event key above already includes date and órgão, so the sanctions table should use equivalent fields (or a stored source key) to avoid dropping official sanction records.

Useful? React with 👍 / 👎.

.where(eq(evidence.evidenceKey, input.evidenceKey))
.limit(1);

if (existing[0]) return existing[0].id;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refresh existing evidence rows on re-ingest

If an upstream record changes under the same natural key, raw_records intentionally appends a new version and upsertCivicEvent updates the event, but this early return leaves the existing evidence pointing at the old rawRecordId, sourceUrl, and excerpt. In that re-ingest scenario the public evidence trail becomes stale even though the event was refreshed, so existing evidence should be updated with the new input before returning.

Useful? React with 👍 / 👎.

@pmarcura
pmarcura merged commit 37a3b1e into main May 30, 2026
5 checks passed
@pmarcura
pmarcura deleted the codex/fundacao-civica-eventos branch May 30, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants