@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,354 @@
1
+ /**
2
+ * Default constants for the estimator.
3
+ *
4
+ * RULE: every constant below carries a `src` note. Anything without published or
5
+ * locally measured grounding is marked UNCALIBRATED and must be tuned per project
6
+ * before an estimate leaves the building.
7
+ */
8
+
9
+ import type { AiClass, DeliveryMode, Phase, RiskLevel } from "./types.js";
10
+
11
+ /** Use Case Points — unadjusted use case weights (Karner). */
12
+ export const UUCW_BANDS = [
13
+ { max: 3, weight: 5, band: 'simple' },
14
+ { max: 7, weight: 10, band: 'average' },
15
+ { max: Infinity, weight: 15, band: 'complex' },
16
+ ] as const;
17
+ export const UUCW_SRC = 'Karner UCP: <=3 tx simple=5, 4-7 average=10, >7 complex=15';
18
+
19
+ /** Use Case Points — unadjusted actor weights (Karner). */
20
+ export const UAW_WEIGHTS = { api: 1, protocol: 2, human: 3 } as const;
21
+ export const UAW_SRC = 'Karner UCP: API actor=1, protocol/DB actor=2, human GUI actor=3';
22
+
23
+ /** UCP technical factors T1..T13 with Karner weights. */
24
+ export const TECHNICAL_FACTORS: Record<string, { weight: number; label: string }> = {
25
+ T1: { weight: 2.0, label: 'Distributed system' },
26
+ T2: { weight: 1.0, label: 'Response time / throughput objectives' },
27
+ T3: { weight: 1.0, label: 'End-user efficiency' },
28
+ T4: { weight: 1.0, label: 'Complex internal processing' },
29
+ T5: { weight: 1.0, label: 'Reusable code' },
30
+ T6: { weight: 0.5, label: 'Easy to install' },
31
+ T7: { weight: 0.5, label: 'Easy to use' },
32
+ T8: { weight: 2.0, label: 'Portable' },
33
+ T9: { weight: 1.0, label: 'Easy to change' },
34
+ T10: { weight: 1.0, label: 'Concurrent' },
35
+ T11: { weight: 1.0, label: 'Special security objectives' },
36
+ T12: { weight: 1.0, label: 'Direct access for third parties' },
37
+ T13: { weight: 1.0, label: 'Special user training facilities' },
38
+ };
39
+
40
+ /** UCP environmental factors E1..E8 with Karner weights. */
41
+ export const ENVIRONMENTAL_FACTORS: Record<string, { weight: number; label: string }> = {
42
+ E1: { weight: 1.5, label: 'Familiarity with the development process' },
43
+ E2: { weight: 0.5, label: 'Application experience' },
44
+ E3: { weight: 1.0, label: 'Object-oriented / paradigm experience' },
45
+ E4: { weight: 0.5, label: 'Lead analyst capability' },
46
+ E5: { weight: 1.0, label: 'Motivation' },
47
+ E6: { weight: 2.0, label: 'Stable requirements' },
48
+ E7: { weight: -1.0, label: 'Part-time staff' },
49
+ E8: { weight: -1.0, label: 'Difficult programming language' },
50
+ };
51
+
52
+ export const TCF_BASE = 0.6;
53
+ export const TCF_COEFF = 0.01;
54
+ export const ECF_BASE = 1.4;
55
+ export const ECF_COEFF = -0.03;
56
+ export const UCP_FACTOR_SRC = 'Karner: TCF = 0.6 + 0.01*TF ; ECF = 1.4 - 0.03*EF';
57
+
58
+ /** Hours per UCP. Karner 20; industry practice 15-30; local offers imply ~20-28. */
59
+ export const DEFAULT_HOURS_PER_UCP = 20;
60
+ export const HOURS_PER_UCP_SRC = 'Karner original 20 h/UCP; practice range 15-30. OVERRIDE with project actuals.';
61
+
62
+ /** Reference project size used to apply the COCOMO scale exponent to a UCP estimate. */
63
+ export const DEFAULT_REFERENCE_UCP = 100;
64
+ export const REFERENCE_UCP_SRC = 'UNCALIBRATED anchor: the size at which hours_per_ucp is assumed true.';
65
+
66
+ /** COCOMO II.2000 Post-Architecture constants (USC Model Definition Manual). */
67
+ export const COCOMO = {
68
+ A: 2.94,
69
+ B: 0.91,
70
+ C: 3.67,
71
+ D: 0.28,
72
+ } as const;
73
+ export const COCOMO_SRC = 'COCOMO II.2000 Model Definition Manual (USC): A=2.94, B=0.91, C=3.67, D=0.28';
74
+
75
+ /** COCOMO II scale factor ratings. Sum feeds E = B + 0.01*sum(SF). */
76
+ export const SCALE_FACTORS: Record<string, Record<string, number>> = {
77
+ PREC: { 'very-low': 6.2, low: 4.96, nominal: 3.72, high: 2.48, 'very-high': 1.24, 'extra-high': 0.0 },
78
+ FLEX: { 'very-low': 5.07, low: 4.05, nominal: 3.04, high: 2.03, 'very-high': 1.01, 'extra-high': 0.0 },
79
+ RESL: { 'very-low': 7.07, low: 5.65, nominal: 4.24, high: 2.83, 'very-high': 1.41, 'extra-high': 0.0 },
80
+ TEAM: { 'very-low': 5.48, low: 4.38, nominal: 3.29, high: 2.19, 'very-high': 1.1, 'extra-high': 0.0 },
81
+ PMAT: { 'very-low': 7.8, low: 6.24, nominal: 4.68, high: 3.12, 'very-high': 1.56, 'extra-high': 0.0 },
82
+ };
83
+ export const SCALE_FACTOR_SRC = 'COCOMO II.2000 scale factor values (PREC, FLEX, RESL, TEAM, PMAT)';
84
+
85
+ /**
86
+ * Role effort ratios. Distribution of TOTAL project effort across roles.
87
+ * Grounded in the local offer corpus (Huawei WMS module split, Sunbloom QA share)
88
+ * and cross-checked against ISBSG role-effort-ratio guidance and McConnell ch.21.
89
+ */
90
+ export const DEFAULT_ROLE_RATIOS: Record<string, number> = {
91
+ 'Product Owner / BA': 0.07,
92
+ Architect: 0.06,
93
+ 'UX / UI Designer': 0.07,
94
+ 'Frontend Developer': 0.17,
95
+ 'Backend Developer': 0.22,
96
+ 'Data / Integration Engineer': 0.09,
97
+ 'QA / Test Automation': 0.16,
98
+ 'DevOps / SRE': 0.06,
99
+ 'Security Engineer': 0.02,
100
+ 'Tech Lead': 0.03,
101
+ 'Project Manager': 0.05,
102
+ };
103
+ export const ROLE_RATIO_SRC =
104
+ 'Local: Huawei WMS module split (QA 15.2%, PM 10%, deploy 11.9%), Sunbloom QA 17% of total. ' +
105
+ 'External: ISBSG Role Effort Ratios; McConnell Software Estimation ch.21.';
106
+
107
+ /** Ratios shift with size: bigger projects spend proportionally more on coordination and test. */
108
+ export const ROLE_RATIO_SIZE_TILT = {
109
+ /** Above this many hours, tilt toward coordination roles. */
110
+ largeThresholdHours: 4000,
111
+ tilt: { 'Project Manager': 0.02, 'QA / Test Automation': 0.02, Architect: 0.01 },
112
+ takeFrom: ['Backend Developer', 'Frontend Developer'],
113
+ } as const;
114
+
115
+ /**
116
+ * AI speedup factors per work-item class, expressed as a multiplier on human-only hours.
117
+ * < 1.0 means faster with AI. > 1.0 means slower (the METR regime).
118
+ * [optimistic, likely, pessimistic] — fed into the PERT distribution.
119
+ */
120
+ export const AI_SPEEDUP: Record<AiClass, [number, number, number]> = {
121
+ boilerplate: [0.35, 0.50, 0.70],
122
+ crud: [0.50, 0.65, 0.85],
123
+ integration: [0.70, 0.85, 1.00],
124
+ algorithmic: [0.75, 0.90, 1.05],
125
+ 'legacy-change': [0.90, 1.10, 1.30],
126
+ 'ux-heavy': [0.75, 0.90, 1.05],
127
+ docs: [0.30, 0.45, 0.65],
128
+ ops: [0.60, 0.80, 1.00],
129
+ };
130
+ export const AI_SPEEDUP_SRC = [
131
+ 'GenAI SLR + 65-dev survey (arXiv 2603.16975): >70% of devs at least halve boilerplate & documentation time.',
132
+ 'GitHub controlled lab study: up to 55% faster on a scoped task.',
133
+ 'Demirer et al. 3 field RCTs, n=4867: +26.08% completed tasks (SE 10.3%); juniors gain most.',
134
+ 'Jellyfish 146k Jira tickets: real-world effect ~8%.',
135
+ 'METR RCT 2025: experienced devs on their own mature repos were 19% SLOWER -> legacy-change > 1.0.',
136
+ ].join(' | ');
137
+
138
+ /** Codebase maturity shifts every speedup: AI helps least where the human already has deep context. */
139
+ export const CODEBASE_MODIFIER: Record<string, number> = {
140
+ greenfield: 0.92,
141
+ brownfield: 1.0,
142
+ legacy: 1.12,
143
+ };
144
+ export const CODEBASE_MODIFIER_SRC = 'Derived from METR (mature repo, expert dev => slowdown) vs greenfield lab results. UNCALIBRATED magnitude.';
145
+
146
+ /** Seniority tilts the effect: juniors gained more in the Demirer field experiments. */
147
+ export const SENIORITY_MODIFIER: Record<string, number> = {
148
+ junior: 0.90,
149
+ mid: 1.0,
150
+ senior: 1.08,
151
+ };
152
+ export const SENIORITY_MODIFIER_SRC = 'Demirer et al.: less experienced developers had higher adoption and greater gains. UNCALIBRATED magnitude.';
153
+
154
+ /** Fraction of AI-produced work that must be reviewed by a human, as a share of AI-mode hours. */
155
+ export const REVIEW_OVERHEAD: Record<DeliveryMode, number> = {
156
+ human_only: 0,
157
+ human_with_ai: 0.08,
158
+ ai_steered_human_supervised: 0.18,
159
+ agentic_hitl: 0.28,
160
+ };
161
+ export const REVIEW_OVERHEAD_SRC = 'UNCALIBRATED. Shape from DORA 2025 (AI amplifies; review becomes the constraint) and ACEM HITL cost dimension.';
162
+
163
+ /** Rework uplift from AI-induced instability, as a share of AI-mode hours. */
164
+ export const REWORK_UPLIFT: Record<DeliveryMode, number> = {
165
+ human_only: 0,
166
+ human_with_ai: 0.05,
167
+ ai_steered_human_supervised: 0.10,
168
+ agentic_hitl: 0.15,
169
+ };
170
+ export const REWORK_UPLIFT_SRC = 'DORA 2025: AI adoption raised instability / rework even as throughput recovered. UNCALIBRATED magnitude.';
171
+
172
+ /**
173
+ * ACEM (arXiv 2608.02582) agentic cost parameters.
174
+ * ACEM ships its constants SYMBOLIC — these are placeholders pending local calibration.
175
+ */
176
+ export const ACEM_DEFAULTS = {
177
+ tokensPerUcp: 250_000,
178
+ /**
179
+ * MEASURED LOWER BOUND (1.05) from 542 local sessions: 0.9% tool-error rate +
180
+ * 3.7% explicit human-correction rate. Held above the measured floor because
181
+ * that proxy cannot see tokens the agent silently redid on its own.
182
+ */
183
+ revisionFactor: 1.25,
184
+ /**
185
+ * MEASURED (5.10) from 542 local sessions: cache-read per assistant turn is
186
+ * 5.1x higher in long sessions (>=60 turns) than short ones (<=20).
187
+ * Context accumulation is real and much larger than ACEM's illustrative 1.25.
188
+ */
189
+ contextFactor: 5.1,
190
+ hitlIntensity: 2 as 1 | 2 | 3 | 4,
191
+ /**
192
+ * Human oversight effort as a SHARE OF THE HUMAN-ONLY BUILD HOURS, by HITL
193
+ * Intensity Score level. Anchored on the local measurement that ~38% of a
194
+ * pre-OSS build was active steering time (Digitalk: 16 steering days of ~42 md).
195
+ */
196
+ hitlShareOfBuild: { 1: 0.15, 2: 0.28, 3: 0.45, 4: 0.65 },
197
+ pricePerMtokIn: 3,
198
+ pricePerMtokOut: 15,
199
+ /**
200
+ * MEASURED (0.0038) from 542 local sessions. Output is a rounding error in the
201
+ * token bill: cache-read is 95.5% of all tokens. Modelling agentic cost as a
202
+ * 25/75 output/input split — as generic token-cost guidance does — overstates
203
+ * the output line by ~66x and misses where the money actually goes.
204
+ */
205
+ outputShare: 0.004,
206
+ infraMonthly: 400,
207
+ licencePerDevMonth: 40,
208
+ /**
209
+ * MEASURED: $10.41 per active steering hour across 542 sessions / 737.5 h /
210
+ * $7,676 billed. PREFERRED over reconstructing cost from RF x CF x price,
211
+ * because it already contains every revision, retry and context effect.
212
+ */
213
+ costPerSteeringHour: 10.41,
214
+ };
215
+ export const ACEM_SRC =
216
+ 'ACEM: A Cost Estimation Model for Agentic Software Engineering (arXiv 2608.02582) — LLM + HITL + infra, ' +
217
+ 'with Revision Factor, Context Factor, HITL Intensity Score. The paper leaves its constants SYMBOLIC; ' +
218
+ 'the values here are MEASURED from 542 local pi sessions (737.5 active steering hours, $7,676 billed) ' +
219
+ 'via scripts/calibrate-sessions.ts.';
220
+
221
+ /**
222
+ * Subscription (seat) plans — USD per seat per month.
223
+ *
224
+ * THIS IS THE REAL COST BASIS for most teams. Agent work is paid by flat
225
+ * subscription, not by the token meter. That changes the SHAPE of the cost:
226
+ *
227
+ * metered cost is proportional to WORK VOLUME
228
+ * subscription cost is proportional to SEATS x CALENDAR MONTHS, capped by quota
229
+ *
230
+ * Consequences the estimator must respect:
231
+ * - A longer project on the same team costs MORE in subscription even when the
232
+ * work is identical. Schedule is a cost driver here; under metering it is not.
233
+ * - Agent usage is FREE AT THE MARGIN until the quota is hit, so the incentive
234
+ * inverts: push agent utilisation up, not down.
235
+ * - Exceeding quota is a SCHEDULE risk (throttling), not a cost overrun.
236
+ *
237
+ * Prices verified 2026-08 against the providers' own pricing pages.
238
+ */
239
+ export const SUBSCRIPTION_PLANS: Record<string, { monthly: number; label: string; src: string }> = {
240
+ 'anthropic-pro': { monthly: 20, label: 'Claude Pro', src: 'claude.com/pricing' },
241
+ 'anthropic-max-5x': { monthly: 100, label: 'Claude Max 5x', src: 'claude.com/pricing' },
242
+ 'anthropic-max-20x': { monthly: 200, label: 'Claude Max 20x', src: 'claude.com/pricing' },
243
+ 'openai-plus': { monthly: 20, label: 'ChatGPT Plus', src: 'openai.com/chatgpt/pricing' },
244
+ 'openai-pro-5x': { monthly: 100, label: 'ChatGPT Pro 5x', src: 'openai.com/chatgpt/pricing' },
245
+ 'openai-pro-20x': { monthly: 200, label: 'ChatGPT Pro 20x', src: 'openai.com/chatgpt/pricing' },
246
+ 'glm-lite': { monthly: 18, label: 'GLM Coding Lite', src: 'z.ai/subscribe' },
247
+ 'glm-pro': { monthly: 72, label: 'GLM Coding Pro', src: 'z.ai/subscribe' },
248
+ 'glm-max': { monthly: 160, label: 'GLM Coding Max', src: 'z.ai/subscribe' },
249
+ };
250
+
251
+ export const SUBSCRIPTION_SRC =
252
+ 'Provider pricing pages, verified 2026-08. Monthly billing; no annual discount published for the Anthropic/OpenAI tiers.';
253
+
254
+ /** Default seat plan when a project declares subscription basis without naming one. */
255
+ export const DEFAULT_SUBSCRIPTION_PLAN = 'anthropic-max-20x';
256
+
257
+ /**
258
+ * Currency conversion for the measured cost-per-steering-hour, which is billed in USD.
259
+ * Override per project when quoting in another currency.
260
+ */
261
+ export const USD_TO_CURRENCY: Record<string, number> = { EUR: 0.92, USD: 1, HUF: 360, GBP: 0.79 };
262
+ export const USD_RATE_SRC = 'Indicative rates. Set project rates explicitly for a contractual quote.';
263
+
264
+ /**
265
+ * Steering-overhead multiplier for the ai_steered_human_supervised mode.
266
+ * Locally measured: manday = steering-day x (1 + overhead), overhead 1.75-1.85x,
267
+ * covering work that never happens inside the agent (manual QA, compliance, PM, client iteration).
268
+ */
269
+ export const STEERING_OVERHEAD = { low: 1.5, base: 1.8, high: 2.25 };
270
+ export const STEERING_OVERHEAD_SRC =
271
+ 'LOCAL MEASURED: Digitalk estimation model — 465 h active pi steering time ~= 58 work-days built the pi-dashboard product; ' +
272
+ 'manday = steering-days x (1 + overhead), overhead 1.75-1.85x; 1.5x mature team/light client, 2.25x heavy compliance.';
273
+
274
+ /** Risk-driven PERT spread multipliers around the most-likely value. */
275
+ export const PERT_SPREAD: Record<RiskLevel, { optimistic: number; pessimistic: number }> = {
276
+ low: { optimistic: 0.9, pessimistic: 1.25 },
277
+ medium: { optimistic: 0.85, pessimistic: 1.5 },
278
+ high: { optimistic: 0.75, pessimistic: 2.0 },
279
+ };
280
+ export const PERT_SRC =
281
+ 'Local: Huawei WMS confidence bands (+/-10% standard CRUD, +/-20% integrations, +/-30% novel) widened ' +
282
+ 'to a right-skewed PERT shape, matching the MFCS becslo tabla PERT_O/P_MULT structure.';
283
+
284
+ /** Beta-PERT shape parameter (lambda). 4 is the classical PERT weighting. */
285
+ export const PERT_LAMBDA = 4;
286
+
287
+ /**
288
+ * Project-level correlated shock, sampled once per Monte Carlo iteration and
289
+ * applied to every work item.
290
+ *
291
+ * Without this, summing many independently-sampled items collapses the variance
292
+ * (central limit) and produces an absurdly tight P85 — the classic way a
293
+ * simulation lies. Real overruns are correlated: scope creep, a wrong
294
+ * architectural bet, an absent client, an unstable environment hit everything
295
+ * at once.
296
+ */
297
+ export const CORRELATED_SHOCK = { optimistic: 0.95, likely: 1.0, pessimistic: 1.45 };
298
+ export const CORRELATED_SHOCK_SRC =
299
+ 'UNCALIBRATED shape. Rationale: Boehm/McConnell cone + reference-class forecasting both show project-level, ' +
300
+ 'not item-level, variance dominates overruns.';
301
+
302
+ /** Cone of uncertainty multipliers by project phase (Boehm / McConnell). */
303
+ export const CONE_OF_UNCERTAINTY: Record<Phase, [number, number]> = {
304
+ 'initial-concept': [0.25, 4.0],
305
+ 'approved-product-definition': [0.5, 2.0],
306
+ 'requirements-complete': [0.67, 1.5],
307
+ 'ui-design-complete': [0.8, 1.25],
308
+ 'detailed-design-complete': [0.9, 1.1],
309
+ };
310
+ export const CONE_SRC = 'Boehm/McConnell cone of uncertainty: 4x band at initiation, narrowing as decisions are made.';
311
+
312
+ /** Default contingency buffer. */
313
+ export const DEFAULT_CONTINGENCY = 0.15;
314
+ export const CONTINGENCY_SRC = 'LOCAL: 15% contingency used in Huawei WMS and Digitalk offers.';
315
+
316
+ export const DEFAULT_HOURS_PER_DAY = 8;
317
+ export const HOURS_PER_DAY_SRC = 'LOCAL: 1 man-day = 8 productive hours (Huawei WMS assumption).';
318
+
319
+ export const DEFAULT_ITERATIONS = 20_000;
320
+ export const DEFAULT_SEED = 20260101;
321
+ export const DEFAULT_CURRENCY = 'EUR';
322
+
323
+ export const DEFAULT_SENIORITY_MIX: Record<string, number> = { senior: 0.4, mid: 0.4, junior: 0.2 };
324
+
325
+ /**
326
+ * Roles whose effort is "build work" — the portion AI can compress.
327
+ * Everything outside this set (PM, client iteration, manual QA, compliance,
328
+ * security sign-off) is the overhead that AI does NOT shrink.
329
+ */
330
+ export const DEV_ROLES = [
331
+ 'Frontend Developer',
332
+ 'Backend Developer',
333
+ 'Data / Integration Engineer',
334
+ 'Architect',
335
+ 'DevOps / SRE',
336
+ ] as const;
337
+ export const DEV_ROLES_SRC =
338
+ 'LOCAL: Digitalk model — "overhead covers work that never happens inside the agent: manual WCAG testing, ' +
339
+ 'security validation, hosting/DPA/DR/SLA, client iteration, PM, content authoring, deployment".';
340
+
341
+ /**
342
+ * Extra leverage of an agentic loop over inline completion, applied on top of
343
+ * the per-class speedup in ai_steered mode. < 1 means agents beat autocomplete.
344
+ */
345
+ export const AGENT_LEVERAGE = 0.75;
346
+ export const AGENT_LEVERAGE_SRC = 'UNCALIBRATED. Separates "AI autocomplete" from "agent writes the change, human steers".';
347
+
348
+ /** Share of non-build effort that survives in a fully agentic delivery. */
349
+ export const NON_DEV_AGENTIC_RETENTION = 0.8;
350
+ export const NON_DEV_AGENTIC_RETENTION_SRC = 'UNCALIBRATED. PM, compliance and client iteration barely shrink with agents.';
351
+
352
+ /** Working days per calendar month. */
353
+ export const WORKING_DAYS_PER_MONTH = 20;
354
+ export const WORKING_DAYS_SRC = 'LOCAL: Huawei WMS timeline assumption — 5 days/week, 20 days/month.';
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Effort layer: turn UCP into human-only hours per work item, apply the
3
+ * residual NFR multiplier, and expand NFR-derived scope into real work items.
4
+ */
5
+
6
+ import {
7
+ DEFAULT_CONTINGENCY,
8
+ DEFAULT_HOURS_PER_UCP,
9
+ DEFAULT_REFERENCE_UCP,
10
+ } from "./defaults.js";
11
+ import { scaleAdjustment, scaleExponent, useCaseWeight } from "./sizing.js";
12
+ import type { AiClass, EstimateInput, RiskLevel, SizingResult, WorkItem } from "./types.js";
13
+
14
+ export interface EffortResult {
15
+ items: WorkItem[];
16
+ nfrMultiplier: number;
17
+ exponent: number;
18
+ adjustment: number;
19
+ baseHours: number;
20
+ contingency: number;
21
+ totalHours: number;
22
+ warnings: string[];
23
+ }
24
+
25
+ /** Residual multiplier from NFRs routed to the `multiplier` path. */
26
+ export function nfrMultiplier(input: EstimateInput): { value: number; warnings: string[] } {
27
+ const warnings: string[] = [];
28
+ let value = 1;
29
+ for (const nfr of input.nfrs ?? []) {
30
+ if (nfr.path !== 'multiplier') continue;
31
+ if (nfr.derived_components?.length) {
32
+ warnings.push(
33
+ `NFR ${nfr.id} is routed to "multiplier" but also declares derived_components — ` +
34
+ `that is double counting. Pick one path.`,
35
+ );
36
+ }
37
+ value *= nfr.multiplier ?? 1;
38
+ }
39
+ return { value, warnings };
40
+ }
41
+
42
+ /** Default AI class inference when the caller did not classify a use case. */
43
+ function inferAiClass(input: EstimateInput, transactions: number): AiClass {
44
+ if (input.context?.codebase === 'legacy') return 'legacy-change';
45
+ return transactions <= 3 ? 'crud' : 'algorithmic';
46
+ }
47
+
48
+ /** Build the full work-item list and the total human-only hour estimate. */
49
+ export function computeEffort(input: EstimateInput, sizing: SizingResult): EffortResult {
50
+ const cal = input.calibration ?? {};
51
+ const hoursPerUcp = cal.hours_per_ucp ?? DEFAULT_HOURS_PER_UCP;
52
+ const referenceUcp = cal.reference_ucp ?? DEFAULT_REFERENCE_UCP;
53
+ const contingencyRate = cal.contingency ?? DEFAULT_CONTINGENCY;
54
+
55
+ const exponent = scaleExponent(input.factors?.cocomo_scale);
56
+ const adjustment = scaleAdjustment(sizing.ucp, referenceUcp, exponent);
57
+ const { value: multiplier, warnings } = nfrMultiplier(input);
58
+
59
+ // Hours contributed per unit of UCP weight, after factor adjustment.
60
+ const totalWeight = sizing.uucw + sizing.uaw;
61
+ const ucpPerWeight = totalWeight > 0 ? sizing.ucp / totalWeight : 0;
62
+ const hoursPerWeight = ucpPerWeight * hoursPerUcp * adjustment * multiplier;
63
+
64
+ const items: WorkItem[] = [];
65
+
66
+ for (const uc of input.use_cases) {
67
+ const { weight } = useCaseWeight(uc.transactions ?? 4);
68
+ const hours = uc.hours_override ?? weight * hoursPerWeight;
69
+ items.push({
70
+ id: uc.id,
71
+ name: uc.name,
72
+ aiClass: uc.ai_class ?? inferAiClass(input, uc.transactions ?? 4),
73
+ risk: (uc.risk ?? 'medium') as RiskLevel,
74
+ hours,
75
+ source: 'use-case',
76
+ });
77
+ }
78
+
79
+ for (const nfr of input.nfrs ?? []) {
80
+ if (nfr.path !== 'derived-scope') continue;
81
+ for (const [i, comp] of (nfr.derived_components ?? []).entries()) {
82
+ const hours =
83
+ comp.hours != null
84
+ ? comp.hours
85
+ : useCaseWeight(comp.transactions ?? 3).weight * hoursPerWeight;
86
+ items.push({
87
+ id: `${nfr.id}-D${i + 1}`,
88
+ name: `${comp.name} (from ${nfr.id}: ${nfr.attribute})`,
89
+ aiClass: comp.ai_class ?? 'ops',
90
+ risk: (comp.risk ?? 'medium') as RiskLevel,
91
+ hours,
92
+ source: 'nfr-derived',
93
+ });
94
+ }
95
+ }
96
+
97
+ if (items.length === 0) warnings.push('No work items produced — check use_cases in the input.');
98
+
99
+ // Actor weight is scope that belongs to no single use case; spread it proportionally.
100
+ const actorHours = sizing.uaw * hoursPerWeight;
101
+ const itemHours = items.reduce((s, it) => s + it.hours, 0);
102
+ if (itemHours > 0 && actorHours > 0) {
103
+ for (const item of items) item.hours += actorHours * (item.hours / itemHours);
104
+ }
105
+
106
+ const baseHours = items.reduce((s, it) => s + it.hours, 0);
107
+ const contingency = baseHours * contingencyRate;
108
+
109
+ return {
110
+ items,
111
+ nfrMultiplier: multiplier,
112
+ exponent,
113
+ adjustment,
114
+ baseHours,
115
+ contingency,
116
+ totalHours: baseHours + contingency,
117
+ warnings,
118
+ };
119
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Orchestrator: input -> sizing -> effort -> roles -> modes -> uncertainty -> business case.
3
+ */
4
+
5
+ import { computeBusinessCase } from "./businesscase.js";
6
+ import {
7
+ ACEM_SRC,
8
+ AI_SPEEDUP_SRC,
9
+ COCOMO_SRC,
10
+ CONE_SRC,
11
+ CONTINGENCY_SRC,
12
+ DEFAULT_CONTINGENCY,
13
+ DEFAULT_CURRENCY,
14
+ DEFAULT_HOURS_PER_DAY,
15
+ DEFAULT_HOURS_PER_UCP,
16
+ DEFAULT_REFERENCE_UCP,
17
+ HOURS_PER_UCP_SRC,
18
+ PERT_SRC,
19
+ REWORK_UPLIFT_SRC,
20
+ ROLE_RATIO_SRC,
21
+ STEERING_OVERHEAD_SRC,
22
+ UCP_FACTOR_SRC,
23
+ } from "./defaults.js";
24
+ import { computeEffort } from "./effort.js";
25
+ import { computeModes } from "./modes.js";
26
+ import { roleRatios } from "./roles.js";
27
+ import { computeSizing, nominalScheduleMonths } from "./sizing.js";
28
+ import { coneBand, simulate } from "./simulate.js";
29
+ import type { EstimateInput, EstimateResult } from "./types.js";
30
+
31
+ /** Run the full estimation pipeline. */
32
+ export function estimate(input: EstimateInput): EstimateResult {
33
+ validate(input);
34
+
35
+ const currency = input.project.currency ?? DEFAULT_CURRENCY;
36
+ const sizing = computeSizing(input);
37
+ const effort = computeEffort(input, sizing);
38
+ const ratios = roleRatios(input, effort.totalHours);
39
+
40
+ const modes = computeModes({
41
+ input,
42
+ items: effort.items,
43
+ totalHours: effort.totalHours,
44
+ ucp: sizing.ucp,
45
+ roleRatios: ratios,
46
+ });
47
+
48
+ // Uncertainty is simulated on the human-only baseline and reported on the
49
+ // contingency-inclusive total, so the scale factor carries the buffer through.
50
+ const scale = effort.baseHours > 0 ? effort.totalHours / effort.baseHours : 1;
51
+ const percentiles = simulate(effort.items, {
52
+ iterations: input.calibration?.iterations,
53
+ seed: input.calibration?.seed,
54
+ scale,
55
+ });
56
+
57
+ const cone = coneBand(input.project.phase, effort.totalHours);
58
+ const chosenMode = modes.find((m) => m.mode === 'human_with_ai') ?? modes[0];
59
+ const businessCase = computeBusinessCase({ input, items: effort.items, chosenMode, currency });
60
+
61
+ const warnings = [...effort.warnings];
62
+ const hoursPerDay = input.team?.hours_per_day ?? DEFAULT_HOURS_PER_DAY;
63
+ const personMonths = effort.totalHours / (hoursPerDay * 20);
64
+ const nominalMonths = nominalScheduleMonths(personMonths, effort.exponent);
65
+ const humanMode = modes.find((m) => m.mode === 'human_only');
66
+ if (humanMode && nominalMonths > 0 && humanMode.calendarMonths < nominalMonths * 0.75) {
67
+ warnings.push(
68
+ `Schedule risk: planned ${humanMode.calendarMonths.toFixed(1)} months is below the COCOMO II nominal ` +
69
+ `${nominalMonths.toFixed(1)} months for this effort. Compressing schedule below ~75% of nominal is where ` +
70
+ `projects historically break.`,
71
+ );
72
+ }
73
+ if (!input.rates?.length) warnings.push('No rate card supplied — costs are zero. Load rates.yaml or set project rates.');
74
+ if (!input.factors?.technical) warnings.push('No UCP technical factors given; all 13 defaulted to 3 (neutral).');
75
+ if (!input.factors?.environmental) warnings.push('No UCP environmental factors given; all 8 defaulted to 3 (neutral).');
76
+ if (!input.project.phase) warnings.push('No project phase set; cone of uncertainty defaulted to approved-product-definition (0.5x-2x).');
77
+
78
+ return {
79
+ input,
80
+ currency,
81
+ sizing,
82
+ items: effort.items,
83
+ nfrMultiplier: effort.nfrMultiplier,
84
+ scaleExponent: effort.exponent,
85
+ scaleAdjustment: effort.adjustment,
86
+ baseHours: effort.baseHours,
87
+ contingency: effort.contingency,
88
+ totalHours: effort.totalHours,
89
+ cone,
90
+ percentiles,
91
+ modes,
92
+ businessCase,
93
+ assumptions: assumptions(input, nominalMonths),
94
+ warnings,
95
+ };
96
+ }
97
+
98
+ function validate(input: EstimateInput): void {
99
+ if (!input.project?.name) throw new Error('input.project.name is required');
100
+ if (!Array.isArray(input.use_cases) || input.use_cases.length === 0) {
101
+ throw new Error('input.use_cases must be a non-empty list');
102
+ }
103
+ const ids = new Set<string>();
104
+ for (const uc of input.use_cases) {
105
+ if (!uc.id) throw new Error('every use case needs an id');
106
+ if (ids.has(uc.id)) throw new Error(`duplicate use case id: ${uc.id}`);
107
+ ids.add(uc.id);
108
+ }
109
+ for (const nfr of input.nfrs ?? []) {
110
+ if (nfr.path !== 'derived-scope' && nfr.path !== 'multiplier') {
111
+ throw new Error(`NFR ${nfr.id}: path must be "derived-scope" or "multiplier"`);
112
+ }
113
+ }
114
+ }
115
+
116
+ /** The assumption register that must travel with every estimate. */
117
+ function assumptions(input: EstimateInput, nominalMonths: number): string[] {
118
+ const cal = input.calibration ?? {};
119
+ return [
120
+ `Sizing: Use Case Points (Karner). ${UCP_FACTOR_SRC}`,
121
+ `Effort: ${cal.hours_per_ucp ?? DEFAULT_HOURS_PER_UCP} h/UCP at a reference size of ${cal.reference_ucp ?? DEFAULT_REFERENCE_UCP} UCP. ${HOURS_PER_UCP_SRC}`,
122
+ `Scale: ${COCOMO_SRC}. Diseconomy of scale applied relative to the reference size.`,
123
+ `Contingency: ${((cal.contingency ?? DEFAULT_CONTINGENCY) * 100).toFixed(0)}%. ${CONTINGENCY_SRC}`,
124
+ `Man-day: ${input.team?.hours_per_day ?? DEFAULT_HOURS_PER_DAY} productive hours; 20 working days per month.`,
125
+ `Roles: ${ROLE_RATIO_SRC}`,
126
+ `AI speedups: ${AI_SPEEDUP_SRC}`,
127
+ `AI rework: ${REWORK_UPLIFT_SRC}`,
128
+ `AI-steered mode: ${STEERING_OVERHEAD_SRC}`,
129
+ `Agentic mode: ${ACEM_SRC}`,
130
+ `Uncertainty: ${PERT_SRC}`,
131
+ `Cone: ${CONE_SRC}`,
132
+ `COCOMO II nominal schedule for this effort: ${nominalMonths.toFixed(1)} months.`,
133
+ 'This is an ESTIMATE, not a target and not a commitment (McConnell).',
134
+ ];
135
+ }