fairbuild-bonding-capacity 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 ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (unreleased)
4
+
5
+ - First version (Fairbuild ver 1): one job, fictional fixtures, eval cases, contract and domain tests.
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,194 @@
1
- # Temporary Holding Version
1
+ # Fairbuild Bonding Capacity (`fairbuild-bonding-capacity`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Summarises bonding capacity from your job list and the single and aggregate limits your surety gave you: bonded backlog against the aggregate, contracts over the single-job limit, bonded jobs forecast at a loss, and whether the bonded bids you are chasing fit in what is left. Drafts the summary for your broker. Not surety advice; requesting bonds 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-bonding-capacity demo
9
+ npx -y fairbuild-bonding-capacity mcp --root ./exports
10
+ ```
11
+
12
+ ## What it needs
13
+
14
+ | Argument | What to give it |
15
+ |---|---|
16
+ | `jobs` (required) | Job list under --root (CSV, Excel or JSON): job, contract amount, estimated cost, cost to date, bonded yes or no |
17
+ | `limits` (required) | Your bonding limits JSON (bonding_limits schema): single_limit and aggregate_limit from your surety, near_pct, and working capital and net worth to show |
18
+ | `pipeline` | Optional bids you are chasing: bid, amount, bond required |
19
+
20
+ Only `jobs` and `limits` are 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
+ - `bond_request`: Fairbuild Bonding Capacity never requests a bid, performance or payment bond.
27
+ - `surety_submit`: Fairbuild Bonding Capacity never sends financial statements or WIP to a surety or broker.
28
+ - `email_send`: Fairbuild Bonding Capacity never sends the summary; a person sends the approved draft.
29
+
30
+ 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):
31
+
32
+ - `bonding_request_send`: Approve the summary (one click)
33
+
34
+ ## Checks
35
+
36
+ What `bonding_check` flags, each with the first example it finds in the fictional fixtures (the eval cases for `bonding_check`):
37
+
38
+ | Code | Example from the fixtures |
39
+ |---|---|
40
+ | `single_over` | Bonded contract 2600000 is over your single-job limit of 2500000 by 100000. Confirm your surety approved it. |
41
+ | `pipeline_exceeds` | With this bid (and the bonded bids listed before it) bonded backlog would be 4101756.1, 101756.1 over your aggregate limit; 1098243.9 was left. |
42
+ | `near_aggregate` | Bonded backlog 2901756.1 is 72.5% of your aggregate limit of 4000000; 1098243.9 left. |
43
+ | `bonded_loss` | Bonded job forecast at a loss of 14000. Sureties watch loss jobs; expect questions. |
44
+
45
+ <!-- generated:start -->
46
+
47
+ ## A demo run
48
+
49
+ `npx -y fairbuild-bonding-capacity demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
50
+
51
+ ```text
52
+ Fairbuild Bonding Capacity demo (fictional jobs, limits and bids), Auto mode on for drafts
53
+
54
+ ▶ Summarise bonding capacity
55
+ status: executed decision: allow
56
+ Bonded backlog 2901756.1 on 4 job(s) is 72.5% of your 4000000 aggregate limit (1098243.9 left). 1 over a limit, 2 bid(s) that would not fit, 2 to review.
57
+ job 24-301 bonded 2600000 over single_over
58
+ bid Example Library Annex bonded 1200000 exceeds pipeline_exceeds
59
+ bid Test Fire Station bonded 600000 exceeds pipeline_exceeds
60
+ program PROGRAM bonded 2901756.1 review near_aggregate
61
+ job 24-103 bonded 50000 review bonded_loss
62
+ job 24-101 bonded 182000 ok
63
+ job 24-102 bonded 69756.1 ok
64
+ job 24-104 225000 ok
65
+ job 24-105 15000 ok
66
+ bid Sample Parking Garage 900000 ok
67
+
68
+ ▶ Explain the Example Library Annex bid
69
+ status: executed decision: allow
70
+ bid Example Library Annex: exceeds. Bonded, contract 1200000, backlog 1200000. With this bid (and the bonded bids listed before it) bonded backlog would be 4101756.1, 101756.1 over your aggregate limit; 1098243.9 was left.
71
+
72
+ ▶ Write the summary
73
+ status: executed decision: allow
74
+ Worklist written: Bonded backlog 2901756.1 on 4 job(s) is 72.5% of your 4000000 aggregate limit (1098243.9 left). 1 over a limit, 2 bid(s) that would not fit, 2 to review.
75
+
76
+ ▶ Draft the broker summary (Auto is opted in for drafts here)
77
+ status: executed decision: allow (auto)
78
+ summary Q4 2026 drafted with 3 open marker(s) ([TO CONFIRM surety broker], [TO CONFIRM your name and company], [ATTACH]). Nothing was sent.
79
+
80
+ ▶ Approve sending it: one named click, even in Auto
81
+ status: needs_approval decision: ask
82
+ reason: binding_send stays one-click, even in Auto
83
+
84
+ ▶ Agent tries to request a bond itself
85
+ status: blocked decision: block
86
+ reason: Fairbuild Bonding Capacity never requests a bid, performance or payment bond.
87
+
88
+ Audit log: <demo folder>
89
+ ```
90
+
91
+ ## Tools
92
+
93
+ | Tool | What it does | Policy |
94
+ |---|---|---|
95
+ | `bonding_check` | Backlog per job by cost to cost; bonded backlog against your aggregate limit; bonded contracts over your single-job limit; bonded jobs forecast at a loss; and, for the bids you list, whether each bonded bid still fits… | runs |
96
+ | `bonding_explain` | Show one job, bid or the program with every finding. | runs |
97
+ | `bonding_write_report` | Write the bonding summary as bonding-capacity.csv (one row per item, blank decision columns for people to fill in) and bonding-capacity.html into out_dir (default fairbuild-out/bonding-capacity). | runs |
98
+ | `bonding_draft_summary` | Write drafts/summary-<label>.md: the bonding capacity summary for your surety broker, with [ATTACH] for the financials and WIP. | asks first (Auto can be opted in) |
99
+ | `bonding_request_send` | After one named human click (even in Auto), record that the reviewed summary draft is approved in summary-requests.csv. | one named click, even in Auto (`binding_send`) |
100
+ | `bond_request` | Fairbuild Bonding Capacity never requests a bid, performance or payment bond. | refused |
101
+ | `surety_submit` | Fairbuild Bonding Capacity never sends financial statements or WIP to a surety or broker. | refused |
102
+ | `email_send` | Fairbuild Bonding Capacity never sends the summary; a person sends the approved draft. | refused |
103
+
104
+ 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.
105
+
106
+ ## Columns it reads
107
+
108
+ 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.
109
+
110
+ ### Jobs and bonding (`jobs`)
111
+
112
+ | Column | Type | Also read as | For example, in other languages |
113
+ |---|---|---|---|
114
+ | `job` (required) | text | Job, Job Number, Project, Project Number | Projekt, Chantier, 工事番号, 项目编号 |
115
+ | `job_name` | text | Job Name, Project Name | Projektname, Nom du chantier, 工事名, 项目名称 |
116
+ | `contract_amount` | amount | Contract Amount, Revised Contract, Contract Value | Auftragssumme, Montant du marché, 請負金額, 合同金额 |
117
+ | `estimated_cost` | amount | Estimated Cost, Revised Estimated Cost, EAC | Kalkulierte Kosten, Coût prévisionnel, 実行予算, 预计总成本 |
118
+ | `cost_to_date` | amount | Cost to Date, JTD Cost, Actual Cost | Ist-Kosten, Réalisé, 実績, 实际成本 |
119
+ | `bonded` | yes/no | Bonded, Bond, P&P Bond, Performance Bond | Bürgschaft, Caution, 履行保証, 履约保函 |
120
+
121
+ ### Bids being chased (`pipeline`)
122
+
123
+ | Column | Type | Also read as | For example, in other languages |
124
+ |---|---|---|---|
125
+ | `bid` (required) | text | Bid, Bid Name, Project, Opportunity, Job Name | - |
126
+ | `amount` | amount | Amount, Bid Amount, Contract Amount, Value | Betrag, Montant, 金額, 金额 |
127
+ | `bond_required` | yes/no | Bond Required, Bonded, Bond | - |
128
+
129
+ ### Files from other countries
130
+
131
+ 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-bonding-capacity inspect <file>` (names and shapes only, never values) and name them in `fairbuild-sources.json`:
132
+
133
+ ```json
134
+ { "files": { "exports/bills.csv": { "columns": { "invoice_number": "Beleg" }, "date_order": "dmy" } } }
135
+ ```
136
+
137
+ ## Install
138
+
139
+ Node 20 or newer. No other dependencies.
140
+
141
+ ```bash
142
+ npx -y fairbuild-bonding-capacity demo
143
+ npx -y fairbuild-bonding-capacity mcp --root /path/to/your/files
144
+ ```
145
+
146
+ Claude Desktop, Cursor and other MCP hosts:
147
+
148
+ ```json
149
+ {
150
+ "mcpServers": {
151
+ "fairbuild-bonding-capacity": {
152
+ "command": "npx",
153
+ "args": [
154
+ "-y",
155
+ "fairbuild-bonding-capacity",
156
+ "mcp",
157
+ "--root",
158
+ "/path/to/your/files"
159
+ ]
160
+ }
161
+ }
162
+ }
163
+ ```
164
+
165
+ Claude Code: `claude mcp add fairbuild-bonding-capacity -- npx -y fairbuild-bonding-capacity mcp --root .`, or install the `fairbuild-bonding-capacity` plugin from this repository's marketplace.
166
+
167
+ ## Modes and approvals
168
+
169
+ - **Review** (`--mode review`): reads and reports only.
170
+ - **Assist** (default): the policy above. A tool that asks returns an `approval_id`; a person approves it once with `fairbuild-bonding-capacity approve <id> --as "Your Name"` (or on the local approvals page, `fairbuild-bonding-capacity approvals`), and the same call is repeated.
171
+ - **Auto** (`--mode auto --auto <tool,...>`): opt-in per tool, with step caps and a kill switch (`fairbuild-bonding-capacity 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.
172
+
173
+ ## CLI
174
+
175
+ ```bash
176
+ fairbuild-bonding-capacity tools # every tool, its policy and arguments
177
+ fairbuild-bonding-capacity sources # the columns each input is read from
178
+ fairbuild-bonding-capacity inspect <file> # how a file would be read (names and shapes, never values)
179
+ fairbuild-bonding-capacity call bonding_check '{"jobs":"<jobs>","limits":"<limits>"}'
180
+ fairbuild-bonding-capacity eval # the private eval cases on the fictional fixtures
181
+ fairbuild-bonding-capacity demo
182
+ ```
183
+
184
+ ## Audit log and data
185
+
186
+ 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.
187
+
188
+ <!-- generated:end -->
189
+
190
+ ## Limits
191
+
192
+ - The limits are the ones you supply from your surety. Fairbuild Bonding Capacity does not estimate bonding capacity or predict what a surety will approve.
193
+ - 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.
194
+ - 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-bonding-capacity', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
@@ -0,0 +1,332 @@
1
+ {
2
+ "suite": "fairbuild-bonding-capacity",
3
+ "root": "..",
4
+ "data_note": "Fictional jobs, made-up limits and bids in ../fixtures. Deterministic checks; no model is called.",
5
+ "cases": [
6
+ {
7
+ "id": "check-totals",
8
+ "tool": "bonding_check",
9
+ "args": {
10
+ "jobs": "fixtures/jobs.csv",
11
+ "limits": "fixtures/limits.json",
12
+ "pipeline": "fixtures/pipeline.csv"
13
+ },
14
+ "expect": {
15
+ "status": "executed",
16
+ "equals": {
17
+ "result.jobs": 6,
18
+ "result.bonded_jobs": 4,
19
+ "result.bonded_backlog": 2901756.1,
20
+ "result.total_backlog": 3141756.1,
21
+ "result.aggregate_used_pct": 72.5,
22
+ "result.aggregate_left": 1098243.9,
23
+ "result.largest_bonded_contract": 2600000,
24
+ "result.bonded_bids": 1800000,
25
+ "result.over": 1,
26
+ "result.exceeds": 2,
27
+ "result.review": 2,
28
+ "result.ok": 5
29
+ }
30
+ }
31
+ },
32
+ {
33
+ "id": "every-planted-issue",
34
+ "tool": "bonding_check",
35
+ "args": {
36
+ "jobs": "fixtures/jobs.csv",
37
+ "limits": "fixtures/limits.json",
38
+ "pipeline": "fixtures/pipeline.csv"
39
+ },
40
+ "expect": {
41
+ "contains": [
42
+ "single_over",
43
+ "bonded_loss",
44
+ "near_aggregate",
45
+ "pipeline_exceeds"
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "id": "explain-bid-that-crosses",
51
+ "tool": "bonding_explain",
52
+ "args": {
53
+ "jobs": "fixtures/jobs.csv",
54
+ "limits": "fixtures/limits.json",
55
+ "pipeline": "fixtures/pipeline.csv",
56
+ "key": "Example Library Annex"
57
+ },
58
+ "expect": {
59
+ "status": "executed",
60
+ "contains": [
61
+ "bonded backlog would be 4101756.1, 101756.1 over your aggregate limit; 1098243.9 was left"
62
+ ],
63
+ "equals": {
64
+ "result.item.findings.0.amount": 101756.1
65
+ }
66
+ }
67
+ },
68
+ {
69
+ "id": "unbonded-bid-not-counted",
70
+ "tool": "bonding_explain",
71
+ "args": {
72
+ "jobs": "fixtures/jobs.csv",
73
+ "limits": "fixtures/limits.json",
74
+ "pipeline": "fixtures/pipeline.csv",
75
+ "key": "Sample Parking Garage"
76
+ },
77
+ "expect": {
78
+ "equals": {
79
+ "result.item.status": "ok",
80
+ "result.item.bonded": false
81
+ }
82
+ }
83
+ },
84
+ {
85
+ "id": "larger-limits",
86
+ "tool": "bonding_check",
87
+ "args": {
88
+ "jobs": "fixtures/jobs.csv",
89
+ "limits": "fixtures/limits-large.json",
90
+ "pipeline": "fixtures/pipeline.csv"
91
+ },
92
+ "expect": {
93
+ "equals": {
94
+ "result.over": 0,
95
+ "result.exceeds": 0,
96
+ "result.review": 1
97
+ },
98
+ "not_contains": [
99
+ "near_aggregate"
100
+ ]
101
+ }
102
+ },
103
+ {
104
+ "id": "jobs-without-pipeline",
105
+ "tool": "bonding_check",
106
+ "args": {
107
+ "jobs": "fixtures/jobs.csv",
108
+ "limits": "fixtures/limits.json"
109
+ },
110
+ "expect": {
111
+ "equals": {
112
+ "result.bonded_bids": 0,
113
+ "result.exceeds": 0
114
+ }
115
+ }
116
+ },
117
+ {
118
+ "id": "limits-schema-error",
119
+ "tool": "bonding_check",
120
+ "args": {
121
+ "jobs": "fixtures/jobs.csv",
122
+ "limits": "fixtures/limits-typo.json"
123
+ },
124
+ "expect": {
125
+ "status": "error",
126
+ "contains": [
127
+ "bonding_limits"
128
+ ]
129
+ }
130
+ },
131
+ {
132
+ "id": "write-report-writes-files",
133
+ "tool": "bonding_write_report",
134
+ "args": {
135
+ "jobs": "fixtures/jobs.csv",
136
+ "limits": "fixtures/limits.json",
137
+ "pipeline": "fixtures/pipeline.csv"
138
+ },
139
+ "expect": {
140
+ "status": "executed",
141
+ "length": {
142
+ "result.files": 2
143
+ }
144
+ }
145
+ },
146
+ {
147
+ "id": "draft-summary",
148
+ "tool": "bonding_draft_summary",
149
+ "mode": "auto",
150
+ "auto_actions": [
151
+ "bonding_draft_summary"
152
+ ],
153
+ "args": {
154
+ "jobs": "fixtures/jobs.csv",
155
+ "limits": "fixtures/limits.json",
156
+ "label": "Q4 2026"
157
+ },
158
+ "expect": {
159
+ "status": "executed",
160
+ "equals": {
161
+ "result.id": "Q4 2026"
162
+ },
163
+ "contains": [
164
+ "Nothing was sent"
165
+ ]
166
+ }
167
+ },
168
+ {
169
+ "id": "policy-invented-tool",
170
+ "tool": "bonding_pay_everything_now",
171
+ "args": {},
172
+ "expect": {
173
+ "status": "blocked"
174
+ }
175
+ },
176
+ {
177
+ "id": "policy-file-outside-root",
178
+ "tool": "bonding_check",
179
+ "args": {
180
+ "jobs": "../../../outside-the-root.csv",
181
+ "limits": "fixtures/limits.json",
182
+ "pipeline": "fixtures/pipeline.csv"
183
+ },
184
+ "expect": {
185
+ "status": "error",
186
+ "contains": [
187
+ "outside"
188
+ ]
189
+ }
190
+ },
191
+ {
192
+ "id": "policy-missing-argument-named",
193
+ "tool": "bonding_check",
194
+ "args": {},
195
+ "expect": {
196
+ "status": "error",
197
+ "contains": [
198
+ "jobs"
199
+ ]
200
+ }
201
+ },
202
+ {
203
+ "id": "policy-review-mode-still-reads",
204
+ "tool": "bonding_check",
205
+ "mode": "review",
206
+ "args": {
207
+ "jobs": "fixtures/jobs.csv",
208
+ "limits": "fixtures/limits.json",
209
+ "pipeline": "fixtures/pipeline.csv"
210
+ },
211
+ "expect": {
212
+ "status": "executed"
213
+ }
214
+ },
215
+ {
216
+ "id": "policy-review-mode-still-reports",
217
+ "tool": "bonding_write_report",
218
+ "mode": "review",
219
+ "args": {
220
+ "jobs": "fixtures/jobs.csv",
221
+ "limits": "fixtures/limits.json",
222
+ "pipeline": "fixtures/pipeline.csv"
223
+ },
224
+ "expect": {
225
+ "status": "executed"
226
+ }
227
+ },
228
+ {
229
+ "id": "policy-review-mode-blocks-draft",
230
+ "tool": "bonding_draft_summary",
231
+ "mode": "review",
232
+ "args": {
233
+ "jobs": "fixtures/jobs.csv",
234
+ "limits": "fixtures/limits.json",
235
+ "label": "Q4 2026"
236
+ },
237
+ "expect": {
238
+ "status": "blocked"
239
+ }
240
+ },
241
+ {
242
+ "id": "policy-bonding-request-send-one-click-in-auto",
243
+ "tool": "bonding_request_send",
244
+ "mode": "auto",
245
+ "args": {
246
+ "draft": "fairbuild-out/drafts/example.md",
247
+ "draft_sha256": "0000000000000000000000000000000000000000000000000000000000000000"
248
+ },
249
+ "expect": {
250
+ "status": "needs_approval"
251
+ }
252
+ },
253
+ {
254
+ "id": "policy-refuses-bond-request",
255
+ "tool": "bond_request",
256
+ "args": {},
257
+ "expect": {
258
+ "status": "blocked"
259
+ }
260
+ },
261
+ {
262
+ "id": "policy-refuses-surety-submit",
263
+ "tool": "surety_submit",
264
+ "args": {},
265
+ "expect": {
266
+ "status": "blocked"
267
+ }
268
+ },
269
+ {
270
+ "id": "policy-refuses-email-send",
271
+ "tool": "email_send",
272
+ "args": {},
273
+ "expect": {
274
+ "status": "blocked"
275
+ }
276
+ },
277
+ {
278
+ "id": "intl-de-check-totals",
279
+ "tool": "bonding_check",
280
+ "args": {
281
+ "jobs": "fixtures/intl/de/jobs.csv",
282
+ "limits": "fixtures/limits.json",
283
+ "pipeline": "fixtures/intl/de/pipeline.csv"
284
+ },
285
+ "expect": {
286
+ "status": "executed",
287
+ "equals": {
288
+ "result.jobs": 6,
289
+ "result.bonded_jobs": 4,
290
+ "result.bonded_backlog": 2901756.1,
291
+ "result.total_backlog": 3141756.1,
292
+ "result.aggregate_used_pct": 72.5,
293
+ "result.aggregate_left": 1098243.9,
294
+ "result.largest_bonded_contract": 2600000,
295
+ "result.bonded_bids": 1800000,
296
+ "result.over": 1,
297
+ "result.exceeds": 2,
298
+ "result.review": 2,
299
+ "result.ok": 5
300
+ }
301
+ },
302
+ "note": "German export of the same data (fixtures/intl/de); must match the English case \"check-totals\"."
303
+ },
304
+ {
305
+ "id": "intl-ja-check-totals",
306
+ "tool": "bonding_check",
307
+ "args": {
308
+ "jobs": "fixtures/intl/ja/jobs.csv",
309
+ "limits": "fixtures/limits.json",
310
+ "pipeline": "fixtures/intl/ja/pipeline.csv"
311
+ },
312
+ "expect": {
313
+ "status": "executed",
314
+ "equals": {
315
+ "result.jobs": 6,
316
+ "result.bonded_jobs": 4,
317
+ "result.bonded_backlog": 2901756.1,
318
+ "result.total_backlog": 3141756.1,
319
+ "result.aggregate_used_pct": 72.5,
320
+ "result.aggregate_left": 1098243.9,
321
+ "result.largest_bonded_contract": 2600000,
322
+ "result.bonded_bids": 1800000,
323
+ "result.over": 1,
324
+ "result.exceeds": 2,
325
+ "result.review": 2,
326
+ "result.ok": 5
327
+ }
328
+ },
329
+ "note": "Japanese export of the same data (fixtures/intl/ja); must match the English case \"check-totals\"."
330
+ }
331
+ ]
332
+ }
@@ -0,0 +1,7 @@
1
+ # Fairbuild Bonding Capacity fixtures
2
+
3
+ Everything here is fictional: jobs, limits, working capital and bids. The limits are made up for the test and are not advice.
4
+
5
+ - `jobs.csv`: six jobs, four bonded. 24-301 is a 2.6 million bonded contract against a 2.5 million single-job limit; 24-103 is a bonded job forecast at a loss.
6
+ - `limits.json`: single 2.5 million, aggregate 4 million, flag at 70% used.
7
+ - `pipeline.csv`: two bonded bids that together would take bonded backlog past the aggregate limit.
@@ -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,7 @@
1
+ Projekt;Projektname;Auftragssumme;Kalkulierte Kosten;Ist-Kosten;B�rgschaft
2
+ 24-101;Example Clinic fit-out;455.000,00;390.000,00;234.000,00;yes
3
+ 24-102;Sample Library roof;260.000,00;205.000,00;150.000,00;yes
4
+ 24-103;Example Clinic annex;200.000,00;214.000,00;160.500,00;yes
5
+ 24-104;Example Warehouse slab;300.000,00;240.000,00;60.000,00;no
6
+ 24-105;Sample Office tenant improvement;90.000,00;66.600,00;55.500,00;no
7
+ 24-301;Example County school addition;2.600.000,00;2.210.000,00;0,00;yes
@@ -0,0 +1,4 @@
1
+ bid;Betrag;bond_required
2
+ Example Library Annex;1.200.000,00;yes
3
+ Sample Parking Garage;900.000,00;no
4
+ Test Fire Station;600.000,00;yes
@@ -0,0 +1,7 @@
1
+ �H���ԍ�,�H����,�������z,���s�\�Z,����,���s�ۏ�
2
+ 24-101,Example Clinic fit-out,"455,000.00","390,000.00","234,000.00",yes
3
+ 24-102,Sample Library roof,"260,000.00","205,000.00","150,000.00",yes
4
+ 24-103,Example Clinic annex,"200,000.00","214,000.00","160,500.00",yes
5
+ 24-104,Example Warehouse slab,"300,000.00","240,000.00","60,000.00",no
6
+ 24-105,Sample Office tenant improvement,"90,000.00","66,600.00","55,500.00",no
7
+ 24-301,Example County school addition,"2,600,000.00","2,210,000.00",0.00,yes
@@ -0,0 +1,4 @@
1
+ bid,���z,bond_required
2
+ Example Library Annex,"1,200,000.00",yes
3
+ Sample Parking Garage,"900,000.00",no
4
+ Test Fire Station,"600,000.00",yes
@@ -0,0 +1,7 @@
1
+ job,job_name,contract_amount,estimated_cost,cost_to_date,bonded
2
+ 24-101,Example Clinic fit-out,455000,390000,234000,yes
3
+ 24-102,Sample Library roof,260000,205000,150000,yes
4
+ 24-103,Example Clinic annex,200000,214000,160500,yes
5
+ 24-104,Example Warehouse slab,300000,240000,60000,no
6
+ 24-105,Sample Office tenant improvement,90000,66600,55500,no
7
+ 24-301,Example County school addition,2600000,2210000,0,yes
@@ -0,0 +1 @@
1
+ { "single_limit": 5000000, "aggregate_limit": 10000000 }
@@ -0,0 +1 @@
1
+ { "single": 2500000 }
@@ -0,0 +1 @@
1
+ { "single_limit": 2500000, "aggregate_limit": 4000000, "near_pct": 70, "working_capital": 380000, "net_worth": 1100000, "as_of": "2026-09-30" }
@@ -0,0 +1,4 @@
1
+ bid,amount,bond_required
2
+ Example Library Annex,1200000,yes
3
+ Sample Parking Garage,900000,no
4
+ Test Fire Station,600000,yes
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "fairbuild-bonding-capacity",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "mcpName": "io.github.fpavia111-creator/fairbuild-bonding-capacity",
5
+ "description": "Fairbuild Bonding Capacity: a bonding capacity summary from your job list and the single and aggregate limits your surety gave you: bonded backlog against the aggregate limit, jobs over the single-job limit, bonded jobs forecast at a loss, and whether the bonded bids you are chasing fit in what is left. Drafts the summary for your surety broker. Never requests a bond or sends financials; not surety advice.",
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-bonding-capacity": "bin/fairbuild-bonding-capacity.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-bonding-capacity.js demo",
33
+ "eval": "node bin/fairbuild-bonding-capacity.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-bonding-capacity"
42
+ },
43
+ "homepage": "https://github.com/fpavia111-creator/fairbuild-agents/tree/master/packages/fairbuild-bonding-capacity#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
+ "bonding-capacity",
55
+ "surety",
56
+ "backlog"
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-bonding-capacity",
4
+ "title": "Fairbuild Bonding Capacity",
5
+ "description": "Fairbuild Bonding Capacity: a bonding capacity summary from your job list and the single and…",
6
+ "version": "0.1.0",
7
+ "repository": {
8
+ "url": "https://github.com/fpavia111-creator/fairbuild-agents",
9
+ "source": "github",
10
+ "subfolder": "packages/fairbuild-bonding-capacity"
11
+ },
12
+ "websiteUrl": "https://fair-agents.com/fairbuild.html",
13
+ "packages": [
14
+ {
15
+ "registryType": "npm",
16
+ "identifier": "fairbuild-bonding-capacity",
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
+ }
package/src/bonding.js ADDED
@@ -0,0 +1,85 @@
1
+ // Fairbuild Bonding Capacity: bonding capacity from the job list and the limits your surety gave you. Pure functions, no I/O.
2
+ //
3
+ // Backlog per job = contract - earned revenue (cost to cost). Bonded backlog counts bonded
4
+ // jobs only and is compared with your aggregate limit; each bonded contract with your
5
+ // single-job limit. Limits are yours to supply; Fairbuild Bonding Capacity does not estimate them.
6
+ import { num, str, round2, pct, readYesNo, finding, orderFindings, byFinding, sortBy } from 'fairbuild-core';
7
+
8
+ const t = (aliases, extra = {}) => ({ aliases, ...extra });
9
+ export const BOND_JOB_FIELDS = Object.freeze({
10
+ job: t(['Job', 'Job Number', 'Project', 'Project Number'], { required: true }),
11
+ job_name: t(['Job Name', 'Project Name']),
12
+ contract_amount: t(['Contract Amount', 'Revised Contract', 'Contract Value'], { type: 'money' }),
13
+ estimated_cost: t(['Estimated Cost', 'Revised Estimated Cost', 'EAC'], { type: 'money' }),
14
+ cost_to_date: t(['Cost to Date', 'JTD Cost', 'Actual Cost'], { type: 'money' }),
15
+ bonded: t(['Bonded', 'Bond', 'P&P Bond', 'Performance Bond'], { type: 'bool' }),
16
+ });
17
+ export const PIPELINE_FIELDS = Object.freeze({
18
+ bid: t(['Bid', 'Bid Name', 'Project', 'Opportunity', 'Job Name'], { required: true }),
19
+ amount: t(['Amount', 'Bid Amount', 'Contract Amount', 'Value'], { type: 'money' }),
20
+ bond_required: t(['Bond Required', 'Bonded', 'Bond'], { type: 'bool' }),
21
+ });
22
+ export const BONDING_SCHEMA = Object.freeze({
23
+ type: 'object', additionalProperties: false, required: ['single_limit', 'aggregate_limit'],
24
+ properties: {
25
+ single_limit: { type: 'number', minimum: 0, description: 'Largest single bonded contract your surety has approved' },
26
+ aggregate_limit: { type: 'number', minimum: 0, description: 'Largest bonded backlog your surety has approved' },
27
+ near_pct: { type: 'number', minimum: 0, maximum: 100, description: 'Bonded backlog above this percent of the aggregate limit is flagged (default 85)' },
28
+ working_capital: { type: 'number', description: 'Working capital from your latest financial statement (shown, not used to compute limits)' },
29
+ net_worth: { type: 'number', description: 'Net worth from your latest financial statement (shown, not used to compute limits)' },
30
+ as_of: { type: 'string', maxLength: 30, description: 'Date of the limits letter or financial statement' },
31
+ },
32
+ });
33
+ const ORDER = ['over_aggregate', 'near_aggregate', 'single_over', 'pipeline_exceeds', 'bonded_loss'];
34
+
35
+ export function checkBonding({ jobRows, limits, pipelineRows = null }) {
36
+ const single = num(limits.single_limit); const aggregate = num(limits.aggregate_limit); const nearPct = num(limits.near_pct) ?? 85;
37
+ const items = []; let bondedBacklog = 0; let totalBacklog = 0;
38
+ for (const j of sortBy(jobRows.filter((x) => str(x.job)), [(x) => str(x.job), 1])) {
39
+ const f = []; const contract = num(j.contract_amount) ?? 0; const est = num(j.estimated_cost); const cost = num(j.cost_to_date) ?? 0; const bonded = readYesNo(j.bonded) === true;
40
+ const pc = est ? Math.min(1, cost / est) : 0; const backlog = round2(contract - contract * pc);
41
+ totalBacklog = round2(totalBacklog + backlog); if (bonded) bondedBacklog = round2(bondedBacklog + backlog);
42
+ if (bonded && single !== null && contract > single) f.push(finding('single_over', contract - single, `Bonded contract ${contract} is over your single-job limit of ${single} by ${round2(contract - single)}. Confirm your surety approved it.`));
43
+ if (bonded && est !== null && est > contract) f.push(finding('bonded_loss', round2(est - contract), `Bonded job forecast at a loss of ${round2(est - contract)}. Sureties watch loss jobs; expect questions.`));
44
+ const c = f.map((x) => x.code);
45
+ items.push({ kind: 'job', key: str(j.job), name: str(j.job_name), bonded, contract_amount: contract, percent_complete: round2(pc * 100), backlog, status: c.includes('single_over') ? 'over' : f.length ? 'review' : 'ok', findings: orderFindings(f, ORDER) });
46
+ }
47
+ const room = aggregate !== null ? round2(aggregate - bondedBacklog) : null; const used = aggregate ? pct(bondedBacklog, aggregate) : null;
48
+ const pf = [];
49
+ if (aggregate !== null && bondedBacklog > aggregate) pf.push(finding('over_aggregate', bondedBacklog - aggregate, `Bonded backlog ${bondedBacklog} is over your aggregate limit of ${aggregate}.`));
50
+ else if (used !== null && used >= nearPct) pf.push(finding('near_aggregate', null, `Bonded backlog ${bondedBacklog} is ${used}% of your aggregate limit of ${aggregate}; ${room} left.`));
51
+ if (pf.length) items.push({ kind: 'program', key: 'PROGRAM', name: 'Bonding program', bonded: true, contract_amount: null, percent_complete: null, backlog: bondedBacklog, status: pf.some((x) => x.code === 'over_aggregate') ? 'over' : 'review', findings: pf });
52
+ let cum = bondedBacklog;
53
+ if (pipelineRows) for (const b of sortBy(pipelineRows.filter((x) => str(x.bid)), [(x) => str(x.bid), 1])) {
54
+ const f = []; const amount = num(b.amount) ?? 0; const need = readYesNo(b.bond_required) === true;
55
+ if (need) {
56
+ if (single !== null && amount > single) f.push(finding('single_over', amount - single, `Bid ${amount} is over your single-job limit of ${single}.`));
57
+ const before = cum; cum = round2(cum + amount);
58
+ if (aggregate !== null && cum > aggregate) f.push(finding('pipeline_exceeds', Math.min(amount, round2(cum - aggregate)), `With this bid (and the bonded bids listed before it) bonded backlog would be ${cum}, ${round2(cum - aggregate)} over your aggregate limit; ${round2(Math.max(0, aggregate - before))} was left.`));
59
+ }
60
+ items.push({ kind: 'bid', key: str(b.bid), name: str(b.bid), bonded: need, contract_amount: amount, percent_complete: 0, backlog: amount, status: f.length ? 'exceeds' : 'ok', findings: orderFindings(f, ORDER) });
61
+ }
62
+ const rank = { over: 0, exceeds: 1, review: 2, ok: 3 };
63
+ const out = sortBy(items, [(i) => rank[i.status]], ['kind', -1], ['key', 1]);
64
+ const count = (st) => out.filter((i) => i.status === st).length;
65
+ const r = {
66
+ jobs: out.filter((i) => i.kind === 'job').length, bonded_jobs: out.filter((i) => i.kind === 'job' && i.bonded).length, total_backlog: totalBacklog, bonded_backlog: bondedBacklog,
67
+ single_limit: single, aggregate_limit: aggregate, aggregate_used_pct: used, aggregate_left: room, largest_bonded_contract: Math.max(0, ...out.filter((i) => i.kind === 'job' && i.bonded).map((i) => i.contract_amount)),
68
+ bonded_bids: round2(out.filter((i) => i.kind === 'bid' && i.bonded).reduce((a, i) => a + i.contract_amount, 0)), working_capital: num(limits.working_capital), net_worth: num(limits.net_worth), limits_as_of: limits.as_of || null,
69
+ over: count('over'), exceeds: count('exceeds'), review: count('review'), ok: count('ok'),
70
+ capacity: [{ single_limit: single, aggregate_limit: aggregate, bonded_backlog: bondedBacklog, aggregate_used_pct: used, aggregate_left: room }],
71
+ by_finding: byFinding(out), items: out,
72
+ };
73
+ r.summary = `Bonded backlog ${bondedBacklog} on ${r.bonded_jobs} job(s) is ${used ?? '?'}% of your ${aggregate ?? '?'} aggregate limit (${room ?? '?'} left). ${r.over} over a limit, ${r.exceeds} bid(s) that would not fit, ${r.review} to review.`;
74
+ return r;
75
+ }
76
+
77
+ /** Markdown body of the bonding summary for your surety broker. */
78
+ export function summaryText(r, { to, from }) {
79
+ const L = ['# Bonding capacity summary', '', `**To:** ${to || '[TO CONFIRM surety broker]'}`, `**From:** ${from || '[TO CONFIRM your name and company]'}`, '',
80
+ `Bonded backlog: ${r.bonded_backlog} on ${r.bonded_jobs} job(s); total backlog ${r.total_backlog}. Aggregate limit ${r.aggregate_limit}, single-job limit ${r.single_limit}${r.limits_as_of ? ` (as of ${r.limits_as_of})` : ''}.`, '',
81
+ `Working capital: ${r.working_capital ?? '[TO CONFIRM from the financial statement]'}. Net worth: ${r.net_worth ?? '[TO CONFIRM from the financial statement]'}.`, '',
82
+ '| Item | Contract | Backlog | Note |', '| --- | --- | --- | --- |', ...r.items.filter((i) => i.bonded).map((i) => `| ${i.kind} ${i.key} | ${i.contract_amount ?? ''} | ${i.backlog} | ${i.findings.map((f) => f.detail).join(' ')} |`), '',
83
+ 'Financial statements and WIP schedule: [ATTACH]'];
84
+ return L.join('\n');
85
+ }
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: ['bonding_draft_summary'] });
6
+ process.stdout.write(`Fairbuild Bonding Capacity demo (fictional jobs, limits and bids) in ${rt.root}, Auto mode on for drafts\n`);
7
+ const f = { jobs: 'jobs.csv', limits: 'limits.json', pipeline: 'pipeline.csv' };
8
+ const a = await rt.call('bonding_check', f);
9
+ printStep('Summarise bonding capacity', a);
10
+ for (const i of a.result.items) process.stdout.write(` ${i.kind.padEnd(8)} ${i.key.padEnd(22)} ${i.bonded ? 'bonded' : ' '} ${String(i.backlog).padStart(10)} ${i.status.padEnd(8)} ${i.findings.map((x) => x.code).join(', ')}\n`);
11
+ printStep('Explain the Example Library Annex bid', await rt.call('bonding_explain', { ...f, key: 'Example Library Annex' }));
12
+ printStep('Write the summary', await rt.call('bonding_write_report', f));
13
+ const d = await rt.call('bonding_draft_summary', { ...f, label: 'Q4 2026' });
14
+ printStep('Draft the broker summary (Auto is opted in for drafts here)', d);
15
+ printStep('Approve sending it: one named click, even in Auto', await rt.call('bonding_request_send', { draft: d.result.draft, draft_sha256: d.result.draft_sha256 }));
16
+ printStep('Agent tries to request a bond itself', await rt.call('bond_request', {}));
17
+ process.stdout.write(`\nAudit log: ${rt.stateDir}/audit.jsonl\n`);
18
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { manifest } from './manifest.js';
2
+ export * from './bonding.js';
@@ -0,0 +1,67 @@
1
+ import { defineManifest, MODEL_PIN, standardTools, draftPair, refusedTools } from 'fairbuild-core';
2
+ import { readFileSync } from 'node:fs';
3
+ import { checkBonding, summaryText, BOND_JOB_FIELDS, PIPELINE_FIELDS, BONDING_SCHEMA } from './bonding.js';
4
+
5
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
6
+ const OUT = 'fairbuild-out/bonding-capacity';
7
+ const props = {
8
+ jobs: { type: 'string', description: 'Job list under --root (CSV, Excel or JSON): job, contract amount, estimated cost, cost to date, bonded yes or no' },
9
+ limits: { type: 'string', description: 'Your bonding limits JSON (bonding_limits schema): single_limit and aggregate_limit from your surety, near_pct, and working capital and net worth to show' },
10
+ pipeline: { type: 'string', description: 'Optional bids you are chasing: bid, amount, bond required' },
11
+ };
12
+ const run = (a, ctx) => checkBonding({ jobRows: ctx.records(a.jobs, 'jobs'), limits: ctx.readJson(a.limits, 'bonding_limits'), pipelineRows: a.pipeline ? ctx.records(a.pipeline, 'pipeline') : null });
13
+ const std = standardTools({
14
+ prefix: 'bonding', outDir: OUT, props, required: ['jobs', 'limits'], run,
15
+ check: { title: 'Summarise bonding capacity', description: 'Backlog per job by cost to cost; bonded backlog against your aggregate limit; bonded contracts over your single-job limit; bonded jobs forecast at a loss; and, for the bids you list, whether each bonded bid still fits in what is left.' },
16
+ explain: { arg: 'key', argDoc: 'Job number, bid name or PROGRAM from bonding_check', key: (i) => i.key, title: 'Explain one job or bid',
17
+ description: 'Show one job, bid or the program with every finding.',
18
+ describe: (i) => `${i.kind} ${i.key}${i.name && i.name !== i.key ? ` (${i.name})` : ''}: ${i.status}. ${i.bonded ? 'Bonded' : 'Not bonded'}, contract ${i.contract_amount ?? 'n/a'}, backlog ${i.backlog}. ${i.findings.map((f) => f.detail).join(' ')}`.trim() },
19
+ report: { base: 'bonding-capacity', title: 'Bonding capacity summary', description: 'Write the bonding summary',
20
+ row: (i) => ({ kind: i.kind, key: i.key, name: i.name, bonded: i.bonded ? 'yes' : 'no', contract_amount: i.contract_amount ?? '', percent_complete: i.percent_complete ?? '', backlog: i.backlog, status: i.status, findings: i.findings.map((f) => f.code).join(' '), reasons: i.findings.map((f) => f.detail).join(' ') }),
21
+ columns: ['kind', 'key', 'name', 'bonded', 'contract_amount', 'percent_complete', 'backlog', 'status', 'findings', 'reasons'],
22
+ htmlColumns: ['kind', 'key', 'bonded', 'contract_amount', 'backlog', 'status', 'reasons'],
23
+ sections: (r) => [
24
+ { title: 'Capacity', rows: r.capacity, columns: ['single_limit', 'aggregate_limit', 'bonded_backlog', 'aggregate_used_pct', 'aggregate_left'] },
25
+ { title: 'By finding', rows: Object.entries(r.by_finding).map(([code, v]) => ({ code, ...v })), columns: ['code', 'count', 'amount'] },
26
+ ],
27
+ limits: ['files', 'advice', 'The limits are the ones you supply from your surety. Fairbuild Bonding Capacity does not estimate bonding capacity or predict what a surety will approve.'] },
28
+ });
29
+ const pair = draftPair({
30
+ prefix: 'bonding', noun: 'summary', verb: 'send', category: 'binding_send', outDir: OUT, actor: 'a person on your team',
31
+ description: 'Write drafts/summary-<label>.md: the bonding capacity summary for your surety broker, with [ATTACH] for the financials and WIP. Marked DRAFT. Sending goes through bonding_request_send (one click).',
32
+ required: ['jobs', 'limits', 'label'],
33
+ args: { ...props, label: { type: 'string', maxLength: 80, description: 'Name for the summary, for example "Q4 2026"' }, to: { type: 'string', maxLength: 200, description: 'Surety broker' }, from: { type: 'string', maxLength: 200, description: 'Your name and company' } },
34
+ build: (a, ctx) => ({ id: a.label, to: a.to || undefined, text: summaryText(run(a, ctx), a) }),
35
+ });
36
+ const refused = refusedTools([
37
+ { name: 'bond_request', category: 'binding_send', description: 'Fairbuild Bonding Capacity never requests a bid, performance or payment bond.' },
38
+ { name: 'surety_submit', category: 'binding_send', description: 'Fairbuild Bonding Capacity never sends financial statements or WIP to a surety or broker.' },
39
+ { name: 'email_send', category: 'binding_send', description: 'Fairbuild Bonding Capacity never sends the summary; a person sends the approved draft.' },
40
+ ]);
41
+
42
+ export const manifest = defineManifest({
43
+ name: 'fairbuild-bonding-capacity', version: pkg.version,
44
+ description: 'Summarises bonding capacity from your job list and the single and aggregate limits your surety gave you: bonded backlog against the aggregate, contracts over the single-job limit, bonded jobs forecast at a loss, and whether the bonded bids you are chasing fit in what is left. Drafts the summary for your broker. Not surety advice; requesting bonds is a person\'s job.',
45
+ model: MODEL_PIN,
46
+ caps: { maxSteps: 60, maxSpendUsd: 0 },
47
+ configSchemas: { bonding_limits: BONDING_SCHEMA },
48
+ sources: {
49
+ jobs: { label: 'Jobs and bonding', args: ['jobs'], fields: BOND_JOB_FIELDS },
50
+ pipeline: { label: 'Bids being chased', args: ['pipeline'], fields: PIPELINE_FIELDS },
51
+ },
52
+ prompts: [{
53
+ name: 'bonding_review', title: 'Quarterly bonding capacity review',
54
+ description: 'Walks the host model through the bonding capacity summary with Fairbuild Bonding Capacity.',
55
+ arguments: [{ name: 'jobs', description: 'Job list', required: true }, { name: 'limits', description: 'Bonding limits JSON', required: true }, { name: 'pipeline', description: 'Bids (optional)', required: false }],
56
+ text: `You are helping a construction CFO prepare for a surety conversation with fairbuild-bonding-capacity. Jobs: {{jobs}}. Limits: {{limits}}. Pipeline: {{pipeline}}.
57
+
58
+ Rules: Fairbuild Bonding Capacity never requests bonds or sends financials; bond_request, surety_submit and email_send are blocked. Never predict what a surety will approve.
59
+
60
+ 1. Call bonding_check. Lead with bonded backlog against the aggregate limit and what is left, then contracts over the single limit, then bids that would not fit and loss jobs.
61
+ 2. Call bonding_explain for anything the person asks about.
62
+ 3. Call bonding_write_report and share the paths.
63
+ 4. Offer bonding_draft_summary; only when the person asks, call bonding_request_send. It needs one named human click.`,
64
+ }],
65
+ tools: [...std.tools, ...pair.tools, ...refused.tools],
66
+ policy: { rules: [...std.rules, ...pair.rules, ...refused.rules, { tool: '*', decision: 'block', reason: 'Not on the Fairbuild Bonding Capacity allowlist.' }] },
67
+ });