Commit Graph
118 Commits
Author SHA1 Message Date
gtiandClaude Sonnet 5 e935ed61d5 feat: audited-decision gate for PIS/COFINS and CFOP_ENTRADA NOT_APPLICABLE/OPERATION_TIME
Missao 2 (fechamento de lacunas fiscais, read-only + UI/engine gated):
- field_contract: pis_cofins_profile now also accepts the literal sentinels
  NOT_APPLICABLE/OPERATION_TIME, resolving to NA only from an audited
  FiscalContextEntry - never inferred from emission statistics. CFOP_ENTRADA
  under an already-decided entry_scope=MIXED_OR_DYNAMIC now resolves to NA
  instead of MANUAL, so it stops blocking product completeness and stops
  re-asking an already-answered question. Regression tests prove: no ADMIN
  decision => unchanged old behavior; decision present => gated bucket, no write.
- context_keys: validate_entry accepts the two sentinels for pis_cofins_profile.
- Contexto Fiscal UI: PIS/COFINS and CFOP_ENTRADA cards show the Bloco 2
  cross-database evidence (5 installations, CRT 1 and 3: emission never reads
  the PIS/COFINS cadastral fields anywhere) and a link to an ADMIN-facing,
  anonymized dossie-for-the-accountant; entry_scope is now a dropdown.
- release/tests: decoupled the Hub's GTI_FISCAL_VERSION from the Agent's own
  version (test_versions_are_coherent_across_hub_and_packages vs the new
  test_agent_version_is_internally_coherent) - a Hub-only release must not
  require touching, rebuilding or republishing the Agent.
