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
package/scripts/mailer/index.js
CHANGED
|
@@ -4,10 +4,26 @@
|
|
|
4
4
|
* scripts/mailer/index.js ā public entry point for the mailer module.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
sendEmail,
|
|
9
|
+
sendTrialWelcomeEmail,
|
|
10
|
+
sendNewsletterWelcomeEmail,
|
|
11
|
+
sendSignupWelcomeEmail,
|
|
12
|
+
dispatchSignupWelcomeEmail,
|
|
13
|
+
isBlockedSignupWelcomeRecipient,
|
|
14
|
+
renderTrialWelcomeBodies,
|
|
15
|
+
renderNewsletterWelcomeBodies,
|
|
16
|
+
renderSignupWelcomeBodies,
|
|
17
|
+
} = require('./resend-mailer');
|
|
8
18
|
|
|
9
19
|
module.exports = {
|
|
10
20
|
sendEmail,
|
|
11
21
|
sendTrialWelcomeEmail,
|
|
22
|
+
sendNewsletterWelcomeEmail,
|
|
23
|
+
sendSignupWelcomeEmail,
|
|
24
|
+
dispatchSignupWelcomeEmail,
|
|
25
|
+
isBlockedSignupWelcomeRecipient,
|
|
12
26
|
renderTrialWelcomeBodies,
|
|
27
|
+
renderNewsletterWelcomeBodies,
|
|
28
|
+
renderSignupWelcomeBodies,
|
|
13
29
|
};
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* scripts/mailer/resend-mailer.js
|
|
5
|
-
*
|
|
6
|
-
* Resend-backed transactional email sender for ThumbGate.
|
|
7
|
-
*
|
|
8
|
-
* Design goals:
|
|
9
|
-
* - Zero-dep: uses global `fetch` (Node 18+) to hit https://api.resend.com/emails.
|
|
10
|
-
* - Gracefully optional: if RESEND_API_KEY is unset, sends are skipped with a
|
|
11
|
-
* logged warning and the caller receives `{ sent: false, reason: 'no_api_key' }`.
|
|
12
|
-
* This prevents the Stripe webhook from failing when email is not configured.
|
|
13
|
-
* - Testable: accepts an injectable `fetch` implementation via opts.fetchImpl.
|
|
14
|
-
* - CAN-SPAM compliant: every commercial email carries business name, physical
|
|
15
|
-
* address, and a functional unsubscribe method.
|
|
16
|
-
*/
|
|
17
|
-
|
|
3
|
+
// Resend-backed transactional email sender for ThumbGate (zero-dep, CAN-SPAM compliant).
|
|
18
4
|
const dns = require('node:dns').promises;
|
|
19
|
-
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
20
7
|
const PRODUCT_NAME = 'ThumbGate Pro';
|
|
21
8
|
const DASHBOARD_URL = 'https://thumbgate-production.up.railway.app/dashboard';
|
|
22
9
|
const DEFAULT_CONTACT_EMAIL = 'igor@igorganapolsky.com';
|
|
@@ -36,21 +23,18 @@ const SENDER_DNS_CACHE_MS = 10 * 60 * 1000;
|
|
|
36
23
|
const ANGLE_EMAIL_RE = /<([^<>@\s]{1,64}@[^<>@\s]{1,255})>/;
|
|
37
24
|
const BARE_EMAIL_RE = /([^\s<>@]{1,64}@[^\s<>@]{1,255})/;
|
|
38
25
|
const DKIM_PUBLIC_KEY_RE = /^p=/i;
|
|
39
|
-
// Resend fronts outbound mail with Amazon SES; the MX for send.<domain> points
|
|
40
|
-
// at feedback-smtp.<region>.amazonses.com. Earlier revisions of this regex
|
|
41
|
-
// mistakenly matched `amazonaws.com`, so the positive branch never fired in
|
|
42
|
-
// production. Matching `amazonses.com` (optionally with a trailing dot) is
|
|
43
|
-
// what Resend's DNS setup wizard actually publishes.
|
|
44
26
|
const AMAZON_SES_MX_RE = /feedback-smtp\..*amazonses\.com\.?$/i;
|
|
45
27
|
const AMAZON_SES_SPF_RE = /include:amazonses\.com/i;
|
|
46
28
|
const TRAILING_EMAIL_DOMAIN_PUNCTUATION = new Set(['>', ')', ',', '.', ';']);
|
|
29
|
+
const BLOCKED_WELCOME_EMAILS = new Set(['igor@igorganapolsky.com', 'iganapolsky@gmail.com', 'igor.ganapolsky@gmail.com', 'support@thumbgate.ai', 'hello@thumbgate.app']);
|
|
30
|
+
const BLOCKED_WELCOME_DOMAINS = new Set(['igorganapolsky.com', 'thumbgate.ai', 'thumbgate.app', 'macyolosafeguards.io', 'ecisolutions.com', 'ecinexus.com', 'eci.com', 'example.com', 'example.org', 'example.net', 'test.com', 'localhost', 'formtests.info', 'mailinator.com', 'privaterelay.appleid.com']);
|
|
31
|
+
const BLOCKED_WELCOME_TLD_RE = /\.(?:test|example|invalid|local|localhost)$/i;
|
|
32
|
+
const BLOCKED_WELCOME_LOCAL_PREFIXES = ['test', 'testing', 'smoke', 'probe', 'synthetic', 'e2e', 'playwright', 'cypress', 'noreply', 'no-reply', 'donotreply', 'mailer-daemon', 'postmaster'];
|
|
33
|
+
const BLOCKED_WELCOME_SUBTAGS = ['test', 'testing', 'smoke', 'probe', 'e2e'];
|
|
34
|
+
const VALID_RECIPIENT_RE = /^[^\s@]{1,64}@[^\s@]{1,255}\.[^\s@.]{2,63}$/;
|
|
47
35
|
const senderDnsCache = new Map();
|
|
48
36
|
|
|
49
37
|
function getApiKey() {
|
|
50
|
-
// Accept both `RESEND_API_KEY` (Railway default, matches provider docs) and
|
|
51
|
-
// the `THUMBGATE_`-prefixed variant that `scripts/billing.js` already honors.
|
|
52
|
-
// Keeping the two readers in sync prevents a silent "skipped: no_api_key"
|
|
53
|
-
// regression if an operator sets only the prefixed name.
|
|
54
38
|
return process.env.RESEND_API_KEY || process.env.THUMBGATE_RESEND_API_KEY || '';
|
|
55
39
|
}
|
|
56
40
|
|
|
@@ -340,6 +324,31 @@ function formatTrialEndDate(trialEndAt) {
|
|
|
340
324
|
return `${month} ${day}, ${year}`;
|
|
341
325
|
}
|
|
342
326
|
|
|
327
|
+
const PRIMARY_CTA_STYLE = 'display:inline-block;background:#45bfd8;color:#061015;text-decoration:none;font-weight:700;padding:12px 20px;border-radius:6px;font-size:14px;';
|
|
328
|
+
const CODE_PRE_STYLE = 'margin:0 0 20px;border-radius:6px;padding:14px;font-size:13px;white-space:pre-wrap;word-break:break-word;';
|
|
329
|
+
|
|
330
|
+
function getFooterContext() {
|
|
331
|
+
const unsubscribeEmail = getUnsubscribeEmail();
|
|
332
|
+
return {
|
|
333
|
+
supportEmail: getSupportEmail(),
|
|
334
|
+
unsubscribeEmail,
|
|
335
|
+
businessName: getBusinessName(),
|
|
336
|
+
businessAddress: getBusinessAddress(),
|
|
337
|
+
unsubscribeMailto: `mailto:${unsubscribeEmail}?subject=unsubscribe&body=Please%20remove%20me%20from%20ThumbGate%20emails.`,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function renderEmailShell({ preheader = '', eyebrow = 'ThumbGate', headline, subhead = '', showLogo = false, bodyRowsHtml, footerReason, customerId = '', footer = getFooterContext() }) {
|
|
342
|
+
const eyebrowHtml = `<div style="font-size:13px;font-weight:700;letter-spacing:0.02em;text-transform:uppercase;color:#73d4e9;">${escapeHtml(eyebrow)}</div>`;
|
|
343
|
+
const headerBrand = showLogo
|
|
344
|
+
? `<table role="presentation" cellpadding="0" cellspacing="0"><tr><td style="padding-right:12px;"><img src="${BRAND_MARK_URL}" width="40" height="40" alt="ThumbGate" style="display:block;border-radius:8px;"></td><td>${eyebrowHtml}</td></tr></table>`
|
|
345
|
+
: eyebrowHtml;
|
|
346
|
+
const preheaderDiv = preheader ? `<div style="display:none;max-height:0;overflow:hidden;opacity:0;">${escapeHtml(preheader)}</div>` : '';
|
|
347
|
+
const subheadHtml = subhead ? `<p style="margin:0;font-size:14px;color:#9cbac4;">${escapeHtml(subhead)}</p>` : '';
|
|
348
|
+
const customerHtml = customerId ? `<p style="margin:8px 0 0;font-size:11px;color:#a0abb2;">Customer ID (for support): <code>${escapeHtml(customerId)}</code></p>` : '';
|
|
349
|
+
return `<!doctype html><html><body style="margin:0;background:#f5f7fb;padding:28px 12px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;color:#17212b;">${preheaderDiv}<table role="presentation" width="100%" cellspacing="0" cellpadding="0"><tr><td align="center"><table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="max-width:640px;background:#fff;border:1px solid #d8e2ea;border-radius:10px;overflow:hidden;"><tr><td style="background:#071115;padding:24px 28px;color:#e7fbff;">${headerBrand}<h1 style="margin:12px 0 6px;font-size:24px;color:#fff;">${escapeHtml(headline)}</h1>${subheadHtml}</td></tr>${bodyRowsHtml}<tr><td style="padding:16px 28px 22px;border-top:1px solid #e2e8ec;background:#fafbfc;"><p style="margin:0 0 6px;font-size:12px;color:#7a8790;">${escapeHtml(footerReason)} <a href="${escapeHtml(footer.unsubscribeMailto)}" style="color:#7a8790;">Unsubscribe</a> (${escapeHtml(footer.unsubscribeEmail)}).</p><p style="margin:0;font-size:12px;color:#7a8790;">${escapeHtml(footer.businessName)} · ${escapeHtml(footer.businessAddress)}</p>${customerHtml}</td></tr></table></td></tr></table></body></html>`;
|
|
350
|
+
}
|
|
351
|
+
|
|
343
352
|
function renderTrialWelcomeBodies({ licenseKey, customerId, customerName, trialEndAt } = {}) {
|
|
344
353
|
const activationCommand = `npx thumbgate pro --activate --key=${licenseKey}`;
|
|
345
354
|
const name = firstName(customerName);
|
|
@@ -353,11 +362,8 @@ function renderTrialWelcomeBodies({ licenseKey, customerId, customerName, trialE
|
|
|
353
362
|
const exampleFeedback =
|
|
354
363
|
'thumbs down: the answer skipped exact files and tests; next time include paths, commands, and verification evidence.';
|
|
355
364
|
const proofUrl = 'https://github.com/IgorGanapolsky/ThumbGate/blob/main/docs/VERIFICATION_EVIDENCE.md';
|
|
356
|
-
const
|
|
357
|
-
const unsubscribeEmail =
|
|
358
|
-
const businessName = getBusinessName();
|
|
359
|
-
const businessAddress = getBusinessAddress();
|
|
360
|
-
const unsubscribeMailto = `mailto:${unsubscribeEmail}?subject=unsubscribe&body=Please%20remove%20me%20from%20ThumbGate%20emails.`;
|
|
365
|
+
const footer = getFooterContext();
|
|
366
|
+
const { supportEmail, unsubscribeEmail, businessName, businessAddress } = footer;
|
|
361
367
|
const postscript =
|
|
362
368
|
`P.S. The first 10 minutes are the best time to catch your agent's most-repeated failure. ` +
|
|
363
369
|
`Open the dashboard, give one concrete thumbs down on a mistake you've seen twice, and watch ThumbGate build the gate.`;
|
|
@@ -398,94 +404,19 @@ function renderTrialWelcomeBodies({ licenseKey, customerId, customerName, trialE
|
|
|
398
404
|
const safeKey = escapeHtml(licenseKey);
|
|
399
405
|
const safeCmd = escapeHtml(activationCommand);
|
|
400
406
|
const safeGreeting = escapeHtml(greeting);
|
|
401
|
-
const safeSubhead = escapeHtml(subhead);
|
|
402
|
-
const safeHeadline = escapeHtml(headline);
|
|
403
|
-
const safeDescription = escapeHtml(description);
|
|
404
|
-
const safeExample = escapeHtml(exampleFeedback);
|
|
405
|
-
const safePostscript = escapeHtml(postscript);
|
|
406
407
|
const safeSupportEmail = escapeHtml(supportEmail);
|
|
407
|
-
const
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
<td align="center">
|
|
420
|
-
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="border-collapse:collapse;max-width:640px;background:#ffffff;border:1px solid #d8e2ea;border-radius:10px;overflow:hidden;">
|
|
421
|
-
<tr>
|
|
422
|
-
<td style="background:#071115;padding:24px 28px;color:#e7fbff;">
|
|
423
|
-
<table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
|
|
424
|
-
<tr>
|
|
425
|
-
<td style="vertical-align:middle;padding-right:12px;">
|
|
426
|
-
<img src="${BRAND_MARK_URL}" width="40" height="40" alt="ThumbGate" style="display:block;border-radius:8px;">
|
|
427
|
-
</td>
|
|
428
|
-
<td style="vertical-align:middle;">
|
|
429
|
-
<div style="font-size:13px;font-weight:700;letter-spacing:0.02em;text-transform:uppercase;color:#73d4e9;">${escapeHtml(PRODUCT_NAME)}</div>
|
|
430
|
-
</td>
|
|
431
|
-
</tr>
|
|
432
|
-
</table>
|
|
433
|
-
<h1 style="margin:16px 0 8px;font-size:26px;line-height:1.2;color:#ffffff;">${safeHeadline}</h1>
|
|
434
|
-
<p style="margin:0;font-size:14px;line-height:1.5;color:#9cbac4;">${safeSubhead}</p>
|
|
435
|
-
</td>
|
|
436
|
-
</tr>
|
|
437
|
-
<tr>
|
|
438
|
-
<td style="padding:26px 28px 6px;">
|
|
439
|
-
<p style="margin:0 0 12px;font-size:15px;line-height:1.6;color:#17212b;">${safeGreeting}</p>
|
|
440
|
-
<p style="margin:0 0 18px;font-size:15px;line-height:1.6;color:#344451;">${safeDescription}</p>
|
|
441
|
-
<p style="margin:0 0 24px;">
|
|
442
|
-
<a href="${DASHBOARD_URL}" style="display:inline-block;background:#45bfd8;color:#061015;text-decoration:none;font-weight:700;padding:12px 22px;border-radius:6px;font-size:15px;">Open your dashboard</a>
|
|
443
|
-
</p>
|
|
444
|
-
</td>
|
|
445
|
-
</tr>
|
|
446
|
-
<tr>
|
|
447
|
-
<td style="padding:0 28px 10px;">
|
|
448
|
-
<h2 style="margin:0 0 10px;font-size:17px;line-height:1.3;color:#17212b;">Your first 10 minutes</h2>
|
|
449
|
-
<p style="margin:0 0 8px;font-size:14px;line-height:1.55;color:#344451;"><strong>1. Activate Pro locally</strong></p>
|
|
450
|
-
<pre style="margin:0 0 20px;background:#081016;color:#d8f7e4;border:1px solid #23343d;border-radius:6px;padding:14px;font-size:13px;line-height:1.45;white-space:pre-wrap;word-break:break-word;"><code>${safeCmd}</code></pre>
|
|
451
|
-
|
|
452
|
-
<p style="margin:0 0 8px;font-size:14px;line-height:1.55;color:#344451;"><strong>2. Save your trial key</strong></p>
|
|
453
|
-
<pre style="margin:0 0 20px;background:#eef6f7;color:#0b343c;border:1px solid #c7e2e7;border-radius:6px;padding:14px;font-size:13px;line-height:1.45;white-space:pre-wrap;word-break:break-word;"><code>${safeKey}</code></pre>
|
|
454
|
-
|
|
455
|
-
<p style="margin:0 0 8px;font-size:14px;line-height:1.55;color:#344451;"><strong>3. Give one concrete thumbs up or thumbs down</strong></p>
|
|
456
|
-
<p style="margin:0 0 8px;font-size:13px;line-height:1.55;color:#526273;">Start with the failure you most want your agent to stop repeating.</p>
|
|
457
|
-
<pre style="margin:0 0 22px;background:#f1fff2;color:#22602b;border:1px solid #bae7c0;border-radius:6px;padding:14px;font-size:13px;line-height:1.45;white-space:pre-wrap;word-break:break-word;"><code>${safeExample}</code></pre>
|
|
458
|
-
</td>
|
|
459
|
-
</tr>
|
|
460
|
-
<tr>
|
|
461
|
-
<td style="padding:6px 28px 22px;">
|
|
462
|
-
<p style="margin:0 0 14px;font-size:14px;line-height:1.6;color:#344451;font-style:italic;">${safePostscript}</p>
|
|
463
|
-
<p style="margin:0 0 4px;font-size:14px;line-height:1.6;color:#17212b;">ā Igor, founder of ThumbGate</p>
|
|
464
|
-
<p style="margin:0;font-size:13px;line-height:1.55;color:#526273;">
|
|
465
|
-
Questions? Just reply to this email or write
|
|
466
|
-
<a href="mailto:${safeSupportEmail}" style="color:#087a91;">${safeSupportEmail}</a>.
|
|
467
|
-
</p>
|
|
468
|
-
</td>
|
|
469
|
-
</tr>
|
|
470
|
-
<tr>
|
|
471
|
-
<td style="padding:16px 28px 22px;border-top:1px solid #e2e8ec;background:#fafbfc;">
|
|
472
|
-
<p style="margin:0 0 6px;font-size:12px;line-height:1.5;color:#7a8790;">
|
|
473
|
-
You're getting this one-time email because you started a ${escapeHtml(PRODUCT_NAME)} trial.
|
|
474
|
-
<a href="${safeUnsubscribeMailto}" style="color:#7a8790;text-decoration:underline;">Unsubscribe</a>
|
|
475
|
-
(${safeUnsubscribeEmail}).
|
|
476
|
-
</p>
|
|
477
|
-
<p style="margin:0;font-size:12px;line-height:1.5;color:#7a8790;">
|
|
478
|
-
${safeBusinessName} · ${safeBusinessAddress}
|
|
479
|
-
</p>
|
|
480
|
-
${safeCustomer ? `<p style="margin:8px 0 0;font-size:11px;color:#a0abb2;">Customer ID (for support): <code>${safeCustomer}</code></p>` : ''}
|
|
481
|
-
</td>
|
|
482
|
-
</tr>
|
|
483
|
-
</table>
|
|
484
|
-
</td>
|
|
485
|
-
</tr>
|
|
486
|
-
</table>
|
|
487
|
-
</body>
|
|
488
|
-
</html>`;
|
|
408
|
+
const bodyRowsHtml = `<tr><td style="padding:26px 28px 6px;"><p style="margin:0 0 12px;font-size:15px;">${safeGreeting}</p><p style="margin:0 0 18px;font-size:15px;color:#344451;">${escapeHtml(description)}</p><p style="margin:0 0 24px;"><a href="${DASHBOARD_URL}" style="${PRIMARY_CTA_STYLE}">Open your dashboard</a></p></td></tr><tr><td style="padding:0 28px 10px;"><h2 style="margin:0 0 10px;font-size:17px;">Your first 10 minutes</h2><p style="margin:0 0 8px;font-size:14px;"><strong>1. Activate Pro locally</strong></p><pre style="${CODE_PRE_STYLE}background:#081016;color:#d8f7e4;border:1px solid #23343d;"><code>${safeCmd}</code></pre><p style="margin:0 0 8px;font-size:14px;"><strong>2. Save your trial key</strong></p><pre style="${CODE_PRE_STYLE}background:#eef6f7;color:#0b343c;border:1px solid #c7e2e7;"><code>${safeKey}</code></pre><p style="margin:0 0 8px;font-size:14px;"><strong>3. Give one concrete thumbs up or thumbs down</strong></p><p style="margin:0 0 8px;font-size:13px;color:#526273;">Start with the failure you most want your agent to stop repeating.</p><pre style="${CODE_PRE_STYLE}background:#f1fff2;color:#22602b;border:1px solid #bae7c0;"><code>${escapeHtml(exampleFeedback)}</code></pre></td></tr><tr><td style="padding:6px 28px 22px;"><p style="margin:0 0 14px;font-size:14px;font-style:italic;">${escapeHtml(postscript)}</p><p style="margin:0 0 4px;font-size:14px;">ā Igor, founder of ThumbGate</p><p style="margin:0;font-size:13px;color:#526273;">Questions? Just reply to this email or write <a href="mailto:${safeSupportEmail}" style="color:#087a91;">${safeSupportEmail}</a>.</p></td></tr>`;
|
|
409
|
+
const html = renderEmailShell({
|
|
410
|
+
preheader: 'Activate Pro in one command, open the dashboard, and start blocking repeated AI coding mistakes.',
|
|
411
|
+
eyebrow: PRODUCT_NAME,
|
|
412
|
+
headline,
|
|
413
|
+
subhead,
|
|
414
|
+
showLogo: true,
|
|
415
|
+
bodyRowsHtml,
|
|
416
|
+
footerReason: `You're getting this one-time email because you started a ${PRODUCT_NAME} trial.`,
|
|
417
|
+
customerId,
|
|
418
|
+
footer,
|
|
419
|
+
});
|
|
489
420
|
|
|
490
421
|
return { html, text, activationCommand, trialEndLabel, greeting, unsubscribeEmail, businessName, businessAddress };
|
|
491
422
|
}
|
|
@@ -513,11 +444,8 @@ async function sendTrialWelcomeEmail({ to, licenseKey, customerId, customerName,
|
|
|
513
444
|
}
|
|
514
445
|
|
|
515
446
|
function renderNewsletterWelcomeBodies() {
|
|
516
|
-
const
|
|
517
|
-
const unsubscribeEmail =
|
|
518
|
-
const businessName = getBusinessName();
|
|
519
|
-
const businessAddress = getBusinessAddress();
|
|
520
|
-
const unsubscribeMailto = `mailto:${unsubscribeEmail}?subject=unsubscribe&body=Please%20remove%20me%20from%20ThumbGate%20emails.`;
|
|
447
|
+
const footer = getFooterContext();
|
|
448
|
+
const { supportEmail, unsubscribeEmail, businessName, businessAddress } = footer;
|
|
521
449
|
const headline = 'Welcome to ThumbGate.';
|
|
522
450
|
const subhead =
|
|
523
451
|
'One concrete AI coding failure prevented per email. No theory, no fluff.';
|
|
@@ -545,70 +473,26 @@ function renderNewsletterWelcomeBodies() {
|
|
|
545
473
|
`${businessName} Ā· ${businessAddress}`,
|
|
546
474
|
].join('\n');
|
|
547
475
|
|
|
548
|
-
const safeHeadline = escapeHtml(headline);
|
|
549
|
-
const safeSubhead = escapeHtml(subhead);
|
|
550
|
-
const safeFirstLesson = escapeHtml(firstLesson);
|
|
551
476
|
const safeSupportEmail = escapeHtml(supportEmail);
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
<body style="margin:0;background:#f5f7fb;padding:28px 12px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;color:#17212b;">
|
|
560
|
-
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="border-collapse:collapse;">
|
|
561
|
-
<tr>
|
|
562
|
-
<td align="center">
|
|
563
|
-
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="border-collapse:collapse;max-width:640px;background:#ffffff;border:1px solid #d8e2ea;border-radius:10px;overflow:hidden;">
|
|
564
|
-
<tr>
|
|
565
|
-
<td style="background:#071115;padding:24px 28px;color:#e7fbff;">
|
|
566
|
-
<div style="font-size:13px;font-weight:700;letter-spacing:0.02em;text-transform:uppercase;color:#73d4e9;">ThumbGate</div>
|
|
567
|
-
<h1 style="margin:10px 0 6px;font-size:24px;line-height:1.25;color:#ffffff;">${safeHeadline}</h1>
|
|
568
|
-
<p style="margin:0;font-size:14px;line-height:1.5;color:#9cbac4;">${safeSubhead}</p>
|
|
569
|
-
</td>
|
|
570
|
-
</tr>
|
|
571
|
-
<tr>
|
|
572
|
-
<td style="padding:24px 28px 10px;">
|
|
573
|
-
<p style="margin:0 0 18px;font-size:15px;line-height:1.6;color:#344451;">${safeFirstLesson}</p>
|
|
574
|
-
<p style="margin:0 0 22px;">
|
|
575
|
-
<a href="${ctaLink}" style="display:inline-block;background:#45bfd8;color:#061015;text-decoration:none;font-weight:700;padding:12px 22px;border-radius:6px;font-size:15px;">See the full Pro loop</a>
|
|
576
|
-
</p>
|
|
577
|
-
</td>
|
|
578
|
-
</tr>
|
|
579
|
-
<tr>
|
|
580
|
-
<td style="padding:0 28px 22px;">
|
|
581
|
-
<p style="margin:0 0 4px;font-size:14px;line-height:1.6;color:#17212b;">ā Igor, founder of ThumbGate</p>
|
|
582
|
-
<p style="margin:0;font-size:13px;line-height:1.55;color:#526273;">
|
|
583
|
-
Questions? Reply or write
|
|
584
|
-
<a href="mailto:${safeSupportEmail}" style="color:#087a91;">${safeSupportEmail}</a>.
|
|
585
|
-
</p>
|
|
586
|
-
</td>
|
|
587
|
-
</tr>
|
|
588
|
-
<tr>
|
|
589
|
-
<td style="padding:16px 28px 22px;border-top:1px solid #e2e8ec;background:#fafbfc;">
|
|
590
|
-
<p style="margin:0 0 6px;font-size:12px;line-height:1.5;color:#7a8790;">
|
|
591
|
-
You signed up on thumbgate.ai.
|
|
592
|
-
<a href="${safeUnsubscribeMailto}" style="color:#7a8790;text-decoration:underline;">Unsubscribe</a>
|
|
593
|
-
(${safeUnsubscribeEmail}).
|
|
594
|
-
</p>
|
|
595
|
-
<p style="margin:0;font-size:12px;line-height:1.5;color:#7a8790;">
|
|
596
|
-
${safeBusinessName} · ${safeBusinessAddress}
|
|
597
|
-
</p>
|
|
598
|
-
</td>
|
|
599
|
-
</tr>
|
|
600
|
-
</table>
|
|
601
|
-
</td>
|
|
602
|
-
</tr>
|
|
603
|
-
</table>
|
|
604
|
-
</body>
|
|
605
|
-
</html>`;
|
|
477
|
+
const html = renderEmailShell({
|
|
478
|
+
headline,
|
|
479
|
+
subhead,
|
|
480
|
+
bodyRowsHtml: `<tr><td style="padding:24px 28px 10px;"><p style="margin:0 0 18px;font-size:15px;color:#344451;">${escapeHtml(firstLesson)}</p><p style="margin:0 0 22px;"><a href="${ctaLink}" style="${PRIMARY_CTA_STYLE}">See the full Pro loop</a></p></td></tr><tr><td style="padding:0 28px 22px;"><p style="margin:0 0 4px;font-size:14px;">ā Igor, founder of ThumbGate</p><p style="margin:0;font-size:13px;color:#526273;">Questions? Reply or write <a href="mailto:${safeSupportEmail}" style="color:#087a91;">${safeSupportEmail}</a>.</p></td></tr>`,
|
|
481
|
+
footerReason: 'You signed up on thumbgate.ai.',
|
|
482
|
+
footer,
|
|
483
|
+
});
|
|
606
484
|
|
|
607
485
|
return { html, text };
|
|
608
486
|
}
|
|
609
487
|
|
|
610
488
|
async function sendNewsletterWelcomeEmail({ to, fetchImpl, dnsResolver } = {}) {
|
|
611
489
|
if (!isNonEmptyString(to)) throw new Error('sendNewsletterWelcomeEmail: `to` is required');
|
|
490
|
+
const addr = extractEmailAddress(to).toLowerCase();
|
|
491
|
+
const at = addr.lastIndexOf('@');
|
|
492
|
+
const baseLocal = at > 0 ? addr.slice(0, at).split('+')[0] : '';
|
|
493
|
+
if (isOwnerEmailAlias(addr, baseLocal, getEmailDomain(addr)) || (getApiKey() && isBlockedSignupWelcomeRecipient(to))) {
|
|
494
|
+
return { sent: false, reason: 'blocked_test_or_owner_recipient' };
|
|
495
|
+
}
|
|
612
496
|
const { html, text } = renderNewsletterWelcomeBodies();
|
|
613
497
|
return sendEmail({
|
|
614
498
|
to,
|
|
@@ -621,12 +505,162 @@ async function sendNewsletterWelcomeEmail({ to, fetchImpl, dnsResolver } = {}) {
|
|
|
621
505
|
});
|
|
622
506
|
}
|
|
623
507
|
|
|
508
|
+
function isBlockedDomain(domain) {
|
|
509
|
+
if (!domain || BLOCKED_WELCOME_DOMAINS.has(domain) || BLOCKED_WELCOME_TLD_RE.test(domain)) return true;
|
|
510
|
+
for (const blocked of BLOCKED_WELCOME_DOMAINS) {
|
|
511
|
+
if (domain.endsWith(`.${blocked}`)) return true;
|
|
512
|
+
}
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function isOwnerEmailAlias(addr, baseLocal, domain) {
|
|
517
|
+
const blockedSet = new Set([...BLOCKED_WELCOME_EMAILS, ...splitCsv(process.env.THUMBGATE_OWNER_EMAILS)]);
|
|
518
|
+
if (blockedSet.has(addr) || blockedSet.has(`${baseLocal}@${domain}`)) return true;
|
|
519
|
+
if (domain !== 'gmail.com' && domain !== 'googlemail.com') return false;
|
|
520
|
+
const canonicalLocal = baseLocal.replaceAll('.', '');
|
|
521
|
+
for (const candidate of blockedSet) {
|
|
522
|
+
const at = candidate.lastIndexOf('@');
|
|
523
|
+
const candDomain = at > 0 ? candidate.slice(at + 1) : '';
|
|
524
|
+
if ((candDomain === 'gmail.com' || candDomain === 'googlemail.com') && candidate.slice(0, at).split('+')[0].replaceAll('.', '') === canonicalLocal) {
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function hasBlockedTokenPrefix(segment, prefixes) {
|
|
532
|
+
for (const prefix of prefixes) {
|
|
533
|
+
if (segment === prefix) return true;
|
|
534
|
+
const sep = segment[prefix.length];
|
|
535
|
+
if (segment.startsWith(prefix) && (sep === '.' || sep === '_' || sep === '-')) return true;
|
|
536
|
+
}
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function isBlockedLocalPart(localPart) {
|
|
541
|
+
const [base = '', ...subtags] = localPart.split('+');
|
|
542
|
+
if (hasBlockedTokenPrefix(base, BLOCKED_WELCOME_LOCAL_PREFIXES)) return true;
|
|
543
|
+
return subtags.some((tag) => hasBlockedTokenPrefix(tag, BLOCKED_WELCOME_SUBTAGS));
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function isBlockedSignupWelcomeRecipient(value) {
|
|
547
|
+
const addr = extractEmailAddress(value).toLowerCase();
|
|
548
|
+
if (!addr || !VALID_RECIPIENT_RE.test(addr)) return true;
|
|
549
|
+
const at = addr.lastIndexOf('@');
|
|
550
|
+
const localPart = addr.slice(0, at);
|
|
551
|
+
const baseLocal = localPart.split('+')[0];
|
|
552
|
+
const domain = getEmailDomain(addr);
|
|
553
|
+
if (isOwnerEmailAlias(addr, baseLocal, domain)) return true;
|
|
554
|
+
return isBlockedLocalPart(localPart) || isBlockedDomain(domain);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function resolvePublicOrigin(appOrigin) {
|
|
558
|
+
let trimmed = String(appOrigin || process.env.THUMBGATE_PUBLIC_APP_ORIGIN || 'https://thumbgate.ai').trim();
|
|
559
|
+
while (trimmed.endsWith('/')) trimmed = trimmed.slice(0, -1);
|
|
560
|
+
return trimmed || 'https://thumbgate.ai';
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function renderSignupWelcomeBodies({ customerName, appOrigin } = {}) {
|
|
564
|
+
const origin = resolvePublicOrigin(appOrigin);
|
|
565
|
+
const installUrl = `${origin}/#install`;
|
|
566
|
+
const diagnosticUrl = `${origin}/diagnostic`;
|
|
567
|
+
const greeting = firstName(customerName) ? `Hi ${firstName(customerName)},` : 'Hi there,';
|
|
568
|
+
const footer = getFooterContext();
|
|
569
|
+
const { unsubscribeEmail, businessName, businessAddress } = footer;
|
|
570
|
+
const intro = 'ThumbGate blocks leaked secrets and repeated AI coding mistakes at PreToolUse before a tool call runs.';
|
|
571
|
+
const text = [
|
|
572
|
+
greeting, '', 'Welcome to ThumbGate.', intro, '',
|
|
573
|
+
`1. Install free in 30 seconds (npx thumbgate init): ${installUrl}`,
|
|
574
|
+
`2. Want one workflow wired with you? Book the $499 diagnostic: ${diagnosticUrl}`, '',
|
|
575
|
+
'ā Igor, founder of ThumbGate', '', '---',
|
|
576
|
+
`You signed up on thumbgate.ai. Don't want these emails? Unsubscribe: ${unsubscribeEmail}`,
|
|
577
|
+
`${businessName} Ā· ${businessAddress}`,
|
|
578
|
+
].join('\n');
|
|
579
|
+
const html = renderEmailShell({
|
|
580
|
+
headline: 'Welcome to ThumbGate.',
|
|
581
|
+
bodyRowsHtml: `<tr><td style="padding:24px 28px 18px;"><p style="margin:0 0 12px;font-size:15px;">${escapeHtml(greeting)}</p><p style="margin:0 0 20px;font-size:15px;color:#344451;">${escapeHtml(intro)} Run <code>npx thumbgate init</code> locally, or have us wire one workflow end-to-end with you.</p><p style="margin:0 0 22px;"><a href="${escapeHtml(installUrl)}" style="${PRIMARY_CTA_STYLE}margin:0 10px 8px 0;">Install ThumbGate free</a><a href="${escapeHtml(diagnosticUrl)}" style="display:inline-block;background:#0f172a;color:#fff;text-decoration:none;font-weight:700;padding:12px 20px;border-radius:6px;font-size:14px;margin:0 0 8px 0;">Book the $499 diagnostic</a></p><p style="margin:0;font-size:14px;">ā Igor, founder of ThumbGate</p></td></tr>`,
|
|
582
|
+
footerReason: 'You signed up on thumbgate.ai.',
|
|
583
|
+
footer,
|
|
584
|
+
});
|
|
585
|
+
return { html, text, installUrl, diagnosticUrl, unsubscribeEmail, businessName, businessAddress };
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
async function sendSignupWelcomeEmail({ to, customerName, appOrigin, idempotencyKey, fetchImpl, dnsResolver } = {}) {
|
|
589
|
+
if (!isNonEmptyString(to)) throw new Error('sendSignupWelcomeEmail: `to` is required');
|
|
590
|
+
if (isBlockedSignupWelcomeRecipient(to)) {
|
|
591
|
+
return { sent: false, reason: 'blocked_test_or_owner_recipient' };
|
|
592
|
+
}
|
|
593
|
+
const cleanTo = extractEmailAddress(to).toLowerCase();
|
|
594
|
+
const { html, text } = renderSignupWelcomeBodies({ customerName, appOrigin });
|
|
595
|
+
const name = firstName(customerName);
|
|
596
|
+
const subject = name ? `${name}, welcome to ThumbGate` : 'Welcome to ThumbGate';
|
|
597
|
+
return sendEmail({
|
|
598
|
+
to: cleanTo,
|
|
599
|
+
subject,
|
|
600
|
+
html,
|
|
601
|
+
text,
|
|
602
|
+
replyTo: getReplyTo(),
|
|
603
|
+
idempotencyKey: idempotencyKey || `signup-welcome:${cleanTo}`,
|
|
604
|
+
fetchImpl,
|
|
605
|
+
dnsResolver,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function hasPriorSentSignupWelcome(ledgerPath, normalizedEmail) {
|
|
610
|
+
if (!ledgerPath || !fs.existsSync(ledgerPath)) return false;
|
|
611
|
+
let lines;
|
|
612
|
+
try { lines = fs.readFileSync(ledgerPath, 'utf8').split('\n').filter(Boolean); } catch { return false; }
|
|
613
|
+
for (const line of lines) {
|
|
614
|
+
try {
|
|
615
|
+
const row = JSON.parse(line);
|
|
616
|
+
if (String(row?.email || '').toLowerCase() === normalizedEmail && row?.status === 'sent') return true;
|
|
617
|
+
} catch { /* skip malformed ledger line */ }
|
|
618
|
+
}
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const inFlightWelcomeDispatches = new Set();
|
|
623
|
+
|
|
624
|
+
async function dispatchSignupWelcomeEmail({ to, customerName, source = 'sso_signup', feedbackDir, appOrigin, fetchImpl, dnsResolver } = {}) {
|
|
625
|
+
if (isBlockedSignupWelcomeRecipient(to)) return { sent: false, reason: 'blocked_test_or_owner_recipient' };
|
|
626
|
+
const cleanTo = extractEmailAddress(to).toLowerCase();
|
|
627
|
+
const ledgerPath = feedbackDir ? path.join(feedbackDir, 'signup-welcome-emails.jsonl') : null;
|
|
628
|
+
const flightKey = `${ledgerPath || ''}:${cleanTo}`;
|
|
629
|
+
if (inFlightWelcomeDispatches.has(flightKey) || hasPriorSentSignupWelcome(ledgerPath, cleanTo)) {
|
|
630
|
+
return { sent: false, reason: 'already_sent' };
|
|
631
|
+
}
|
|
632
|
+
inFlightWelcomeDispatches.add(flightKey);
|
|
633
|
+
try {
|
|
634
|
+
const result = await sendSignupWelcomeEmail({ to: cleanTo, customerName, appOrigin, fetchImpl, dnsResolver });
|
|
635
|
+
if (ledgerPath) {
|
|
636
|
+
try {
|
|
637
|
+
fs.mkdirSync(path.dirname(ledgerPath), { recursive: true });
|
|
638
|
+
fs.appendFileSync(ledgerPath, `${JSON.stringify({
|
|
639
|
+
recordedAt: new Date().toISOString(),
|
|
640
|
+
email: cleanTo,
|
|
641
|
+
source,
|
|
642
|
+
status: result.sent ? 'sent' : 'skipped',
|
|
643
|
+
reason: result.reason || null,
|
|
644
|
+
providerId: result.id || null,
|
|
645
|
+
})}\n`, { mode: 0o600 });
|
|
646
|
+
} catch { /* best-effort ledger write */ }
|
|
647
|
+
}
|
|
648
|
+
return result;
|
|
649
|
+
} finally {
|
|
650
|
+
inFlightWelcomeDispatches.delete(flightKey);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
624
654
|
module.exports = {
|
|
625
655
|
sendEmail,
|
|
626
656
|
sendTrialWelcomeEmail,
|
|
627
657
|
sendNewsletterWelcomeEmail,
|
|
658
|
+
sendSignupWelcomeEmail,
|
|
659
|
+
dispatchSignupWelcomeEmail,
|
|
660
|
+
isBlockedSignupWelcomeRecipient,
|
|
628
661
|
renderTrialWelcomeBodies,
|
|
629
662
|
renderNewsletterWelcomeBodies,
|
|
663
|
+
renderSignupWelcomeBodies,
|
|
630
664
|
_resolveSenderAddress: resolveSenderAddress,
|
|
631
665
|
_hasResendSenderDns: hasResendSenderDns,
|
|
632
666
|
_recordsHaveResendDns: recordsHaveResendDns,
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ThumbGate WriteGuard CLI & Gateway Runner
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('node:fs');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const {
|
|
11
|
+
evaluateMcpCall,
|
|
12
|
+
exportCloudflareWriteGuardPolicy,
|
|
13
|
+
classifyMcpTool,
|
|
14
|
+
} = require('../src/mcp-writeguard.js');
|
|
15
|
+
|
|
16
|
+
function parseArgs(args) {
|
|
17
|
+
const options = {
|
|
18
|
+
eval: null,
|
|
19
|
+
tool: null,
|
|
20
|
+
params: {},
|
|
21
|
+
server: 'default',
|
|
22
|
+
exportPolicy: false,
|
|
23
|
+
json: false,
|
|
24
|
+
auditLog: null,
|
|
25
|
+
help: false,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < args.length; i++) {
|
|
29
|
+
const arg = args[i];
|
|
30
|
+
if (arg === '--help' || arg === '-h') {
|
|
31
|
+
options.help = true;
|
|
32
|
+
} else if (arg === '--json') {
|
|
33
|
+
options.json = true;
|
|
34
|
+
} else if (arg === '--export-policy') {
|
|
35
|
+
options.exportPolicy = true;
|
|
36
|
+
} else if (arg === '--tool') {
|
|
37
|
+
options.tool = args[++i];
|
|
38
|
+
} else if (arg === '--server') {
|
|
39
|
+
options.server = args[++i];
|
|
40
|
+
} else if (arg === '--params') {
|
|
41
|
+
try {
|
|
42
|
+
options.params = JSON.parse(args[++i]);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
options.params = { raw: args[i] };
|
|
45
|
+
}
|
|
46
|
+
} else if (arg === '--eval') {
|
|
47
|
+
try {
|
|
48
|
+
options.eval = JSON.parse(args[++i]);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.error('Invalid JSON for --eval:', err.message);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
} else if (arg === '--audit-log') {
|
|
54
|
+
options.auditLog = args[++i];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return options;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function main() {
|
|
62
|
+
const args = process.argv.slice(2);
|
|
63
|
+
const opts = parseArgs(args);
|
|
64
|
+
|
|
65
|
+
if (opts.help) {
|
|
66
|
+
console.log(`ThumbGate WriteGuard ā Fine-Grained MCP Pre-Action Security Layer
|
|
67
|
+
|
|
68
|
+
Usage:
|
|
69
|
+
thumbgate writeguard --tool <name> [--params <json>] [--json]
|
|
70
|
+
thumbgate writeguard --eval <json-request> [--json]
|
|
71
|
+
thumbgate writeguard --export-policy [--json]
|
|
72
|
+
|
|
73
|
+
Options:
|
|
74
|
+
--tool <name> Tool name to evaluate
|
|
75
|
+
--params <json> JSON parameters passed to tool
|
|
76
|
+
--server <name> MCP server name (default: "default")
|
|
77
|
+
--eval <json> Full MCP call envelope to evaluate
|
|
78
|
+
--export-policy Export Cloudflare WriteGuard compatible JSON policy
|
|
79
|
+
--audit-log <path> Append scrubbed attribution event to audit file
|
|
80
|
+
--json Emit structured JSON output
|
|
81
|
+
--help, -h Show this help text
|
|
82
|
+
`);
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (opts.exportPolicy) {
|
|
87
|
+
const standardTools = [
|
|
88
|
+
'view_file',
|
|
89
|
+
'grep_search',
|
|
90
|
+
'list_dir',
|
|
91
|
+
'find_by_name',
|
|
92
|
+
'read_url_content',
|
|
93
|
+
'search_web',
|
|
94
|
+
'write_to_file',
|
|
95
|
+
'replace_file_content',
|
|
96
|
+
'run_command',
|
|
97
|
+
'manage_task',
|
|
98
|
+
'set_branch_governance',
|
|
99
|
+
'approve_protected_action',
|
|
100
|
+
'capture_feedback',
|
|
101
|
+
];
|
|
102
|
+
const policy = exportCloudflareWriteGuardPolicy(standardTools);
|
|
103
|
+
console.log(JSON.stringify(policy, null, 2));
|
|
104
|
+
process.exit(0);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const callRequest = opts.eval || {
|
|
108
|
+
server: opts.server,
|
|
109
|
+
tool: opts.tool || 'view_file',
|
|
110
|
+
parameters: opts.params,
|
|
111
|
+
context: {
|
|
112
|
+
user: process.env.USER || 'operator',
|
|
113
|
+
client: 'cli',
|
|
114
|
+
sessionId: process.env.THUMBGATE_SESSION_AGENT || 'local-cli',
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const receipt = evaluateMcpCall(callRequest);
|
|
119
|
+
|
|
120
|
+
if (opts.auditLog) {
|
|
121
|
+
try {
|
|
122
|
+
const line = JSON.stringify(receipt) + '\n';
|
|
123
|
+
fs.appendFileSync(opts.auditLog, line);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.error(`Warning: Failed to write audit log: ${err.message}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (opts.json) {
|
|
130
|
+
console.log(JSON.stringify(receipt, null, 2));
|
|
131
|
+
} else {
|
|
132
|
+
console.log(`\nš”ļø ThumbGate WriteGuard Intercept: ${receipt.tool}`);
|
|
133
|
+
console.log(`āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
134
|
+
console.log(` Decision : ${receipt.decision.toUpperCase()}`);
|
|
135
|
+
console.log(` Risk Tier : ${receipt.riskTier}`);
|
|
136
|
+
console.log(` Event ID : ${receipt.eventId}`);
|
|
137
|
+
console.log(` User/Client: ${receipt.user} (${receipt.client})`);
|
|
138
|
+
if (receipt.reasons.length > 0) {
|
|
139
|
+
console.log(` Reasons : ${receipt.reasons.join('; ')}`);
|
|
140
|
+
}
|
|
141
|
+
console.log(` Duration : ${receipt.durationMs}ms\n`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (receipt.decision === 'blocked') {
|
|
145
|
+
process.exit(2);
|
|
146
|
+
} else if (receipt.decision === 'escalated') {
|
|
147
|
+
process.exit(1);
|
|
148
|
+
} else {
|
|
149
|
+
process.exit(0);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const isMain = process.argv[1] && path.resolve(process.argv[1]) === __filename;
|
|
154
|
+
if (isMain) {
|
|
155
|
+
main();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
module.exports = { parseArgs, main };
|