fairbuild-backlog 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 +181 -2
- package/bin/fairbuild-backlog.js +7 -0
- package/evals/cases.json +304 -0
- package/fixtures/README.md +5 -0
- package/fixtures/history.csv +17 -0
- package/fixtures/intl/README.md +12 -0
- package/fixtures/intl/de/history.csv +17 -0
- package/fixtures/intl/ja/history.csv +17 -0
- package/fixtures/settings-typo.json +1 -0
- package/fixtures/settings-wide.json +1 -0
- package/fixtures/settings.json +1 -0
- package/package.json +57 -4
- package/server.json +37 -0
- package/src/backlog.js +72 -0
- package/src/demo.js +18 -0
- package/src/index.js +2 -0
- package/src/manifest.js +63 -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,182 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Fairbuild Backlog (`fairbuild-backlog`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Measures backlog and margin fade from month-end job history: the work left to earn and the gross profit in it, jobs whose estimated margin has faded since the first estimate or since last month, loss forecasts, margins that rose sharply and estimates not updated while the job moved. Drafts the backlog memo. Changing estimates 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-backlog demo
|
|
9
|
+
npx -y fairbuild-backlog mcp --root ./exports
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## What it needs
|
|
13
|
+
|
|
14
|
+
| Argument | What to give it |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `history` (required) | Month-end job history under --root (CSV, Excel or JSON), one row per job and period: job, period (YYYY-MM or a date), contract amount, estimated cost, cost to date. Past WIP schedules stacked together work |
|
|
17
|
+
| `settings` | Optional settings JSON (fade_settings schema): fade_pts, gain_pts, stale_move_pts |
|
|
18
|
+
|
|
19
|
+
Only `history` is required. Each optional file turns on the checks that need it.
|
|
20
|
+
|
|
21
|
+
## What it refuses, and what waits for a person
|
|
22
|
+
|
|
23
|
+
Refused in every mode (the tool is listed so an assistant can see it, and every call is blocked):
|
|
24
|
+
|
|
25
|
+
- `estimate_update`: Fairbuild Backlog never changes an estimate or a forecast.
|
|
26
|
+
- `gl_post`: Fairbuild Backlog never posts to the ledger.
|
|
27
|
+
- `email_send`: Fairbuild Backlog never sends the memo; a person sends the approved draft.
|
|
28
|
+
|
|
29
|
+
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):
|
|
30
|
+
|
|
31
|
+
- `backlog_request_send`: Approve the memo (one click)
|
|
32
|
+
|
|
33
|
+
## Checks
|
|
34
|
+
|
|
35
|
+
What `backlog_check` flags, each with the first example it finds in the fictional fixtures (the eval cases for `backlog_check`):
|
|
36
|
+
|
|
37
|
+
| Code | Example from the fixtures |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `loss_forecast` | Forecast at a loss: estimated cost 214000 on a contract of 200000 (-7%). |
|
|
40
|
+
| `margin_fade` | Margin has faded from 7% (2026-08) to -7% (2026-10), 14 points: estimated gross profit down 28000. |
|
|
41
|
+
| `fade_since_last` | Down 8 points since 2026-09 alone. |
|
|
42
|
+
| `estimate_not_updated` | Estimated cost has stayed at 240000 for three periods while the job went from 0% to 25% complete. Ask for a reforecast. |
|
|
43
|
+
| `margin_gain` | Margin has risen from 20% to 26%, 6 points. Check the estimate to complete is real and no cost is missing or misposted. |
|
|
44
|
+
|
|
45
|
+
<!-- generated:start -->
|
|
46
|
+
|
|
47
|
+
## A demo run
|
|
48
|
+
|
|
49
|
+
`npx -y fairbuild-backlog demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
Fairbuild Backlog demo (six fictional jobs, three months), Auto mode on for drafts
|
|
53
|
+
|
|
54
|
+
▶ Measure backlog and fade
|
|
55
|
+
status: executed decision: allow
|
|
56
|
+
Backlog at 2026-10: 661756.1 on 6 job(s), 106156.1 gross profit in it (16%). 1 job(s) with margin fade or a loss forecast (28000 of estimated gross profit lost), 2 to review.
|
|
57
|
+
24-103 7% -> -7% backlog 50000 fade loss_forecast, margin_fade, fade_since_last
|
|
58
|
+
24-104 20% -> 20% backlog 225000 review estimate_not_updated
|
|
59
|
+
24-105 20% -> 26% backlog 15000 review margin_gain
|
|
60
|
+
24-101 15% -> 14.29% backlog 182000 ok
|
|
61
|
+
24-106 16.67% -> 16.67% backlog 120000 ok
|
|
62
|
+
24-102 20% -> 21.15% backlog 69756.1 ok
|
|
63
|
+
|
|
64
|
+
▶ Explain job 24-103
|
|
65
|
+
status: executed decision: allow
|
|
66
|
+
24-103: fade. Margin 7% (2026-08) to -7% (2026-10); 75% complete; backlog 50000 with -3500 gross profit. Forecast at a loss: estimated cost 214000 on a contract of 200000 (-7%). Margin has faded from 7% (2026-08) to -7% (2026-10), 14 points: estimated gross profit down 28000. Down 8 points since 2026-09 alone.
|
|
67
|
+
|
|
68
|
+
▶ Write the worklist
|
|
69
|
+
status: executed decision: allow
|
|
70
|
+
Worklist written: Backlog at 2026-10: 661756.1 on 6 job(s), 106156.1 gross profit in it (16%). 1 job(s) with margin fade or a loss forecast (28000 of estimated gross profit lost), 2 to review.
|
|
71
|
+
|
|
72
|
+
▶ Draft the backlog memo (Auto is opted in for drafts here)
|
|
73
|
+
status: executed decision: allow (auto)
|
|
74
|
+
memo 2026-10 drafted for 661756.1 with 2 open marker(s) ([TO CONFIRM your name], [TO CONFIRM]). Nothing was sent.
|
|
75
|
+
|
|
76
|
+
▶ Approve sending it: one named click, even in Auto
|
|
77
|
+
status: needs_approval decision: ask
|
|
78
|
+
reason: binding_send stays one-click, even in Auto
|
|
79
|
+
|
|
80
|
+
▶ Agent tries to change an estimate itself
|
|
81
|
+
status: blocked decision: block
|
|
82
|
+
reason: Fairbuild Backlog never changes an estimate or a forecast.
|
|
83
|
+
|
|
84
|
+
Audit log: <demo folder>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Tools
|
|
88
|
+
|
|
89
|
+
| Tool | What it does | Policy |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `backlog_check` | Per job across periods: estimated margin at the first and latest period and the fade between them, fade since last period, loss forecasts, margins that rose sharply, estimates not updated while the job moved, and the … | runs |
|
|
92
|
+
| `backlog_explain` | Show one job's margin history, backlog and every finding. | runs |
|
|
93
|
+
| `backlog_write_report` | Write the backlog and fade worklist as backlog.csv (one row per item, blank decision columns for people to fill in) and backlog.html into out_dir (default fairbuild-out/backlog). | runs |
|
|
94
|
+
| `backlog_draft_memo` | Write drafts/memo-<period>.md: the backlog and fade memo for the owner or CFO, with [TO CONFIRM] for each job's cause. | asks first (Auto can be opted in) |
|
|
95
|
+
| `backlog_request_send` | After one named human click (even in Auto), record that the reviewed memo draft is approved in memo-requests.csv. | one named click, even in Auto (`binding_send`) |
|
|
96
|
+
| `estimate_update` | Fairbuild Backlog never changes an estimate or a forecast. | refused |
|
|
97
|
+
| `gl_post` | Fairbuild Backlog never posts to the ledger. | refused |
|
|
98
|
+
| `email_send` | Fairbuild Backlog never sends the memo; a person sends the approved draft. | refused |
|
|
99
|
+
|
|
100
|
+
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.
|
|
101
|
+
|
|
102
|
+
## Columns it reads
|
|
103
|
+
|
|
104
|
+
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.
|
|
105
|
+
|
|
106
|
+
### Month-end job history (`history`)
|
|
107
|
+
|
|
108
|
+
| Column | Type | Also read as | For example, in other languages |
|
|
109
|
+
|---|---|---|---|
|
|
110
|
+
| `job` (required) | text | Job, Job Number, Project, Project Number | Projekt, Chantier, 工事番号, 项目编号 |
|
|
111
|
+
| `period` (required) | text | Period, Month, Period End, As Of, Fiscal Period | Zeitraum, Période, 期間, 期间 |
|
|
112
|
+
| `contract_amount` | amount | Contract Amount, Revised Contract, Contract Value | Auftragssumme, Montant du marché, 請負金額, 合同金额 |
|
|
113
|
+
| `estimated_cost` | amount | Estimated Cost, Revised Estimated Cost, Estimated Cost at Completion, EAC | Kalkulierte Kosten, Coût prévisionnel, 実行予算, 预计总成本 |
|
|
114
|
+
| `cost_to_date` | amount | Cost to Date, JTD Cost, Actual Cost | Ist-Kosten, Réalisé, 実績, 实际成本 |
|
|
115
|
+
|
|
116
|
+
### Files from other countries
|
|
117
|
+
|
|
118
|
+
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-backlog inspect <file>` (names and shapes only, never values) and name them in `fairbuild-sources.json`:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{ "files": { "exports/bills.csv": { "columns": { "invoice_number": "Beleg" }, "date_order": "dmy" } } }
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Install
|
|
125
|
+
|
|
126
|
+
Node 20 or newer. No other dependencies.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npx -y fairbuild-backlog demo
|
|
130
|
+
npx -y fairbuild-backlog mcp --root /path/to/your/files
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Claude Desktop, Cursor and other MCP hosts:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"mcpServers": {
|
|
138
|
+
"fairbuild-backlog": {
|
|
139
|
+
"command": "npx",
|
|
140
|
+
"args": [
|
|
141
|
+
"-y",
|
|
142
|
+
"fairbuild-backlog",
|
|
143
|
+
"mcp",
|
|
144
|
+
"--root",
|
|
145
|
+
"/path/to/your/files"
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Claude Code: `claude mcp add fairbuild-backlog -- npx -y fairbuild-backlog mcp --root .`, or install the `fairbuild-backlog` plugin from this repository's marketplace.
|
|
153
|
+
|
|
154
|
+
## Modes and approvals
|
|
155
|
+
|
|
156
|
+
- **Review** (`--mode review`): reads and reports only.
|
|
157
|
+
- **Assist** (default): the policy above. A tool that asks returns an `approval_id`; a person approves it once with `fairbuild-backlog approve <id> --as "Your Name"` (or on the local approvals page, `fairbuild-backlog approvals`), and the same call is repeated.
|
|
158
|
+
- **Auto** (`--mode auto --auto <tool,...>`): opt-in per tool, with step caps and a kill switch (`fairbuild-backlog 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.
|
|
159
|
+
|
|
160
|
+
## CLI
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
fairbuild-backlog tools # every tool, its policy and arguments
|
|
164
|
+
fairbuild-backlog sources # the columns each input is read from
|
|
165
|
+
fairbuild-backlog inspect <file> # how a file would be read (names and shapes, never values)
|
|
166
|
+
fairbuild-backlog call backlog_check '{"history":"<history>"}'
|
|
167
|
+
fairbuild-backlog eval # the private eval cases on the fictional fixtures
|
|
168
|
+
fairbuild-backlog demo
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Audit log and data
|
|
172
|
+
|
|
173
|
+
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.
|
|
174
|
+
|
|
175
|
+
<!-- generated:end -->
|
|
176
|
+
|
|
177
|
+
## Limits
|
|
178
|
+
|
|
179
|
+
- Fade is measured on the estimates in your history file. Fairbuild Backlog does not know why a margin moved; the project managers do.
|
|
180
|
+
- 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.
|
|
181
|
+
- Thresholds, percentages, rates and dates come from the settings file you supply; the defaults it used are listed in the result.
|
|
182
|
+
- 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-backlog', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
|
package/evals/cases.json
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
{
|
|
2
|
+
"suite": "fairbuild-backlog",
|
|
3
|
+
"root": "..",
|
|
4
|
+
"data_note": "Six fictional jobs over three month-ends in ../fixtures. Deterministic checks; no model is called.",
|
|
5
|
+
"cases": [
|
|
6
|
+
{
|
|
7
|
+
"id": "check-totals",
|
|
8
|
+
"tool": "backlog_check",
|
|
9
|
+
"args": {
|
|
10
|
+
"history": "fixtures/history.csv",
|
|
11
|
+
"settings": "fixtures/settings.json"
|
|
12
|
+
},
|
|
13
|
+
"expect": {
|
|
14
|
+
"status": "executed",
|
|
15
|
+
"equals": {
|
|
16
|
+
"result.jobs": 6,
|
|
17
|
+
"result.latest_period": "2026-10",
|
|
18
|
+
"result.backlog": 661756.1,
|
|
19
|
+
"result.backlog_gross_profit": 106156.1,
|
|
20
|
+
"result.fade_amount": 28000,
|
|
21
|
+
"result.fade": 1,
|
|
22
|
+
"result.review": 2,
|
|
23
|
+
"result.ok": 3
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "every-planted-issue",
|
|
29
|
+
"tool": "backlog_check",
|
|
30
|
+
"args": {
|
|
31
|
+
"history": "fixtures/history.csv",
|
|
32
|
+
"settings": "fixtures/settings.json"
|
|
33
|
+
},
|
|
34
|
+
"expect": {
|
|
35
|
+
"contains": [
|
|
36
|
+
"loss_forecast",
|
|
37
|
+
"margin_fade",
|
|
38
|
+
"fade_since_last",
|
|
39
|
+
"margin_gain",
|
|
40
|
+
"estimate_not_updated"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "explain-faded-job",
|
|
46
|
+
"tool": "backlog_explain",
|
|
47
|
+
"args": {
|
|
48
|
+
"history": "fixtures/history.csv",
|
|
49
|
+
"job": "24-103"
|
|
50
|
+
},
|
|
51
|
+
"expect": {
|
|
52
|
+
"status": "executed",
|
|
53
|
+
"contains": [
|
|
54
|
+
"Margin has faded from 7% (2026-08) to -7% (2026-10), 14 points: estimated gross profit down 28000",
|
|
55
|
+
"Down 8 points since 2026-09 alone"
|
|
56
|
+
],
|
|
57
|
+
"equals": {
|
|
58
|
+
"result.item.backlog": 50000
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"id": "explain-stale-estimate",
|
|
64
|
+
"tool": "backlog_explain",
|
|
65
|
+
"args": {
|
|
66
|
+
"history": "fixtures/history.csv",
|
|
67
|
+
"job": "24-104"
|
|
68
|
+
},
|
|
69
|
+
"expect": {
|
|
70
|
+
"contains": [
|
|
71
|
+
"stayed at 240000 for three periods while the job went from 0% to 25% complete"
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": "small-moves-are-not-fade",
|
|
77
|
+
"tool": "backlog_explain",
|
|
78
|
+
"args": {
|
|
79
|
+
"history": "fixtures/history.csv",
|
|
80
|
+
"job": "24-101"
|
|
81
|
+
},
|
|
82
|
+
"expect": {
|
|
83
|
+
"equals": {
|
|
84
|
+
"result.item.status": "ok",
|
|
85
|
+
"result.item.fade_pts": 0.71
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"id": "wide-thresholds",
|
|
91
|
+
"tool": "backlog_check",
|
|
92
|
+
"args": {
|
|
93
|
+
"history": "fixtures/history.csv",
|
|
94
|
+
"settings": "fixtures/settings-wide.json"
|
|
95
|
+
},
|
|
96
|
+
"expect": {
|
|
97
|
+
"equals": {
|
|
98
|
+
"result.fade": 1,
|
|
99
|
+
"result.review": 0
|
|
100
|
+
},
|
|
101
|
+
"not_contains": [
|
|
102
|
+
"margin_fade",
|
|
103
|
+
"margin_gain",
|
|
104
|
+
"estimate_not_updated"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"id": "settings-typo-is-named",
|
|
110
|
+
"tool": "backlog_check",
|
|
111
|
+
"args": {
|
|
112
|
+
"history": "fixtures/history.csv",
|
|
113
|
+
"settings": "fixtures/settings-typo.json"
|
|
114
|
+
},
|
|
115
|
+
"expect": {
|
|
116
|
+
"status": "error",
|
|
117
|
+
"contains": [
|
|
118
|
+
"fade_settings"
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"id": "write-report-writes-files",
|
|
124
|
+
"tool": "backlog_write_report",
|
|
125
|
+
"args": {
|
|
126
|
+
"history": "fixtures/history.csv"
|
|
127
|
+
},
|
|
128
|
+
"expect": {
|
|
129
|
+
"status": "executed",
|
|
130
|
+
"length": {
|
|
131
|
+
"result.files": 2
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"id": "draft-memo",
|
|
137
|
+
"tool": "backlog_draft_memo",
|
|
138
|
+
"mode": "auto",
|
|
139
|
+
"auto_actions": [
|
|
140
|
+
"backlog_draft_memo"
|
|
141
|
+
],
|
|
142
|
+
"args": {
|
|
143
|
+
"history": "fixtures/history.csv"
|
|
144
|
+
},
|
|
145
|
+
"expect": {
|
|
146
|
+
"status": "executed",
|
|
147
|
+
"equals": {
|
|
148
|
+
"result.id": "2026-10",
|
|
149
|
+
"result.amount": 661756.1
|
|
150
|
+
},
|
|
151
|
+
"contains": [
|
|
152
|
+
"Nothing was sent"
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"id": "policy-invented-tool",
|
|
158
|
+
"tool": "backlog_pay_everything_now",
|
|
159
|
+
"args": {},
|
|
160
|
+
"expect": {
|
|
161
|
+
"status": "blocked"
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"id": "policy-file-outside-root",
|
|
166
|
+
"tool": "backlog_check",
|
|
167
|
+
"args": {
|
|
168
|
+
"history": "../../../outside-the-root.csv",
|
|
169
|
+
"settings": "fixtures/settings.json"
|
|
170
|
+
},
|
|
171
|
+
"expect": {
|
|
172
|
+
"status": "error",
|
|
173
|
+
"contains": [
|
|
174
|
+
"outside"
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"id": "policy-missing-argument-named",
|
|
180
|
+
"tool": "backlog_check",
|
|
181
|
+
"args": {},
|
|
182
|
+
"expect": {
|
|
183
|
+
"status": "error",
|
|
184
|
+
"contains": [
|
|
185
|
+
"history"
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"id": "policy-review-mode-still-reads",
|
|
191
|
+
"tool": "backlog_check",
|
|
192
|
+
"mode": "review",
|
|
193
|
+
"args": {
|
|
194
|
+
"history": "fixtures/history.csv",
|
|
195
|
+
"settings": "fixtures/settings.json"
|
|
196
|
+
},
|
|
197
|
+
"expect": {
|
|
198
|
+
"status": "executed"
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"id": "policy-review-mode-still-reports",
|
|
203
|
+
"tool": "backlog_write_report",
|
|
204
|
+
"mode": "review",
|
|
205
|
+
"args": {
|
|
206
|
+
"history": "fixtures/history.csv"
|
|
207
|
+
},
|
|
208
|
+
"expect": {
|
|
209
|
+
"status": "executed"
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"id": "policy-review-mode-blocks-draft",
|
|
214
|
+
"tool": "backlog_draft_memo",
|
|
215
|
+
"mode": "review",
|
|
216
|
+
"args": {
|
|
217
|
+
"history": "fixtures/history.csv"
|
|
218
|
+
},
|
|
219
|
+
"expect": {
|
|
220
|
+
"status": "blocked"
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"id": "policy-backlog-request-send-one-click-in-auto",
|
|
225
|
+
"tool": "backlog_request_send",
|
|
226
|
+
"mode": "auto",
|
|
227
|
+
"args": {
|
|
228
|
+
"draft": "fairbuild-out/drafts/example.md",
|
|
229
|
+
"draft_sha256": "0000000000000000000000000000000000000000000000000000000000000000"
|
|
230
|
+
},
|
|
231
|
+
"expect": {
|
|
232
|
+
"status": "needs_approval"
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"id": "policy-refuses-estimate-update",
|
|
237
|
+
"tool": "estimate_update",
|
|
238
|
+
"args": {},
|
|
239
|
+
"expect": {
|
|
240
|
+
"status": "blocked"
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"id": "policy-refuses-gl-post",
|
|
245
|
+
"tool": "gl_post",
|
|
246
|
+
"args": {},
|
|
247
|
+
"expect": {
|
|
248
|
+
"status": "blocked"
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"id": "policy-refuses-email-send",
|
|
253
|
+
"tool": "email_send",
|
|
254
|
+
"args": {},
|
|
255
|
+
"expect": {
|
|
256
|
+
"status": "blocked"
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
"id": "intl-de-check-totals",
|
|
261
|
+
"tool": "backlog_check",
|
|
262
|
+
"args": {
|
|
263
|
+
"history": "fixtures/intl/de/history.csv",
|
|
264
|
+
"settings": "fixtures/settings.json"
|
|
265
|
+
},
|
|
266
|
+
"expect": {
|
|
267
|
+
"status": "executed",
|
|
268
|
+
"equals": {
|
|
269
|
+
"result.jobs": 6,
|
|
270
|
+
"result.latest_period": "2026-10",
|
|
271
|
+
"result.backlog": 661756.1,
|
|
272
|
+
"result.backlog_gross_profit": 106156.1,
|
|
273
|
+
"result.fade_amount": 28000,
|
|
274
|
+
"result.fade": 1,
|
|
275
|
+
"result.review": 2,
|
|
276
|
+
"result.ok": 3
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
"note": "German export of the same data (fixtures/intl/de); must match the English case \"check-totals\"."
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"id": "intl-ja-check-totals",
|
|
283
|
+
"tool": "backlog_check",
|
|
284
|
+
"args": {
|
|
285
|
+
"history": "fixtures/intl/ja/history.csv",
|
|
286
|
+
"settings": "fixtures/settings.json"
|
|
287
|
+
},
|
|
288
|
+
"expect": {
|
|
289
|
+
"status": "executed",
|
|
290
|
+
"equals": {
|
|
291
|
+
"result.jobs": 6,
|
|
292
|
+
"result.latest_period": "2026-10",
|
|
293
|
+
"result.backlog": 661756.1,
|
|
294
|
+
"result.backlog_gross_profit": 106156.1,
|
|
295
|
+
"result.fade_amount": 28000,
|
|
296
|
+
"result.fade": 1,
|
|
297
|
+
"result.review": 2,
|
|
298
|
+
"result.ok": 3
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
"note": "Japanese export of the same data (fixtures/intl/ja); must match the English case \"check-totals\"."
|
|
302
|
+
}
|
|
303
|
+
]
|
|
304
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Fairbuild Backlog fixtures
|
|
2
|
+
|
|
3
|
+
Everything here is fictional: six jobs over three month-ends.
|
|
4
|
+
|
|
5
|
+
- `history.csv`: 24-103 fades from 7% to a loss of 7%; 24-105 rises from 20% to 26%; 24-104 keeps the same estimate for three months while it goes from 0% to 25% complete; 24-101 and 24-102 move less than two points; 24-106 started in October.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
job,period,contract_amount,estimated_cost,cost_to_date
|
|
2
|
+
24-101,2026-08,450000,382500,120000
|
|
3
|
+
24-101,2026-09,450000,385000,180000
|
|
4
|
+
24-101,2026-10,455000,390000,234000
|
|
5
|
+
24-102,2026-08,260000,208000,60000
|
|
6
|
+
24-102,2026-09,260000,205000,110000
|
|
7
|
+
24-102,2026-10,260000,205000,150000
|
|
8
|
+
24-103,2026-08,200000,186000,60000
|
|
9
|
+
24-103,2026-09,200000,198000,120000
|
|
10
|
+
24-103,2026-10,200000,214000,160500
|
|
11
|
+
24-104,2026-08,300000,240000,0
|
|
12
|
+
24-104,2026-09,300000,240000,20000
|
|
13
|
+
24-104,2026-10,300000,240000,60000
|
|
14
|
+
24-105,2026-08,90000,72000,20000
|
|
15
|
+
24-105,2026-09,90000,70200,40000
|
|
16
|
+
24-105,2026-10,90000,66600,55500
|
|
17
|
+
24-106,2026-10,120000,100000,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,17 @@
|
|
|
1
|
+
Projekt;Zeitraum;Auftragssumme;Kalkulierte Kosten;Ist-Kosten
|
|
2
|
+
24-101;2026-08;450.000,00;382.500,00;120.000,00
|
|
3
|
+
24-101;2026-09;450.000,00;385.000,00;180.000,00
|
|
4
|
+
24-101;2026-10;455.000,00;390.000,00;234.000,00
|
|
5
|
+
24-102;2026-08;260.000,00;208.000,00;60.000,00
|
|
6
|
+
24-102;2026-09;260.000,00;205.000,00;110.000,00
|
|
7
|
+
24-102;2026-10;260.000,00;205.000,00;150.000,00
|
|
8
|
+
24-103;2026-08;200.000,00;186.000,00;60.000,00
|
|
9
|
+
24-103;2026-09;200.000,00;198.000,00;120.000,00
|
|
10
|
+
24-103;2026-10;200.000,00;214.000,00;160.500,00
|
|
11
|
+
24-104;2026-08;300.000,00;240.000,00;0,00
|
|
12
|
+
24-104;2026-09;300.000,00;240.000,00;20.000,00
|
|
13
|
+
24-104;2026-10;300.000,00;240.000,00;60.000,00
|
|
14
|
+
24-105;2026-08;90.000,00;72.000,00;20.000,00
|
|
15
|
+
24-105;2026-09;90.000,00;70.200,00;40.000,00
|
|
16
|
+
24-105;2026-10;90.000,00;66.600,00;55.500,00
|
|
17
|
+
24-106;2026-10;120.000,00;100.000,00;0,00
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
�H���ԍ�,����,�������z,���s�\�Z,����
|
|
2
|
+
24-101,2026-08,"450,000.00","382,500.00","120,000.00"
|
|
3
|
+
24-101,2026-09,"450,000.00","385,000.00","180,000.00"
|
|
4
|
+
24-101,2026-10,"455,000.00","390,000.00","234,000.00"
|
|
5
|
+
24-102,2026-08,"260,000.00","208,000.00","60,000.00"
|
|
6
|
+
24-102,2026-09,"260,000.00","205,000.00","110,000.00"
|
|
7
|
+
24-102,2026-10,"260,000.00","205,000.00","150,000.00"
|
|
8
|
+
24-103,2026-08,"200,000.00","186,000.00","60,000.00"
|
|
9
|
+
24-103,2026-09,"200,000.00","198,000.00","120,000.00"
|
|
10
|
+
24-103,2026-10,"200,000.00","214,000.00","160,500.00"
|
|
11
|
+
24-104,2026-08,"300,000.00","240,000.00",0.00
|
|
12
|
+
24-104,2026-09,"300,000.00","240,000.00","20,000.00"
|
|
13
|
+
24-104,2026-10,"300,000.00","240,000.00","60,000.00"
|
|
14
|
+
24-105,2026-08,"90,000.00","72,000.00","20,000.00"
|
|
15
|
+
24-105,2026-09,"90,000.00","70,200.00","40,000.00"
|
|
16
|
+
24-105,2026-10,"90,000.00","66,600.00","55,500.00"
|
|
17
|
+
24-106,2026-10,"120,000.00","100,000.00",0.00
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "fade": 2 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "fade_pts": 20, "gain_pts": 10, "stale_move_pts": 50 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "fade_pts": 2, "gain_pts": 4, "stale_move_pts": 20 }
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fairbuild-backlog",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"mcpName": "io.github.fpavia111-creator/fairbuild-backlog",
|
|
5
|
+
"description": "Fairbuild Backlog: backlog and margin fade from your month-end job history: work left to earn and the gross profit in it, jobs whose estimated margin has faded since the first estimate or since last month, jobs now forecast at a loss, margins that rose suspiciously, and estimates not updated while the job moved. Drafts the backlog memo. Never changes an estimate.",
|
|
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-backlog": "bin/fairbuild-backlog.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-backlog.js demo",
|
|
33
|
+
"eval": "node bin/fairbuild-backlog.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-backlog"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/fpavia111-creator/fairbuild-agents/tree/master/packages/fairbuild-backlog#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
|
+
"backlog",
|
|
55
|
+
"margin-fade",
|
|
56
|
+
"profit-fade",
|
|
57
|
+
"wip-history"
|
|
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-backlog",
|
|
4
|
+
"title": "Fairbuild Backlog",
|
|
5
|
+
"description": "Fairbuild Backlog: backlog and margin fade from your month-end job history: work left to earn and…",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "https://github.com/fpavia111-creator/fairbuild-agents",
|
|
9
|
+
"source": "github",
|
|
10
|
+
"subfolder": "packages/fairbuild-backlog"
|
|
11
|
+
},
|
|
12
|
+
"websiteUrl": "https://fair-agents.com/fairbuild.html",
|
|
13
|
+
"packages": [
|
|
14
|
+
{
|
|
15
|
+
"registryType": "npm",
|
|
16
|
+
"identifier": "fairbuild-backlog",
|
|
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/backlog.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Fairbuild Backlog: backlog and margin fade from month-end job history. Pure functions, no I/O.
|
|
2
|
+
//
|
|
3
|
+
// Per job and period: estimated gross profit = contract - estimated cost, margin % = GP / contract.
|
|
4
|
+
// Fade = margin at the first period on file minus margin at the latest (percentage points).
|
|
5
|
+
// Backlog = contract - earned revenue (cost to cost) at the latest period.
|
|
6
|
+
import { num, str, round2, pct, monthKey, finding, orderFindings, byFinding, sortBy } from 'fairbuild-core';
|
|
7
|
+
|
|
8
|
+
const t = (aliases, extra = {}) => ({ aliases, ...extra });
|
|
9
|
+
export const HISTORY_FIELDS = Object.freeze({
|
|
10
|
+
job: t(['Job', 'Job Number', 'Project', 'Project Number'], { required: true }),
|
|
11
|
+
period: t(['Period', 'Month', 'Period End', 'As Of', 'Fiscal Period'], { required: true }),
|
|
12
|
+
contract_amount: t(['Contract Amount', 'Revised Contract', 'Contract Value'], { type: 'money' }),
|
|
13
|
+
estimated_cost: t(['Estimated Cost', 'Revised Estimated Cost', 'Estimated Cost at Completion', 'EAC'], { type: 'money' }),
|
|
14
|
+
cost_to_date: t(['Cost to Date', 'JTD Cost', 'Actual Cost'], { type: 'money' }),
|
|
15
|
+
});
|
|
16
|
+
export const FADE_SETTINGS_SCHEMA = Object.freeze({
|
|
17
|
+
type: 'object', additionalProperties: false,
|
|
18
|
+
properties: {
|
|
19
|
+
fade_pts: { type: 'number', minimum: 0, maximum: 100, description: 'Margin drop, in percentage points, that counts as fade (default 2)' },
|
|
20
|
+
gain_pts: { type: 'number', minimum: 0, maximum: 100, description: 'Margin rise, in points, worth a second look (default 4)' },
|
|
21
|
+
stale_move_pts: { type: 'number', minimum: 0, maximum: 100, description: 'An estimate unchanged for three periods while percent complete moved more than this many points is flagged (default 20)' },
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const ORDER = ['loss_forecast', 'margin_fade', 'fade_since_last', 'margin_gain', 'estimate_not_updated'];
|
|
25
|
+
const periodOf = (v) => { const s = str(v); return /^\d{4}-\d{2}$/.test(s) ? s : monthKey(s); };
|
|
26
|
+
|
|
27
|
+
export function checkBacklog({ rows, settings = {} }) {
|
|
28
|
+
const fadePts = num(settings.fade_pts) ?? 2; const gainPts = num(settings.gain_pts) ?? 4; const stalePts = num(settings.stale_move_pts) ?? 20;
|
|
29
|
+
const jobs = new Map();
|
|
30
|
+
for (const r of rows) { const j = str(r.job); const p = periodOf(r.period); if (!j || !p) continue; if (!jobs.has(j.toUpperCase())) jobs.set(j.toUpperCase(), { job: j, periods: new Map() }); jobs.get(j.toUpperCase()).periods.set(p, { period: p, contract: num(r.contract_amount) ?? 0, est: num(r.estimated_cost), cost: num(r.cost_to_date) ?? 0 }); }
|
|
31
|
+
const items = [];
|
|
32
|
+
for (const j of jobs.values()) {
|
|
33
|
+
const ps = [...j.periods.values()].sort((a, b) => (a.period < b.period ? -1 : 1));
|
|
34
|
+
const first = ps[0], last = ps.at(-1), prev = ps.length > 1 ? ps.at(-2) : null;
|
|
35
|
+
const m = (x) => (x && x.est !== null && x.contract ? pct(x.contract - x.est, x.contract, 2) : null);
|
|
36
|
+
const gp = (x) => (x && x.est !== null ? round2(x.contract - x.est) : null);
|
|
37
|
+
const pc = (x) => (x && x.est ? Math.min(1, x.cost / x.est) : null);
|
|
38
|
+
const f = []; const mf = m(first), ml = m(last), mp = m(prev);
|
|
39
|
+
if (ml !== null && ml < 0) f.push(finding('loss_forecast', gp(last), `Forecast at a loss: estimated cost ${last.est} on a contract of ${last.contract} (${ml}%).`));
|
|
40
|
+
if (mf !== null && ml !== null && mf - ml > fadePts) f.push(finding('margin_fade', round2(gp(first) - gp(last)), `Margin has faded from ${mf}% (${first.period}) to ${ml}% (${last.period}), ${round2(mf - ml)} points: estimated gross profit down ${round2(gp(first) - gp(last))}.`));
|
|
41
|
+
if (mp !== null && ml !== null && mp - ml > fadePts && prev !== first) f.push(finding('fade_since_last', round2(gp(prev) - gp(last)), `Down ${round2(mp - ml)} points since ${prev.period} alone.`));
|
|
42
|
+
if (mf !== null && ml !== null && ml - mf > gainPts) f.push(finding('margin_gain', null, `Margin has risen from ${mf}% to ${ml}%, ${round2(ml - mf)} points. Check the estimate to complete is real and no cost is missing or misposted.`));
|
|
43
|
+
if (ps.length >= 3) { const last3 = ps.slice(-3); if (last3.every((x) => x.est === last3[0].est) && pc(last3[2]) !== null && (pc(last3[2]) - pc(last3[0])) * 100 > stalePts) f.push(finding('estimate_not_updated', null, `Estimated cost has stayed at ${last3[0].est} for three periods while the job went from ${round2(pc(last3[0]) * 100)}% to ${round2(pc(last3[2]) * 100)}% complete. Ask for a reforecast.`)); }
|
|
44
|
+
const pcl = pc(last); const earned = pcl === null ? null : round2(last.contract * pcl); const backlog = earned === null ? last.contract : round2(last.contract - earned);
|
|
45
|
+
const remainingGp = pcl === null || gp(last) === null ? null : round2((1 - pcl) * gp(last));
|
|
46
|
+
const codes = f.map((x) => x.code);
|
|
47
|
+
const status = codes.some((x) => ['loss_forecast', 'margin_fade', 'fade_since_last'].includes(x)) ? 'fade' : f.length ? 'review' : 'ok';
|
|
48
|
+
items.push({ job: j.job, periods: ps.length, first_period: first.period, latest_period: last.period, contract_amount: last.contract, estimated_cost: last.est, first_margin_pct: mf, latest_margin_pct: ml, fade_pts: mf !== null && ml !== null ? round2(mf - ml) : null, percent_complete: pcl === null ? null : round2(pcl * 100), earned_revenue: earned, backlog, backlog_gross_profit: remainingGp, status, findings: orderFindings(f, ORDER) });
|
|
49
|
+
}
|
|
50
|
+
const rank = { fade: 0, review: 1, ok: 2 };
|
|
51
|
+
const out = sortBy(items, [(i) => rank[i.status]], [(i) => -(i.fade_pts ?? 0), 1], ['job', 1]);
|
|
52
|
+
const count = (st) => out.filter((i) => i.status === st).length;
|
|
53
|
+
const s = (k) => round2(out.reduce((a, i) => a + (i[k] || 0), 0));
|
|
54
|
+
const latest = out.reduce((a, i) => (i.latest_period > a ? i.latest_period : a), '');
|
|
55
|
+
const r = {
|
|
56
|
+
jobs: out.length, latest_period: latest, backlog: s('backlog'), backlog_gross_profit: s('backlog_gross_profit'), backlog_margin_pct: pct(s('backlog_gross_profit'), s('backlog')),
|
|
57
|
+
fade_amount: round2(out.flatMap((i) => i.findings).filter((x) => x.code === 'margin_fade').reduce((a, x) => a + (x.amount || 0), 0)), fade: count('fade'), review: count('review'), ok: count('ok'),
|
|
58
|
+
settings_used: { fade_pts: fadePts, gain_pts: gainPts, stale_move_pts: stalePts }, by_finding: byFinding(out), items: out,
|
|
59
|
+
};
|
|
60
|
+
r.summary = `Backlog at ${latest}: ${r.backlog} on ${r.jobs} job(s), ${r.backlog_gross_profit} gross profit in it (${r.backlog_margin_pct}%). ${r.fade} job(s) with margin fade or a loss forecast (${r.fade_amount} of estimated gross profit lost), ${r.review} to review.`;
|
|
61
|
+
return r;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Markdown body of the backlog memo. */
|
|
65
|
+
export function memoText(r, { to, from }) {
|
|
66
|
+
const L = [`# Backlog and margin fade, ${r.latest_period}`, '', `**To:** ${to || '[TO CONFIRM owner or CFO]'}`, `**From:** ${from || '[TO CONFIRM your name]'}`, '',
|
|
67
|
+
`Backlog ${r.backlog} with ${r.backlog_gross_profit} of gross profit in it (${r.backlog_margin_pct}%). Estimated gross profit lost to fade since the first estimate: ${r.fade_amount}.`, '',
|
|
68
|
+
'| Job | First margin % | Latest margin % | Fade (points) | Backlog | Finding |', '| --- | --- | --- | --- | --- | --- |',
|
|
69
|
+
...r.items.filter((i) => i.status !== 'ok').map((i) => `| ${i.job} | ${i.first_margin_pct ?? ''} | ${i.latest_margin_pct ?? ''} | ${i.fade_pts ?? ''} | ${i.backlog} | ${i.findings.map((f) => f.detail).join(' ')} |`),
|
|
70
|
+
'', 'Cause of fade per job (from the project managers): [TO CONFIRM]'];
|
|
71
|
+
return L.join('\n');
|
|
72
|
+
}
|
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: ['backlog_draft_memo'] });
|
|
6
|
+
process.stdout.write(`Fairbuild Backlog demo (six fictional jobs, three months) in ${rt.root}, Auto mode on for drafts\n`);
|
|
7
|
+
const f = { history: 'history.csv', settings: 'settings.json' };
|
|
8
|
+
const a = await rt.call('backlog_check', f);
|
|
9
|
+
printStep('Measure backlog and fade', a);
|
|
10
|
+
for (const i of a.result.items) process.stdout.write(` ${i.job} ${String(i.first_margin_pct).padStart(6)}% -> ${String(i.latest_margin_pct).padStart(6)}% backlog ${String(i.backlog).padStart(9)} ${i.status.padEnd(6)} ${i.findings.map((x) => x.code).join(', ')}\n`);
|
|
11
|
+
printStep('Explain job 24-103', await rt.call('backlog_explain', { ...f, job: '24-103' }));
|
|
12
|
+
printStep('Write the worklist', await rt.call('backlog_write_report', f));
|
|
13
|
+
const d = await rt.call('backlog_draft_memo', { ...f, to: 'Owner (fictional)' });
|
|
14
|
+
printStep('Draft the backlog memo (Auto is opted in for drafts here)', d);
|
|
15
|
+
printStep('Approve sending it: one named click, even in Auto', await rt.call('backlog_request_send', { draft: d.result.draft, draft_sha256: d.result.draft_sha256 }));
|
|
16
|
+
printStep('Agent tries to change an estimate itself', await rt.call('estimate_update', {}));
|
|
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,63 @@
|
|
|
1
|
+
import { defineManifest, MODEL_PIN, standardTools, draftPair, refusedTools } from 'fairbuild-core';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { checkBacklog, memoText, HISTORY_FIELDS, FADE_SETTINGS_SCHEMA } from './backlog.js';
|
|
4
|
+
|
|
5
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
6
|
+
const OUT = 'fairbuild-out/backlog';
|
|
7
|
+
const props = {
|
|
8
|
+
history: { type: 'string', description: 'Month-end job history under --root (CSV, Excel or JSON), one row per job and period: job, period (YYYY-MM or a date), contract amount, estimated cost, cost to date. Past WIP schedules stacked together work' },
|
|
9
|
+
settings: { type: 'string', description: 'Optional settings JSON (fade_settings schema): fade_pts, gain_pts, stale_move_pts' },
|
|
10
|
+
};
|
|
11
|
+
const run = (a, ctx) => checkBacklog({ rows: ctx.records(a.history, 'history'), settings: a.settings ? ctx.readJson(a.settings, 'fade_settings') : {} });
|
|
12
|
+
const std = standardTools({
|
|
13
|
+
prefix: 'backlog', outDir: OUT, props, required: ['history'], run,
|
|
14
|
+
check: { title: 'Measure backlog and margin fade', description: 'Per job across periods: estimated margin at the first and latest period and the fade between them, fade since last period, loss forecasts, margins that rose sharply, estimates not updated while the job moved, and the backlog (contract less earned revenue) with the gross profit still in it.' },
|
|
15
|
+
explain: { arg: 'job', argDoc: 'Job number from backlog_check', key: (i) => i.job, title: 'Explain one job',
|
|
16
|
+
description: 'Show one job\'s margin history, backlog and every finding.',
|
|
17
|
+
describe: (i) => `${i.job}: ${i.status}. Margin ${i.first_margin_pct ?? '?'}% (${i.first_period}) to ${i.latest_margin_pct ?? '?'}% (${i.latest_period}); ${i.percent_complete ?? '?'}% complete; backlog ${i.backlog} with ${i.backlog_gross_profit ?? 'n/a'} gross profit. ${i.findings.map((f) => f.detail).join(' ')}`.trim() },
|
|
18
|
+
report: { base: 'backlog', title: 'Backlog and margin fade', description: 'Write the backlog and fade worklist',
|
|
19
|
+
row: (i) => ({ job: i.job, periods: i.periods, first_period: i.first_period, latest_period: i.latest_period, contract_amount: i.contract_amount, first_margin_pct: i.first_margin_pct ?? '', latest_margin_pct: i.latest_margin_pct ?? '', fade_pts: i.fade_pts ?? '', percent_complete: i.percent_complete ?? '', backlog: i.backlog, backlog_gross_profit: i.backlog_gross_profit ?? '', status: i.status, findings: i.findings.map((f) => f.code).join(' '), reasons: i.findings.map((f) => f.detail).join(' ') }),
|
|
20
|
+
columns: ['job', 'periods', 'first_period', 'latest_period', 'contract_amount', 'first_margin_pct', 'latest_margin_pct', 'fade_pts', 'percent_complete', 'backlog', 'backlog_gross_profit', 'status', 'findings', 'reasons'],
|
|
21
|
+
htmlColumns: ['job', 'contract_amount', 'first_margin_pct', 'latest_margin_pct', 'fade_pts', 'backlog', 'backlog_gross_profit', 'status', 'reasons'],
|
|
22
|
+
sections: (r) => [
|
|
23
|
+
{ title: 'Totals', rows: [{ jobs: r.jobs, backlog: r.backlog, backlog_gross_profit: r.backlog_gross_profit, backlog_margin_pct: r.backlog_margin_pct, fade_amount: r.fade_amount }], columns: ['jobs', 'backlog', 'backlog_gross_profit', 'backlog_margin_pct', 'fade_amount'] },
|
|
24
|
+
{ title: 'By finding', rows: Object.entries(r.by_finding).map(([code, v]) => ({ code, ...v })), columns: ['code', 'count', 'amount'] },
|
|
25
|
+
],
|
|
26
|
+
limits: ['files', 'settings', 'advice', 'Fade is measured on the estimates in your history file. Fairbuild Backlog does not know why a margin moved; the project managers do.'] },
|
|
27
|
+
});
|
|
28
|
+
const pair = draftPair({
|
|
29
|
+
prefix: 'backlog', noun: 'memo', verb: 'send', category: 'binding_send', outDir: OUT, actor: 'a person on your team',
|
|
30
|
+
description: 'Write drafts/memo-<period>.md: the backlog and fade memo for the owner or CFO, with [TO CONFIRM] for each job\'s cause. Marked DRAFT. Sending goes through backlog_request_send (one click).',
|
|
31
|
+
required: ['history'],
|
|
32
|
+
args: { ...props, to: { type: 'string', maxLength: 200, description: 'Owner or CFO' }, from: { type: 'string', maxLength: 200, description: 'Your name' } },
|
|
33
|
+
build: (a, ctx) => { const r = run(a, ctx); if (!r.jobs) throw new Error('the history file has no jobs'); return { id: r.latest_period, to: a.to || undefined, text: memoText(r, a), amount: r.backlog }; },
|
|
34
|
+
});
|
|
35
|
+
const refused = refusedTools([
|
|
36
|
+
{ name: 'estimate_update', category: 'production_deploy', description: 'Fairbuild Backlog never changes an estimate or a forecast.' },
|
|
37
|
+
{ name: 'gl_post', category: 'production_deploy', description: 'Fairbuild Backlog never posts to the ledger.' },
|
|
38
|
+
{ name: 'email_send', category: 'binding_send', description: 'Fairbuild Backlog never sends the memo; a person sends the approved draft.' },
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export const manifest = defineManifest({
|
|
42
|
+
name: 'fairbuild-backlog', version: pkg.version,
|
|
43
|
+
description: 'Measures backlog and margin fade from month-end job history: the work left to earn and the gross profit in it, jobs whose estimated margin has faded since the first estimate or since last month, loss forecasts, margins that rose sharply and estimates not updated while the job moved. Drafts the backlog memo. Changing estimates is a person\'s job.',
|
|
44
|
+
model: MODEL_PIN,
|
|
45
|
+
caps: { maxSteps: 60, maxSpendUsd: 0 },
|
|
46
|
+
configSchemas: { fade_settings: FADE_SETTINGS_SCHEMA },
|
|
47
|
+
sources: { history: { label: 'Month-end job history', args: ['history'], fields: HISTORY_FIELDS } },
|
|
48
|
+
prompts: [{
|
|
49
|
+
name: 'backlog_review', title: 'Monthly backlog and fade review',
|
|
50
|
+
description: 'Walks the host model through backlog and fade with Fairbuild Backlog.',
|
|
51
|
+
arguments: [{ name: 'history', description: 'Month-end job history', required: true }],
|
|
52
|
+
text: `You are helping a construction CFO or controller review backlog and margin fade with fairbuild-backlog. History: {{history}}.
|
|
53
|
+
|
|
54
|
+
Rules: Fairbuild Backlog never changes estimates or posts; estimate_update, gl_post and email_send are blocked. Do not guess why a margin moved.
|
|
55
|
+
|
|
56
|
+
1. Call backlog_check. Lead with total backlog and its gross profit, then loss forecasts and fade, then sharp gains and stale estimates.
|
|
57
|
+
2. Call backlog_explain for jobs the person asks about.
|
|
58
|
+
3. Call backlog_write_report and share the paths.
|
|
59
|
+
4. Offer backlog_draft_memo; only when the person asks, call backlog_request_send. It needs one named human click.`,
|
|
60
|
+
}],
|
|
61
|
+
tools: [...std.tools, ...pair.tools, ...refused.tools],
|
|
62
|
+
policy: { rules: [...std.rules, ...pair.rules, ...refused.rules, { tool: '*', decision: 'block', reason: 'Not on the Fairbuild Backlog allowlist.' }] },
|
|
63
|
+
});
|