fairbuild-bid-leveling 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 +194 -2
- package/bin/fairbuild-bid-leveling.js +7 -0
- package/evals/cases.json +342 -0
- package/fixtures/README.md +6 -0
- package/fixtures/bids.csv +7 -0
- package/fixtures/intl/README.md +12 -0
- package/fixtures/intl/de/bids.csv +7 -0
- package/fixtures/intl/de/scope.csv +8 -0
- package/fixtures/intl/ja/bids.csv +7 -0
- package/fixtures/intl/ja/scope.csv +8 -0
- package/fixtures/scope.csv +8 -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/bids.js +87 -0
- package/src/demo.js +18 -0
- package/src/index.js +2 -0
- package/src/manifest.js +73 -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,195 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Fairbuild Bid Leveling (`fairbuild-bid-leveling`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tabulates and levels subcontractor bids by bid package: scope items a bidder left out priced at your plug values, bids missing addenda or a bid bond, late bids, and bids far below or above the others; shows the lowest responsive leveled bid per package. Drafts clarification letters. Awarding is a person's decision.
|
|
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-bid-leveling demo
|
|
9
|
+
npx -y fairbuild-bid-leveling mcp --root ./exports
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## What it needs
|
|
13
|
+
|
|
14
|
+
| Argument | What to give it |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `bids` (required) | Bids received under --root (CSV, Excel or JSON): bid package, bidder, base bid, scope included (items separated by ;), exclusions, bid bond, addenda acknowledged, time received |
|
|
17
|
+
| `scope` | Optional scope checklist: bid package, scope item, your plug value for it |
|
|
18
|
+
| `settings` | Optional settings JSON (bid_settings schema): addenda_required, require_bond, due_at, outlier_pct |
|
|
19
|
+
|
|
20
|
+
Only `bids` 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
|
+
- `award_contract`: Fairbuild Bid Leveling never awards a bid or issues a subcontract.
|
|
27
|
+
- `bid_reject_notice`: Fairbuild Bid Leveling never rejects or notifies a bidder.
|
|
28
|
+
- `email_send`: Fairbuild Bid Leveling never sends the clarification; 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
|
+
- `bid_leveling_request_send`: Approve the clarification (one click)
|
|
33
|
+
|
|
34
|
+
## Checks
|
|
35
|
+
|
|
36
|
+
What `bid_leveling_check` flags, each with the first example it finds in the fictional fixtures (the eval cases for `bid_leveling_check`):
|
|
37
|
+
|
|
38
|
+
| Code | Example from the fixtures |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `scope_gap` | Does not include insulation (plug 18000); leveled bid is 249500. |
|
|
41
|
+
| `has_exclusions` | Exclusions: Insulation by others. |
|
|
42
|
+
| `late_bid` | Received 2026-11-10 14:10, after the due time 2026-11-10 14:00. |
|
|
43
|
+
| `no_bond` | No bid bond with the bid. |
|
|
44
|
+
| `missing_addenda` | Acknowledges 1 of 2 addenda. |
|
|
45
|
+
| `low_outlier` | Base bid 189000 is 18.36% below the package median 231500. Confirm the bidder's scope and quantities before relying on it. |
|
|
46
|
+
|
|
47
|
+
<!-- generated:start -->
|
|
48
|
+
|
|
49
|
+
## A demo run
|
|
50
|
+
|
|
51
|
+
`npx -y fairbuild-bid-leveling demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
Fairbuild Bid Leveling demo (fictional bidders and packages), Auto mode on for drafts
|
|
55
|
+
|
|
56
|
+
▶ Level six bids on two packages
|
|
57
|
+
status: executed decision: allow
|
|
58
|
+
6 bid(s) on 2 package(s): 5 responsive, 1 not responsive (late, no bond or missing addenda), 2 leveled for scope gaps (53000 in plugs). Lowest responsive leveled: 09 Drywall: Test Drywall Co 248000; 26 Electrical: Example Electric Inc 412000.
|
|
59
|
+
09 Drywall Test Drywall Co 248000 248000 rank 1 ok
|
|
60
|
+
09 Drywall Sample Interiors LLC 231500 249500 rank 2 leveled scope_gap, has_exclusions
|
|
61
|
+
09 Drywall Example Wallboard Inc 189000 189000 rank - non_responsive late_bid, no_bond, missing_addenda, low_outlier
|
|
62
|
+
26 Electrical Example Electric Inc 412000 412000 rank 1 ok
|
|
63
|
+
26 Electrical Sample Power Co 398000 433000 rank 2 leveled scope_gap, has_exclusions
|
|
64
|
+
26 Electrical Test Circuit LLC 455000 455000 rank 3 ok
|
|
65
|
+
|
|
66
|
+
▶ Explain the Sample Power bid
|
|
67
|
+
status: executed decision: allow
|
|
68
|
+
Sample Power Co on 26 Electrical: leveled, rank 2. Base 398000, plugs 35000, leveled 433000. Does not include fire alarm (plug 35000); leveled bid is 433000. Exclusions: Fire alarm excluded.
|
|
69
|
+
|
|
70
|
+
▶ Write the tabulation
|
|
71
|
+
status: executed decision: allow
|
|
72
|
+
Worklist written: 6 bid(s) on 2 package(s): 5 responsive, 1 not responsive (late, no bond or missing addenda), 2 leveled for scope gaps (53000 in plugs). Lowest responsive leveled: 09 Drywall: Test Drywall Co 248000; 26 Electrical: Example Electric Inc 412000.
|
|
73
|
+
|
|
74
|
+
▶ Draft a clarification letter (Auto is opted in for drafts here)
|
|
75
|
+
status: executed decision: allow (auto)
|
|
76
|
+
clarification Sample Power Co drafted with 2 open marker(s) ([TO CONFIRM bidder contact], [TO CONFIRM your name and company]). Nothing was sent.
|
|
77
|
+
|
|
78
|
+
▶ Approve sending it: one named click, even in Auto
|
|
79
|
+
status: needs_approval decision: ask
|
|
80
|
+
reason: binding_send stays one-click, even in Auto
|
|
81
|
+
|
|
82
|
+
▶ Agent tries to award the contract itself
|
|
83
|
+
status: blocked decision: block
|
|
84
|
+
reason: Fairbuild Bid Leveling never awards a bid or issues a subcontract.
|
|
85
|
+
|
|
86
|
+
Audit log: <demo folder>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Tools
|
|
90
|
+
|
|
91
|
+
| Tool | What it does | Policy |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `bid_leveling_check` | Per bid package and bidder: scope items not included, priced at your plug values into a leveled bid; addenda not acknowledged, no bid bond, late; base bids far below or above the package median; exclusions. | runs |
|
|
94
|
+
| `bid_leveling_explain` | Show one bid's base, plugs, leveled price, rank and every finding. | runs |
|
|
95
|
+
| `bid_leveling_write_report` | Write the bid tabulation as bid-leveling.csv (one row per item, blank decision columns for people to fill in) and bid-leveling.html into out_dir (default fairbuild-out/bid-leveling). | runs |
|
|
96
|
+
| `bid_leveling_draft_clarification` | Write drafts/clarification-<bidder>.md: a letter asking one bidder to confirm scope gaps, exclusions, addenda or a low price. | asks first (Auto can be opted in) |
|
|
97
|
+
| `bid_leveling_request_send` | After one named human click (even in Auto), record that the reviewed clarification draft is approved in clarification-requests.csv. | one named click, even in Auto (`binding_send`) |
|
|
98
|
+
| `award_contract` | Fairbuild Bid Leveling never awards a bid or issues a subcontract. | refused |
|
|
99
|
+
| `bid_reject_notice` | Fairbuild Bid Leveling never rejects or notifies a bidder. | refused |
|
|
100
|
+
| `email_send` | Fairbuild Bid Leveling never sends the clarification; a person sends the approved draft. | refused |
|
|
101
|
+
|
|
102
|
+
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.
|
|
103
|
+
|
|
104
|
+
## Columns it reads
|
|
105
|
+
|
|
106
|
+
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.
|
|
107
|
+
|
|
108
|
+
### Bids received (`bids`)
|
|
109
|
+
|
|
110
|
+
| Column | Type | Also read as | For example, in other languages |
|
|
111
|
+
|---|---|---|---|
|
|
112
|
+
| `bid_package` (required) | text | Bid Package, Package, Trade, Scope Package, Division | Vergabepaket, Lot, 入札パッケージ, 招标包 |
|
|
113
|
+
| `bidder` (required) | text | Bidder, Subcontractor, Company, Vendor | Bieter, Soumissionnaire, 入札者, 投标人 |
|
|
114
|
+
| `base_bid` | amount | Base Bid, Bid Amount, Bid, Amount, Price | Angebotssumme, Offre de base, 基本入札額, 基本报价 |
|
|
115
|
+
| `includes` | text | Includes, Included Scope, Scope Included, Inclusions | - |
|
|
116
|
+
| `exclusions` | text | Exclusions, Excludes, Qualifications | Ausschlüsse, Exclusions, 除外項目, 不含项目 |
|
|
117
|
+
| `bond` | yes/no | Bond, Bid Bond, Bond Included | - |
|
|
118
|
+
| `addenda_acknowledged` | number | Addenda Acknowledged, Addenda, Addenda Received | - |
|
|
119
|
+
| `received_at` | date and time | Received At, Received, Submitted At, Time Received | - |
|
|
120
|
+
|
|
121
|
+
### Scope checklist and plugs (`scope`)
|
|
122
|
+
|
|
123
|
+
| Column | Type | Also read as | For example, in other languages |
|
|
124
|
+
|---|---|---|---|
|
|
125
|
+
| `bid_package` (required) | text | Bid Package, Package, Trade | Vergabepaket, Lot, 入札パッケージ, 招标包 |
|
|
126
|
+
| `item` (required) | text | Item, Scope Item, Scope | Position, Ligne, 明細番号, 行号 |
|
|
127
|
+
| `plug_value` | amount | Plug Value, Plug, Estimate, Allowance | - |
|
|
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-bid-leveling 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-bid-leveling demo
|
|
143
|
+
npx -y fairbuild-bid-leveling mcp --root /path/to/your/files
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Claude Desktop, Cursor and other MCP hosts:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"mcpServers": {
|
|
151
|
+
"fairbuild-bid-leveling": {
|
|
152
|
+
"command": "npx",
|
|
153
|
+
"args": [
|
|
154
|
+
"-y",
|
|
155
|
+
"fairbuild-bid-leveling",
|
|
156
|
+
"mcp",
|
|
157
|
+
"--root",
|
|
158
|
+
"/path/to/your/files"
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Claude Code: `claude mcp add fairbuild-bid-leveling -- npx -y fairbuild-bid-leveling mcp --root .`, or install the `fairbuild-bid-leveling` 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-bid-leveling approve <id> --as "Your Name"` (or on the local approvals page, `fairbuild-bid-leveling 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-bid-leveling 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-bid-leveling tools # every tool, its policy and arguments
|
|
177
|
+
fairbuild-bid-leveling sources # the columns each input is read from
|
|
178
|
+
fairbuild-bid-leveling inspect <file> # how a file would be read (names and shapes, never values)
|
|
179
|
+
fairbuild-bid-leveling call bid_leveling_check '{"bids":"<bids>"}'
|
|
180
|
+
fairbuild-bid-leveling eval # the private eval cases on the fictional fixtures
|
|
181
|
+
fairbuild-bid-leveling 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
|
+
- Plug values are your estimates, not the bidders' prices. The lowest leveled bid is a starting point for review, not an award recommendation.
|
|
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
|
+
- Thresholds, percentages, rates and dates come from the settings file you supply; the defaults it used are listed in the result.
|
|
195
|
+
- 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-bid-leveling', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
|
package/evals/cases.json
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
{
|
|
2
|
+
"suite": "fairbuild-bid-leveling",
|
|
3
|
+
"root": "..",
|
|
4
|
+
"data_note": "Fictional bidders, packages, prices and plug values in ../fixtures. Deterministic checks; no model is called.",
|
|
5
|
+
"cases": [
|
|
6
|
+
{
|
|
7
|
+
"id": "check-totals",
|
|
8
|
+
"tool": "bid_leveling_check",
|
|
9
|
+
"args": {
|
|
10
|
+
"bids": "fixtures/bids.csv",
|
|
11
|
+
"scope": "fixtures/scope.csv",
|
|
12
|
+
"settings": "fixtures/settings.json"
|
|
13
|
+
},
|
|
14
|
+
"expect": {
|
|
15
|
+
"status": "executed",
|
|
16
|
+
"equals": {
|
|
17
|
+
"result.packages": 2,
|
|
18
|
+
"result.bids": 6,
|
|
19
|
+
"result.responsive": 5,
|
|
20
|
+
"result.non_responsive": 1,
|
|
21
|
+
"result.leveled": 2,
|
|
22
|
+
"result.ok": 3,
|
|
23
|
+
"result.plugs_added": 53000,
|
|
24
|
+
"result.by_package.09 Drywall.low_leveled": "Test Drywall Co 248000",
|
|
25
|
+
"result.by_package.26 Electrical.low_leveled": "Example Electric Inc 412000"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "every-planted-issue",
|
|
31
|
+
"tool": "bid_leveling_check",
|
|
32
|
+
"args": {
|
|
33
|
+
"bids": "fixtures/bids.csv",
|
|
34
|
+
"scope": "fixtures/scope.csv",
|
|
35
|
+
"settings": "fixtures/settings.json"
|
|
36
|
+
},
|
|
37
|
+
"expect": {
|
|
38
|
+
"contains": [
|
|
39
|
+
"late_bid",
|
|
40
|
+
"no_bond",
|
|
41
|
+
"missing_addenda",
|
|
42
|
+
"scope_gap",
|
|
43
|
+
"low_outlier",
|
|
44
|
+
"has_exclusions"
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"id": "explain-leveled",
|
|
50
|
+
"tool": "bid_leveling_explain",
|
|
51
|
+
"args": {
|
|
52
|
+
"bids": "fixtures/bids.csv",
|
|
53
|
+
"scope": "fixtures/scope.csv",
|
|
54
|
+
"bid": "Sample Power Co"
|
|
55
|
+
},
|
|
56
|
+
"expect": {
|
|
57
|
+
"status": "executed",
|
|
58
|
+
"contains": [
|
|
59
|
+
"Does not include fire alarm (plug 35000); leveled bid is 433000"
|
|
60
|
+
],
|
|
61
|
+
"equals": {
|
|
62
|
+
"result.item.rank": 2
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "low-base-not-lowest-leveled",
|
|
68
|
+
"tool": "bid_leveling_check",
|
|
69
|
+
"args": {
|
|
70
|
+
"bids": "fixtures/bids.csv",
|
|
71
|
+
"scope": "fixtures/scope.csv",
|
|
72
|
+
"settings": "fixtures/settings.json"
|
|
73
|
+
},
|
|
74
|
+
"expect": {
|
|
75
|
+
"equals": {
|
|
76
|
+
"result.by_package.09 Drywall.low_base": "Example Wallboard Inc 189000",
|
|
77
|
+
"result.by_package.09 Drywall.responsive": 2
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": "without-scope-checklist",
|
|
83
|
+
"tool": "bid_leveling_check",
|
|
84
|
+
"args": {
|
|
85
|
+
"bids": "fixtures/bids.csv",
|
|
86
|
+
"settings": "fixtures/settings.json"
|
|
87
|
+
},
|
|
88
|
+
"expect": {
|
|
89
|
+
"equals": {
|
|
90
|
+
"result.plugs_added": 0,
|
|
91
|
+
"result.leveled": 0,
|
|
92
|
+
"result.by_package.26 Electrical.low_leveled": "Sample Power Co 398000"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "lenient-settings",
|
|
98
|
+
"tool": "bid_leveling_check",
|
|
99
|
+
"args": {
|
|
100
|
+
"bids": "fixtures/bids.csv",
|
|
101
|
+
"scope": "fixtures/scope.csv",
|
|
102
|
+
"settings": "fixtures/settings-lenient.json"
|
|
103
|
+
},
|
|
104
|
+
"expect": {
|
|
105
|
+
"equals": {
|
|
106
|
+
"result.non_responsive": 0,
|
|
107
|
+
"result.by_package.09 Drywall.low_leveled": "Example Wallboard Inc 189000"
|
|
108
|
+
},
|
|
109
|
+
"not_contains": [
|
|
110
|
+
"low_outlier"
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"id": "settings-typo-is-named",
|
|
116
|
+
"tool": "bid_leveling_check",
|
|
117
|
+
"args": {
|
|
118
|
+
"bids": "fixtures/bids.csv",
|
|
119
|
+
"settings": "fixtures/settings-typo.json"
|
|
120
|
+
},
|
|
121
|
+
"expect": {
|
|
122
|
+
"status": "error",
|
|
123
|
+
"contains": [
|
|
124
|
+
"bid_settings"
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"id": "write-report-writes-files",
|
|
130
|
+
"tool": "bid_leveling_write_report",
|
|
131
|
+
"args": {
|
|
132
|
+
"bids": "fixtures/bids.csv",
|
|
133
|
+
"scope": "fixtures/scope.csv",
|
|
134
|
+
"settings": "fixtures/settings.json"
|
|
135
|
+
},
|
|
136
|
+
"expect": {
|
|
137
|
+
"status": "executed",
|
|
138
|
+
"length": {
|
|
139
|
+
"result.files": 2
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"id": "draft-clarification",
|
|
145
|
+
"tool": "bid_leveling_draft_clarification",
|
|
146
|
+
"mode": "auto",
|
|
147
|
+
"auto_actions": [
|
|
148
|
+
"bid_leveling_draft_clarification"
|
|
149
|
+
],
|
|
150
|
+
"args": {
|
|
151
|
+
"bids": "fixtures/bids.csv",
|
|
152
|
+
"scope": "fixtures/scope.csv",
|
|
153
|
+
"bidder": "Sample Power Co"
|
|
154
|
+
},
|
|
155
|
+
"expect": {
|
|
156
|
+
"status": "executed",
|
|
157
|
+
"equals": {
|
|
158
|
+
"result.id": "Sample Power Co"
|
|
159
|
+
},
|
|
160
|
+
"contains": [
|
|
161
|
+
"Nothing was sent"
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"id": "draft-nothing-to-clarify",
|
|
167
|
+
"tool": "bid_leveling_draft_clarification",
|
|
168
|
+
"mode": "auto",
|
|
169
|
+
"auto_actions": [
|
|
170
|
+
"bid_leveling_draft_clarification"
|
|
171
|
+
],
|
|
172
|
+
"args": {
|
|
173
|
+
"bids": "fixtures/bids.csv",
|
|
174
|
+
"scope": "fixtures/scope.csv",
|
|
175
|
+
"bidder": "Test Circuit LLC"
|
|
176
|
+
},
|
|
177
|
+
"expect": {
|
|
178
|
+
"status": "error",
|
|
179
|
+
"contains": [
|
|
180
|
+
"nothing to clarify"
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"id": "policy-invented-tool",
|
|
186
|
+
"tool": "bid_leveling_pay_everything_now",
|
|
187
|
+
"args": {},
|
|
188
|
+
"expect": {
|
|
189
|
+
"status": "blocked"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"id": "policy-file-outside-root",
|
|
194
|
+
"tool": "bid_leveling_check",
|
|
195
|
+
"args": {
|
|
196
|
+
"bids": "../../../outside-the-root.csv",
|
|
197
|
+
"scope": "fixtures/scope.csv",
|
|
198
|
+
"settings": "fixtures/settings.json"
|
|
199
|
+
},
|
|
200
|
+
"expect": {
|
|
201
|
+
"status": "error",
|
|
202
|
+
"contains": [
|
|
203
|
+
"outside"
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"id": "policy-missing-argument-named",
|
|
209
|
+
"tool": "bid_leveling_check",
|
|
210
|
+
"args": {},
|
|
211
|
+
"expect": {
|
|
212
|
+
"status": "error",
|
|
213
|
+
"contains": [
|
|
214
|
+
"bids"
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"id": "policy-review-mode-still-reads",
|
|
220
|
+
"tool": "bid_leveling_check",
|
|
221
|
+
"mode": "review",
|
|
222
|
+
"args": {
|
|
223
|
+
"bids": "fixtures/bids.csv",
|
|
224
|
+
"scope": "fixtures/scope.csv",
|
|
225
|
+
"settings": "fixtures/settings.json"
|
|
226
|
+
},
|
|
227
|
+
"expect": {
|
|
228
|
+
"status": "executed"
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"id": "policy-review-mode-still-reports",
|
|
233
|
+
"tool": "bid_leveling_write_report",
|
|
234
|
+
"mode": "review",
|
|
235
|
+
"args": {
|
|
236
|
+
"bids": "fixtures/bids.csv",
|
|
237
|
+
"scope": "fixtures/scope.csv",
|
|
238
|
+
"settings": "fixtures/settings.json"
|
|
239
|
+
},
|
|
240
|
+
"expect": {
|
|
241
|
+
"status": "executed"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"id": "policy-review-mode-blocks-draft",
|
|
246
|
+
"tool": "bid_leveling_draft_clarification",
|
|
247
|
+
"mode": "review",
|
|
248
|
+
"args": {
|
|
249
|
+
"bids": "fixtures/bids.csv",
|
|
250
|
+
"scope": "fixtures/scope.csv",
|
|
251
|
+
"bidder": "Sample Power Co"
|
|
252
|
+
},
|
|
253
|
+
"expect": {
|
|
254
|
+
"status": "blocked"
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"id": "policy-bid-leveling-request-send-one-click-in-auto",
|
|
259
|
+
"tool": "bid_leveling_request_send",
|
|
260
|
+
"mode": "auto",
|
|
261
|
+
"args": {
|
|
262
|
+
"draft": "fairbuild-out/drafts/example.md",
|
|
263
|
+
"draft_sha256": "0000000000000000000000000000000000000000000000000000000000000000"
|
|
264
|
+
},
|
|
265
|
+
"expect": {
|
|
266
|
+
"status": "needs_approval"
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"id": "policy-refuses-award-contract",
|
|
271
|
+
"tool": "award_contract",
|
|
272
|
+
"args": {},
|
|
273
|
+
"expect": {
|
|
274
|
+
"status": "blocked"
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
"id": "policy-refuses-bid-reject-notice",
|
|
279
|
+
"tool": "bid_reject_notice",
|
|
280
|
+
"args": {},
|
|
281
|
+
"expect": {
|
|
282
|
+
"status": "blocked"
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
"id": "policy-refuses-email-send",
|
|
287
|
+
"tool": "email_send",
|
|
288
|
+
"args": {},
|
|
289
|
+
"expect": {
|
|
290
|
+
"status": "blocked"
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
"id": "intl-de-check-totals",
|
|
295
|
+
"tool": "bid_leveling_check",
|
|
296
|
+
"args": {
|
|
297
|
+
"bids": "fixtures/intl/de/bids.csv",
|
|
298
|
+
"scope": "fixtures/intl/de/scope.csv",
|
|
299
|
+
"settings": "fixtures/settings.json"
|
|
300
|
+
},
|
|
301
|
+
"expect": {
|
|
302
|
+
"status": "executed",
|
|
303
|
+
"equals": {
|
|
304
|
+
"result.packages": 2,
|
|
305
|
+
"result.bids": 6,
|
|
306
|
+
"result.responsive": 5,
|
|
307
|
+
"result.non_responsive": 1,
|
|
308
|
+
"result.leveled": 2,
|
|
309
|
+
"result.ok": 3,
|
|
310
|
+
"result.plugs_added": 53000,
|
|
311
|
+
"result.by_package.09 Drywall.low_leveled": "Test Drywall Co 248000",
|
|
312
|
+
"result.by_package.26 Electrical.low_leveled": "Example Electric Inc 412000"
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
"note": "German export of the same data (fixtures/intl/de); must match the English case \"check-totals\"."
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
"id": "intl-ja-check-totals",
|
|
319
|
+
"tool": "bid_leveling_check",
|
|
320
|
+
"args": {
|
|
321
|
+
"bids": "fixtures/intl/ja/bids.csv",
|
|
322
|
+
"scope": "fixtures/intl/ja/scope.csv",
|
|
323
|
+
"settings": "fixtures/settings.json"
|
|
324
|
+
},
|
|
325
|
+
"expect": {
|
|
326
|
+
"status": "executed",
|
|
327
|
+
"equals": {
|
|
328
|
+
"result.packages": 2,
|
|
329
|
+
"result.bids": 6,
|
|
330
|
+
"result.responsive": 5,
|
|
331
|
+
"result.non_responsive": 1,
|
|
332
|
+
"result.leveled": 2,
|
|
333
|
+
"result.ok": 3,
|
|
334
|
+
"result.plugs_added": 53000,
|
|
335
|
+
"result.by_package.09 Drywall.low_leveled": "Test Drywall Co 248000",
|
|
336
|
+
"result.by_package.26 Electrical.low_leveled": "Example Electric Inc 412000"
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
"note": "Japanese export of the same data (fixtures/intl/ja); must match the English case \"check-totals\"."
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Fairbuild Bid Leveling fixtures
|
|
2
|
+
|
|
3
|
+
Everything here is fictional: bidders, bid packages, prices and plug values.
|
|
4
|
+
|
|
5
|
+
- `bids.csv`: six bids on two packages, due 2026-11-10 at 14:00. Sample Interiors leaves out insulation; Example Wallboard is 18% below the median, has no bond, acknowledges one of two addenda and came in at 14:10; Sample Power leaves out the fire alarm.
|
|
6
|
+
- `scope.csv`: the scope checklist with plug values for leveling.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
bid_package,bidder,base_bid,includes,exclusions,bond,addenda_acknowledged,received_at
|
|
2
|
+
09 Drywall,Test Drywall Co,248000,framing;board;tape;insulation,,yes,2,2026-11-10T13:55
|
|
3
|
+
09 Drywall,Sample Interiors LLC,231500,framing;board;tape,Insulation by others,yes,2,2026-11-10T13:40
|
|
4
|
+
09 Drywall,Example Wallboard Inc,189000,framing;board;tape;insulation,,no,1,2026-11-10T14:10
|
|
5
|
+
26 Electrical,Example Electric Inc,412000,power;lighting;fire alarm,,yes,2,2026-11-10T13:30
|
|
6
|
+
26 Electrical,Sample Power Co,398000,power;lighting,Fire alarm excluded,yes,2,2026-11-10T13:45
|
|
7
|
+
26 Electrical,Test Circuit LLC,455000,power;lighting;fire alarm,,yes,2,2026-11-10T13:50
|
|
@@ -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
|
+
Vergabepaket;Bieter;Angebotssumme;includes;Ausschl�sse;bond;addenda_acknowledged;received_at
|
|
2
|
+
09 Drywall;Test Drywall Co;248.000,00;"framing;board;tape;insulation";;yes;2;10.11.2026 13:55
|
|
3
|
+
09 Drywall;Sample Interiors LLC;231.500,00;"framing;board;tape";Insulation by others;yes;2;10.11.2026 13:40
|
|
4
|
+
09 Drywall;Example Wallboard Inc;189.000,00;"framing;board;tape;insulation";;no;1;10.11.2026 14:10
|
|
5
|
+
26 Electrical;Example Electric Inc;412.000,00;"power;lighting;fire alarm";;yes;2;10.11.2026 13:30
|
|
6
|
+
26 Electrical;Sample Power Co;398.000,00;"power;lighting";Fire alarm excluded;yes;2;10.11.2026 13:45
|
|
7
|
+
26 Electrical;Test Circuit LLC;455.000,00;"power;lighting;fire alarm";;yes;2;10.11.2026 13:50
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
���D�p�b�P�[�W,���D��,��{���D�z,includes,���O����,bond,addenda_acknowledged,received_at
|
|
2
|
+
09 Drywall,Test Drywall Co,"248,000.00",framing;board;tape;insulation,,yes,2,2026/11/10 13:55
|
|
3
|
+
09 Drywall,Sample Interiors LLC,"231,500.00",framing;board;tape,Insulation by others,yes,2,2026/11/10 13:40
|
|
4
|
+
09 Drywall,Example Wallboard Inc,"189,000.00",framing;board;tape;insulation,,no,1,2026/11/10 14:10
|
|
5
|
+
26 Electrical,Example Electric Inc,"412,000.00",power;lighting;fire alarm,,yes,2,2026/11/10 13:30
|
|
6
|
+
26 Electrical,Sample Power Co,"398,000.00",power;lighting,Fire alarm excluded,yes,2,2026/11/10 13:45
|
|
7
|
+
26 Electrical,Test Circuit LLC,"455,000.00",power;lighting;fire alarm,,yes,2,2026/11/10 13:50
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
���D�p�b�P�[�W,���הԍ�,plug_value
|
|
2
|
+
09 Drywall,framing,"60,000.00"
|
|
3
|
+
09 Drywall,board,"90,000.00"
|
|
4
|
+
09 Drywall,tape,"40,000.00"
|
|
5
|
+
09 Drywall,insulation,"18,000.00"
|
|
6
|
+
26 Electrical,power,"200,000.00"
|
|
7
|
+
26 Electrical,lighting,"150,000.00"
|
|
8
|
+
26 Electrical,fire alarm,"35,000.00"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "addenda_required": 1, "outlier_pct": 30 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "addenda": 2 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "addenda_required": 2, "require_bond": true, "due_at": "2026-11-10T14:00", "outlier_pct": 15 }
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fairbuild-bid-leveling",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"mcpName": "io.github.fpavia111-creator/fairbuild-bid-leveling",
|
|
5
|
+
"description": "Fairbuild Bid Leveling: subcontractor bids tabulated and leveled by bid package: scope items a bidder left out priced at your plug values, bids missing addenda or a bid bond, late bids, and bids far below or above the others. Shows the lowest responsive leveled bid per package. Drafts scope clarification letters. Never awards, rejects or notifies a bidder.",
|
|
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-bid-leveling": "bin/fairbuild-bid-leveling.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-bid-leveling.js demo",
|
|
33
|
+
"eval": "node bin/fairbuild-bid-leveling.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-bid-leveling"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/fpavia111-creator/fairbuild-agents/tree/master/packages/fairbuild-bid-leveling#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
|
+
"bid-leveling",
|
|
55
|
+
"bid-tabulation",
|
|
56
|
+
"subcontractor-bids"
|
|
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-bid-leveling",
|
|
4
|
+
"title": "Fairbuild Bid Leveling",
|
|
5
|
+
"description": "Fairbuild Bid Leveling: subcontractor bids tabulated and leveled by bid package: scope items a…",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "https://github.com/fpavia111-creator/fairbuild-agents",
|
|
9
|
+
"source": "github",
|
|
10
|
+
"subfolder": "packages/fairbuild-bid-leveling"
|
|
11
|
+
},
|
|
12
|
+
"websiteUrl": "https://fair-agents.com/fairbuild.html",
|
|
13
|
+
"packages": [
|
|
14
|
+
{
|
|
15
|
+
"registryType": "npm",
|
|
16
|
+
"identifier": "fairbuild-bid-leveling",
|
|
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/bids.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Fairbuild Bid Leveling: subcontractor bid tabulation and leveling by bid package. Pure functions, no I/O.
|
|
2
|
+
//
|
|
3
|
+
// Leveled bid = base bid + your plug value for every scope item the bidder did not include.
|
|
4
|
+
// A bid is responsive when it acknowledges every addendum, carries a bond where one is
|
|
5
|
+
// required and arrived on time; the lowest responsive leveled bid is shown for review.
|
|
6
|
+
import { num, str, round2, readYesNo, finding, orderFindings, byFinding, sortBy } from 'fairbuild-core';
|
|
7
|
+
|
|
8
|
+
const t = (aliases, extra = {}) => ({ aliases, ...extra });
|
|
9
|
+
export const BID_FIELDS = Object.freeze({
|
|
10
|
+
bid_package: t(['Bid Package', 'Package', 'Trade', 'Scope Package', 'Division'], { required: true }),
|
|
11
|
+
bidder: t(['Bidder', 'Subcontractor', 'Company', 'Vendor'], { required: true }),
|
|
12
|
+
base_bid: t(['Base Bid', 'Bid Amount', 'Bid', 'Amount', 'Price'], { type: 'money' }),
|
|
13
|
+
includes: t(['Includes', 'Included Scope', 'Scope Included', 'Inclusions']),
|
|
14
|
+
exclusions: t(['Exclusions', 'Excludes', 'Qualifications']),
|
|
15
|
+
bond: t(['Bond', 'Bid Bond', 'Bond Included'], { type: 'bool' }),
|
|
16
|
+
addenda_acknowledged: t(['Addenda Acknowledged', 'Addenda', 'Addenda Received'], { type: 'number' }),
|
|
17
|
+
received_at: t(['Received At', 'Received', 'Submitted At', 'Time Received'], { type: 'datetime' }),
|
|
18
|
+
});
|
|
19
|
+
export const SCOPE_FIELDS = Object.freeze({
|
|
20
|
+
bid_package: t(['Bid Package', 'Package', 'Trade'], { required: true }),
|
|
21
|
+
item: t(['Item', 'Scope Item', 'Scope'], { required: true }),
|
|
22
|
+
plug_value: t(['Plug Value', 'Plug', 'Estimate', 'Allowance'], { type: 'money' }),
|
|
23
|
+
});
|
|
24
|
+
export const BID_SETTINGS_SCHEMA = Object.freeze({
|
|
25
|
+
type: 'object', additionalProperties: false,
|
|
26
|
+
properties: {
|
|
27
|
+
addenda_required: { type: 'integer', minimum: 0, maximum: 100, description: 'Number of addenda every bid must acknowledge (default 0)' },
|
|
28
|
+
require_bond: { type: 'boolean', description: 'A bid bond is required (default false)' },
|
|
29
|
+
due_at: { type: 'string', maxLength: 40, description: 'Bid due date and time, YYYY-MM-DDTHH:MM (optional)' },
|
|
30
|
+
outlier_pct: { type: 'number', minimum: 0, maximum: 100, description: 'A base bid more than this percent below or above the package median is flagged (default 15)' },
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const ORDER = ['late_bid', 'no_bond', 'missing_addenda', 'scope_gap', 'low_outlier', 'high_outlier', 'has_exclusions'];
|
|
34
|
+
const norm = (s) => str(s).toLowerCase().replace(/\s+/g, ' ');
|
|
35
|
+
const median = (xs) => { const s = [...xs].sort((a, b) => a - b); const m = Math.floor(s.length / 2); return s.length ? (s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2) : null; };
|
|
36
|
+
const stamp = (v) => { const s = str(v).replace(' ', 'T'); return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(s) ? s.slice(0, 16) : null; };
|
|
37
|
+
|
|
38
|
+
export function levelBids({ bidRows, scopeRows = null, settings = {} }) {
|
|
39
|
+
const addenda = num(settings.addenda_required) ?? 0; const bondReq = settings.require_bond === true; const due = stamp(settings.due_at); const out_pct = num(settings.outlier_pct) ?? 15;
|
|
40
|
+
// Each scope item counts once per package (a sheet listing it twice must not double its plug); the higher plug wins, whatever the row order.
|
|
41
|
+
const scope = new Map(); const seenItem = new Map(); if (scopeRows) for (const s of scopeRows) { const p = norm(s.bid_package); if (!p || !str(s.item)) continue; const ik = `${p}|${norm(s.item)}`; const plug = num(s.plug_value) ?? 0; if (seenItem.has(ik)) { const e = seenItem.get(ik); e.plug = Math.max(e.plug, plug); continue; } const e = { item: str(s.item), key: norm(s.item), plug }; seenItem.set(ik, e); if (!scope.has(p)) scope.set(p, []); scope.get(p).push(e); }
|
|
42
|
+
const packages = new Map(); for (const b of bidRows) { const p = norm(b.bid_package); if (!p || !str(b.bidder)) continue; if (!packages.has(p)) packages.set(p, { name: str(b.bid_package), bids: [] }); packages.get(p).bids.push(b); }
|
|
43
|
+
const items = []; const byPackage = {};
|
|
44
|
+
for (const [p, pk] of [...packages].sort(([a], [b]) => (a < b ? -1 : 1))) {
|
|
45
|
+
const med = median(pk.bids.map((b) => num(b.base_bid)).filter((x) => x !== null));
|
|
46
|
+
const list = [];
|
|
47
|
+
for (const b of pk.bids) {
|
|
48
|
+
const f = []; const base = num(b.base_bid) ?? 0;
|
|
49
|
+
const inc = new Set(str(b.includes).split(/[;,|]/).map(norm).filter(Boolean)); const missing = (scope.get(p) || []).filter((s) => !inc.has(s.key));
|
|
50
|
+
const plugs = round2(missing.reduce((a, s) => a + s.plug, 0));
|
|
51
|
+
if (missing.length) f.push(finding('scope_gap', plugs, `Does not include ${missing.map((s) => `${s.item} (plug ${s.plug})`).join(', ')}; leveled bid is ${round2(base + plugs)}.`));
|
|
52
|
+
const ack = num(b.addenda_acknowledged) ?? 0; if (ack < addenda) f.push(finding('missing_addenda', null, `Acknowledges ${ack} of ${addenda} addenda.`));
|
|
53
|
+
if (bondReq && readYesNo(b.bond) !== true) f.push(finding('no_bond', null, 'No bid bond with the bid.'));
|
|
54
|
+
const at = stamp(b.received_at); if (due && at && at > due) f.push(finding('late_bid', null, `Received ${at.replace('T', ' ')}, after the due time ${due.replace('T', ' ')}.`));
|
|
55
|
+
if (med && base && base < med * (1 - out_pct / 100)) f.push(finding('low_outlier', null, `Base bid ${base} is ${round2((1 - base / med) * 100)}% below the package median ${med}. Confirm the bidder's scope and quantities before relying on it.`));
|
|
56
|
+
if (med && base > med * (1 + out_pct / 100)) f.push(finding('high_outlier', null, `Base bid ${base} is ${round2((base / med - 1) * 100)}% above the package median ${med}.`));
|
|
57
|
+
if (str(b.exclusions)) f.push(finding('has_exclusions', null, `Exclusions: ${str(b.exclusions)}.`));
|
|
58
|
+
const codes = f.map((x) => x.code); const responsive = !codes.some((c) => ['late_bid', 'no_bond', 'missing_addenda'].includes(c));
|
|
59
|
+
const status = !responsive ? 'non_responsive' : codes.includes('scope_gap') ? 'leveled' : codes.some((c) => ['low_outlier', 'high_outlier', 'has_exclusions'].includes(c)) ? 'review' : 'ok';
|
|
60
|
+
list.push({ key: `${pk.name} ${str(b.bidder)}`, bid_package: pk.name, bidder: str(b.bidder), base_bid: base, plugs, leveled_bid: round2(base + plugs), responsive, rank: null, status, findings: orderFindings(f, ORDER) });
|
|
61
|
+
}
|
|
62
|
+
const ranked = sortBy(list.filter((x) => x.responsive), ['leveled_bid', 1], ['bidder', 1]); ranked.forEach((x, i) => { x.rank = i + 1; });
|
|
63
|
+
const lowBase = sortBy(list, ['base_bid', 1], ['bidder', 1])[0];
|
|
64
|
+
byPackage[pk.name] = { bidders: list.length, responsive: ranked.length, low_base: lowBase ? `${lowBase.bidder} ${lowBase.base_bid}` : '', low_leveled: ranked[0] ? `${ranked[0].bidder} ${ranked[0].leveled_bid}` : 'none responsive', spread_pct: ranked.length > 1 ? round2((ranked.at(-1).leveled_bid / ranked[0].leveled_bid - 1) * 100) : 0 };
|
|
65
|
+
items.push(...list);
|
|
66
|
+
}
|
|
67
|
+
const rank = { non_responsive: 0, leveled: 1, review: 2, ok: 3 };
|
|
68
|
+
const out = sortBy(items, ['bid_package', 1], [(i) => i.rank ?? 99, 1], [(i) => rank[i.status], 1], ['bidder', 1]);
|
|
69
|
+
const count = (st) => out.filter((i) => i.status === st).length;
|
|
70
|
+
const r = {
|
|
71
|
+
packages: packages.size, bids: out.length, responsive: out.filter((i) => i.responsive).length, non_responsive: count('non_responsive'), leveled: count('leveled'), review: count('review'), ok: count('ok'),
|
|
72
|
+
plugs_added: round2(out.reduce((a, i) => a + i.plugs, 0)), settings_used: { addenda_required: addenda, require_bond: bondReq, due_at: due, outlier_pct: out_pct },
|
|
73
|
+
by_package: byPackage, by_finding: byFinding(out), items: out,
|
|
74
|
+
};
|
|
75
|
+
r.summary = `${r.bids} bid(s) on ${r.packages} package(s): ${r.responsive} responsive, ${r.non_responsive} not responsive (late, no bond or missing addenda), ${r.leveled} leveled for scope gaps (${r.plugs_added} in plugs). Lowest responsive leveled: ${Object.entries(byPackage).map(([k, v]) => `${k}: ${v.low_leveled}`).join('; ')}.`;
|
|
76
|
+
return r;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Markdown body of a scope clarification letter to one bidder. */
|
|
80
|
+
export function clarificationText(items, { bidder, contact, from }) {
|
|
81
|
+
const rows = items.filter((i) => i.findings.some((f) => ['scope_gap', 'has_exclusions', 'missing_addenda', 'low_outlier'].includes(f.code)));
|
|
82
|
+
const L = [`# Bid clarification: ${bidder}`, '', `**To:** ${contact || '[TO CONFIRM bidder contact]'}`, `**From:** ${from || '[TO CONFIRM your name and company]'}`, '',
|
|
83
|
+
'Thank you for your bid. Before we can compare it, please confirm the points below in writing.', '', '| Package | Base bid | Please confirm |', '| --- | --- | --- |',
|
|
84
|
+
...rows.map((i) => `| ${i.bid_package} | ${i.base_bid} | ${i.findings.filter((f) => ['scope_gap', 'has_exclusions', 'missing_addenda', 'low_outlier'].includes(f.code)).map((f) => f.code === 'scope_gap' ? `whether your price includes ${f.detail.replace(/^Does not include /, '').replace(/; leveled bid.*$/, '')}` : f.code === 'missing_addenda' ? 'that you received and priced every addendum' : f.code === 'low_outlier' ? 'your scope and quantities' : `the exclusions (${f.detail.replace(/^Exclusions: /, '')})`).join('; ')} |`),
|
|
85
|
+
'', 'This letter does not award or reject any bid.'];
|
|
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: ['bid_leveling_draft_clarification'] });
|
|
6
|
+
process.stdout.write(`Fairbuild Bid Leveling demo (fictional bidders and packages) in ${rt.root}, Auto mode on for drafts\n`);
|
|
7
|
+
const f = { bids: 'bids.csv', scope: 'scope.csv', settings: 'settings.json' };
|
|
8
|
+
const a = await rt.call('bid_leveling_check', f);
|
|
9
|
+
printStep('Level six bids on two packages', a);
|
|
10
|
+
for (const i of a.result.items) process.stdout.write(` ${i.bid_package.padEnd(14)} ${i.bidder.padEnd(22)} ${String(i.base_bid).padStart(7)} ${String(i.leveled_bid).padStart(7)} rank ${String(i.rank ?? '-').padEnd(2)} ${i.status.padEnd(15)} ${i.findings.map((x) => x.code).join(', ')}\n`);
|
|
11
|
+
printStep('Explain the Sample Power bid', await rt.call('bid_leveling_explain', { ...f, bid: 'Sample Power Co' }));
|
|
12
|
+
printStep('Write the tabulation', await rt.call('bid_leveling_write_report', f));
|
|
13
|
+
const d = await rt.call('bid_leveling_draft_clarification', { ...f, bidder: 'Sample Power Co' });
|
|
14
|
+
printStep('Draft a clarification letter (Auto is opted in for drafts here)', d);
|
|
15
|
+
printStep('Approve sending it: one named click, even in Auto', await rt.call('bid_leveling_request_send', { draft: d.result.draft, draft_sha256: d.result.draft_sha256 }));
|
|
16
|
+
printStep('Agent tries to award the contract itself', await rt.call('award_contract', {}));
|
|
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,73 @@
|
|
|
1
|
+
import { defineManifest, MODEL_PIN, standardTools, draftPair, refusedTools, sameParty } from 'fairbuild-core';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { levelBids, clarificationText, BID_FIELDS, SCOPE_FIELDS, BID_SETTINGS_SCHEMA } from './bids.js';
|
|
4
|
+
|
|
5
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
6
|
+
const OUT = 'fairbuild-out/bid-leveling';
|
|
7
|
+
const props = {
|
|
8
|
+
bids: { type: 'string', description: 'Bids received under --root (CSV, Excel or JSON): bid package, bidder, base bid, scope included (items separated by ;), exclusions, bid bond, addenda acknowledged, time received' },
|
|
9
|
+
scope: { type: 'string', description: 'Optional scope checklist: bid package, scope item, your plug value for it' },
|
|
10
|
+
settings: { type: 'string', description: 'Optional settings JSON (bid_settings schema): addenda_required, require_bond, due_at, outlier_pct' },
|
|
11
|
+
};
|
|
12
|
+
const run = (a, ctx) => levelBids({ bidRows: ctx.records(a.bids, 'bids'), scopeRows: a.scope ? ctx.records(a.scope, 'scope') : null, settings: a.settings ? ctx.readJson(a.settings, 'bid_settings') : {} });
|
|
13
|
+
const std = standardTools({
|
|
14
|
+
prefix: 'bid_leveling', outDir: OUT, props, required: ['bids'], run,
|
|
15
|
+
check: { title: 'Tabulate and level bids', description: 'Per bid package and bidder: scope items not included, priced at your plug values into a leveled bid; addenda not acknowledged, no bid bond, late; base bids far below or above the package median; exclusions. Ranks responsive bids by leveled price.' },
|
|
16
|
+
explain: { arg: 'bid', argDoc: 'Bid from bid_leveling_check as "package bidder", or the bidder name', key: (i) => [i.key, i.bidder], title: 'Explain one bid',
|
|
17
|
+
description: 'Show one bid\'s base, plugs, leveled price, rank and every finding.',
|
|
18
|
+
describe: (i) => `${i.bidder} on ${i.bid_package}: ${i.status}${i.rank ? `, rank ${i.rank}` : ''}. Base ${i.base_bid}, plugs ${i.plugs}, leveled ${i.leveled_bid}. ${i.findings.map((f) => f.detail).join(' ')}`.trim() },
|
|
19
|
+
report: { base: 'bid-leveling', title: 'Bid tabulation', description: 'Write the bid tabulation',
|
|
20
|
+
row: (i) => ({ bid_package: i.bid_package, bidder: i.bidder, base_bid: i.base_bid, plugs: i.plugs, leveled_bid: i.leveled_bid, rank: i.rank ?? '', responsive: i.responsive ? 'yes' : 'no', status: i.status, findings: i.findings.map((f) => f.code).join(' '), reasons: i.findings.map((f) => f.detail).join(' ') }),
|
|
21
|
+
columns: ['bid_package', 'bidder', 'base_bid', 'plugs', 'leveled_bid', 'rank', 'responsive', 'status', 'findings', 'reasons'],
|
|
22
|
+
htmlColumns: ['bid_package', 'bidder', 'base_bid', 'plugs', 'leveled_bid', 'rank', 'status', 'reasons'],
|
|
23
|
+
sections: (r) => [
|
|
24
|
+
{ title: 'By bid package', rows: Object.entries(r.by_package).map(([trade_package, v]) => ({ trade_package, ...v })), columns: ['trade_package', 'bidders', 'responsive', 'low_base', 'low_leveled', 'spread_pct'] },
|
|
25
|
+
{ title: 'By finding', rows: Object.entries(r.by_finding).map(([code, v]) => ({ code, ...v })), columns: ['code', 'count', 'amount'] },
|
|
26
|
+
],
|
|
27
|
+
limits: ['files', 'settings', 'advice', 'Plug values are your estimates, not the bidders\' prices. The lowest leveled bid is a starting point for review, not an award recommendation.'] },
|
|
28
|
+
});
|
|
29
|
+
const pair = draftPair({
|
|
30
|
+
prefix: 'bid_leveling', noun: 'clarification', verb: 'send', category: 'binding_send', outDir: OUT, actor: 'a person on your team',
|
|
31
|
+
description: 'Write drafts/clarification-<bidder>.md: a letter asking one bidder to confirm scope gaps, exclusions, addenda or a low price. Marked DRAFT; it does not award or reject. Sending goes through bid_leveling_request_send (one click).',
|
|
32
|
+
required: ['bids', 'bidder'],
|
|
33
|
+
args: { ...props, bidder: { type: 'string', maxLength: 200, description: 'Bidder name' }, contact: { type: 'string', maxLength: 200, description: 'Bidder contact' }, from: { type: 'string', maxLength: 200, description: 'Your name and company' } },
|
|
34
|
+
build: (a, ctx) => {
|
|
35
|
+
const r = run(a, ctx); const items = r.items.filter((i) => sameParty(i.bidder, a.bidder));
|
|
36
|
+
if (!items.length) throw new Error(`no bids from "${a.bidder}"`);
|
|
37
|
+
const t = clarificationText(items, { ...a, bidder: items[0].bidder });
|
|
38
|
+
if (!t.count) throw new Error(`nothing to clarify with ${items[0].bidder}`);
|
|
39
|
+
return { id: items[0].bidder, to: a.contact || undefined, text: t.text, extra: { packages: t.count } };
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const refused = refusedTools([
|
|
43
|
+
{ name: 'award_contract', category: 'binding_send', description: 'Fairbuild Bid Leveling never awards a bid or issues a subcontract.' },
|
|
44
|
+
{ name: 'bid_reject_notice', category: 'binding_send', description: 'Fairbuild Bid Leveling never rejects or notifies a bidder.' },
|
|
45
|
+
{ name: 'email_send', category: 'binding_send', description: 'Fairbuild Bid Leveling never sends the clarification; a person sends the approved draft.' },
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
export const manifest = defineManifest({
|
|
49
|
+
name: 'fairbuild-bid-leveling', version: pkg.version,
|
|
50
|
+
description: 'Tabulates and levels subcontractor bids by bid package: scope items a bidder left out priced at your plug values, bids missing addenda or a bid bond, late bids, and bids far below or above the others; shows the lowest responsive leveled bid per package. Drafts clarification letters. Awarding is a person\'s decision.',
|
|
51
|
+
model: MODEL_PIN,
|
|
52
|
+
caps: { maxSteps: 60, maxSpendUsd: 0 },
|
|
53
|
+
configSchemas: { bid_settings: BID_SETTINGS_SCHEMA },
|
|
54
|
+
sources: {
|
|
55
|
+
bids: { label: 'Bids received', args: ['bids'], fields: BID_FIELDS },
|
|
56
|
+
scope: { label: 'Scope checklist and plugs', args: ['scope'], fields: SCOPE_FIELDS },
|
|
57
|
+
},
|
|
58
|
+
prompts: [{
|
|
59
|
+
name: 'bid_leveling', title: 'Bid day leveling',
|
|
60
|
+
description: 'Walks the host model through bid leveling with Fairbuild Bid Leveling.',
|
|
61
|
+
arguments: [{ name: 'bids', description: 'Bids received', required: true }, { name: 'scope', description: 'Scope checklist (optional)', required: false }],
|
|
62
|
+
text: `You are helping an estimator level subcontractor bids with fairbuild-bid-leveling. Bids: {{bids}}. Scope: {{scope}}.
|
|
63
|
+
|
|
64
|
+
Rules: Fairbuild Bid Leveling never awards, rejects or sends; award_contract, bid_reject_notice and email_send are blocked. The lowest leveled bid is for review, not an award.
|
|
65
|
+
|
|
66
|
+
1. Call bid_leveling_check. Per package, lead with the lowest responsive leveled bid, then non-responsive bids and why, then scope gaps and outliers.
|
|
67
|
+
2. Call bid_leveling_explain for bids the person asks about.
|
|
68
|
+
3. Call bid_leveling_write_report and share the paths.
|
|
69
|
+
4. Offer bid_leveling_draft_clarification for bidders with gaps; only when the person asks, call bid_leveling_request_send. It needs one named human click.`,
|
|
70
|
+
}],
|
|
71
|
+
tools: [...std.tools, ...pair.tools, ...refused.tools],
|
|
72
|
+
policy: { rules: [...std.rules, ...pair.rules, ...refused.rules, { tool: '*', decision: 'block', reason: 'Not on the Fairbuild Bid Leveling allowlist.' }] },
|
|
73
|
+
});
|