@mudraforge/statutory 2.12.1 → 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 (134) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +19 -0
  3. package/okf/corporate_ma_restructuring/business_combinations_indas_103/ast.json +20 -0
  4. package/okf/corporate_ma_restructuring/impairment_of_assets_indas_36/ast.json +20 -0
  5. package/okf/corporate_ma_restructuring/loss_carryforward_sec79/ast.json +33 -0
  6. package/okf/corporate_ma_restructuring/share_based_payments_indas_102/ast.json +20 -0
  7. package/okf/corporate_ma_restructuring/slump_sale_50b/ast.json +21 -0
  8. package/okf/corporate_ma_restructuring/tax_clearance_sec281/ast.json +21 -0
  9. package/okf/direct_tax/corporate_tax_115baa_115jb/ast.json +23 -0
  10. package/okf/direct_tax/income_taxes_deferred_tax_indas_12/ast.json +20 -0
  11. package/okf/direct_tax/special_rates_non_filer_206ab/ast.json +26 -0
  12. package/okf/direct_tax/statutory_disallowance_43b/ast.json +35 -0
  13. package/okf/direct_tax/tcs_goods_206c_1h/ast.json +69 -0
  14. package/okf/direct_tax/tds_commission_194h/ast.json +60 -0
  15. package/okf/direct_tax/tds_contractor_194c/ast.json +71 -0
  16. package/okf/direct_tax/tds_ecommerce_194o/ast.json +48 -0
  17. package/okf/direct_tax/tds_goods_194q/ast.json +71 -0
  18. package/okf/direct_tax/tds_goods_393/ast.json +59 -0
  19. package/okf/direct_tax/tds_individual_contract_194m/ast.json +59 -0
  20. package/okf/direct_tax/tds_interest_194a/ast.json +59 -0
  21. package/okf/direct_tax/tds_perquisites_194r/ast.json +47 -0
  22. package/okf/direct_tax/tds_property_194ia/ast.json +70 -0
  23. package/okf/direct_tax/tds_rent_194i/ast.json +60 -0
  24. package/okf/direct_tax/tds_rent_individual_194ib/ast.json +59 -0
  25. package/okf/direct_tax/tds_services_194j/ast.json +60 -0
  26. package/okf/indirect_tax_gst/blocked_itc_17_5/ast.json +26 -0
  27. package/okf/indirect_tax_gst/common_itc_reversal_rule42_43/ast.json +26 -0
  28. package/okf/indirect_tax_gst/composite_mixed_supplies_sec8/ast.json +21 -0
  29. package/okf/indirect_tax_gst/composition_levy_sec10/ast.json +23 -0
  30. package/okf/indirect_tax_gst/credit_debit_notes_sec34/ast.json +21 -0
  31. package/okf/indirect_tax_gst/e_invoicing_rule48_4/ast.json +20 -0
  32. package/okf/indirect_tax_gst/export_services_lut_sec16/ast.json +20 -0
  33. package/okf/indirect_tax_gst/gst_tds_sec51/ast.json +23 -0
  34. package/okf/indirect_tax_gst/itc_eligibility_16_2/ast.json +20 -0
  35. package/okf/indirect_tax_gst/itc_reversal_rule37_37a/ast.json +45 -0
  36. package/okf/indirect_tax_gst/rcm_liability_sec9_3/ast.json +26 -0
  37. package/okf/international_tax/cross_border_remittance_195/ast.json +39 -0
  38. package/okf/international_tax/financial_instruments_ecl_indas_109/ast.json +24 -0
  39. package/okf/international_tax/foreign_exchange_indas_21_109/ast.json +20 -0
  40. package/okf/international_tax/foreign_tax_credit_irc_901_904/ast.json +20 -0
  41. package/okf/international_tax/transfer_pricing_alp_92c/ast.json +25 -0
  42. package/okf/manifest.json +49 -3
  43. package/okf/msme_commercial/delayed_payments_15_16/ast.json +38 -0
  44. package/okf/msme_commercial/enterprise_classification_sec7/ast.json +25 -0
  45. package/okf/msme_commercial/lease_accounting_indas_116/ast.json +20 -0
  46. package/okf/msme_commercial/mca_msme_1_filing/ast.json +20 -0
  47. package/okf/msme_commercial/provisions_contingencies_indas_37/ast.json +20 -0
  48. package/okf/msme_commercial/revenue_recognition_indas_115/ast.json +20 -0
  49. package/okf/msme_commercial/statutory_disclosures_sec22/ast.json +21 -0
  50. package/package.json +16 -4
  51. package/src/calculators.js +139 -3
  52. package/src/constants.js +1 -1
  53. package/src/index.js +16 -2
  54. package/src/payroll.js +506 -0
  55. package/src/usvm/evaluation_vm.js +504 -0
  56. package/src/usvm/index.js +65 -0
  57. package/src/usvm/math_rational.js +165 -0
  58. package/src/usvm/rules/sec_115baa_115jb_mat.json +23 -0
  59. package/src/usvm/rules/sec_192_salary_tds.json +23 -0
  60. package/src/usvm/rules/sec_194a_interest.json +59 -0
  61. package/src/usvm/rules/sec_194c_contractors.json +71 -0
  62. package/src/usvm/rules/sec_194h_commission.json +60 -0
  63. package/src/usvm/rules/sec_194i_rent.json +60 -0
  64. package/src/usvm/rules/sec_194ia_property.json +70 -0
  65. package/src/usvm/rules/sec_194ib_rent_ind.json +59 -0
  66. package/src/usvm/rules/sec_194j_services.json +60 -0
  67. package/src/usvm/rules/sec_194m_contract_ind.json +59 -0
  68. package/src/usvm/rules/sec_194o_ecommerce.json +48 -0
  69. package/src/usvm/rules/sec_194q_goods.json +71 -0
  70. package/src/usvm/rules/sec_194r_perquisites.json +47 -0
  71. package/src/usvm/rules/sec_195_cross_border.json +39 -0
  72. package/src/usvm/rules/sec_206ab_non_filer.json +26 -0
  73. package/src/usvm/rules/sec_206c1h_tcs.json +69 -0
  74. package/src/usvm/rules/sec_281_tax_clearance.json +21 -0
  75. package/src/usvm/rules/sec_393_goods.json +59 -0
  76. package/src/usvm/rules/sec_43bh_disallowance.json +35 -0
  77. package/src/usvm/rules/sec_50b_slump_sale.json +21 -0
  78. package/src/usvm/rules/sec_79_loss_continuity.json +33 -0
  79. package/src/usvm/rules/sec_92c_transfer_pricing.json +25 -0
  80. package/src/usvm/rules/sec_ftc_dtaa_relief.json +20 -0
  81. package/src/usvm/rules/sec_gst_blocked_itc_17_5.json +26 -0
  82. package/src/usvm/rules/sec_gst_composite_mixed_8.json +21 -0
  83. package/src/usvm/rules/sec_gst_composition_levy_10.json +23 -0
  84. package/src/usvm/rules/sec_gst_credit_debit_notes_34.json +21 -0
  85. package/src/usvm/rules/sec_gst_einvoicing_rule48_4.json +20 -0
  86. package/src/usvm/rules/sec_gst_ewaybill_rule138.json +21 -0
  87. package/src/usvm/rules/sec_gst_export_lut_16.json +20 -0
  88. package/src/usvm/rules/sec_gst_itc_eligibility_16_2.json +20 -0
  89. package/src/usvm/rules/sec_gst_itc_reversal_rule37_37a.json +45 -0
  90. package/src/usvm/rules/sec_gst_rcm_liability_9_3.json +26 -0
  91. package/src/usvm/rules/sec_gst_rule42_43_apportionment.json +26 -0
  92. package/src/usvm/rules/sec_gst_tds_sec51.json +23 -0
  93. package/src/usvm/rules/sec_indas102_esop.json +20 -0
  94. package/src/usvm/rules/sec_indas103_mna.json +20 -0
  95. package/src/usvm/rules/sec_indas109_ecl.json +24 -0
  96. package/src/usvm/rules/sec_indas115_revenue.json +20 -0
  97. package/src/usvm/rules/sec_indas116_leases.json +20 -0
  98. package/src/usvm/rules/sec_indas12_deferred_tax.json +20 -0
  99. package/src/usvm/rules/sec_indas21_fx_reval.json +20 -0
  100. package/src/usvm/rules/sec_indas36_impairment.json +20 -0
  101. package/src/usvm/rules/sec_indas37_provisions.json +20 -0
  102. package/src/usvm/rules/sec_msme_classification_sec7.json +25 -0
  103. package/src/usvm/rules/sec_msme_delayed_payments_15_16.json +38 -0
  104. package/src/usvm/rules/sec_msme_disclosures_sec22.json +21 -0
  105. package/src/usvm/rules/sec_msme_mca_form_1.json +20 -0
  106. package/src/usvm/schemas/statutory_ast_schema.js +203 -0
  107. package/src/usvm/usvm_domain_evaluators.js +1021 -0
  108. package/types/index.d.ts +134 -0
  109. package/conformance/README.md +0 -54
  110. package/conformance/fixtures/invalid_malformed_temporal_dates.json +0 -10
  111. package/conformance/fixtures/invalid_missing_effective_period.json +0 -6
  112. package/conformance/fixtures/invalid_missing_section_code.json +0 -9
  113. package/conformance/fixtures/valid_circular_frontmatter.md +0 -16
  114. package/conformance/fixtures/valid_full_section.json +0 -35
  115. package/conformance/fixtures/valid_minimal_section.json +0 -11
  116. package/conformance/test_conformance.js +0 -129
  117. package/docs/ACCOUNTING_ASSURANCE_AUDIT_DOSSIER.md +0 -276
  118. package/docs/ADESHA_ASSURANCE_OVERVIEW.md +0 -166
  119. package/docs/ARCHITECTURE.md +0 -750
  120. package/docs/ARCHITECTURE_DECISIONS.md +0 -138
  121. package/docs/CASE_01_FORM_TEXT.txt +0 -48
  122. package/docs/CATALOG.md +0 -1901
  123. package/docs/CA_PILOT_BENCHMARK_CASES.md +0 -282
  124. package/docs/CORPUS_QUALITY.md +0 -106
  125. package/docs/DATA_LICENSING.md +0 -73
  126. package/docs/DOMAIN_BREADTH_AND_DEPTH_COMPARISON.md +0 -209
  127. package/docs/ENTERPRISE_GOVERNANCE.md +0 -159
  128. package/docs/OKF_MAINTENANCE_SOP.md +0 -286
  129. package/docs/PILOT_EVALUATION_GUIDE.md +0 -214
  130. package/docs/PROVENANCE.md +0 -33
  131. package/docs/VERIFICATION.md +0 -106
  132. package/examples/README.md +0 -56
  133. package/examples/invoice_deduction_trace.json +0 -149
  134. package/examples/simulate_end_to_end_trace.js +0 -106
