@mudraforge/statutory 2.13.0 → 2.14.0

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 (32) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +6 -0
  3. package/package.json +1 -4
  4. package/src/calculators.js +139 -3
  5. package/src/constants.js +1 -1
  6. package/types/index.d.ts +95 -0
  7. package/conformance/README.md +0 -54
  8. package/conformance/fixtures/invalid_malformed_temporal_dates.json +0 -10
  9. package/conformance/fixtures/invalid_missing_effective_period.json +0 -6
  10. package/conformance/fixtures/invalid_missing_section_code.json +0 -9
  11. package/conformance/fixtures/valid_circular_frontmatter.md +0 -16
  12. package/conformance/fixtures/valid_full_section.json +0 -35
  13. package/conformance/fixtures/valid_minimal_section.json +0 -11
  14. package/conformance/test_conformance.js +0 -129
  15. package/docs/ACCOUNTING_ASSURANCE_AUDIT_DOSSIER.md +0 -276
  16. package/docs/ADESHA_ASSURANCE_OVERVIEW.md +0 -166
  17. package/docs/ARCHITECTURE.md +0 -773
  18. package/docs/ARCHITECTURE_DECISIONS.md +0 -158
  19. package/docs/CASE_01_FORM_TEXT.txt +0 -48
  20. package/docs/CATALOG.md +0 -1901
  21. package/docs/CA_PILOT_BENCHMARK_CASES.md +0 -282
  22. package/docs/CORPUS_QUALITY.md +0 -106
  23. package/docs/DATA_LICENSING.md +0 -73
  24. package/docs/DOMAIN_BREADTH_AND_DEPTH_COMPARISON.md +0 -209
  25. package/docs/ENTERPRISE_GOVERNANCE.md +0 -160
  26. package/docs/OKF_MAINTENANCE_SOP.md +0 -286
  27. package/docs/PILOT_EVALUATION_GUIDE.md +0 -215
  28. package/docs/PROVENANCE.md +0 -33
  29. package/docs/VERIFICATION.md +0 -106
  30. package/examples/README.md +0 -56
  31. package/examples/invoice_deduction_trace.json +0 -149
  32. package/examples/simulate_end_to_end_trace.js +0 -106
