Skip to content

feat: LLM navigation support + Reforma Tributaria IBS/CBS/IS (NT 2025.002-RTC)#448

Open
felps-dev wants to merge 8 commits intoTadaSoftware:mainfrom
nuvelbr:master
Open

feat: LLM navigation support + Reforma Tributaria IBS/CBS/IS (NT 2025.002-RTC)#448
felps-dev wants to merge 8 commits intoTadaSoftware:mainfrom
nuvelbr:master

Conversation

@felps-dev
Copy link
Collaborator

@felps-dev felps-dev commented Feb 13, 2026

Summary

  • LLM Navigation Support: Added AGENTS.md and source map files (*_map.md) for all large files (>200 lines), enabling LLM tools to navigate the codebase efficiently without reading entire files
  • Reforma Tributaria (EC 132/2023): Core XML infrastructure for Brazil's new dual VAT system (IBS/CBS/IS), including entity fields, CST enumerations, XML serialization (<IBSCBS> as direct child of <imposto>), totals accumulation (<IBSCBSTot>), tests, and documentation

Reforma Tributaria Details

Adds support for the three new taxes introduced by Brazil's tax reform (NT 2025.002-RTC):

Tax Type Replaces
CBS (Contribuicao sobre Bens e Servicos) Federal PIS/COFINS
IBS (Imposto sobre Bens e Servicos) State+Municipal ICMS/ISS
IS (Imposto Seletivo) Extrafiscal IPI (partial)

Scope: Core XML serialization only (entity fields, CSTs, serialization, totals). No Split Payment, cashback, or transition calculation helpers.

Key design decisions:

  • <IBSCBS> is a direct child of <imposto> (no wrapper element) — per NT 2025.002-RTC schema (TTribNFe type)
  • IBS split into <gIBSUF> (estadual) and <gIBSMun> (municipal) with shared <vBC>
  • Totals in <IBSCBSTot> (type TIBSCBSMonoTot) as sibling of <ICMSTot> under <total>
  • <cMunFGIBS> in <ide> header for IBS municipality of taxable event
  • vNF does NOT include IBS/CBS/IS values (prohibited in 2025-2026)
  • IS entity fields ready for 2027 but serialization disabled (_serializar_is() exists, not called)
  • finNFe=5 (Nota de Debito) and finNFe=6 (Nota de Credito) added

Backward compatible: If no ibscbs_* fields are set, the <IBSCBS> group is not emitted — existing NF-e generation is unaffected.

Files Changed

