thumbgate 1.40.12 → 1.40.14

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/src/api/server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  const { withDataScope, withoutDataScope, currentDataScope, tenantDataScope, assertScopedDataPath, dataScopeKey } = require('../../scripts/feedback-scope');
3
- const { parseProjectSelection, projectForCapture, projectForRecord, matchesProject, validProjectKey } = require('../../scripts/project-identity');
3
+ const { isProjectFolder, parseProjectSelection, projectForCapture, projectForRecord, matchesProject, validProjectKey } = require('../../scripts/project-identity');
4
4
  const { readProjectRows, buildProjectCatalog } = require('../../scripts/project-catalog');
5
5
  const ownerAdmin = require('../../scripts/owner-admin');
6
6
  const opsLog = require('../../scripts/ops-log');
@@ -255,6 +255,7 @@ const {
255
255
  } = require('../../scripts/gates-engine');
256
256
  const {
257
257
  summarizeFirstBlockEvents,
258
+ summarizeActivationFunnel,
258
259
  } = require('../../scripts/activation-tracker');
259
260
  const {
260
261
  evaluateOperationalIntegrity,
@@ -3152,6 +3153,7 @@ const CHECKOUT_GATE_NOTICES = Object.freeze({
3152
3153
  retry: "We couldn't confirm that click. Press the button again.",
3153
3154
  network: 'Your connection changed while we confirmed the click. Press the button again.',
3154
3155
  busy: 'Many checkouts are starting from your network right now. Wait a minute, then press the button again.',
3156
+ unavailable: "We couldn't open the Stripe payment page just now. Nothing was charged. Press the button again in a minute.",
3155
3157
  });
3156
3158
 
3157
3159
  function checkoutGateNoticeCode(reason) {
@@ -3871,6 +3873,8 @@ async function serveTrackedLinkRedirect({ req, res, parsed, hostedConfig, isHead
3871
3873
  return;
3872
3874
  }
3873
3875
  }
3876
+ // Set when an admitted click could not get a Stripe session; the visitor is told instead of silently seeing the same page.
3877
+ let sessionFailure = null;
3874
3878
  if (!isHeadRequest && isDirectProSessionSlug(target.slug) && process.env.STRIPE_SECRET_KEY) {
3875
3879
  try {
3876
3880
  const dynamicSessionUrl = await tryCreateDirectProCheckoutRedirect({
@@ -3894,6 +3898,7 @@ async function serveTrackedLinkRedirect({ req, res, parsed, hostedConfig, isHead
3894
3898
  res.end();
3895
3899
  return;
3896
3900
  }
3901
+ sessionFailure = 'no_session_url';
3897
3902
  } catch (err) {
3898
3903
  if (err && err.code === 'AUTOMATED_CHECKOUT_BLOCKED') {
3899
3904
  const deflectUrl = new URL(target.botDeflectPath || '/checkout/pro', hostedConfig.appOrigin);
@@ -3910,6 +3915,8 @@ async function serveTrackedLinkRedirect({ req, res, parsed, hostedConfig, isHead
3910
3915
  }
3911
3916
  // Dynamic session creation failed: Pro slugs go to the confirm page below.
3912
3917
  console.warn('[checkout] dynamic session creation failed', target.slug, err && (err.code || err.message));
3918
+ // Only a short code-shaped value reaches telemetry; any other error text becomes 'error'.
3919
+ sessionFailure = err && typeof err.code === 'string' && /^[A-Za-z0-9_]{1,40}$/.test(err.code) ? err.code : 'error';
3913
3920
  }
3914
3921
  }
3915
3922
  if (isProSubscriptionSlug(target.slug)) {
@@ -3917,6 +3924,16 @@ async function serveTrackedLinkRedirect({ req, res, parsed, hostedConfig, isHead
3917
3924
  // the visitor to the confirm page, never to a payment link.
3918
3925
  const confirmUrl = new URL('/checkout/pro', hostedConfig.appOrigin);
3919
3926
  appendTrackedLinkQueryParams(confirmUrl, parsed, { ...target, allowCustomerEmail: false });
3927
+ if (sessionFailure && req.method === 'POST') {
3928
+ // A real buyer clicked Pay and nothing opened: say so, and count it (the reason code only, never free text).
3929
+ confirmUrl.searchParams.set('gate_notice', 'unavailable');
3930
+ appendBestEffortTelemetry(
3931
+ FEEDBACK_DIR,
3932
+ { eventType: 'checkout_session_failed', clientType: 'web', page: `/go/${target.slug}`, reason: sessionFailure.slice(0, 60), planId: 'pro' },
3933
+ req.headers,
3934
+ 'checkout_session_failed'
3935
+ );
3936
+ }
3920
3937
  res.writeHead(302, {
3921
3938
  ...(journeyState.setCookieHeaders.length ? { 'Set-Cookie': journeyState.setCookieHeaders } : {}),
3922
3939
  'Cache-Control': 'no-store',
@@ -5140,6 +5157,7 @@ function renderSitemapXml(runtimeConfig) {
5140
5157
  { path: '/learn/future-agi-self-healing-agent-firewall', changefreq: 'weekly', priority: '0.85' },
5141
5158
  { path: '/learn/five-walls-enterprise-agent-deployment', changefreq: 'weekly', priority: '0.85' },
5142
5159
  { path: '/learn/okta-mcp-governance-per-tool-call-gates', changefreq: 'weekly', priority: '0.85' },
5160
+ { path: '/learn/ai-finops-agent-spend-guardrails', changefreq: 'weekly', priority: '0.85' },
5143
5161
  { path: '/compare/claude-code-hooks', changefreq: 'weekly', priority: '0.85' },
5144
5162
  { path: '/compare/bumblebee', changefreq: 'weekly', priority: '0.85' },
5145
5163
  { path: '/compare/anthropic-containment', changefreq: 'weekly', priority: '0.85' },
@@ -7001,6 +7019,10 @@ async function handleFirstBlockActivationRoute(req, res, expectedApiKey, expecte
7001
7019
  clientType: 'cli',
7002
7020
  installId: trustedInstallId,
7003
7021
  firstBlockAt: recorded.firstBlockAt,
7022
+ // Keep the CLI's own classification; an admin or operator key is the owner by definition.
7023
+ visitorType: (isAdmin || isOperator)
7024
+ ? 'owner'
7025
+ : (['real_user', 'owner', 'ci'].includes(body?.visitorType) ? body.visitorType : 'real_user'),
7004
7026
  ...(typeof body?.gateId === 'string' ? { gateId: body.gateId.slice(0, 120) } : {}),
7005
7027
  }, req.headers);
7006
7028
  } catch { /* telemetry best-effort */ }
@@ -7568,6 +7590,10 @@ function createUnscopedApiServer({ ownerAdminDependencies = {} } = {}) {
7568
7590
  health: () => ({ version: pkg.version, buildSha: BUILD_METADATA.buildSha, uptime: process.uptime() }),
7569
7591
  ...ownerAdminDependencies,
7570
7592
  })));
7593
+ // Cost meter for the owner console's unit economics: hosted deployments only (Railway sets RAILWAY_ENVIRONMENT), never under tests.
7594
+ if (!process.env.NODE_TEST_CONTEXT && (process.env.RAILWAY_ENVIRONMENT || process.env.THUMBGATE_COST_METER === '1')) {
7595
+ try { require('../../scripts/cost-meter').start({ feedbackDir: withoutDataScope(() => getFeedbackPaths().FEEDBACK_DIR) }); } catch { /* best-effort */ }
7596
+ }
7571
7597
  const observedRequests = new WeakSet();
7572
7598
  const eventBus = new EventEmitter();
7573
7599
  eventBus.setMaxListeners(200);
@@ -10423,8 +10449,13 @@ a{color:#8b9}</style></head><body><form class="card" method="post" action="/oaut
10423
10449
  const sevenDaysAgo = now - 7 * 24 * 60 * 60 * 1000;
10424
10450
 
10425
10451
  const classified = entries.map(e => {
10452
+ if (e.visitorType) return e;
10453
+ // A CLI ping comes from node, not a browser, so an empty User-Agent says nothing about it;
10454
+ // UA classification would label every unclassified CLI event (e.g. first_block) a bot.
10455
+ // The CLI marks CI and owner installs itself; one that didn't is a real install.
10456
+ if ((e.clientType || e.client) === 'cli') return { ...e, visitorType: 'real_user' };
10426
10457
  const cls = bd.classifyVisitor({ headers: { 'user-agent': e.userAgent || '' }, email: e.email || '' });
10427
- return { ...e, visitorType: e.visitorType || cls.type };
10458
+ return { ...e, visitorType: cls.type };
10428
10459
  });
10429
10460
 
10430
10461
  const recent = classified.filter(e => {
@@ -10459,6 +10490,8 @@ a{color:#8b9}</style></head><body><form class="card" method="post" action="/oaut
10459
10490
  'cli_capture', 'cli_recall', 'cli_stats',
10460
10491
  'activation_first_rule_promoted',
10461
10492
  'first_blocked_tool_call',
10493
+ // What production CLIs actually send for the first gate firing.
10494
+ 'first_block',
10462
10495
  ]);
10463
10496
  const thirtyDaysAgo = now - 30 * 24 * 60 * 60 * 1000;
10464
10497
  const last30 = classified.filter(e => {
@@ -10509,6 +10542,7 @@ a{color:#8b9}</style></head><body><form class="card" method="post" action="/oaut
10509
10542
  activeInstalls: activeInstalls30d.size,
10510
10543
  uniqueSessions: uniqueSessions30d.size,
10511
10544
  firstBlockedToolCall: summarizeFirstBlockEvents(last30),
10545
+ activationFunnel: summarizeActivationFunnel(last30),
10512
10546
  },
10513
10547
  last7Days: {
10514
10548
  total: recent.length,
@@ -10520,6 +10554,7 @@ a{color:#8b9}</style></head><body><form class="card" method="post" action="/oaut
10520
10554
  activeInstalls: activeInstalls7d.size,
10521
10555
  uniqueSessions: uniqueSessions7d.size,
10522
10556
  firstBlockedToolCall: summarizeFirstBlockEvents(recent),
10557
+ activationFunnel: summarizeActivationFunnel(recent),
10523
10558
  },
10524
10559
  byEventType,
10525
10560
  byVisitorType,
@@ -11820,7 +11855,12 @@ footer{margin-top:40px;padding-top:20px;border-top:1px solid #e5e7eb;color:#6b72
11820
11855
  const _token = extractBearerToken(req);
11821
11856
  if (_token && _token !== expectedApiKey) recordUsage(_token);
11822
11857
  Object.assign(projectOptions, { projectKey: requestProjectKey, feedbackDir: requestFeedbackDir }, projectEvidenceForRequest(req, parsed, requestFeedbackDir, requestDataIdentity));
11823
- if (req.method === 'GET' && pathname === '/v1/projects') { sendJson(res, 200, { ...buildProjectCatalog(requestFeedbackDir, projectOptions), projectDir: projectOptions.projectDir || process.env.THUMBGATE_PROJECT_DIR || null }); return; }
11858
+ if (req.method === 'GET' && pathname === '/v1/projects') {
11859
+ // The folder the dashboard was opened for: the page's own projectDir (loopback only), else the server's.
11860
+ const catalogDir = getEffectiveRequestedProjectSelection(req, parsed) || projectOptions.projectDir || process.env.THUMBGATE_PROJECT_DIR || null;
11861
+ sendJson(res, 200, { ...buildProjectCatalog(requestFeedbackDir, projectOptions), projectDir: catalogDir, projectDirIsProject: catalogDir ? isProjectFolder(catalogDir) : null });
11862
+ return;
11863
+ }
11824
11864
  if (requestProjectKey != null && req.method === 'GET' && ['/v1/dashboard', '/v1/feedback/stats'].includes(pathname)) {
11825
11865
  const data = generateDashboard(requestFeedbackDir, {
11826
11866
  projectKey: requestProjectKey, ...projectOptions, humanOnly: true,
@@ -344,8 +344,8 @@ const STRIPE_OFFER_CATALOG = Object.freeze({
344
344
  }),
345
345
  pro_19: Object.freeze({
346
346
  offerId: 'pro_19', productPagePath: '/pro', priceUsd: 19, billingType: 'subscription', proofPath: '/pro',
347
- headline: 'ThumbGate Pro is for one operator who already hit a repeated AI-agent failure and now needs proof: what was blocked, why it was blocked, and what changed before the next risky run.', ctaLabel: 'Start Pro',
348
- rationale: 'Start Pro when you want the local dashboard, DPO export, and a single proof lane for the repeated mistake you need to stop.',
347
+ headline: 'Keep every lesson your agent learned, and ask it what went wrong before.', ctaLabel: 'Start Pro',
348
+ rationale: 'The free CLI already denies catastrophic commands and secret leaks. ThumbGate Pro is about memory: every rule you teach with a thumbs-down stays active, you can record as many thumbs as you like, and you can search and export what was learned.',
349
349
  checkoutPath: '/go/pro-direct?utm_source=website&utm_medium=objection_rescue&utm_campaign=pro_upgrade',
350
350
  }),
351
351
  diagnostic_499: Object.freeze({