@@ -1,158 +0,0 @@
1
- # MudraForge Statutory Knowledge Substrate — Architecture Decision Records (ADRs)
2
-
3
- > **Standard**: Lightweight ADR Format inspired by Michael Nygard & OpenSSF Project Governance
4
- > **Package**: `@mudraforge/statutory`
5
- > **Status**: Institutional Normative Standard
6
-
7
- ---
8
-
9
- ## ADR-0001: Offline-First Bundled Commons vs. Hosted Cloudflare Edge Sync
10
-
11
- ### Context
12
- Developers, AI agents, and enterprise ERP integrations need access to Indian statutory provisions (such as Section 194Q, 194J, 206C(1H), MSMED 15/16, and GST 17(5)). Relying solely on a hosted remote API introduces network latency, availability risks, single-point-of-failure vulnerabilities, and developer friction (requiring API keys for basic lookups).
13
-
14
- ### Decision
15
- We bundle an offline package of 29 canonical provisions across 5 domains directly within the NPM package filesystem (`okf/`), validated by an immutable SHA-256 Merkle root digest.
16
- - Lookups in default or `mode: 'local'` execute entirely against local disk with zero network requests.
17
- - Hosted Cloudflare Anycast edge synchronization is provided on a best-effort basis during beta to discover real-time gazette updates and expanded unbundled provisions.
18
- - If edge sync is unreachable, callers automatically degrade to the verified local snapshot with an explicit `advisory` signal.
19
-
20
- ### Consequences
21
- - **Positive**: Zero-network local evaluation works reliably in offline environments, test runners, and air-gapped CI/CD pipelines.
22
- - **Trade-off**: Bundled snapshots reflect the law at release time. Consumers must run `checkUpdates()` or check gazette notices for recent legislative amendments.
23
-
24
- ---
25
-
26
- ## ADR-0002: Decoupling Deterministic Statutory Calculators from Declarative OKF Data Models
27
-
28
- ### Context
29
- Large Language Models (LLMs) frequently hallucinate complex statutory threshold arithmetic (e.g. calculating Section 194Q TDS on the full ₹80 Lakhs invoice instead of the excess over ₹50 Lakhs, or failing to compound MSMED interest at 3x RBI bank rate).
30
-
31
- ### Decision
32
- We strictly decouple the declarative knowledge format (OKF v0.2 JSON schemas and Markdown circulars) from arithmetic calculation engines:
33
- 1. The open-source `@mudraforge/statutory` package defines declarative schemas, thresholds, rate schedules, and temporal validity bounds.
34
- 2. Exact statutory calculations are executed either by deterministic client functions or the paid MudraForge Cloudflare Worker engine.
35
- 3. Neither LLM text generation nor probabilistic prompts are ever permitted to compute statutory tax liability or interest.
36
-
37
- ### Consequences
38
- - **Positive**: Prevents catastrophic financial calculation drift and prompt injection risks.
39
- - **Trade-off**: The open-source package serves as a structured reference and validator; enterprise high-volume calculation is gated behind the deterministic calculation engine.
40
-
41
- ---
42
-
43
- ## ADR-0003: Commercial Boundary of Adesha Sovereign Payment Execution
44
-
45
- ### Context
46
- Open-sourcing tax knowledge creates technical trust, but enterprise organizations require governed execution to automate corporate accounts payable, treasury operations, and bank rail payouts without risk.
47
-
48
- ### Decision
49
- We formalize a strict 4-layer operational boundary:
50
- 1. **Layer 1: Open Statutory Knowledge (Open Source / MIT & CC BY 4.0)**: Machine-readable OKF schemas, circular frontmatter, CLI, and offline validator.
51
- 2. **Layer 2: Hosted Knowledge Services (Free Beta / Metered API)**: Cloudflare Anycast edge synchronization, remote manifest checking, and catalog expansions.
52
- 3. **Layer 3: Statutory Deduction Engine (Commercial Paid)**: Entity fact-matching, cross-provision conflict resolution, and deterministic statutory arithmetic.
53
- 4. **Layer 4: Adesha Sovereign Runtime (Enterprise Commercial)**: Human-in-the-Loop mobile authorization harness, TLA+-verified single-use payment leases, two-way ERP sync (SAP/Tally), and corporate banking rails.
54
-
55
- ### Consequences
56
- - **Positive**: Clear division of responsibilities; open-source users have an unencumbered, fully functional tax commons, while commercial clients obtain bank-grade execution safety.
57
-
58
- ---
59
-
60
- ## ADR-0004: Tripartite Versioning Specification
61
-
62
- ### Context
63
- Confusing package software updates with legal statutory amendments leads to silent downstream breakages. A statutory amendment does not necessarily change software APIs, and an SDK performance patch does not alter the law.
64
-
65
- ### Decision
66
- We establish three independent, non-interchangeable versioning dimensions:
67
-
68
- | Version Identifier | Target Governed | Lifecycle & Increment Rules | Example |
69
- | :--- | :--- | :--- | :--- |
70
- | **`okfVersion`** | Knowledge Schema Structure | Incremented only when the JSON schema or metadata fields change (e.g., adding a required field). | `0.2.0` |
71
- | **`corpusRelease`** | Legal Corpus Snapshot | Incremented when statutory provisions, rates, or circulars are updated or added. | `2026.04.1` |
72
- | **`version`** (SemVer) | NPM Client SDK & CLI | Standard Semantic Versioning for the JavaScript library, CLI commands, and test runners. | `2.10.0` |
73
-
74
- ---
75
-
76
- ## ADR-0005: Formal Product Capability Status Register
77
-
78
- ### Context
79
- To maintain institutional credibility, public documentation must never blur the line between currently published capabilities, planned features, and proprietary enterprise software.
80
-
81
- ### Status Register
82
-
83
- | Subsystem / Capability | Architectural Layer | Operational Status | Availability / Access | Verification Evidence |
84
- | :--- | :--- | :--- | :--- | :--- |
85
- | **Bundled OKF Statutory Corpus (46 Provisions across 5 Domains)** | Layer 1: Public Package | `PUBLIC_BUNDLED` | Immediate (Local repo & release candidate) | 166/166 test suites passing; SHA-256 Merkle root verified |
86
- | **Zero-Network CLI (`mudraforge-statutory`)** | Layer 1: Public Package | `PUBLIC_BUNDLED` | Immediate (Global / NPX) | `bin/cli.js` verified across Windows & Linux |
87
- | **Vendor-Neutral Conformance Suite** | Layer 1: Public Package | `PUBLIC_BUNDLED` | Immediate (`conformance/`) | 12/12 fixture tests passing |
88
- | **Local Query SDK (`src/index.js`)** | Layer 1: Public Package | `PUBLIC_BUNDLED` | Immediate (Node.js v18+) | Zero-dependency offline lookup and temporal checks |
89
- | **Synthetic AP Execution Trace (`examples/`)** | Layer 1: Public Package | `PUBLIC_DEMO_SYNTHETIC` | Immediate (`npm run example:trace`) | Modeled 7-stage lifecycle with synthetic test fixtures |
90
- | **Cloudflare Anycast Edge Sync** | Layer 2: Public Edge Service | `PUBLIC_EDGE_SYNC` | Free Beta (`api.mudraforge.in`) | Cloudflare Edge Worker manifest & bundle endpoints |
91
- | **Interactive API Documentation** | Layer 2: Public Edge Service | `PUBLIC_EDGE_SYNC` | Free Beta (`/api/v1/statutory/docs`) | OpenAPI 3.1 schema rendered live on Anycast edge |
92
- | **Universal Statutory Virtual Machine (USVM Kernel & Rules)** | Layer 1: Public Package | `PUBLIC_BUNDLED` | Immediate (`@mudraforge/statutory/usvm`) | 48 pre-cached declarative AST rule packages, rational BigInt math (<15µs latency) |
93
- | **Deterministic Corporate Finance Calculators** | Layer 1: Public Package | `PUBLIC_BUNDLED` | Immediate (`@mudraforge/statutory/calculators`) | Corporate tax MAT vs concessional, GST POS/LUT, TP ALP, Section 79, Ind AS 109, Section 288B |
94
- | **Hosted AP Engine & Cumulative Spend Tracking** | Layer 3: Enterprise Internal | `PILOT_STAGE_INTERNAL` | Metered Enterprise API (Selective) | Hosted cumulative Section 194Q thresholding & Section 16 MSMED interest |
95
- | **Dual-Custody Mobile Approval Harness** | Layer 4: Adesha Runtime | `INTERNAL_PROTOTYPE` | Enterprise License / Pilot Proposal | Mobile passkey approval prototype & TLA+ state machine |
96
- | **ERP Two-Way Connectors (SAP/Tally/Zoho)** | Layer 4: Adesha Runtime | `INTERNAL_DEVELOPMENT` | Custom Enterprise Pilot | Shadow-mode test connectors; no turnkey plug-ins shipped |
97
- | **Bank Rail API Adapters (ICICI/HDFC/RazorpayX)**| Layer 4: Adesha Runtime | `INTERNAL_DEVELOPMENT` | Custom Enterprise Pilot | Sandbox banking adapters requiring corporate partner onboarding |
98
-
99
- > **Critical Operational Distinction**: Items marked `PUBLIC_BUNDLED` and `PUBLIC_EDGE_SYNC` represent inspectable, working software. Items marked `PILOT_STAGE_INTERNAL`, `INTERNAL_PROTOTYPE`, and `INTERNAL_DEVELOPMENT` represent proprietary or developing enterprise capabilities; they are not shipped as generally available consumer software and their execution traces rely on modeled synthetic data.
100
-
101
- ---
102
-
103
- ## ADR-0006: Declarative Composite Transaction Profiles and Domain Knowledge Graphs
104
-
105
- ### Context
106
- Commercial lifecycle events (such as corporate acquisitions, slump sales, mergers, and vendor onboarding runs) are not individual statutes. Instead, they represent business transaction archetypes that trigger multiple intersecting statutory regimes across Direct Tax, Indirect Tax (GST), and Corporate Governance (Companies Act).
107
-
108
- Treating complex transactions as flat, isolated `section.json` files forces consuming developers and AI agents to guess the relationships, execution sequences, and documentary requirements connecting relevant laws. Conversely, hardcoding operational execution logic, linear numbering assumptions, or premature legal verdicts (e.g. declaring a deal void due to a missing certificate without evaluating statutory safe harbors) into declarative formats violates both open knowledge standards and sound statutory jurisprudence.
109
-
110
- ### Decision
111
- We establish a 3-tier declarative knowledge model for complex multi-statute transactions:
112
-
113
- 1. **Tier 1: Atomic Statutory Provision (`section.json`)**: Authoritative legislative text, official Gazette citations, rates, and temporal validity windows.
114
- 2. **Tier 2: Legal Concept Definition (`concepts/*.md`)**: Substantive interpretation boundaries, statutory conditions, exceptions, safe harbors, and evidence checklists (Markdown with structured YAML frontmatter).
115
- 3. **Tier 3: Composite Transaction Profile (`composites/*.json`)**: Declarative relationship graph connecting relevant concepts and provisions for a specific business transaction archetype.
116
-
117
- #### Core Architectural Invariants:
118
- 1. **Extension Attribution**: Composite profiles are documented as a versioned **MudraForge OKF Transaction Extension**, keeping them distinct from upstream Google OKF v0.2 core specifications while fully utilizing OKF frontmatter conventions.
119
- 2. **Logical Dependencies vs. Operational Ordering**:
120
- - `dependsOn` strictly denotes a **logical prerequisite** where a downstream statutory test is contingent on an upstream outcome (e.g. evaluating GST Notification 12/2017 going-concern nil-rate eligibility logically depends on whether the transfer satisfies the Section 50B "undertaking" test).
121
- - In contrast, operational ordering is not enforced as a rigid constraint; independent checks (such as Section 281 tax proceedings verification and Section 180 corporate approval) remain independently runnable even when another inquiry is pending, unresolved, or awaiting documentation.
122
- 3. **Statutory Safe Harbors over Binary Failure Verdicts**: Profiles declare applicable legal questions, statutory conditions, safe harbors (e.g., bona fide purchaser for value without notice under Section 281), and evidentiary burdens, leaving judicial or executive determinations to runtime evaluation engines.
123
- 4. **Strict Temporal Enactment Distinguishability**: Corresponding provisions under the Income-tax Act, 1961 (such as §281, §170) and the Income-tax Act, 2025 (such as §499, §313 taking effect 1 April 2026) must remain explicitly distinguished by enactment code and effective period.
124
- 5. **Separation of Open Knowledge from Governed Execution**:
125
- - The open commons (`@mudraforge/statutory`) provides the inspectable, reusable, and testable dependency graph of laws and evidence requirements.
126
- - The commercial runtime (Adesha) executes deterministic calculations, enforces bank escrow locks, requires CFO biometric authorization, and writes balanced ERP journal entries.
127
- 6. **Normative Scope & Independent Legal Validation**:
128
- - An Architecture Decision Record defines structural design invariants and data contracts; it does not substitute for independent legal certification of specific transaction scenarios. All composite profiles and legal-version mappings must be validated against independent legal ground truth in dedicated scenario test suites before promotion to stable status.
129
-
130
- #### Prototype Implementation Requirements (feature/composite-transaction-profiles):
131
- Prior to merging any composite transaction prototype into `main`, the implementation must satisfy four strict verification gates:
132
- 1. **Precise Graph Semantics & Acyclicity**: Formally define `dependsOn`, `parallelIndependentChecks`, and `conditionalDownstreamChecks`. Implement automated DAG validation that rejects circular dependencies and cleanly halts downstream evaluation when an upstream prerequisite is `UNKNOWN` or `UNRESOLVED`.
133
- 2. **Temporal & Provenance Continuity**: Every statutory reference in a profile must carry an unambiguous enactment code, provision identifier, official Gazette source URL, and `effectivePeriod`. Cross-regime profiles must evaluate against an explicit `asOfDate` rather than silently blending provisions from different legislative eras.
134
- 3. **Four-State Epistemic Uncertainty Model**: Inquiries must be evaluated against an explicit four-state epistemic model (`SATISFIED`, `NOT_SATISFIED`, `UNKNOWN` / `EVIDENCE_PENDING`, and `NOT_APPLICABLE`). Missing documentation or unverified assertions must remain `UNKNOWN` rather than prematurely collapsing into negative legal conclusions.
135
- 4. **Independent Open-Source Usability (Zero Vendor Lock-in)**: A third-party developer or external AI agent must be able to load a composite profile, validate its schema, traverse its dependency graph, and inspect its evidence checklists locally and offline using only `@mudraforge/statutory`, with zero dependency on the proprietary Adesha runtime, API keys, or remote servers.
136
-
137
- ### Consequences
138
- - **Positive**: Makes complex statutory relationships discoverable and machine-readable for AI agents without compromising open-source format purity or disclosing proprietary execution code.
139
- - **Lifecycle Management**: Implemented as an experimental prototype on a dedicated feature branch (`feature/composite-transaction-profiles`) and subjected to independent legal scenario benchmarking prior to promotion into public release `v2.5.0`. Release `v2.4.0` remains focused on the verified atomic statutory corpus.
140
-
141
- ---
142
-
143
- ## ADR-0007: Universal Statutory Virtual Machine (USVM) Declarative AST Kernel
144
-
145
- ### Context
146
- Historically, statutory tax calculations were coded as imperative JavaScript branching functions. As statutory provisions grew to 46+ sections across 5 domains, imperative functions introduced code duplication, maintenance overhead, and higher bundle sizes for edge and browser environments. Imperative procedural code also made independent statutory verification opaque for non-developer tax professionals and audit teams.
147
-
148
- ### Decision
149
- We introduce the Universal Statutory Virtual Machine (USVM) declarative Abstract Syntax Tree (AST) evaluation kernel:
150
- 1. **Stateless AST Evaluation Kernel (`src/usvm/evaluation_vm.js`)**: A compact 355-line stateless virtual machine evaluating declarative AST rule definitions without imperative branching.
151
- 2. **5-Stage Rational BigInt Arithmetic (`src/usvm/math_rational.js`)**: Arithmetic is evaluated using exact rational fractions (`[numerator, denominator]` pairs) to eliminate IEEE 754 floating-point precision loss.
152
- 3. **Co-Located Declarative Rules**: 46 `ast.json` rule packages co-located within the 5 canonical OKF domains, alongside 48 pre-cached rules in `src/usvm/rules/*.json`.
153
- 4. **Tree-Shakable Subpath (`@mudraforge/statutory/usvm`)**: Exposes `evaluateStatutoryAst`, `validateStatutoryAst`, and `toBigIntPaise` in an ultra-lightweight bundle (~12 kB GZIP vs 92.9 kB full library).
154
- 5. **Fiduciary Statutory Invariant**: Every evaluation strictly enforces `isAuthorizedToDisburse: false`.
155
-
156
- ### Consequences
157
- - **Positive**: Replaces thousands of lines of imperative procedural code with declarative JSON AST definitions; achieves sub-microsecond evaluation latency (p50: 14.32 microseconds); enables tree-shakable client bundles.
158
- - **Backward Compatibility**: Fully backward compatible with existing procedural API callers.
@@ -1,48 +0,0 @@
1
- INWARD INVOICE SLIP (TAX INVOICE)
2
- --------------------------------------------------------------------------------
3
- Supplier: Precision Castings Pvt. Ltd. | GSTIN: 27AAACP1234F1ZV (Maharashtra)
4
- PAN : AAACP1234F (Company) | MSME : UDYAM-MH-03-0019842 (Micro Mfr)
5
- Inv No : PCPL/25-26/0541 | Date : 01-May-2025 (GRN: 01-May-2025)
6
- Terms : PO-2025-0892 (Net 60 Days) | Supply: HSN 732599 (Valve Castings)
7
- Basic : ₹20,00,000.00 | IGST 18%: ₹3,60,000.00
8
- Total : ₹23,60,000.00 | Place of Supply: Gujarat (Interstate)
9
-
10
- BUYER ERP CONTEXT (Zenith Engineering Pvt. Ltd.)
11
- --------------------------------------------------------------------------------
12
- Prior FY Turnover : ₹18.50 Crore (Exceeds ₹10 Cr 194Q Gate)
13
- YTD Purchases : ₹45,00,000.00 prior to this bill (Excl. GST, on credit)
14
- PAN Status : Active & Operative
15
-
16
- MUDRAFORGE ENGINE OUTPUT (STATUTORY DETERMINATION)
17
- --------------------------------------------------------------------------------
18
- 1. Section 194Q TDS:
19
- - Taxable Base : ₹15,00,000 (Excess over ₹50L; GST excluded per Cir 13/2021)
20
- - TDS Rate : 0.1% (Standard operative PAN rate)
21
- - TDS Amount : ₹1,500.00 (Exceeds ₹50L base; satisfies Section 288B multiple-of-10 rounding)
22
-
23
- 2. MSMED Act Sec 15 & Sec 43B(h):
24
- - Status : Micro Manufacturer (NIC 24311)
25
- - Credit Term : 60-day term is void; capped at 45 days from GRN (01-May-2025)
26
- - Cutoff Date : 15-June-2025 (To avoid Sec 16 interest & 43B(h) disallowance)
27
-
28
- 3. General Ledger Posting:
29
- - Dr. Expense ₹20,00,000 | Dr. IGST ₹3,60,000
30
- - Cr. TDS Payable ₹1,500 | Cr. Vendor AP ₹23,58,500
31
-
32
- SPREADSHEET COMPLIANCE FORMULAS
33
- --------------------------------------------------------------------------------
34
- 1. TDS WITHHOLDING (Section 194Q):
35
- • Standard Excel (Generic All-in-One):
36
- =IF(AND(BuyerTurnoverCr > 10, TxnDate >= DATE(2021,7,1)), ROUND((MAX(0, (PriorSpend + IF(IsAdvance, GrossAmt, GrossAmt - GstAmt)) - 5000000) - MAX(0, PriorSpend - 5000000)) * IF(HasOperativePAN, 0.1%, 5.0%), -1), 0)
37
-
38
- • Standard Excel (Case 01 Values):
39
- =IF(AND(18.5 > 10, DATE(2025,5,1) >= DATE(2021,7,1)), ROUND((MAX(0, (4500000 + IF(FALSE, 2360000, 2360000 - 360000)) - 5000000) - MAX(0, 4500000 - 5000000)) * IF(TRUE, 0.1%, 5.0%), -1), 0)
40
-
41
- • MudraForge Add-in:
42
- =MF.TDS("194Q", 2360000, 4500000, TRUE, "2025-05-01", 18.5, 360000, FALSE)
43
- -> Result : ₹1,500.00
44
-
45
- 2. STATUTORY DUE DATE (MSMED Act Section 15 & Section 43B(h)):
46
- • Standard Excel : =DeliveryDate + MIN(AgreedContractDays, 45)
47
- • MudraForge : =MF.MSME.DUEDATE("2025-05-01", TRUE, "2025-06-30")
48
- -> Result : 15-June-2025