@@ -1,276 +0,0 @@
1
- # MudraForge Accounting Assurance & Statutory Audit Defense Dossier
2
-
3
- This document serves as the authoritative, permanent reference manual and verification catalog for the enterprise Accounts Payable (AP) reconciliation, numerical hygiene, and statutory assurance capabilities implemented in `@mudraforge/statutory`.
4
-
5
- External technical, financial, and tax audits (e.g. Big-4 accounting firms, statutory auditors, tax counsel) frequently probe automated financial platforms for theoretical shortcuts, unhandled edge cases, and legal misinterpretations. This dossier establishes the legal ground truth, mathematical definitions, error boundaries, and corresponding automated regression tests (Tests 120 through 146 in `packages/statutory/test.js`) that guarantee deterministic audit defensibility.
6
-
7
- ---
8
-
9
- ## 1. Architectural Philosophy: From Statutory Calculation to Accounting Assurance
10
-
11
- A statutory calculation engine that merely implements standalone formulas (e.g. `turnover * 0.001`) fails when exposed to real enterprise ERP exports. Raw corporate accounting data is inherently messy: it contains parenthesized credits, trailing minus signs, inconsistent currency formatting, conflicting tax allocations, multi-state branch structures, and varying payment appropriation policies.
12
-
13
- MudraForge implements **Transaction-Level Accounting Assurance**:
14
-
15
- ```
16
- Messy Accounting Ingestion (Zoho Books / Tally Daybooks / GSTR-2B)
17
- ↓
18
- Four-State Numeric Classification & Integer-Paise Normalization (Zero Drift)
19
- ↓
20
- Epistemic Uncertainty Gate (ISO Mod-36 Checksums, Duplicate Billing, Defective Tax Splits)
21
- ↓
22
- 4-Way Decoupled Jurisdictional Evaluation (Tax Classification, Jurisdiction, Eligibility, Routing)
23
- ↓
24
- Statutory Provisos & Accounting Math (Rule 37 Proportional Allocation, Rule 88B ECL Audit)
25
- ↓
26
- Actionable Exception Register & Executive Audit Memorandum (isAuthorizedToDisburse: false)
27
- ```
28
-
29
- ---
30
-
31
- ## 2. Numerical Hygiene & Input Boundary Hardening
32
-
33
- ### 2.1 Four-State Numeric Classification Model
34
- Standard JavaScript type coercion (`Number(x) || 0`) introduces catastrophic statutory failures: malformed strings (e.g. `"₹ 10,00,000"`, `"#VALUE!"`) silently evaluate to `NaN` and collapse to `0`, preventing mandatory tax deductions and creating massive penal exposure under Section 40(a)(ia).
35
-
36
- MudraForge's `cleanNumericAmount(val, options)` classifies every numeric input into one of four distinct states:
37
-
38
- | Input State | Example | Engine Behavior | Statutory Rationale |
39
- |---|---|---|---|
40
- | **Valid Numeric** | `100000`, `"₹ 10,00,000"`, `"(₹ 50,000)"` | Deterministic float or integer paise | Legitimate transaction amount. |
41
- | **Valid Zero** | `0`, `"0"`, `"₹ 0.00"` | Returns `0` (or `0` paise) | Explicit non-taxable base or zero-rated voucher. |
42
- | **Missing Optional** | `undefined`, `null`, `""` (when optional) | Returns `options.defaultValue` | Unused optional fields (e.g. surcharge, cess). |
43
- | **Missing Mandatory** | `undefined`, `null`, `""` (when mandatory) | Throws `MissingMandatoryParameterError` | Essential statutory threshold inputs cannot be guessed. |
44
- | **Malformed Representation** | `"100 200"`, `"1,,000"`, `"#VALUE!"` | Throws `MalformedNumericInputError` | Prevents corrupt ERP exports from silently distorting tax calculations. |
45
-
46
- ### 2.2 Integer-Paise Arithmetic & Max Safe Integer Boundary
47
- To eliminate floating-point drift across cumulative annual purchases and multi-invoice allocations:
48
- - **Integer Representation**: All intermediate thresholds, allocations, and variances are converted to integer paise using `toIntegerPaise(amount)`.
49
- - **Ceiling Boundary**: Values exceeding `Number.MAX_SAFE_INTEGER` (9,007,199,254,740,991 paise = ₹90,071,992,547,409.91) are rejected fail-closed to prevent IEEE 754 precision degradation.
50
- - **Sub-Paisa Rounding**: Half-up rounding (`roundToPaisa(amount)`) is applied consistently.
51
-
52
- ### 2.3 Accounting Format Ingestion
53
- - **Parenthesized Negatives**: Accounting conventions representing negative balances as `(₹ 50,000.00)` or `INR (25,000)` are parsed as negative numbers.
54
- - **Trailing Minus**: ERP formats such as `50,000.00-` are normalized to `-50000.00`.
55
- - **Ledger-Aware CR Credits**: Credit indicators (`CR`) are not blindly negated; credit balances are preserved as positive balances unless `{ interpretCreditAsNegative: true }` is explicitly requested by the ledger parser.
56
-
57
- ---
58
-
59
- ## 3. Four-Way Decoupled Jurisdictional Matrix
60
-
61
- Enterprise ERP workflows cannot rely on a single binary eligibility flag (`ELIGIBLE` vs `INELIGIBLE`). Real tax assurance requires decoupling four orthogonal decisions on every transaction:
62
-
63
- ```
64
- Transaction Evaluation
65
- │
66
- ┌──────────────────┬──────────────┴─────┬─────────────────┐
67
- ▼ ▼ ▼ ▼
68
- 1. Tax Determination 2. Recipient 3. ITC 4. Operational
69
- (IGST Act Sec 5/10) Jurisdiction Eligibility Routing
70
- (CGST Sec 25(4)) (Sec 16/17(5)) (ERP Action)
71
- ```
72
-
73
- ### 3.1 Decision Taxonomy
74
-
75
- #### 1. Tax Determination (`taxClassification`)
76
- - `INTRASTATE_CORRECT`: Supplier state equals POS state; local CGST + SGST charged correctly.
77
- - `INTERSTATE_CORRECT`: Supplier state differs from POS state; IGST charged correctly.
78
- - `ERRONEOUS_INTRASTATE_LEVY`: Supplier state differs from POS, but supplier erroneously charged local CGST/SGST.
79
- - `ERRONEOUS_INTERSTATE_LEVY`: Supplier state equals POS, but supplier erroneously charged IGST.
80
- - `INDETERMINATE`: Missing Place of Supply or conflicting tax split.
81
-
82
- #### 2. Recipient Jurisdiction (`recipientJurisdiction`)
83
- - `FILING_GSTIN_MATCHES_POS`: The filing entity's registered state matches the Place of Supply.
84
- - `REGISTERED_DISTINCT_PERSON_BRANCH`: Recipient's corporate enterprise maintains a valid distinct-person GSTIN under Section 25(4) in the POS state.
85
- - `UNREGISTERED_IN_POS_STATE`: Recipient has no GST registration in the POS state.
86
- - `INDETERMINATE`: Missing recipient or POS state code.
87
-
88
- #### 3. ITC Eligibility (`itcEligibility`)
89
- - `ELIGIBLE_NORMAL`: Valid tax invoice, populated in GSTR-2B, no statutory blocks.
90
- - `ELIGIBLE_IN_BRANCH_RETURN`: Valid tax credit, but must be claimed in the branch GSTIN's GSTR-3B.
91
- - `INELIGIBLE_STRANDED_LOCAL_LEVY`: Mandatory local supply under Section 12(3)/12(4) (e.g. hotel, catering) in a state where recipient is unregistered.
92
- - `INELIGIBLE_BLOCKED_SEC_17_5`: Blocked under Section 17(5) (motor vehicles, outdoor catering, employee personal perks).
93
- - `INELIGIBLE_DEFECTIVE_INVOICE`: Defective tax split or erroneous jurisdiction.
94
- - `INELIGIBLE_PORTAL_FLAGGED`: Flagged ineligible by GSTN portal in Form GSTR-2B (e.g. Section 16(4) time-bar).
95
- - `PROVISIONAL_PENDING_FILING`: Missing in current GSTR-2B, credit restricted under Section 16(2)(aa) and Rule 36(4).
96
- - `INDETERMINATE`: Requires human review.
97
-
98
- #### 4. Operational Routing (`operationalRouting`)
99
- - `CLAIM_IN_CURRENT_GSTR3B_TABLE_4A5`: Avail in current tax period return.
100
- - `ROUTE_TO_BRANCH_GSTIN`: Route accounting voucher to branch entity for inclusion in their state return.
101
- - `BOOK_AS_EXPENSE_NO_ITC`: Absorb tax component as business operating expense; do not avail in ECL.
102
- - `REPORT_IN_GSTR3B_TABLE_4B1_PERMANENT_REVERSAL`: Report permanent non-reclaimable reversal.
103
- - `REQUEST_VENDOR_CREDIT_NOTE_AMENDMENT`: Issue commercial dispute notice demanding credit note and reissue.
104
- - `WITHHOLD_CLAIM_PENDING_SUPPLIER_GSTR1`: Withhold claim until vendor files Form GSTR-1/IFF.
105
- - `PHYSICAL_GOODS_RECEIPT_VERIFICATION_PENDING`: In GSTR-2B but missing in books (unrecorded AP or transit).
106
- - `MANUAL_HUMAN_INVESTIGATION_REQUIRED`: Escalate to senior tax auditor.
107
-
108
- ---
109
-
110
- ## 4. Rule 37 Proportional Reversal & Rule 88B(3) ECL Audit
111
-
112
- ### 4.1 Section 16(2) Second Proviso & Rule 37 Payment Appropriation
113
- Section 16(2) second proviso requires a recipient to pay the supplier the value of supply along with tax within 180 days from the invoice date. Failure to pay triggers mandatory ITC reversal.
114
-
115
- MudraForge implements three payment appropriation models:
116
- 1. **`PROPORTIONATE` (Default Statutory Baseline)**:
117
- $$\text{Unpaid Ratio} = \frac{\text{Balance Due}}{\text{Total Invoice Amount}}$$
118
- $$\text{Reversal ITC} = \text{Total ITC} \times \text{Unpaid Ratio}$$
119
- 2. **`VALUE_FIRST` (Contractual Preference)**:
120
- Payments satisfy the taxable base first; remaining balance is attributed to unpaid tax.
121
- 3. **`TAX_FIRST` (Tax Compliance Priority)**:
122
- Payments satisfy tax liability first. Note: Failure to pay taxable consideration still triggers proportional reversal under Rule 37(1).
123
-
124
- ### 4.2 Statutory Exemptions from Rule 37
125
- - **Proviso 1 to Rule 37(1) — Reverse Charge (RCM)**: RCM supplies under Section 9(3)/9(4) are statutorily exempt because tax is paid directly to the Government, not the supplier.
126
- - **Proviso 2 to Rule 37(1) — Schedule I Deemed Supplies**: Supplies without consideration between distinct or related persons are statutorily exempt.
127
-
128
- ### 4.3 Rule 88B(3) Electronic Credit Ledger Audit & Section 50(1) Interest
129
- Under Section 50(1) read with Rule 88B(3) (inserted retrospectively w.e.f. 1 July 2017), interest is levied **only when ITC has been wrongly availed and utilized**.
130
-
131
- - **ECL Closing Balance Check**: If the minimum daily closing balance in the taxpayer's Electronic Credit Ledger (`minimumEclBalanceInr`) remained equal to or greater than the unreversed ITC throughout the default window:
132
- $$\text{Wrongful Utilization} = \max(0, \text{Unreversed ITC} - \text{Minimum ECL Balance}) = ₹0.00$$
133
- $$\text{Statutory Interest} = ₹0.00$$
134
- - **Dipped Balance**: If the ECL balance dipped below the unreversed ITC, 18% annual interest is computed strictly on the utilized portion for the days elapsed past 180:
135
- $$\text{Interest} = \text{Utilized Amount} \times \frac{0.18}{365} \times (\text{Days Elapsed} - 180)$$
136
- - **Unavailable History**: If closing ledger balances are missing, the engine refuses to guess, issuing an advisory requiring human verification of ledger statements.
137
-
138
- ---
139
-
140
- ## 5. Epistemic Uncertainty & Fail-Closed Governance
141
-
142
- When financial or legal evidence is incomplete, automated accounting engines must never fabricate certainty. MudraForge marks transactions as `REQUIRES_HUMAN_VERIFICATION` under five statutory conditions:
143
-
144
- 1. **`INVALID_SUPPLIER_GSTIN_CHECKSUM`**: Supplier GSTIN fails ISO Mod-36 check digit calculation. Prevents claiming credits on invalid or fraudulent registrations.
145
- 2. **`AMBIGUOUS_DUPLICATE_INVOICE_MATCH`**: Multiple candidate records share the identical supplier GSTIN and invoice number. Prevents guessing between duplicate billing and amended vouchers.
146
- 3. **`CONTRADICTORY_TAX_SPLIT`**: Voucher contains concurrent CGST/SGST and IGST. Defective on its face under Section 31.
147
- 4. **`MISSING_POS_DATA`**: Place of Supply is omitted or indeterminate in both Books and GSTR-2B.
148
- 5. **`MISSING_ECL_HISTORY`**: Electronic Credit Ledger closing balances are omitted when evaluating delayed interest.
149
-
150
- ---
151
-
152
- ## 6. The Complete Verification Matrix: Tests 120 through 146
153
-
154
- Every statutory capability and defensive boundary is continuously verified by deterministic regression tests in `packages/statutory/test.js`:
155
-
156
- | Test # | Test Title | Statutory / Accounting Provision | Ground Truth Verified |
157
- |---|---|---|---|
158
- | **120** | Numerical Input Resilience & Currency Sanitization | Enterprise ERP Ingestion Standards | Normalizes `"₹ 10,00,000"`, `"1,23,456.78"`, whitespace, and non-finite inputs. |
159
- | **121** | Excel Date Serial & Diverse Date Normalization | RFC 4180 / Microsoft Excel Standards | Normalizes Excel serial numbers (`45453` -> `2024-06-10`) and Indian date formats (`10/06/2024`). |
160
- | **122** | Accounting Negative Formats: Parens, Minus & CR | GAAP / Ind AS Presentation Rules | Correctly identifies `(₹ 50,000.00)` as negative and preserves `50,000.00 CR` ledger credits. |
161
- | **123** | Zero-Argument & Empty Destructuring Robustness | Safe API Contract Standards | Invocations with `{}` or zero arguments execute safely without unhandled TypeErrors. |
162
- | **124** | UTF-8 BOM & European Delimiter Parsing | RFC 4180 CSV Ingestion | Strips UTF-8 BOM (`\uFEFF`) and automatically detects semicolon (`;`) and tab (`\t`) delimiters. |
163
- | **125** | Parenthesized Negative Vouchers & Return Netting | CBDT Circular 13/2021 Question 4 | Parenthesized `(₹ 10,00,000)` return voucher reduces rolling purchase base to ₹45L, preventing wrongful Section 194Q alerts. |
164
- | **126** | StatutoryClient Programmatic Parity for Daybooks | Package Architecture Parity | Verifies full client parity for `parseTallyDaybookCsv`, `reconcile194QDaybook`, XML, and reports. |
165
- | **127** | Strict Malformed Numeric & Integer-Paise Precision | Financial Computation Integrity | Enforces 4-state classification, `Number.MAX_SAFE_INTEGER` bounds, and fractional sub-paisa rules. |
166
- | **128** | Mandatory Parameter Enforcement across Calculators | Statutory Defensive Architecture | Asserts 12 core statutory calculators throw `MissingMandatoryParameterError` on incomplete data. |
167
- | **129** | Real-World Tally Ingestion: Dual Columns & Quotes | TallyPrime Export Specifications | Dual Debit/Credit column netting, Particulars header lookup, blank-row filtering, and RFC 4180 quotes. |
168
- | **130** | StatutoryClient Arithmetic and Precision Parity | Package Architecture Parity | Exposes `cleanNumericAmount`, `toIntegerPaise`, `fromIntegerPaise`, `roundToPaisa` on `StatutoryClient`. |
169
- | **131** | Zoho Books Bills CSV Parsing | Zoho Books Export Specifications | Parses Zoho bill CSVs, extracting Section 17(5) categories, RCM flags, and Schedule I deemed supplies. |
170
- | **132** | Zoho API JSON & GSTR-2B JSON Ingestion | GST Portal API Schema / Zoho REST API | Parses B2B invoices, CDNR credit/debit notes netting, date normalization, and item tax rollups. |
171
- | **133** | 2-Way Reconciliation MATCHED_ELIGIBLE | CGST Act Section 16(2) | Fuzzy alphanumeric key matching resolves separator variance (`INV/2024-25/001` vs `INV-2024-25-001`). |
172
- | **134** | Statutory Dispositions: Missing 2B, Books, Mismatch | CGST Act Sec 16(2)(aa) & Rule 36(4) | Categorizes `MISSING_IN_GSTR2B` (provisional restricted), `MISMATCH_AMOUNT_VALUE`, and `MISSING_IN_BOOKS`. |
173
- | **135** | Section 17(5) Blocked Credit & POS Mismatch | CGST Act Sec 17(5) & IGST Act Sec 12 | Isolates blocked motor vehicle ITC for GSTR-3B Table 4(B)(1) and disallows out-of-state local tax. |
174
- | **136** | Rule 37 180-Day Aging & Section 50(1) Delayed Interest | CGST Act Sec 16(2) 2nd Proviso & Rule 37 | Unpaid bill >180 days triggers Table 4(B)(2) reversal + 18% delayed interest exposure for overdue days. |
175
- | **137** | StatutoryClient Parity & Executive Report Generation | Client API & Audit Memorandum | Verifies programmatic methods and renders executive Markdown audit memorandum with health matrix. |
176
- | **138** | CLI Integration — reconcile-gstr2b | Command Line Interface | Executes CLI command `reconcile-gstr2b` with JSON pipeline and report output. |
177
- | **139** | Multi-State POS Triangulation & Branch Routing | CGST Act Sec 25(4) & IGST Act Sec 12(3) | Routes distinct-person vouchers to branch GSTIN; absorbs stranded hotel local CGST/SGST as expense. |
178
- | **140** | Rule 37 Exceptions, Proportional Netting & Rule 88B | Rule 37(1) Provisos & Rule 88B(3) | Validates RCM & Schedule 1 exemptions, 50% partial payment netting, and 0% interest on unutilized ECL. |
179
- | **141** | GSTR-2B GSTN Ineligible Flag & Goods-In-Transit | CGST Act Sec 16(4) & Sec 16(2)(b) | Captures portal `itcavl: "N"` flag; classifies recent unrecorded invoices (<15 days) as goods in transit. |
180
- | **142** | Zoho Books Vendor Credits Netting | Accounting Double-Entry Principles | Parses native `vendor_credits` array, performing negative taxable and tax netting against gross AP. |
181
- | **143** | Explicit Uncertainty Routing (REQUIRES_HUMAN) | Audit Governance & Epistemic Honesty | Fails closed on invalid GSTIN checksum, contradictory tax splits, and duplicate invoice candidates. |
182
- | **144** | Payment Appropriation Policies & Dipped ECL Math | Rule 37(1) & Rule 88B(3) Math | Verifies `VALUE_FIRST` vs `PROPORTIONATE` reversal math and computes 18% interest on dipped ECL balances. |
183
- | **145** | Decoupled Jurisdictional Decisions Structure | Architectural Assurance | Asserts transaction-level 4-way decisions structure (`taxClassification`, `recipientJurisdiction`, etc.). |
184
- | **146** | 50-Transaction Synthetic E2E Batch Test | Comprehensive Enterprise AP Simulation | 47 bills and 45 GSTR-2B records across 9 compliance groups evaluated in an end-to-end stress run. |
185
- | **147** | Chronological Rule 88B(3) ECL Ledger History | CGST Act Section 50(1) & Rule 88B(3) | Evaluates day-by-day movements across 5 trajectories: zero dip, temporary dip, multiple dips/recoveries, partial dip, and post-utilization reversal. |
186
- | **148** | Evidence Provenance Integrity & Audit Trail | Forensic Audit Reproducibility | Attaches cryptographic `evidenceProvenance` object with SHA-256 derived signature (`MF-PROV-...`), source references, 4-way decisions, and pinned Merkle root. |
187
- | **149** | Section 12(3) Lodging vs Section 12(7) Event Management | IGST Act Place of Supply Triangulation | Distinguishes immovable lodging (property location -> stranded expense) from B2B event organizing (recipient location -> mandatory IGST / vendor credit note demand). |
188
- | **150** | Zoho Books API Contract Hardening | Enterprise API Resilience | Validates pagination `page_context` retention, null/empty record resilience, and fail-closed handling of Zoho API error codes (e.g. Code 14). |
189
- | **151** | Property-Based Fuzz Testing (500 Transactions) | Invariant Enforcement & Stress Resilience | Generates 500 randomized transactions, asserting double-entry accounting conservation, zero floating-point drift, and immutable `isAuthorizedToDisburse: false`. |
190
-
191
- ---
192
-
193
- ## 7. The 50-Transaction Synthetic E2E Batch Specification (Test 146)
194
-
195
- Test 146 constructs an end-to-end multi-scenario corporate portfolio evaluating 47 Zoho purchase bills and 45 GST Portal GSTR-2B records across 9 orthogonal compliance groups:
196
-
197
- | Group | Invoice Range | Transaction Character | Statutory Grounding | Resulting Engine Disposition |
198
- |---|---|---|---|---|
199
- | **Group 1** | 01–20 | Clean matched bills alternating intrastate (Maharashtra `27`) and interstate (Karnataka `29`). | CGST Act Section 16(2) | `MATCHED_ELIGIBLE` (Table 4A5 credit) |
200
- | **Group 2** | 21–25 | Bangalore supplier (`29`) charging Karnataka local tax where recipient has a distinct-person branch in `29`. | CGST Act Section 25(4) | `MATCHED_ROUTABLE_TO_BRANCH_GSTIN` (`ROUTE_TO_BRANCH_GSTIN`) |
201
- | **Group 3** | 26–30 | Chennai hotel (`33`) charging Tamil Nadu local tax where recipient has no branch in `33`. | IGST Act Section 12(3) | `MATCHED_INELIGIBLE_STRANDED_LOCAL_CGST_SGST` (`BOOK_AS_EXPENSE_NO_ITC`) |
202
- | **Group 4** | 31–35 | Invoices dated 210 days ago, 50% paid balance remaining. | Rule 37(1) & Rule 88B(3) | `MATCHED_ELIGIBLE` with `rule37OverdueCount: 5`, proportional Table 4(B)(2) reversal, and ₹0.00 interest due to ₹10L ECL balance. |
203
- | **Group 5** | 36–38 | Goods Transport Agency (GTA) freight invoices unpaid past 180 days. | Rule 37(1) Proviso 1 (RCM) | `MATCHED_ELIGIBLE` with `EXEMPT_RCM_SUPPLY` (zero reversal required). |
204
- | **Group 6** | 39–41 | Invoices flagged `itcavl: false` by GSTN with reason `TIME_BARRED_SEC_16_4`. | CGST Act Section 16(4) | `GSTR2B_INELIGIBLE_FLAGGED_BY_GSTN` (`REPORT_IN_GSTR3B_TABLE_4B1_PERMANENT_REVERSAL`) |
205
- | **Group 7** | 42–44 | Fresh invoices dated 5 days prior to audit date, absent in GSTR-2B. | CGST Act Section 16(2)(aa) | `MISSING_IN_GSTR2B_TIMING` (`PROVISIONAL_PENDING_NEXT_GSTR2B`) |
206
- | **Group 8** | 45–47 | Invoices present in GSTR-2B dated 3 days ago, absent in Zoho Books. | CGST Act Section 16(2)(b) | `MISSING_IN_BOOKS` (`PHYSICAL_GOODS_RECEIPT_VERIFICATION_PENDING`) |
207
- | **Group 9** | 48–50 | Corrupted checksum (48), contradictory tax split (49), missing Place of Supply (50). | Fail-Closed Governance | `REQUIRES_HUMAN_VERIFICATION` (with discrete `uncertaintyReason` codes). |
208
-
209
- ---
210
-
211
- ## 8. Advanced Accounting Assurance & Forensic Integrity (Tests 147–151)
212
-
213
- ### A. Chronological Rule 88B(3) ECL Simulation
214
- Under Explanation (1) to Rule 88B of the CGST Rules, wrongful utilization of input tax credit occurs **only when and to the extent that** the balance in the Electronic Credit Ledger (ECL) dips below the unreversed ITC amount. MudraForge models this day-by-day:
215
- - **Trajectory 1 (Zero Dip)**: ECL balance remains above unreversed ITC -> 0% interest throughout.
216
- - **Trajectory 2 (Temporary Dip)**: ECL dips below unreversed ITC for a 10-day window -> interest is calculated strictly for those 10 days on the dipped amount.
217
- - **Trajectory 3 (Multiple Dips & Recoveries)**: Sum of day-weighted interest across each distinct dip interval.
218
- - **Trajectory 4 (Partial Utilization)**: If the ECL balance remains positive (e.g. ₹3,00,000 against ₹5,00,000 unreversed ITC), interest is quantified strictly on the ₹2,00,000 shortfall.
219
- - **Trajectory 5 (Post-Utilization Reversal)**: If the taxpayer reverses the ITC prior to assessment, interest calculation terminates on the exact reversal date.
220
-
221
- ### B. Cryptographic Evidence Provenance (`MF-PROV-...`)
222
- Every reconciliation item now bears an immutable, self-contained `evidenceProvenance` object:
223
- ```json
224
- {
225
- "provenanceId": "MF-PROV-3A7F8B12C4E9D021",
226
- "provenanceTimestamp": "2024-08-10T14:30:00.000Z",
227
- "source": { "sourceSystem": "ZOHO_BOOKS", "billNumber": "INV-2024-001" },
228
- "externalEvidence": { "sourceSystem": "GST_PORTAL_GSTR2B", "presentInGstr2b": true },
229
- "matchingMethod": "EXACT",
230
- "statutoryBasis": {
231
- "governingStatute": "Central Goods and Services Tax Act, 2017 / Integrated Goods and Services Tax Act, 2017",
232
- "primarySection": "CGST Act Section 16(2)"
233
- },
234
- "jurisdictionDecisions": {
235
- "taxClassification": "INTRASTATE_CORRECT",
236
- "recipientJurisdiction": "FILING_GSTIN_MATCHES_POS",
237
- "itcEligibility": "ELIGIBLE_NORMAL",
238
- "operationalRouting": "CLAIM_IN_CURRENT_GSTR3B_TABLE_4A5"
239
- },
240
- "uncertaintyAssessment": { "isCertain": true, "uncertaintyReason": "NONE" },
241
- "governanceTrail": {
242
- "requiresHumanReview": false,
243
- "merkleSubstrateRoot": "sha256-f7709f6a77a3b5ae16d69baf49f6e5c69bb01e29a4f13a506eb757220bf68e03",
244
- "isAuthorizedToDisburse": false
245
- }
246
- }
247
- ```
248
-
249
- ### C. Section 12(3) vs Section 12(7) Place of Supply Triangulation
250
- - **Section 12(3)(a) Immovable Lodging**: Accommodation in hotels, guest houses, or campsites strictly fixes the Place of Supply at the property location. If the recipient has no GST registration in that state, the CGST/SGST is legally stranded and absorbed as an operating expense (`BOOK_AS_EXPENSE_NO_ITC`).
251
- - **Section 12(7)(a)(i) B2B Event Management**: Organization of conferences, exhibitions, or corporate events provided to a registered person fixes the Place of Supply at the **location of the recipient**. If a local vendor charges venue state CGST/SGST, it is an `ERRONEOUS_INTRASTATE_LEVY`. The engine flags this as a defective invoice and instructs the AP team to demand a vendor credit note and corrected IGST invoice (`REQUEST_VENDOR_CREDIT_NOTE_AMENDMENT`).
252
-
253
- ### D. Zoho Books API Contracts & Property-Based Fuzz Testing
254
- - **API Pagination**: Preserves `page_context` (`page`, `per_page`, `has_more_page`, `total`) for multi-page batch ingestion.
255
- - **Fail-Closed API Errors**: Throws explicit, actionable errors upon encountering Zoho API error codes (e.g. Code 14 invalid parameter).
256
- - **500-Transaction Fuzz Invariants**: Validates that double-entry balance, disposition categorization, and disbursement lock (`isAuthorizedToDisburse: false`) hold across 500 randomized transactions.
257
-
258
- ---
259
-
260
- ## 9. Preserving Audit Defensibility in Production
261
-
262
- To prove compliance to external auditors, execute the automated verification pipeline:
263
-
264
- ```bash
265
- # 1. Full statutory test suite (asserts all 151 tests pass)
266
- npm test
267
-
268
- # 2. Excel Add-in verification suite (asserts 25 custom functions pass)
269
- npm -C packages/excel-addin test
270
-
271
- # 3. OKF v0.2 Schema, Circular, and Form validator
272
- npm run validate
273
-
274
- # 4. Cryptographic Merkle Root integrity check (asserts 117/117 files match pinned hash)
275
- npm run manifest:check
276
- ```
@@ -1,166 +0,0 @@
1
- # MudraForge Adesha — Enterprise Runtime Assurance Overview
2
-
3
- > **Target**: Commercial Adesha Sovereign Autonomous Finance Runtime
4
- > **Classification**: Enterprise Commercial Architecture & Verification Specification
5
- > **Status**: Proprietary Enterprise Engine (Not distributed in the `@mudraforge/statutory` open-source package)
6
-
7
- ---
8
-
9
- ## 1. Overview & Architectural Role
10
-
11
- While the open-source `@mudraforge/statutory` package provides declarative knowledge schemas, thresholds, and administrative circulars, the **Adesha Sovereign Runtime** is the commercial execution engine. It governs autonomous accounts payable, payment authorization leases, two-way ERP reconciliation, and bank rail execution.
12
-
13
- > **The Payment Instruction Boundary**:
14
- > *The dangerous moment in finance AI isn't when the model is wrong. It's when its output becomes a payment instruction. In marketing, an AI hallucination is a typo. In accounts payable, an unhandled bank timeout can trigger a retry that double-pays a vendor. Reasoning can be probabilistic, but financial execution needs deterministic boundaries.*
15
-
16
- To guarantee that autonomous financial agents cannot execute unauthorized disbursements or corrupt general ledgers, the Adesha runtime is engineered around four core execution pillars, formal verification, adversarial mutation testing, and fail-closed state machine invariants.
17
-
18
- ---
19
-
20
- ## 2. The Four Pillars of Autonomous Finance Execution
21
-
22
- 1. **Retrieval is Not Verification**:
23
- Early on, our claim validator relied on pre-populated test files holding expected answers. We scrapped that crutch. Our tests now exercise retrieval from connected systems of record (including live Zoho Books / SAP ERP readback) and authenticated tenant statutory vaults. Finding a document or matching keywords isn't enough; the system must verify what evidence legally supports before any downstream calculation runs.
24
-
25
- 2. **Safe Tools Do Not Guarantee Safe Workflows**:
26
- An AI agent can call individually safe API tools and still coordinate an unauthorized or illegal transaction. We separated reasoning from execution: the generative AI coordinates investigations and extracts messy invoice narratives; deterministic code calculates statutory taxes and enforces ledger invariants. Human oversight shouldn't mean accountants re-auditing math; the runtime provides statutory provenance so humans can focus on the actual decision.
27
- *Rule 11: Agreement with the Engine ≠ Agreement with the Law.*
28
-
29
- 3. **Preventing Silent Financial Drift**:
30
- Deterministic code computes numbers. RFC 8785 JSON Canonicalization Scheme (JCS) and SHA-256 bind the result to a verifiable, immutable fingerprint. The hash doesn't calculate—it detects any drift between calculation, human approval, and bank execution. If the financial result no longer matches the verified record, the workflow halts immediately.
31
-
32
- 4. **Testing Payment Boundaries Against Failure**:
33
- - **Duplicate-Payment Prevention**: Single-use Compare-and-Swap (CAS) leases tested under concurrent races using MongoDB-compatible atomic operations (`findAndModify`): exactly one consumer succeeds; all concurrent races are rejected with `LEASE_ALREADY_CONSUMED`.
34
- - **Formal TLA+ Modeling**: TLC explored all 361 reachable states in our configured distributed model (covering two leases, retries, and network timeouts) with zero invariant violations, and caught four deliberate defects injected into the spec.
35
- - **Edge Execution**: Built on Cloudflare Workers V8 isolates without container-based execution or cold starts.
36
- - **Accounting Integrity**: Adversarial tests target unbalanced journals, duplicate credits, and amount mismatches, enforcing strict double-entry ledger balance before ERP writeback.
37
-
38
- ---
39
-
40
- ## 3. Statutory Ground Truth Oracle & Adversarial Mutation Matrix
41
-
42
- To prevent the **Epistemic Gap** (where engineers embed incorrect tax interpretations into both the code and the tests), Adesha validates statutory computations against an independent test oracle across an adversarial mutation matrix.
43
-
44
- ### Deliberate Misinterpretation Mutants & Runtime Defenses
45
-
46
- | Mutant ID | Injected Corruption | Statutory Legal Ground Truth | Adesha Defense & Interception |
47
- | :--- | :--- | :--- | :--- |
48
- | **MUTANT-01** | Section 194Q rate increased from 0.1% to 1.0% | Section 194Q: 0.1% strictly on excess over ₹50L | [PASS] Intercepted by statutory calculator gate |
49
- | **MUTANT-02** | Section 194Q threshold lowered from ₹50L to ₹10L | Section 194Q: Mandates ₹50 Lakhs cumulative threshold | [PASS] Intercepted by threshold invariant |
50
- | **MUTANT-03** | Section 206C(1H) evaluated on or after 1 April 2025 | Finance Act 2025: Sunsets Section 206C(1H) w.e.f. 01-04-2025 | [PASS] Intercepted by temporal state machine |
51
- | **MUTANT-04** | Section 194Q computed on gross invoice including GST | CBDT Circular 13/2021: Mandates unbundling GST component | [PASS] Intercepted by tax base unbundling parser |
52
- | **MUTANT-05** | Missing PAN on 194Q penalized at 20% instead of 5% | Section 206AA(1) Proviso: Capped strictly at 5% for Sec 194Q | [PASS] Intercepted by statutory rate cap |
53
- | **MUTANT-06** | MSMED penal rate computed from RBI Repo Rate (6.5%) | MSMED Sec 16: Specifies 3x RBI Bank Rate (Sec 49 RBI Act) | [PASS] Intercepted by statutory rate binding |
54
- | **MUTANT-07** | MSMED penal interest computed as simple annual interest| MSMED Sec 16: Mandates compound interest with monthly rests | [PASS] Intercepted by multi-interval compound math |
55
- | **MUTANT-08** | Section 43B(h) disallowance applied to Medium units | Section 43B(h): Applies strictly to Micro and Small enterprises | [PASS] Intercepted by enterprise class gate |
56
- | **MUTANT-09** | Section 194Q applied to foreign vendor without PE | CBDT Circular 13/2021 Q3: Exempts direct foreign imports | [PASS] Intercepted by residency exemption check |
57
- | **MUTANT-10** | Tie-breaker inverted when buyer turnover is under ₹10 Cr| Sec 206C(1H) 2nd Proviso: Only yields if buyer is legally liable | [PASS] Intercepted by dual-statute tiebreaker |
58
- | **MUTANT-11** | Section 194Q deducted on entire invoice crossing ₹50L | Only the incremental excess over ₹50L is the taxable base | [PASS] Intercepted by excess calculation invariant |
59
- | **MUTANT-12** | Advance netting deducted without adjusting prior advance TDS| CBDT Circular 13/2021 Q1: Prevents double withholding | [PASS] Intercepted by advance ledger reconciliation |
60
-
61
- ---
62
-
63
- ## 4. Formal TLA+ State Machine Verification
64
-
65
- The payment authorization lease lifecycle in MudraForge Adesha is formally modeled in TLA+ (`specs/adesha_lease_state_machine.tla`) and verified using the **TLC Model Checker** (`tlc2.TLC`).
66
-
67
- ### 1. Full Concurrent Distributed Model (361 Reachable States)
68
- In the complete distributed execution configuration covering concurrent transactions, retry attempts, and network drops:
69
- - **Reachable States Explored**: **361 unique reachable states** fully traversed by TLC.
70
- - **Safety Invariant Violations**: **0 violations**. Every reachable state maintains mutual exclusion, single-consumption CAS gates, and fail-closed ambiguity preservation.
71
- - **Concurrency Coverage**: Evaluates concurrent races between multiple leases competing for settlement rails under network fault conditions.
72
-
73
- ### 2. Four Deliberate TLA+ Mutation Challenges (Caught by TLC)
74
- To prove that the formal TLA+ specification is sensitive to real-world edge defects (and not a tautology), four unsafe transitions were deliberately injected into the model (`tools/run_tla_mutant_challenges.js`). TLC caught and generated counterexample traces for every single mutant:
75
-
76
- | Mutant ID | Injected Defect | Formal Invariant Guarding It | TLC Verification Outcome |
77
- | :--- | :--- | :--- | :--- |
78
- | **TLA-MUTANT-1** | Missing CAS guard (permitting lease re-use post-settlement) | `InvariantNoDoubleDisbursement` | [CAUGHT] TLC found counterexample trace at Depth 4 |
79
- | **TLA-MUTANT-2** | Optimistic timeout retry under HTTP 504 uncertainty | `InvariantAmbiguityPreservedFailClosed` | [CAUGHT] TLC found counterexample trace at Depth 3 |
80
- | **TLA-MUTANT-3** | Premature ledger writeback prior to bank settlement | `InvariantNoLedgerWritebackWithoutSettlement` | [CAUGHT] TLC found counterexample trace at Depth 2 |
81
- | **TLA-MUTANT-4** | Unleased direct dispatch bypassing authority harness | `InvariantNoUnleasedDisbursement` | [CAUGHT] TLC found counterexample trace at Depth 1 |
82
-
83
- ### 3. Single-Lease Micro-State Space (25 States & 225 Evaluations)
84
- For an isolated lease in the differential test harness (`tests/test_oracle_tla_differential_equivalence.js`):
85
- - **Reachable States**: 25 unique reachable states.
86
- - **Formal Actions**: 8 formal transition actions.
87
- - **Differential Evaluations**: 225 state-action checks (28 enabled transitions, 197 blocked precondition rejections).
88
- - **Agreement**: 100% differential equivalence between the TLA+ formal specification and the private runtime implementation.
89
-
90
- #### Mathematical Derivation of the 225 Checks
91
- 1. **Seven Deterministic Actions (Single-Branch, 1 Evaluation per State)**:
92
- `IssueLease`, `ConsumeLeaseCAS`, `WireSettlementSuccess`, `StatementIngestionConfirmsSettlement`, `GatewayCertifiesReversal`, `RetryWireWithLinkedKey`, `PostGeneralLedgerVoucher`.
93
- $$\text{Subtotal} = 25 \text{ states} \times 7 \text{ actions} \times 1 \text{ branch} = 175 \text{ evaluations}$$
94
-
95
- 2. **One Non-Deterministic Action (Two-Branch, 2 Evaluations per State)**:
96
- `WireNetworkTimeout504`: Under an HTTP 504 network timeout, the banking partner may or may not have disbursed funds before the connection dropped:
97
- - Branch 1 (`executed`): Bank disbursed funds.
98
- - Branch 2 (`non_executed`): Bank did not disburse funds.
99
- $$\text{Subtotal} = 25 \text{ states} \times 1 \text{ action} \times 2 \text{ branches} = 50 \text{ evaluations}$$
100
-
101
- 3. **Total**: $175 + 50 = 225 \text{ differential evaluations}$.
102
-
103
- ---
104
-
105
- ## 5. The Two-Generals Problem & In-Flight Banking Resolution
106
-
107
- In distributed banking, network communication over public payment rails is fundamentally subject to the **Two-Generals Problem**:
108
-
109
- ```
110
- Client ──[ POST /v1/payouts ]──► Gateway ──► Bank Rail
111
- ▲ │
112
- │ ▼
113
- └───[ HTTP 504 Timeout / Socket Drop ]─────────┘
114
- ```
115
-
116
- When an enterprise runtime encounters an HTTP 504 gateway timeout, socket reset, or worker crash after transmitting a payment, the client cannot know whether the bank executed the wire.
117
-
118
- ### Enforced Invariants
119
- 1. **Preserving Uncertainty Fail-Closed**:
120
- The lease transitions to `AMBIGUOUS_RECONCILING` with `safeToRetry: false`. In this state, the runtime strictly blocks automatic retries or new lease issuance.
121
- 2. **Elapsed Time Never Unlocks a Retry**:
122
- Waiting for an arbitrary cooling-off period (e.g., 30 minutes) does not guarantee non-execution, because anti-fraud holds and clearinghouse queues can delay settlement.
123
- 3. **Dual-Mode Resolution Contract**:
124
- - `IDEMPOTENT_RETRY`: Re-transmits using the **exact original `transportIdempotencyKey`** and identical request body. Both RazorpayX and Modern Treasury return existing transaction outcomes without creating duplicate debits.
125
- - `COMPENSATED_REATTEMPT`: Only after receiving an authoritative reversal or failure certification does the runtime generate a fresh linked transport token (`attemptIndex: 2`) under the same business lease.
126
-
127
- ---
128
-
129
- ## 6. Double-Entry General Ledger Balance Invariants
130
-
131
- In corporate accounting, recording a voucher before external settlement creates accounting distortions. Adesha enforces:
132
-
133
- 1. **Precondition Gate**: General ledger writeback is strictly locked until a verified bank Unique Transaction Reference (UTR) is present.
134
- 2. **Source-Bound Line Invariant (`verifySourceBoundLineInvariants`)**:
135
- Every journal line must bind directly to an authoritative source document:
136
- - COGS / Expense binds to the invoice basic value.
137
- - GST Input Tax Credit binds to the digitally signed government e-invoice (IRP) digest.
138
- - TDS Payable binds to the deterministic statutory calculator output.
139
- - Advance Netting binds to the unapplied advance ledger balance.
140
- - Bank Credit binds to the authorized wire disbursement amount.
141
- 3. **Paisa-Level Equilibrium**:
142
- $$\sum \text{Debits} \equiv \sum \text{Credits} \quad (\text{Discrepancy } \le ₹0.01)$$
143
-
144
- ---
145
-
146
- ## 7. Current Development Status & Scoped Pilot Boundary
147
-
148
- > **Honest Operational Status**:
149
- > All 60 enterprise test suites are passing across formal TLA+ state machines, mutation matrices, and differential calculators, and our core engine baseline is frozen at `v2.2.0`.
150
- >
151
- > Importantly, **Adesha itself remains under active development**; passing tests does not make the product production-ready. Our planned initial pilot is deliberately and narrowly scoped:
152
- > - **Domain Focus**: Domestic Accounts Payable (AP) in supervised shadow mode.
153
- > - **System of Record**: Live ERP readback from connected systems (Zoho Books / SAP S/4HANA).
154
- > - **Safety Constraints**: No live bank credentials connected, and **zero live funds at risk**.
155
- >
156
- > Autonomous finance will not be unlocked by bigger AI models alone. It requires traceable evidence, deterministic calculations, and execution boundaries that hold when a model gets something wrong.
157
-
158
- ---
159
-
160
- ## 8. Access & Commercial Deployment
161
-
162
- For enterprises, financial institutions, and audit firms seeking deployment details, pilot onboarding, or custom ERP connector specifications:
163
-
164
- - **Commercial Inquiries**: [hello@mudraforge.in](mailto:hello@mudraforge.in)
165
- - **Technical Architecture Desk**: [engineering@mudraforge.in](mailto:engineering@mudraforge.in)
166
- - **Enterprise Governance Whitepaper**: See [`ENTERPRISE_GOVERNANCE.md`](./ENTERPRISE_GOVERNANCE.md).