fairbuild-commitments 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +243 -2
- package/bin/fairbuild-commitments.js +7 -0
- package/evals/cases.json +398 -0
- package/fixtures/README.md +7 -0
- package/fixtures/commitments.csv +9 -0
- package/fixtures/exports/procore-commitments.csv +4 -0
- package/fixtures/intl/README.md +12 -0
- package/fixtures/intl/de/commitments.csv +9 -0
- package/fixtures/intl/de/invoices.csv +13 -0
- package/fixtures/intl/ja/commitments.csv +9 -0
- package/fixtures/intl/ja/invoices.csv +13 -0
- package/fixtures/invoices.csv +13 -0
- package/fixtures/settings-lenient.json +1 -0
- package/fixtures/settings-typo.json +1 -0
- package/fixtures/settings.json +1 -0
- package/package.json +56 -4
- package/server.json +37 -0
- package/src/commitments.js +87 -0
- package/src/demo.js +18 -0
- package/src/index.js +2 -0
- package/src/manifest.js +76 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kurt Francisco
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,244 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Fairbuild Commitments (`fairbuild-commitments`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Checks subcontracts and purchase orders against AP invoices and payments: committed cost still open, commitments billed or paid past their value, billing on unsigned subcontracts, retainage held at the wrong rate, closed commitments with a balance, stale open POs and invoices that name no commitment. Drafts vendor letters. Closing or changing a commitment is a person's job.
|
|
4
|
+
|
|
5
|
+
MIT · Node 20 or newer · local files only · built on [`fairbuild-core`](../fairbuild-core) · part of [Fairbuild](../../README.md)
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx -y fairbuild-commitments demo
|
|
9
|
+
npx -y fairbuild-commitments mcp --root ./exports
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## What it needs
|
|
13
|
+
|
|
14
|
+
| Argument | What to give it |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `commitments` (required) | Subcontracts and purchase orders under --root (CSV, Excel or JSON): number, job, vendor, original amount, approved changes, revised amount, invoiced, paid, retainage, status, executed. Procore and Buildertrend layouts are recognised |
|
|
17
|
+
| `invoices` | Optional AP invoice register with the commitment each invoice is billed against. When given, invoiced to date comes from it and is tied to the commitment report |
|
|
18
|
+
| `settings` | Optional settings JSON (commitment_settings schema): stale_days, tolerance, retainage_check |
|
|
19
|
+
|
|
20
|
+
Only `commitments` is required. Each optional file turns on the checks that need it.
|
|
21
|
+
|
|
22
|
+
## What it refuses, and what waits for a person
|
|
23
|
+
|
|
24
|
+
Refused in every mode (the tool is listed so an assistant can see it, and every call is blocked):
|
|
25
|
+
|
|
26
|
+
- `po_close`: Fairbuild Commitments never closes or reduces a commitment in your accounting system; a person does after the vendor confirms.
|
|
27
|
+
- `po_change`: Fairbuild Commitments never issues or changes a subcontract, PO or change order.
|
|
28
|
+
- `ap_pay_invoice`: Fairbuild Commitments never pays vendors.
|
|
29
|
+
- `email_send`: Fairbuild Commitments never sends letters; a person sends the approved draft.
|
|
30
|
+
|
|
31
|
+
Waits for one named person's click, even in Auto mode (nothing is sent, paid or posted by the agent; the click is recorded for the person who acts):
|
|
32
|
+
|
|
33
|
+
- `commitments_request_send`: Approve the letter (one click)
|
|
34
|
+
|
|
35
|
+
## Checks
|
|
36
|
+
|
|
37
|
+
What `commitments_check` flags, each with the first example it finds in the fictional fixtures (the eval cases for `commitments_check`):
|
|
38
|
+
|
|
39
|
+
| Code | Example from the fixtures |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `over_invoiced` | Invoiced 25400 is more than the commitment's value 9000 by 16400. Look for an unissued change order or a bill coded to the wrong commitment. |
|
|
42
|
+
| `paid_over_invoiced` | Paid 10000 is more than invoiced 9000 by 1000. |
|
|
43
|
+
| `invoiced_does_not_tie` | AP invoices against SC-105 add up to 9000 (2); the commitment report shows 6000 invoiced. |
|
|
44
|
+
| `unknown_commitment` | Invoice(s) EX-77 from Example Glazing LLC (8800) name commitment "SC-199", which is not in the commitment list. |
|
|
45
|
+
| `not_executed` | 18000 has been invoiced against SC-102, which is not marked executed. Get the signed subcontract or PO before paying more. |
|
|
46
|
+
| `revised_math` | Original 85000 plus approved changes 5000 is 90000; the commitment says 92000. |
|
|
47
|
+
| `stale_open` | 4000 is still open on PO-202 with no invoice for 220 days (since 2026-04-10). Ask the vendor whether more is coming or close it. |
|
|
48
|
+
| `closed_with_balance` | PO-203 is closed with 2500 not invoiced. If the work is finished, reduce the commitment so committed cost is not overstated. |
|
|
49
|
+
| `retainage_off` | Retainage held is 13500; 10% of 150000 invoiced is 15000. |
|
|
50
|
+
|
|
51
|
+
<!-- generated:start -->
|
|
52
|
+
|
|
53
|
+
## A demo run
|
|
54
|
+
|
|
55
|
+
`npx -y fairbuild-commitments demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
Fairbuild Commitments demo (fictional jobs, vendors and commitments), Auto mode on for drafts
|
|
59
|
+
|
|
60
|
+
▶ Check eight subcontracts and POs against the AP invoices
|
|
61
|
+
status: executed decision: allow
|
|
62
|
+
8 commitment(s): 208500 still open of 558500 committed. 2 billed or paid past their value (16400 over-invoiced, 1000 overpaid), 5 to review, 1 invoice group(s) naming no commitment (8800).
|
|
63
|
+
PO-201 Sample Lumber Supply 9000 25400 over over_invoiced
|
|
64
|
+
SC-105 Sample Painting Co 30000 9000 over paid_over_invoiced, invoiced_does_not_tie
|
|
65
|
+
SC-199 Example Glazing LLC 0 8800 unmatched unknown_commitment
|
|
66
|
+
SC-102 Test Drywall Co 64000 18000 review not_executed
|
|
67
|
+
SC-103 Example Electric Inc 92000 45000 review revised_math
|
|
68
|
+
PO-202 Sample Rebar Co 15000 11000 review stale_open
|
|
69
|
+
PO-203 Sample Sheet Metal 12000 9500 review closed_with_balance
|
|
70
|
+
SC-104 Example Roofing LLC 205000 150000 review retainage_off
|
|
71
|
+
SC-101 Example Concrete LLC 131500 96000 ok
|
|
72
|
+
|
|
73
|
+
▶ Explain the lumber PO
|
|
74
|
+
status: executed decision: allow
|
|
75
|
+
PO-201 Sample Lumber Supply (job 24-101): over. Value 9000, invoiced 25400, paid 25400, open 0. Invoiced 25400 is more than the commitment's value 9000 by 16400. Look for an unissued change order or a bill coded to the wrong commitment.
|
|
76
|
+
|
|
77
|
+
▶ Write the worklist
|
|
78
|
+
status: executed decision: allow
|
|
79
|
+
Worklist written: 8 commitment(s): 208500 still open of 558500 committed. 2 billed or paid past their value (16400 over-invoiced, 1000 overpaid), 5 to review, 1 invoice group(s) naming no commitment (8800).
|
|
80
|
+
|
|
81
|
+
▶ Draft a letter to Sample Lumber Supply (Auto is opted in for drafts here)
|
|
82
|
+
status: executed decision: allow (auto)
|
|
83
|
+
letter Sample Lumber Supply drafted with 1 open marker(s) ([TO CONFIRM vendor contact]). Nothing was sent.
|
|
84
|
+
|
|
85
|
+
▶ Approve sending it: one named click, even in Auto
|
|
86
|
+
status: needs_approval decision: ask
|
|
87
|
+
reason: binding_send stays one-click, even in Auto
|
|
88
|
+
|
|
89
|
+
▶ Agent tries to close the PO itself
|
|
90
|
+
status: blocked decision: block
|
|
91
|
+
reason: Fairbuild Commitments never closes or reduces a commitment in your accounting system; a person does after the vendor confirms.
|
|
92
|
+
|
|
93
|
+
Audit log: <demo folder>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Tools
|
|
97
|
+
|
|
98
|
+
| Tool | What it does | Policy |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| `commitments_check` | Per subcontract and PO: value (original plus approved changes), invoiced, paid and still open; billed or paid past its value; billing on an unsigned commitment; retainage held at the wrong rate; closed with a balance;… | runs |
|
|
101
|
+
| `commitments_explain` | Show one commitment's value, invoiced, paid, open balance and every finding. | runs |
|
|
102
|
+
| `commitments_write_report` | Write the commitments worklist as commitments.csv (one row per item, blank decision columns for people to fill in) and commitments.html into out_dir (default fairbuild-out/commitments). | runs |
|
|
103
|
+
| `commitments_draft_letter` | Write drafts/letter-<vendor>.md: one letter to one vendor listing its commitments that need an answer (a credit or change order for over-billing, the signed subcontract, a final invoice for a stale PO). | asks first (Auto can be opted in) |
|
|
104
|
+
| `commitments_request_send` | After one named human click (even in Auto), record that the reviewed letter draft is approved in letter-requests.csv. | one named click, even in Auto (`binding_send`) |
|
|
105
|
+
| `po_close` | Fairbuild Commitments never closes or reduces a commitment in your accounting system; a person does after the vendor confirms. | refused |
|
|
106
|
+
| `po_change` | Fairbuild Commitments never issues or changes a subcontract, PO or change order. | refused |
|
|
107
|
+
| `ap_pay_invoice` | Fairbuild Commitments never pays vendors. | refused |
|
|
108
|
+
| `email_send` | Fairbuild Commitments never sends letters; a person sends the approved draft. | refused |
|
|
109
|
+
|
|
110
|
+
Any tool name not in this table is blocked, including names a model invents. `refused` tools are listed so a model can see they exist and are refused.
|
|
111
|
+
|
|
112
|
+
## Columns it reads
|
|
113
|
+
|
|
114
|
+
Table inputs can be CSV, TSV, semicolon- or pipe-separated text, Excel `.xlsx`, JSON or JSONL. Columns are matched by the agent's own name, then by the English names below, then by their names in German, French, Spanish, Portuguese, Italian, Japanese, Chinese and Korean. Dates become `YYYY-MM-DD`; amounts are read with either decimal mark; weights, distances and dimensions are converted when the column says it holds kilograms, kilometres or centimetres. Every result lists under `sources` how each file was read.
|
|
115
|
+
|
|
116
|
+
### Subcontracts and purchase orders (`commitments`)
|
|
117
|
+
|
|
118
|
+
| Column | Type | Also read as | For example, in other languages |
|
|
119
|
+
|---|---|---|---|
|
|
120
|
+
| `commitment` (required) | text | Commitment, Commitment Number, Number, Contract Number, Subcontract, Subcontract Number | Auftragsnummer NU, N° de commande, 発注番号, 合同编号 |
|
|
121
|
+
| `commitment_type` | text | Commitment Type, Type, Contract Type, Doc Type | Vertragsart, Type de contrat, 契約区分, 合同类型 |
|
|
122
|
+
| `job` | text | Job, Job Number, Job No, Job #, Job No., Job ID | Projekt, Chantier, 工事番号, 项目编号 |
|
|
123
|
+
| `vendor` | text | Vendor, Vendor Name, Subcontractor, Sub, Supplier, Contract Company | Lieferant, Fournisseur, 仕入先, 供应商 |
|
|
124
|
+
| `cost_code` | text | Cost Code, Costcode, Cost Code Number, Phase, Phase Code, Phase/Cost Code | Leistungsposition, Code de coût, 工種, 成本科目 |
|
|
125
|
+
| `cost_type` | text | Cost Type, Category, Cost Category, Cost Class, CostType, Type Code | Kostenart, Nature de coût, 原価区分, 成本类型 |
|
|
126
|
+
| `description` | text | Description, Title, Scope, Name | Beschreibung, Description, 摘要, 摘要 |
|
|
127
|
+
| `date` | date | Date, Contract Date, PO Date, Issued, Issue Date, Created | Datum, Date, 日付, 日期 |
|
|
128
|
+
| `status` | text | Status, Commitment Status, PO Status | Status, Statut, ステータス, 状态 |
|
|
129
|
+
| `original_amount` | amount | Original Amount, Original Contract Amount, Original Commitment, Orig Amount, Contract Amount, PO Amount | Ursprüngliche Auftragssumme, Montant initial du marché, 当初契約額, 原合同金额 |
|
|
130
|
+
| `approved_changes` | amount | Approved Changes, Approved Change Orders, Approved COs, Change Orders | Genehmigte Nachträge, Avenants validés, 承認済み変更, 已批准变更 |
|
|
131
|
+
| `revised_amount` | amount | Revised Amount, Revised Contract Amount, Current Commitment, Revised Commitment, Current Amount, Total Commitment | Aktuelle Auftragssumme, Montant actualisé, 変更後契約額, 调整后合同金额 |
|
|
132
|
+
| `invoiced` | amount | Invoiced, Invoiced to Date, Billed to Date, Billed, Invoiced Amount, Received to Date | Abgerechnet, Facturé, 請求済, 已开票 |
|
|
133
|
+
| `paid` | amount | Paid, Paid to Date, Payments Issued, Payments, Amount Paid | Bezahlt, Payé, 支払済, 已付款 |
|
|
134
|
+
| `retainage_held` | amount | Retainage Held, Retainage, Retention Held, Retainage Withheld | Einbehalt, Retenue de garantie, 保留金, 质保金 |
|
|
135
|
+
| `retainage_pct` | number | Retainage %, Retainage Percent, Retention % | Einbehalt %, Retenue de garantie %, 保留率, 质保金比例 |
|
|
136
|
+
| `executed` | yes/no | Executed, Signed, Fully Executed, Contract Signed | Unterschrieben, Signé, 契約締結, 已签订 |
|
|
137
|
+
|
|
138
|
+
Named exports recognised by their column names:
|
|
139
|
+
|
|
140
|
+
| System | Export | Recognised by | Layout checked against vendor docs |
|
|
141
|
+
|---|---|---|---|
|
|
142
|
+
| Procore | Commitments tool, export to CSV (subcontracts and purchase orders) | Number, Contract Company, Original Contract Amount | no |
|
|
143
|
+
| Buildertrend | Purchase Orders list, export to Excel | PO #, Assigned To, Total | no |
|
|
144
|
+
|
|
145
|
+
Where a layout says "checked", its column names were compared with the vendor's documentation on that date. The other layouts were written from knowledge of the export and were not checked. None was tested against a live account.
|
|
146
|
+
|
|
147
|
+
### AP invoices (`invoices`)
|
|
148
|
+
|
|
149
|
+
| Column | Type | Also read as | For example, in other languages |
|
|
150
|
+
|---|---|---|---|
|
|
151
|
+
| `invoice_number` (required) | text | Invoice Number, Invoice, Invoice No, Invoice #, Inv No, Bill # | Rechnungsnummer, N° de facture, 請求書番号, 发票号 |
|
|
152
|
+
| `vendor` | text | Vendor, Vendor Name, Subcontractor, Sub, Supplier, Contract Company | Lieferant, Fournisseur, 仕入先, 供应商 |
|
|
153
|
+
| `vendor_id` | text | Vendor ID, Vendor Number, Vendor No, Vendor Code, Supplier ID | Lieferantennummer, Code fournisseur, 仕入先コード, 供应商编号 |
|
|
154
|
+
| `job` | text | Job, Job Number, Job No, Job #, Job No., Job ID | Projekt, Chantier, 工事番号, 项目编号 |
|
|
155
|
+
| `cost_code` | text | Cost Code, Costcode, Cost Code Number, Phase, Phase Code, Phase/Cost Code | Leistungsposition, Code de coût, 工種, 成本科目 |
|
|
156
|
+
| `cost_type` | text | Cost Type, Category, Cost Category, Cost Class, CostType, Type Code | Kostenart, Nature de coût, 原価区分, 成本类型 |
|
|
157
|
+
| `invoice_date` | date | Invoice Date, Date, Bill Date, Inv Date | Rechnungsdatum, Date de facture, 請求日, 发票日期 |
|
|
158
|
+
| `due_date` | date | Due Date, Due, Pay By | Fälligkeitsdatum, Date d'échéance, 期日, 截止日期 |
|
|
159
|
+
| `received_date` | date | Received Date, Date Received, Entered, Entry Date | Eingangsdatum, Date de réception, 受領日, 收到日期 |
|
|
160
|
+
| `amount` | amount | Amount, Invoice Amount, Invoice Total, Total, Gross Amount, Bill Amount | Betrag, Montant, 金額, 金额 |
|
|
161
|
+
| `retainage` | amount | Retainage, Retainage Withheld, Retention, Retainage Amount | Einbehalt, Retenue de garantie, 保留金, 质保金 |
|
|
162
|
+
| `tax` | amount | Tax, Sales Tax, Tax Amount, Use Tax | Steuer, TVA, 消費税, 税额 |
|
|
163
|
+
| `commitment` | text | Commitment, PO, PO Number, PO #, Purchase Order, Subcontract | Auftragsnummer NU, N° de commande, 発注番号, 合同编号 |
|
|
164
|
+
| `status` | text | Status, Invoice Status, Approval Status, Pay Status | Status, Statut, ステータス, 状态 |
|
|
165
|
+
| `paid_date` | date | Paid Date, Payment Date, Date Paid, Check Date | Zahlungsdatum, Date de paiement, 支払日, 付款日期 |
|
|
166
|
+
| `paid_amount` | amount | Paid Amount, Amount Paid, Payment Amount, Paid | Bezahlt, Montant payé, 支払額, 已付金额 |
|
|
167
|
+
| `check_number` | text | Check Number, Check #, Check No, Payment Number, Payment Ref | Zahlungsnummer, N° de paiement, 支払番号, 付款编号 |
|
|
168
|
+
| `description` | text | Description, Memo, Notes, Title | Beschreibung, Description, 摘要, 摘要 |
|
|
169
|
+
|
|
170
|
+
Named exports recognised by their column names:
|
|
171
|
+
|
|
172
|
+
| System | Export | Recognised by | Layout checked against vendor docs |
|
|
173
|
+
|---|---|---|---|
|
|
174
|
+
| Sage 300 Construction and Real Estate | AP invoice register exported to Excel or CSV | Vendor, Invoice, Invoice Date, Retainage | no |
|
|
175
|
+
| Buildertrend | Bills list, export to Excel | Bill #, Assigned To, Total | no |
|
|
176
|
+
|
|
177
|
+
Where a layout says "checked", its column names were compared with the vendor's documentation on that date. The other layouts were written from knowledge of the export and were not checked. None was tested against a live account.
|
|
178
|
+
|
|
179
|
+
### Files from other countries
|
|
180
|
+
|
|
181
|
+
A German export in Windows-1252 with semicolons, `1.234,56` and `03.11.2026`, or a Japanese one in Shift_JIS with `2026/11/03`, is read the same way as the English file. [`fixtures/intl/`](fixtures/intl) has both versions of the demo data, and the eval cases `intl-de-*` and `intl-ja-*` require the same results as the English case. Columns named differently? Run `npx fairbuild-commitments inspect <file>` (names and shapes only, never values) and name them in `fairbuild-sources.json`:
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{ "files": { "exports/bills.csv": { "columns": { "invoice_number": "Beleg" }, "date_order": "dmy" } } }
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Install
|
|
188
|
+
|
|
189
|
+
Node 20 or newer. No other dependencies.
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
npx -y fairbuild-commitments demo
|
|
193
|
+
npx -y fairbuild-commitments mcp --root /path/to/your/files
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Claude Desktop, Cursor and other MCP hosts:
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
{
|
|
200
|
+
"mcpServers": {
|
|
201
|
+
"fairbuild-commitments": {
|
|
202
|
+
"command": "npx",
|
|
203
|
+
"args": [
|
|
204
|
+
"-y",
|
|
205
|
+
"fairbuild-commitments",
|
|
206
|
+
"mcp",
|
|
207
|
+
"--root",
|
|
208
|
+
"/path/to/your/files"
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Claude Code: `claude mcp add fairbuild-commitments -- npx -y fairbuild-commitments mcp --root .`, or install the `fairbuild-commitments` plugin from this repository's marketplace.
|
|
216
|
+
|
|
217
|
+
## Modes and approvals
|
|
218
|
+
|
|
219
|
+
- **Review** (`--mode review`): reads and reports only.
|
|
220
|
+
- **Assist** (default): the policy above. A tool that asks returns an `approval_id`; a person approves it once with `fairbuild-commitments approve <id> --as "Your Name"` (or on the local approvals page, `fairbuild-commitments approvals`), and the same call is repeated.
|
|
221
|
+
- **Auto** (`--mode auto --auto <tool,...>`): opt-in per tool, with step caps and a kill switch (`fairbuild-commitments kill`). Paying, sending, posting to a ledger or a live system and accepting a learned fact stay **one named click even in Auto**; an approval is tied to the sha256 of the reviewed draft, so a changed draft needs a new click.
|
|
222
|
+
|
|
223
|
+
## CLI
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
fairbuild-commitments tools # every tool, its policy and arguments
|
|
227
|
+
fairbuild-commitments sources # the columns each input is read from
|
|
228
|
+
fairbuild-commitments inspect <file> # how a file would be read (names and shapes, never values)
|
|
229
|
+
fairbuild-commitments call commitments_check '{"commitments":"<commitments>"}'
|
|
230
|
+
fairbuild-commitments eval # the private eval cases on the fictional fixtures
|
|
231
|
+
fairbuild-commitments demo
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Audit log and data
|
|
235
|
+
|
|
236
|
+
Every call is written to `.fairbuild/audit.jsonl` under the root: hash-chained JSON lines, with arguments stored as a hash, signed with an Ed25519 key when you configure one. Everything runs on your machine on files you choose. No network calls, no telemetry, no credentials. The bundled fixtures are fictional.
|
|
237
|
+
|
|
238
|
+
<!-- generated:end -->
|
|
239
|
+
|
|
240
|
+
## Limits
|
|
241
|
+
|
|
242
|
+
- Reads only the files you give it. It does not log in to your accounting system, project management system, bank, surety, insurer or any government portal.
|
|
243
|
+
- Thresholds, percentages, rates and dates come from the settings file you supply; the defaults it used are listed in the result.
|
|
244
|
+
- Not legal, tax, lien, insurance, surety or accounting advice. A person decides what to bill, pay, hold, send or file.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { main } from 'fairbuild-core';
|
|
4
|
+
import { manifest } from '../src/manifest.js';
|
|
5
|
+
import { demo } from '../src/demo.js';
|
|
6
|
+
|
|
7
|
+
main(manifest, { bin: 'fairbuild-commitments', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
|
package/evals/cases.json
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
{
|
|
2
|
+
"suite": "fairbuild-commitments",
|
|
3
|
+
"root": "..",
|
|
4
|
+
"data_note": "Fictional jobs, vendors and commitments in ../fixtures. Deterministic checks; no model is called.",
|
|
5
|
+
"cases": [
|
|
6
|
+
{
|
|
7
|
+
"id": "check-totals",
|
|
8
|
+
"tool": "commitments_check",
|
|
9
|
+
"args": {
|
|
10
|
+
"commitments": "fixtures/commitments.csv",
|
|
11
|
+
"invoices": "fixtures/invoices.csv",
|
|
12
|
+
"settings": "fixtures/settings.json",
|
|
13
|
+
"as_of": "2026-11-16"
|
|
14
|
+
},
|
|
15
|
+
"expect": {
|
|
16
|
+
"status": "executed",
|
|
17
|
+
"equals": {
|
|
18
|
+
"result.commitments": 8,
|
|
19
|
+
"result.revised": 558500,
|
|
20
|
+
"result.invoiced": 363900,
|
|
21
|
+
"result.open_balance": 208500,
|
|
22
|
+
"result.over": 2,
|
|
23
|
+
"result.review": 5,
|
|
24
|
+
"result.unmatched": 1,
|
|
25
|
+
"result.ok": 1,
|
|
26
|
+
"result.over_invoiced": 16400,
|
|
27
|
+
"result.overpaid": 1000,
|
|
28
|
+
"result.unmatched_invoices": 8800
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "every-planted-issue",
|
|
34
|
+
"tool": "commitments_check",
|
|
35
|
+
"args": {
|
|
36
|
+
"commitments": "fixtures/commitments.csv",
|
|
37
|
+
"invoices": "fixtures/invoices.csv",
|
|
38
|
+
"settings": "fixtures/settings.json",
|
|
39
|
+
"as_of": "2026-11-16"
|
|
40
|
+
},
|
|
41
|
+
"expect": {
|
|
42
|
+
"contains": [
|
|
43
|
+
"over_invoiced",
|
|
44
|
+
"paid_over_invoiced",
|
|
45
|
+
"not_executed",
|
|
46
|
+
"invoiced_does_not_tie",
|
|
47
|
+
"retainage_off",
|
|
48
|
+
"closed_with_balance",
|
|
49
|
+
"stale_open",
|
|
50
|
+
"unknown_commitment",
|
|
51
|
+
"revised_math"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"id": "explain-lumber-po",
|
|
57
|
+
"tool": "commitments_explain",
|
|
58
|
+
"args": {
|
|
59
|
+
"commitments": "fixtures/commitments.csv",
|
|
60
|
+
"invoices": "fixtures/invoices.csv",
|
|
61
|
+
"as_of": "2026-11-16",
|
|
62
|
+
"commitment": "PO-201"
|
|
63
|
+
},
|
|
64
|
+
"expect": {
|
|
65
|
+
"status": "executed",
|
|
66
|
+
"contains": [
|
|
67
|
+
"Invoiced 25400 is more than the commitment's value 9000 by 16400"
|
|
68
|
+
],
|
|
69
|
+
"equals": {
|
|
70
|
+
"result.item.status": "over",
|
|
71
|
+
"result.item.open": 0
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": "roofing-retainage-rate",
|
|
77
|
+
"tool": "commitments_explain",
|
|
78
|
+
"args": {
|
|
79
|
+
"commitments": "fixtures/commitments.csv",
|
|
80
|
+
"invoices": "fixtures/invoices.csv",
|
|
81
|
+
"as_of": "2026-11-16",
|
|
82
|
+
"commitment": "SC-104"
|
|
83
|
+
},
|
|
84
|
+
"expect": {
|
|
85
|
+
"contains": [
|
|
86
|
+
"Retainage held is 13500; 10% of 150000 invoiced is 15000"
|
|
87
|
+
],
|
|
88
|
+
"equals": {
|
|
89
|
+
"result.item.findings.0.amount": 1500
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "stale-days-setting",
|
|
95
|
+
"tool": "commitments_check",
|
|
96
|
+
"args": {
|
|
97
|
+
"commitments": "fixtures/commitments.csv",
|
|
98
|
+
"invoices": "fixtures/invoices.csv",
|
|
99
|
+
"as_of": "2026-11-16",
|
|
100
|
+
"settings": "fixtures/settings-lenient.json"
|
|
101
|
+
},
|
|
102
|
+
"expect": {
|
|
103
|
+
"equals": {
|
|
104
|
+
"result.review": 4,
|
|
105
|
+
"result.settings_used.stale_days": 365
|
|
106
|
+
},
|
|
107
|
+
"not_contains": [
|
|
108
|
+
"stale_open"
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"id": "commitments-alone",
|
|
114
|
+
"tool": "commitments_check",
|
|
115
|
+
"args": {
|
|
116
|
+
"commitments": "fixtures/commitments.csv",
|
|
117
|
+
"as_of": "2026-11-16"
|
|
118
|
+
},
|
|
119
|
+
"expect": {
|
|
120
|
+
"equals": {
|
|
121
|
+
"result.invoiced": 360900,
|
|
122
|
+
"result.unmatched": 0,
|
|
123
|
+
"result.over": 2,
|
|
124
|
+
"result.overpaid": 4000
|
|
125
|
+
},
|
|
126
|
+
"not_contains": [
|
|
127
|
+
"invoiced_does_not_tie"
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "procore-commitments-export",
|
|
133
|
+
"tool": "commitments_check",
|
|
134
|
+
"args": {
|
|
135
|
+
"commitments": "fixtures/exports/procore-commitments.csv",
|
|
136
|
+
"as_of": "2026-11-16"
|
|
137
|
+
},
|
|
138
|
+
"expect": {
|
|
139
|
+
"equals": {
|
|
140
|
+
"result.commitments": 3,
|
|
141
|
+
"result.review": 2,
|
|
142
|
+
"result.ok": 1
|
|
143
|
+
},
|
|
144
|
+
"contains": [
|
|
145
|
+
"procore_commitments",
|
|
146
|
+
"not_executed"
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"id": "settings-typo-is-named",
|
|
152
|
+
"tool": "commitments_check",
|
|
153
|
+
"args": {
|
|
154
|
+
"commitments": "fixtures/commitments.csv",
|
|
155
|
+
"settings": "fixtures/settings-typo.json"
|
|
156
|
+
},
|
|
157
|
+
"expect": {
|
|
158
|
+
"status": "error",
|
|
159
|
+
"contains": [
|
|
160
|
+
"commitment_settings"
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"id": "write-report-writes-files",
|
|
166
|
+
"tool": "commitments_write_report",
|
|
167
|
+
"args": {
|
|
168
|
+
"commitments": "fixtures/commitments.csv",
|
|
169
|
+
"invoices": "fixtures/invoices.csv",
|
|
170
|
+
"as_of": "2026-11-16"
|
|
171
|
+
},
|
|
172
|
+
"expect": {
|
|
173
|
+
"status": "executed",
|
|
174
|
+
"length": {
|
|
175
|
+
"result.files": 2
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"id": "draft-letter",
|
|
181
|
+
"tool": "commitments_draft_letter",
|
|
182
|
+
"mode": "auto",
|
|
183
|
+
"auto_actions": [
|
|
184
|
+
"commitments_draft_letter"
|
|
185
|
+
],
|
|
186
|
+
"args": {
|
|
187
|
+
"commitments": "fixtures/commitments.csv",
|
|
188
|
+
"invoices": "fixtures/invoices.csv",
|
|
189
|
+
"as_of": "2026-11-16",
|
|
190
|
+
"vendor": "Sample Lumber Supply"
|
|
191
|
+
},
|
|
192
|
+
"expect": {
|
|
193
|
+
"status": "executed",
|
|
194
|
+
"equals": {
|
|
195
|
+
"result.id": "Sample Lumber Supply",
|
|
196
|
+
"result.commitments": 1
|
|
197
|
+
},
|
|
198
|
+
"contains": [
|
|
199
|
+
"Nothing was sent"
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"id": "draft-letter-clean-vendor",
|
|
205
|
+
"tool": "commitments_draft_letter",
|
|
206
|
+
"mode": "auto",
|
|
207
|
+
"auto_actions": [
|
|
208
|
+
"commitments_draft_letter"
|
|
209
|
+
],
|
|
210
|
+
"args": {
|
|
211
|
+
"commitments": "fixtures/commitments.csv",
|
|
212
|
+
"invoices": "fixtures/invoices.csv",
|
|
213
|
+
"as_of": "2026-11-16",
|
|
214
|
+
"vendor": "Example Concrete LLC"
|
|
215
|
+
},
|
|
216
|
+
"expect": {
|
|
217
|
+
"status": "error",
|
|
218
|
+
"contains": [
|
|
219
|
+
"nothing to ask"
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"id": "policy-invented-tool",
|
|
225
|
+
"tool": "commitments_pay_everything_now",
|
|
226
|
+
"args": {},
|
|
227
|
+
"expect": {
|
|
228
|
+
"status": "blocked"
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"id": "policy-file-outside-root",
|
|
233
|
+
"tool": "commitments_check",
|
|
234
|
+
"args": {
|
|
235
|
+
"commitments": "../../../outside-the-root.csv",
|
|
236
|
+
"invoices": "fixtures/invoices.csv",
|
|
237
|
+
"settings": "fixtures/settings.json",
|
|
238
|
+
"as_of": "2026-11-16"
|
|
239
|
+
},
|
|
240
|
+
"expect": {
|
|
241
|
+
"status": "error",
|
|
242
|
+
"contains": [
|
|
243
|
+
"outside"
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"id": "policy-missing-argument-named",
|
|
249
|
+
"tool": "commitments_check",
|
|
250
|
+
"args": {},
|
|
251
|
+
"expect": {
|
|
252
|
+
"status": "error",
|
|
253
|
+
"contains": [
|
|
254
|
+
"commitments"
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"id": "policy-review-mode-still-reads",
|
|
260
|
+
"tool": "commitments_check",
|
|
261
|
+
"mode": "review",
|
|
262
|
+
"args": {
|
|
263
|
+
"commitments": "fixtures/commitments.csv",
|
|
264
|
+
"invoices": "fixtures/invoices.csv",
|
|
265
|
+
"settings": "fixtures/settings.json",
|
|
266
|
+
"as_of": "2026-11-16"
|
|
267
|
+
},
|
|
268
|
+
"expect": {
|
|
269
|
+
"status": "executed"
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"id": "policy-review-mode-still-reports",
|
|
274
|
+
"tool": "commitments_write_report",
|
|
275
|
+
"mode": "review",
|
|
276
|
+
"args": {
|
|
277
|
+
"commitments": "fixtures/commitments.csv",
|
|
278
|
+
"invoices": "fixtures/invoices.csv",
|
|
279
|
+
"as_of": "2026-11-16"
|
|
280
|
+
},
|
|
281
|
+
"expect": {
|
|
282
|
+
"status": "executed"
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
"id": "policy-review-mode-blocks-draft",
|
|
287
|
+
"tool": "commitments_draft_letter",
|
|
288
|
+
"mode": "review",
|
|
289
|
+
"args": {
|
|
290
|
+
"commitments": "fixtures/commitments.csv",
|
|
291
|
+
"invoices": "fixtures/invoices.csv",
|
|
292
|
+
"as_of": "2026-11-16",
|
|
293
|
+
"vendor": "Sample Lumber Supply"
|
|
294
|
+
},
|
|
295
|
+
"expect": {
|
|
296
|
+
"status": "blocked"
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"id": "policy-commitments-request-send-one-click-in-auto",
|
|
301
|
+
"tool": "commitments_request_send",
|
|
302
|
+
"mode": "auto",
|
|
303
|
+
"args": {
|
|
304
|
+
"draft": "fairbuild-out/drafts/example.md",
|
|
305
|
+
"draft_sha256": "0000000000000000000000000000000000000000000000000000000000000000"
|
|
306
|
+
},
|
|
307
|
+
"expect": {
|
|
308
|
+
"status": "needs_approval"
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"id": "policy-refuses-po-close",
|
|
313
|
+
"tool": "po_close",
|
|
314
|
+
"args": {},
|
|
315
|
+
"expect": {
|
|
316
|
+
"status": "blocked"
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
"id": "policy-refuses-po-change",
|
|
321
|
+
"tool": "po_change",
|
|
322
|
+
"args": {},
|
|
323
|
+
"expect": {
|
|
324
|
+
"status": "blocked"
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
"id": "policy-refuses-ap-pay-invoice",
|
|
329
|
+
"tool": "ap_pay_invoice",
|
|
330
|
+
"args": {},
|
|
331
|
+
"expect": {
|
|
332
|
+
"status": "blocked"
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
"id": "policy-refuses-email-send",
|
|
337
|
+
"tool": "email_send",
|
|
338
|
+
"args": {},
|
|
339
|
+
"expect": {
|
|
340
|
+
"status": "blocked"
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
"id": "intl-de-check-totals",
|
|
345
|
+
"tool": "commitments_check",
|
|
346
|
+
"args": {
|
|
347
|
+
"commitments": "fixtures/intl/de/commitments.csv",
|
|
348
|
+
"invoices": "fixtures/intl/de/invoices.csv",
|
|
349
|
+
"settings": "fixtures/settings.json",
|
|
350
|
+
"as_of": "2026-11-16"
|
|
351
|
+
},
|
|
352
|
+
"expect": {
|
|
353
|
+
"status": "executed",
|
|
354
|
+
"equals": {
|
|
355
|
+
"result.commitments": 8,
|
|
356
|
+
"result.revised": 558500,
|
|
357
|
+
"result.invoiced": 363900,
|
|
358
|
+
"result.open_balance": 208500,
|
|
359
|
+
"result.over": 2,
|
|
360
|
+
"result.review": 5,
|
|
361
|
+
"result.unmatched": 1,
|
|
362
|
+
"result.ok": 1,
|
|
363
|
+
"result.over_invoiced": 16400,
|
|
364
|
+
"result.overpaid": 1000,
|
|
365
|
+
"result.unmatched_invoices": 8800
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
"note": "German export of the same data (fixtures/intl/de); must match the English case \"check-totals\"."
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
"id": "intl-ja-check-totals",
|
|
372
|
+
"tool": "commitments_check",
|
|
373
|
+
"args": {
|
|
374
|
+
"commitments": "fixtures/intl/ja/commitments.csv",
|
|
375
|
+
"invoices": "fixtures/intl/ja/invoices.csv",
|
|
376
|
+
"settings": "fixtures/settings.json",
|
|
377
|
+
"as_of": "2026-11-16"
|
|
378
|
+
},
|
|
379
|
+
"expect": {
|
|
380
|
+
"status": "executed",
|
|
381
|
+
"equals": {
|
|
382
|
+
"result.commitments": 8,
|
|
383
|
+
"result.revised": 558500,
|
|
384
|
+
"result.invoiced": 363900,
|
|
385
|
+
"result.open_balance": 208500,
|
|
386
|
+
"result.over": 2,
|
|
387
|
+
"result.review": 5,
|
|
388
|
+
"result.unmatched": 1,
|
|
389
|
+
"result.ok": 1,
|
|
390
|
+
"result.over_invoiced": 16400,
|
|
391
|
+
"result.overpaid": 1000,
|
|
392
|
+
"result.unmatched_invoices": 8800
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
"note": "Japanese export of the same data (fixtures/intl/ja); must match the English case \"check-totals\"."
|
|
396
|
+
}
|
|
397
|
+
]
|
|
398
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Fairbuild Commitments fixtures
|
|
2
|
+
|
|
3
|
+
Everything here is fictional: jobs 24-101 and 24-102, vendors (Example Concrete LLC, Test Drywall Co, Example Electric Inc, Sample Lumber Supply, Sample Rebar Co, Example Roofing LLC, Sample Sheet Metal, Sample Painting Co, Example Glazing LLC) and amounts.
|
|
4
|
+
|
|
5
|
+
- `commitments.csv`: eight subcontracts and POs, planted with: a drywall subcontract billed but not signed (SC-102), an electrical subcontract whose revised amount does not add up (SC-103), a lumber PO invoiced 16,400 past its value (PO-201), a rebar PO open with no invoice since April (PO-202), roofing retainage held at the wrong rate (SC-104), a closed PO with 2,500 not invoiced (PO-203), a painting subcontract paid 1,000 more than invoiced and whose invoiced column does not tie (SC-105). SC-101 is clean.
|
|
6
|
+
- `invoices.csv`: the AP invoices behind them, plus EX-77 naming a commitment that does not exist.
|
|
7
|
+
- `exports/procore-commitments.csv`: three of the subcontracts as a Procore commitments export.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
commitment,commitment_type,job,vendor,cost_code,description,date,status,original_amount,approved_changes,revised_amount,invoiced,paid,retainage_held,retainage_pct,executed
|
|
2
|
+
SC-101,Subcontract,24-101,Example Concrete LLC,03-300,Cast-in-place concrete,2026-06-01,Open,120000,11500,131500,96000,86400,9600,10,Yes
|
|
3
|
+
SC-102,Subcontract,24-101,Test Drywall Co,09-250,Drywall and framing,2026-08-15,Open,64000,0,64000,18000,0,1800,10,No
|
|
4
|
+
SC-103,Subcontract,24-101,Example Electric Inc,26-000,Electrical,2026-06-10,Open,85000,5000,92000,45000,40500,4500,10,Yes
|
|
5
|
+
PO-201,Purchase order,24-101,Sample Lumber Supply,06-100,Framing lumber,2026-09-01,Open,9000,0,9000,25400,25400,0,0,Yes
|
|
6
|
+
PO-202,Purchase order,24-102,Sample Rebar Co,03-200,Rebar,2026-03-02,Open,15000,0,15000,11000,11000,0,0,Yes
|
|
7
|
+
SC-104,Subcontract,24-102,Example Roofing LLC,07-500,Membrane roofing,2026-05-01,Open,205000,0,205000,150000,135000,13500,10,Yes
|
|
8
|
+
PO-203,Purchase order,24-102,Sample Sheet Metal,07-600,Flashing,2026-07-01,Closed,12000,0,12000,9500,9500,0,0,Yes
|
|
9
|
+
SC-105,Subcontract,24-102,Sample Painting Co,09-900,Painting,2026-10-01,Open,30000,0,30000,6000,10000,0,0,Yes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
Number,Type,Project Number,Contract Company,Title,Status,Original Contract Amount,Approved Change Orders,Revised Contract Amount,Invoiced,Payments Issued,Retainage,Executed
|
|
2
|
+
SC-101,Subcontract,24-101,Example Concrete LLC,Cast-in-place concrete,Approved,120000,11500,131500,96000,86400,9600,Yes
|
|
3
|
+
SC-102,Subcontract,24-101,Test Drywall Co,Drywall and framing,Draft,64000,0,64000,18000,0,1800,No
|
|
4
|
+
SC-103,Subcontract,24-101,Example Electric Inc,Electrical,Approved,85000,5000,92000,45000,40500,4500,Yes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Fixtures from other countries
|
|
2
|
+
|
|
3
|
+
Generated by `node scripts/make-intl-fixtures.mjs` from the English fixtures one
|
|
4
|
+
folder up. The same fictional data, written the way a local export writes it:
|
|
5
|
+
|
|
6
|
+
- `de/`: German column names, Windows-1252 text, semicolons, comma decimals
|
|
7
|
+
(1.234,56), day-first dotted dates (03.11.2026), kilograms and kilometres.
|
|
8
|
+
- `ja/`: Japanese column names, Shift_JIS text, year-first dates (2026/11/03),
|
|
9
|
+
kilograms and kilometres.
|
|
10
|
+
|
|
11
|
+
Values (names, codes, charge wording) stay in English. The eval cases
|
|
12
|
+
`intl-de-*` and `intl-ja-*` expect exactly the same results as the English case.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Auftragsnummer NU;Vertragsart;Projekt;Lieferant;Leistungsposition;Beschreibung;Datum;Zustand;Urspr�ngliche Auftragssumme;Genehmigte Nachtr�ge;Aktuelle Auftragssumme;Abgerechnet;Bezahlt;Einbehalt;Einbehalt %;Unterschrieben
|
|
2
|
+
SC-101;Subcontract;24-101;Example Concrete LLC;03-300;Cast-in-place concrete;01.06.2026;Open;120.000,00;11.500,00;131.500,00;96.000,00;86.400,00;9.600,00;10;Yes
|
|
3
|
+
SC-102;Subcontract;24-101;Test Drywall Co;09-250;Drywall and framing;15.08.2026;Open;64.000,00;0,00;64.000,00;18.000,00;0,00;1.800,00;10;No
|
|
4
|
+
SC-103;Subcontract;24-101;Example Electric Inc;26-000;Electrical;10.06.2026;Open;85.000,00;5.000,00;92.000,00;45.000,00;40.500,00;4.500,00;10;Yes
|
|
5
|
+
PO-201;Purchase order;24-101;Sample Lumber Supply;06-100;Framing lumber;01.09.2026;Open;9.000,00;0,00;9.000,00;25.400,00;25.400,00;0,00;0;Yes
|
|
6
|
+
PO-202;Purchase order;24-102;Sample Rebar Co;03-200;Rebar;02.03.2026;Open;15.000,00;0,00;15.000,00;11.000,00;11.000,00;0,00;0;Yes
|
|
7
|
+
SC-104;Subcontract;24-102;Example Roofing LLC;07-500;Membrane roofing;01.05.2026;Open;205.000,00;0,00;205.000,00;150.000,00;135.000,00;13.500,00;10;Yes
|
|
8
|
+
PO-203;Purchase order;24-102;Sample Sheet Metal;07-600;Flashing;01.07.2026;Closed;12.000,00;0,00;12.000,00;9.500,00;9.500,00;0,00;0;Yes
|
|
9
|
+
SC-105;Subcontract;24-102;Sample Painting Co;09-900;Painting;01.10.2026;Open;30.000,00;0,00;30.000,00;6.000,00;10.000,00;0,00;0;Yes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Rechnungsnummer;Lieferant;Projekt;Auftragsnummer NU;Rechnungsdatum;Betrag;Einbehalt
|
|
2
|
+
EC-2210;Example Concrete LLC;24-101;SC-101;20.10.2026;56.000,00;5.600,00
|
|
3
|
+
EC-2231;Example Concrete LLC;24-101;SC-101;10.11.2026;40.000,00;4.000,00
|
|
4
|
+
TD-101;Test Drywall Co;24-101;SC-102;12.11.2026;18.000,00;1.800,00
|
|
5
|
+
EE-5501;Example Electric Inc;24-101;SC-103;28.10.2026;45.000,00;4.500,00
|
|
6
|
+
SL-88120;Sample Lumber Supply;24-101;PO-201;12.10.2026;14.400,00;0,00
|
|
7
|
+
SL-88341;Sample Lumber Supply;24-101;PO-201;03.11.2026;11.000,00;0,00
|
|
8
|
+
SR-310;Sample Rebar Co;24-102;PO-202;10.04.2026;11.000,00;0,00
|
|
9
|
+
ER-7001;Example Roofing LLC;24-102;SC-104;07.11.2026;150.000,00;13.500,00
|
|
10
|
+
SM-41;Sample Sheet Metal;24-102;PO-203;20.08.2026;9.500,00;0,00
|
|
11
|
+
SP-12;Sample Painting Co;24-102;SC-105;01.11.2026;6.000,00;0,00
|
|
12
|
+
SP-13;Sample Painting Co;24-102;SC-105;14.11.2026;3.000,00;0,00
|
|
13
|
+
EX-77;Example Glazing LLC;24-102;SC-199;05.11.2026;8.800,00;0,00
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
�����ԍ�,�_��敪,�H���ԍ�,�d����,�H��,�E�v,���t,�X�e�[�^�X,�����_��z,���F�ςݕύX,�ύX��_��z,������,�x����,�ۗ���,�ۗ���,�_�����
|
|
2
|
+
SC-101,Subcontract,24-101,Example Concrete LLC,03-300,Cast-in-place concrete,2026/06/01,Open,"120,000.00","11,500.00","131,500.00","96,000.00","86,400.00","9,600.00",10,Yes
|
|
3
|
+
SC-102,Subcontract,24-101,Test Drywall Co,09-250,Drywall and framing,2026/08/15,Open,"64,000.00",0.00,"64,000.00","18,000.00",0.00,"1,800.00",10,No
|
|
4
|
+
SC-103,Subcontract,24-101,Example Electric Inc,26-000,Electrical,2026/06/10,Open,"85,000.00","5,000.00","92,000.00","45,000.00","40,500.00","4,500.00",10,Yes
|
|
5
|
+
PO-201,Purchase order,24-101,Sample Lumber Supply,06-100,Framing lumber,2026/09/01,Open,"9,000.00",0.00,"9,000.00","25,400.00","25,400.00",0.00,0,Yes
|
|
6
|
+
PO-202,Purchase order,24-102,Sample Rebar Co,03-200,Rebar,2026/03/02,Open,"15,000.00",0.00,"15,000.00","11,000.00","11,000.00",0.00,0,Yes
|
|
7
|
+
SC-104,Subcontract,24-102,Example Roofing LLC,07-500,Membrane roofing,2026/05/01,Open,"205,000.00",0.00,"205,000.00","150,000.00","135,000.00","13,500.00",10,Yes
|
|
8
|
+
PO-203,Purchase order,24-102,Sample Sheet Metal,07-600,Flashing,2026/07/01,Closed,"12,000.00",0.00,"12,000.00","9,500.00","9,500.00",0.00,0,Yes
|
|
9
|
+
SC-105,Subcontract,24-102,Sample Painting Co,09-900,Painting,2026/10/01,Open,"30,000.00",0.00,"30,000.00","6,000.00","10,000.00",0.00,0,Yes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
�������ԍ�,�d����,�H���ԍ�,�����ԍ�,������,���z,�ۗ���
|
|
2
|
+
EC-2210,Example Concrete LLC,24-101,SC-101,2026/10/20,"56,000.00","5,600.00"
|
|
3
|
+
EC-2231,Example Concrete LLC,24-101,SC-101,2026/11/10,"40,000.00","4,000.00"
|
|
4
|
+
TD-101,Test Drywall Co,24-101,SC-102,2026/11/12,"18,000.00","1,800.00"
|
|
5
|
+
EE-5501,Example Electric Inc,24-101,SC-103,2026/10/28,"45,000.00","4,500.00"
|
|
6
|
+
SL-88120,Sample Lumber Supply,24-101,PO-201,2026/10/12,"14,400.00",0.00
|
|
7
|
+
SL-88341,Sample Lumber Supply,24-101,PO-201,2026/11/03,"11,000.00",0.00
|
|
8
|
+
SR-310,Sample Rebar Co,24-102,PO-202,2026/04/10,"11,000.00",0.00
|
|
9
|
+
ER-7001,Example Roofing LLC,24-102,SC-104,2026/11/07,"150,000.00","13,500.00"
|
|
10
|
+
SM-41,Sample Sheet Metal,24-102,PO-203,2026/08/20,"9,500.00",0.00
|
|
11
|
+
SP-12,Sample Painting Co,24-102,SC-105,2026/11/01,"6,000.00",0.00
|
|
12
|
+
SP-13,Sample Painting Co,24-102,SC-105,2026/11/14,"3,000.00",0.00
|
|
13
|
+
EX-77,Example Glazing LLC,24-102,SC-199,2026/11/05,"8,800.00",0.00
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
invoice_number,vendor,job,commitment,invoice_date,amount,retainage
|
|
2
|
+
EC-2210,Example Concrete LLC,24-101,SC-101,2026-10-20,56000,5600
|
|
3
|
+
EC-2231,Example Concrete LLC,24-101,SC-101,2026-11-10,40000,4000
|
|
4
|
+
TD-101,Test Drywall Co,24-101,SC-102,2026-11-12,18000,1800
|
|
5
|
+
EE-5501,Example Electric Inc,24-101,SC-103,2026-10-28,45000,4500
|
|
6
|
+
SL-88120,Sample Lumber Supply,24-101,PO-201,2026-10-12,14400,0
|
|
7
|
+
SL-88341,Sample Lumber Supply,24-101,PO-201,2026-11-03,11000,0
|
|
8
|
+
SR-310,Sample Rebar Co,24-102,PO-202,2026-04-10,11000,0
|
|
9
|
+
ER-7001,Example Roofing LLC,24-102,SC-104,2026-11-07,150000,13500
|
|
10
|
+
SM-41,Sample Sheet Metal,24-102,PO-203,2026-08-20,9500,0
|
|
11
|
+
SP-12,Sample Painting Co,24-102,SC-105,2026-11-01,6000,0
|
|
12
|
+
SP-13,Sample Painting Co,24-102,SC-105,2026-11-14,3000,0
|
|
13
|
+
EX-77,Example Glazing LLC,24-102,SC-199,2026-11-05,8800,0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "stale_days": 365 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "stale_after": 90 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "stale_days": 90, "tolerance": 1, "retainage_check": true }
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fairbuild-commitments",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"mcpName": "io.github.fpavia111-creator/fairbuild-commitments",
|
|
5
|
+
"description": "Fairbuild Commitments: subcontracts and purchase orders against invoices and payments: committed cost still open, commitments billed past their value, unsigned subcontracts being billed, stale open POs, closed POs with a balance, retainage held at the wrong rate and invoices that name no commitment. Drafts vendor letters. Never closes or changes a PO.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "Kurt Francisco",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=20"
|
|
11
|
+
},
|
|
12
|
+
"main": "src/index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./src/index.js",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"fairbuild-commitments": "bin/fairbuild-commitments.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"bin",
|
|
23
|
+
"fixtures",
|
|
24
|
+
"evals",
|
|
25
|
+
"README.md",
|
|
26
|
+
"CHANGELOG.md",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"server.json"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node scripts/run-tests.cjs",
|
|
32
|
+
"demo": "node bin/fairbuild-commitments.js demo",
|
|
33
|
+
"eval": "node bin/fairbuild-commitments.js eval"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"fairbuild-core": "^0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/fpavia111-creator/fairbuild-agents.git",
|
|
41
|
+
"directory": "packages/fairbuild-commitments"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/fpavia111-creator/fairbuild-agents/tree/master/packages/fairbuild-commitments#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/fpavia111-creator/fairbuild-agents/issues"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"mcp",
|
|
49
|
+
"mcp-server",
|
|
50
|
+
"construction",
|
|
51
|
+
"contractors",
|
|
52
|
+
"construction-accounting",
|
|
53
|
+
"fairbuild",
|
|
54
|
+
"commitments",
|
|
55
|
+
"subcontracts",
|
|
56
|
+
"purchase-orders"
|
|
57
|
+
]
|
|
58
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.fpavia111-creator/fairbuild-commitments",
|
|
4
|
+
"title": "Fairbuild Commitments",
|
|
5
|
+
"description": "Fairbuild Commitments: subcontracts and purchase orders against invoices and payments: committed…",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "https://github.com/fpavia111-creator/fairbuild-agents",
|
|
9
|
+
"source": "github",
|
|
10
|
+
"subfolder": "packages/fairbuild-commitments"
|
|
11
|
+
},
|
|
12
|
+
"websiteUrl": "https://fair-agents.com/fairbuild.html",
|
|
13
|
+
"packages": [
|
|
14
|
+
{
|
|
15
|
+
"registryType": "npm",
|
|
16
|
+
"identifier": "fairbuild-commitments",
|
|
17
|
+
"version": "0.1.0",
|
|
18
|
+
"transport": {
|
|
19
|
+
"type": "stdio"
|
|
20
|
+
},
|
|
21
|
+
"packageArguments": [
|
|
22
|
+
{
|
|
23
|
+
"type": "positional",
|
|
24
|
+
"value": "mcp"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"type": "named",
|
|
28
|
+
"name": "--root",
|
|
29
|
+
"description": "Folder holding the exports this agent may read and write (it cannot reach outside it)",
|
|
30
|
+
"isRequired": true,
|
|
31
|
+
"format": "filepath",
|
|
32
|
+
"valueHint": "exports_folder"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Fairbuild Commitments: subcontracts and purchase orders against AP invoices and payments. Pure functions, no I/O.
|
|
2
|
+
import { num, str, round2, isoDate, daysBetween, statusOf, readYesNo, partyKey, finding, orderFindings, byFinding, sortBy } from 'fairbuild-core';
|
|
3
|
+
|
|
4
|
+
export const COMMITMENT_SETTINGS_SCHEMA = Object.freeze({
|
|
5
|
+
type: 'object', additionalProperties: false,
|
|
6
|
+
properties: {
|
|
7
|
+
stale_days: { type: 'integer', minimum: 1, maximum: 3650, description: 'An open commitment with no invoice for this many days is flagged to close or confirm (default 90)' },
|
|
8
|
+
tolerance: { type: 'number', minimum: 0, maximum: 1000, description: 'Differences up to this amount are rounding (default 1.00)' },
|
|
9
|
+
retainage_check: { type: 'boolean', description: 'Check retainage held against retainage % times invoiced (default true)' },
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const ORDER = ['revised_math', 'over_invoiced', 'paid_over_invoiced', 'not_executed', 'invoiced_does_not_tie', 'retainage_off', 'closed_with_balance', 'stale_open', 'unknown_commitment'];
|
|
13
|
+
const key = (v) => str(v).toUpperCase().replace(/\s+/g, '');
|
|
14
|
+
|
|
15
|
+
export function checkCommitments({ commitmentRows, invoiceRows = null, settings = {}, asOf }) {
|
|
16
|
+
const tol = num(settings.tolerance) ?? 1; const staleDays = num(settings.stale_days) ?? 90; const retCheck = settings.retainage_check !== false;
|
|
17
|
+
const byId = new Map();
|
|
18
|
+
for (const r of commitmentRows) {
|
|
19
|
+
const id = str(r.commitment); if (!id) continue;
|
|
20
|
+
let c = byId.get(key(id));
|
|
21
|
+
if (!c) { c = { commitment: id, type: str(r.commitment_type), job: str(r.job), vendor: str(r.vendor), cost_code: str(r.cost_code), description: str(r.description), date: isoDate(r.date), status_raw: str(r.status), original: 0, changes: null, revised: null, invoiced: null, paid: null, retainage_held: null, retainage_pct: num(r.retainage_pct), executed: readYesNo(r.executed) }; byId.set(key(id), c); }
|
|
22
|
+
const add = (f, v) => { const n = num(v); if (n !== null) c[f] = round2((c[f] || 0) + n); };
|
|
23
|
+
c.original = round2(c.original + (num(r.original_amount) || 0)); add('changes', r.approved_changes); add('revised', r.revised_amount); add('invoiced', r.invoiced); add('paid', r.paid); add('retainage_held', r.retainage_held);
|
|
24
|
+
}
|
|
25
|
+
const inv = new Map(); const orphans = new Map();
|
|
26
|
+
if (invoiceRows) for (const r of invoiceRows) {
|
|
27
|
+
const amt = num(r.amount); if (amt === null) continue;
|
|
28
|
+
const k = key(r.commitment); const c = k ? byId.get(k) : null;
|
|
29
|
+
if (!c) { const ok = `${k}|${partyKey(r.vendor)}`; const o = orphans.get(ok) || { commitment: str(r.commitment) || '(none)', vendor: str(r.vendor), job: str(r.job), amount: 0, invoices: [] }; o.amount = round2(o.amount + amt); o.invoices.push(str(r.invoice_number)); orphans.set(ok, o); continue; }
|
|
30
|
+
const e = inv.get(k) || { amount: 0, retainage: 0, count: 0, last: null };
|
|
31
|
+
e.amount = round2(e.amount + amt); e.retainage = round2(e.retainage + (num(r.retainage) || 0)); e.count++;
|
|
32
|
+
const d = isoDate(r.invoice_date); if (d && (!e.last || d > e.last)) e.last = d;
|
|
33
|
+
inv.set(k, e);
|
|
34
|
+
}
|
|
35
|
+
const items = [];
|
|
36
|
+
for (const [k, c] of byId) {
|
|
37
|
+
const f = [];
|
|
38
|
+
const computed = round2(c.original + (c.changes || 0));
|
|
39
|
+
const revised = c.revised ?? computed;
|
|
40
|
+
if (c.revised !== null && c.changes !== null && Math.abs(c.revised - computed) > tol) f.push(finding('revised_math', c.revised - computed, `Original ${c.original} plus approved changes ${c.changes} is ${computed}; the commitment says ${c.revised}.`));
|
|
41
|
+
const e = inv.get(k);
|
|
42
|
+
const invoiced = e ? e.amount : (c.invoiced ?? 0);
|
|
43
|
+
if (e && c.invoiced !== null && Math.abs(e.amount - c.invoiced) > tol) f.push(finding('invoiced_does_not_tie', null, `AP invoices against ${c.commitment} add up to ${e.amount} (${e.count}); the commitment report shows ${c.invoiced} invoiced.`));
|
|
44
|
+
if (invoiced - revised > tol) f.push(finding('over_invoiced', invoiced - revised, `Invoiced ${invoiced} is more than the commitment's value ${revised} by ${round2(invoiced - revised)}. Look for an unissued change order or a bill coded to the wrong commitment.`));
|
|
45
|
+
if (c.paid !== null && c.paid - invoiced > tol) f.push(finding('paid_over_invoiced', c.paid - invoiced, `Paid ${c.paid} is more than invoiced ${invoiced} by ${round2(c.paid - invoiced)}.`));
|
|
46
|
+
if (c.executed === false && invoiced > tol) f.push(finding('not_executed', null, `${invoiced} has been invoiced against ${c.commitment}, which is not marked executed. Get the signed subcontract or PO before paying more.`));
|
|
47
|
+
const held = c.retainage_held ?? (e ? e.retainage : null);
|
|
48
|
+
if (retCheck && c.retainage_pct !== null && held !== null) { const want = round2(invoiced * c.retainage_pct / 100); if (Math.abs(want - held) > tol) f.push(finding('retainage_off', want - held, `Retainage held is ${held}; ${c.retainage_pct}% of ${invoiced} invoiced is ${want}.`)); }
|
|
49
|
+
const st = statusOf(c.status_raw); const closed = st === 'closed' || st === 'void';
|
|
50
|
+
const open = closed ? 0 : round2(Math.max(0, revised - invoiced));
|
|
51
|
+
if (closed && revised - invoiced > tol) f.push(finding('closed_with_balance', revised - invoiced, `${c.commitment} is ${c.status_raw.toLowerCase()} with ${round2(revised - invoiced)} not invoiced. If the work is finished, reduce the commitment so committed cost is not overstated.`));
|
|
52
|
+
const last = (e && e.last) || c.date; const idle = last && asOf ? daysBetween(last, asOf) : null;
|
|
53
|
+
if (!closed && open > tol && idle !== null && idle > staleDays) f.push(finding('stale_open', null, `${open} is still open on ${c.commitment} with no invoice for ${idle} days (since ${last}). Ask the vendor whether more is coming or close it.`));
|
|
54
|
+
const status = f.some((x) => ['over_invoiced', 'paid_over_invoiced'].includes(x.code)) ? 'over' : f.length ? 'review' : 'ok';
|
|
55
|
+
items.push({ commitment: c.commitment, type: c.type, job: c.job, vendor: c.vendor, cost_code: c.cost_code, description: c.description, revised, invoiced, paid: c.paid, open, retainage_held: held, executed: c.executed, last_invoice: (e && e.last) || null, days_idle: idle, status, findings: orderFindings(f, ORDER) });
|
|
56
|
+
}
|
|
57
|
+
for (const o of orphans.values()) items.push({ commitment: o.commitment, type: '', job: o.job, vendor: o.vendor, cost_code: '', description: '', revised: 0, invoiced: o.amount, paid: null, open: 0, retainage_held: null, executed: null, last_invoice: null, days_idle: null, status: 'unmatched', findings: [finding('unknown_commitment', o.amount, `Invoice(s) ${o.invoices.sort().join(', ')} from ${o.vendor || 'an unnamed vendor'} (${o.amount}) name commitment "${o.commitment}", which is not in the commitment list.`)] });
|
|
58
|
+
const rank = { over: 0, unmatched: 1, review: 2, ok: 3 };
|
|
59
|
+
const sorted = sortBy(items, [(i) => rank[i.status]], ['job', 1], ['commitment', 1]);
|
|
60
|
+
const vendors = {}; const jobs = {};
|
|
61
|
+
for (const i of sorted.filter((x) => x.status !== 'unmatched')) {
|
|
62
|
+
const v = vendors[i.vendor] = vendors[i.vendor] || { commitments: 0, revised: 0, invoiced: 0, open: 0 }; v.commitments++; v.revised = round2(v.revised + i.revised); v.invoiced = round2(v.invoiced + i.invoiced); v.open = round2(v.open + i.open);
|
|
63
|
+
const j = jobs[i.job] = jobs[i.job] || { commitments: 0, revised: 0, invoiced: 0, open: 0 }; j.commitments++; j.revised = round2(j.revised + i.revised); j.invoiced = round2(j.invoiced + i.invoiced); j.open = round2(j.open + i.open);
|
|
64
|
+
}
|
|
65
|
+
const sumCode = (code) => round2(sorted.flatMap((i) => i.findings).filter((x) => x.code === code).reduce((a, x) => a + (x.amount || 0), 0));
|
|
66
|
+
const count = (st) => sorted.filter((i) => i.status === st).length;
|
|
67
|
+
const r = {
|
|
68
|
+
commitments: byId.size, revised: round2([...sorted].filter((i) => i.status !== 'unmatched').reduce((a, i) => a + i.revised, 0)), invoiced: round2(sorted.filter((i) => i.status !== 'unmatched').reduce((a, i) => a + i.invoiced, 0)),
|
|
69
|
+
open_balance: round2(sorted.reduce((a, i) => a + i.open, 0)), over: count('over'), review: count('review'), unmatched: count('unmatched'), ok: count('ok'),
|
|
70
|
+
over_invoiced: sumCode('over_invoiced'), overpaid: sumCode('paid_over_invoiced'), unmatched_invoices: sumCode('unknown_commitment'), as_of: asOf,
|
|
71
|
+
settings_used: { stale_days: staleDays, tolerance: tol, retainage_check: retCheck }, by_vendor: vendors, by_job: jobs, by_finding: byFinding(sorted), items: sorted,
|
|
72
|
+
};
|
|
73
|
+
r.summary = `${r.commitments} commitment(s): ${r.open_balance} still open of ${r.revised} committed. ${r.over} billed or paid past their value (${r.over_invoiced} over-invoiced, ${r.overpaid} overpaid), ${r.review} to review, ${r.unmatched} invoice group(s) naming no commitment (${r.unmatched_invoices}).`;
|
|
74
|
+
return r;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Markdown body of a letter to one vendor about its commitments that need its answer. */
|
|
78
|
+
export function letterText(items, { vendor, from, contact }) {
|
|
79
|
+
const rows = items.filter((i) => i.findings.some((f) => ['over_invoiced', 'not_executed', 'stale_open', 'closed_with_balance', 'unknown_commitment', 'invoiced_does_not_tie'].includes(f.code)));
|
|
80
|
+
const ask = { over_invoiced: 'a credit memo or the change order that covers the extra billing', not_executed: 'the signed subcontract or PO', stale_open: 'whether more will be invoiced, or a final invoice so the commitment can be closed', closed_with_balance: 'confirmation that no more will be invoiced', unknown_commitment: 'the subcontract or PO number these invoices belong to', invoiced_does_not_tie: 'a statement of everything invoiced to date' };
|
|
81
|
+
const L = [`# Commitments: ${vendor}`, '', `**To:** ${contact || '[TO CONFIRM vendor contact]'}`, `**From:** ${from || '[TO CONFIRM your name and company]'}`, '',
|
|
82
|
+
`We are reconciling our subcontracts and purchase orders with ${vendor}. Please reply on each item below.`, '',
|
|
83
|
+
'| Commitment | Job | Value | Invoiced | What we need from you |', '| --- | --- | --- | --- | --- |',
|
|
84
|
+
...rows.map((i) => `| ${i.commitment} | ${i.job} | ${i.revised} | ${i.invoiced} | ${[...new Set(i.findings.map((f) => ask[f.code]).filter(Boolean))].join('; ')} |`),
|
|
85
|
+
'', 'Nothing here changes a payment that is already approved. Thank you.'];
|
|
86
|
+
return { text: L.join('\n'), count: rows.length };
|
|
87
|
+
}
|
package/src/demo.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { demoRuntime, printStep } from 'fairbuild-core';
|
|
3
|
+
|
|
4
|
+
export async function demo(manifest) {
|
|
5
|
+
const rt = demoRuntime(manifest, fileURLToPath(new URL('../fixtures', import.meta.url)), { mode: 'auto', autoActions: ['commitments_draft_letter'] });
|
|
6
|
+
process.stdout.write(`Fairbuild Commitments demo (fictional jobs, vendors and commitments) in ${rt.root}, Auto mode on for drafts\n`);
|
|
7
|
+
const f = { commitments: 'commitments.csv', invoices: 'invoices.csv', settings: 'settings.json', as_of: '2026-11-16' };
|
|
8
|
+
const a = await rt.call('commitments_check', f);
|
|
9
|
+
printStep('Check eight subcontracts and POs against the AP invoices', a);
|
|
10
|
+
for (const i of a.result.items) process.stdout.write(` ${i.commitment.padEnd(7)} ${i.vendor.padEnd(22)} ${String(i.revised).padStart(8)} ${String(i.invoiced).padStart(8)} ${i.status.padEnd(9)} ${i.findings.map((x) => x.code).join(', ')}\n`);
|
|
11
|
+
printStep('Explain the lumber PO', await rt.call('commitments_explain', { ...f, commitment: 'PO-201' }));
|
|
12
|
+
printStep('Write the worklist', await rt.call('commitments_write_report', f));
|
|
13
|
+
const d = await rt.call('commitments_draft_letter', { ...f, vendor: 'Sample Lumber Supply', from: 'Dana Example, project accountant (fictional)' });
|
|
14
|
+
printStep('Draft a letter to Sample Lumber Supply (Auto is opted in for drafts here)', d);
|
|
15
|
+
printStep('Approve sending it: one named click, even in Auto', await rt.call('commitments_request_send', { draft: d.result.draft, draft_sha256: d.result.draft_sha256 }));
|
|
16
|
+
printStep('Agent tries to close the PO itself', await rt.call('po_close', {}));
|
|
17
|
+
process.stdout.write(`\nAudit log: ${rt.stateDir}/audit.jsonl\n`);
|
|
18
|
+
}
|
package/src/index.js
ADDED
package/src/manifest.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { defineManifest, MODEL_PIN, COMMITMENT_FIELDS, COMMITMENT_PROFILES, AP_INVOICE_FIELDS, AP_PROFILES, standardTools, draftPair, refusedTools, asOfDate, sameParty } from 'fairbuild-core';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { checkCommitments, letterText, COMMITMENT_SETTINGS_SCHEMA } from './commitments.js';
|
|
4
|
+
|
|
5
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
6
|
+
const OUT = 'fairbuild-out/commitments';
|
|
7
|
+
const props = {
|
|
8
|
+
commitments: { type: 'string', description: 'Subcontracts and purchase orders under --root (CSV, Excel or JSON): number, job, vendor, original amount, approved changes, revised amount, invoiced, paid, retainage, status, executed. Procore and Buildertrend layouts are recognised' },
|
|
9
|
+
invoices: { type: 'string', description: 'Optional AP invoice register with the commitment each invoice is billed against. When given, invoiced to date comes from it and is tied to the commitment report' },
|
|
10
|
+
settings: { type: 'string', description: 'Optional settings JSON (commitment_settings schema): stale_days, tolerance, retainage_check' },
|
|
11
|
+
as_of: { type: 'string', maxLength: 30, description: 'Date the open balances are judged on, YYYY-MM-DD (default today)' },
|
|
12
|
+
};
|
|
13
|
+
const run = (a, ctx) => checkCommitments({ commitmentRows: ctx.records(a.commitments, 'commitments'), invoiceRows: a.invoices ? ctx.records(a.invoices, 'invoices') : null, settings: a.settings ? ctx.readJson(a.settings, 'commitment_settings') : {}, asOf: asOfDate(a.as_of) });
|
|
14
|
+
const std = standardTools({
|
|
15
|
+
prefix: 'commitments', outDir: OUT, props, required: ['commitments'], run,
|
|
16
|
+
check: { title: 'Check commitments and open POs', description: 'Per subcontract and PO: value (original plus approved changes), invoiced, paid and still open; billed or paid past its value; billing on an unsigned commitment; retainage held at the wrong rate; closed with a balance; open with no invoice for a long time; invoices that name no commitment.' },
|
|
17
|
+
explain: { arg: 'commitment', argDoc: 'Commitment number from commitments_check (subcontract or PO)', key: (i) => i.commitment, title: 'Explain one commitment',
|
|
18
|
+
description: 'Show one commitment\'s value, invoiced, paid, open balance and every finding.',
|
|
19
|
+
describe: (i) => `${i.commitment} ${i.vendor} (job ${i.job}): ${i.status}. Value ${i.revised}, invoiced ${i.invoiced}, paid ${i.paid ?? 'n/a'}, open ${i.open}. ${i.findings.map((f) => f.detail).join(' ')}`.trim() },
|
|
20
|
+
report: { base: 'commitments', title: 'Commitments and open purchase orders', description: 'Write the commitments worklist',
|
|
21
|
+
row: (i) => ({ commitment: i.commitment, job: i.job, vendor: i.vendor, cost_code: i.cost_code, revised: i.revised, invoiced: i.invoiced, paid: i.paid ?? '', open_amount: i.open, last_invoice: i.last_invoice || '', status: i.status, findings: i.findings.map((f) => f.code).join(' '), reasons: i.findings.map((f) => f.detail).join(' ') }),
|
|
22
|
+
columns: ['commitment', 'job', 'vendor', 'cost_code', 'revised', 'invoiced', 'paid', 'open_amount', 'last_invoice', 'status', 'findings', 'reasons'],
|
|
23
|
+
htmlColumns: ['commitment', 'job', 'vendor', 'revised', 'invoiced', 'open_amount', 'status', 'reasons'],
|
|
24
|
+
sections: (r) => [
|
|
25
|
+
{ title: 'By vendor', rows: Object.entries(r.by_vendor).map(([vendor, v]) => ({ vendor, ...v })), columns: ['vendor', 'commitments', 'revised', 'invoiced', 'open'] },
|
|
26
|
+
{ title: 'By job', rows: Object.entries(r.by_job).map(([job, v]) => ({ job, ...v })), columns: ['job', 'commitments', 'revised', 'invoiced', 'open'] },
|
|
27
|
+
{ title: 'By finding', rows: Object.entries(r.by_finding).map(([code, v]) => ({ code, ...v })), columns: ['code', 'count', 'amount'] },
|
|
28
|
+
],
|
|
29
|
+
limits: ['files', 'settings', 'advice'] },
|
|
30
|
+
});
|
|
31
|
+
const pair = draftPair({
|
|
32
|
+
prefix: 'commitments', noun: 'letter', verb: 'send', category: 'binding_send', outDir: OUT, actor: 'a person on your team',
|
|
33
|
+
description: 'Write drafts/letter-<vendor>.md: one letter to one vendor listing its commitments that need an answer (a credit or change order for over-billing, the signed subcontract, a final invoice for a stale PO). Marked DRAFT. Sending goes through commitments_request_send (one click).',
|
|
34
|
+
required: ['commitments', 'vendor'],
|
|
35
|
+
args: { ...props, vendor: { type: 'string', maxLength: 200, description: 'Vendor name as it appears in the commitment list' }, contact: { type: 'string', maxLength: 200, description: 'Vendor contact (name or e-mail)' }, from: { type: 'string', maxLength: 200, description: 'Your name and company' } },
|
|
36
|
+
build: (a, ctx) => {
|
|
37
|
+
const r = run(a, ctx); const items = r.items.filter((i) => sameParty(i.vendor, a.vendor));
|
|
38
|
+
if (!items.length) throw new Error(`no commitments for vendor "${a.vendor}"; vendors in the file: ${Object.keys(r.by_vendor).join(', ')}`);
|
|
39
|
+
const l = letterText(items, { ...a, vendor: items[0].vendor });
|
|
40
|
+
if (!l.count) throw new Error(`nothing to ask ${items[0].vendor}: its commitments need no answer from the vendor`);
|
|
41
|
+
return { id: items[0].vendor, to: a.contact || undefined, text: l.text, extra: { commitments: l.count } };
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const refused = refusedTools([
|
|
45
|
+
{ name: 'po_close', category: 'production_deploy', description: 'Fairbuild Commitments never closes or reduces a commitment in your accounting system; a person does after the vendor confirms.' },
|
|
46
|
+
{ name: 'po_change', category: 'production_deploy', description: 'Fairbuild Commitments never issues or changes a subcontract, PO or change order.' },
|
|
47
|
+
{ name: 'ap_pay_invoice', category: 'move_money', description: 'Fairbuild Commitments never pays vendors.' },
|
|
48
|
+
{ name: 'email_send', category: 'binding_send', description: 'Fairbuild Commitments never sends letters; a person sends the approved draft.' },
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
export const manifest = defineManifest({
|
|
52
|
+
name: 'fairbuild-commitments', version: pkg.version,
|
|
53
|
+
description: 'Checks subcontracts and purchase orders against AP invoices and payments: committed cost still open, commitments billed or paid past their value, billing on unsigned subcontracts, retainage held at the wrong rate, closed commitments with a balance, stale open POs and invoices that name no commitment. Drafts vendor letters. Closing or changing a commitment is a person\'s job.',
|
|
54
|
+
model: MODEL_PIN,
|
|
55
|
+
caps: { maxSteps: 60, maxSpendUsd: 0 },
|
|
56
|
+
configSchemas: { commitment_settings: COMMITMENT_SETTINGS_SCHEMA },
|
|
57
|
+
sources: {
|
|
58
|
+
commitments: { label: 'Subcontracts and purchase orders', args: ['commitments'], fields: COMMITMENT_FIELDS, profiles: COMMITMENT_PROFILES },
|
|
59
|
+
invoices: { label: 'AP invoices', args: ['invoices'], fields: AP_INVOICE_FIELDS, profiles: AP_PROFILES },
|
|
60
|
+
},
|
|
61
|
+
prompts: [{
|
|
62
|
+
name: 'commitment_review', title: 'Monthly commitment review',
|
|
63
|
+
description: 'Walks the host model through the commitment review with Fairbuild Commitments.',
|
|
64
|
+
arguments: [{ name: 'commitments', description: 'Commitment list under --root', required: true }, { name: 'invoices', description: 'AP invoice register (optional)', required: false }],
|
|
65
|
+
text: `You are helping a project accountant review subcontracts and POs with fairbuild-commitments. Commitments: {{commitments}}. Invoices: {{invoices}}.
|
|
66
|
+
|
|
67
|
+
Rules: Fairbuild Commitments never closes, changes or pays anything; po_close, po_change, ap_pay_invoice and email_send are blocked.
|
|
68
|
+
|
|
69
|
+
1. Call commitments_check. Lead with commitments billed or paid past their value, then billing on unsigned commitments, then invoices that name no commitment, then stale and closed balances.
|
|
70
|
+
2. Call commitments_explain for any commitment the person asks about.
|
|
71
|
+
3. Call commitments_write_report and share the paths.
|
|
72
|
+
4. Offer commitments_draft_letter per vendor; only when the person asks, call commitments_request_send. It needs one named human click.`,
|
|
73
|
+
}],
|
|
74
|
+
tools: [...std.tools, ...pair.tools, ...refused.tools],
|
|
75
|
+
policy: { rules: [...std.rules, ...pair.rules, ...refused.rules, { tool: '*', decision: 'block', reason: 'Not on the Fairbuild Commitments allowlist.' }] },
|
|
76
|
+
});
|