@blackbelt-technology/pi-dashboard-cost-estimator 0.7.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.
Files changed (38) hide show
  1. package/.pi/skills/software-cost-estimator/SKILL.md +200 -0
  2. package/.pi/skills/software-cost-estimator/assets/calibration/reference-classes.md +126 -0
  3. package/.pi/skills/software-cost-estimator/assets/calibration/wms-reference.yaml +217 -0
  4. package/.pi/skills/software-cost-estimator/assets/example-quality-hub.yaml +230 -0
  5. package/.pi/skills/software-cost-estimator/assets/rates.default.yaml +106 -0
  6. package/.pi/skills/software-cost-estimator/assets/templates/architecture-plan.md +115 -0
  7. package/.pi/skills/software-cost-estimator/assets/templates/offer-summary.md +99 -0
  8. package/.pi/skills/software-cost-estimator/references/ai-delivery-modes.md +276 -0
  9. package/.pi/skills/software-cost-estimator/references/business-case.md +134 -0
  10. package/.pi/skills/software-cost-estimator/references/nfr-catalog.md +112 -0
  11. package/.pi/skills/software-cost-estimator/references/rates.md +84 -0
  12. package/.pi/skills/software-cost-estimator/references/role-model.md +109 -0
  13. package/.pi/skills/software-cost-estimator/references/sizing-methods.md +147 -0
  14. package/README.md +113 -0
  15. package/bin/calibrate-sessions.mjs +12 -0
  16. package/bin/calibrate.mjs +12 -0
  17. package/bin/estimate.mjs +12 -0
  18. package/package.json +96 -0
  19. package/src/bin/calibrate-sessions.ts +247 -0
  20. package/src/bin/calibrate.ts +77 -0
  21. package/src/bin/estimate.ts +129 -0
  22. package/src/client/index.tsx +300 -0
  23. package/src/configSchema.json +56 -0
  24. package/src/engine/businesscase.ts +139 -0
  25. package/src/engine/defaults.ts +354 -0
  26. package/src/engine/effort.ts +119 -0
  27. package/src/engine/estimate.ts +135 -0
  28. package/src/engine/modes.ts +312 -0
  29. package/src/engine/report.ts +239 -0
  30. package/src/engine/roles.ts +82 -0
  31. package/src/engine/simulate.ts +114 -0
  32. package/src/engine/sizing.ts +108 -0
  33. package/src/engine/types.ts +288 -0
  34. package/src/engine/workbook.ts +143 -0
  35. package/src/engine/xlsx.ts +228 -0
  36. package/src/engine/yaml.ts +205 -0
  37. package/src/server/index.ts +123 -0
  38. package/src/telemetry/sessions.ts +380 -0
