fairbuild-certified-payroll 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,207 @@
1
- # Temporary Holding Version
1
+ # Fairbuild Certified Payroll (`fairbuild-certified-payroll`)
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
+ Checks certified payroll lines against the wage rates of the job's determination: cash plus fringe below the rate for the classification, overtime not paid as overtime, classifications with no rate, missing worker ids, full Social Security numbers on the report and lines entered twice. Worker names and ids are masked in what the model sees. Drafts payroll corrections; submitting payroll and paying 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-certified-payroll demo
9
+ npx -y fairbuild-certified-payroll mcp --root ./exports
10
+ ```
11
+
12
+ ## What it needs
13
+
14
+ | Argument | What to give it |
15
+ |---|---|
16
+ | `payroll` (required) | Certified payroll lines under --root (CSV, Excel or JSON): job, week ending, worker, worker id or last four of SSN, classification, straight and overtime hours, rate paid, fringe paid per hour. A WH-347-style column layout is recognised |
17
+ | `rates` (required) | Wage determination rates for the job: classification, base rate, fringe rate |
18
+ | `settings` | Optional settings JSON (wage_settings schema): ot_multiplier, weekly_ot_after, classification_aliases, tolerance |
19
+
20
+ Only `payroll` and `rates` 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
+ - `payroll_submit`: Fairbuild Certified Payroll never signs or submits a certified payroll to an agency or owner.
27
+ - `payroll_run`: Fairbuild Certified Payroll never runs payroll or pays restitution.
28
+ - `email_send`: Fairbuild Certified Payroll never sends the correction note; 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
+ - `certified_payroll_request_send`: Approve the corrections (one click)
33
+
34
+ ## Checks
35
+
36
+ What `certified_payroll_check` flags, each with the first example it finds in the fictional fixtures (the eval cases for `certified_payroll_check`):
37
+
38
+ | Code | Example from the fixtures |
39
+ |---|---|
40
+ | `underpaid` | Paid 30 + 12.5 fringe per hour; the determination for Roofer is 31.5 + 12.5 (overtime 47.25 + 12.5). Short 69 for 40 straight and 4 overtime hour(s). |
41
+ | `ot_not_paid` | 44 straight-time hours in one week: 4 hour(s) past 40 are overtime, 63 short at 1.5 times the base rate. |
42
+ | `missing_worker_id` | No identifying number for PERSON-638f272c. The report needs the worker's id or the last four digits of the SSN. |
43
+ | `no_rate` | "Sheet Metal Worker" is not on the wage determination you supplied. Use the determination's classification, or add a conformance rate. |
44
+ | `full_ssn_on_report` | The worker id for PERSON-fd9ab9af looks like a full Social Security number. Use only the last four digits or an employee id on a certified payroll. |
45
+ | `duplicate_line` | PERSON-241bd4c9 appears 2 times for the week ending 2026-11-14 in the same classification. Only one line is counted; correct the payroll. |
46
+
47
+ <!-- generated:start -->
48
+
49
+ ## A demo run
50
+
51
+ `npx -y fairbuild-certified-payroll demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
52
+
53
+ ```text
54
+ Fairbuild Certified Payroll demo (fictional workers and rates; names are masked in results), Auto mode on for drafts
55
+
56
+ ▶ Check two weeks of certified payroll against the determination
57
+ status: executed decision: allow
58
+ 8 payroll line(s), 5 worker(s), 2 week(s), 302 hour(s): 3 line(s) paid below the determination (450 short), 4 to review.
59
+ 2026-11-07 PERSON-64c318d7 Roofer short 69 underpaid underpaid
60
+ 2026-11-07 PERSON-fd9ab9af Laborer Group 1 short 318 underpaid underpaid
61
+ 2026-11-14 PERSON-d1953839 Roofer short 63 underpaid ot_not_paid
62
+ 2026-11-07 PERSON-638f272c Roofer short 0 review missing_worker_id
63
+ 2026-11-14 PERSON-64c318d7 Sheet Metal Worker short 0 review no_rate
64
+ 2026-11-14 PERSON-fd9ab9af Laborer Group 1 short 0 review full_ssn_on_report
65
+ 2026-11-14 PERSON-241bd4c9 Roofer short 0 review duplicate_line
66
+ 2026-11-07 PERSON-d1953839 Roofer short 0 ok
67
+
68
+ ▶ Explain one line by its masked key
69
+ status: executed decision: allow
70
+ PERSON-64c318d7 week ending 2026-11-07 (Roofer): underpaid. 40 straight + 4 overtime hour(s) at 30 + 12.5; rate 31.5 + 12.5; short 69. Paid 30 + 12.5 fringe per hour; the determination for Roofer is 31.5 + 12.5 (overtime 47.25 + 12.5). Short 69 for 40 straight and 4 overtime hour(s).
71
+
72
+ ▶ Write the worklist (the files keep the real names)
73
+ status: executed decision: allow
74
+ Worklist written: 8 payroll line(s), 5 worker(s), 2 week(s), 302 hour(s): 3 line(s) paid below the determination (450 short), 4 to review.
75
+
76
+ ▶ Draft the payroll corrections (Auto is opted in for drafts here)
77
+ status: executed decision: allow (auto)
78
+ corrections 24-102 November drafted for 450 with 3 open marker(s) ([TO CONFIRM payroll], [TO CONFIRM your name], [TO CONFIRM with your labor compliance adviser]). Nothing was sent.
79
+
80
+ ▶ Approve sending them: 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 submit the certified payroll itself
85
+ status: blocked decision: block
86
+ reason: Fairbuild Certified Payroll never signs or submits a certified payroll to an agency or owner.
87
+
88
+ Audit log: <demo folder>
89
+ ```
90
+
91
+ ## Tools
92
+
93
+ | Tool | What it does | Policy |
94
+ |---|---|---|
95
+ | `certified_payroll_check` | Per worker and week: cash plus fringe per hour against base plus fringe for the classification, straight and overtime; straight-time hours past the weekly limit; classifications not on the determination; missing worke… | runs |
96
+ | `certified_payroll_explain` | Show one worker-week line against the rate and every finding. | runs |
97
+ | `certified_payroll_write_report` | Write the certified payroll worklist as certified-payroll.csv (one row per item, blank decision columns for people to fill in) and certified-payroll.html into out_dir (default fairbuild-out/certified-payroll). | runs |
98
+ | `certified_payroll_draft_corrections` | Write drafts/corrections-<label>.md: the lines to correct before the certified payroll is signed, with the amount short per line. | asks first (Auto can be opted in) |
99
+ | `certified_payroll_request_send` | After one named human click (even in Auto), record that the reviewed corrections draft is approved in corrections-requests.csv. | one named click, even in Auto (`binding_send`) |
100
+ | `payroll_submit` | Fairbuild Certified Payroll never signs or submits a certified payroll to an agency or owner. | refused |
101
+ | `payroll_run` | Fairbuild Certified Payroll never runs payroll or pays restitution. | refused |
102
+ | `email_send` | Fairbuild Certified Payroll never sends the correction note; 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
+ ### Certified payroll lines (`payroll`)
111
+
112
+ | Column | Type | Also read as | For example, in other languages |
113
+ |---|---|---|---|
114
+ | `job` | text | Job, Job Number, Project, Project Number, Contract | Projekt, Chantier, 工事番号, 项目编号 |
115
+ | `week_ending` | date | Week Ending, Week End, Period Ending, Pay Period End, W/E | Wochenende, Semaine se terminant le, 週末日, 周结束日 |
116
+ | `worker` (required) | text | Worker, Employee, Employee Name, Name, Name of Worker | Mitarbeiter, Salarié, 作業員, 工人 |
117
+ | `worker_id` | text | Worker ID, Employee ID, Employee Number, Last 4 SSN, SSN Last 4, ID | Personalnummer, Matricule, 社員番号, 工号 |
118
+ | `classification` | text | Classification, Work Classification, Craft, Trade, Job Class | Lohngruppe, Qualification, 職種, 工种 |
119
+ | `hours` | number | Hours, Straight Time Hours, ST Hours, Regular Hours, Total Hours | Stunden, Heures, 時間, 工时 |
120
+ | `overtime_hours` | number | Overtime Hours, OT Hours, Overtime | Überstunden, Heures supplémentaires, 残業時間, 加班工时 |
121
+ | `rate_paid` | amount | Rate Paid, Rate of Pay, Hourly Rate, Base Rate Paid, Rate | - |
122
+ | `fringe_paid` | amount | Fringe Paid, Fringe, Fringe Benefits, Fringes per Hour, Fringe Rate Paid | Zulagen, Avantages, 福利費, 福利 |
123
+
124
+ Named exports recognised by their column names:
125
+
126
+ | System | Export | Recognised by | Layout checked against vendor docs |
127
+ |---|---|---|---|
128
+ | Certified payroll (WH-347 layout) | Certified payroll lines typed or exported in the WH-347 column order | Work Classification, Rate of Pay, Total Hours or Straight Time Hours | no |
129
+
130
+ Where a layout says "checked", its column names were compared with the vendor's documentation on that date. The other layouts were written from knowledge of the export and were not checked. None was tested against a live account.
131
+
132
+ ### Wage determination rates (`rates`)
133
+
134
+ | Column | Type | Also read as | For example, in other languages |
135
+ |---|---|---|---|
136
+ | `classification` (required) | text | Classification, Craft, Work Classification, Trade | Lohngruppe, Qualification, 職種, 工种 |
137
+ | `base_rate` | amount | Base Rate, Rate, Basic Hourly Rate, Hourly Rate | Stundenlohn, Taux, 単価, 单价 |
138
+ | `fringe_rate` | amount | Fringe Rate, Fringe, Fringe Benefits, Fringes | Zulagen, Avantages, 福利費, 福利 |
139
+
140
+ ### Files from other countries
141
+
142
+ 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-certified-payroll inspect <file>` (names and shapes only, never values) and name them in `fairbuild-sources.json`:
143
+
144
+ ```json
145
+ { "files": { "exports/bills.csv": { "columns": { "invoice_number": "Beleg" }, "date_order": "dmy" } } }
146
+ ```
147
+
148
+ ## Install
149
+
150
+ Node 20 or newer. No other dependencies.
151
+
152
+ ```bash
153
+ npx -y fairbuild-certified-payroll demo
154
+ npx -y fairbuild-certified-payroll mcp --root /path/to/your/files
155
+ ```
156
+
157
+ Claude Desktop, Cursor and other MCP hosts:
158
+
159
+ ```json
160
+ {
161
+ "mcpServers": {
162
+ "fairbuild-certified-payroll": {
163
+ "command": "npx",
164
+ "args": [
165
+ "-y",
166
+ "fairbuild-certified-payroll",
167
+ "mcp",
168
+ "--root",
169
+ "/path/to/your/files"
170
+ ]
171
+ }
172
+ }
173
+ }
174
+ ```
175
+
176
+ Claude Code: `claude mcp add fairbuild-certified-payroll -- npx -y fairbuild-certified-payroll mcp --root .`, or install the `fairbuild-certified-payroll` plugin from this repository's marketplace.
177
+
178
+ ## Modes and approvals
179
+
180
+ - **Review** (`--mode review`): reads and reports only.
181
+ - **Assist** (default): the policy above. A tool that asks returns an `approval_id`; a person approves it once with `fairbuild-certified-payroll approve <id> --as "Your Name"` (or on the local approvals page, `fairbuild-certified-payroll approvals`), and the same call is repeated.
182
+ - **Auto** (`--mode auto --auto <tool,...>`): opt-in per tool, with step caps and a kill switch (`fairbuild-certified-payroll 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.
183
+
184
+ ## CLI
185
+
186
+ ```bash
187
+ fairbuild-certified-payroll tools # every tool, its policy and arguments
188
+ fairbuild-certified-payroll sources # the columns each input is read from
189
+ fairbuild-certified-payroll inspect <file> # how a file would be read (names and shapes, never values)
190
+ fairbuild-certified-payroll call certified_payroll_check '{"payroll":"<payroll>","rates":"<rates>"}'
191
+ fairbuild-certified-payroll eval # the private eval cases on the fictional fixtures
192
+ fairbuild-certified-payroll demo
193
+ ```
194
+
195
+ ## Audit log and data
196
+
197
+ 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.
198
+
199
+ <!-- generated:end -->
200
+
201
+ ## Limits
202
+
203
+ - Fairbuild Certified Payroll compares cash plus fringe with the rates you supplied. Which determination applies, apprentice rates, fringe credits and overtime rules are for your labor compliance adviser.
204
+ - 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.
205
+ - Thresholds, percentages, rates and dates come from the settings file you supply; the defaults it used are listed in the result.
206
+ - Not legal, tax, lien, insurance, surety or accounting advice. A person decides what to bill, pay, hold, send or file.
207
+ - Results returned to the AI model have worker names, worker ids, Social Security numbers and homeowner contact details masked. The files written here keep the real values: keep them in a secure folder.
@@ -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-certified-payroll', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
@@ -0,0 +1,365 @@
1
+ {
2
+ "suite": "fairbuild-certified-payroll",
3
+ "root": "..",
4
+ "data_note": "Fictional workers, ids and wage rates in ../fixtures. Deterministic checks; no model is called.",
5
+ "cases": [
6
+ {
7
+ "id": "check-totals",
8
+ "tool": "certified_payroll_check",
9
+ "args": {
10
+ "payroll": "fixtures/payroll.csv",
11
+ "rates": "fixtures/rates.csv",
12
+ "settings": "fixtures/settings.json"
13
+ },
14
+ "expect": {
15
+ "status": "executed",
16
+ "equals": {
17
+ "result.lines": 8,
18
+ "result.workers": 5,
19
+ "result.weeks": 2,
20
+ "result.hours": 302,
21
+ "result.owed": 450,
22
+ "result.underpaid": 3,
23
+ "result.review": 4,
24
+ "result.ok": 1
25
+ }
26
+ }
27
+ },
28
+ {
29
+ "id": "every-planted-issue",
30
+ "tool": "certified_payroll_check",
31
+ "args": {
32
+ "payroll": "fixtures/payroll.csv",
33
+ "rates": "fixtures/rates.csv",
34
+ "settings": "fixtures/settings.json"
35
+ },
36
+ "expect": {
37
+ "contains": [
38
+ "underpaid",
39
+ "ot_not_paid",
40
+ "no_rate",
41
+ "duplicate_line",
42
+ "full_ssn_on_report",
43
+ "missing_worker_id"
44
+ ]
45
+ }
46
+ },
47
+ {
48
+ "id": "names-and-ssn-never-reach-the-model",
49
+ "tool": "certified_payroll_check",
50
+ "args": {
51
+ "payroll": "fixtures/payroll.csv",
52
+ "rates": "fixtures/rates.csv"
53
+ },
54
+ "expect": {
55
+ "not_contains": [
56
+ "Jordan Example",
57
+ "Casey Sample",
58
+ "Riley Test",
59
+ "Morgan Example",
60
+ "Taylor Sample",
61
+ "900-12-3456"
62
+ ],
63
+ "contains": [
64
+ "PERSON-",
65
+ "personal_data"
66
+ ],
67
+ "not_matches": [
68
+ "(?<![0-9A-Za-z])4411(?![0-9A-Za-z])"
69
+ ]
70
+ }
71
+ },
72
+ {
73
+ "id": "explain-underpaid-line",
74
+ "tool": "certified_payroll_explain",
75
+ "args": {
76
+ "payroll": "fixtures/payroll.csv",
77
+ "rates": "fixtures/rates.csv",
78
+ "worker": "2026-11-07 Casey Sample"
79
+ },
80
+ "expect": {
81
+ "status": "executed",
82
+ "equals": {
83
+ "result.item.owed": 69,
84
+ "result.item.status": "underpaid"
85
+ },
86
+ "not_contains": [
87
+ "Casey Sample"
88
+ ]
89
+ }
90
+ },
91
+ {
92
+ "id": "overtime-short",
93
+ "tool": "certified_payroll_check",
94
+ "args": {
95
+ "payroll": "fixtures/payroll.csv",
96
+ "rates": "fixtures/rates.csv"
97
+ },
98
+ "expect": {
99
+ "contains": [
100
+ "44 straight-time hours in one week: 4 hour(s) past 40 are overtime, 63 short at 1.5 times the base rate"
101
+ ]
102
+ }
103
+ },
104
+ {
105
+ "id": "underpaid-with-overtime",
106
+ "tool": "certified_payroll_check",
107
+ "args": {
108
+ "payroll": "fixtures/payroll.csv",
109
+ "rates": "fixtures/rates.csv"
110
+ },
111
+ "expect": {
112
+ "contains": [
113
+ "Short 69 for 40 straight and 4 overtime hour(s)",
114
+ "Short 318 for 40 straight hour(s)"
115
+ ]
116
+ }
117
+ },
118
+ {
119
+ "id": "classification-alias",
120
+ "tool": "certified_payroll_check",
121
+ "args": {
122
+ "payroll": "fixtures/payroll.csv",
123
+ "rates": "fixtures/rates.csv",
124
+ "settings": "fixtures/settings-alias.json"
125
+ },
126
+ "expect": {
127
+ "not_contains": [
128
+ "no_rate"
129
+ ],
130
+ "equals": {
131
+ "result.review": 3
132
+ }
133
+ }
134
+ },
135
+ {
136
+ "id": "wh347-layout",
137
+ "tool": "certified_payroll_check",
138
+ "args": {
139
+ "payroll": "fixtures/exports/wh347-lines.csv",
140
+ "rates": "fixtures/rates.csv"
141
+ },
142
+ "expect": {
143
+ "equals": {
144
+ "result.lines": 3,
145
+ "result.owed": 387,
146
+ "result.underpaid": 2
147
+ },
148
+ "contains": [
149
+ "wh347_payroll_lines"
150
+ ]
151
+ }
152
+ },
153
+ {
154
+ "id": "settings-typo-is-named",
155
+ "tool": "certified_payroll_check",
156
+ "args": {
157
+ "payroll": "fixtures/payroll.csv",
158
+ "rates": "fixtures/rates.csv",
159
+ "settings": "fixtures/settings-typo.json"
160
+ },
161
+ "expect": {
162
+ "status": "error",
163
+ "contains": [
164
+ "wage_settings"
165
+ ]
166
+ }
167
+ },
168
+ {
169
+ "id": "write-report-writes-files",
170
+ "tool": "certified_payroll_write_report",
171
+ "args": {
172
+ "payroll": "fixtures/payroll.csv",
173
+ "rates": "fixtures/rates.csv"
174
+ },
175
+ "expect": {
176
+ "status": "executed",
177
+ "length": {
178
+ "result.files": 2
179
+ }
180
+ }
181
+ },
182
+ {
183
+ "id": "draft-corrections",
184
+ "tool": "certified_payroll_draft_corrections",
185
+ "mode": "auto",
186
+ "auto_actions": [
187
+ "certified_payroll_draft_corrections"
188
+ ],
189
+ "args": {
190
+ "payroll": "fixtures/payroll.csv",
191
+ "rates": "fixtures/rates.csv",
192
+ "label": "24-102 November",
193
+ "job": "24-102"
194
+ },
195
+ "expect": {
196
+ "status": "executed",
197
+ "equals": {
198
+ "result.id": "24-102 November",
199
+ "result.amount": 450
200
+ },
201
+ "contains": [
202
+ "Nothing was sent"
203
+ ],
204
+ "not_contains": [
205
+ "Casey Sample"
206
+ ]
207
+ }
208
+ },
209
+ {
210
+ "id": "policy-invented-tool",
211
+ "tool": "certified_payroll_pay_everything_now",
212
+ "args": {},
213
+ "expect": {
214
+ "status": "blocked"
215
+ }
216
+ },
217
+ {
218
+ "id": "policy-file-outside-root",
219
+ "tool": "certified_payroll_check",
220
+ "args": {
221
+ "payroll": "../../../outside-the-root.csv",
222
+ "rates": "fixtures/rates.csv",
223
+ "settings": "fixtures/settings.json"
224
+ },
225
+ "expect": {
226
+ "status": "error",
227
+ "contains": [
228
+ "outside"
229
+ ]
230
+ }
231
+ },
232
+ {
233
+ "id": "policy-missing-argument-named",
234
+ "tool": "certified_payroll_check",
235
+ "args": {},
236
+ "expect": {
237
+ "status": "error",
238
+ "contains": [
239
+ "payroll"
240
+ ]
241
+ }
242
+ },
243
+ {
244
+ "id": "policy-review-mode-still-reads",
245
+ "tool": "certified_payroll_check",
246
+ "mode": "review",
247
+ "args": {
248
+ "payroll": "fixtures/payroll.csv",
249
+ "rates": "fixtures/rates.csv",
250
+ "settings": "fixtures/settings.json"
251
+ },
252
+ "expect": {
253
+ "status": "executed"
254
+ }
255
+ },
256
+ {
257
+ "id": "policy-review-mode-still-reports",
258
+ "tool": "certified_payroll_write_report",
259
+ "mode": "review",
260
+ "args": {
261
+ "payroll": "fixtures/payroll.csv",
262
+ "rates": "fixtures/rates.csv"
263
+ },
264
+ "expect": {
265
+ "status": "executed"
266
+ }
267
+ },
268
+ {
269
+ "id": "policy-review-mode-blocks-draft",
270
+ "tool": "certified_payroll_draft_corrections",
271
+ "mode": "review",
272
+ "args": {
273
+ "payroll": "fixtures/payroll.csv",
274
+ "rates": "fixtures/rates.csv",
275
+ "label": "24-102 November",
276
+ "job": "24-102"
277
+ },
278
+ "expect": {
279
+ "status": "blocked"
280
+ }
281
+ },
282
+ {
283
+ "id": "policy-certified-payroll-request-send-one-click-in-auto",
284
+ "tool": "certified_payroll_request_send",
285
+ "mode": "auto",
286
+ "args": {
287
+ "draft": "fairbuild-out/drafts/example.md",
288
+ "draft_sha256": "0000000000000000000000000000000000000000000000000000000000000000"
289
+ },
290
+ "expect": {
291
+ "status": "needs_approval"
292
+ }
293
+ },
294
+ {
295
+ "id": "policy-refuses-payroll-submit",
296
+ "tool": "payroll_submit",
297
+ "args": {},
298
+ "expect": {
299
+ "status": "blocked"
300
+ }
301
+ },
302
+ {
303
+ "id": "policy-refuses-payroll-run",
304
+ "tool": "payroll_run",
305
+ "args": {},
306
+ "expect": {
307
+ "status": "blocked"
308
+ }
309
+ },
310
+ {
311
+ "id": "policy-refuses-email-send",
312
+ "tool": "email_send",
313
+ "args": {},
314
+ "expect": {
315
+ "status": "blocked"
316
+ }
317
+ },
318
+ {
319
+ "id": "intl-de-check-totals",
320
+ "tool": "certified_payroll_check",
321
+ "args": {
322
+ "payroll": "fixtures/intl/de/payroll.csv",
323
+ "rates": "fixtures/intl/de/rates.csv",
324
+ "settings": "fixtures/settings.json"
325
+ },
326
+ "expect": {
327
+ "status": "executed",
328
+ "equals": {
329
+ "result.lines": 8,
330
+ "result.workers": 5,
331
+ "result.weeks": 2,
332
+ "result.hours": 302,
333
+ "result.owed": 450,
334
+ "result.underpaid": 3,
335
+ "result.review": 4,
336
+ "result.ok": 1
337
+ }
338
+ },
339
+ "note": "German export of the same data (fixtures/intl/de); must match the English case \"check-totals\"."
340
+ },
341
+ {
342
+ "id": "intl-ja-check-totals",
343
+ "tool": "certified_payroll_check",
344
+ "args": {
345
+ "payroll": "fixtures/intl/ja/payroll.csv",
346
+ "rates": "fixtures/intl/ja/rates.csv",
347
+ "settings": "fixtures/settings.json"
348
+ },
349
+ "expect": {
350
+ "status": "executed",
351
+ "equals": {
352
+ "result.lines": 8,
353
+ "result.workers": 5,
354
+ "result.weeks": 2,
355
+ "result.hours": 302,
356
+ "result.owed": 450,
357
+ "result.underpaid": 3,
358
+ "result.review": 4,
359
+ "result.ok": 1
360
+ }
361
+ },
362
+ "note": "Japanese export of the same data (fixtures/intl/ja); must match the English case \"check-totals\"."
363
+ }
364
+ ]
365
+ }
@@ -0,0 +1,7 @@
1
+ # Fairbuild Certified Payroll fixtures
2
+
3
+ Everything here is fictional: job 24-102, worker names, worker ids and rates. 900-12-3456 is not a valid Social Security number (no number starting with 9 is issued); it stands for a full number typed by mistake.
4
+
5
+ - `payroll.csv`: nine lines for two weeks. Casey Sample is paid 30.00 against 31.50 for a roofer, straight and overtime; Riley Test is paid 24.00 and no fringe against 22.10 + 9.85 in week one; Morgan Example has no id; Jordan Example has 44 straight-time hours in week two; Casey Sample works as a sheet metal worker, which is not on the determination; Riley Test's id in week two is a full SSN; Taylor Sample's line is entered twice.
6
+ - `rates.csv`: the wage determination for the job.
7
+ - `exports/wh347-lines.csv`: week one in a WH-347-style column layout.
@@ -0,0 +1,4 @@
1
+ Project,Week Ending,Name of Worker,Identifying Number,Work Classification,Straight Time Hours,Overtime Hours,Rate of Pay,Fringe Benefits
2
+ 24-102,2026-11-07,Jordan Example,4411,Roofer,40,0,32.00,12.50
3
+ 24-102,2026-11-07,Casey Sample,7722,Roofer,40,4,30.00,12.50
4
+ 24-102,2026-11-07,Riley Test,3355,Laborer Group 1,40,0,24.00,0
@@ -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,10 @@
1
+ Projekt;Wochenende;Mitarbeiter;Personalnummer;Lohngruppe;Stunden;�berstunden;rate_paid;Zulagen
2
+ 24-102;07.11.2026;Jordan Example;4411;Roofer;40;0;32,00;12,50
3
+ 24-102;07.11.2026;Casey Sample;7722;Roofer;40;4;30,00;12,50
4
+ 24-102;07.11.2026;Riley Test;3355;Laborer Group 1;40;0;24,00;0,00
5
+ 24-102;07.11.2026;Morgan Example;;Roofer;38;0;32,00;12,50
6
+ 24-102;14.11.2026;Jordan Example;4411;Roofer;44;0;32,00;12,50
7
+ 24-102;14.11.2026;Casey Sample;7722;Sheet Metal Worker;16;0;38,00;15,00
8
+ 24-102;14.11.2026;Riley Test;900-12-3456;Laborer Group 1;40;0;24,00;8,00
9
+ 24-102;14.11.2026;Taylor Sample;5566;Roofer;40;0;32,00;12,50
10
+ 24-102;14.11.2026;Taylor Sample;5566;Roofer;40;0;32,00;12,50
@@ -0,0 +1,4 @@
1
+ Lohngruppe;Stundenlohn;Zulagen
2
+ Roofer;31,50;12,50
3
+ Laborer Group 1;22,10;9,85
4
+ Electrician;41,20;18,75
@@ -0,0 +1,10 @@
1
+ �H���ԍ�,�T����,��ƈ�,�Ј��ԍ�,�E��,����,�c�Ǝ���,rate_paid,������
2
+ 24-102,2026/11/07,Jordan Example,4411,Roofer,40,0,32.00,12.50
3
+ 24-102,2026/11/07,Casey Sample,7722,Roofer,40,4,30.00,12.50
4
+ 24-102,2026/11/07,Riley Test,3355,Laborer Group 1,40,0,24.00,0.00
5
+ 24-102,2026/11/07,Morgan Example,,Roofer,38,0,32.00,12.50
6
+ 24-102,2026/11/14,Jordan Example,4411,Roofer,44,0,32.00,12.50
7
+ 24-102,2026/11/14,Casey Sample,7722,Sheet Metal Worker,16,0,38.00,15.00
8
+ 24-102,2026/11/14,Riley Test,900-12-3456,Laborer Group 1,40,0,24.00,8.00
9
+ 24-102,2026/11/14,Taylor Sample,5566,Roofer,40,0,32.00,12.50
10
+ 24-102,2026/11/14,Taylor Sample,5566,Roofer,40,0,32.00,12.50
@@ -0,0 +1,4 @@
1
+ �E��,�P��,������
2
+ Roofer,31.50,12.50
3
+ Laborer Group 1,22.10,9.85
4
+ Electrician,41.20,18.75
@@ -0,0 +1,10 @@
1
+ job,week_ending,worker,worker_id,classification,hours,overtime_hours,rate_paid,fringe_paid
2
+ 24-102,2026-11-07,Jordan Example,4411,Roofer,40,0,32.00,12.50
3
+ 24-102,2026-11-07,Casey Sample,7722,Roofer,40,4,30.00,12.50
4
+ 24-102,2026-11-07,Riley Test,3355,Laborer Group 1,40,0,24.00,0
5
+ 24-102,2026-11-07,Morgan Example,,Roofer,38,0,32.00,12.50
6
+ 24-102,2026-11-14,Jordan Example,4411,Roofer,44,0,32.00,12.50
7
+ 24-102,2026-11-14,Casey Sample,7722,Sheet Metal Worker,16,0,38.00,15.00
8
+ 24-102,2026-11-14,Riley Test,900-12-3456,Laborer Group 1,40,0,24.00,8.00
9
+ 24-102,2026-11-14,Taylor Sample,5566,Roofer,40,0,32.00,12.50
10
+ 24-102,2026-11-14,Taylor Sample,5566,Roofer,40,0,32.00,12.50
@@ -0,0 +1,4 @@
1
+ classification,base_rate,fringe_rate
2
+ Roofer,31.50,12.50
3
+ Laborer Group 1,22.10,9.85
4
+ Electrician,41.20,18.75
@@ -0,0 +1 @@
1
+ { "classification_aliases": { "Sheet Metal Worker": "Roofer" } }
@@ -0,0 +1 @@
1
+ { "overtime": 1.5 }
@@ -0,0 +1 @@
1
+ { "ot_multiplier": 1.5, "weekly_ot_after": 40, "tolerance": 0.05 }
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "fairbuild-certified-payroll",
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-certified-payroll",
5
+ "description": "Fairbuild Certified Payroll: certified payroll lines against the wage rates of the job's wage determination: hourly cash plus fringe below the rate for the classification, overtime not paid as overtime, classifications with no rate, missing worker ids, full Social Security numbers on the report, and lines entered twice. Worker names and ids are masked in what the AI model sees. Drafts payroll corrections. Never submits payroll or pays anyone.",
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-certified-payroll": "bin/fairbuild-certified-payroll.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-certified-payroll.js demo",
33
+ "eval": "node bin/fairbuild-certified-payroll.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-certified-payroll"
42
+ },
43
+ "homepage": "https://github.com/fpavia111-creator/fairbuild-agents/tree/master/packages/fairbuild-certified-payroll#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
+ "certified-payroll",
55
+ "prevailing-wage",
56
+ "davis-bacon",
57
+ "wh-347"
58
+ ]
59
+ }
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-certified-payroll",
4
+ "title": "Fairbuild Certified Payroll",
5
+ "description": "Fairbuild Certified Payroll: certified payroll lines against the wage rates of the job's wage…",
6
+ "version": "0.1.0",
7
+ "repository": {
8
+ "url": "https://github.com/fpavia111-creator/fairbuild-agents",
9
+ "source": "github",
10
+ "subfolder": "packages/fairbuild-certified-payroll"
11
+ },
12
+ "websiteUrl": "https://fair-agents.com/fairbuild.html",
13
+ "packages": [
14
+ {
15
+ "registryType": "npm",
16
+ "identifier": "fairbuild-certified-payroll",
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/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: ['certified_payroll_draft_corrections'] });
6
+ process.stdout.write(`Fairbuild Certified Payroll demo (fictional workers and rates; names are masked in results) in ${rt.root}, Auto mode on for drafts\n`);
7
+ const f = { payroll: 'payroll.csv', rates: 'rates.csv', settings: 'settings.json' };
8
+ const a = await rt.call('certified_payroll_check', f);
9
+ printStep('Check two weeks of certified payroll against the determination', a);
10
+ for (const i of a.result.items) process.stdout.write(` ${i.week_ending} ${i.worker.padEnd(16)} ${i.classification.padEnd(19)} short ${String(i.owed).padStart(6)} ${i.status.padEnd(9)} ${i.findings.map((x) => x.code).join(', ')}\n`);
11
+ printStep('Explain one line by its masked key', await rt.call('certified_payroll_explain', { ...f, worker: a.result.items[0].key }));
12
+ printStep('Write the worklist (the files keep the real names)', await rt.call('certified_payroll_write_report', f));
13
+ const d = await rt.call('certified_payroll_draft_corrections', { ...f, label: '24-102 November', job: '24-102' });
14
+ printStep('Draft the payroll corrections (Auto is opted in for drafts here)', d);
15
+ printStep('Approve sending them: one named click, even in Auto', await rt.call('certified_payroll_request_send', { draft: d.result.draft, draft_sha256: d.result.draft_sha256 }));
16
+ printStep('Agent tries to submit the certified payroll itself', await rt.call('payroll_submit', {}));
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 './wages.js';
@@ -0,0 +1,68 @@
1
+ import { defineManifest, MODEL_PIN, standardTools, draftPair, refusedTools, exportProfile } from 'fairbuild-core';
2
+ import { readFileSync } from 'node:fs';
3
+ import { checkWages, correctionText, PAYROLL_FIELDS, DETERMINATION_FIELDS, WAGE_SETTINGS_SCHEMA } from './wages.js';
4
+
5
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
6
+ const OUT = 'fairbuild-out/certified-payroll';
7
+ const PAYROLL_PROFILES = [exportProfile('wh347_payroll_lines', { worker: ['Name of Worker', 'Name'], worker_id: ['Identifying Number', 'Last 4 SSN'], classification: 'Work Classification', hours: ['Total Hours', 'Straight Time Hours'], overtime_hours: 'Overtime Hours', rate_paid: 'Rate of Pay', fringe_paid: 'Fringe Benefits', week_ending: 'Week Ending', job: ['Project', 'Project Number'] })];
8
+ const props = {
9
+ payroll: { type: 'string', description: 'Certified payroll lines under --root (CSV, Excel or JSON): job, week ending, worker, worker id or last four of SSN, classification, straight and overtime hours, rate paid, fringe paid per hour. A WH-347-style column layout is recognised' },
10
+ rates: { type: 'string', description: 'Wage determination rates for the job: classification, base rate, fringe rate' },
11
+ settings: { type: 'string', description: 'Optional settings JSON (wage_settings schema): ot_multiplier, weekly_ot_after, classification_aliases, tolerance' },
12
+ };
13
+ const run = (a, ctx) => checkWages({ payrollRows: ctx.records(a.payroll, 'payroll'), rateRows: ctx.records(a.rates, 'rates'), settings: a.settings ? ctx.readJson(a.settings, 'wage_settings') : {} });
14
+ const std = standardTools({
15
+ prefix: 'certified_payroll', outDir: OUT, props, required: ['payroll', 'rates'], run,
16
+ check: { title: 'Check certified payroll against wage rates', description: 'Per worker and week: cash plus fringe per hour against base plus fringe for the classification, straight and overtime; straight-time hours past the weekly limit; classifications not on the determination; missing worker ids; full Social Security numbers on the report; lines entered twice. Worker names and ids are masked in what the model sees.' },
17
+ explain: { arg: 'worker', argDoc: 'Worker (the pseudonym shown in certified_payroll_check) or "week worker"', key: (i) => [i.key, i.worker], personal: 'name', title: 'Explain one payroll line',
18
+ description: 'Show one worker-week line against the rate and every finding.',
19
+ describe: (i) => `${i.worker} week ending ${i.week_ending} (${i.classification}): ${i.status}. ${i.hours} straight + ${i.overtime_hours} overtime hour(s) at ${i.rate_paid} + ${i.fringe_paid}; rate ${i.required_rate ?? 'none'} + ${i.required_fringe ?? 'none'}; short ${i.owed}. ${i.findings.map((f) => f.detail).join(' ')}`.trim() },
20
+ report: { base: 'certified-payroll', title: 'Certified payroll against wage rates', description: 'Write the certified payroll worklist',
21
+ row: (i) => ({ job: i.job, week_ending: i.week_ending, worker: i.worker, worker_id: i.worker_id, classification: i.classification, hours: i.hours, overtime_hours: i.overtime_hours, rate_paid: i.rate_paid, fringe_paid: i.fringe_paid, required_rate: i.required_rate ?? '', required_fringe: i.required_fringe ?? '', owed: i.owed, status: i.status, findings: i.findings.map((f) => f.code).join(' '), reasons: i.findings.map((f) => f.detail).join(' ') }),
22
+ columns: ['job', 'week_ending', 'worker', 'worker_id', 'classification', 'hours', 'overtime_hours', 'rate_paid', 'fringe_paid', 'required_rate', 'required_fringe', 'owed', 'status', 'findings', 'reasons'],
23
+ htmlColumns: ['week_ending', 'worker', 'classification', 'hours', 'overtime_hours', 'rate_paid', 'fringe_paid', 'owed', 'status', 'reasons'],
24
+ sections: (r) => [
25
+ { title: 'By classification', rows: Object.entries(r.by_classification).map(([classification, v]) => ({ classification, ...v })), columns: ['classification', 'lines', 'hours', 'owed'] },
26
+ { title: 'By finding', rows: Object.entries(r.by_finding).map(([code, v]) => ({ code, ...v })), columns: ['code', 'count', 'amount'] },
27
+ ],
28
+ limits: ['files', 'settings', 'advice', 'personal', 'Fairbuild Certified Payroll compares cash plus fringe with the rates you supplied. Which determination applies, apprentice rates, fringe credits and overtime rules are for your labor compliance adviser.'] },
29
+ });
30
+ const pair = draftPair({
31
+ prefix: 'certified_payroll', noun: 'corrections', verb: 'send', category: 'binding_send', outDir: OUT, actor: 'a person in payroll',
32
+ description: 'Write drafts/corrections-<label>.md: the lines to correct before the certified payroll is signed, with the amount short per line. Marked DRAFT. Sending goes through certified_payroll_request_send (one click). The draft holds real names; keep it in a secure folder.',
33
+ required: ['payroll', 'rates', 'label'],
34
+ args: { ...props, label: { type: 'string', maxLength: 80, description: 'Name for the note, for example "24-102 week ending 2026-11-14"' }, job: { type: 'string', maxLength: 60, description: 'Job number for the heading' }, to: { type: 'string', maxLength: 200, description: 'Payroll contact' }, from: { type: 'string', maxLength: 200, description: 'Your name' } },
35
+ build: (a, ctx) => { const r = run(a, ctx); if (!r.items.some((i) => i.status !== 'ok')) throw new Error('nothing to correct: every line meets the rates'); return { id: a.label, to: a.to || undefined, text: correctionText(r, a), amount: r.owed }; },
36
+ });
37
+ const refused = refusedTools([
38
+ { name: 'payroll_submit', category: 'binding_send', description: 'Fairbuild Certified Payroll never signs or submits a certified payroll to an agency or owner.' },
39
+ { name: 'payroll_run', category: 'move_money', description: 'Fairbuild Certified Payroll never runs payroll or pays restitution.' },
40
+ { name: 'email_send', category: 'binding_send', description: 'Fairbuild Certified Payroll never sends the correction note; a person sends the approved draft.' },
41
+ ]);
42
+
43
+ export const manifest = defineManifest({
44
+ name: 'fairbuild-certified-payroll', version: pkg.version,
45
+ description: 'Checks certified payroll lines against the wage rates of the job\'s determination: cash plus fringe below the rate for the classification, overtime not paid as overtime, classifications with no rate, missing worker ids, full Social Security numbers on the report and lines entered twice. Worker names and ids are masked in what the model sees. Drafts payroll corrections; submitting payroll and paying is a person\'s job.',
46
+ model: MODEL_PIN,
47
+ caps: { maxSteps: 60, maxSpendUsd: 0 },
48
+ configSchemas: { wage_settings: WAGE_SETTINGS_SCHEMA },
49
+ sources: {
50
+ payroll: { label: 'Certified payroll lines', args: ['payroll'], fields: PAYROLL_FIELDS, profiles: PAYROLL_PROFILES },
51
+ rates: { label: 'Wage determination rates', args: ['rates'], fields: DETERMINATION_FIELDS },
52
+ },
53
+ prompts: [{
54
+ name: 'certified_payroll_check', title: 'Weekly certified payroll check',
55
+ description: 'Walks the host model through the certified payroll check with Fairbuild Certified Payroll.',
56
+ arguments: [{ name: 'payroll', description: 'Payroll lines', required: true }, { name: 'rates', description: 'Wage determination rates', required: true }],
57
+ text: `You are helping a construction payroll or compliance lead check certified payroll with fairbuild-certified-payroll. Payroll: {{payroll}}. Rates: {{rates}}.
58
+
59
+ Rules: Fairbuild Certified Payroll never submits payroll or pays; payroll_submit, payroll_run and email_send are blocked. Worker names and ids reach you as pseudonyms: use them as given and never ask for real names. This is not legal advice.
60
+
61
+ 1. Call certified_payroll_check. Lead with lines paid below the determination and the amount short, then overtime, then classifications with no rate and id problems.
62
+ 2. Call certified_payroll_explain for lines the person asks about.
63
+ 3. Call certified_payroll_write_report and share the paths (the files hold real names).
64
+ 4. Offer certified_payroll_draft_corrections; only when the person asks, call certified_payroll_request_send. It needs one named human click.`,
65
+ }],
66
+ tools: [...std.tools, ...pair.tools, ...refused.tools],
67
+ policy: { rules: [...std.rules, ...pair.rules, ...refused.rules, { tool: '*', decision: 'block', reason: 'Not on the Fairbuild Certified Payroll allowlist.' }] },
68
+ });
package/src/wages.js ADDED
@@ -0,0 +1,92 @@
1
+ // Fairbuild Certified Payroll: certified payroll lines against the wage determination for the job. Pure functions, no I/O.
2
+ //
3
+ // Per hour, the rate for the classification (base + fringe) can be met by any mix of cash
4
+ // and fringe paid, so the check is on the total: straight time (rate paid + fringe paid)
5
+ // against (base + fringe); overtime (rate paid × multiplier + fringe paid) against
6
+ // (base × multiplier + fringe). This is the common reading; your determination, contract
7
+ // and counsel decide what applies. Worker names and ids are masked before results reach a model.
8
+ import { num, str, round2, isoDate, finding, orderFindings, byFinding, sortBy } from 'fairbuild-core';
9
+
10
+ const t = (aliases, extra = {}) => ({ aliases, ...extra });
11
+ export const PAYROLL_FIELDS = Object.freeze({
12
+ job: t(['Job', 'Job Number', 'Project', 'Project Number', 'Contract']),
13
+ week_ending: t(['Week Ending', 'Week End', 'Period Ending', 'Pay Period End', 'W/E'], { type: 'date' }),
14
+ worker: t(['Worker', 'Employee', 'Employee Name', 'Name', 'Name of Worker'], { required: true }),
15
+ worker_id: t(['Worker ID', 'Employee ID', 'Employee Number', 'Last 4 SSN', 'SSN Last 4', 'ID', 'Identifying Number']),
16
+ classification: t(['Classification', 'Work Classification', 'Craft', 'Trade', 'Job Class']),
17
+ hours: t(['Hours', 'Straight Time Hours', 'ST Hours', 'Regular Hours', 'Total Hours'], { type: 'number' }),
18
+ overtime_hours: t(['Overtime Hours', 'OT Hours', 'Overtime'], { type: 'number' }),
19
+ rate_paid: t(['Rate Paid', 'Rate of Pay', 'Hourly Rate', 'Base Rate Paid', 'Rate'], { type: 'money' }),
20
+ fringe_paid: t(['Fringe Paid', 'Fringe', 'Fringe Benefits', 'Fringes per Hour', 'Fringe Rate Paid'], { type: 'money' }),
21
+ });
22
+ export const DETERMINATION_FIELDS = Object.freeze({
23
+ classification: t(['Classification', 'Craft', 'Work Classification', 'Trade'], { required: true }),
24
+ base_rate: t(['Base Rate', 'Rate', 'Basic Hourly Rate', 'Hourly Rate'], { type: 'money' }),
25
+ fringe_rate: t(['Fringe Rate', 'Fringe', 'Fringe Benefits', 'Fringes'], { type: 'money' }),
26
+ });
27
+ export const WAGE_SETTINGS_SCHEMA = Object.freeze({
28
+ type: 'object', additionalProperties: false,
29
+ properties: {
30
+ ot_multiplier: { type: 'number', minimum: 1, maximum: 3, description: 'Overtime multiplier on the base rate (default 1.5)' },
31
+ weekly_ot_after: { type: 'number', minimum: 0, maximum: 168, description: 'Straight-time hours in one week past this are owed as overtime (default 40)' },
32
+ classification_aliases: { type: 'object', additionalProperties: { type: 'string', maxLength: 80 }, description: 'Your words for a classification on the determination, e.g. {"Roofer Journeyman": "Roofer"}' },
33
+ tolerance: { type: 'number', minimum: 0, maximum: 100, description: 'Differences up to this amount per line are rounding (default 0.05)' },
34
+ },
35
+ });
36
+ const ORDER = ['underpaid', 'ot_not_paid', 'no_rate', 'duplicate_line', 'full_ssn_on_report', 'missing_worker_id'];
37
+ const norm = (s) => str(s).toLowerCase().replace(/\s+/g, ' ');
38
+
39
+ export function checkWages({ payrollRows, rateRows, settings = {} }) {
40
+ const mult = num(settings.ot_multiplier) ?? 1.5; const otAfter = num(settings.weekly_ot_after) ?? 40; const tol = num(settings.tolerance) ?? 0.05;
41
+ const alias = Object.fromEntries(Object.entries(settings.classification_aliases || {}).map(([k, v]) => [norm(k), norm(v)]));
42
+ const rates = new Map(); for (const r of rateRows) { const c = norm(r.classification); if (c) rates.set(c, { name: str(r.classification), base: num(r.base_rate) ?? 0, fringe: num(r.fringe_rate) ?? 0 }); }
43
+ const groups = new Map();
44
+ for (const p of payrollRows) {
45
+ const worker = str(p.worker); if (!worker) continue;
46
+ const k = [str(p.job).toUpperCase(), isoDate(p.week_ending) || '', worker.toLowerCase(), norm(p.classification)].join('|');
47
+ if (!groups.has(k)) groups.set(k, []); groups.get(k).push(p);
48
+ }
49
+ const items = [];
50
+ for (const list of groups.values()) {
51
+ const p = sortBy(list, [(x) => num(x.hours) ?? 0, -1], [(x) => num(x.rate_paid) ?? 0, -1])[0]; const f = [];
52
+ const cls = norm(p.classification); const rate = rates.get(alias[cls] || cls);
53
+ const hours = num(p.hours) ?? 0; const ot = num(p.overtime_hours) ?? 0; const paid = num(p.rate_paid) ?? 0; const fringePaid = num(p.fringe_paid) ?? 0;
54
+ const id = str(p.worker_id); const digits = id.replace(/\D/g, '');
55
+ if (list.length > 1) f.push(finding('duplicate_line', null, `${str(p.worker)} appears ${list.length} times for the week ending ${isoDate(p.week_ending)} in the same classification. Only one line is counted; correct the payroll.`));
56
+ if (!id) f.push(finding('missing_worker_id', null, `No identifying number for ${str(p.worker)}. The report needs the worker's id or the last four digits of the SSN.`));
57
+ else if (digits.length >= 9) f.push(finding('full_ssn_on_report', null, `The worker id for ${str(p.worker)} looks like a full Social Security number. Use only the last four digits or an employee id on a certified payroll.`));
58
+ let owed = 0;
59
+ if (!rate) f.push(finding('no_rate', null, `"${str(p.classification)}" is not on the wage determination you supplied. Use the determination's classification, or add a conformance rate.`));
60
+ else {
61
+ const stShort = round2((rate.base + rate.fringe) - (paid + fringePaid)); const otShort = round2((rate.base * mult + rate.fringe) - (paid * mult + fringePaid));
62
+ const under = round2(Math.max(0, stShort) * hours + Math.max(0, otShort) * ot);
63
+ if (under > tol) { owed = round2(owed + under); f.push(finding('underpaid', under, `Paid ${paid} + ${fringePaid} fringe per hour; the determination for ${rate.name} is ${rate.base} + ${rate.fringe}${ot ? ` (overtime ${round2(rate.base * mult)} + ${rate.fringe})` : ''}. Short ${under} for ${hours} straight${ot ? ` and ${ot} overtime` : ''} hour(s).`)); }
64
+ if (hours > otAfter) { const extra = round2(hours - otAfter); const due = round2(extra * rate.base * (mult - 1)); owed = round2(owed + due); f.push(finding('ot_not_paid', due, `${hours} straight-time hours in one week: ${extra} hour(s) past ${otAfter} are overtime, ${due} short at ${mult} times the base rate.`)); }
65
+ }
66
+ const codes = f.map((x) => x.code);
67
+ const status = codes.some((x) => ['underpaid', 'ot_not_paid'].includes(x)) ? 'underpaid' : f.length ? 'review' : 'ok';
68
+ items.push({ key: `${isoDate(p.week_ending)} ${str(p.worker)}`, job: str(p.job), week_ending: isoDate(p.week_ending), worker: str(p.worker), worker_id: id, classification: str(p.classification), hours, overtime_hours: ot, rate_paid: paid, fringe_paid: fringePaid, required_rate: rate ? rate.base : null, required_fringe: rate ? rate.fringe : null, owed, status, findings: orderFindings(f, ORDER) });
69
+ }
70
+ const rank = { underpaid: 0, review: 1, ok: 2 };
71
+ const out = sortBy(items, [(i) => rank[i.status]], ['week_ending', 1], ['worker', 1], ['classification', 1]);
72
+ const byClass = {}; for (const i of out) { const c = byClass[i.classification] = byClass[i.classification] || { lines: 0, hours: 0, owed: 0 }; c.lines++; c.hours = round2(c.hours + i.hours + i.overtime_hours); c.owed = round2(c.owed + i.owed); }
73
+ const count = (st) => out.filter((i) => i.status === st).length;
74
+ const r = {
75
+ lines: out.length, workers: new Set(out.map((i) => i.worker.toLowerCase())).size, weeks: new Set(out.map((i) => i.week_ending)).size, hours: round2(out.reduce((a, i) => a + i.hours + i.overtime_hours, 0)),
76
+ owed: round2(out.reduce((a, i) => a + i.owed, 0)), underpaid: count('underpaid'), review: count('review'), ok: count('ok'),
77
+ settings_used: { ot_multiplier: mult, weekly_ot_after: otAfter, tolerance: tol }, by_classification: byClass, by_finding: byFinding(out), items: out,
78
+ };
79
+ r.summary = `${r.lines} payroll line(s), ${r.workers} worker(s), ${r.weeks} week(s), ${r.hours} hour(s): ${r.underpaid} line(s) paid below the determination (${r.owed} short), ${r.review} to review.`;
80
+ return r;
81
+ }
82
+
83
+ /** Markdown body of the correction note to payroll (internal). */
84
+ export function correctionText(r, { to, from, job }) {
85
+ const rows = r.items.filter((i) => i.status !== 'ok');
86
+ const L = [`# Certified payroll corrections${job ? `: job ${job}` : ''}`, '', `**To:** ${to || '[TO CONFIRM payroll]'}`, `**From:** ${from || '[TO CONFIRM your name]'}`, '',
87
+ `Before the certified payroll is signed and submitted, please review these ${rows.length} line(s). Amounts short are restitution to confirm, not a calculation of what the law requires [TO CONFIRM with your labor compliance adviser].`, '',
88
+ '| Week ending | Worker | Classification | Short | Problem |', '| --- | --- | --- | --- | --- |',
89
+ ...rows.map((i) => `| ${i.week_ending} | ${i.worker} | ${i.classification} | ${i.owed} | ${i.findings.map((f) => f.detail).join(' ')} |`), '',
90
+ `Total short: ${r.owed}.`];
91
+ return L.join('\n');
92
+ }