@vijaypjavvadi/bdd2pw 3.8.1 → 3.9.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 CHANGED
@@ -9,6 +9,87 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  _Nothing yet._
11
11
 
12
+ ## [3.9.0] — 2026-06-05
13
+
14
+ ### Added — opt-in LLM telemetry sidecar
15
+
16
+ `scaffold({ llmStats: true })` now writes
17
+ `<repo>/artefacts/llm-stats.json` capturing per-scaffold LLM activity:
18
+
19
+ {
20
+ "version": "3.9.0",
21
+ "scaffoldId": "scaffold-...",
22
+ "generatedAt": "2026-06-05T...",
23
+ "totals": {
24
+ "callsAttempted": 5,
25
+ "callsSuccessful": 5,
26
+ "bindingsGenerated": 23,
27
+ "cacheHits": 12,
28
+ "cacheMisses": 11,
29
+ "cacheHitRate": 0.522,
30
+ "inputTokens": 24500,
31
+ "outputTokens": 8200,
32
+ "estimatedCostUsd": 0.0735
33
+ },
34
+ "calls": [
35
+ { "index": 1, "model": "...", "inputTokens": 4900,
36
+ "outputTokens": 1820, "latencyMs": 2310,
37
+ "fromCache": false, "batchSize": 5 },
38
+ ...
39
+ ],
40
+ "latencyMs": { "p50": 2100, "p95": 3450, "min": 1200, "max": 3450 },
41
+ "pricing": { "model": "claude-sonnet-4-6",
42
+ "inputUsdPerMillion": 3, "outputUsdPerMillion": 15 }
43
+ }
44
+
45
+ **Why it exists.** v3.5.0 introduced per-scenario LLM batching with
46
+ the promise of ~75% cost reduction on unmatched-heavy scaffolds.
47
+ Until now, the savings were invisible — operators had no per-scaffold
48
+ record of cache hit rate, batch size distribution, token counts, or
49
+ estimated cost. This sidecar makes the ROI measurable per run.
50
+
51
+ **How it works.** New `src/llm/telemetry.ts` ships an `LLMTelemetry`
52
+ class that subscribes to the existing `LLMLogEvent` stream
53
+ (`cache_hit` / `cache_miss` / `provider_call_start` /
54
+ `provider_call_done` / `binding_parsed` events that
55
+ `AnthropicLLMClient` already emits). The scaffold orchestrator fans
56
+ the log callback to BOTH the existing pino logger AND the telemetry
57
+ collector. Zero overhead when disabled — no telemetry instance is
58
+ constructed and the fan-out is a single `?.` null check.
59
+
60
+ **Pricing.** Cost is an ESTIMATE — provider prices change. The
61
+ sidecar records the per-million rates used (default snapshot for
62
+ Claude Sonnet 4.6: $3/M input, $15/M output) so a reviewer can
63
+ re-derive the number against current pricing. Override via
64
+ `new LLMTelemetry(scaffoldId, version, pricingOverride)` if you
65
+ have negotiated rates or a different model.
66
+
67
+ **New exports** from `@vijaypjavvadi/bdd2pw`:
68
+ - `LLMTelemetry` — the collector class.
69
+ - `DEFAULT_PRICING` — per-million USD pricing snapshot. Pre-seeded
70
+ for `claude-sonnet-4-6`, `claude-3-7-sonnet-latest`,
71
+ `claude-opus-4-6`, `claude-haiku-4-5-20251001`.
72
+ - Types: `TelemetryCall`, `TelemetrySummary`.
73
+
74
+ ### Default behavior
75
+
76
+ `llmStats` is **off** by default — pure-UI scaffolds and existing
77
+ LLM-enabled scaffolds emit the same files as v3.8.x. Operators opt
78
+ in when they want to track spend or debug latency.
79
+
80
+ ### Tests
81
+
82
+ `tests/unit/v390Telemetry.test.ts`:
83
+ - Single-batch aggregates correctly (cache misses incremented,
84
+ tokens captured, latency recorded, bindings counted).
85
+ - Cache hit rate computed across mixed cached + uncached calls.
86
+ - p50 / p95 latency from a 10-element sample.
87
+ - Cost estimation against the known Sonnet pricing snapshot.
88
+ - Scaffold context (id, version, generated timestamp) stamped
89
+ into the summary.
90
+ - Zero-event scaffold produces a clean empty summary (no crash,
91
+ no NaN).
92
+
12
93
  ## [3.8.0] — 2026-05-24
13
94
 
14
95
  ### Added — four more opt-in domain rule packs