@@ -0,0 +1,300 @@
1
+ /**
2
+ * cost-estimator · CLIENT entry.
3
+ *
4
+ * Renders measured delivery telemetry: active steering hours per project, the
5
+ * meter-equivalent spend, and — when a seat plan is configured — the ACTUAL
6
+ * subscription cost plus the leverage between the two.
7
+ *
8
+ * DISPLAY INVARIANT: the meter figure is labelled "meter-equivalent" wherever it
9
+ * appears, and leverage is labelled leverage, never a saving. Presenting the
10
+ * theoretical meter as cash out is the single easiest way to make an estimate
11
+ * indefensible under scrutiny.
12
+ */
13
+ import React, { useEffect, useState } from "react";
14
+ import { usePluginConfig, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime/context";
15
+
16
+ interface Measured {
17
+ sessions: number;
18
+ activeHours: number;
19
+ steeringDays: number;
20
+ totalCost: number;
21
+ costPerSteeringHour: number;
22
+ costPerSteeringDay: number;
23
+ contextFactor: number;
24
+ revisionFactorLowerBound: number;
25
+ outputShare: number;
26
+ cacheReadShare: number;
27
+ assistantPerHumanTurn: number;
28
+ activeMonths: number;
29
+ hoursPerMonth: number;
30
+ meterPerMonth: number;
31
+ unmeteredHourShare: number;
32
+ }
33
+
34
+ interface ProjectRow {
35
+ project: string;
36
+ sessions: number;
37
+ activeHours: number;
38
+ steeringDays: number;
39
+ cost: number;
40
+ costPerHour: number;
41
+ }
42
+
43
+ interface Subscription {
44
+ monthlySeatCost: number;
45
+ months: number;
46
+ subscriptionCost: number;
47
+ meterEquivalent: number;
48
+ leverage: number;
49
+ effectiveCostPerHour: number;
50
+ meteredCostPerHour: number;
51
+ }
52
+
53
+ interface TelemetryPayload {
54
+ ok: boolean;
55
+ empty?: boolean;
56
+ error?: string;
57
+ measured: Measured | null;
58
+ projects: ProjectRow[];
59
+ subscription: Subscription | null;
60
+ seatPlan?: string;
61
+ seats?: number;
62
+ }
63
+
64
+ export interface CostEstimatorConfig {
65
+ gapCapMinutes: number;
66
+ hoursPerDay: number;
67
+ seatPlan: string;
68
+ seatMonthlyUsd: number;
69
+ seats: number;
70
+ }
71
+
72
+ const num = (value: number, digits = 0) =>
73
+ value.toLocaleString("en-US", { minimumFractionDigits: digits, maximumFractionDigits: digits });
74
+
75
+ const cell: React.CSSProperties = { padding: "4px 10px", textAlign: "right", whiteSpace: "nowrap" };
76
+ const label: React.CSSProperties = { ...cell, textAlign: "left" };
77
+ const muted: React.CSSProperties = { fontSize: "11px", opacity: 0.65 };
78
+
79
+ /** CostView — full-screen measured-cost view. Claimed on content-view + command-route. */
80
+ export function CostView() {
81
+ const [data, setData] = useState<TelemetryPayload | null>(null);
82
+ const [failed, setFailed] = useState<string | null>(null);
83
+
84
+ useEffect(() => {
85
+ let cancelled = false;
86
+ fetch("/api/cost-estimator/telemetry")
87
+ .then((response) => {
88
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
89
+ return response.json() as Promise<TelemetryPayload>;
90
+ })
91
+ .then((payload) => {
92
+ if (!cancelled) setData(payload);
93
+ })
94
+ .catch((error: unknown) => {
95
+ if (!cancelled) setFailed(error instanceof Error ? error.message : String(error));
96
+ });
97
+ return () => {
98
+ cancelled = true;
99
+ };
100
+ }, []);
101
+
102
+ if (failed) return <div style={{ padding: 16 }}>Could not load cost telemetry: {failed}</div>;
103
+ if (!data) return <div style={{ padding: 16 }}>Measuring sessions…</div>;
104
+ if (!data.ok) return <div style={{ padding: 16 }}>Cost telemetry unavailable: {data.error}</div>;
105
+ if (data.empty || !data.measured) return <div style={{ padding: 16 }}>No sessions measured yet.</div>;
106
+
107
+ const m = data.measured;
108
+ const sub = data.subscription;
109
+
110
+ return (
111
+ <div data-testid="cost-view" style={{ padding: 16, overflow: "auto", fontSize: 13 }}>
112
+ <h2 style={{ margin: "0 0 4px" }}>Measured delivery cost</h2>
113
+ <div style={muted}>
114
+ {num(m.sessions)} sessions · {num(m.activeHours, 1)} active steering hours ({num(m.steeringDays, 1)} steering-days)
115
+ · {m.activeMonths} active months · breaks over the configured gap are excluded
116
+ </div>
117
+
118
+ {sub ? (
119
+ <section style={{ marginTop: 16 }}>
120
+ <h3 style={{ margin: "0 0 4px" }}>Actual cost — subscription</h3>
121
+ <table>
122
+ <tbody>
123
+ <tr>
124
+ <td style={label}>Cash out ({data.seats}× {data.seatPlan}, {num(sub.months, 0)} mo)</td>
125
+ <td style={{ ...cell, fontWeight: 600 }}>${num(sub.subscriptionCost, 2)}</td>
126
+ </tr>
127
+ <tr>
128
+ <td style={label}>Effective per steering hour</td>
129
+ <td style={cell}>${num(sub.effectiveCostPerHour, 2)}</td>
130
+ </tr>
131
+ <tr>
132
+ <td style={label}>Meter-equivalent (theoretical, not paid)</td>
133
+ <td style={{ ...cell, opacity: 0.7 }}>${num(sub.meterEquivalent, 2)}</td>
134
+ </tr>
135
+ <tr>
136
+ <td style={label}>Subscription leverage</td>
137
+ <td style={{ ...cell, fontWeight: 600 }}>{sub.leverage.toFixed(1)}×</td>
138
+ </tr>
139
+ </tbody>
140
+ </table>
141
+ <div style={{ ...muted, marginTop: 4 }}>
142
+ {sub.leverage >= 1
143
+ ? "Leverage is on-demand value the flat plan captured — not a saving to pass on as a discount."
144
+ : "The plan costs more than metering at this volume; pay-as-you-go would be cheaper."}
145
+ </div>
146
+ </section>
147
+ ) : (
148
+ <section style={{ marginTop: 16 }}>
149
+ <h3 style={{ margin: "0 0 4px" }}>Metered basis</h3>
150
+ <div style={muted}>
151
+ No seat plan configured, so costs below are billed meter figures. If capacity is actually bought on a
152
+ subscription, set the plan in Settings — otherwise these numbers are theoretical.
153
+ </div>
154
+ </section>
155
+ )}
156
+
157
+ <section style={{ marginTop: 16 }}>
158
+ <h3 style={{ margin: "0 0 4px" }}>Meter-equivalent rates</h3>
159
+ <table>
160
+ <tbody>
161
+ <tr>
162
+ <td style={label}>Per steering hour</td>
163
+ <td style={cell}>${num(m.costPerSteeringHour, 2)}</td>
164
+ </tr>
165
+ <tr>
166
+ <td style={label}>Per steering day</td>
167
+ <td style={cell}>${num(m.costPerSteeringDay, 2)}</td>
168
+ </tr>
169
+ <tr>
170
+ <td style={label}>Per active month</td>
171
+ <td style={cell}>${num(m.meterPerMonth, 2)}</td>
172
+ </tr>
173
+ <tr>
174
+ <td style={label}>Cache-read share of tokens</td>
175
+ <td style={cell}>{(m.cacheReadShare * 100).toFixed(1)}%</td>
176
+ </tr>
177
+ <tr>
178
+ <td style={label}>Assistant turns per human turn</td>
179
+ <td style={cell}>{m.assistantPerHumanTurn.toFixed(1)} : 1</td>
180
+ </tr>
181
+ </tbody>
182
+ </table>
183
+ {m.unmeteredHourShare > 0.01 && (
184
+ <div style={{ ...muted, marginTop: 4 }}>
185
+ {(m.unmeteredHourShare * 100).toFixed(1)}% of hours ran on models the meter priced at $0 (routed or
186
+ subscription-billed) — the rates above are understated by that much.
187
+ </div>
188
+ )}
189
+ </section>
190
+
191
+ <section style={{ marginTop: 16 }}>
192
+ <h3 style={{ margin: "0 0 4px" }}>By project</h3>
193
+ <table>
194
+ <thead>
195
+ <tr>
196
+ <th style={label}>Project</th>
197
+ <th style={cell}>Sessions</th>
198
+ <th style={cell}>Active h</th>
199
+ <th style={cell}>Steering days</th>
200
+ <th style={cell}>Meter $</th>
201
+ <th style={cell}>$/h</th>
202
+ </tr>
203
+ </thead>
204
+ <tbody>
205
+ {data.projects.slice(0, 25).map((row) => (
206
+ <tr key={row.project}>
207
+ <td style={label}>{row.project}</td>
208
+ <td style={cell}>{num(row.sessions)}</td>
209
+ <td style={cell}>{num(row.activeHours, 1)}</td>
210
+ <td style={cell}>{num(row.steeringDays, 1)}</td>
211
+ <td style={cell}>{num(row.cost, 0)}</td>
212
+ <td style={cell}>{num(row.costPerHour, 2)}</td>
213
+ </tr>
214
+ ))}
215
+ </tbody>
216
+ </table>
217
+ </section>
218
+
219
+ <div style={{ ...muted, marginTop: 16 }}>
220
+ Active time counts hours where a human was engaged with the session. It is not billable-hours truth, and it does
221
+ not capture work done outside the agent.
222
+ </div>
223
+ </div>
224
+ );
225
+ }
226
+
227
+ /** CostSettings — seat plan configuration. Claimed on settings-section. */
228
+ export function CostSettings() {
229
+ const config = usePluginConfig<CostEstimatorConfig>();
230
+ const send = usePluginSend();
231
+
232
+ const write = (partial: Partial<CostEstimatorConfig>) =>
233
+ send({ type: "plugin_config_write", id: "cost-estimator", config: { ...config, ...partial } });
234
+
235
+ return (
236
+ <div data-testid="cost-settings" style={{ fontSize: 12 }}>
237
+ <div style={{ ...muted, marginBottom: 6 }}>
238
+ Session cost is recorded as a metered API price. If capacity is bought on a subscription, set the plan here so
239
+ the dashboard reports real cash rather than a theoretical meter.
240
+ </div>
241
+
242
+ <label style={{ display: "block", marginBottom: 6 }}>
243
+ Seat plan{" "}
244
+ <select
245
+ data-testid="cost-seat-plan"
246
+ value={config.seatPlan ?? "anthropic-max-20x"}
247
+ onChange={(event) => write({ seatPlan: event.target.value })}
248
+ >
249
+ <option value="metered">Metered (pay-as-you-go)</option>
250
+ <option value="anthropic-pro">Claude Pro — $20</option>
251
+ <option value="anthropic-max-5x">Claude Max 5× — $100</option>
252
+ <option value="anthropic-max-20x">Claude Max 20× — $200</option>
253
+ <option value="openai-plus">ChatGPT Plus — $20</option>
254
+ <option value="openai-pro-5x">ChatGPT Pro 5× — $100</option>
255
+ <option value="openai-pro-20x">ChatGPT Pro 20× — $200</option>
256
+ <option value="glm-lite">GLM Coding Lite — $18</option>
257
+ <option value="glm-pro">GLM Coding Pro — $72</option>
258
+ <option value="glm-max">GLM Coding Max — $160</option>
259
+ <option value="custom">Custom…</option>
260
+ </select>
261
+ </label>
262
+
263
+ {config.seatPlan === "custom" && (
264
+ <label style={{ display: "block", marginBottom: 6 }}>
265
+ USD per seat per month{" "}
266
+ <input
267
+ data-testid="cost-seat-monthly"
268
+ type="number"
269
+ min={0}
270
+ value={config.seatMonthlyUsd ?? 0}
271
+ onChange={(event) => write({ seatMonthlyUsd: Number(event.target.value) })}
272
+ />
273
+ </label>
274
+ )}
275
+
276
+ <label style={{ display: "block", marginBottom: 6 }}>
277
+ Seats{" "}
278
+ <input
279
+ data-testid="cost-seats"
280
+ type="number"
281
+ min={1}
282
+ value={config.seats ?? 1}
283
+ onChange={(event) => write({ seats: Number(event.target.value) })}
284
+ />
285
+ </label>
286
+
287
+ <label style={{ display: "block" }}>
288
+ Break threshold (minutes){" "}
289
+ <input
290
+ data-testid="cost-gap-cap"
291
+ type="number"
292
+ min={1}
293
+ max={120}
294
+ value={config.gapCapMinutes ?? 15}
295
+ onChange={(event) => write({ gapCapMinutes: Number(event.target.value) })}
296
+ />
297
+ </label>
298
+ </div>
299
+ );
300
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "title": "Cost estimator",
5
+ "description": "Seat plans and rates used to turn measured session telemetry into money. The token meter is theoretical when capacity is bought on a subscription; these values give the real cash figure.",
6
+ "properties": {
7
+ "gapCapMinutes": {
8
+ "type": "integer",
9
+ "title": "Break threshold (minutes)",
10
+ "description": "A gap longer than this counts as a break, not work.",
11
+ "default": 15,
12
+ "minimum": 1,
13
+ "maximum": 120
14
+ },
15
+ "hoursPerDay": {
16
+ "type": "number",
17
+ "title": "Productive hours per man-day",
18
+ "default": 8,
19
+ "minimum": 1,
20
+ "maximum": 24
21
+ },
22
+ "seatPlan": {
23
+ "type": "string",
24
+ "title": "Seat plan",
25
+ "description": "Subscription actually paid for. Drives the real cost and the leverage ratio.",
26
+ "default": "anthropic-max-20x",
27
+ "enum": [
28
+ "metered",
29
+ "anthropic-pro",
30
+ "anthropic-max-5x",
31
+ "anthropic-max-20x",
32
+ "openai-plus",
33
+ "openai-pro-5x",
34
+ "openai-pro-20x",
35
+ "glm-lite",
36
+ "glm-pro",
37
+ "glm-max",
38
+ "custom"
39
+ ]
40
+ },
41
+ "seatMonthlyUsd": {
42
+ "type": "number",
43
+ "title": "Custom seat price (USD/seat/month)",
44
+ "description": "Used when seat plan is 'custom'.",
45
+ "default": 0,
46
+ "minimum": 0
47
+ },
48
+ "seats": {
49
+ "type": "integer",
50
+ "title": "Seats",
51
+ "default": 1,
52
+ "minimum": 1
53
+ }
54
+ },
55
+ "additionalProperties": false
56
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Business-case layer: NPV, ROI, payback, TCO, sensitivity and a scope ladder.
3
+ *
4
+ * The scope ladder is the answer to "what tasks are needed for a business case
5
+ * and with how much effort" — must/should/could tiers with the cost of each,
6
+ * so the sponsor can buy the tier they can afford instead of the whole thing.
7
+ */
8
+
9
+ import type { BusinessCaseResult, EstimateInput, ModeResult, WorkItem } from "./types.js";
10
+
11
+ export interface BusinessCaseContext {
12
+ input: EstimateInput;
13
+ items: WorkItem[];
14
+ chosenMode: ModeResult;
15
+ currency: string;
16
+ }
17
+
18
+ /** Build the full business case for the chosen delivery mode. */
19
+ export function computeBusinessCase(ctx: BusinessCaseContext): BusinessCaseResult | null {
20
+ const cfg = ctx.input.business;
21
+ if (!cfg) return null;
22
+
23
+ const discountRate = cfg.discount_rate ?? 0.12;
24
+ const horizonYears = cfg.horizon_years ?? 3;
25
+ const buildCost = ctx.chosenMode.totalCost;
26
+ const annualRunCost = (cfg.run_costs ?? []).reduce((s, r) => s + r.annual_value, 0);
27
+ const annualBenefit = (cfg.benefits ?? []).reduce(
28
+ (s, b) => s + b.annual_value * (b.confidence ?? 1),
29
+ 0,
30
+ );
31
+
32
+ const yearly: BusinessCaseResult['yearly'] = [];
33
+ let cumulative = 0;
34
+ let npv = -buildCost;
35
+
36
+ for (let year = 1; year <= horizonYears; year++) {
37
+ const benefit = (cfg.benefits ?? [])
38
+ .filter((b) => year >= (b.start_year ?? 1))
39
+ .reduce((s, b) => s + b.annual_value * (b.confidence ?? 1), 0);
40
+ const cost = annualRunCost + (year === 1 ? buildCost : 0);
41
+ const net = benefit - annualRunCost;
42
+ const discounted = net / Math.pow(1 + discountRate, year);
43
+ npv += discounted;
44
+ cumulative += net;
45
+ yearly.push({ year, cost, benefit, net, discounted, cumulative });
46
+ }
47
+
48
+ const tco = buildCost + annualRunCost * horizonYears;
49
+ const totalBenefit = yearly.reduce((s, y) => s + y.benefit, 0);
50
+ const roi = tco > 0 ? (totalBenefit - tco) / tco : 0;
51
+
52
+ return {
53
+ currency: ctx.currency,
54
+ buildCost,
55
+ annualRunCost,
56
+ annualBenefit,
57
+ horizonYears,
58
+ discountRate,
59
+ npv,
60
+ roi,
61
+ paybackYears: paybackPeriod(buildCost, yearly),
62
+ tco,
63
+ yearly,
64
+ sensitivity: sensitivity(buildCost, annualBenefit, annualRunCost, discountRate, horizonYears),
65
+ scopeLadder: scopeLadder(ctx),
66
+ };
67
+ }
68
+
69
+ /** Linear-interpolated payback period in years, or null when it never pays back. */
70
+ function paybackPeriod(buildCost: number, yearly: BusinessCaseResult['yearly']): number | null {
71
+ let cumulative = 0;
72
+ for (const row of yearly) {
73
+ const previous = cumulative;
74
+ cumulative += row.net;
75
+ if (cumulative >= buildCost) {
76
+ const needed = buildCost - previous;
77
+ return row.year - 1 + (row.net > 0 ? needed / row.net : 0);
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+
83
+ /** One-at-a-time sensitivity on the three drivers that actually move NPV. */
84
+ function sensitivity(
85
+ buildCost: number,
86
+ annualBenefit: number,
87
+ annualRunCost: number,
88
+ discountRate: number,
89
+ years: number,
90
+ ): BusinessCaseResult['sensitivity'] {
91
+ const npvOf = (cost: number, benefit: number, run: number, rate: number) => {
92
+ let value = -cost;
93
+ for (let y = 1; y <= years; y++) value += (benefit - run) / Math.pow(1 + rate, y);
94
+ return value;
95
+ };
96
+ const base = npvOf(buildCost, annualBenefit, annualRunCost, discountRate);
97
+ return [
98
+ {
99
+ driver: 'Build cost ±30%',
100
+ low: npvOf(buildCost * 1.3, annualBenefit, annualRunCost, discountRate),
101
+ base,
102
+ high: npvOf(buildCost * 0.7, annualBenefit, annualRunCost, discountRate),
103
+ },
104
+ {
105
+ driver: 'Annual benefit ±40%',
106
+ low: npvOf(buildCost, annualBenefit * 0.6, annualRunCost, discountRate),
107
+ base,
108
+ high: npvOf(buildCost, annualBenefit * 1.4, annualRunCost, discountRate),
109
+ },
110
+ {
111
+ driver: 'Run cost ±50%',
112
+ low: npvOf(buildCost, annualBenefit, annualRunCost * 1.5, discountRate),
113
+ base,
114
+ high: npvOf(buildCost, annualBenefit, annualRunCost * 0.5, discountRate),
115
+ },
116
+ ];
117
+ }
118
+
119
+ /** Cost of each must/should/could tier, cumulative — the "what can we cut" table. */
120
+ function scopeLadder(ctx: BusinessCaseContext): BusinessCaseResult['scopeLadder'] {
121
+ const tiers = ctx.input.business?.scope_tiers ?? [];
122
+ if (tiers.length === 0) return [];
123
+
124
+ const totalHours = ctx.items.reduce((s, it) => s + it.hours, 0);
125
+ const costPerHour = totalHours > 0 ? ctx.chosenMode.totalCost / totalHours : 0;
126
+ const byId = new Map(ctx.items.map((it) => [it.id, it]));
127
+
128
+ const order = ['must', 'should', 'could'];
129
+ let cumulativeCost = 0;
130
+ return tiers
131
+ .slice()
132
+ .sort((a, b) => order.indexOf(a.tier) - order.indexOf(b.tier))
133
+ .map((tier) => {
134
+ const hours = tier.use_cases.reduce((s, id) => s + (byId.get(id)?.hours ?? 0), 0);
135
+ const cost = hours * costPerHour;
136
+ cumulativeCost += cost;
137
+ return { tier: tier.tier, hours, cost, cumulativeCost };
138
+ });
139
+ }