Area Files
CST Enumerations pynfe/utils/flags.py
Entity Fields pynfe/entidades/notafiscal.py
XML Serialization pynfe/processamento/serializacao.py
Tests tests/test_nfe_serializacao_reforma_tributaria.py (10 test cases)
Documentation docs/reforma_tributaria.md, AGENTS.md, docs/*_map.md source maps

Test plan

  • All existing tests pass (0 regressions)
  • 10 new test cases covering:
    • CST 000 — full regular taxation with IBS UF/Mun split
    • CST 222 — exemption (no vBC, values zero)
    • No reforma data — backward compatibility (IBSCBS not emitted)
    • Multiple products — totals accumulation
    • Mixed legacy (ICMS/PIS/COFINS) + reform (IBSCBS) coexistence
    • vNF does NOT include IBS/CBS
    • Totals in IBSCBSTot (not ICMSTot)
    • IS entity fields stored but NOT serialized to XML
    • cMunFGIBS emitted in <ide> header
    • cMunFGIBS NOT emitted when not set
  • ruff check passes with no issues

🤖 Generated with Claude Code

felps-dev and others added 3 commits February 13, 2026 00:08
Source maps provide section-by-section breakdowns with exact line ranges
for all files over 200 lines, enabling LLMs to navigate directly to
specific code sections instead of reading entire files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add core XML infrastructure for Brazil's dual VAT system (IVA Dual):
- CST enumerations for IBS, CBS and IS in flags.py
- Product-level and invoice-level entity fields in notafiscal.py
- XML serialization (impostoMisto group) in serializacao.py
- Totals accumulation and vNF formula updated
- 5 test cases covering all serialization scenarios
- Documentation in docs/reforma_tributaria.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ia tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
leogregianin
leogregianin previously approved these changes Feb 13, 2026
Copy link
Collaborator

@leogregianin leogregianin left a comment

Choose a reason for hiding this comment

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

Ótimo trabalho 👏

@leotada
Copy link
Member

leotada commented Feb 13, 2026

Por favor crie uma pasta docs e coloque as documentações e referencie na docstring para os arquivos .md, para não ficar poluída as pastas de código.
Sobre o CLAUDE.md, geralmente o nome AGENTS.md é mais agnóstico a modelos e preferível.

Address PR TadaSoftware#448 review feedback: consolidate documentation files
under docs/ directory and use model-agnostic AGENTS.md naming.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…RTC schema

Remove impostoMisto wrapper — IBSCBS is now direct child of <imposto>.
Unify entity field naming to ibscbs_* pattern with shared vBC.
Add IBSCBSTot totals with nested gIBS/gCBS structure, cMunFGIBS in <ide>,
finNFe 5/6, and IS entity fields ready for 2027. Update docs and source maps.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 15, 2026 01:47
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@felps-dev felps-dev changed the title feat: LLM navigation support + Reforma Tributaria IBS/CBS/IS feat: LLM navigation support + Reforma Tributaria IBS/CBS/IS (NT 2025.002-RTC) Feb 15, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive support for Brazil's Reforma Tributaria (Constitutional Amendment 132/2023) dual VAT system and LLM navigation aids through source maps. The implementation focuses on core XML serialization infrastructure for the three new taxes (IBS, CBS, IS) that will gradually replace five existing taxes starting in 2026.

Changes:

  • Added source map documentation files (*_map.md) enabling efficient navigation of large files (>200 lines) without reading entire contents
  • Implemented IBS/CBS/IS entity fields, CST enumerations, XML serialization with <IBSCBS> as direct child of <imposto>, and totals accumulation in separate <IBSCBSTot> group
  • Added comprehensive test suite (8 test methods) covering full taxation, exemption, backward compatibility, totals accumulation, legacy/reform coexistence, vNF exclusion, and IS entity storage

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_nfe_serializacao_reforma_tributaria.py 8 comprehensive test cases for IBS/CBS/IS XML serialization and totals
pynfe/utils/flags.py Added IBS_CBS_TIPOS_TRIBUTACAO (15 3-digit CSTs), IS_TIPOS_TRIBUTACAO (7 2-digit CSTs), and finNFe values 5/6
pynfe/entidades/notafiscal.py Added reforma tributaria entity fields (ibscbs_, is_, totais_*, municipio_fato_gerador_ibs) with proper Decimal initialization and accumulation logic
pynfe/processamento/serializacao.py Implemented IBSCBS/IS serialization methods with CST-based conditional emission, totals in IBSCBSTot group, vNF exclusion logic
docs/reforma_tributaria.md Comprehensive documentation of tax reform implementation with usage examples and technical references
docs/*_map.md Source navigation maps for serializacao.py, comunicacao.py, notafiscal.py, flags.py, and other large files
AGENTS.md LLM navigation guide mandating source map consultation before reading large files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@felps-dev
Copy link
Collaborator Author

Contexto sobre o desenvolvimento da Reforma Tributaria:

O plano inicial de implementacao foi feito utilizando o Gemini, que gerou uma estrutura com bastante alucinacao sobre o XSD do XML — nomes de tags incorretos, estruturas de grupos inventadas, e relacoes entre elementos que nao existiam no schema real (PL 010b / DFeTiposBasicos_v1.00.xsd).

Apos testes com clientes reais em producao e validacao direta no SEFAZ, fomos corrigindo os problemas com auxilio do Claude, ate chegar na estrutura correta:

  • <IBSCBS> como filho direto de <imposto> (sem wrapper <impostoMisto> que o Gemini havia sugerido)
  • Tags conforme os tipos XSD reais: TTribNFe, TCIBS, TIBSCBSMonoTot, TIS
  • CSTs de 3 digitos conforme tabela oficial da NT 2025.002-RTC
  • Totais em <IBSCBSTot> com estrutura aninhada gIBS/gIBSUF, gIBS/gIBSMun, gCBS — validando no SEFAZ sem rejeicao

O XML agora esta validando corretamente no ambiente de producao do SEFAZ.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@felps-dev
Copy link
Collaborator Author

Validado, todos os clientes da minha base estão emitindo normalmente NF-e e NFC-e com a reforma tributária.

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.

3 participants