thumbgate 1.39.1 → 1.40.2
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/.claude-plugin/plugin.json +1 -1
- package/.well-known/llms.txt +2 -2
- package/.well-known/mcp/server-card.json +1 -1
- package/README.md +5 -4
- package/adapters/claude/.mcp.json +6 -2
- package/adapters/codex/config.toml +5 -0
- package/adapters/forge/forge.yaml +4 -4
- package/adapters/future-agi/.mcp.json +1 -1
- package/adapters/future-agi/config.toml +1 -1
- package/adapters/future-agi/opencode.json +1 -1
- package/adapters/herdr/herdr-plugin.toml +2 -2
- package/adapters/mcp/server-stdio.js +82 -7
- package/adapters/opencode/opencode.json +1 -1
- package/bin/cli.js +128 -15
- package/config/brand-standards.json +131 -0
- package/config/gates/default.json +18 -1
- package/config/github-about.json +1 -1
- package/config/mcp-allowlists.json +16 -3
- package/config/merge-quality-checks.json +1 -0
- package/config/post-deploy-marketing-pages.json +3 -3
- package/config/schemas/task-outcome-receipt.schema.json +9 -0
- package/openapi/openapi.yaml +7 -3
- package/package.json +98 -31
- package/public/about.html +2 -2
- package/public/admin.html +771 -0
- package/public/agent-manager.html +3 -3
- package/public/agents-cost-savings.html +1 -1
- package/public/ai-malpractice-prevention.html +12 -12
- package/public/architecture.html +0 -1
- package/public/assets/diagrams/decision.svg +3 -3
- package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +1 -1
- package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +1 -1
- package/public/blog/git-at-agent-scale.html +2 -2
- package/public/blog/inside-your-boundary.html +1 -1
- package/public/blog/process-over-outcome-gates.html +1 -1
- package/public/case-studies.html +1 -2
- package/public/codex-enterprise.html +1 -1
- package/public/codex-plugin.html +1 -1
- package/public/dashboard.html +773 -481
- package/public/diagnostic.html +8 -3
- package/public/enterprise-governance.html +26 -174
- package/public/eval-scorecard.html +3 -4
- package/public/eval-scorecard.json +2 -2
- package/public/evaluations.html +0 -1
- package/public/founders.html +3 -3
- package/public/gaming-playbook.html +4 -4
- package/public/guide.html +3 -5
- package/public/index.html +181 -205
- package/public/install.html +12 -11
- package/public/js/buyer-intent.js +49 -8
- package/public/lessons.html +103 -46
- package/public/numbers.html +32 -33
- package/public/operator-framework.html +44 -72
- package/public/peter.html +3 -3
- package/public/platform-partners.html +1 -1
- package/public/pricing.html +61 -327
- package/public/pro.html +3 -1
- package/public/project-switcher.js +76 -0
- package/public/whitepaper.html +1 -2
- package/scripts/activation-quickstart.js +15 -3
- package/scripts/activation-tracker.js +280 -3
- package/scripts/agent-action-inventory.js +235 -143
- package/scripts/agent-operations-planner.js +1 -1
- package/scripts/agent-readiness.js +36 -6
- package/scripts/agentic-prompt-pipelines.js +901 -0
- package/scripts/analytics-report.js +363 -0
- package/scripts/analytics-window.js +7 -1
- package/scripts/async-job-runner.js +66 -11
- package/scripts/audit-trail.js +37 -24
- package/scripts/auto-context-packs.js +249 -0
- package/scripts/auto-promote-gates.js +37 -27
- package/scripts/backfill-lesson-scopes.js +122 -0
- package/scripts/billing-setup.js +137 -0
- package/scripts/billing.js +889 -132
- package/scripts/bot-detection.js +112 -0
- package/scripts/brand-standards-gate.js +571 -0
- package/scripts/chatgpt-ads-readiness-pack.js +1 -1
- package/scripts/check-update.js +236 -0
- package/scripts/cli-schema.js +1 -1
- package/scripts/commercial-offer.js +2 -2
- package/scripts/contextfs.js +9 -3
- package/scripts/conversion-rate-stats.js +442 -0
- package/scripts/cost-cli.js +147 -0
- package/scripts/creator-campaigns.js +239 -0
- package/scripts/cross-encoder-reranker.js +4 -0
- package/scripts/cuda-gate-batch.js +560 -0
- package/scripts/daemon-manager.js +108 -0
- package/scripts/dashboard-chat.js +11 -0
- package/scripts/dashboard.js +576 -169
- package/scripts/decision-journal.js +7 -4
- package/scripts/delegation-runtime.js +1036 -0
- package/scripts/dispatch-brief.js +159 -0
- package/scripts/distribution-surfaces.js +110 -0
- package/scripts/docker-sandbox-planner.js +3 -3
- package/scripts/egm-goldfish-packet.js +95 -0
- package/scripts/embeddinggemma-adapter.js +407 -0
- package/scripts/export-dpo-pairs.js +12 -7
- package/scripts/feedback-aggregate.js +4 -0
- package/scripts/feedback-attribution.js +6 -4
- package/scripts/feedback-history-distiller.js +18 -6
- package/scripts/feedback-loop.js +255 -89
- package/scripts/feedback-paths.js +8 -1
- package/scripts/feedback-sanitizer.js +5 -0
- package/scripts/feedback-scope.js +106 -0
- package/scripts/feedback-session.js +8 -2
- package/scripts/filesystem-search.js +13 -8
- package/scripts/financial-control-plane.js +707 -45
- package/scripts/funnel-analytics.js +35 -0
- package/scripts/gate-semantic-layer.js +292 -0
- package/scripts/gate-stats.js +8 -2
- package/scripts/gates-engine.js +694 -230
- package/scripts/generate-eval-scorecard.js +0 -1
- package/scripts/harness-tool-names.js +31 -5
- package/scripts/hybrid-feedback-context.js +5 -2
- package/scripts/implementation-notes.js +241 -0
- package/scripts/intent-router.js +518 -0
- package/scripts/intervention-policy.js +2 -1
- package/scripts/latency-budget.js +164 -0
- package/scripts/lesson-canonical.js +2 -2
- package/scripts/lesson-db.js +55 -14
- package/scripts/lesson-graph.js +2 -1
- package/scripts/lesson-retrieval.js +95 -9
- package/scripts/lesson-search.js +86 -22
- package/scripts/lesson-synthesis.js +21 -5
- package/scripts/mailer/index.js +17 -1
- package/scripts/mailer/resend-mailer.js +213 -179
- package/scripts/mcp-writeguard.js +158 -0
- package/scripts/migrate-project-scope.js +209 -0
- package/scripts/model-candidates.js +414 -0
- package/scripts/openrouter-armor-partnership-diode.js +2419 -0
- package/scripts/operational-dashboard.js +172 -0
- package/scripts/operational-integrity.js +436 -3
- package/scripts/operational-summary.js +190 -0
- package/scripts/operator-artifacts.js +622 -0
- package/scripts/optimize-context.js +17 -0
- package/scripts/override-audit.js +2 -0
- package/scripts/owner-admin.js +338 -0
- package/scripts/pr-manager.js +194 -1
- package/scripts/predictive-insights.js +449 -0
- package/scripts/profound-aeo-citation-engine.js +583 -0
- package/scripts/progressive-signoff.js +260 -0
- package/scripts/project-catalog.js +243 -0
- package/scripts/project-dashboard.js +61 -0
- package/scripts/project-evidence.js +172 -0
- package/scripts/project-identity.js +182 -0
- package/scripts/project-scope.js +381 -0
- package/scripts/prompt-guard.js +446 -52
- package/scripts/proof-report.js +232 -0
- package/scripts/provider-action-normalizer.js +14 -6
- package/scripts/pulse.js +80 -0
- package/scripts/rate-limiter.js +41 -0
- package/scripts/rrsi-doctor.js +2698 -0
- package/scripts/secret-redaction.js +171 -25
- package/scripts/secret-scanner.js +101 -42
- package/scripts/self-protection.js +2 -2
- package/scripts/seo-gsd.js +14 -14
- package/scripts/session-context-dedupe.js +66 -0
- package/scripts/session-report.js +120 -0
- package/scripts/settings-hierarchy.js +4 -2
- package/scripts/statusline-meta.js +34 -23
- package/scripts/subagent-profiles.js +79 -0
- package/scripts/task-outcomes.js +29 -2
- package/scripts/telemetry-analytics.js +238 -13
- package/scripts/third-author-cli.js +118 -0
- package/scripts/third-author-governance.js +437 -0
- package/scripts/thumbgate-dream.js +878 -0
- package/scripts/thumbgate-search.js +23 -9
- package/scripts/tool-kpi-tracker.js +5 -2
- package/scripts/tool-registry.js +42 -1
- package/scripts/triage-savings-calculator.js +1 -1
- package/scripts/vector-store.js +4 -1
- package/scripts/verified-lessons.js +270 -0
- package/scripts/verify-marketing-pages-deployed.js +2 -2
- package/scripts/workflow-sentinel.js +29 -10
- package/server.json +2 -2
- package/skills/thumbgate-daily-discoveries/SKILL.md +25 -41
- package/src/api/server.js +2371 -451
- package/src/feedback.js +21 -0
- package/src/hermes-sync-plane.js +2 -1
- package/src/index.js +2 -0
- package/src/lesson-search.js +9 -0
- package/src/mckinsey-top-company-ai-coding.js +493 -0
- package/src/mcp/server.js +3 -0
- package/src/mcp-writeguard.js +772 -11
- package/src/openshell-lovable-engine.js +1475 -0
- package/src/task-outcome.js +3 -0
- package/config/evals/agent-safety-eval.json +0 -447
- package/config/evals/retrieval-ranking-golden.json +0 -522
- package/config/progressive/01-wire-only.json +0 -11
- package/config/progressive/02-dashboard-empty-ok.json +0 -10
- package/config/progressive/03-one-lesson.json +0 -10
- package/config/progressive/04-warn-fires.json +0 -11
- package/config/progressive/05-strict-optional.json +0 -11
- package/config/progressive/README.md +0 -15
- package/public/assets/diagrams/agent-integration.png +0 -0
- package/public/assets/diagrams/thumbgate-architecture.png +0 -0
- package/scripts/install-thumbgate-daily-publish-launchd.sh +0 -83
- package/scripts/thumbgate-daily-discoveries-publish.js +0 -461
- package/scripts/thumbgate-daily-discoveries-publish.sh +0 -18
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function toNumber(value) {
|
|
5
|
+
const numeric = Number(value || 0);
|
|
6
|
+
return Number.isFinite(numeric) ? numeric : 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function safeRate(numerator, denominator, precision = 4) {
|
|
10
|
+
if (!denominator) return 0;
|
|
11
|
+
return Number((toNumber(numerator) / toNumber(denominator)).toFixed(precision));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function clamp01(value) {
|
|
15
|
+
return Math.max(0, Math.min(1, toNumber(value)));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function normalizeCapped(value, cap) {
|
|
19
|
+
const capped = toNumber(cap);
|
|
20
|
+
if (!capped || capped <= 0) return 0;
|
|
21
|
+
return clamp01(toNumber(value) / capped);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function sumCounter(counter = {}) {
|
|
25
|
+
return Object.values(counter).reduce((sum, value) => sum + toNumber(value), 0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function summarizeSeverity(anomalies = []) {
|
|
29
|
+
if (anomalies.some((entry) => entry.severity === 'critical')) return 'critical';
|
|
30
|
+
if (anomalies.some((entry) => entry.severity === 'warning')) return 'warning';
|
|
31
|
+
return 'healthy';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function toBand(score) {
|
|
35
|
+
if (score >= 0.8) return 'very_high';
|
|
36
|
+
if (score >= 0.6) return 'high';
|
|
37
|
+
if (score >= 0.4) return 'medium';
|
|
38
|
+
if (score >= 0.2) return 'low';
|
|
39
|
+
return 'very_low';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function weightedAverage(entries = []) {
|
|
43
|
+
const active = entries.filter((entry) => entry && Number.isFinite(entry.value) && entry.weight > 0);
|
|
44
|
+
const totalWeight = active.reduce((sum, entry) => sum + entry.weight, 0);
|
|
45
|
+
if (!totalWeight) return 0;
|
|
46
|
+
return active.reduce((sum, entry) => sum + (entry.value * entry.weight), 0) / totalWeight;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function smoothedRate(successes, trials, priorRate = 0, priorWeight = 8) {
|
|
50
|
+
const trialCount = Math.max(0, toNumber(trials));
|
|
51
|
+
const successCount = Math.max(0, toNumber(successes));
|
|
52
|
+
const boundedPrior = clamp01(priorRate);
|
|
53
|
+
return safeRate(successCount + (boundedPrior * priorWeight), trialCount + priorWeight, 6);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function countQualifiedCreators(rows = []) {
|
|
57
|
+
return rows.filter((row) => {
|
|
58
|
+
return toNumber(row.workflowSprintLeads) > 0
|
|
59
|
+
|| toNumber(row.qualifiedWorkflowSprintLeads) > 0
|
|
60
|
+
|| toNumber(row.bookedRevenueCents) > 0
|
|
61
|
+
|| toNumber(row.checkoutStarts) > 0;
|
|
62
|
+
}).length;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function buildBenchmarks({ telemetryAnalytics = {}, billingSummary = {}, stagingModel = {} } = {}) {
|
|
66
|
+
const uniqueVisitors = toNumber(telemetryAnalytics.visitors && telemetryAnalytics.visitors.uniqueVisitors);
|
|
67
|
+
const checkoutStarts = toNumber(telemetryAnalytics.ctas && telemetryAnalytics.ctas.checkoutStarts);
|
|
68
|
+
const acquisitionLeads = toNumber(billingSummary.signups && billingSummary.signups.uniqueLeads);
|
|
69
|
+
const paidCustomers = toNumber(billingSummary.revenue && billingSummary.revenue.paidCustomers);
|
|
70
|
+
const bookedRevenueCents = toNumber(billingSummary.revenue && billingSummary.revenue.bookedRevenueCents);
|
|
71
|
+
const revenuePerPaidCents = paidCustomers > 0
|
|
72
|
+
? Math.max(1, Math.round(bookedRevenueCents / paidCustomers))
|
|
73
|
+
: 1900;
|
|
74
|
+
const creatorRows = Array.isArray(stagingModel.dims && stagingModel.dims.creators)
|
|
75
|
+
? stagingModel.dims.creators
|
|
76
|
+
: [];
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
uniqueVisitors,
|
|
80
|
+
checkoutStarts,
|
|
81
|
+
acquisitionLeads,
|
|
82
|
+
paidCustomers,
|
|
83
|
+
bookedRevenueCents,
|
|
84
|
+
revenuePerPaidCents,
|
|
85
|
+
visitorToCheckoutRate: safeRate(checkoutStarts, uniqueVisitors, 6),
|
|
86
|
+
visitorToLeadRate: safeRate(acquisitionLeads, uniqueVisitors, 6),
|
|
87
|
+
visitorToPaidRate: safeRate(paidCustomers, uniqueVisitors, 6),
|
|
88
|
+
checkoutToLeadRate: safeRate(acquisitionLeads, checkoutStarts, 6),
|
|
89
|
+
checkoutToPaidRate: safeRate(paidCustomers, checkoutStarts, 6),
|
|
90
|
+
leadToPaidRate: safeRate(paidCustomers, acquisitionLeads, 6),
|
|
91
|
+
creatorCount: creatorRows.length,
|
|
92
|
+
qualifiedCreatorCount: countQualifiedCreators(creatorRows),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function buildOpportunityForecast(row, benchmarks, labelKey) {
|
|
97
|
+
const pageViews = toNumber(row.pageViews);
|
|
98
|
+
const checkoutStarts = toNumber(row.checkoutStarts);
|
|
99
|
+
const acquisitionLeads = toNumber(row.acquisitionLeads);
|
|
100
|
+
const paidCustomers = toNumber(row.paidCustomers);
|
|
101
|
+
const bookedRevenueCents = toNumber(row.bookedRevenueCents);
|
|
102
|
+
const workflowSprintLeads = toNumber(row.workflowSprintLeads);
|
|
103
|
+
const qualifiedWorkflowSprintLeads = toNumber(row.qualifiedWorkflowSprintLeads);
|
|
104
|
+
|
|
105
|
+
const visitorToPaid = smoothedRate(
|
|
106
|
+
paidCustomers,
|
|
107
|
+
pageViews,
|
|
108
|
+
benchmarks.visitorToPaidRate,
|
|
109
|
+
12
|
|
110
|
+
);
|
|
111
|
+
const checkoutToPaid = smoothedRate(
|
|
112
|
+
paidCustomers,
|
|
113
|
+
checkoutStarts,
|
|
114
|
+
benchmarks.checkoutToPaidRate,
|
|
115
|
+
8
|
|
116
|
+
);
|
|
117
|
+
const leadToPaid = smoothedRate(
|
|
118
|
+
paidCustomers,
|
|
119
|
+
acquisitionLeads,
|
|
120
|
+
benchmarks.leadToPaidRate,
|
|
121
|
+
6
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const predictedPaidCustomers = Math.max(
|
|
125
|
+
paidCustomers,
|
|
126
|
+
weightedAverage([
|
|
127
|
+
{ value: pageViews * visitorToPaid, weight: pageViews > 0 ? 0.2 : 0 },
|
|
128
|
+
{ value: checkoutStarts * checkoutToPaid, weight: checkoutStarts > 0 ? 0.45 : 0 },
|
|
129
|
+
{ value: acquisitionLeads * leadToPaid, weight: acquisitionLeads > 0 ? 0.35 : 0 },
|
|
130
|
+
])
|
|
131
|
+
);
|
|
132
|
+
const predictedBookedRevenueCents = Math.round(predictedPaidCustomers * benchmarks.revenuePerPaidCents);
|
|
133
|
+
const opportunityRevenueCents = Math.max(0, predictedBookedRevenueCents - bookedRevenueCents);
|
|
134
|
+
const sampleVolume = pageViews + checkoutStarts + (acquisitionLeads * 2) + (workflowSprintLeads * 3);
|
|
135
|
+
const confidence = clamp01(Math.log1p(sampleVolume) / Math.log1p(40));
|
|
136
|
+
const momentumScore = clamp01(weightedAverage([
|
|
137
|
+
{ value: normalizeCapped(pageViews, 50), weight: 0.2 },
|
|
138
|
+
{ value: normalizeCapped(checkoutStarts, 12), weight: 0.35 },
|
|
139
|
+
{ value: normalizeCapped(acquisitionLeads, 6), weight: 0.25 },
|
|
140
|
+
{ value: normalizeCapped(qualifiedWorkflowSprintLeads, 3), weight: 0.2 },
|
|
141
|
+
]));
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
key: row.key || 'unknown',
|
|
145
|
+
label: row[labelKey] || row.key || 'unknown',
|
|
146
|
+
pageViews,
|
|
147
|
+
checkoutStarts,
|
|
148
|
+
acquisitionLeads,
|
|
149
|
+
paidCustomers,
|
|
150
|
+
bookedRevenueCents,
|
|
151
|
+
workflowSprintLeads,
|
|
152
|
+
qualifiedWorkflowSprintLeads,
|
|
153
|
+
predictedPaidCustomers: Number(predictedPaidCustomers.toFixed(2)),
|
|
154
|
+
predictedBookedRevenueCents,
|
|
155
|
+
opportunityRevenueCents,
|
|
156
|
+
confidence: Number(confidence.toFixed(4)),
|
|
157
|
+
momentumScore: Number(momentumScore.toFixed(4)),
|
|
158
|
+
band: toBand(clamp01((confidence * 0.45) + (momentumScore * 0.55))),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function scoreDimensionForecasts(rows = [], benchmarks = {}, labelKey = 'key') {
|
|
163
|
+
return rows
|
|
164
|
+
.map((row) => buildOpportunityForecast(row, benchmarks, labelKey))
|
|
165
|
+
.filter((row) => row.pageViews > 0 || row.checkoutStarts > 0 || row.acquisitionLeads > 0 || row.bookedRevenueCents > 0)
|
|
166
|
+
.sort((left, right) => {
|
|
167
|
+
if (right.opportunityRevenueCents !== left.opportunityRevenueCents) {
|
|
168
|
+
return right.opportunityRevenueCents - left.opportunityRevenueCents;
|
|
169
|
+
}
|
|
170
|
+
if (right.predictedBookedRevenueCents !== left.predictedBookedRevenueCents) {
|
|
171
|
+
return right.predictedBookedRevenueCents - left.predictedBookedRevenueCents;
|
|
172
|
+
}
|
|
173
|
+
return String(left.key).localeCompare(String(right.key));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function summarizeDrivers(drivers = []) {
|
|
178
|
+
return drivers
|
|
179
|
+
.sort((left, right) => right.impact - left.impact)
|
|
180
|
+
.filter((driver) => driver.impact > 0)
|
|
181
|
+
.slice(0, 3)
|
|
182
|
+
.map((driver) => ({
|
|
183
|
+
key: driver.key,
|
|
184
|
+
label: driver.label,
|
|
185
|
+
impact: Number(driver.impact.toFixed(4)),
|
|
186
|
+
rawValue: driver.rawValue,
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function scoreUpgradePropensity({ telemetryAnalytics = {}, billingSummary = {}, stagingModel = {}, gateStats = {}, team = {} } = {}) {
|
|
191
|
+
const benchmarks = buildBenchmarks({ telemetryAnalytics, billingSummary, stagingModel });
|
|
192
|
+
const pricingSignals = toNumber(telemetryAnalytics.pricing && telemetryAnalytics.pricing.pricingInterestEvents);
|
|
193
|
+
const tooExpensiveSignals = toNumber(telemetryAnalytics.buyerLoss && telemetryAnalytics.buyerLoss.reasonsByCode && telemetryAnalytics.buyerLoss.reasonsByCode.too_expensive);
|
|
194
|
+
const workflowSprintLeads = toNumber(billingSummary.pipeline && billingSummary.pipeline.workflowSprintLeads && billingSummary.pipeline.workflowSprintLeads.total);
|
|
195
|
+
const qualifiedWorkflowSprintLeads = toNumber(billingSummary.pipeline && billingSummary.pipeline.qualifiedWorkflowSprintLeads && billingSummary.pipeline.qualifiedWorkflowSprintLeads.total);
|
|
196
|
+
const activeProKeys = toNumber(billingSummary.keys && billingSummary.keys.active);
|
|
197
|
+
const totalUsage = toNumber(billingSummary.keys && billingSummary.keys.totalUsage);
|
|
198
|
+
const blockedActions = toNumber(gateStats.blocked);
|
|
199
|
+
const activeAgents = toNumber(team.activeAgents);
|
|
200
|
+
|
|
201
|
+
const proDrivers = [
|
|
202
|
+
{ key: 'checkoutStarts', label: 'checkout starts', impact: normalizeCapped(benchmarks.checkoutStarts, 12) * 0.28, rawValue: benchmarks.checkoutStarts },
|
|
203
|
+
{ key: 'acquisitionLeads', label: 'captured leads', impact: normalizeCapped(benchmarks.acquisitionLeads, 6) * 0.2, rawValue: benchmarks.acquisitionLeads },
|
|
204
|
+
{ key: 'visitorToCheckoutRate', label: 'visitor → checkout rate', impact: normalizeCapped(benchmarks.visitorToCheckoutRate, 0.08) * 0.18, rawValue: benchmarks.visitorToCheckoutRate },
|
|
205
|
+
{ key: 'pricingInterest', label: 'pricing intent', impact: normalizeCapped(pricingSignals, 8) * 0.14, rawValue: pricingSignals },
|
|
206
|
+
{ key: 'totalUsage', label: 'usage depth', impact: normalizeCapped(totalUsage, 300) * 0.12, rawValue: totalUsage },
|
|
207
|
+
{ key: 'blockedActions', label: 'blocked mistakes', impact: normalizeCapped(blockedActions, 30) * 0.08, rawValue: blockedActions },
|
|
208
|
+
];
|
|
209
|
+
const proPenalty = normalizeCapped(tooExpensiveSignals, 6) * 0.12;
|
|
210
|
+
const proScore = clamp01(proDrivers.reduce((sum, driver) => sum + driver.impact, 0) - proPenalty);
|
|
211
|
+
|
|
212
|
+
const teamDrivers = [
|
|
213
|
+
{ key: 'qualifiedWorkflowSprintLeads', label: 'qualified workflow sprint leads', impact: normalizeCapped(qualifiedWorkflowSprintLeads, 3) * 0.3, rawValue: qualifiedWorkflowSprintLeads },
|
|
214
|
+
{ key: 'workflowSprintLeads', label: 'workflow sprint leads', impact: normalizeCapped(workflowSprintLeads, 5) * 0.22, rawValue: workflowSprintLeads },
|
|
215
|
+
{ key: 'activeProKeys', label: 'active Pro keys', impact: normalizeCapped(activeProKeys, 5) * 0.16, rawValue: activeProKeys },
|
|
216
|
+
{ key: 'qualifiedCreators', label: 'qualified creators/channels', impact: normalizeCapped(benchmarks.qualifiedCreatorCount, 4) * 0.12, rawValue: benchmarks.qualifiedCreatorCount },
|
|
217
|
+
{ key: 'activeAgents', label: 'active agents', impact: normalizeCapped(activeAgents, 6) * 0.12, rawValue: activeAgents },
|
|
218
|
+
{ key: 'leadToPaidRate', label: 'lead → paid rate', impact: normalizeCapped(benchmarks.leadToPaidRate, 0.5) * 0.08, rawValue: benchmarks.leadToPaidRate },
|
|
219
|
+
];
|
|
220
|
+
const teamScore = clamp01(teamDrivers.reduce((sum, driver) => sum + driver.impact, 0));
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
pro: {
|
|
224
|
+
score: Number(proScore.toFixed(4)),
|
|
225
|
+
band: toBand(proScore),
|
|
226
|
+
confidence: Number(clamp01(Math.log1p(benchmarks.uniqueVisitors + benchmarks.checkoutStarts + pricingSignals) / Math.log1p(80)).toFixed(4)),
|
|
227
|
+
drivers: summarizeDrivers(proDrivers),
|
|
228
|
+
pricingResistanceSignals: tooExpensiveSignals,
|
|
229
|
+
},
|
|
230
|
+
team: {
|
|
231
|
+
score: Number(teamScore.toFixed(4)),
|
|
232
|
+
band: toBand(teamScore),
|
|
233
|
+
confidence: Number(clamp01(Math.log1p(workflowSprintLeads + qualifiedWorkflowSprintLeads + activeProKeys + activeAgents) / Math.log1p(24)).toFixed(4)),
|
|
234
|
+
drivers: summarizeDrivers(teamDrivers),
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function detectPredictiveAnomalies({ telemetryAnalytics = {}, billingSummary = {}, creatorForecasts = [], sourceForecasts = [] } = {}) {
|
|
240
|
+
const anomalies = [];
|
|
241
|
+
const uniqueVisitors = toNumber(telemetryAnalytics.visitors && telemetryAnalytics.visitors.uniqueVisitors);
|
|
242
|
+
const checkoutStarts = toNumber(telemetryAnalytics.ctas && telemetryAnalytics.ctas.checkoutStarts);
|
|
243
|
+
const paidCustomers = toNumber(billingSummary.revenue && billingSummary.revenue.paidCustomers);
|
|
244
|
+
const attributionCoverageRate = toNumber(telemetryAnalytics.visitors && telemetryAnalytics.visitors.attributionCoverageRate);
|
|
245
|
+
const unreconciledPaidEvents = toNumber(billingSummary.dataQuality && billingSummary.dataQuality.unreconciledPaidEvents);
|
|
246
|
+
const tooExpensiveSignals = toNumber(telemetryAnalytics.buyerLoss && telemetryAnalytics.buyerLoss.reasonsByCode && telemetryAnalytics.buyerLoss.reasonsByCode.too_expensive);
|
|
247
|
+
const buyerLossSignals = toNumber(telemetryAnalytics.buyerLoss && telemetryAnalytics.buyerLoss.totalSignals);
|
|
248
|
+
|
|
249
|
+
if (checkoutStarts >= 3 && paidCustomers === 0) {
|
|
250
|
+
anomalies.push({
|
|
251
|
+
type: 'conversion_stall',
|
|
252
|
+
severity: checkoutStarts >= 8 ? 'critical' : 'warning',
|
|
253
|
+
message: 'Checkout starts are arriving without paid conversions.',
|
|
254
|
+
evidence: `checkoutStarts=${checkoutStarts}, paidCustomers=${paidCustomers}`,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (uniqueVisitors >= 10 && attributionCoverageRate < 0.6) {
|
|
259
|
+
anomalies.push({
|
|
260
|
+
type: 'attribution_blindspot',
|
|
261
|
+
severity: attributionCoverageRate < 0.35 ? 'critical' : 'warning',
|
|
262
|
+
message: 'Attribution coverage is too low for reliable predictive routing.',
|
|
263
|
+
evidence: `uniqueVisitors=${uniqueVisitors}, attributionCoverageRate=${attributionCoverageRate}`,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (unreconciledPaidEvents > 0) {
|
|
268
|
+
anomalies.push({
|
|
269
|
+
type: 'billing_reconciliation',
|
|
270
|
+
severity: unreconciledPaidEvents >= 3 ? 'critical' : 'warning',
|
|
271
|
+
message: 'Paid events are waiting on reconciliation, which weakens revenue forecasts.',
|
|
272
|
+
evidence: `unreconciledPaidEvents=${unreconciledPaidEvents}`,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (buyerLossSignals >= 3 && safeRate(tooExpensiveSignals, buyerLossSignals, 4) >= 0.5) {
|
|
277
|
+
anomalies.push({
|
|
278
|
+
type: 'pricing_resistance',
|
|
279
|
+
severity: 'warning',
|
|
280
|
+
message: 'Price sensitivity dominates current loss reasons.',
|
|
281
|
+
evidence: `tooExpensiveSignals=${tooExpensiveSignals}, buyerLossSignals=${buyerLossSignals}`,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const underperformingCreator = creatorForecasts.find((row) => row.checkoutStarts >= 2 && row.bookedRevenueCents === 0 && row.opportunityRevenueCents >= 1500);
|
|
286
|
+
if (underperformingCreator) {
|
|
287
|
+
anomalies.push({
|
|
288
|
+
type: 'creator_underperformance',
|
|
289
|
+
severity: 'warning',
|
|
290
|
+
message: `Creator ${underperformingCreator.key} is generating intent without revenue conversion.`,
|
|
291
|
+
evidence: `checkouts=${underperformingCreator.checkoutStarts}, opportunityRevenueCents=${underperformingCreator.opportunityRevenueCents}`,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const underperformingSource = sourceForecasts.find((row) => row.checkoutStarts >= 3 && row.bookedRevenueCents === 0 && row.opportunityRevenueCents >= 1900);
|
|
296
|
+
if (underperformingSource) {
|
|
297
|
+
anomalies.push({
|
|
298
|
+
type: 'channel_underperformance',
|
|
299
|
+
severity: 'warning',
|
|
300
|
+
message: `Channel ${underperformingSource.key} is leaking revenue between checkout and paid.`,
|
|
301
|
+
evidence: `checkouts=${underperformingSource.checkoutStarts}, opportunityRevenueCents=${underperformingSource.opportunityRevenueCents}`,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return anomalies;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Principled revenue range from a Bayesian beta-binomial credible interval on the
|
|
310
|
+
* conversion rate (reuses scripts/conversion-rate-stats.js). Unlike the heuristic
|
|
311
|
+
* point forecast, this is honest about uncertainty: with little data the interval
|
|
312
|
+
* (and the revenue range) is wide; as N grows it tightens toward the empirical rate.
|
|
313
|
+
*
|
|
314
|
+
* Returns the low / expected / high booked-revenue in cents plus the rate interval
|
|
315
|
+
* and a data-grounded confidence = 1 - intervalWidth (clamped). Defensive: any
|
|
316
|
+
* stats error degrades to a point estimate so this never throws into the forecast.
|
|
317
|
+
*
|
|
318
|
+
* @returns {{trials, rateLo, rateExpected, rateHi, lowCents, expectedCents, highCents, credibleLevel, confidence}}
|
|
319
|
+
*/
|
|
320
|
+
function revenueCredibleRange({ successes, trials, revenuePerPaidCents, credibleLevel = 0.9 } = {}) {
|
|
321
|
+
const successCount = Math.max(0, Math.round(toNumber(successes)));
|
|
322
|
+
const trialCount = Math.max(successCount, Math.round(toNumber(trials)));
|
|
323
|
+
const revenuePerPaid = Math.max(1, Math.round(toNumber(revenuePerPaidCents)));
|
|
324
|
+
const toCents = (rate) => Math.round(trialCount * clamp01(rate) * revenuePerPaid);
|
|
325
|
+
|
|
326
|
+
if (trialCount === 0) {
|
|
327
|
+
return {
|
|
328
|
+
trials: 0,
|
|
329
|
+
rateLo: 0,
|
|
330
|
+
rateExpected: 0,
|
|
331
|
+
rateHi: 0,
|
|
332
|
+
lowCents: 0,
|
|
333
|
+
expectedCents: 0,
|
|
334
|
+
highCents: 0,
|
|
335
|
+
credibleLevel,
|
|
336
|
+
confidence: 0,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
const { estimateConversionRate } = require('./conversion-rate-stats');
|
|
342
|
+
const est = estimateConversionRate({ successes: successCount, trials: trialCount, credibleLevel });
|
|
343
|
+
const rateLo = clamp01(est.lower);
|
|
344
|
+
const rateHi = clamp01(est.upper);
|
|
345
|
+
const rateExpected = clamp01(est.mean);
|
|
346
|
+
return {
|
|
347
|
+
trials: trialCount,
|
|
348
|
+
rateLo: Number(rateLo.toFixed(6)),
|
|
349
|
+
rateExpected: Number(rateExpected.toFixed(6)),
|
|
350
|
+
rateHi: Number(rateHi.toFixed(6)),
|
|
351
|
+
lowCents: toCents(rateLo),
|
|
352
|
+
expectedCents: toCents(rateExpected),
|
|
353
|
+
highCents: toCents(rateHi),
|
|
354
|
+
credibleLevel,
|
|
355
|
+
// Narrower interval = more data = higher confidence. Width is in rate space [0,1].
|
|
356
|
+
confidence: Number(clamp01(1 - (rateHi - rateLo)).toFixed(4)),
|
|
357
|
+
};
|
|
358
|
+
} catch (_) {
|
|
359
|
+
const point = safeRate(successCount, trialCount);
|
|
360
|
+
return {
|
|
361
|
+
trials: trialCount,
|
|
362
|
+
rateLo: point,
|
|
363
|
+
rateExpected: point,
|
|
364
|
+
rateHi: point,
|
|
365
|
+
lowCents: toCents(point),
|
|
366
|
+
expectedCents: toCents(point),
|
|
367
|
+
highCents: toCents(point),
|
|
368
|
+
credibleLevel,
|
|
369
|
+
confidence: 0,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function buildPredictiveInsights({ telemetryAnalytics = {}, billingSummary = {}, stagingModel = {}, gateStats = {}, team = {} } = {}) {
|
|
375
|
+
const benchmarks = buildBenchmarks({ telemetryAnalytics, billingSummary, stagingModel });
|
|
376
|
+
const creators = scoreDimensionForecasts(stagingModel.dims && stagingModel.dims.creators ? stagingModel.dims.creators : [], benchmarks);
|
|
377
|
+
const sources = scoreDimensionForecasts(stagingModel.dims && stagingModel.dims.sources ? stagingModel.dims.sources : [], benchmarks);
|
|
378
|
+
const upgradePropensity = scoreUpgradePropensity({ telemetryAnalytics, billingSummary, stagingModel, gateStats, team });
|
|
379
|
+
const anomalies = detectPredictiveAnomalies({
|
|
380
|
+
telemetryAnalytics,
|
|
381
|
+
billingSummary,
|
|
382
|
+
creatorForecasts: creators,
|
|
383
|
+
sourceForecasts: sources,
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
const aggregatePredictedBookedRevenueCents = Math.max(
|
|
387
|
+
benchmarks.bookedRevenueCents,
|
|
388
|
+
Math.round(weightedAverage([
|
|
389
|
+
{ value: benchmarks.uniqueVisitors * smoothedRate(benchmarks.paidCustomers, benchmarks.uniqueVisitors, benchmarks.visitorToPaidRate, 12) * benchmarks.revenuePerPaidCents, weight: benchmarks.uniqueVisitors > 0 ? 0.2 : 0 },
|
|
390
|
+
{ value: benchmarks.checkoutStarts * smoothedRate(benchmarks.paidCustomers, benchmarks.checkoutStarts, benchmarks.checkoutToPaidRate, 8) * benchmarks.revenuePerPaidCents, weight: benchmarks.checkoutStarts > 0 ? 0.45 : 0 },
|
|
391
|
+
{ value: benchmarks.acquisitionLeads * smoothedRate(benchmarks.paidCustomers, benchmarks.acquisitionLeads, benchmarks.leadToPaidRate, 6) * benchmarks.revenuePerPaidCents, weight: benchmarks.acquisitionLeads > 0 ? 0.35 : 0 },
|
|
392
|
+
]))
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
generatedAt: new Date().toISOString(),
|
|
397
|
+
modelVersion: 'predictive-insights-v1',
|
|
398
|
+
benchmarks,
|
|
399
|
+
upgradePropensity,
|
|
400
|
+
revenueForecast: (() => {
|
|
401
|
+
// Strongest-signal conversion path for the credible range: prefer
|
|
402
|
+
// checkout→paid (highest intent + weight), fall back to visitor→paid.
|
|
403
|
+
const useCheckout = benchmarks.checkoutStarts > 0;
|
|
404
|
+
const range = revenueCredibleRange({
|
|
405
|
+
successes: benchmarks.paidCustomers,
|
|
406
|
+
trials: useCheckout ? benchmarks.checkoutStarts : benchmarks.uniqueVisitors,
|
|
407
|
+
revenuePerPaidCents: benchmarks.revenuePerPaidCents,
|
|
408
|
+
credibleLevel: 0.9,
|
|
409
|
+
});
|
|
410
|
+
return {
|
|
411
|
+
predictedBookedRevenueCents: aggregatePredictedBookedRevenueCents,
|
|
412
|
+
incrementalOpportunityCents: Math.max(0, aggregatePredictedBookedRevenueCents - benchmarks.bookedRevenueCents),
|
|
413
|
+
confidence: Number(clamp01((upgradePropensity.pro.confidence + upgradePropensity.team.confidence) / 2).toFixed(4)),
|
|
414
|
+
band: toBand(clamp01((upgradePropensity.pro.score * 0.55) + (upgradePropensity.team.score * 0.45))),
|
|
415
|
+
// Bayesian credible range — honest uncertainty, defensible to a buyer.
|
|
416
|
+
range: {
|
|
417
|
+
lowCents: range.lowCents,
|
|
418
|
+
expectedCents: range.expectedCents,
|
|
419
|
+
highCents: range.highCents,
|
|
420
|
+
},
|
|
421
|
+
rateCredibleInterval: {
|
|
422
|
+
lower: range.rateLo,
|
|
423
|
+
expected: range.rateExpected,
|
|
424
|
+
upper: range.rateHi,
|
|
425
|
+
level: range.credibleLevel,
|
|
426
|
+
basis: useCheckout ? 'checkout_to_paid' : 'visitor_to_paid',
|
|
427
|
+
sampleSize: range.trials,
|
|
428
|
+
},
|
|
429
|
+
statisticalConfidence: range.confidence,
|
|
430
|
+
};
|
|
431
|
+
})(),
|
|
432
|
+
topCreators: creators.slice(0, 5),
|
|
433
|
+
topSources: sources.slice(0, 5),
|
|
434
|
+
anomalies,
|
|
435
|
+
anomalySummary: {
|
|
436
|
+
count: anomalies.length,
|
|
437
|
+
severity: summarizeSeverity(anomalies),
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
module.exports = {
|
|
443
|
+
buildBenchmarks,
|
|
444
|
+
buildPredictiveInsights,
|
|
445
|
+
detectPredictiveAnomalies,
|
|
446
|
+
scoreDimensionForecasts,
|
|
447
|
+
scoreUpgradePropensity,
|
|
448
|
+
revenueCredibleRange,
|
|
449
|
+
};
|