credit-memo-agent 0.2.0__tar.gz

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 (172) hide show
  1. credit_memo_agent-0.2.0/.gitignore +29 -0
  2. credit_memo_agent-0.2.0/LICENSE +21 -0
  3. credit_memo_agent-0.2.0/PKG-INFO +406 -0
  4. credit_memo_agent-0.2.0/README.md +367 -0
  5. credit_memo_agent-0.2.0/docs/decisions/001-the-model-never-does-the-arithmetic.md +43 -0
  6. credit_memo_agent-0.2.0/docs/images/case.png +0 -0
  7. credit_memo_agent-0.2.0/docs/images/cases.png +0 -0
  8. credit_memo_agent-0.2.0/docs/images/review.png +0 -0
  9. credit_memo_agent-0.2.0/docs/statement-review/antigravity-rereview-triage.md +71 -0
  10. credit_memo_agent-0.2.0/docs/statement-review/codex-rereview-triage.md +32 -0
  11. credit_memo_agent-0.2.0/docs/statement-review/owner-decisions.md +24 -0
  12. credit_memo_agent-0.2.0/docs/v2-newly-recognised.md +31 -0
  13. credit_memo_agent-0.2.0/evals/run_evals.py +175 -0
  14. credit_memo_agent-0.2.0/examples/cafe_stretched.csv +390 -0
  15. credit_memo_agent-0.2.0/examples/cafe_stretched.memo.evidence.json +9857 -0
  16. credit_memo_agent-0.2.0/examples/cafe_stretched.memo.md +68 -0
  17. credit_memo_agent-0.2.0/examples/cafe_stretched.truth.json +438 -0
  18. credit_memo_agent-0.2.0/packaging/CreditMemo.py +5 -0
  19. credit_memo_agent-0.2.0/pyproject.toml +72 -0
  20. credit_memo_agent-0.2.0/src/cma/__init__.py +3 -0
  21. credit_memo_agent-0.2.0/src/cma/app/__init__.py +3 -0
  22. credit_memo_agent-0.2.0/src/cma/app/actions.py +215 -0
  23. credit_memo_agent-0.2.0/src/cma/app/cases.py +141 -0
  24. credit_memo_agent-0.2.0/src/cma/app/launcher.py +135 -0
  25. credit_memo_agent-0.2.0/src/cma/app/pages.py +556 -0
  26. credit_memo_agent-0.2.0/src/cma/app/server.py +380 -0
  27. credit_memo_agent-0.2.0/src/cma/app/static/app.css +155 -0
  28. credit_memo_agent-0.2.0/src/cma/bank_profiles/__init__.py +3 -0
  29. credit_memo_agent-0.2.0/src/cma/bank_profiles/profiles.yaml +65 -0
  30. credit_memo_agent-0.2.0/src/cma/case.py +1531 -0
  31. credit_memo_agent-0.2.0/src/cma/categorise.py +1614 -0
  32. credit_memo_agent-0.2.0/src/cma/cli.py +1157 -0
  33. credit_memo_agent-0.2.0/src/cma/firm.py +303 -0
  34. credit_memo_agent-0.2.0/src/cma/firm_rules.py +208 -0
  35. credit_memo_agent-0.2.0/src/cma/graph.py +980 -0
  36. credit_memo_agent-0.2.0/src/cma/guard.py +223 -0
  37. credit_memo_agent-0.2.0/src/cma/importers/__init__.py +1 -0
  38. credit_memo_agent-0.2.0/src/cma/importers/bankcsv.py +415 -0
  39. credit_memo_agent-0.2.0/src/cma/importers/contract.py +136 -0
  40. credit_memo_agent-0.2.0/src/cma/importers/monzo.py +331 -0
  41. credit_memo_agent-0.2.0/src/cma/importers/openbanking.py +734 -0
  42. credit_memo_agent-0.2.0/src/cma/importers/truelayer.py +237 -0
  43. credit_memo_agent-0.2.0/src/cma/indicators.py +513 -0
  44. credit_memo_agent-0.2.0/src/cma/ingest.py +627 -0
  45. credit_memo_agent-0.2.0/src/cma/llm.py +228 -0
  46. credit_memo_agent-0.2.0/src/cma/mcp_server.py +268 -0
  47. credit_memo_agent-0.2.0/src/cma/memo_fields/__init__.py +1 -0
  48. credit_memo_agent-0.2.0/src/cma/memo_fields/memo_fields.yaml +101 -0
  49. credit_memo_agent-0.2.0/src/cma/metrics.py +1298 -0
  50. credit_memo_agent-0.2.0/src/cma/models.py +337 -0
  51. credit_memo_agent-0.2.0/src/cma/overrides.py +683 -0
  52. credit_memo_agent-0.2.0/src/cma/pack.py +922 -0
  53. credit_memo_agent-0.2.0/src/cma/policies/__init__.py +0 -0
  54. credit_memo_agent-0.2.0/src/cma/policies/uk_sme_default.yaml +91 -0
  55. credit_memo_agent-0.2.0/src/cma/policy.py +258 -0
  56. credit_memo_agent-0.2.0/src/cma/promotion.py +363 -0
  57. credit_memo_agent-0.2.0/src/cma/pseudonymise.py +565 -0
  58. credit_memo_agent-0.2.0/src/cma/record.py +134 -0
  59. credit_memo_agent-0.2.0/src/cma/report.py +177 -0
  60. credit_memo_agent-0.2.0/src/cma/review/__init__.py +1 -0
  61. credit_memo_agent-0.2.0/src/cma/review/compare.py +240 -0
  62. credit_memo_agent-0.2.0/src/cma/review/drilldown.py +208 -0
  63. credit_memo_agent-0.2.0/src/cma/review/edit.py +213 -0
  64. credit_memo_agent-0.2.0/src/cma/review/memo_view.py +53 -0
  65. credit_memo_agent-0.2.0/src/cma/review/promote.py +180 -0
  66. credit_memo_agent-0.2.0/src/cma/review/server.py +438 -0
  67. credit_memo_agent-0.2.0/src/cma/review/signoff.py +151 -0
  68. credit_memo_agent-0.2.0/src/cma/review/static/app.css +154 -0
  69. credit_memo_agent-0.2.0/src/cma/review/static/app.js +71 -0
  70. credit_memo_agent-0.2.0/src/cma/review/static/index.html +22 -0
  71. credit_memo_agent-0.2.0/src/cma/review/static/theme.css +173 -0
  72. credit_memo_agent-0.2.0/src/cma/review/summary.py +664 -0
  73. credit_memo_agent-0.2.0/src/cma/rules/__init__.py +0 -0
  74. credit_memo_agent-0.2.0/src/cma/rules/v1.yaml +60 -0
  75. credit_memo_agent-0.2.0/src/cma/rules/v2.yaml +407 -0
  76. credit_memo_agent-0.2.0/src/cma/store.py +997 -0
  77. credit_memo_agent-0.2.0/src/cma/synth.py +714 -0
  78. credit_memo_agent-0.2.0/src/cma/thresholds/__init__.py +1 -0
  79. credit_memo_agent-0.2.0/src/cma/thresholds/indicators.yaml +68 -0
  80. credit_memo_agent-0.2.0/src/cma/verify.py +464 -0
  81. credit_memo_agent-0.2.0/tests/conftest.py +54 -0
  82. credit_memo_agent-0.2.0/tests/golden/bank_csv/barclays.export.golden +4 -0
  83. credit_memo_agent-0.2.0/tests/golden/bank_csv/barclays.statement.golden +4 -0
  84. credit_memo_agent-0.2.0/tests/golden/bank_csv/custom.export.golden +4 -0
  85. credit_memo_agent-0.2.0/tests/golden/bank_csv/custom.mapping.yaml +9 -0
  86. credit_memo_agent-0.2.0/tests/golden/bank_csv/custom.statement.golden +4 -0
  87. credit_memo_agent-0.2.0/tests/golden/bank_csv/hsbc.export.golden +4 -0
  88. credit_memo_agent-0.2.0/tests/golden/bank_csv/hsbc.statement.golden +5 -0
  89. credit_memo_agent-0.2.0/tests/golden/bank_csv/lloyds.export.golden +5 -0
  90. credit_memo_agent-0.2.0/tests/golden/bank_csv/lloyds.statement.golden +5 -0
  91. credit_memo_agent-0.2.0/tests/golden/bank_csv/natwest.export.golden +4 -0
  92. credit_memo_agent-0.2.0/tests/golden/bank_csv/natwest.statement.golden +4 -0
  93. credit_memo_agent-0.2.0/tests/golden/bank_csv/starling.export.golden +4 -0
  94. credit_memo_agent-0.2.0/tests/golden/bank_csv/starling.statement.golden +4 -0
  95. credit_memo_agent-0.2.0/tests/golden/monzo/business_export.golden +5 -0
  96. credit_memo_agent-0.2.0/tests/golden/monzo/business_statement.golden +5 -0
  97. credit_memo_agent-0.2.0/tests/golden/monzo/personal_export.golden +13 -0
  98. credit_memo_agent-0.2.0/tests/golden/monzo/personal_statement.golden +12 -0
  99. credit_memo_agent-0.2.0/tests/golden/monzo/results.json +26 -0
  100. credit_memo_agent-0.2.0/tests/golden/openbanking/per_line_balances.json +92 -0
  101. credit_memo_agent-0.2.0/tests/golden/openbanking/per_line_balances.statement.golden +6 -0
  102. credit_memo_agent-0.2.0/tests/golden/openbanking/statement_balance.json +45 -0
  103. credit_memo_agent-0.2.0/tests/golden/openbanking/statement_balance.statement.golden +4 -0
  104. credit_memo_agent-0.2.0/tests/golden/p7_tools/capture_plugin.py +86 -0
  105. credit_memo_agent-0.2.0/tests/golden/p7_tools/make_p7_baseline.py +144 -0
  106. credit_memo_agent-0.2.0/tests/golden/p7_v1_baseline.json.gz +0 -0
  107. credit_memo_agent-0.2.0/tests/golden/synth_archetypes.sha256.json +182 -0
  108. credit_memo_agent-0.2.0/tests/golden/truelayer/running_balance.json +93 -0
  109. credit_memo_agent-0.2.0/tests/golden/truelayer/running_balance.statement.golden +6 -0
  110. credit_memo_agent-0.2.0/tests/golden/truelayer/statement_balance.json +33 -0
  111. credit_memo_agent-0.2.0/tests/golden/truelayer/statement_balance.statement.golden +4 -0
  112. credit_memo_agent-0.2.0/tests/previous_release.py +46 -0
  113. credit_memo_agent-0.2.0/tests/test_binary_writes.py +42 -0
  114. credit_memo_agent-0.2.0/tests/test_case_app.py +445 -0
  115. credit_memo_agent-0.2.0/tests/test_case_flow_end_to_end.py +100 -0
  116. credit_memo_agent-0.2.0/tests/test_case_log.py +3443 -0
  117. credit_memo_agent-0.2.0/tests/test_case_profile.py +401 -0
  118. credit_memo_agent-0.2.0/tests/test_case_purge.py +351 -0
  119. credit_memo_agent-0.2.0/tests/test_case_store.py +586 -0
  120. credit_memo_agent-0.2.0/tests/test_categorise.py +57 -0
  121. credit_memo_agent-0.2.0/tests/test_cli.py +596 -0
  122. credit_memo_agent-0.2.0/tests/test_compare.py +364 -0
  123. credit_memo_agent-0.2.0/tests/test_drilldown.py +585 -0
  124. credit_memo_agent-0.2.0/tests/test_evals_rulesets.py +22 -0
  125. credit_memo_agent-0.2.0/tests/test_firm.py +1866 -0
  126. credit_memo_agent-0.2.0/tests/test_firm_rule_promotion.py +697 -0
  127. credit_memo_agent-0.2.0/tests/test_firm_rules.py +334 -0
  128. credit_memo_agent-0.2.0/tests/test_graph.py +137 -0
  129. credit_memo_agent-0.2.0/tests/test_guard.py +247 -0
  130. credit_memo_agent-0.2.0/tests/test_import_bank_csv.py +415 -0
  131. credit_memo_agent-0.2.0/tests/test_import_monzo.py +201 -0
  132. credit_memo_agent-0.2.0/tests/test_import_openbanking.py +631 -0
  133. credit_memo_agent-0.2.0/tests/test_import_truelayer.py +384 -0
  134. credit_memo_agent-0.2.0/tests/test_importer_contract.py +203 -0
  135. credit_memo_agent-0.2.0/tests/test_indicators.py +427 -0
  136. credit_memo_agent-0.2.0/tests/test_ingest.py +112 -0
  137. credit_memo_agent-0.2.0/tests/test_judgement_queue.py +220 -0
  138. credit_memo_agent-0.2.0/tests/test_m27_m28.py +182 -0
  139. credit_memo_agent-0.2.0/tests/test_mcp_paths.py +135 -0
  140. credit_memo_agent-0.2.0/tests/test_metrics.py +99 -0
  141. credit_memo_agent-0.2.0/tests/test_models.py +325 -0
  142. credit_memo_agent-0.2.0/tests/test_money_in.py +1860 -0
  143. credit_memo_agent-0.2.0/tests/test_monthly.py +216 -0
  144. credit_memo_agent-0.2.0/tests/test_monthly_hardening.py +82 -0
  145. credit_memo_agent-0.2.0/tests/test_multi_account.py +490 -0
  146. credit_memo_agent-0.2.0/tests/test_overrides.py +396 -0
  147. credit_memo_agent-0.2.0/tests/test_own_account_pairing.py +345 -0
  148. credit_memo_agent-0.2.0/tests/test_owner_decisions_2026_11_27.py +44 -0
  149. credit_memo_agent-0.2.0/tests/test_p7_history.py +218 -0
  150. credit_memo_agent-0.2.0/tests/test_pack_evidence.py +247 -0
  151. credit_memo_agent-0.2.0/tests/test_panel_run02_metrics.py +183 -0
  152. credit_memo_agent-0.2.0/tests/test_panel_run03.py +205 -0
  153. credit_memo_agent-0.2.0/tests/test_policy.py +221 -0
  154. credit_memo_agent-0.2.0/tests/test_preview.py +457 -0
  155. credit_memo_agent-0.2.0/tests/test_previous_release.py +185 -0
  156. credit_memo_agent-0.2.0/tests/test_pseudonymise.py +452 -0
  157. credit_memo_agent-0.2.0/tests/test_record.py +405 -0
  158. credit_memo_agent-0.2.0/tests/test_report.py +338 -0
  159. credit_memo_agent-0.2.0/tests/test_review_server.py +368 -0
  160. credit_memo_agent-0.2.0/tests/test_rules.py +701 -0
  161. credit_memo_agent-0.2.0/tests/test_rules_v2.py +2607 -0
  162. credit_memo_agent-0.2.0/tests/test_signoff.py +811 -0
  163. credit_memo_agent-0.2.0/tests/test_sync_folder.py +247 -0
  164. credit_memo_agent-0.2.0/tests/test_synth.py +27 -0
  165. credit_memo_agent-0.2.0/tests/test_synth_case.py +259 -0
  166. credit_memo_agent-0.2.0/tests/test_synth_features.py +208 -0
  167. credit_memo_agent-0.2.0/tests/test_v2_default.py +184 -0
  168. credit_memo_agent-0.2.0/tests/test_verify.py +530 -0
  169. credit_memo_agent-0.2.0/tests/test_workspace_indicators.py +279 -0
  170. credit_memo_agent-0.2.0/tests/test_workspace_overrides.py +623 -0
  171. credit_memo_agent-0.2.0/tests/test_workspace_policy_check.py +346 -0
  172. credit_memo_agent-0.2.0/tests/test_workspace_summary.py +558 -0
