codex/aram-multidimensional-mapping-20261101
add-index-html-10623938925177053894
arena/094f314c-aram
chatgpt-phase1b2-autopilot
codex/adr-future-connectors-pi-v1
codex/aram-account-note-source-trace-20261031
codex/aram-actions-node24-maintenance-20261031
codex/aram-analyst-review-workbook-20261031
codex/aram-bs-candidate-statement-20261031
codex/aram-cash-flow-direct-candidate-20261031
codex/aram-clean-reference-year-integrity-20261030
codex/aram-cross-statement-controls-20261031
codex/aram-equity-changes-candidate-20261031
codex/aram-five-statement-cli-20261031
codex/aram-five-statement-integration-20261031
codex/aram-five-statement-orchestrator-20261031
codex/aram-gate3-coverage-target-guard-20261030
codex/aram-gate3-hidden-xlsx-guard-20261030
codex/aram-gate3-integration-validation-20261030
codex/aram-gate3-mapping-change-preview-20261030
codex/aram-gate3-stale-note-guard-20261030
codex/aram-income-statement-candidate-20261031
codex/aram-manifest-referential-integrity-20261031
codex/aram-mapping-source-parser-20261101
codex/aram-multidimensional-mapping-20261101
codex/aram-multistatement-mapping-20261031
codex/aram-pipeline-manifest-schema-20261031
codex/aram-readonly-mapping-coverage-20261031
codex/aram-reconciliation-review-gate-20261031
codex/aram-same-flush-fiscal-lock-20261030
codex/aram-synthetic-windows-demo-20261031
codex/aram-trial-balance-diagnostic-20261031
codex/aram-windows-background-detail-search-20261031
codex/aram-windows-detail-review-20261031
codex/aram-windows-five-statement-pilot-20261031
codex/aram-windows-statement-figures-20261031
codex/gate-2a-pilot-workbook
codex/gate-2a-pilot-workbook-6864754244772568979
codex/gate3-authenticated-principal-boundary-20261030
codex/gate3-authored-draft-staging-20261030
codex/gate3-carry-forward-preview-20261023
codex/gate3-draft-staging-audit-20261030
codex/gate3-mapping-batch-freshness-20261030
codex/gate3-mapping-batch-review-20261030
codex/gate3-mapping-core
codex/gate3-mapping-coverage-20261023
codex/gate3-mapping-excel-20261023
codex/gate3-note-mapping-review-20261023
codex/gate3-signed-year-scope-20261030
codex/gate3-unapproved-proposal-storage-20261030
codex/payvast-mapping-discovery-20261023
codex/phase-2a-backend-foundation
codex/phase-2b-post-merge-record
codex/phase-2b-source-registration
codex/phase-2b-source-registration-12955190277775369594
codex/post-gate2a-control-reconciliation
codex/post-pr18-acceptance-record
codex/project-control-foundation
codex/t1-repo-hygiene-20261023
codex/t2-ci-hardening-20261023
codex/t3-explicit-migrations-20261023
codex/t6a-readonly-diagnostics-20261023
codex/v1-01-safety-gate-hardening
codex/v1-year-isolation-followup-20261023
codex/windows-native-pilot-shell-20261030
docs/aram-master-control-plan-20261111
docs/aram-roadmap-dashboard-20261030
docs/financial-statement-reconciliation-1402-1404-20261110
feat/gate3-governed-mapping-20261101
feat/gate3-package9-1-security-20261103
feat/gate3-package9-isolated-20261103
fix/password-unicode-validation-20261111
governance/aram-5-1-3-controls-20261030
governance/role-based-operating-model
jules-1168663913887856558-73b8a885
jules-gate-2b-mapping-workflow-foundation-4137724387867065330
phase-1b1-audit-report-7365389436990903239
phase-2a-backend-foundation-10237597358138521261
phase1b2-postmerge-metadata-fix
refactor/drg-parent-year-id-15088443704684163304
source-data-cleanup
| 1 | """Single-snapshot orchestration for ARAM's five unsigned statement engines. |
| 2 | |
| 3 | The pipeline is read-only. It invokes each existing candidate builder with the |
| 4 | same immutable workbook bytes and the same frozen note-reference collection, |
| 5 | then runs the cross-statement arithmetic gate. It never authorizes, posts, |
| 6 | exports or releases financial statements. |
| 7 | """ |
| 8 | from __future__ import annotations |
| 9 | |
| 10 | from dataclasses import dataclass |
| 11 | from typing import Any, Sequence |
| 12 | |
| 13 | from aram_backend.balance_sheet_candidate import ( |
| 14 | BalanceSheetCandidate, BalanceSheetLinePolicy, build_balance_sheet_candidate, |
| 15 | ) |
| 16 | from aram_backend.cash_flow_direct_candidate import ( |
| 17 | CashAccountPolicy, CashCounterpartPolicy, CashFlowEntry, |
| 18 | DirectCashFlowCandidate, build_direct_cash_flow_candidate, |
| 19 | ) |
| 20 | from aram_backend.coverage_preview import ( |
| 21 | CoverageError, CoveragePreview, preview_mapping_coverage, |
| 22 | ) |
| 23 | from aram_backend.cross_statement_reconciliation import ( |
| 24 | CashBalanceNoteSelection, CrossStatementReconciliation, |
| 25 | reconcile_cross_statements, |
| 26 | ) |
| 27 | from aram_backend.equity_changes_candidate import ( |
| 28 | EquityChangesCandidate, EquityMovementPolicy, build_equity_changes_candidate, |
| 29 | ) |
| 30 | from aram_backend.income_statement_candidate import ( |
| 31 | IncomeStatementCandidate, IncomeStatementLinePolicy, |
| 32 | build_income_statement_candidate, |
| 33 | ) |
| 34 | from aram_backend.reconciliation_review import NoteReference |
| 35 | from aram_backend.trial_balance_diagnostic import ( |
| 36 | TrialBalanceDiagnostic, analyze_trial_balance, |
| 37 | ) |
| 38 | |
| 39 | |
| 40 | def _freeze_sequence(value: object, label: str) -> tuple[Any, ...]: |
| 41 | if not isinstance(value, (tuple, list)): |
| 42 | raise CoverageError("INVALID_FIVE_STATEMENT_" + label) |
| 43 | return tuple(value) |
| 44 | |
| 45 | |
| 46 | @dataclass(frozen=True) |
| 47 | class FiveStatementPipelineResult: |
| 48 | balance_sheet: BalanceSheetCandidate |
| 49 | income_statement: IncomeStatementCandidate |
| 50 | equity_changes: EquityChangesCandidate |
| 51 | cash_flow: DirectCashFlowCandidate |
| 52 | trial_balance: TrialBalanceDiagnostic |
| 53 | reconciliation: CrossStatementReconciliation |
| 54 | mapping_coverage: CoveragePreview |
| 55 | kind: str = "UNAPPROVED_FIVE_STATEMENT_PIPELINE_CANDIDATE" |
| 56 | source_ledger_completeness_verified: bool = False |
| 57 | accounting_policy_authorized: bool = False |
| 58 | independently_reviewed: bool = False |
| 59 | trusted_approvals: bool = False |
| 60 | official_financial_statement: bool = False |
| 61 | export_authorized: bool = False |
| 62 | releasable: bool = False |
| 63 | |
| 64 | @property |
| 65 | def company_code(self) -> str: |
| 66 | return self.reconciliation.company_code |
| 67 | |
| 68 | @property |
| 69 | def fiscal_year(self) -> int: |
| 70 | return self.reconciliation.fiscal_year |
| 71 | |
| 72 | @property |
| 73 | def source_sha256(self) -> str: |
| 74 | return self.reconciliation.source_sha256 |
| 75 | |
| 76 | @property |
| 77 | def eligible_for_analyst_review(self) -> bool: |
| 78 | return self.reconciliation.eligible_for_analyst_review |
| 79 | |
| 80 | @property |
| 81 | def findings(self) -> tuple[str, ...]: |
| 82 | return self.reconciliation.findings |
| 83 | |
| 84 | def to_dict(self) -> dict[str, Any]: |
| 85 | return { |
| 86 | "kind": self.kind, |
| 87 | "company_code": self.company_code, |
| 88 | "fiscal_year": self.fiscal_year, |
| 89 | "source_sha256": self.source_sha256, |
| 90 | "eligible_for_analyst_review": self.eligible_for_analyst_review, |
| 91 | "findings": list(self.findings), |
| 92 | "balance_sheet": self.balance_sheet.to_dict(), |
| 93 | "income_statement": self.income_statement.to_dict(), |
| 94 | "equity_changes": self.equity_changes.to_dict(), |
| 95 | "cash_flow": self.cash_flow.to_dict(), |
| 96 | "trial_balance": self.trial_balance.to_dict(), |
| 97 | "reconciliation": self.reconciliation.to_dict(), |
| 98 | "mapping_coverage": self.mapping_coverage.to_dict(), |
| 99 | "source_ledger_completeness_verified": False, |
| 100 | "accounting_policy_authorized": False, |
| 101 | "independently_reviewed": False, |
| 102 | "trusted_approvals": False, |
| 103 | "official_financial_statement": False, |
| 104 | "export_authorized": False, |
| 105 | "releasable": False, |
| 106 | } |
| 107 | |
| 108 | |
| 109 | def build_five_statement_pipeline( |
| 110 | workbook_bytes: bytes, *, |
| 111 | company_code: str, |
| 112 | fiscal_year: int, |
| 113 | references: Sequence[NoteReference], |
| 114 | balance_sheet_policies: Sequence[BalanceSheetLinePolicy], |
| 115 | income_statement_policies: Sequence[IncomeStatementLinePolicy], |
| 116 | equity_movement_policies: Sequence[EquityMovementPolicy], |
| 117 | currency: str, |
| 118 | unit: str, |
| 119 | cash_accounts: Sequence[CashAccountPolicy], |
| 120 | counterpart_policies: Sequence[CashCounterpartPolicy], |
| 121 | transactions: Sequence[CashFlowEntry], |
| 122 | cash_balance_notes: Sequence[CashBalanceNoteSelection], |
| 123 | ) -> FiveStatementPipelineResult: |
| 124 | """Run all five candidate builders on one source snapshot and reconcile. |
| 125 | |
| 126 | Input sequences are frozen once at the orchestration boundary. In |
| 127 | particular, the exact same immutable reference tuple is supplied to BS, |
| 128 | IS and EQ, preventing accidental reference-snapshot drift between engines. |
| 129 | A blocked upstream candidate is returned as a blocked pipeline result; |
| 130 | invalid source/policy preconditions raise CoverageError. |
| 131 | """ |
| 132 | if type(workbook_bytes) is not bytes or not workbook_bytes: |
| 133 | raise CoverageError("INVALID_FIVE_STATEMENT_WORKBOOK_BYTES") |
| 134 | if (not isinstance(company_code, str) or not company_code.strip() |
| 135 | or company_code != company_code.strip()): |
| 136 | raise CoverageError("INVALID_FIVE_STATEMENT_COMPANY_SCOPE") |
| 137 | if type(fiscal_year) is not int or fiscal_year <= 0: |
| 138 | raise CoverageError("INVALID_FIVE_STATEMENT_FISCAL_YEAR") |
| 139 | |
| 140 | shared_references = _freeze_sequence(references, "NOTE_REFERENCES") |
| 141 | bs_policies = _freeze_sequence(balance_sheet_policies, "BS_POLICIES") |
| 142 | is_policies = _freeze_sequence(income_statement_policies, "IS_POLICIES") |
| 143 | eq_policies = _freeze_sequence(equity_movement_policies, "EQ_POLICIES") |
| 144 | selected_cash_accounts = _freeze_sequence(cash_accounts, "CASH_ACCOUNTS") |
| 145 | selected_counterpart_policies = _freeze_sequence( |
| 146 | counterpart_policies, "COUNTERPART_POLICIES", |
| 147 | ) |
| 148 | transaction_rows = _freeze_sequence(transactions, "CASH_TRANSACTIONS") |
| 149 | cash_note_selections = _freeze_sequence( |
| 150 | cash_balance_notes, "CASH_NOTE_SELECTIONS", |
| 151 | ) |
| 152 | |
| 153 | balance_sheet = build_balance_sheet_candidate( |
| 154 | workbook_bytes, company_code=company_code, fiscal_year=fiscal_year, |
| 155 | references=shared_references, policies=bs_policies, |
| 156 | ) |
| 157 | income_statement = build_income_statement_candidate( |
| 158 | workbook_bytes, company_code=company_code, fiscal_year=fiscal_year, |
| 159 | references=shared_references, policies=is_policies, |
| 160 | ) |
| 161 | equity_changes = build_equity_changes_candidate( |
| 162 | workbook_bytes, company_code=company_code, fiscal_year=fiscal_year, |
| 163 | references=shared_references, policies=eq_policies, |
| 164 | ) |
| 165 | cash_flow = build_direct_cash_flow_candidate( |
| 166 | workbook_bytes, company_code=company_code, fiscal_year=fiscal_year, |
| 167 | currency=currency, unit=unit, |
| 168 | cash_accounts=selected_cash_accounts, |
| 169 | counterpart_policies=selected_counterpart_policies, |
| 170 | transactions=transaction_rows, |
| 171 | ) |
| 172 | trial_balance = analyze_trial_balance( |
| 173 | workbook_bytes, company_code=company_code, fiscal_year=fiscal_year, |
| 174 | ) |
| 175 | mapping_coverage = preview_mapping_coverage( |
| 176 | workbook_bytes, company_code=company_code, fiscal_year=fiscal_year, |
| 177 | ) |
| 178 | reconciliation = reconcile_cross_statements( |
| 179 | balance_sheet=balance_sheet, |
| 180 | income_statement=income_statement, |
| 181 | equity_changes=equity_changes, |
| 182 | cash_flow=cash_flow, |
| 183 | trial_balance=trial_balance, |
| 184 | cash_balance_notes=cash_note_selections, |
| 185 | ) |
| 186 | return FiveStatementPipelineResult( |
| 187 | balance_sheet=balance_sheet, |
| 188 | income_statement=income_statement, |
| 189 | equity_changes=equity_changes, |
| 190 | cash_flow=cash_flow, |
| 191 | trial_balance=trial_balance, |
| 192 | reconciliation=reconciliation, |
| 193 | mapping_coverage=mapping_coverage, |
| 194 | ) |