fairwire-cloud-costs 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 (Fairwire ver 1).
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,235 @@
1
- # Temporary Holding Version
1
+ # Fairwire Cloud Costs
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
+ Cloud bill review from AWS, Azure or Google Cloud cost exports: services that jumped month on month, spend with no owner tag, spend in regions you do not use, dev and test resources charged around the clock, data egress, and commitments about to expire. Drafts notes for owners; never changes a cloud account.
4
+
5
+ Part of **Fairwire**, the IT and network family of [Mythos Machines](https://fair-agents.com) agents. The software is free (MIT); you pay a fixed price for the setup on your files. It reads files your IT team exports, on your own computer, and drafts notes. Every change to a live device, firewall, DNS zone, directory or cloud account stays one named person's click.
6
+
7
+ ## What it checks
8
+
9
+ | Finding | What it means |
10
+ |---|---|
11
+ | `region_not_allowed` | Spend in a region outside your list (often a forgotten test or a mistake, sometimes a stolen account). |
12
+ | `month_jump` | A service in an account that cost much more this month than last month. |
13
+ | `untagged_spend` | A share of the month's spend with no owner tag, so nobody is accountable for it. |
14
+ | `commitment_expiring` | A savings plan, reservation or committed-use discount that ends soon; renewing or not changes next month's bill. |
15
+ | `dev_always_on` | A development or test resource billed for (almost) every hour of the month, nights and weekends included. |
16
+ | `egress_share` | Data transfer out of the cloud is a large share of an account's spend. |
17
+ | `marketplace_charge` | A marketplace or third-party charge on the cloud bill, for its owner to confirm. |
18
+
19
+ Findings come back worst first (high, medium, low). A finding a named person has reviewed can be accepted as known, with a reason and a date to look again; it then moves to "Accepted as known" instead of counting as open.
20
+
21
+ ## Settings
22
+
23
+ Pass a settings file with `settings`. Every setting is optional; a misspelt setting is refused by name.
24
+
25
+ | Setting | What it does |
26
+ |---|---|
27
+ | `allowed_regions` | Regions you use (no check when empty) |
28
+ | `jump_pct` | Month-on-month rise in percent that is flagged (default 50) |
29
+ | `jump_min` | Smallest rise in money worth flagging (default 100) |
30
+ | `untagged_pct` | Share of the month's spend with no owner above which it is flagged (default 10) |
31
+ | `dev_environments` | Environment tag values that mean development or test (default dev, test, staging, qa, sandbox) |
32
+ | `always_on_share` | Share of the month's hours that counts as always on (default 0.95) |
33
+ | `egress_pct` | Share of an account's spend on data transfer out above which it is flagged (default 10) |
34
+ | `commitment_notice_days` | Days before a commitment ends to start flagging it (default 60) |
35
+
36
+ ## What it never does
37
+
38
+ - `cloud_stop_resource` is refused: Fairwire Cloud Costs never stops, resizes or deletes a cloud resource.
39
+ - `cloud_buy_commitment` is refused: Fairwire Cloud Costs never buys or renews a savings plan, reservation or commitment.
40
+ - `cloud_costs_request_send` waits for one named person's click, even in Auto (`binding_send`).
41
+ - `cloud_costs_accept_learning` waits for one named person's click, even in Auto (`accept_learning`).
42
+ - `cloud_costs_retire_memory` waits for one named person's click, even in Auto (`accept_learning`).
43
+ - `cloud_stop_resource` waits for one named person's click, even in Auto (`production_deploy`).
44
+ - `cloud_buy_commitment` waits for one named person's click, even in Auto (`move_money`).
45
+
46
+ <!-- generated:start -->
47
+
48
+ ## A demo run
49
+
50
+ `npx -y fairwire-cloud-costs demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
51
+
52
+ ```text
53
+ Fairwire Cloud Costs demo (fictional data) in a temporary folder, Auto on for the draft only
54
+
55
+ ▶ Check the exported files
56
+ status: executed decision: allow
57
+ 2026-10: 4165 spent (previous month 2730), credits -50, 29.1% untagged: 10 open finding(s), 1 high.
58
+ high region_not_allowed prod-acct
59
+ medium commitment_expiring SP-001
60
+ medium month_jump prod-acct
61
+ medium month_jump prod-acct
62
+ medium untagged_spend 2026-10
63
+ low dev_always_on dev-acct
64
+ low dev_always_on prod-acct
65
+ low egress_share prod-acct
66
+ low marketplace_charge prod-acct
67
+ low month_jump prod-acct
68
+
69
+ ▶ Explain one finding
70
+ status: executed decision: allow
71
+ low dev_always_on: dev resource i-dev1 in dev-acct ran 744 of 744 hours in 2026-10 (310). Fix: Stop it nights and weekends with a schedule, if nobody needs it then.
72
+
73
+ ▶ Write the worklist
74
+ status: executed decision: allow
75
+ Cloud bill review written: 2026-10: 4165 spent (previous month 2730), credits -50, 29.1% untagged: 10 open finding(s), 1 high.
76
+
77
+ ▶ Draft the note for a person
78
+ status: executed decision: allow (auto)
79
+ owner note 2026-11-18 drafted with 1 open marker(s) ([TO CONFIRM account owners and finance]). Nothing was sent.
80
+
81
+ ▶ Auto: approving it still waits for one named person
82
+ status: needs_approval decision: ask
83
+ reason: binding_send stays one-click, even in Auto
84
+
85
+ ▶ The agent tries to change the live system itself
86
+ status: blocked decision: block
87
+ reason: Fairwire Cloud Costs never stops, resizes or deletes a cloud resource.
88
+ ```
89
+
90
+ ## Tools
91
+
92
+ | Tool | What it does | Policy |
93
+ |---|---|---|
94
+ | `cloud_costs_check` | Review the latest month of cloud costs against the month before and list region, jump, tagging, commitment, always-on, egress and marketplace findings. | runs |
95
+ | `cloud_costs_explain` | Every finding for one account, subscription or project. | runs |
96
+ | `cloud_costs_write_report` | Write cloud-costs.csv (one row per finding, with blank owner and decision columns) and cloud-costs.html into out_dir (default fairwire-out/cloud_costs). | runs |
97
+ | `cloud_costs_draft_owner_note` | Write drafts/owner_note-<date>.md: the open findings at or above min_severity (default medium), each with what to do, addressed to account owners and finance. | asks first (Auto can be opted in) |
98
+ | `cloud_costs_request_send` | After one named human click (even in Auto), record that the reviewed owner note draft is approved in owner_note-requests.csv. | one named click, even in Auto (`binding_send`) |
99
+ | `cloud_costs_recall` | Search this agent's own memory of the customer's setup: accepted facts (in use) and facts waiting for a person. | runs |
100
+ | `cloud_costs_learn` | Propose one fact about the customer's setup for this agent to remember. | runs |
101
+ | `cloud_costs_accept_learning` | A named person accepts or rejects a fact waiting in this agent's memory. | one named click, even in Auto (`accept_learning`) |
102
+ | `cloud_costs_retire_memory` | A named person stops an accepted fact from applying. | one named click, even in Auto (`accept_learning`) |
103
+ | `cloud_stop_resource` | Fairwire Cloud Costs never stops, resizes or deletes a cloud resource. | refused |
104
+ | `cloud_buy_commitment` | Fairwire Cloud Costs never buys or renews a savings plan, reservation or commitment. | refused |
105
+
106
+ 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.
107
+
108
+ ## Columns it reads
109
+
110
+ 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 and counts are read with either decimal mark. Every result lists under `sources` how each file was read.
111
+
112
+ ### Cloud cost lines (`costs`)
113
+
114
+ | Column | Type | Also read as | For example, in other languages |
115
+ |---|---|---|---|
116
+ | `date` (required) | date | Date, Usage Date, Billing Period, Month, lineItem/UsageStartDate, Usage start time | Datum, Date, 日付, 日期 |
117
+ | `account` | text | Account, Account ID, Subscription, SubscriptionName, Project, Project name | Konto, Compte, 勘定科目, 科目代码 |
118
+ | `service` (required) | text | Service, Product, MeterCategory, Service description, lineItem/ProductCode, Service Name | Service, Service, サービス, 服务 |
119
+ | `region` | text | Region, Location, ResourceLocation, product/region, Region/Zone | Region, Région, リージョン, 地域 |
120
+ | `resource_id` | text | Resource ID, ResourceId, lineItem/ResourceId, Resource, Resource name | - |
121
+ | `cost` (required) | amount | Cost, CostInBillingCurrency, Unblended Cost, lineItem/UnblendedCost, Cost ($), Amount | Kosten, Coût, コスト, 费用 |
122
+ | `owner` | text | Owner, Tag: owner, resourceTags/user:owner, Owner Tag, Cost Center, Team | Verantwortlich, Responsable, 担当者, 负责人 |
123
+ | `environment` | text | Environment, Env, Tag: environment, resourceTags/user:env, Stage | - |
124
+ | `usage_type` | text | Usage Type, lineItem/UsageType, MeterName, SKU description, Meter | - |
125
+ | `usage_hours` | number | Usage Hours, Hours, Running Hours, Usage Quantity (Hrs) | - |
126
+ | `charge_type` | text | Charge Type, lineItem/LineItemType, ChargeType, Cost type | - |
127
+
128
+ Named exports recognised by their column names:
129
+
130
+ | System | Export | Recognised by | Layout checked against vendor docs |
131
+ |---|---|---|---|
132
+ | Amazon Web Services | Cost and Usage Report, CSV | lineItem/UsageAccountId, lineItem/ProductCode, lineItem/UnblendedCost | no |
133
+ | Microsoft Azure | Cost details export, CSV | SubscriptionName, MeterCategory, CostInBillingCurrency | no |
134
+ | Google Cloud | Billing report downloaded as CSV | Project name, Service description, SKU description | no |
135
+
136
+ 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.
137
+
138
+ ### Commitments (`commitments`)
139
+
140
+ | Column | Type | Also read as | For example, in other languages |
141
+ |---|---|---|---|
142
+ | `commitment` (required) | text | Commitment, ID, Savings Plan ID, Reservation ID, Name | - |
143
+ | `type` | text | Type, Commitment Type, Plan Type | Typ, Type, 種類, 类型 |
144
+ | `end_date` (required) | date | End Date, Expires, Expiration, Term End | Austrittsdatum, Date de sortie, 退職日, 离职日期 |
145
+ | `monthly_amount` | amount | Monthly Amount, Monthly Commitment, Amount, Recurring Fee | - |
146
+
147
+ ### Files from other countries
148
+
149
+ 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 fairwire-cloud-costs inspect <file>` (names and shapes only, never values) and name them in `fairwire-sources.json`:
150
+
151
+ ```json
152
+ { "files": { "exports/devices.csv": { "columns": { "host": "Gerätename" }, "date_order": "dmy" } } }
153
+ ```
154
+
155
+ ## Memory
156
+
157
+ fairwire-cloud-costs can remember facts about your setup so the next run does not have to be told again. `cloud_costs_learn` only proposes a fact; it changes nothing until a named person accepts it with `cloud_costs_accept_learning`, which is one click even in Auto. Facts live in one hash-chained file per agent under `.fairwire/memory/`; if the chain does not verify, no fact is used. Credentials, personal identifiers and text that reads like instructions to an AI are refused. Run without memory with `--no-memory`.
158
+
159
+ | Kind | What an accepted fact changes |
160
+ |---|---|
161
+ | `known_exception` | that finding is listed under "Accepted as known" instead of as open, until review_by (when given) has passed. |
162
+ | `note` | nothing (shown by recall only) |
163
+
164
+ ```bash
165
+ fairwire-cloud-costs memory list
166
+ fairwire-cloud-costs memory accept MEM-1a2b3c4d5e6f --as "Your Name"
167
+ fairwire-cloud-costs memory retire MEM-1a2b3c4d5e6f --as "Your Name" --reason "rule removed"
168
+ ```
169
+
170
+ ## Install
171
+
172
+ Node 20 or newer. No other dependencies.
173
+
174
+ ```bash
175
+ npx -y fairwire-cloud-costs demo
176
+ npx -y fairwire-cloud-costs mcp --root /path/to/your/files
177
+ ```
178
+
179
+ Claude Desktop, Cursor and other MCP hosts:
180
+
181
+ ```json
182
+ {
183
+ "mcpServers": {
184
+ "fairwire-cloud-costs": {
185
+ "command": "npx",
186
+ "args": [
187
+ "-y",
188
+ "fairwire-cloud-costs",
189
+ "mcp",
190
+ "--root",
191
+ "/path/to/your/files"
192
+ ]
193
+ }
194
+ }
195
+ }
196
+ ```
197
+
198
+ Claude Code: `claude mcp add fairwire-cloud-costs -- npx -y fairwire-cloud-costs mcp --root .`, or install the `fairwire-cloud-costs` plugin from this repository's marketplace.
199
+
200
+ ## Modes and approvals
201
+
202
+ - **Review** (`--mode review`): reads and reports only.
203
+ - **Assist** (default): the policy above. A tool that asks returns an `approval_id`; a person approves it once with `fairwire-cloud-costs approve <id> --as "Your Name"` (or on the local approvals page, `fairwire-cloud-costs approvals`), and the same call is repeated.
204
+ - **Auto** (`--mode auto --auto <tool,...>`): opt-in per tool, with step caps and a kill switch (`fairwire-cloud-costs 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.
205
+
206
+ ## CLI
207
+
208
+ ```bash
209
+ fairwire-cloud-costs tools # every tool, its policy and arguments
210
+ fairwire-cloud-costs sources # the columns each input is read from
211
+ fairwire-cloud-costs inspect <file> # how a file would be read (names and shapes, never values)
212
+ fairwire-cloud-costs call cloud_costs_check '{"costs":"<costs>"}'
213
+ fairwire-cloud-costs eval # the private eval cases on the fictional fixtures
214
+ fairwire-cloud-costs demo
215
+ ```
216
+
217
+ ## Audit log and data
218
+
219
+ Every call is written to `.fairwire/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.
220
+
221
+ <!-- generated:end -->
222
+
223
+ ## Limits
224
+
225
+ - Reads only the files you export and give it. It does not log in to a firewall, switch, controller, cloud console, identity provider or any other live system.
226
+ - Amounts are the costs in your export, in its currency, before or after discounts as the export shows them; this is not an invoice check against your contract.
227
+ - Month-on-month rises compare the last two months in the file; a month that is not complete yet looks smaller.
228
+ - Thresholds are working defaults in a settings file you control; they are not a vendor rule, a requirement of any standard or a security guarantee.
229
+ - Totals are arithmetic on the numbers in your files, not forecasts or quotes.
230
+ - It changes nothing on a live device, firewall, DNS zone, directory or cloud account. Every change it suggests is a draft that one named person applies.
231
+ - Export layouts were written from knowledge of common exports and have not been tested on live customer accounts. Run `inspect` on a new export and name columns in `fairwire-sources.json` when they differ.
232
+
233
+ ## Licence
234
+
235
+ MIT. Fictional data only in `fixtures/`.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from 'node:url';
3
+ import { main } from 'fairwire-core';
4
+ import { manifest } from '../src/manifest.js';
5
+ import { demo } from '../src/demo.js';
6
+
7
+ main(manifest, { bin: 'fairwire-cloud-costs', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
@@ -0,0 +1,364 @@
1
+ {
2
+ "suite": "fairwire-cloud-costs",
3
+ "root": "..",
4
+ "data_note": "Fictional cloud costs in ../fixtures for September and October 2026, as of 2026-11-18. No model is called.",
5
+ "cases": [
6
+ {
7
+ "id": "check-totals",
8
+ "tool": "cloud_costs_check",
9
+ "args": {
10
+ "costs": "fixtures/costs.csv",
11
+ "commitments": "fixtures/commitments.csv",
12
+ "settings": "fixtures/settings.json",
13
+ "as_of": "2026-11-18"
14
+ },
15
+ "expect": {
16
+ "equals": {
17
+ "result.month": "2026-10",
18
+ "result.total": 4165,
19
+ "result.previous_total": 2730,
20
+ "result.credits": -50,
21
+ "result.untagged_pct": 29.1,
22
+ "result.open": 10,
23
+ "result.high": 1
24
+ }
25
+ }
26
+ },
27
+ {
28
+ "id": "every-planted-issue",
29
+ "tool": "cloud_costs_check",
30
+ "args": {
31
+ "costs": "fixtures/costs.csv",
32
+ "commitments": "fixtures/commitments.csv",
33
+ "settings": "fixtures/settings.json",
34
+ "as_of": "2026-11-18"
35
+ },
36
+ "expect": {
37
+ "contains": [
38
+ "region_not_allowed",
39
+ "ap-southeast-2",
40
+ "month_jump",
41
+ "+650",
42
+ "+350",
43
+ "untagged_spend",
44
+ "1210 of 4165",
45
+ "commitment_expiring",
46
+ "SP-001",
47
+ "dev_always_on",
48
+ "i-dev1",
49
+ "egress_share",
50
+ "11.9%",
51
+ "marketplace_charge"
52
+ ],
53
+ "not_contains": [
54
+ "RI-002",
55
+ "i-dev2 in"
56
+ ]
57
+ }
58
+ },
59
+ {
60
+ "id": "no-region-list-no-commitments",
61
+ "tool": "cloud_costs_check",
62
+ "args": {
63
+ "costs": "fixtures/costs.csv",
64
+ "as_of": "2026-11-18"
65
+ },
66
+ "expect": {
67
+ "equals": {
68
+ "result.open": 8,
69
+ "result.high": 0
70
+ }
71
+ }
72
+ },
73
+ {
74
+ "id": "aws-cur-layout",
75
+ "tool": "cloud_costs_check",
76
+ "args": {
77
+ "costs": "fixtures/exports/aws-cur.csv",
78
+ "settings": "fixtures/settings.json",
79
+ "as_of": "2026-11-18"
80
+ },
81
+ "expect": {
82
+ "equals": {
83
+ "result.total": 1550,
84
+ "result.previous_total": 1200
85
+ },
86
+ "contains": [
87
+ "aws_cur",
88
+ "sa-east-1"
89
+ ]
90
+ }
91
+ },
92
+ {
93
+ "id": "explain-dev-account",
94
+ "tool": "cloud_costs_explain",
95
+ "args": {
96
+ "costs": "fixtures/costs.csv",
97
+ "commitments": "fixtures/commitments.csv",
98
+ "settings": "fixtures/settings.json",
99
+ "as_of": "2026-11-18",
100
+ "account": "dev-acct"
101
+ },
102
+ "expect": {
103
+ "contains": [
104
+ "dev_always_on",
105
+ "i-dev1"
106
+ ],
107
+ "equals": {
108
+ "result.findings": 1
109
+ }
110
+ }
111
+ },
112
+ {
113
+ "id": "draft-after-approval",
114
+ "tool": "cloud_costs_draft_owner_note",
115
+ "approve": "Pat Example",
116
+ "args": {
117
+ "costs": "fixtures/costs.csv",
118
+ "commitments": "fixtures/commitments.csv",
119
+ "settings": "fixtures/settings.json",
120
+ "as_of": "2026-11-18"
121
+ },
122
+ "expect": {
123
+ "status": "executed",
124
+ "contains": [
125
+ "Nothing was sent"
126
+ ],
127
+ "equals": {
128
+ "result.items": 5,
129
+ "result.open_markers": 1
130
+ }
131
+ }
132
+ },
133
+ {
134
+ "id": "review-mode-still-reads",
135
+ "tool": "cloud_costs_check",
136
+ "mode": "review",
137
+ "args": {
138
+ "costs": "fixtures/costs.csv",
139
+ "commitments": "fixtures/commitments.csv",
140
+ "settings": "fixtures/settings.json",
141
+ "as_of": "2026-11-18"
142
+ },
143
+ "expect": {
144
+ "status": "executed",
145
+ "equals": {
146
+ "result.month": "2026-10",
147
+ "result.total": 4165,
148
+ "result.previous_total": 2730,
149
+ "result.credits": -50,
150
+ "result.untagged_pct": 29.1,
151
+ "result.open": 10,
152
+ "result.high": 1
153
+ }
154
+ },
155
+ "generated": true
156
+ },
157
+ {
158
+ "id": "severity-filter",
159
+ "tool": "cloud_costs_check",
160
+ "args": {
161
+ "costs": "fixtures/costs.csv",
162
+ "commitments": "fixtures/commitments.csv",
163
+ "settings": "fixtures/settings.json",
164
+ "as_of": "2026-11-18",
165
+ "severity": "high"
166
+ },
167
+ "expect": {
168
+ "status": "executed",
169
+ "equals": {
170
+ "result.findings": 1
171
+ }
172
+ },
173
+ "generated": true
174
+ },
175
+ {
176
+ "id": "missing-argument-named",
177
+ "tool": "cloud_costs_check",
178
+ "args": {},
179
+ "expect": {
180
+ "status": "error",
181
+ "contains": [
182
+ "costs"
183
+ ]
184
+ },
185
+ "generated": true
186
+ },
187
+ {
188
+ "id": "file-outside-root-refused",
189
+ "tool": "cloud_costs_check",
190
+ "args": {
191
+ "costs": "../../../outside.csv",
192
+ "commitments": "fixtures/commitments.csv",
193
+ "settings": "fixtures/settings.json",
194
+ "as_of": "2026-11-18"
195
+ },
196
+ "expect": {
197
+ "status": "error",
198
+ "contains": [
199
+ "outside"
200
+ ]
201
+ },
202
+ "generated": true
203
+ },
204
+ {
205
+ "id": "invented-tool-name-refused",
206
+ "tool": "cloud_costs_apply_every_fix_now",
207
+ "args": {},
208
+ "expect": {
209
+ "status": "blocked"
210
+ },
211
+ "generated": true
212
+ },
213
+ {
214
+ "id": "write-report-writes-files",
215
+ "tool": "cloud_costs_write_report",
216
+ "args": {
217
+ "costs": "fixtures/costs.csv",
218
+ "commitments": "fixtures/commitments.csv",
219
+ "settings": "fixtures/settings.json",
220
+ "as_of": "2026-11-18"
221
+ },
222
+ "expect": {
223
+ "status": "executed",
224
+ "contains": [
225
+ "cloud-costs.csv",
226
+ "cloud-costs.html"
227
+ ]
228
+ },
229
+ "generated": true
230
+ },
231
+ {
232
+ "id": "recall-memory-starts-empty",
233
+ "tool": "cloud_costs_recall",
234
+ "args": {},
235
+ "expect": {
236
+ "status": "executed",
237
+ "contains": [
238
+ "memory is empty"
239
+ ]
240
+ },
241
+ "generated": true
242
+ },
243
+ {
244
+ "id": "accept-learning-stays-one-click",
245
+ "tool": "cloud_costs_accept_learning",
246
+ "mode": "auto",
247
+ "args": {
248
+ "id": "MEM-000000000000",
249
+ "decision": "accept"
250
+ },
251
+ "expect": {
252
+ "status": "needs_approval"
253
+ },
254
+ "generated": true
255
+ },
256
+ {
257
+ "id": "never-cloud-stop-resource",
258
+ "tool": "cloud_stop_resource",
259
+ "mode": "auto",
260
+ "args": {},
261
+ "expect": {
262
+ "status": "blocked"
263
+ },
264
+ "generated": true
265
+ },
266
+ {
267
+ "id": "never-cloud-buy-commitment",
268
+ "tool": "cloud_buy_commitment",
269
+ "mode": "auto",
270
+ "args": {},
271
+ "expect": {
272
+ "status": "blocked"
273
+ },
274
+ "generated": true
275
+ },
276
+ {
277
+ "id": "draft-waits-for-a-person",
278
+ "tool": "cloud_costs_draft_owner_note",
279
+ "args": {
280
+ "costs": "fixtures/costs.csv",
281
+ "commitments": "fixtures/commitments.csv",
282
+ "settings": "fixtures/settings.json",
283
+ "as_of": "2026-11-18"
284
+ },
285
+ "expect": {
286
+ "status": "needs_approval",
287
+ "decision": "ask"
288
+ },
289
+ "generated": true
290
+ },
291
+ {
292
+ "id": "review-mode-drafts-nothing",
293
+ "tool": "cloud_costs_draft_owner_note",
294
+ "mode": "review",
295
+ "args": {
296
+ "costs": "fixtures/costs.csv",
297
+ "commitments": "fixtures/commitments.csv",
298
+ "settings": "fixtures/settings.json",
299
+ "as_of": "2026-11-18"
300
+ },
301
+ "expect": {
302
+ "status": "blocked"
303
+ },
304
+ "generated": true
305
+ },
306
+ {
307
+ "id": "request-stays-one-click",
308
+ "tool": "cloud_costs_request_send",
309
+ "mode": "auto",
310
+ "args": {
311
+ "draft": "fixtures/README.md",
312
+ "draft_sha256": "0000000000000000000000000000000000000000000000000000000000000000"
313
+ },
314
+ "expect": {
315
+ "status": "needs_approval"
316
+ },
317
+ "generated": true
318
+ },
319
+ {
320
+ "id": "intl-de-check-totals",
321
+ "tool": "cloud_costs_check",
322
+ "args": {
323
+ "costs": "fixtures/intl/de/costs.csv",
324
+ "commitments": "fixtures/intl/de/commitments.csv",
325
+ "settings": "fixtures/settings.json",
326
+ "as_of": "2026-11-18"
327
+ },
328
+ "expect": {
329
+ "equals": {
330
+ "result.month": "2026-10",
331
+ "result.total": 4165,
332
+ "result.previous_total": 2730,
333
+ "result.credits": -50,
334
+ "result.untagged_pct": 29.1,
335
+ "result.open": 10,
336
+ "result.high": 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": "cloud_costs_check",
344
+ "args": {
345
+ "costs": "fixtures/intl/ja/costs.csv",
346
+ "commitments": "fixtures/intl/ja/commitments.csv",
347
+ "settings": "fixtures/settings.json",
348
+ "as_of": "2026-11-18"
349
+ },
350
+ "expect": {
351
+ "equals": {
352
+ "result.month": "2026-10",
353
+ "result.total": 4165,
354
+ "result.previous_total": 2730,
355
+ "result.credits": -50,
356
+ "result.untagged_pct": 29.1,
357
+ "result.open": 10,
358
+ "result.high": 1
359
+ }
360
+ },
361
+ "note": "Japanese export of the same data (fixtures/intl/ja); must match the English case \"check-totals\"."
362
+ }
363
+ ]
364
+ }
@@ -0,0 +1,8 @@
1
+ # Fairwire Cloud Costs fixtures
2
+
3
+ Fictional cloud costs for September and October 2026 in two made-up accounts.
4
+
5
+ - `costs.csv`: 15 monthly lines. In October a test instance runs all month in ap-southeast-2 with no owner tag, data transfer out goes from 100 to 450, a marketplace firewall subscription appears, and a dev instance runs every hour; a promotional credit is left out of the totals.
6
+ - `commitments.csv`: a savings plan ending on 31 December and a reservation ending next June.
7
+ - `settings.json`: us-east-1 and eu-west-1 are the regions in use.
8
+ - `exports/aws-cur.csv`: three lines in AWS Cost and Usage Report column names (written from knowledge of the export, not checked against a live account), with one in a region outside the list.
@@ -0,0 +1,3 @@
1
+ commitment,type,end_date,monthly_amount
2
+ SP-001,Compute Savings Plan,2026-12-31,700
3
+ RI-002,Reserved Instance,2027-06-30,250
@@ -0,0 +1,16 @@
1
+ date,account,service,region,resource_id,cost,owner,environment,usage_type,usage_hours,charge_type
2
+ 2026-09-01,prod-acct,EC2,us-east-1,i-web1,1200,web-team,prod,BoxUsage,720,Usage
3
+ 2026-09-01,prod-acct,RDS,us-east-1,db-1,900,data-team,prod,InstanceUsage,720,Usage
4
+ 2026-09-01,prod-acct,S3,us-east-1,bucket-logs,150,,prod,TimedStorage,,Usage
5
+ 2026-09-01,prod-acct,DataTransfer,us-east-1,,100,,prod,DataTransfer-Out-Bytes,,Usage
6
+ 2026-09-01,dev-acct,EC2,us-east-1,i-dev1,300,dev-team,dev,BoxUsage,720,Usage
7
+ 2026-09-01,dev-acct,EC2,us-east-1,i-dev2,80,dev-team,dev,BoxUsage,200,Usage
8
+ 2026-10-01,prod-acct,EC2,us-east-1,i-web1,1250,web-team,prod,BoxUsage,744,Usage
9
+ 2026-10-01,prod-acct,RDS,us-east-1,db-1,910,data-team,prod,InstanceUsage,744,Usage
10
+ 2026-10-01,prod-acct,S3,us-east-1,bucket-logs,160,,prod,TimedStorage,,Usage
11
+ 2026-10-01,prod-acct,DataTransfer,us-east-1,,450,,prod,DataTransfer-Out-Bytes,,Usage
12
+ 2026-10-01,prod-acct,EC2,ap-southeast-2,i-test9,600,,test,BoxUsage,744,Usage
13
+ 2026-10-01,prod-acct,AWS Marketplace,global,fw-subscription,400,security,prod,Marketplace,,Usage
14
+ 2026-10-01,dev-acct,EC2,us-east-1,i-dev1,310,dev-team,dev,BoxUsage,744,Usage
15
+ 2026-10-01,dev-acct,EC2,us-east-1,i-dev2,85,dev-team,dev,BoxUsage,210,Usage
16
+ 2026-10-01,dev-acct,Credit,global,,-50,,,Promotional credit,,Credit
@@ -0,0 +1,4 @@
1
+ lineItem/UsageStartDate,lineItem/UsageAccountId,lineItem/ProductCode,product/region,lineItem/ResourceId,lineItem/UsageType,lineItem/LineItemType,lineItem/UnblendedCost
2
+ 2026-09-01T00:00:00Z,111122223333,AmazonEC2,us-east-1,i-web1,BoxUsage:m6i.large,Usage,1200
3
+ 2026-10-01T00:00:00Z,111122223333,AmazonEC2,us-east-1,i-web1,BoxUsage:m6i.large,Usage,1250
4
+ 2026-10-01T00:00:00Z,111122223333,AmazonEC2,sa-east-1,i-odd1,BoxUsage:m6i.large,Usage,300
@@ -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,3 @@
1
+ commitment;Typ;Austrittsdatum;monthly_amount
2
+ SP-001;Compute Savings Plan;31.12.2026;700,00
3
+ RI-002;Reserved Instance;30.06.2027;250,00
@@ -0,0 +1,16 @@
1
+ Datum;Konto;Serviceart;region;resource_id;Kosten;Verantwortlich;environment;usage_type;usage_hours;charge_type
2
+ 01.09.2026;prod-acct;EC2;us-east-1;i-web1;1.200,00;web-team;prod;BoxUsage;720;Usage
3
+ 01.09.2026;prod-acct;RDS;us-east-1;db-1;900,00;data-team;prod;InstanceUsage;720;Usage
4
+ 01.09.2026;prod-acct;S3;us-east-1;bucket-logs;150,00;;prod;TimedStorage;;Usage
5
+ 01.09.2026;prod-acct;DataTransfer;us-east-1;;100,00;;prod;DataTransfer-Out-Bytes;;Usage
6
+ 01.09.2026;dev-acct;EC2;us-east-1;i-dev1;300,00;dev-team;dev;BoxUsage;720;Usage
7
+ 01.09.2026;dev-acct;EC2;us-east-1;i-dev2;80,00;dev-team;dev;BoxUsage;200;Usage
8
+ 01.10.2026;prod-acct;EC2;us-east-1;i-web1;1.250,00;web-team;prod;BoxUsage;744;Usage
9
+ 01.10.2026;prod-acct;RDS;us-east-1;db-1;910,00;data-team;prod;InstanceUsage;744;Usage
10
+ 01.10.2026;prod-acct;S3;us-east-1;bucket-logs;160,00;;prod;TimedStorage;;Usage
11
+ 01.10.2026;prod-acct;DataTransfer;us-east-1;;450,00;;prod;DataTransfer-Out-Bytes;;Usage
12
+ 01.10.2026;prod-acct;EC2;ap-southeast-2;i-test9;600,00;;test;BoxUsage;744;Usage
13
+ 01.10.2026;prod-acct;AWS Marketplace;global;fw-subscription;400,00;security;prod;Marketplace;;Usage
14
+ 01.10.2026;dev-acct;EC2;us-east-1;i-dev1;310,00;dev-team;dev;BoxUsage;744;Usage
15
+ 01.10.2026;dev-acct;EC2;us-east-1;i-dev2;85,00;dev-team;dev;BoxUsage;210;Usage
16
+ 01.10.2026;dev-acct;Credit;global;;-50,00;;;Promotional credit;;Credit
@@ -0,0 +1,3 @@
1
+ commitment,���,�ސE��,monthly_amount
2
+ SP-001,Compute Savings Plan,2026/12/31,700.00
3
+ RI-002,Reserved Instance,2027/06/30,250.00
@@ -0,0 +1,16 @@
1
+ ���t,����Ȗ�,�T�[�r�X,���[�W����,resource_id,�R�X�g,�S����,environment,usage_type,usage_hours,charge_type
2
+ 2026/09/01,prod-acct,EC2,us-east-1,i-web1,"1,200.00",web-team,prod,BoxUsage,720,Usage
3
+ 2026/09/01,prod-acct,RDS,us-east-1,db-1,900.00,data-team,prod,InstanceUsage,720,Usage
4
+ 2026/09/01,prod-acct,S3,us-east-1,bucket-logs,150.00,,prod,TimedStorage,,Usage
5
+ 2026/09/01,prod-acct,DataTransfer,us-east-1,,100.00,,prod,DataTransfer-Out-Bytes,,Usage
6
+ 2026/09/01,dev-acct,EC2,us-east-1,i-dev1,300.00,dev-team,dev,BoxUsage,720,Usage
7
+ 2026/09/01,dev-acct,EC2,us-east-1,i-dev2,80.00,dev-team,dev,BoxUsage,200,Usage
8
+ 2026/10/01,prod-acct,EC2,us-east-1,i-web1,"1,250.00",web-team,prod,BoxUsage,744,Usage
9
+ 2026/10/01,prod-acct,RDS,us-east-1,db-1,910.00,data-team,prod,InstanceUsage,744,Usage
10
+ 2026/10/01,prod-acct,S3,us-east-1,bucket-logs,160.00,,prod,TimedStorage,,Usage
11
+ 2026/10/01,prod-acct,DataTransfer,us-east-1,,450.00,,prod,DataTransfer-Out-Bytes,,Usage
12
+ 2026/10/01,prod-acct,EC2,ap-southeast-2,i-test9,600.00,,test,BoxUsage,744,Usage
13
+ 2026/10/01,prod-acct,AWS Marketplace,global,fw-subscription,400.00,security,prod,Marketplace,,Usage
14
+ 2026/10/01,dev-acct,EC2,us-east-1,i-dev1,310.00,dev-team,dev,BoxUsage,744,Usage
15
+ 2026/10/01,dev-acct,EC2,us-east-1,i-dev2,85.00,dev-team,dev,BoxUsage,210,Usage
16
+ 2026/10/01,dev-acct,Credit,global,,-50.00,,,Promotional credit,,Credit
@@ -0,0 +1,3 @@
1
+ {
2
+ "allowed_regions": ["us-east-1", "eu-west-1"]
3
+ }
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "fairwire-cloud-costs",
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/fairwire-cloud-costs",
5
+ "description": "Fairwire Cloud Costs: Cloud bill review from AWS, Azure or Google Cloud cost exports: services that jumped month on month, spend with no owner tag, spend in regions you do not use, dev and test resources charged around the clock, data egress, and commitments about to expire. Drafts notes for owners; never changes a cloud account.",
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
+ "fairwire-cloud-costs": "bin/fairwire-cloud-costs.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/fairwire-cloud-costs.js demo",
33
+ "eval": "node bin/fairwire-cloud-costs.js eval"
34
+ },
35
+ "dependencies": {
36
+ "fairwire-core": "^0.1.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/fpavia111-creator/fairwire-agents.git",
41
+ "directory": "packages/fairwire-cloud-costs"
42
+ },
43
+ "homepage": "https://github.com/fpavia111-creator/fairwire-agents/tree/master/packages/fairwire-cloud-costs#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/fpavia111-creator/fairwire-agents/issues"
46
+ },
47
+ "keywords": [
48
+ "mcp",
49
+ "mcp-server",
50
+ "it-operations",
51
+ "network",
52
+ "fairwire",
53
+ "finops",
54
+ "cloud-cost",
55
+ "aws",
56
+ "azure",
57
+ "gcp",
58
+ "cost-and-usage-report"
59
+ ]
60
+ }
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/fairwire-cloud-costs",
4
+ "title": "Fairwire Cloud Costs",
5
+ "description": "Fairwire Cloud Costs: Cloud bill review from AWS, Azure or Google Cloud cost exports: services…",
6
+ "version": "0.1.0",
7
+ "repository": {
8
+ "url": "https://github.com/fpavia111-creator/fairwire-agents",
9
+ "source": "github",
10
+ "subfolder": "packages/fairwire-cloud-costs"
11
+ },
12
+ "websiteUrl": "https://fair-agents.com/fairwire.html",
13
+ "packages": [
14
+ {
15
+ "registryType": "npm",
16
+ "identifier": "fairwire-cloud-costs",
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,19 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { readFileSync } from 'node:fs';
3
+ import { standardDemo } from 'fairwire-core';
4
+
5
+ // The demo runs the eval case "check-totals" and the agent's draft on the fictional fixtures.
6
+ const cases = JSON.parse(readFileSync(new URL('../evals/cases.json', import.meta.url), 'utf8')).cases;
7
+ const base = cases.find((c) => c.id === 'check-totals');
8
+ const explain = cases.find((c) => /_explain$/.test(c.tool) && !c.expect.status);
9
+ const draft = cases.find((c) => /_draft_/.test(c.tool) && c.approve);
10
+
11
+ export async function demo(manifest) {
12
+ const refused = manifest.tools.filter((t) => (manifest.policy.rules.find((r) => r.tool === t.name) || {}).decision === 'block')[0];
13
+ await standardDemo(manifest, fileURLToPath(new URL('../fixtures', import.meta.url)), {
14
+ title: 'Fairwire Cloud Costs demo', args: base.args,
15
+ explain: explain ? { label: 'Explain one finding', args: explain.args } : null,
16
+ draft: draft ? { label: 'Draft the note for a person', args: draft.args } : null,
17
+ refused: refused ? refused.name : null,
18
+ });
19
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { manifest } from './manifest.js';
2
+ export * from './logic.js';
package/src/logic.js ADDED
@@ -0,0 +1,70 @@
1
+ // Fairwire Cloud Costs: cloud bill review from AWS, Azure or Google Cloud cost exports. Pure functions.
2
+ import { num, str, low, monthOf, isoDate, daysBetween, pct, round2, finding } from 'fairwire-core';
3
+
4
+ export const CHECKS = Object.freeze({
5
+ region_not_allowed: 'Spend in a region outside your list (often a forgotten test or a mistake, sometimes a stolen account).',
6
+ month_jump: 'A service in an account that cost much more this month than last month.',
7
+ untagged_spend: 'A share of the month\'s spend with no owner tag, so nobody is accountable for it.',
8
+ commitment_expiring: 'A savings plan, reservation or committed-use discount that ends soon; renewing or not changes next month\'s bill.',
9
+ dev_always_on: 'A development or test resource billed for (almost) every hour of the month, nights and weekends included.',
10
+ egress_share: 'Data transfer out of the cloud is a large share of an account\'s spend.',
11
+ marketplace_charge: 'A marketplace or third-party charge on the cloud bill, for its owner to confirm.',
12
+ });
13
+
14
+ export const COST_FIELDS = Object.freeze({
15
+ date: { type: 'date', aliases: ['Date', 'Usage Date', 'Billing Period', 'Month', 'lineItem/UsageStartDate', 'Usage start time'], required: true },
16
+ account: { aliases: ['Account', 'Account ID', 'Subscription', 'SubscriptionName', 'Project', 'Project name', 'lineItem/UsageAccountId'] },
17
+ service: { aliases: ['Service', 'Product', 'MeterCategory', 'Service description', 'lineItem/ProductCode', 'Service Name'], required: true },
18
+ region: { aliases: ['Region', 'Location', 'ResourceLocation', 'product/region', 'Region/Zone'] },
19
+ resource_id: { aliases: ['Resource ID', 'ResourceId', 'lineItem/ResourceId', 'Resource', 'Resource name'] },
20
+ cost: { type: 'money', aliases: ['Cost', 'CostInBillingCurrency', 'Unblended Cost', 'lineItem/UnblendedCost', 'Cost ($)', 'Amount'], required: true },
21
+ owner: { aliases: ['Owner', 'Tag: owner', 'resourceTags/user:owner', 'Owner Tag', 'Cost Center', 'Team'] },
22
+ environment: { aliases: ['Environment', 'Env', 'Tag: environment', 'resourceTags/user:env', 'Stage'] },
23
+ usage_type: { aliases: ['Usage Type', 'lineItem/UsageType', 'MeterName', 'SKU description', 'Meter'] },
24
+ usage_hours: { type: 'number', aliases: ['Usage Hours', 'Hours', 'Running Hours', 'Usage Quantity (Hrs)'] },
25
+ charge_type: { aliases: ['Charge Type', 'lineItem/LineItemType', 'ChargeType', 'Cost type'] },
26
+ });
27
+ export const COMMIT_FIELDS = Object.freeze({
28
+ commitment: { aliases: ['Commitment', 'ID', 'Savings Plan ID', 'Reservation ID', 'Name'], required: true },
29
+ type: { aliases: ['Type', 'Commitment Type', 'Plan Type'] },
30
+ end_date: { type: 'date', aliases: ['End Date', 'Expires', 'Expiration', 'Term End'], required: true },
31
+ monthly_amount: { type: 'money', aliases: ['Monthly Amount', 'Monthly Commitment', 'Amount', 'Recurring Fee'] },
32
+ });
33
+
34
+ export const SETTINGS_SCHEMA = { type: 'object', additionalProperties: false, properties: {
35
+ allowed_regions: { type: 'array', items: { type: 'string' }, maxItems: 100, description: 'Regions you use (no check when empty)' },
36
+ jump_pct: { type: 'number', minimum: 1, description: 'Month-on-month rise in percent that is flagged (default 50)' },
37
+ jump_min: { type: 'number', minimum: 0, description: 'Smallest rise in money worth flagging (default 100)' },
38
+ untagged_pct: { type: 'number', minimum: 0, maximum: 100, description: 'Share of the month\'s spend with no owner above which it is flagged (default 10)' },
39
+ dev_environments: { type: 'array', items: { type: 'string' }, maxItems: 20, description: 'Environment tag values that mean development or test (default dev, test, staging, qa, sandbox)' },
40
+ always_on_share: { type: 'number', minimum: 0.5, maximum: 1, description: 'Share of the month\'s hours that counts as always on (default 0.95)' },
41
+ egress_pct: { type: 'number', minimum: 1, maximum: 100, description: 'Share of an account\'s spend on data transfer out above which it is flagged (default 10)' },
42
+ commitment_notice_days: { type: 'integer', minimum: 1, description: 'Days before a commitment ends to start flagging it (default 60)' },
43
+ } };
44
+ export const DEFAULTS = Object.freeze({ allowed_regions: [], jump_pct: 50, jump_min: 100, untagged_pct: 10, dev_environments: ['dev', 'test', 'staging', 'qa', 'sandbox'], always_on_share: 0.95, egress_pct: 10, commitment_notice_days: 60 });
45
+
46
+ const isCredit = (r) => /credit|refund|discount|savingsplannegation|tax/i.test(r.charge) || r.cost < 0;
47
+ const isEgress = (r) => /datatransfer-out|data transfer out|egress|internet data transfer|outbound/i.test(`${r.usage} ${r.service}`);
48
+ const isMarket = (r) => /marketplace|third.?party/i.test(`${r.service} ${r.charge}`);
49
+ const hoursIn = (m) => { const [y, mo] = m.split('-').map(Number); return new Date(Date.UTC(y, mo, 0)).getUTCDate() * 24; };
50
+
51
+ export function reviewCloud(rows, commitRows = [], settings = {}, asOf) {
52
+ const s = { ...DEFAULTS, ...settings };
53
+ const ls = rows.map((r) => ({ month: monthOf(r.date), account: str(r.account) || '(no account)', service: str(r.service), region: low(r.region), resource: str(r.resource_id), cost: num(r.cost) || 0, owner: str(r.owner), env: low(r.environment), usage: str(r.usage_type), hours: num(r.usage_hours), charge: str(r.charge_type) })).filter((l) => l.month && l.service);
54
+ const months = [...new Set(ls.map((l) => l.month))].sort(); const cur = months.at(-1); const prev = months.at(-2);
55
+ const now = ls.filter((l) => l.month === cur && !isCredit(l)); const before = ls.filter((l) => l.month === prev && !isCredit(l));
56
+ const total = round2(now.reduce((t, l) => t + l.cost, 0)); const items = [];
57
+ const sumBy = (list, key) => { const m = new Map(); for (const l of list) m.set(key(l), round2((m.get(key(l)) || 0) + l.cost)); return m; };
58
+ if (s.allowed_regions.length) { const allowed = s.allowed_regions.map(low); const bad = sumBy(now.filter((l) => l.region && !['global', 'none', ''].includes(l.region) && !allowed.includes(l.region)), (l) => `${l.account}|${l.region}`); for (const [k, v] of bad) { const [acc, reg] = k.split('|'); items.push(finding('region_not_allowed', 'high', k, `${acc} spent ${v} in ${reg} in ${cur}, a region outside your list.`, 'Find what runs there and who started it; stop it if nobody owns it, and consider a policy that blocks the region.', { subject: acc, amount: v })); } }
59
+ if (prev) { const a = sumBy(now, (l) => `${l.account}|${l.service}`); const b = sumBy(before, (l) => `${l.account}|${l.service}`); for (const [k, v] of a) { const p = b.get(k) || 0; const d = round2(v - p); if (d >= s.jump_min && (p === 0 || (100 * d) / p >= s.jump_pct)) { const [acc, svc] = k.split('|'); items.push(finding('month_jump', p === 0 || d >= 5 * s.jump_min ? 'medium' : 'low', k, `${svc} in ${acc} cost ${v} in ${cur} against ${p} in ${prev} (+${d}).`, 'Ask the account owner what changed; look at new resources and usage types first.', { subject: acc, amount: d })); } } }
60
+ const untagged = round2(now.filter((l) => !l.owner).reduce((t, l) => t + l.cost, 0)); const up = pct(untagged, total);
61
+ if (total && up > s.untagged_pct) items.push(finding('untagged_spend', 'medium', cur, `${untagged} of ${total} spent in ${cur} (${up}%) has no owner tag.`, 'Tag the resources, or enforce an owner tag with a policy so new resources cannot be created without one.', { subject: cur, amount: untagged }));
62
+ const dev = new Set(s.dev_environments.map(low));
63
+ for (const l of now) if (dev.has(l.env) && l.hours !== null && l.hours >= s.always_on_share * hoursIn(cur)) items.push(finding('dev_always_on', 'low', l.resource || `${l.account}|${l.service}`, `${l.env} resource ${l.resource || l.service} in ${l.account} ran ${l.hours} of ${hoursIn(cur)} hours in ${cur} (${l.cost}).`, 'Stop it nights and weekends with a schedule, if nobody needs it then.', { subject: l.account, amount: l.cost }));
64
+ const byAcc = sumBy(now, (l) => l.account); const egress = sumBy(now.filter(isEgress), (l) => l.account);
65
+ for (const [acc, e] of egress) { const sh = pct(e, byAcc.get(acc)); if (sh > s.egress_pct) items.push(finding('egress_share', 'low', acc, `Data transfer out was ${e} of ${byAcc.get(acc)} in ${acc} in ${cur} (${sh}%).`, 'Find the largest sources of outbound traffic; a CDN, compression or keeping traffic in one region often helps.', { subject: acc, amount: e })); }
66
+ for (const l of now.filter(isMarket)) items.push(finding('marketplace_charge', 'low', `${l.account}|${l.resource || l.usage || l.service}`, `${l.account} paid ${l.cost} for a marketplace product (${l.resource || l.usage || l.service}) in ${cur}.`, 'Confirm with its owner that it is still used and on the right contract.', { subject: l.account, amount: l.cost }));
67
+ for (const c of commitRows) { const end = isoDate(c.end_date); if (!end || !asOf) continue; const days = daysBetween(asOf, end); if (days >= 0 && days <= s.commitment_notice_days) items.push(finding('commitment_expiring', 'medium', str(c.commitment), `${str(c.type) || 'Commitment'} ${str(c.commitment)} ends on ${end} (in ${days} days)${num(c.monthly_amount) !== null ? `; it covers ${num(c.monthly_amount)} a month` : ''}.`, 'Decide whether to renew, change or let it lapse, based on the last three months of use.', { subject: str(c.commitment), ends: end })); }
68
+ const credits = round2(ls.filter((l) => l.month === cur && isCredit(l)).reduce((t, l) => t + l.cost, 0));
69
+ return { months, month: cur || null, total, previous_total: prev ? round2(before.reduce((t, l) => t + l.cost, 0)) : null, credits, untagged_pct: total ? up : 0, by_service: [...sumBy(now, (l) => l.service).entries()].map(([service, cost]) => ({ service, cost })).sort((a, b) => b.cost - a.cost || (a.service < b.service ? -1 : 1)), items };
70
+ }
@@ -0,0 +1,41 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { wireAgent, fileArg, SETTINGS_ARG, AS_OF_ARG, settingsFrom, LIMITS, exportProfile, today } from 'fairwire-core';
3
+ import { COST_FIELDS, COMMIT_FIELDS, SETTINGS_SCHEMA, DEFAULTS, reviewCloud } from './logic.js';
4
+
5
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
6
+ const args = {
7
+ costs: fileArg('Cloud cost export under --root (AWS Cost and Usage Report, Azure cost details, Google Cloud billing export or any CSV, Excel or JSON) covering at least the last two months: one row per day or month per resource with account, service, region, cost, owner and environment tags, usage type and hours'),
8
+ commitments: fileArg('Optional list of savings plans, reservations or committed-use discounts with their end dates'),
9
+ settings: SETTINGS_ARG('allowed_regions, jump_pct, jump_min, untagged_pct, dev_environments, always_on_share, egress_pct, commitment_notice_days'),
10
+ as_of: AS_OF_ARG,
11
+ };
12
+ const PROFILES = [
13
+ exportProfile('aws_cur', { date: 'lineItem/UsageStartDate', account: 'lineItem/UsageAccountId', service: 'lineItem/ProductCode', region: 'product/region', resource_id: 'lineItem/ResourceId', cost: 'lineItem/UnblendedCost', usage_type: 'lineItem/UsageType', charge_type: 'lineItem/LineItemType' }),
14
+ exportProfile('azure_cost_details', { date: 'Date', account: 'SubscriptionName', service: 'MeterCategory', region: 'ResourceLocation', resource_id: 'ResourceId', cost: 'CostInBillingCurrency', usage_type: 'MeterName', charge_type: 'ChargeType' }),
15
+ exportProfile('gcp_billing_report', { date: 'Usage start time', account: 'Project name', service: 'Service description', usage_type: 'SKU description', cost: 'Cost ($)' }),
16
+ ];
17
+
18
+ export const manifest = wireAgent({
19
+ // Columns the "value is missing" checks depend on: an export without the column skips the check instead of flagging every row.
20
+ needs: { untagged_spend: ['owner'] },
21
+ pkg, prefix: 'cloud_costs', title: 'Fairwire Cloud Costs',
22
+ description: 'Reviews AWS, Azure and Google Cloud cost exports for the latest month: spend in regions outside your list, services that jumped month on month, spend with no owner tag, commitments about to end, dev and test resources running all month, data egress and marketplace charges. Drafts notes for owners; never changes a cloud account.',
23
+ args, required: ['costs'],
24
+ sources: { costs: { label: 'Cloud cost lines', args: ['costs'], fields: COST_FIELDS, profiles: PROFILES }, commitments: { label: 'Commitments', args: ['commitments'], fields: COMMIT_FIELDS } },
25
+ configSchemas: { cloud_costs_settings: SETTINGS_SCHEMA },
26
+ run: (a, ctx) => reviewCloud(ctx.records(a.costs, 'costs'), a.commitments ? ctx.records(a.commitments, 'commitments') : [], settingsFrom(a, ctx, 'cloud_costs_settings', DEFAULTS), a.as_of || today()),
27
+ summary: (o) => `${o.month ? `${o.month}: ${o.total} spent${o.previous_total !== null ? ` (previous month ${o.previous_total})` : ''}, credits ${o.credits}, ${o.untagged_pct}% untagged` : 'No cost lines'}: ${o.open} open finding(s), ${o.high} high.`,
28
+ check: { title: 'Review the cloud bill', description: 'Review the latest month of cloud costs against the month before and list region, jump, tagging, commitment, always-on, egress and marketplace findings.' },
29
+ explain: { arg: 'account', argSchema: { type: 'string', maxLength: 200, description: 'Account, subscription or project from cloud_costs_check' }, title: 'Explain one account', description: 'Every finding for one account, subscription or project.', match: (i, v) => i.subject === v || String(i.key).split('|')[0] === v || i.key === v },
30
+ report: {
31
+ title: 'Cloud bill review', base: 'cloud-costs',
32
+ sections: (o) => [{ title: 'By service', rows: o.by_service.slice(0, 25), columns: ['service', 'cost'] }],
33
+ limits: [LIMITS.files, 'Amounts are the costs in your export, in its currency, before or after discounts as the export shows them; this is not an invoice check against your contract.', 'Month-on-month rises compare the last two months in the file; a month that is not complete yet looks smaller.', LIMITS.defaults, LIMITS.estimate, LIMITS.live],
34
+ },
35
+ note: { noun: 'owner_note', verb: 'send', category: 'binding_send', actor: 'the cloud cost owner', to: 'account owners and finance', subject: 'Cloud spend to look at', ask: 'Please explain or fix each item; nothing is stopped or deleted until the owner agrees.' },
36
+ refused: [
37
+ { name: 'cloud_stop_resource', category: 'production_deploy', description: 'Fairwire Cloud Costs never stops, resizes or deletes a cloud resource.' },
38
+ { name: 'cloud_buy_commitment', category: 'move_money', description: 'Fairwire Cloud Costs never buys or renews a savings plan, reservation or commitment.' },
39
+ ],
40
+ prompt: { title: 'Review the cloud bill', description: 'Walks the host model through a cloud bill review with Fairwire Cloud Costs.', text: 'You are helping a finance or IT lead review the cloud bill with fairwire-cloud-costs. Fairwire Cloud Costs only reads exports. 1. Call cloud_costs_check; lead with regions outside the list and the largest jumps. 2. Use cloud_costs_explain for one account. 3. Call cloud_costs_write_report. 4. Offer cloud_costs_draft_owner_note; cloud_costs_request_send waits for one named click.' },
41
+ });