@@ -0,0 +1,29 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ venv/
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ .env
11
+ out/
12
+ evals/results/
13
+
14
+ # Real statements never go in this public repo. Everything the CLI reads or writes for a
15
+ # real case is ignored by default; the synthetic examples and test data are let back in
16
+ # explicitly, so a new data file has to be added on purpose.
17
+ private/
18
+ *.private.csv
19
+ *.csv
20
+ *.memo.md
21
+ memo*.md
22
+ *.rejected.md
23
+ *.evidence.json
24
+ *.sqlite
25
+ *.sqlite3
26
+ *.db
27
+ !examples/*.csv
28
+ !examples/*.evidence.json
29
+ !examples/*.memo.md
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anoop Vijayan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,406 @@
1
+ Metadata-Version: 2.5
2
+ Name: credit-memo-agent
3
+ Version: 0.2.0
4
+ Summary: Turns a UK small business's bank statements into a credit memo draft where every number traces to its transactions, reviewed and signed by a person, on your own computer.
5
+ Project-URL: Homepage, https://github.com/anoopvijayan-dev/credit-memo-agent
6
+ Project-URL: Source, https://github.com/anoopvijayan-dev/credit-memo-agent
7
+ Project-URL: Issues, https://github.com/anoopvijayan-dev/credit-memo-agent/issues
8
+ Project-URL: Download, https://github.com/anoopvijayan-dev/credit-memo-agent/releases
9
+ Author: Anoop Vijayan
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: SME lending,bank statements,credit memo,credit risk,open banking,underwriting
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Financial and Insurance Industry
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Office/Business :: Financial
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: langgraph>=1.0
24
+ Requires-Dist: pydantic>=2.6
25
+ Requires-Dist: pyyaml>=6
26
+ Requires-Dist: rich>=13
27
+ Requires-Dist: typer>=0.12
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8; extra == 'dev'
30
+ Requires-Dist: ruff>=0.5; extra == 'dev'
31
+ Provides-Extra: durable
32
+ Requires-Dist: langgraph-checkpoint-sqlite>=3.0; extra == 'durable'
33
+ Provides-Extra: llm
34
+ Requires-Dist: anthropic>=0.40; extra == 'llm'
35
+ Requires-Dist: openai>=1.40; extra == 'llm'
36
+ Provides-Extra: mcp
37
+ Requires-Dist: mcp>=2.0; extra == 'mcp'
38
+ Description-Content-Type: text/markdown
39
+
40
+ # Credit Memo Agent
41
+
42
+ **From a small business's bank statements to a credit memo you can trace: on your own computer,
43
+ with a person checking every figure and the underwriter making the decision.**
44
+
45
+ ![A case in the app: key figures and the month-by-month picture](docs/images/case.png)
46
+
47
+ Import the bank's download as it comes. The app works out the figures an underwriter reads
48
+ first (revenue, lowest balance, overdrawn days, returned direct debits, late VAT, debt service
49
+ cover with the new facility), and every one links to the exact transactions behind it. Unusual
50
+ lines wait for the analyst to decide, with a reason and a name. The memo is drafted from the
51
+ figures only, and a check refuses any number it cannot trace. Signing confirms the figures
52
+ were checked; it does not approve the loan. A signed memo can be re-checked against the
53
+ statements at any time.
54
+
55
+ Statements never leave the computer: the app listens on 127.0.0.1 only.
56
+
57
+ ## Get it
58
+
59
+ | Who | How | Needs |
60
+ |---|---|---|
61
+ | Underwriters and analysts | Download **CreditMemo.exe** from the [latest release](https://github.com/anoopvijayan-dev/credit-memo-agent/releases/latest) and double-click it. The app opens in your browser. | Windows. Nothing to install. |
62
+ | Technical users | `pipx install credit-memo-agent`, then `cma app` | Python 3.11 or later |
63
+ | Developers | Clone this repository: `pip install -e ".[dev]"`, then `cma app` | Python 3.11 or later |
64
+
65
+ The Windows download keeps cases in `%LOCALAPPDATA%\Credit Memo`. `cma app` keeps them in
66
+ `private/cma` under the folder it starts from, or wherever `CMA_HOME` points. Keep the window
67
+ the app runs in open while you work; closing it stops the app. Windows may warn about a new,
68
+ unsigned download the first time: choose "More info", then "Run anyway".
69
+
70
+ ## Try it in 2 minutes
71
+
72
+ 1. Start the app (above).
73
+ 2. Click **Try with demo data**. You get a synthetic café with a year of statements on two
74
+ accounts, marked as a demonstration everywhere.
75
+ 3. Look at the key figures and the monthly chart, then open **Review and sign**.
76
+ 4. Click any figure to see the lines behind it. Decide a flagged line. Build the memo and sign.
77
+ 5. Open **Signed memo**: it is re-checked against the statements and shown as **Verified**.
78
+
79
+ Then try your own: **New case**, add the business's details, and import its statements under
80
+ **Statements** (HSBC, Barclays, Lloyds, NatWest, Starling, Monzo, Open Banking, TrueLayer, or a
81
+ standard CSV of date, description, amount and balance).
82
+
83
+ | The case list | The review |
84
+ |---|---|
85
+ | ![Cases by status](docs/images/cases.png) | ![The review: key figures and the lines to decide](docs/images/review.png) |
86
+
87
+ ## How it works
88
+
89
+ ```
90
+ load → categorise → metrics → policy → draft → guard → review (human) → finalise
91
+ ↑ │
92
+ └──── redraft ────┘ if ungrounded, max 2
93
+ ```
94
+
95
+ Every figure is computed deterministically, cited to the statement lines behind it, checked
96
+ by a grounding guard, and held for a person to sign off. A language model, when used, writes
97
+ prose; it never does the arithmetic. Lenders don't need a model that guesses at cash flow.
98
+ They need one that says "revenue averaged £22,114 a month [M3]" and lets an analyst click
99
+ through to the 261 settlements that number came from. See
100
+ [ADR 001](docs/decisions/001-the-model-never-does-the-arithmetic.md).
101
+
102
+ The policy thresholds shipped with it are illustrative, not any lender's policy. Everything
103
+ in this repository is synthetic: no real statements, no customer data.
104
+
105
+ ## Releasing
106
+
107
+ A tag such as `v0.2.0` builds CreditMemo.exe on Windows and the Python package, self-tests
108
+ both, attaches them to a GitHub Release and publishes the package to PyPI through trusted
109
+ publishing (`.github/workflows/release.yml`). Pull requests build and self-test both without
110
+ publishing.
111
+
112
+ ## Command line (for developers)
113
+
114
+ ```bash
115
+ pip install -e ".[dev]"
116
+
117
+ # Make a synthetic statement (there is no open UK SME dataset, so we generate one
118
+ # with a ground-truth file alongside it).
119
+ cma generate --archetype cafe --profile stretched --out examples
120
+
121
+ # Opt-in features (repeat --feature, or --feature all): acquirers, director, cash,
122
+ # lenders, two_accounts. The truth file then holds every money-in bucket, every line's
123
+ # category and every indicator, for the v2 rules and the case profile it records;
124
+ # two_accounts also writes the reserve account as cafe_stretched_reserve.csv.
125
+ # Without --feature the statement and truth are byte-identical to earlier releases.
126
+ cma generate --archetype cafe --profile stretched --out /tmp/cma-demo --feature all
127
+ # --case also makes one demo case in CMA_HOME holding both accounts and the case profile;
128
+ # the truth's "case" then holds that case's truth, the own-account pairs included.
129
+ cma generate --archetype cafe --profile stretched --out /tmp/cma-demo --feature all --case
130
+
131
+ # Run the memo graph. It stops, asks your name, and asks you to approve.
132
+ # --vat-stagger is the HMRC stagger group from the VAT certificate (the examples use 3).
133
+ cma run examples/cafe_stretched.csv --vat-stagger 3
134
+
135
+ # Scripts can approve with --yes, but only with a named reviewer and only if
136
+ # every figure passed the grounding check; the memo is stamped
137
+ # "automated, no interactive review". --out also writes memo.evidence.json
138
+ # (every transaction id behind every figure, with "schema_version": 1; a record
139
+ # without that key is v0, and v1 only adds keys); a rejected memo goes to
140
+ # memo.rejected.md.
141
+ # Existing files are never overwritten.
142
+ cma run examples/cafe_stretched.csv --vat-stagger 3 --yes --reviewer "A. Analyst" --out private/memo.md
143
+
144
+ # Keep a pending review across restarts (pip install -e ".[durable]"). The database
145
+ # holds the whole statement, so keep it in private/ too.
146
+ cma run examples/cafe_stretched.csv --checkpoint-db private/reviews.sqlite --thread case-7
147
+ cma resume case-7 --checkpoint-db private/reviews.sqlite
148
+
149
+ # A real statement: keep the export and everything made from it under private/
150
+ # (git-ignored, as are *.csv, memo files, evidence files and databases anywhere).
151
+ cma import monzo "private/Monzo Data Export.csv" --opening-balance 123.45 --out private/mine.csv
152
+
153
+ # A case: a folder under the case root (CMA_HOME, default private/cma; owner-only, and
154
+ # refused inside a git tree that does not ignore it). Each command is logged in the case.
155
+ # A root inside a OneDrive, Dropbox, Google Drive or iCloud Drive folder gets a warning
156
+ # on stderr before the case is made, recorded in the case log: keep cases on a local disk.
157
+ cma case new --demo --label "Cafe trial" # prints a random case id
158
+ cma case profile <id> --director "Jane Doe" --own-account "ACME HOLDINGS" --proposed-repayment 1500
159
+ cma case import <id> private/statement.csv --format csv
160
+ cma case import <id> "private/Monzo Data Export.csv" --format monzo --account monzo --opening-balance 123.45
161
+ # An OBIE v3.1 transactions file (one response, an array of pages, or pages one after
162
+ # another): booked GBP lines only, pending ones left out and counted, the bank's
163
+ # TransactionId kept as the line id, a transaction a page repeats kept once. The balance
164
+ # comes from the per-line balances, or from a statement balance at the end of a date.
165
+ cma case import <id> private/transactions.json --format openbanking --account current
166
+ cma case import <id> private/transactions.json --format openbanking --statement-balance 1389.75 --at 2026-04-03
167
+ # Lines booked at the same moment (a date-only export puts a day at midnight) are put in the
168
+ # order their per-line balances chain in. An export with a balance on every line, on none or
169
+ # on each day's last line always imports. When only some lines at one moment carry a balance,
170
+ # finding the order is a search: it is found in nearly every case, and otherwise the file is
171
+ # refused saying the search limit was reached (never that the chain is broken).
172
+ # A TrueLayer Data API transactions export gets the same checks, its running_balance read
173
+ # as the per-line balance. TrueLayer's own categories are kept beside the statement only as
174
+ # untrusted hints (statements/<account>.hints.json); no figure, rule or indicator reads them.
175
+ cma case import <id> private/truelayer.json --format truelayer --account current
176
+ # A bank's own CSV download (paid-in and paid-out columns, dates like 03/03/2026 or
177
+ # 3 Mar 2026, newest first) through a named profile (barclays, hsbc, lloyds, natwest, starling;
178
+ # HSBC's download has no header line and needs --opening-balance),
179
+ # or through your own column mapping (columns, date_format, order; see
180
+ # src/cma/bank_profiles/profiles.yaml). The statement written passes the same checks as a
181
+ # five-column CSV; without the bank's balance column, pass --opening-balance.
182
+ cma case import <id> private/lloyds.csv --format bank-csv:lloyds --account current
183
+ cma case import <id> private/hsbc.csv --format bank-csv:hsbc --account current --opening-balance 1234.56
184
+ cma case import <id> private/bank.csv --format bank-csv --mapping private/bank-map.yaml --opening-balance 200.00
185
+
186
+ # Correct one line's category (only the category; one valid for the line's direction),
187
+ # with a reason and your typed name. The override goes to overrides.jsonl and the case
188
+ # log with your operating-system user and the UTC time. `cma case figures` recomputes
189
+ # every figure from the statements and the whole override log and marks with * each one
190
+ # that rests on an overridden line. An override whose line is gone, or whose statement
191
+ # changed since it was recorded, is stale and not applied until you confirm or drop it.
192
+ cma case override <id> L42 director_funding --reason "director's own transfer" --name "Pat"
193
+ cma case overrides <id> # applied, stale, superseded or dropped
194
+ cma case figures <id>
195
+ cma case resolve-override <id> 3 --confirm --name "Pat" # or --drop
196
+
197
+ # Open the review workspace for a case: a page served on 127.0.0.1 only, from the next
198
+ # free port from 8765 (--port to choose another). Each start prints a URL with a new
199
+ # random token; a request without it, or whose Host is not 127.0.0.1 and that port, is
200
+ # refused. The page loads only files bundled in the package. Ctrl-C stops it.
201
+ # Every figure, money-in bucket and monthly cell on the page links to exactly the lines
202
+ # behind it (date, description, amount, balance, category and the rule or override that
203
+ # set it), with the lines' total for a sum (the figure negated for money paid out), or the
204
+ # inputs and method for an average, share, ratio or count.
205
+ # Each line in the judgement queue and the drill-downs has a form to change its category
206
+ # (only categories valid for its direction), with a reason and your typed name; stale
207
+ # overrides are listed to confirm or drop. A save from a page older than the case log is
208
+ # refused as a conflict: reload and save again. Each save is appended to the case log and
209
+ # the page comes back with the figures, indicators and policy check recomputed.
210
+ # "Compare with your own figure" takes your figure for a memo field or a month and shows
211
+ # the difference from the tool's (to the penny for money), with that period's cash
212
+ # deposits, unexplained lines, possible own-account transfers and overridden lines,
213
+ # largest first. A comparison saves nothing.
214
+ cma review <id> # --no-browser to only print the URL
215
+
216
+ # Preview the pack before sign-off: the memo-ready sections in the order of the memo field
217
+ # map (by default the 13 fields in src/cma/memo_fields/memo_fields.yaml; a firm's own
218
+ # memo_fields.yaml at the case root replaces it), each figure followed by its id, fields
219
+ # with no figure marked for the underwriter and left empty, the illustrative policy check
220
+ # (label first) while show_policy_verdict is on, the demo stamp on a demo case, the
221
+ # grounding guard's verdict and the snapshot hash a sign-off is bound to. It writes no
222
+ # file, only a preview entry in the case log. Exit 1 when the text fails the guard.
223
+ cma case preview <id>
224
+
225
+ # Sign off the figures of the latest preview (or --snapshot <hash>): it asks for your typed
226
+ # name and confirms, records it with your operating-system user and the UTC time, and writes
227
+ # memo.md, record.html (a self-contained record that works offline: every figure links to
228
+ # its lines, with the sign-off), evidence.json and monthly.csv once to packs/<snapshot> in
229
+ # the case folder. Signing off the
230
+ # figures does not approve the loan. Refused, writing nothing, when the case changed since
231
+ # the preview (it names what), when the case log is broken (exit 3, naming the first bad
232
+ # entry), when the figures do not reconcile or the text fails the guard, or when that
233
+ # snapshot's pack is already written; a pack is never overwritten. There is no --yes. The
234
+ # workspace (`cma review`) offers the same preview and sign-off from the case page.
235
+ cma case sign <id>
236
+
237
+ # Verify an evidence record: recompute every figure, bucket and monthly cell from the
238
+ # inputs it recorded and list each mismatch by id (never a description). A pack is checked
239
+ # against its case's statements, profile and firm rules, which must be the ones recorded,
240
+ # and the override log up to the position the pack recorded, so later overrides and
241
+ # accounts imported later change nothing. A `cma run` record is checked against its
242
+ # statement file, which must hash as recorded. A record made with another ruleset is
243
+ # refused, naming the package version and ruleset that made it; a record without
244
+ # schema_version (v0) is checked for M1 to M16 only. It writes nothing. Exit 0 with no
245
+ # mismatch, 1 with a mismatch, 2 when the record cannot be verified.
246
+ cma verify private/cma/cases/<id>/packs/<snapshot>/evidence.json
247
+ cma verify memo.evidence.json --statement private/statement.csv
248
+
249
+ # Drop an entry the case log holds past its recorded entries that a crash, a full disk or a
250
+ # lost power left unfinished, once you confirm it with your typed name; the drop is itself
251
+ # recorded. Refused, changing nothing, when nothing is torn or the log is broken before it
252
+ # (exit 3). Then sign off or save again what the entry held.
253
+ cma case repair <id>
254
+
255
+ # Check a case's hash-chained log (log.jsonl) against its head file. Exit 3 names the
256
+ # first entry that was changed, removed, reordered or left half written.
257
+ cma case check private/cma/cases/<id>
258
+
259
+ # Summarise every case under the case root: judgement-queue lines, lines per indicator,
260
+ # overrides by old and new category, the unexplained share, and whether every figure was
261
+ # traced, reconciled and signed off. No names, descriptions, amounts or durations
262
+ # (--json for JSON). Exit 1 when any case is untraced, unreconciled or cannot be read.
263
+ cma report
264
+
265
+ # Delete every file of a case (asks first; --yes skips the question). The case root's
266
+ # purge_ledger.jsonl gains one line with only the case id, the UTC time and your
267
+ # operating-system user. A purge stopped part-way is finished by running it again.
268
+ cma case purge <id>
269
+
270
+ # Write a pseudonymised copy of a statement (any --format `cma case import` takes) and,
271
+ # with --profile, of a case's profile into a new folder: personal and business names and
272
+ # account numbers become consistent tokens (the profile's names become the tokens their
273
+ # occurrences in the descriptions become); recognised institutions and every id, date,
274
+ # amount and balance are kept. The copy is checked to give the same figures, buckets,
275
+ # monthly cells and indicators under v1 and v2, or nothing is written. It is labelled as
276
+ # pseudonymised personal data, not anonymous data; the token mapping is never written.
277
+ cma pseudonymise private/statement.csv --format csv --out private/pseudo --profile <id>
278
+
279
+ # Choose the categorisation table (src/cma/rules/<id>.yaml; default v2). v1 is the
280
+ # original table, frozen; v2 adds real UK acquirers, gateways, marketplaces, delivery
281
+ # platforms, lenders and merchant cash advance providers, own pots and savings, cash
282
+ # paid in (counted as trading receipts), cash-withdrawal wording, HMRC repayments,
283
+ # refunds and explained non-trading credits. An unknown id is refused. The evidence
284
+ # file records the table's id and hash, and under "lines" each line's id, category and
285
+ # the rule that set it (no descriptions). CMA_RULESET=v1 is the rollback. The committed
286
+ # lines whose category v2 changes are listed in docs/v2-newly-recognised.md; M1-M16 do
287
+ # not move on any committed case or fixture. To go back to the previous release itself,
288
+ # set CMA_RULESET=v1 first and finish any review drafted under v2 before installing it: a
289
+ # review drafted under v2 can hold a category (director_funding, for one) that the
290
+ # previous release cannot read back.
291
+ CMA_RULESET=v1 cma run examples/cafe_stretched.csv
292
+
293
+ # Use a real model instead of the offline one. The offline lock in firm.yaml (under
294
+ # CMA_HOME, default private/cma) is on by default and refuses hosted models and the MCP
295
+ # server; turn it off on purpose first. The prompt still carries only the tables.
296
+ # Edit the file the tool reads, keeping its other settings: open it in an editor and set
297
+ # offline_lock: false
298
+ # (create it with just that line if it does not exist yet).
299
+ mkdir -p "${CMA_HOME:-private/cma}" && ${EDITOR:-nano} "${CMA_HOME:-private/cma}/firm.yaml"
300
+ # In a case of more than one account, a debit pairs with the single credit of the same
301
+ # amount in another account dated within own_account_pairing_days (default 3, 0 to 31) of
302
+ # it; a debit with more than one such credit is left unpaired and listed in the judgement
303
+ # queue with every candidate. A card, gateway, marketplace or delivery platform payout is
304
+ # trading income and is never paired, whatever debit its amount and date match. The value is part of the preview's snapshot, so changing it
305
+ # after a preview makes sign-off refuse that preview. Delete the key before installing
306
+ # an older release: an older release refuses a firm.yaml with a key it does not know.
307
+ export ANTHROPIC_API_KEY=... # or OPENAI_API_KEY
308
+ cma run examples/cafe_stretched.csv --llm anthropic
309
+ ```
310
+
311
+ `examples/cafe_stretched.memo.md` is the output of the offline model on the committed
312
+ example.
313
+
314
+ ## What's in the box
315
+
316
+ | Layer | File | What it does |
317
+ |---|---|---|
318
+ | Synthetic data | `synth.py` | Three business archetypes (café, trades, e-commerce) × three risk profiles (good, stretched, poor). Seeded. Writes the ground truth next to each statement. |
319
+ | Ingest | `ingest.py` | CSV in: `id, date, description, amount, balance`. Refuses duplicate ids, non-ISO or future dates, out-of-order dates, loose amounts and a broken balance chain; reads newest-first files. |
320
+ | Import | `importers/monzo.py` | Monzo export → statement CSV, locally. Monzo Flex is read as a loan. |
321
+ | Categoriser | `categorise.py` + `cma/rules/v1.yaml`, `v2.yaml` | Ordered regex rules and name lists, direction-aware, kept as validated data and chosen by `CMA_RULESET`. Precedence: per-line override, protected rules (the line-type cues: returned DD, own-pot moves, HMRC, refunds; then lenders, director, capital introduced, shareholder, generic loan wording), an own-account pairing, an ambiguous verdict, profile names, firm rules, the rest of the table, the default; each line records its rule id. Under v2 a credit whose matching rules point to two or more money-in buckets (cues first; names only when no cue matches), or that has a payment rail with cash paid-in wording, is ambiguous: it stays `OTHER` (unexplained, never trading receipts) and records `v2:conflict:` with every rule it matched in either stage, the rail included, until a person overrides it or an own-account pairing settles it; a director's or own account's name from the case profile only adds itself as one more candidate. A credit that names both a director or shareholder and an own account from the profile is ambiguous too, under v1 as under v2, unless a protected verdict decides it; on v1 the returned-payment, HMRC, loan, drawings and director, owner, shareholder, capital-introduced, refund, reversal and own-pot rules give that protected verdict. Inside one bucket the table's `category_order` picks the category (cash deposit, customer transfer, card settlement; returned payment, refund), never rule order. Names match as whole words in any script. A transfer in is revenue only with an invoice reference. Returned DDs are linked to the debit they undo. Unmatched lines are `OTHER`, never guessed. |
322
+ | Metrics | `metrics.py` | Twenty-eight figures (revenue, trend, lowest balance, days overdrawn, returned DDs, debt service cover after drawings, VAT timeliness by stagger group, non-trading money in (M16), total money in (M17), cash inside trading receipts (M18), the seven other money-in buckets (M19-M25), the unexplained share (M26), average end-of-day balance (M27) and debt service cover including a proposed facility (M28, n/a with the reason in `cma run`, which has no case profile)…), added up in integer pence. Each carries the transaction ids it came from; a figure that can't be computed is n/a with the reason, never a placeholder. If the money-in buckets do not add up to total money in to the penny, no figures are shown: `cma run` exits 6 naming the difference in pence and the lines. |
323
+ | Indicators | `indicators.py` + `cma/thresholds/indicators.yaml` | Eight risk indicators (a large single credit, a cash deposit at or above the single-deposit limit, a cash-heavy month, cash paid back in after a similar withdrawal, gambling payments, returned direct debits, runs of overdrawn days, irregular credits from a named acquirer), compared in pence and written into the evidence record, each with its lines and the thresholds that fired. The thresholds are illustrative; `cma run --thresholds FILE` takes a firm's own, and a malformed file is refused naming the line. |
324
+ | Policy | `cma/policies/uk_sme_default.yaml` | Nine illustrative rules with pass / refer / fail, and what a missing figure means. Validated on load. Edit the YAML, not the code. |
325
+ | Draft | `graph.py` + `llm.py` | The model gets the metrics table and the policy table, nothing else, and must tag every figure ([Mn]) and threshold ([Rn]). |
326
+ | Guard | `guard.py` | Reads every number in the memo, in digits or words, back against the table: value at the precision written, unit, sign, and the tag right after it. |
327
+ | Review | `graph.py` | LangGraph `interrupt()`; resumes only with a named reviewer's decision. The final memo carries an appendix of every figure, rule, the model and file hashes. |
328
+ | MCP server | `mcp_server.py` | Exposes metrics, the money-in buckets (`money_in_buckets`, read only, line ids only), policy and evidence lookup as tools for any MCP client; reads only .csv/.yaml under `CMA_DATA_DIR`; refuses to start while the offline lock is on. |
329
+ | Evals | `evals/run_evals.py` | Runs all nine cases, reports grounding rate, redrafts and agreement with ground truth on nine metrics. Fails CI if any metric disagrees with truth or the offline memo is ungrounded. |
330
+
331
+ ## Evaluation
332
+
333
+ With the offline model, all nine synthetic cases are fully grounded and every metric
334
+ matches the generator's truth:
335
+
336
+ ```
337
+ case policy grounded rate redrafts truth
338
+ cafe/good pass True 1.0 0 ok
339
+ cafe/stretched refer True 1.0 0 ok
340
+ cafe/poor fail True 1.0 0 ok
341
+ trades/good refer True 1.0 0 ok
342
+ …
343
+ 9/9 memos fully grounded
344
+ ```
345
+
346
+ Run `python evals/run_evals.py --llm anthropic` to measure a real model. The
347
+ interesting numbers are grounding rate and redrafts, which is where models differ.
348
+
349
+ ## Independent review
350
+
351
+ v0.1 was reviewed by a six-seat agent panel (reviewer, security, clean-code,
352
+ platform, staff, data-intensive) run with [Bridgie](https://github.com/anoopvijayan-dev/bridge),
353
+ each seat in a fresh context against written requirements. Verdict: **fail**, with
354
+ 17 consolidated issues; the report is in
355
+ [`.bridgie/runs/v01-pilot-ready/panel.md`](.bridgie/runs/v01-pilot-ready/panel.md).
356
+ The blocker and the five majors that broke the core promises (C1–C6) are fixed, each
357
+ with regression tests taken from the seats' repros. A second panel run on the fixes
358
+ ([`panel-02.md`](.bridgie/runs/v01-pilot-ready/panel-02.md)) found 19 more (D1–D19,
359
+ one blocker), and a third ([`panel-03.md`](.bridgie/runs/v01-pilot-ready/panel-03.md))
360
+ found 27 (E1–E27, one blocker) in those fixes and the new code; all are fixed, with
361
+ tests named after each finding.
362
+
363
+ ## Known limits
364
+
365
+ - Inputs: the five-column CSV, OBIE v3.1 and TrueLayer JSON, and a bank's own CSV
366
+ download (built-in profiles: barclays, hsbc, lloyds, natwest, starling; any other bank
367
+ through a column mapping). CAMT.053 and MT940 are not read yet.
368
+ - No real statement has been run end to end yet. Every figure is checked against
369
+ synthetic statements with a ground-truth file; the first real case is the next test.
370
+ - Revenue trend compares the first and last three months, so a seasonal business
371
+ (the `trades` archetype peaks in winter) can be referred for decline. The fix is 24
372
+ months of data and a year-on-year comparison, not a cleverer prompt.
373
+ - The guard checks figures, not judgements: "no late VAT payments" when M13 is 2 has
374
+ no number in it. The reviewer reads the metrics table in the appendix for that.
375
+ - Revenue by bank transfer needs an invoice reference to count. Statements without
376
+ references show it as non-trading money in (M16), which refers the case.
377
+ - Card-acquirer payouts (money in) are trading revenue and are never paired as a
378
+ transfer between the business's own accounts.
379
+ - With several accounts, the policy check and the memo's "At a glance" summary judge
380
+ the business as a whole; each account's own figures follow below it.
381
+ - Pending reviews live in memory unless you pass `--checkpoint-db`.
382
+ - The reviewer's name is asserted, not authenticated: anyone at the terminal can type
383
+ any name. A pilot inside a lender would put the CLI behind their own sign-in.
384
+ - Signing approves the memo's figures and wording, not the lending decision, which
385
+ stays with the underwriter.
386
+ - Debt service cover (M10) is historical and covers existing debt only. M28 adds the
387
+ facility being applied for. Money in that isn't explained as trading is left out of
388
+ both, and shows as non-trading money in (M16).
389
+ - The categoriser knows common UK acquirer names. Card revenue from an acquirer it
390
+ doesn't recognise lands in M16 and refers the case until a rule is added.
391
+ - Corporation tax and self-assessment payments to HMRC are not a category of their
392
+ own yet; they stay outside the VAT figures.
393
+ - Policy thresholds are illustrative. They are not any lender's real policy.
394
+ - The cloud-sync warning knows each client's own folder names, the OneDrive
395
+ variables Windows sets and Dropbox's info file. A folder synced under any other
396
+ name, or a network share, is not detected.
397
+ - Owner decisions behind these choices: `docs/statement-review/owner-decisions.md`.
398
+
399
+ ## Data
400
+
401
+ Everything here is synthetic. No real statements, no customer data, no employer
402
+ data. The counterparties are invented.
403
+
404
+ ## Licence
405
+
406
+ MIT.