@diy-accounting-uk/diya-gl 1.0.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 (157) hide show
  1. package/README.md +63 -0
  2. package/bin/diya-gl-mcp.js +10 -0
  3. package/bin/diya-gl-read-workbook.js +11 -0
  4. package/bin/diya-gl-recalc.js +10 -0
  5. package/bin/diya-gl-write-workbook.js +12 -0
  6. package/bin/diya-gl.js +24 -0
  7. package/bin/run-dist-bin.js +23 -0
  8. package/dist/app/bin/build-diya-gl-spec.js +680 -0
  9. package/dist/app/bin/build-packages.js +149 -0
  10. package/dist/app/bin/build-reconciliation-pages.js +1052 -0
  11. package/dist/app/bin/build-sitemaps.js +51 -0
  12. package/dist/app/bin/compliance-report.js +125 -0
  13. package/dist/app/bin/cross-package-reconciliation.js +92 -0
  14. package/dist/app/bin/diya-gl-mcp.js +27 -0
  15. package/dist/app/bin/export.js +318 -0
  16. package/dist/app/bin/extract-scenarios.js +1348 -0
  17. package/dist/app/bin/generate.js +353 -0
  18. package/dist/app/bin/judge-reconciliation.js +649 -0
  19. package/dist/app/bin/reconcile.js +247 -0
  20. package/dist/app/bin/report.js +291 -0
  21. package/dist/app/bin/verify-roundtrip.js +941 -0
  22. package/dist/app/bin/verify-stability.js +429 -0
  23. package/dist/app/bin/write-workbook.js +106 -0
  24. package/dist/app/data/filing/ct-computation-v1.1.toml +1033 -0
  25. package/dist/app/data/filing/ct600-v3.toml +2329 -0
  26. package/dist/app/data/filing/frs105-formats.toml +244 -0
  27. package/dist/app/data/fixture-master-gaps.json +247 -0
  28. package/dist/app/data/hmrc/SOURCE.md +14 -0
  29. package/dist/app/data/hmrc/form-layouts/bst.json +116 -0
  30. package/dist/app/data/hmrc/form-layouts/ltd.json +452 -0
  31. package/dist/app/data/hmrc/form-layouts/se.json +485 -0
  32. package/dist/app/data/hmrc/form-layouts/taxi.json +117 -0
  33. package/dist/app/data/hmrc/sa103-mtd-mapping.json +1078 -0
  34. package/dist/app/data/hmrc/sa103f_mapping_v3.csv +111 -0
  35. package/dist/app/data/judge-rubric.md +52 -0
  36. package/dist/app/data/ltd-2020.toml +49 -0
  37. package/dist/app/data/ltd-2021.toml +49 -0
  38. package/dist/app/data/ltd-2022.toml +49 -0
  39. package/dist/app/data/ltd-2023.toml +49 -0
  40. package/dist/app/data/ltd-2024.toml +49 -0
  41. package/dist/app/data/ltd-2025.toml +49 -0
  42. package/dist/app/data/ltd-2026.toml +53 -0
  43. package/dist/app/data/ltd-2027.toml +51 -0
  44. package/dist/app/data/render-unrepresentable/bst.json +24 -0
  45. package/dist/app/data/render-unrepresentable/ltd.json +863 -0
  46. package/dist/app/data/render-unrepresentable/se.json +455 -0
  47. package/dist/app/data/render-unrepresentable/taxi.json +16 -0
  48. package/dist/app/data/roundtrip-budget.json +38 -0
  49. package/dist/app/data/roundtrip-matrix-budget.json +26 -0
  50. package/dist/app/data/roundtrip-unrepresentable.json +401 -0
  51. package/dist/app/data/se-2020-2021.toml +52 -0
  52. package/dist/app/data/se-2021-2022.toml +52 -0
  53. package/dist/app/data/se-2022-2023.toml +55 -0
  54. package/dist/app/data/se-2023-2024.toml +54 -0
  55. package/dist/app/data/se-2024-2025.toml +51 -0
  56. package/dist/app/data/se-2025-2026.toml +51 -0
  57. package/dist/app/data/se-2026-2027.toml +51 -0
  58. package/dist/app/data/volatile-cells.json +16 -0
  59. package/dist/app/lib/anchors/bst.js +79 -0
  60. package/dist/app/lib/anchors/ltd.js +626 -0
  61. package/dist/app/lib/anchors/run.js +100 -0
  62. package/dist/app/lib/anchors/se.js +456 -0
  63. package/dist/app/lib/anchors/taxi.js +164 -0
  64. package/dist/app/lib/app-resources.js +80 -0
  65. package/dist/app/lib/book-checks/ltd.js +408 -0
  66. package/dist/app/lib/book-checks/se.js +687 -0
  67. package/dist/app/lib/book-checks/taxi.js +215 -0
  68. package/dist/app/lib/book-checks.js +872 -0
  69. package/dist/app/lib/books-engine.js +197 -0
  70. package/dist/app/lib/books-interchange.js +533 -0
  71. package/dist/app/lib/calculators/bst.js +381 -0
  72. package/dist/app/lib/calculators/ltd.js +1938 -0
  73. package/dist/app/lib/calculators/se.js +1239 -0
  74. package/dist/app/lib/calculators/shared.js +131 -0
  75. package/dist/app/lib/calculators/taxi.js +461 -0
  76. package/dist/app/lib/canonical-report-value.js +77 -0
  77. package/dist/app/lib/compliance-report.js +341 -0
  78. package/dist/app/lib/diya-gl-calculator.js +52 -0
  79. package/dist/app/lib/diya-gl-canonical.js +355 -0
  80. package/dist/app/lib/diya-gl-edits-ltd.js +144 -0
  81. package/dist/app/lib/diya-gl-edits.js +361 -0
  82. package/dist/app/lib/diya-gl-loader.js +774 -0
  83. package/dist/app/lib/diya-gl-schema.js +212 -0
  84. package/dist/app/lib/generator.js +1912 -0
  85. package/dist/app/lib/guide.js +33 -0
  86. package/dist/app/lib/headlines.js +293 -0
  87. package/dist/app/lib/link-caches.js +421 -0
  88. package/dist/app/lib/ltd-layout.js +139 -0
  89. package/dist/app/lib/mcp/diya-gl-tools.js +330 -0
  90. package/dist/app/lib/mcp/jsonrpc-stdio.js +66 -0
  91. package/dist/app/lib/mcp/server.js +65 -0
  92. package/dist/app/lib/overtype-sidecar.js +180 -0
  93. package/dist/app/lib/package-builder.js +202 -0
  94. package/dist/app/lib/payslips-date-chain.js +481 -0
  95. package/dist/app/lib/payslips-layout.js +235 -0
  96. package/dist/app/lib/period-shift.js +111 -0
  97. package/dist/app/lib/product-workbook.js +317 -0
  98. package/dist/app/lib/products.js +27 -0
  99. package/dist/app/lib/provenance-data.js +36 -0
  100. package/dist/app/lib/provenance.js +92 -0
  101. package/dist/app/lib/report-generator.js +374 -0
  102. package/dist/app/lib/report-indicators.js +468 -0
  103. package/dist/app/lib/report-serializer.js +392 -0
  104. package/dist/app/lib/scenario-extractor.js +1403 -0
  105. package/dist/app/lib/scenario-loader.js +84 -0
  106. package/dist/app/lib/sitemap-builder.js +59 -0
  107. package/dist/app/lib/spreadsheet-runner.js +566 -0
  108. package/dist/app/lib/tax/capital-allowances.js +77 -0
  109. package/dist/app/lib/tax/corporation-tax.js +144 -0
  110. package/dist/app/lib/tax/income-tax.js +122 -0
  111. package/dist/app/lib/tax/mileage.js +69 -0
  112. package/dist/app/lib/tax/national-insurance.js +31 -0
  113. package/dist/app/lib/tax/vat.js +188 -0
  114. package/dist/app/lib/tax-year.js +31 -0
  115. package/dist/app/lib/template-formula-map.js +253 -0
  116. package/dist/app/lib/workbook-set.js +153 -0
  117. package/dist/app/lib/xlsx-exporter.js +2815 -0
  118. package/dist/app/lib/xlsx-parts.js +111 -0
  119. package/dist/app/lib/xlsx-reader.js +84 -0
  120. package/dist/app/products/bst.js +727 -0
  121. package/dist/app/products/ltd.js +4270 -0
  122. package/dist/app/products/se.js +3403 -0
  123. package/dist/app/products/taxi.js +912 -0
  124. package/dist/app/templates/bst/bst-excel.xlsx +0 -0
  125. package/dist/app/templates/bst/meta.toml +27 -0
  126. package/dist/app/templates/ltd/Cashaccount.xlsx +0 -0
  127. package/dist/app/templates/ltd/Companysecretary.xlsx +0 -0
  128. package/dist/app/templates/ltd/Creditcardaccount.xlsx +0 -0
  129. package/dist/app/templates/ltd/Currentaccount.xlsx +0 -0
  130. package/dist/app/templates/ltd/Dividend Voucher.docx +0 -0
  131. package/dist/app/templates/ltd/Financialaccounts.xlsx +0 -0
  132. package/dist/app/templates/ltd/Fixedassets.xlsx +0 -0
  133. package/dist/app/templates/ltd/Payslips.xlsx +0 -0
  134. package/dist/app/templates/ltd/Purchases.xlsx +0 -0
  135. package/dist/app/templates/ltd/Sales.xlsx +0 -0
  136. package/dist/app/templates/ltd/Salesinvoice.xlsx +0 -0
  137. package/dist/app/templates/ltd/Savingaccount.xlsx +0 -0
  138. package/dist/app/templates/ltd/Vatreturns.xlsx +0 -0
  139. package/dist/app/templates/ltd/expensesform.xlsx +0 -0
  140. package/dist/app/templates/ltd/meta.toml +54 -0
  141. package/dist/app/templates/meta.toml +12 -0
  142. package/dist/app/templates/se/Bank.xlsx +0 -0
  143. package/dist/app/templates/se/Cash.xlsx +0 -0
  144. package/dist/app/templates/se/Financialaccounts.xlsx +0 -0
  145. package/dist/app/templates/se/Fixedassets.xlsx +0 -0
  146. package/dist/app/templates/se/Payslips.xlsx +0 -0
  147. package/dist/app/templates/se/Purchases.xlsx +0 -0
  148. package/dist/app/templates/se/Sales.xlsx +0 -0
  149. package/dist/app/templates/se/Salesinvoice.xlsx +0 -0
  150. package/dist/app/templates/se/Vat.xlsx +0 -0
  151. package/dist/app/templates/se/meta.toml +43 -0
  152. package/dist/app/templates/taxi/meta.toml +43 -0
  153. package/dist/app/templates/taxi/taxi-excel.xlsx +0 -0
  154. package/dist/web/spreadsheets.diyaccounting.co.uk/public/schema/diya-gl-book-v2.schema.json +713 -0
  155. package/dist/web/spreadsheets.diyaccounting.co.uk/public/schema/diya-gl-docs.md +930 -0
  156. package/dist/web/spreadsheets.diyaccounting.co.uk/public/schema/diya-gl-lines-v2.schema.json +220 -0
  157. package/package.json +37 -0
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # @diy-accounting-uk/diya-gl
2
+
3
+ Run a UK sole trader's or company's accounts from the command line. A diya-gl book is a
4
+ book.toml and a lines.jsonl file, usually a few kilobytes, that hold a year of transactions
5
+ and the chart of accounts they post to. This package recalculates one, reads one out of an
6
+ Excel workbook, writes one back into a workbook, and serves one over MCP, all through the
7
+ same engine the [DIY Accounting spreadsheets site](https://spreadsheets.diyaccounting.co.uk)
8
+ reconciles in CI.
9
+
10
+ Four products: Basic Sole Trader, Taxi Driver, Self Employed, Limited Company.
11
+
12
+ ## Install
13
+
14
+ ```
15
+ npm install -g @diy-accounting-uk/diya-gl
16
+ ```
17
+
18
+ ## Use
19
+
20
+ ```
21
+ diya-gl recalc --package bst --data my-book --years se-2025-2026 --output-dir out
22
+ diya-gl read-workbook --file my-workbook.xlsx --output-dir out
23
+ diya-gl write-workbook --data my-book --output-dir out
24
+ diya-gl mcp
25
+ ```
26
+
27
+ Each subcommand is also its own command, if you only want one on your `PATH`:
28
+ `diya-gl-recalc`, `diya-gl-read-workbook`, `diya-gl-write-workbook`, `diya-gl-mcp`.
29
+
30
+ - **recalc** takes a diya-gl book (`--data`) or a populated workbook (`--source-dir`,
31
+ `--mode saved|recalculate`) and writes `report.json`: every figure, report section and
32
+ compliance check the engine computes.
33
+ - **read-workbook** takes an `.xlsx`, a package zip, or a diya-gl zip or JSON file
34
+ (`--file`), and writes `book.toml`, `lines.jsonl`, `report.json` and `bookchecks.json`.
35
+ - **write-workbook** takes a diya-gl book (`--data` or `--file`) and writes the Excel
36
+ package its product composes onto its template — the same client-side path the site's
37
+ books page uses, so it never needs LibreOffice. Add `--zip` for the package as one zip.
38
+ - **mcp** runs a stdio [MCP](https://modelcontextprotocol.io) server with four tools:
39
+ `extract_book`, `report`, `edit_lines`, `save_workbook`. Point an MCP client at
40
+ `diya-gl-mcp` (or `diya-gl mcp`) with no arguments.
41
+
42
+ ## The format
43
+
44
+ A diya-gl book's fields are drawn from the XBRL Global Ledger Taxonomy Framework 2015 and
45
+ map onto HMRC's SA103S boxes. The two schemas that validate a book are published at
46
+ [`/schema/diya-gl-book-v2.schema.json`](https://spreadsheets.diyaccounting.co.uk/schema/diya-gl-book-v2.schema.json)
47
+ and
48
+ [`/schema/diya-gl-lines-v2.schema.json`](https://spreadsheets.diyaccounting.co.uk/schema/diya-gl-lines-v2.schema.json).
49
+ The full field mapping, the check catalogue and the reconciliation evidence behind them are
50
+ on the [format spec page](https://spreadsheets.diyaccounting.co.uk/diya-gl.html).
51
+
52
+ ## Provenance
53
+
54
+ Every book this package writes carries five stamps: the format version, this package's own
55
+ version and commit, a hash over the tax-year data applied, and each product's template hash
56
+ and reconciliation scorecard. Recalculating an old book either reproduces its `report.json`
57
+ byte for byte or names the stamp that differs. Every published release is cut from a commit
58
+ whose reconciliation checks passed; the scorecards are on the
59
+ [reconciled releases page](https://spreadsheets.diyaccounting.co.uk/reconciliation/releases.html).
60
+
61
+ ## License
62
+
63
+ AGPL-3.0-only. Copyright (C) 2026 DIY Accounting Ltd.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ // Copyright (C) 2026 DIY Accounting Ltd
4
+ //
5
+ // diya-gl-mcp.js — the stdio MCP server, four tools over a loaded diya-gl
6
+ // book: extract_book, report, edit_lines, save_workbook. See
7
+ // app/lib/mcp/server.js in the source repository for the method table.
8
+
9
+ import { runDistBin } from "./run-dist-bin.js";
10
+ runDistBin("app/bin/diya-gl-mcp.js", process.argv.slice(2));
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ // Copyright (C) 2026 DIY Accounting Ltd
4
+ //
5
+ // diya-gl-read-workbook.js — reads an .xlsx, a package zip, or any of the
6
+ // diya-gl formats, and extracts book.toml, lines.jsonl, report.json and
7
+ // bookchecks.json. See app/bin/export.js in the source repository for the
8
+ // full option list (--file or --source-dir plus --package).
9
+
10
+ import { runDistBin } from "./run-dist-bin.js";
11
+ runDistBin("app/bin/export.js", process.argv.slice(2));
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ // Copyright (C) 2026 DIY Accounting Ltd
4
+ //
5
+ // diya-gl-recalc.js — report.json and bookchecks.json from a diya-gl book
6
+ // or a populated Excel package. See `diya-gl recalc --help` for usage, or
7
+ // app/bin/report.js in the source repository for the full option list.
8
+
9
+ import { runDistBin } from "./run-dist-bin.js";
10
+ runDistBin("app/bin/report.js", process.argv.slice(2));
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ // Copyright (C) 2026 DIY Accounting Ltd
4
+ //
5
+ // diya-gl-write-workbook.js — writes the Excel package a diya-gl book
6
+ // composes onto its product's template, with no LibreOffice: the same
7
+ // client-side compose path the books page uses. See
8
+ // app/bin/write-workbook.js in the source repository for the full option
9
+ // list (--data or --file, plus --zip for the package download).
10
+
11
+ import { runDistBin } from "./run-dist-bin.js";
12
+ runDistBin("app/bin/write-workbook.js", process.argv.slice(2));
package/bin/diya-gl.js ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ // Copyright (C) 2026 DIY Accounting Ltd
4
+ //
5
+ // diya-gl.js — the dispatcher: diya-gl <recalc|read-workbook|write-workbook|mcp> [args].
6
+ // Each subcommand is also its own bin (diya-gl-recalc, and so on), for a
7
+ // caller that wants one command on its PATH without the others.
8
+
9
+ import { runDistBin } from "./run-dist-bin.js";
10
+
11
+ const SUBCOMMANDS = {
12
+ "recalc": "app/bin/report.js",
13
+ "read-workbook": "app/bin/export.js",
14
+ "write-workbook": "app/bin/write-workbook.js",
15
+ "mcp": "app/bin/diya-gl-mcp.js",
16
+ };
17
+
18
+ const [subcommand, ...rest] = process.argv.slice(2);
19
+ const target = SUBCOMMANDS[subcommand];
20
+ if (!target) {
21
+ console.error(`Usage: diya-gl <${Object.keys(SUBCOMMANDS).join("|")}> [args]`);
22
+ process.exit(1);
23
+ }
24
+ runDistBin(target, rest);
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (C) 2026 DIY Accounting Ltd
3
+ //
4
+ // run-dist-bin.js — every wrapper below spawns the real entry point under
5
+ // dist/ as a child process rather than importing it, so each one runs the
6
+ // same way regardless of whether the target file guards its own main() on
7
+ // import.meta.url (report.js does not; export.js and write-workbook.js do)
8
+ // -- an import would silently skip the guarded ones. stdio is inherited,
9
+ // so the MCP server's stdin/stdout JSON-RPC transport passes straight
10
+ // through to whatever spawned this wrapper.
11
+
12
+ import { spawnSync } from "child_process";
13
+ import { dirname, resolve } from "path";
14
+ import { fileURLToPath } from "url";
15
+
16
+ const BIN_DIR = dirname(fileURLToPath(import.meta.url));
17
+
18
+ export function runDistBin(relativePath, args) {
19
+ const target = resolve(BIN_DIR, "..", "dist", relativePath);
20
+ const result = spawnSync(process.execPath, [target, ...args], { stdio: "inherit" });
21
+ if (result.error) throw result.error;
22
+ process.exit(result.status ?? 1);
23
+ }