- New read-only evidence: docs/runs/GTI_dryrun_universe_summary.json (527
  products, Agent 2's real database), docs/runs/BLOCO2_PIS_COFINS_CROSS_DB_V1.json
  (5 installations), docs/fiscal_completeness_matrix.md, docs/dossie_contador.md
  (internal, real names) + central/static/docs/dossie_contador.md (public,
  anonymized - no CNPJ/razao social/product names), docs/AGENT2_UPGRADE_RUNBOOK_V1.md.
- CLAUDE.md: recorded the permanent fiscal-mission rules (no AI/scraping, no
  Firebird schema changes, deploy only via deploy_hub.ps1, never reenroll,
  no remote access to client Agent hosts, no client data in unauthenticated
  static routes).

No schema/migration change. Zero Firebird writes (new scripts never open a
write connection). Hub only - Agent code untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-28 09:44:05 -03:00
gti 1621ea4e0b feat: Contexto Fiscal admin UI - reduces fiscal policy list to 3 real decisions
Adds an ADMIN-only "Contexto Fiscal" section to the Agent detail page: confirm/alter/clear the fiscal decisions
field_contract.resolve_product genuinely cannot derive from the ERP alone (icms_treatment, pis_cofins_profile,
entry_scope). Persists through the existing FiscalContextEntry table (the same one blocker_resolution already
writes operator answers into) - no new persistence model, no opaque JSON box. CSRF + RBAC + audit reuse the exact
mechanism already proven for /agents/{id}/features. Confirming or clearing flags every already-enriched product on
the installation for re-evaluation.

The list was reduced from 5 candidates to 3 by auditing real production data (Agent 2, 2026-09-27/28):
icms_rate/credit_rate and rounding were dropped - both proven NOT_APPLICABLE / ALREADY_DERIVED for this CRT=1
company from real field_contract dry-runs, not assumption. Real evidence surfaced in the UI is a dated, one-time
manual read-only measurement (disclosed in the card copy itself as such) - the Hub has no direct Firebird access,
so this is not a live query; a follow-up should pipe it through the heartbeat the same way CRT/CONTRIBUINTE_IPI
were wired.

Also found, during the same audit, that this client's NFC-e emission ignores the product's cadastral PIS/COFINS
CST/rate fields entirely (verified on the 3 real products that DO have them populated - the emitted documents never
carry the cadastral value) - documented as a strong OPEN recommendation for a future field_contract change, not
applied here, since changing canonical fiscal semantics needs accountant sign-off, not just my own inference.

1129 tests passed (tests + central/tests + agent/tests), 0 failed. Version 1.3.9 (single GTI_FISCAL_VERSION). Hub
only - Agent unchanged, no new installer this release.
2026-09-27 22:09:41 -03:00
gti 4701ff8724 fix: REPROCESS_PRODUCTS resolved company=None for unified_fiscal/RTC
REPROCESS_PRODUCTS is not in SYNC_JOB_KINDS, so it fell to the else branch of execute_job and hardcoded company=None
for _unified_fiscal - a real gap, not a missing feature: the same deterministic, fail-closed company_context.resolve()
every sync job already uses is cheap (no full-table scan, confirmed against the real database) and applies just as
well to a one-off reprocess job. Now resolves the real company the same way; falls back to None only when the
company genuinely cannot be resolved yet, never a silent guess. Does not touch RTC rule logic.

Verified end-to-end against the real production database (dry-run, zero writes) that this was the last domain still
carrying the old bug - field_contract's post-NCM fiscal completion already bypassed it entirely by reading
Installation.company_uf/crt/company_contribuinte_ipi directly (populated via the 1.3.7 heartbeat fix).

1123 tests passed (tests + central/tests + agent/tests), 0 failed. Version 1.3.8 (single GTI_FISCAL_VERSION).
2026-09-27 21:32:28 -03:00
gti 7e83d17533 feat: wire field_contract into product enrichment; auto-discover CRT/CONTRIBUINTE_IPI at heartbeat; targeted per-product ERP evidence
field_contract.resolve_product was only exercised by its own unit tests. /v1/products/resolve now calls it for every product whose NCM
resolves, merging CFOP/CST/CSOSN/PIS-COFINS/CST_IPI/SITUACAO_TRIBUTARIA/IAT/IPPT decisions alongside CLASSIFICACAO_FISCAL/CEST/IPI - reusing
the same engine, the same FiscalContextEntry table the blocker-resolution workflow already writes to, no duplicated rules.

Closes three real transport/discovery gaps found while wiring it in:
- Agent heartbeat never sent company_crt (env-var UF only) or company_contribuinte_ipi, so Installation.company_crt stayed permanently empty
  even though company_context.resolve() already proves both from C000004/EMISSOR for every coverage job. Resolved once, cached, retried only
  while unresolved. Migration 0032 adds Installation.company_contribuinte_ipi (NULL=unknown, never coerced to "N").
- The Agent's enrichment payload only ever reported 3 old fields (CLASSIFICACAO_FISCAL/CEST/IPI) as "current", so the Hub could never see the
  product's own CFOP/CST/CSOSN/... nor the classification columns (TIPO/PROD_COZINHA/PRODUTO_SERVICO/CODGRUPO) infer_role needs - separated
  into a read-only CURRENT_REPORT_FIELDS list, the write allowlist (PRODUCT_ENRICHMENT_WRITE_V1) untouched.
- Added a targeted, product_code-scoped evidence query (firebird_reader.read_product_evidence: recipes/composed/purchases/stock, indexed WHERE,
  never a full-table scan) so st_withheld/product_role can be proven for a single ad-hoc resolve, not only during a full sync job.

Verified read-only against the real database (D:\PROJETOS\GTISISTEMAS\Banco\GTI.FDB): CRT=1, CONTRIBUINTE_IPI=N, company_context.resolve()
reaches HIGH confidence; infer_role correctly resolved RESALE/OWN_PRODUCTION for 5/8 sample real products with zero operator questions.

1121 tests passed (tests + central/tests + agent/tests), 0 failed. Version 1.3.7 (single GTI_FISCAL_VERSION shared by Hub and Agent per
central/app/version.py's own design - never independently versioned).
2026-09-27 18:26:20 -03:00
gtiandClaude Sonnet 5 72edff0510 test: regression for the wrong-GTIN attest incident (similar-name products stay independent, EAN_AUSENTE is never terminal, shared-description local rows resolve independently from one KB verification)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-27 12:58:35 -03:00
gtiandClaude Sonnet 5 fbff392ec9 fix: KB dashboard search was applying the strict fiscal name-match rule (used to authorize automatic writes) to human browsing, so a natural query (e.g. missing the unit word) found nothing; now a separate, lenient, global, paginated server-side search — filter over the whole KB, then count/order/paginate. 1.3.6 (Hub only)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-27 10:33:45 -03:00
gti 0f5d27025d fix: keep the RTC 'Preenchimento automático' label, disambiguated from the enrichment 2026-09-26 14:48:29 -03:00
gti 085c95c89f fix: panel wording keeps 'cClassTrib' out of the RTC-off page 2026-09-26 14:47:15 -03:00
gti 1333ac1bc4 feat: visible per-product enrichment status, flagged re-evaluation (panel/Reprocessar/Sincronizar/KB decision), operator NCM decision, deterministic name-only match, stale-write guard; 1.3.5 2026-09-26 14:37:37 -03:00
gtiandClaude Sonnet 5 ab65ddd679 fix: OSCBR role is IDENTITY (V3 contract has no NCM/CEST): v3 endpoint, provides_ncm=false, leading-zero NCM guard, backfill refuses until NCM is proven
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-26 12:00:05 -03:00
gtiandClaude Sonnet 5 c68c6c67ed feat: TECHNICAL_PLACEHOLDER (NCM 00000000) is replaceable by the product enrichment; real values preserved; Agent 1.3.4
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-26 10:50:12 -03:00
gti 5281c1d79b fix: OSCBR backfill sends GTIN-8 in its canonical 8-digit form 2026-09-26 10:12:16 -03:00
gtiandClaude Sonnet 5 1e4a31ea88 feat: OSCBR token support, Cosmos out of the active chain, quota-safe OSCBR backfill (dry-run selection), provider env passthrough; 1.3.3 (Hub only)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-26 10:04:51 -03:00
gtiandClaude Sonnet 5 ac1ecccc50 feat: coverage V2 - historical evidence miner, KB evidence model + promotion audit + revalidation, Kodebar/OSCBR limits, KB/provider panel, seed import; 1.3.2 (Hub only)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-26 08:14:57 -03:00
gti 19e145ea47 docs: sandbox post-reboot E2E evidence, benchmark refresh 2026-09-26 01:02:40 -03:00
gtiandClaude Sonnet 5 e6bcf12d53 feat: OSCBR optional provider, re-baseline after inactivity, field audit, provider UI/feature matrix tests, benchmark chain; 1.3.1
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-26 00:48:18 -03:00
gti c3c9d1b4e0 docs: project state for product enrichment 2026-09-25 19:50:32 -03:00
gtiandClaude Sonnet 5 4fc83a33d5 feat: product enrichment observability, lab KB study, benchmark, copy + local-Hub E2E, docs; 1.3.0
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 19:26:13 -03:00
gtiandClaude Sonnet 5 5deebea14e feat: enrichment Hub API, feature flags UI/gating, NCM refresher, Agent enrichment worker with tests
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 18:47:35 -03:00
gtiandClaude Sonnet 5 27f992d9e0 feat: product enrichment foundation (GTIN, KB evidence, providers, quota gateway, resolver, migration 0029)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 18:35:42 -03:00
gti 4a12640031 fix: gate cClassTrib applicability by CRT and date 2026-09-25 17:47:04 -03:00
gti 95605c2ff5 feat: explain RTC blockers when no R3 candidates are eligible 2026-09-25 16:04:29 -03:00
gtiandClaude Sonnet 5 d8f1bd3415 fix: Agent tolerates ~3 minutes of network outage mid-job (10 attempts with backoff); 1.2.4
Sandbox test: a 26 s outage exhausted the previous 15 s retry budget and failed a REPROCESS_ALL.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 12:46:20 -03:00
gtiandClaude Sonnet 5 6f0f072d84 fix: fresh install archives stale state of a previous installation; a fatal Agent loop error stops the service instead of leaving a dead 'Running' one; 1.2.3
Found by uninstall + fresh install on the clean Windows Sandbox: the old agent_state.sqlite identity conflicted with the new enrollment and the service sat idle.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 12:25:53 -03:00
gtiandClaude Sonnet 5 2e5598ce9c fix: Agent retries transient transport errors/proxy 5xx with backoff (classify, complete, fail); hide console behind the GUI wizard; 1.2.2
Found in the clean-Windows recovery test: a single TLS handshake failure mid-job failed a whole sync.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 12:02:11 -03:00
gtiandClaude Sonnet 5 abeb6ad878 chore: ignore scratch_sandbox (disposable Windows Sandbox harness)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 11:12:41 -03:00
gtiandClaude Sonnet 5 f94f1527f1 fix: cClassTrib control page tables scroll inside their own container (no page-level horizontal overflow)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 09:55:47 -03:00
gtiandClaude Sonnet 5 af5d9b4436 feat: RBAC for RTC write modes (Gerenciador ADMIN only, denials audited), central backpressure for heavy jobs (HEAVY_JOB_CONCURRENCY_LIMIT), concurrency simulation evidence
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 09:46:21 -03:00
gtiandClaude Sonnet 5 7063c8c161 feat: re-check central RTC authorization right before every write (GET /v1/agents/me/authorizations), human labels on the cClassTrib control page, final corpus/scale evidence; 1.2.1
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 08:57:45 -03:00
gtiandClaude Sonnet 5 42dc172763 feat: central RTC write modes (DISABLED/DRY_RUN/APPROVAL/ENABLED), R4 suggestion-only, preview/approval, per-record rollback, bulk blocker upsert; 1.2.0
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 22:46:05 -03:00
gtiandClaude Sonnet 5 3c10422e81 test: importing the RTC copy E2E script must not change the environment (credential test isolation)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 21:23:57 -03:00
gtiandClaude Sonnet 5 9f08998800 feat: deterministic cClassTrib resolver + gated CCLASSTRIB auto-apply (default OFF), RTC panel summary; 1.1.9
- resolver (rules RTC-R0..R4/A1..A3/G1..G2) over the official cClassTrib table 2026-06-22 and LC 214/2025 annexes; local vs official catalog comparison
- ONE root-cause RTC blocker per product (missing/unresolved/ambiguous/conflict/official mismatch/catalog outdated/evidence missing)
- auto-apply: C000025.CCLASSTRIB only, three switches (FIREBIRD_WRITES + RTC_AUTO_APPLY_ENABLED + Hub authorization), per-product re-read and re-decision, never overwrites, rowcount 1, audit table rtc_write_audits (migration 0027)
- copy-only write E2E (280/280 applied, only CCLASSTRIB changed, 2nd run 0 writes, stale decision 0 writes); real databases untouched
- docs: cclasstrib_resolution, rtc_auto_apply, unified_fiscal_completeness

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 21:18:34 -03:00
gtiandClaude Sonnet 5 88f4318072 fix: RTC observed live with provenance, non-circular PIS/COFINS applicability, canonical CST normalization (1.1.8)
- RTC: Agent reads ALL PARAMETROS rows every sync (conflict => off), reports rtc_source/rtc_observed_at/rtc_param_rows; legal_effective_context is informational only
- PIS/COFINS: applicability from CRT + PISCOFINS flag + incidence only (never from empty fields); Simples w/o special treatment NOT_APPLICABLE, taxed regime with explicit N OPTIONAL, unreadable declaration NEEDS_REVIEW
- CST: one digit with an official zero-padded form is VALID_AFTER_NORMALIZATION (non-blocking warning), nothing is written to the ERP
- tests: RTC toggle 0->1->0 across syncs (Agent + Hub stale closing), non-circularity, normalization, panel provenance

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 17:46:45 -03:00
gtiandClaude Sonnet 5 1430042322 release: 1.1.8 - unified fiscal coverage (PIS/COFINS applicability + conditional RTC)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 16:43:39 -03:00
gtiandClaude Sonnet 5 b15dbea213 feat: unified fiscal coverage - PIS/COFINS applicability + conditional RTC in one definition, one queue, one panel
- central/app/unified_fiscal_coverage.py: pure rules (PIS/COFINS NOT_APPLICABLE/REQUIRED/OPTIONAL/NEEDS_REVIEW, RTC only when the ERP switch is on)
- agent: read-only loader (unified_fiscal.py) replaces the legacy/expanded module; findings feed the single operational state, coverage and blocker queue
- hub: BLOCKED_FISCAL_DATA blockers (PIS/COFINS/RTC) share the queue; stale ones close on the next full pass; dashboard breakdown gains CEST/PIS/COFINS/RTC
- panel: legacy/expanded coverage block removed; discreet 'Reforma Tributaria: Ativa/Desativada'
- docs: unified_fiscal_completeness, pis_cofins_applicability, rtc_pis_cofins_model + official source manifests; read-only E2E script

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 16:39:53 -03:00
gtiandClaude Sonnet 5 d897cceebb feat: read-only RTC + PIS/COFINS assessment (capabilities, validators, applicability, legacy vs expanded coverage) with panel labels and docs
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 15:41:51 -03:00
gtiandClaude Sonnet 5 e0ea842168 docs: read-only fiscal/RTC/PIS-COFINS discovery of TESTESOFICIAIS.FDB
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 15:25:31 -03:00
gtiandClaude Sonnet 5 c950ffb47f feat: UI polish - dark default, version drift vs default release, humanized enums, failed-jobs layout, processing button hierarchy, PT-BR titles/CTAs
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 14:26:44 -03:00
gtiandClaude Sonnet 5 9a142975a6 feat: operational panel UI - active-scope dashboard, drill-down cards, scoped Agents/Blockers/Jobs, PT-BR labels, responsive CSS
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 13:38:40 -03:00
gtiandClaude Sonnet 5 bfd4d28aa4 test: keep installer tests out of the real installer.log
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 11:25:27 -03:00
gtiandClaude Sonnet 5 065cdc4eff fix: fdb shadowing scan ignores generated build output (dist/build bundles contain fdb)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 11:18:21 -03:00
gtiandClaude Sonnet 5 f5f05d87e6 fix: installer tolerates localized 'service exists' (1073) and restarts the service if an upgrade step fails; 1.1.7
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 11:13:19 -03:00
gtiandClaude Sonnet 5 55e858e261 fix: deploy_hub.ps1 stray line
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 11:02:12 -03:00
gtiandClaude Sonnet 5 2341546c50 fix: deploy_hub basetemp path
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 11:01:41 -03:00
gtiandClaude Sonnet 5 d5d313375c fix: deploy test gate uses a per-run pytest basetemp
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 10:59:25 -03:00
gtiandClaude Sonnet 5 40a4d835fe fix: installer starts the service reliably (retry + verify + installer.log), fails loudly; 1.1.6
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 10:54:19 -03:00
gtiandClaude Sonnet 5 7e229f4b84 docs: deploy rule for agents (use deploy_hub.ps1)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 10:30:57 -03:00
gtiandClaude Sonnet 5 59443ffe3e fix: deploy extra smoke uses Gerenciador /login and is non-blocking
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 10:25:45 -03:00
gtiandClaude Sonnet 5 25a8321dd4 fix: deploy verify uses mirrored client, release revoke via Session, remote error tail
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 10:22:18 -03:00
gtiandClaude Sonnet 5 7080ef4d73 fix: deploy health via docker exec (prod port bound to VM IP), safe rollback, error propagation, VPN retry, release default + download verification
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-24 10:17:47 -03:00