thumbgate 1.39.0 → 1.40.1
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/.agents/skills/craft-playbook-gate/SKILL.md +51 -0
- package/.agents/skills/qwenwork-policy-group-honesty-not-clone/SKILL.md +36 -0
- 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 +11 -5
- 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 +104 -7
- package/adapters/opencode/opencode.json +1 -1
- package/adapters/strands/strands-middleware.js +31 -4
- package/bin/cli.js +191 -54
- 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 +3 -1
- package/config/post-deploy-marketing-pages.json +4 -4
- package/config/schemas/task-outcome-receipt.schema.json +9 -0
- package/hooks/hooks.json +24 -0
- package/openapi/openapi.yaml +7 -3
- package/package.json +87 -33
- 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/assets/diagrams/hero-thumbs.svg +2 -4
- 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 +5 -6
- package/public/codex-enterprise.html +1 -1
- package/public/codex-plugin.html +1 -1
- package/public/dashboard.html +775 -483
- package/public/diagnostic.html +15 -10
- 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 +302 -97
- package/public/install.html +16 -10
- package/public/js/buyer-intent.js +49 -8
- package/public/lessons.html +246 -83
- 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 +163 -66
- package/public/pro.html +3 -1
- package/public/project-switcher.js +76 -0
- package/public/whitepaper.html +1 -2
- package/scripts/action-receipts.js +393 -0
- 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-window.js +7 -1
- package/scripts/async-job-runner.js +66 -11
- package/scripts/audit-trail.js +37 -24
- package/scripts/auto-promote-gates.js +37 -27
- package/scripts/auto-wire-hooks.js +64 -25
- package/scripts/backfill-lesson-scopes.js +122 -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/cli-demo.js +5 -27
- package/scripts/cli-schema.js +25 -1
- package/scripts/commercial-offer.js +2 -2
- package/scripts/contextfs.js +9 -3
- package/scripts/craft-playbook-gate.js +550 -0
- package/scripts/cross-encoder-reranker.js +4 -0
- package/scripts/dashboard-chat.js +11 -0
- package/scripts/dashboard.js +574 -167
- package/scripts/decision-journal.js +7 -4
- package/scripts/docker-sandbox-planner.js +3 -3
- package/scripts/export-dpo-pairs.js +12 -7
- package/scripts/failure-diagnostics.js +11 -0
- 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/gate-stats.js +38 -5
- package/scripts/gates-engine.js +1326 -240
- package/scripts/generate-eval-scorecard.js +0 -1
- package/scripts/gitlab-sdlc-prompts.js +397 -0
- package/scripts/harness-tool-names.js +31 -5
- package/scripts/hook-runtime.js +10 -0
- package/scripts/hybrid-feedback-context.js +7 -2
- package/scripts/intervention-policy.js +2 -1
- 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/mabl-failure-honesty.js +273 -0
- package/scripts/mailer/index.js +17 -1
- package/scripts/mailer/resend-mailer.js +213 -179
- package/scripts/migrate-project-scope.js +209 -0
- package/scripts/model-distress-detector.js +3 -3
- package/scripts/operational-integrity.js +436 -3
- package/scripts/override-audit.js +2 -0
- package/scripts/owner-admin.js +338 -0
- package/scripts/pr-manager.js +194 -1
- package/scripts/product-feedback.js +35 -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-eval.js +1 -1
- package/scripts/prompt-guard.js +446 -52
- package/scripts/proof-report.js +232 -0
- package/scripts/provider-action-normalizer.js +14 -6
- package/scripts/qwenwork-policy-group.js +413 -0
- package/scripts/rate-limiter.js +41 -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/settings-hierarchy.js +4 -2
- package/scripts/statusline-meta.js +34 -23
- package/scripts/tailscale-october-access.js +416 -0
- package/scripts/task-outcomes.js +58 -2
- package/scripts/telemetry-analytics.js +260 -16
- 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/src/api/server.js +2478 -470
- 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/email-triage-server/index.js +973 -0
- package/src/mcp/email-triage-server/package.json +12 -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
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
resolveFallbackArtifactPath,
|
|
15
15
|
} = require('./feedback-paths');
|
|
16
16
|
const { readTextTail } = require('./fs-utils');
|
|
17
|
+
const { getOwnerEmails } = require('./bot-detection');
|
|
17
18
|
|
|
18
19
|
const TELEMETRY_FILE_NAME = 'telemetry-pings.jsonl';
|
|
19
20
|
const MARKETING_CLICK_EVENT_TYPES = new Set([
|
|
@@ -32,6 +33,9 @@ const MARKETING_CLICK_EVENT_TYPES = new Set([
|
|
|
32
33
|
'demo_click',
|
|
33
34
|
'github_repo_click',
|
|
34
35
|
'community_landing_redirect',
|
|
36
|
+
// Human /go/pro-direct hop. The browser beacon for the same tap is ignored
|
|
37
|
+
// below so one Pay click is one click.
|
|
38
|
+
'pro_checkout_direct_stripe',
|
|
35
39
|
]);
|
|
36
40
|
const CHECKOUT_START_EVENT_TYPES = new Set([
|
|
37
41
|
'checkout_start',
|
|
@@ -40,6 +44,7 @@ const CHECKOUT_START_EVENT_TYPES = new Set([
|
|
|
40
44
|
// issuing the external Payment Link redirect. This is stronger than a CTA
|
|
41
45
|
// click and is the service equivalent of the Pro checkout bootstrap.
|
|
42
46
|
'diagnostic_checkout_confirmed',
|
|
47
|
+
'pro_checkout_direct_stripe',
|
|
43
48
|
]);
|
|
44
49
|
|
|
45
50
|
function shouldIncludeLegacyTelemetry() {
|
|
@@ -85,6 +90,12 @@ function normalizeInteger(value) {
|
|
|
85
90
|
return Number.isFinite(parsed) ? Math.trunc(parsed) : null;
|
|
86
91
|
}
|
|
87
92
|
|
|
93
|
+
function normalizeFiniteNumber(value) {
|
|
94
|
+
if (value === undefined || value === null || value === '') return null;
|
|
95
|
+
const parsed = Number(value);
|
|
96
|
+
return Number.isFinite(parsed) ? Number(parsed.toFixed(4)) : null;
|
|
97
|
+
}
|
|
98
|
+
|
|
88
99
|
function normalizeRate(value) {
|
|
89
100
|
if (value === undefined || value === null || value === '') return null;
|
|
90
101
|
const parsed = Number(value);
|
|
@@ -105,6 +116,16 @@ function isCheckoutStartEvent(eventType) {
|
|
|
105
116
|
return CHECKOUT_START_EVENT_TYPES.has(String(eventType || '').toLowerCase());
|
|
106
117
|
}
|
|
107
118
|
|
|
119
|
+
function isDirectStripeBeacon(entry) {
|
|
120
|
+
return (entry.eventType || entry.event) === 'checkout_interstitial_cta_clicked'
|
|
121
|
+
&& entry.ctaId === 'pro_checkout_direct_stripe';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function isInterstitialPayHop(entry) {
|
|
125
|
+
return (entry.eventType || entry.event) === 'pro_checkout_direct_stripe'
|
|
126
|
+
&& entry.ctaPlacement === 'checkout_interstitial';
|
|
127
|
+
}
|
|
128
|
+
|
|
108
129
|
function getTelemetryPath(feedbackDir) {
|
|
109
130
|
return path.join(feedbackDir, TELEMETRY_FILE_NAME);
|
|
110
131
|
}
|
|
@@ -297,8 +318,32 @@ function addAudienceReason(reasons, code) {
|
|
|
297
318
|
if (!reasons.includes(code)) reasons.push(code);
|
|
298
319
|
}
|
|
299
320
|
|
|
300
|
-
|
|
321
|
+
const VALID_PERSISTED_AUDIENCE_REASONS = new Set([
|
|
322
|
+
'bot_or_automation_user_agent',
|
|
323
|
+
'test_identity',
|
|
324
|
+
'test_or_audit_attribution',
|
|
325
|
+
'internal_host',
|
|
326
|
+
'internal_operator_or_ci',
|
|
327
|
+
'unknown_direct_no_identity',
|
|
328
|
+
]);
|
|
329
|
+
|
|
330
|
+
function canonicalizeTelemetryEmail(rawEmail = '') {
|
|
331
|
+
const email = String(rawEmail || '').trim().toLowerCase();
|
|
332
|
+
const atIdx = email.indexOf('@');
|
|
333
|
+
if (atIdx <= 0 || atIdx !== email.lastIndexOf('@') || atIdx === email.length - 1) return '';
|
|
334
|
+
const localPart = email.slice(0, atIdx).replace(/\+.*$/, '');
|
|
335
|
+
const domainPart = email.slice(atIdx + 1);
|
|
336
|
+
return localPart && domainPart ? `${localPart}@${domainPart}` : '';
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function classifyTelemetryAudience(entry = {}, raw = {}, options = {}) {
|
|
301
340
|
const reasons = [];
|
|
341
|
+
for (const persisted of Array.isArray(options.persistedAudienceReasons) ? options.persistedAudienceReasons : []) {
|
|
342
|
+
const code = normalizeText(persisted, 64);
|
|
343
|
+
if (code && VALID_PERSISTED_AUDIENCE_REASONS.has(code)) {
|
|
344
|
+
addAudienceReason(reasons, code);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
302
347
|
const identityValues = [
|
|
303
348
|
raw.email,
|
|
304
349
|
raw.customerEmail,
|
|
@@ -343,16 +388,42 @@ function classifyTelemetryAudience(entry = {}, raw = {}) {
|
|
|
343
388
|
'curl/',
|
|
344
389
|
'wget/',
|
|
345
390
|
'lighthouse',
|
|
391
|
+
'money-v',
|
|
392
|
+
'protocolv1-gate',
|
|
393
|
+
'fuzz faster u fool',
|
|
394
|
+
'ffuf',
|
|
395
|
+
'firstpage/',
|
|
346
396
|
])) {
|
|
347
397
|
addAudienceReason(reasons, 'bot_or_automation_user_agent');
|
|
348
398
|
}
|
|
349
399
|
|
|
350
|
-
|
|
400
|
+
const canonicalOwners = new Set(
|
|
401
|
+
getOwnerEmails().map((ownerEmail) => canonicalizeTelemetryEmail(ownerEmail)).filter(Boolean)
|
|
402
|
+
);
|
|
403
|
+
const emailCandidates = [raw.email, raw.customerEmail, raw.buyerEmail, raw.userEmail]
|
|
404
|
+
.map((candidate) => canonicalizeTelemetryEmail(candidate))
|
|
405
|
+
.filter(Boolean);
|
|
406
|
+
const matchesOwnerEmail = canonicalOwners.size > 0
|
|
407
|
+
&& emailCandidates.some((candidate) => canonicalOwners.has(candidate));
|
|
408
|
+
if (matchesOwnerEmail || includesAnyToken([...identityValues, ...emailCandidates], [
|
|
351
409
|
'@example.com',
|
|
410
|
+
'@example.org',
|
|
411
|
+
'@example.net',
|
|
352
412
|
'buyer@example.com',
|
|
353
413
|
'test@example.com',
|
|
414
|
+
'buyer@acme.io',
|
|
415
|
+
'buyer@acme.com',
|
|
416
|
+
'@acme.io',
|
|
417
|
+
'@acme.com',
|
|
418
|
+
'@formtests.info',
|
|
419
|
+
'@mailinator.com',
|
|
420
|
+
'founder@agent-startup.io',
|
|
421
|
+
'test@test.com',
|
|
354
422
|
'codex-verification',
|
|
355
423
|
'audit@thumbgate.ai',
|
|
424
|
+
'test-checkout-probe@thumbgate.ai',
|
|
425
|
+
'e2e-probe',
|
|
426
|
+
'checkout-probe',
|
|
356
427
|
])) {
|
|
357
428
|
addAudienceReason(reasons, 'test_identity');
|
|
358
429
|
}
|
|
@@ -419,7 +490,61 @@ function classifyTelemetryAudience(entry = {}, raw = {}) {
|
|
|
419
490
|
};
|
|
420
491
|
}
|
|
421
492
|
|
|
422
|
-
function
|
|
493
|
+
function parseTelemetryCookies(headerValue) {
|
|
494
|
+
const cookies = {};
|
|
495
|
+
const raw = normalizeText(headerValue, 4096);
|
|
496
|
+
if (!raw) return cookies;
|
|
497
|
+
for (const chunk of raw.split(';')) {
|
|
498
|
+
const [name, ...rest] = chunk.split('=');
|
|
499
|
+
const key = normalizeText(name, 128);
|
|
500
|
+
if (!key) continue;
|
|
501
|
+
const value = normalizeText(rest.join('='), 512);
|
|
502
|
+
if (!value) continue;
|
|
503
|
+
try {
|
|
504
|
+
cookies[key] = decodeURIComponent(value);
|
|
505
|
+
} catch {
|
|
506
|
+
cookies[key] = value;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return cookies;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function inferCampaignVariant(raw = {}, cookies = {}, eventType = '') {
|
|
513
|
+
const explicit = pickFirstText(
|
|
514
|
+
raw.campaignVariant,
|
|
515
|
+
raw.variant,
|
|
516
|
+
cookies.thumbgate_campaign_variant,
|
|
517
|
+
cookies.tg_var
|
|
518
|
+
);
|
|
519
|
+
if (explicit) return explicit;
|
|
520
|
+
if (!isCheckoutStartEvent(eventType) && !isMarketingClickEvent(eventType)) {
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
const byOfferOrPlan = pickFirstText(
|
|
524
|
+
raw.offerCode,
|
|
525
|
+
raw.offer,
|
|
526
|
+
raw.coupon,
|
|
527
|
+
raw.planId,
|
|
528
|
+
raw.linkSlug,
|
|
529
|
+
raw.destinationSlug
|
|
530
|
+
);
|
|
531
|
+
if (byOfferOrPlan) return byOfferOrPlan.toLowerCase();
|
|
532
|
+
const campaign = pickFirstText(raw.utmCampaign, raw.campaign);
|
|
533
|
+
if (campaign && campaign.toLowerCase() !== 'organic') {
|
|
534
|
+
return campaign.toLowerCase();
|
|
535
|
+
}
|
|
536
|
+
const cta = pickFirstText(raw.ctaId);
|
|
537
|
+
if (cta) return cta.toLowerCase();
|
|
538
|
+
const pathText = (pickFirstText(raw.destinationPath, raw.page, raw.landingPath, raw.path) || '').toLowerCase();
|
|
539
|
+
if (pathText.includes('bundle-49') || pathText.includes('bundle_49')) return 'bundle_49';
|
|
540
|
+
if (pathText.includes('pro-direct') || pathText.includes('pro_direct')) return 'pro_direct';
|
|
541
|
+
if (pathText.includes('playbook')) return 'playbook_999';
|
|
542
|
+
if (pathText.includes('diagnostic')) return 'sprint_diagnostic_499';
|
|
543
|
+
if (pathText.includes('checkout/pro')) return 'pro_checkout';
|
|
544
|
+
return isCheckoutStartEvent(eventType) ? 'direct_checkout' : null;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function sanitizeTelemetryPayload(payload = {}, headers = {}, options = {}) {
|
|
423
548
|
const envelope = payload && typeof payload === 'object' ? payload : {};
|
|
424
549
|
const nestedProps = envelope.props
|
|
425
550
|
&& typeof envelope.props === 'object'
|
|
@@ -429,6 +554,7 @@ function sanitizeTelemetryPayload(payload = {}, headers = {}) {
|
|
|
429
554
|
// Browser analytics libraries conventionally wrap event properties in
|
|
430
555
|
// `props`. Flatten that envelope while letting explicit top-level fields win.
|
|
431
556
|
const raw = { ...nestedProps, ...envelope };
|
|
557
|
+
const cookies = parseTelemetryCookies(headers?.cookie || headers?.Cookie);
|
|
432
558
|
const clientType = inferClientType(raw);
|
|
433
559
|
const eventType = inferEventType(raw, clientType);
|
|
434
560
|
const source = pickFirstText(raw.source, raw.utmSource, clientType === 'cli' ? 'cli' : 'direct');
|
|
@@ -437,6 +563,7 @@ function sanitizeTelemetryPayload(payload = {}, headers = {}) {
|
|
|
437
563
|
const utmCampaign = pickFirstText(raw.utmCampaign, raw.campaign, clientType === 'web' ? 'organic' : null);
|
|
438
564
|
const referrer = pickFirstText(raw.referrer, headers.referer, headers.referrer);
|
|
439
565
|
const referrerHost = parseReferrerHost(referrer);
|
|
566
|
+
const campaignVariant = inferCampaignVariant(raw, cookies, eventType);
|
|
440
567
|
const reasonCode = pickFirstText(
|
|
441
568
|
raw.reasonCode,
|
|
442
569
|
raw.reason,
|
|
@@ -451,10 +578,26 @@ function sanitizeTelemetryPayload(payload = {}, headers = {}) {
|
|
|
451
578
|
event: eventType,
|
|
452
579
|
eventType,
|
|
453
580
|
installId: pickFirstText(raw.installId),
|
|
454
|
-
visitorId: pickFirstText(
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
581
|
+
visitorId: pickFirstText(
|
|
582
|
+
raw.visitorId,
|
|
583
|
+
raw.visitor_id,
|
|
584
|
+
cookies.thumbgate_visitor_id,
|
|
585
|
+
cookies.tg_vid
|
|
586
|
+
),
|
|
587
|
+
sessionId: pickFirstText(
|
|
588
|
+
raw.sessionId,
|
|
589
|
+
raw.session_id,
|
|
590
|
+
raw.visitor_session_id,
|
|
591
|
+
cookies.thumbgate_session_id,
|
|
592
|
+
cookies.tg_sid
|
|
593
|
+
),
|
|
594
|
+
traceId: pickFirstText(raw.traceId, raw.trace_id),
|
|
595
|
+
acquisitionId: pickFirstText(
|
|
596
|
+
raw.acquisitionId,
|
|
597
|
+
raw.acquisition_id,
|
|
598
|
+
cookies.thumbgate_acquisition_id,
|
|
599
|
+
cookies.tg_aid
|
|
600
|
+
),
|
|
458
601
|
version: pickFirstText(raw.version, raw.appVersion),
|
|
459
602
|
platform: pickFirstText(raw.platform),
|
|
460
603
|
nodeVersion: pickFirstText(raw.nodeVersion),
|
|
@@ -472,7 +615,7 @@ function sanitizeTelemetryPayload(payload = {}, headers = {}) {
|
|
|
472
615
|
utmContent: pickFirstText(raw.utmContent),
|
|
473
616
|
utmTerm: pickFirstText(raw.utmTerm),
|
|
474
617
|
creator: pickFirstText(raw.creator, raw.creatorHandle, raw.creator_handle),
|
|
475
|
-
campaignVariant
|
|
618
|
+
campaignVariant,
|
|
476
619
|
offerCode: pickFirstText(raw.offerCode, raw.offer, raw.coupon),
|
|
477
620
|
community: pickFirstText(raw.community, raw.subreddit),
|
|
478
621
|
postId: pickFirstText(raw.postId, raw.post_id),
|
|
@@ -480,7 +623,7 @@ function sanitizeTelemetryPayload(payload = {}, headers = {}) {
|
|
|
480
623
|
ctaId: pickFirstText(raw.ctaId),
|
|
481
624
|
ctaPlacement: pickFirstText(raw.ctaPlacement),
|
|
482
625
|
planId: pickFirstText(raw.planId),
|
|
483
|
-
segment: pickFirstText(raw.segment, raw.buyerSegment,
|
|
626
|
+
segment: pickFirstText(raw.segment, raw.buyerSegment, campaignVariant),
|
|
484
627
|
experimentId: pickFirstText(raw.experimentId, raw.experiment, raw.utmCampaign),
|
|
485
628
|
value: normalizeInteger(raw.value),
|
|
486
629
|
currency: pickFirstText(raw.currency),
|
|
@@ -515,12 +658,20 @@ function sanitizeTelemetryPayload(payload = {}, headers = {}) {
|
|
|
515
658
|
isBot: pickFirstText(raw.isBot),
|
|
516
659
|
interstitialSampled: pickFirstText(raw.interstitialSampled),
|
|
517
660
|
interstitialSampleRate: normalizeRate(raw.interstitialSampleRate),
|
|
661
|
+
gateId: pickFirstText(raw.gateId, raw.gate),
|
|
662
|
+
latencyMs: normalizeInteger(raw.latencyMs),
|
|
663
|
+
signupToFirstBlockMs: normalizeInteger(raw.signupToFirstBlockMs),
|
|
664
|
+
elapsedSinceOpenMs: normalizeInteger(raw.elapsedSinceOpenMs),
|
|
665
|
+
minutesSinceInstall: normalizeFiniteNumber(raw.minutesSinceInstall),
|
|
666
|
+
minutesToFirstBlock: normalizeFiniteNumber(raw.minutesToFirstBlock),
|
|
667
|
+
daysSinceInstall: normalizeInteger(raw.daysSinceInstall),
|
|
668
|
+
visitorType: pickFirstText(raw.visitorType),
|
|
518
669
|
attributionTagged: Boolean(
|
|
519
670
|
pickFirstText(raw.utmSource, raw.utmMedium, raw.utmCampaign, raw.utmContent, raw.utmTerm)
|
|
520
671
|
),
|
|
521
672
|
};
|
|
522
673
|
|
|
523
|
-
const audience = classifyTelemetryAudience(entry, raw);
|
|
674
|
+
const audience = classifyTelemetryAudience(entry, raw, options);
|
|
524
675
|
entry.audience = audience.audience;
|
|
525
676
|
entry.trafficAudience = audience.audience;
|
|
526
677
|
entry.audienceReasons = audience.reasons;
|
|
@@ -544,7 +695,7 @@ function appendTelemetryEvent(feedbackDir, payload = {}, headers = {}) {
|
|
|
544
695
|
if (headerHasPrivacyOptOut(headers)) {
|
|
545
696
|
return null;
|
|
546
697
|
}
|
|
547
|
-
const entry = sanitizeTelemetryPayload(payload, headers);
|
|
698
|
+
const entry = { ...sanitizeTelemetryPayload(payload, headers), ...require('./project-identity').projectForRecord(payload) };
|
|
548
699
|
const telemetryPath = getTelemetryPath(feedbackDir);
|
|
549
700
|
fs.mkdirSync(path.dirname(telemetryPath), { recursive: true });
|
|
550
701
|
fs.appendFileSync(telemetryPath, `${JSON.stringify(entry)}\n`, 'utf-8');
|
|
@@ -552,6 +703,19 @@ function appendTelemetryEvent(feedbackDir, payload = {}, headers = {}) {
|
|
|
552
703
|
}
|
|
553
704
|
|
|
554
705
|
const DEFAULT_BOUNDED_TELEMETRY_TAIL_BYTES = 8 * 1024 * 1024;
|
|
706
|
+
const WINDOW_TELEMETRY_TAIL_BYTES = Object.freeze({
|
|
707
|
+
today: 8 * 1024 * 1024,
|
|
708
|
+
'7d': 16 * 1024 * 1024,
|
|
709
|
+
'30d': 32 * 1024 * 1024,
|
|
710
|
+
'90d': 64 * 1024 * 1024,
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
function resolveBoundedTelemetryTailBytes(analyticsWindow, options = {}) {
|
|
714
|
+
const explicit = Number(options.telemetryTailBytes);
|
|
715
|
+
if (Number.isFinite(explicit) && explicit > 0) return explicit;
|
|
716
|
+
const windowKey = analyticsWindow?.window;
|
|
717
|
+
return WINDOW_TELEMETRY_TAIL_BYTES[windowKey] || DEFAULT_BOUNDED_TELEMETRY_TAIL_BYTES;
|
|
718
|
+
}
|
|
555
719
|
|
|
556
720
|
// Delegates to readTextTail(), which applies an UNCONDITIONAL full-read ceiling
|
|
557
721
|
// and drops the partial first line after a mid-file seek.
|
|
@@ -587,7 +751,9 @@ function parseTelemetryLines(raw) {
|
|
|
587
751
|
.map((line) => {
|
|
588
752
|
try {
|
|
589
753
|
const parsed = JSON.parse(line);
|
|
590
|
-
const normalized = sanitizeTelemetryPayload(parsed
|
|
754
|
+
const normalized = sanitizeTelemetryPayload(parsed, {}, {
|
|
755
|
+
persistedAudienceReasons: parsed?.audienceReasons,
|
|
756
|
+
});
|
|
591
757
|
return {
|
|
592
758
|
...normalized,
|
|
593
759
|
receivedAt: pickFirstText(parsed.receivedAt, parsed.timestamp) || normalized.receivedAt,
|
|
@@ -742,7 +908,7 @@ function summarizeExternalTrafficQuality(events) {
|
|
|
742
908
|
incrementCounter(pageViewsByTrafficChannel, entry.trafficChannel);
|
|
743
909
|
}
|
|
744
910
|
|
|
745
|
-
if (isMarketingClickEvent(eventType)) {
|
|
911
|
+
if (isMarketingClickEvent(eventType) && !isDirectStripeBeacon(entry)) {
|
|
746
912
|
externalCtaClicks += 1;
|
|
747
913
|
}
|
|
748
914
|
|
|
@@ -815,7 +981,7 @@ function summarizeExternalTrafficQuality(events) {
|
|
|
815
981
|
function getTelemetrySummary(feedbackDir, options = {}) {
|
|
816
982
|
const analyticsWindow = resolveAnalyticsWindow(options);
|
|
817
983
|
const telemetryLoadOptions = analyticsWindow.bounded
|
|
818
|
-
? { maxBytes:
|
|
984
|
+
? { maxBytes: resolveBoundedTelemetryTailBytes(analyticsWindow, options) }
|
|
819
985
|
: {};
|
|
820
986
|
// readTextTail() applies an unconditional ceiling even for the unbounded
|
|
821
987
|
// ("lifetime") window, so a large enough telemetry log is read as a tail.
|
|
@@ -881,6 +1047,9 @@ function getTelemetrySummary(feedbackDir, options = {}) {
|
|
|
881
1047
|
let ctaClicks = 0;
|
|
882
1048
|
let ctaImpressions = 0;
|
|
883
1049
|
let checkoutStarts = 0;
|
|
1050
|
+
let qualifiedCancelPageViews = 0;
|
|
1051
|
+
const checkoutStartCandidates = [];
|
|
1052
|
+
const visitorWebEventCounts = new Map();
|
|
884
1053
|
let diagnosticCheckoutStarts = 0;
|
|
885
1054
|
let checkoutInterstitialViews = 0;
|
|
886
1055
|
let checkoutBotDeflections = 0;
|
|
@@ -933,6 +1102,9 @@ function getTelemetrySummary(feedbackDir, options = {}) {
|
|
|
933
1102
|
webEvents += 1;
|
|
934
1103
|
const visitorKey = pickFirstText(entry.visitorId, entry.installId, entry.sessionId);
|
|
935
1104
|
if (visitorKey) webVisitors.add(visitorKey);
|
|
1105
|
+
if (visitorKey) {
|
|
1106
|
+
visitorWebEventCounts.set(visitorKey, (visitorWebEventCounts.get(visitorKey) || 0) + 1);
|
|
1107
|
+
}
|
|
936
1108
|
if (entry.sessionId) webSessions.add(entry.sessionId);
|
|
937
1109
|
if (entry.visitorId) webEventsWithVisitorId += 1;
|
|
938
1110
|
if (entry.sessionId) webEventsWithSessionId += 1;
|
|
@@ -952,7 +1124,7 @@ function getTelemetrySummary(feedbackDir, options = {}) {
|
|
|
952
1124
|
if (entry.attributionTagged) attributedPageViews += 1;
|
|
953
1125
|
}
|
|
954
1126
|
|
|
955
|
-
if (isMarketingClickEvent(entry.eventType || entry.event)) {
|
|
1127
|
+
if (isMarketingClickEvent(entry.eventType || entry.event) && !isDirectStripeBeacon(entry)) {
|
|
956
1128
|
ctaClicks += 1;
|
|
957
1129
|
incrementCounter(ctaClicksBySource, entry.source);
|
|
958
1130
|
incrementCounter(ctaClicksByCampaign, entry.utmCampaign);
|
|
@@ -975,7 +1147,7 @@ function getTelemetrySummary(feedbackDir, options = {}) {
|
|
|
975
1147
|
checkoutBotDeflections += 1;
|
|
976
1148
|
}
|
|
977
1149
|
|
|
978
|
-
if ((entry.eventType || entry.event) === 'checkout_interstitial_cta_clicked') {
|
|
1150
|
+
if ((entry.eventType || entry.event) === 'checkout_interstitial_cta_clicked' && !isDirectStripeBeacon(entry)) {
|
|
979
1151
|
checkoutInterstitialClicks += 1;
|
|
980
1152
|
if (entry.ctaId === 'pro_checkout_confirmed') {
|
|
981
1153
|
checkoutInterstitialProConfirms += 1;
|
|
@@ -990,8 +1162,16 @@ function getTelemetrySummary(feedbackDir, options = {}) {
|
|
|
990
1162
|
}
|
|
991
1163
|
}
|
|
992
1164
|
|
|
1165
|
+
if (isInterstitialPayHop(entry)) {
|
|
1166
|
+
checkoutInterstitialClicks += 1;
|
|
1167
|
+
checkoutInterstitialProConfirms += 1;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
993
1170
|
if (isCheckoutStartEvent(entry.eventType || entry.event)) {
|
|
994
1171
|
checkoutStarts += 1;
|
|
1172
|
+
if ((entry.audience || 'external') === 'external') {
|
|
1173
|
+
checkoutStartCandidates.push(entry);
|
|
1174
|
+
}
|
|
995
1175
|
if ((entry.eventType || entry.event) === 'diagnostic_checkout_confirmed') {
|
|
996
1176
|
diagnosticCheckoutStarts += 1;
|
|
997
1177
|
}
|
|
@@ -1029,6 +1209,9 @@ function getTelemetrySummary(feedbackDir, options = {}) {
|
|
|
1029
1209
|
|
|
1030
1210
|
if ((entry.eventType || entry.event) === 'checkout_cancel_page_view') {
|
|
1031
1211
|
checkoutCancelPageViews += 1;
|
|
1212
|
+
if ((entry.audience || 'external') === 'external') {
|
|
1213
|
+
qualifiedCancelPageViews += 1;
|
|
1214
|
+
}
|
|
1032
1215
|
}
|
|
1033
1216
|
|
|
1034
1217
|
if ((entry.eventType || entry.event) === 'checkout_paid_confirmed') {
|
|
@@ -1217,6 +1400,7 @@ function getTelemetrySummary(feedbackDir, options = {}) {
|
|
|
1217
1400
|
pageViews,
|
|
1218
1401
|
ctaClicks,
|
|
1219
1402
|
checkoutStarts,
|
|
1403
|
+
qualifiedCheckoutStarts: countNonBurstCheckoutStarts(checkoutStartCandidates, visitorWebEventCounts),
|
|
1220
1404
|
diagnosticCheckoutStarts,
|
|
1221
1405
|
checkoutInterstitialViews,
|
|
1222
1406
|
checkoutBotDeflections,
|
|
@@ -1231,6 +1415,7 @@ function getTelemetrySummary(feedbackDir, options = {}) {
|
|
|
1231
1415
|
checkoutAbandoned,
|
|
1232
1416
|
checkoutSuccessPageViews,
|
|
1233
1417
|
checkoutCancelPageViews,
|
|
1418
|
+
qualifiedCancelPageViews,
|
|
1234
1419
|
checkoutPaidConfirmations,
|
|
1235
1420
|
checkoutPending,
|
|
1236
1421
|
checkoutLookupFailures,
|
|
@@ -1330,6 +1515,63 @@ function getTopCounterEntry(counter) {
|
|
|
1330
1515
|
.sort((a, b) => b[1] - a[1])[0] || null;
|
|
1331
1516
|
}
|
|
1332
1517
|
|
|
1518
|
+
function countNonBurstCheckoutStarts(entries = [], visitorWebEventCounts = new Map()) {
|
|
1519
|
+
if (entries.length < 2) return entries.length;
|
|
1520
|
+
const buckets = new Map();
|
|
1521
|
+
const timedRows = [];
|
|
1522
|
+
entries.forEach((entry, idx) => {
|
|
1523
|
+
const ms = Date.parse(entry.receivedAt || entry.timestamp || '');
|
|
1524
|
+
if (!Number.isFinite(ms)) return;
|
|
1525
|
+
const identity = pickFirstText(
|
|
1526
|
+
entry.visitorId,
|
|
1527
|
+
entry.sessionId,
|
|
1528
|
+
entry.acquisitionId,
|
|
1529
|
+
entry.installId && entry.installId !== 'unknown' ? entry.installId : null
|
|
1530
|
+
) || '__anon__';
|
|
1531
|
+
const ctaId = entry.ctaId || entry.linkSlug || entry.page || '';
|
|
1532
|
+
const totalEvents = identity === '__anon__' ? 0 : (visitorWebEventCounts.get(identity) || 0);
|
|
1533
|
+
const row = { idx, ms, identity, ctaId, totalEvents };
|
|
1534
|
+
if (!buckets.has(identity)) buckets.set(identity, []);
|
|
1535
|
+
buckets.get(identity).push(row);
|
|
1536
|
+
timedRows.push(row);
|
|
1537
|
+
});
|
|
1538
|
+
const excluded = new Set();
|
|
1539
|
+
for (const [identity, rows] of buckets.entries()) {
|
|
1540
|
+
if (rows.length < 3) continue;
|
|
1541
|
+
rows.sort((a, b) => a.ms - b.ms);
|
|
1542
|
+
for (let i = 0; i < rows.length; i += 1) {
|
|
1543
|
+
const cluster = [rows[i]];
|
|
1544
|
+
for (let j = i + 1; j < rows.length; j += 1) {
|
|
1545
|
+
if (rows[j].ms - rows[i].ms > 60 * 1000) break;
|
|
1546
|
+
cluster.push(rows[j]);
|
|
1547
|
+
}
|
|
1548
|
+
const distinctTargets = new Set(cluster.map((row) => row.ctaId).filter(Boolean));
|
|
1549
|
+
if (cluster.length >= 3 && (distinctTargets.size >= 2 || identity === '__anon__')) {
|
|
1550
|
+
for (const row of cluster) excluded.add(row.idx);
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
const ephemeralRows = timedRows
|
|
1555
|
+
.filter((row) => (
|
|
1556
|
+
!excluded.has(row.idx) &&
|
|
1557
|
+
row.totalEvents <= 1 &&
|
|
1558
|
+
(buckets.get(row.identity)?.length || 0) <= 1
|
|
1559
|
+
))
|
|
1560
|
+
.sort((a, b) => a.ms - b.ms);
|
|
1561
|
+
for (let i = 0; i < ephemeralRows.length; i += 1) {
|
|
1562
|
+
const sweep = [ephemeralRows[i]];
|
|
1563
|
+
for (let j = i + 1; j < ephemeralRows.length; j += 1) {
|
|
1564
|
+
if (ephemeralRows[j].ms - ephemeralRows[i].ms > 60 * 1000) break;
|
|
1565
|
+
sweep.push(ephemeralRows[j]);
|
|
1566
|
+
}
|
|
1567
|
+
const distinctTargets = new Set(sweep.map((row) => row.ctaId).filter(Boolean));
|
|
1568
|
+
if (sweep.length >= 3 && distinctTargets.size >= 3) {
|
|
1569
|
+
for (const row of sweep) excluded.add(row.idx);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
return entries.length - excluded.size;
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1333
1575
|
function getTelemetryAnalytics(feedbackDir, options = {}) {
|
|
1334
1576
|
const summary = getTelemetrySummary(feedbackDir, options);
|
|
1335
1577
|
const topSource = getTopCounterEntry(summary.marketing.pageViewsBySource);
|
|
@@ -1402,6 +1644,7 @@ function getTelemetryAnalytics(feedbackDir, options = {}) {
|
|
|
1402
1644
|
ctas: {
|
|
1403
1645
|
totalClicks: summary.web.ctaClicks,
|
|
1404
1646
|
checkoutStarts: summary.web.checkoutStarts,
|
|
1647
|
+
qualifiedCheckoutStarts: summary.web.qualifiedCheckoutStarts,
|
|
1405
1648
|
diagnosticCheckoutStarts: summary.web.diagnosticCheckoutStarts,
|
|
1406
1649
|
checkoutInterstitialViews: summary.web.checkoutInterstitialViews,
|
|
1407
1650
|
checkoutBotDeflections: summary.web.checkoutBotDeflections,
|
|
@@ -1418,6 +1661,7 @@ function getTelemetryAnalytics(feedbackDir, options = {}) {
|
|
|
1418
1661
|
ctaImpressions: summary.web.ctaImpressions,
|
|
1419
1662
|
successPageViews: summary.web.checkoutSuccessPageViews,
|
|
1420
1663
|
cancelPageViews: summary.web.checkoutCancelPageViews,
|
|
1664
|
+
qualifiedCancelPageViews: summary.web.qualifiedCancelPageViews,
|
|
1421
1665
|
paidConfirmations: summary.web.checkoutPaidConfirmations,
|
|
1422
1666
|
sessionPending: summary.web.checkoutPending,
|
|
1423
1667
|
lookupFailures: summary.web.checkoutLookupFailures,
|
|
@@ -73,8 +73,9 @@ function extractFeedbackCorrectiveAction(record) {
|
|
|
73
73
|
|
|
74
74
|
function mapFeedbackResult(record) {
|
|
75
75
|
return {
|
|
76
|
+
...require('./project-identity').projectForRecord(record),
|
|
76
77
|
id: record.id || null,
|
|
77
|
-
source: 'feedback',
|
|
78
|
+
source: record._kind || 'feedback',
|
|
78
79
|
score: clampScore(record._score),
|
|
79
80
|
signal: normalizeRecordSignal(record.signal),
|
|
80
81
|
tags: safeArray(record.tags),
|
|
@@ -178,7 +179,8 @@ function deduplicateResults(results) {
|
|
|
178
179
|
const bestByFeedbackId = new Map();
|
|
179
180
|
|
|
180
181
|
for (const r of results) {
|
|
181
|
-
const
|
|
182
|
+
const rawFeedId = extractFeedbackId(r.id || r.title || r.file || '');
|
|
183
|
+
const feedId = rawFeedId ? (r.projectKey || 'unassigned') + ':' + rawFeedId : null;
|
|
182
184
|
if (feedId) {
|
|
183
185
|
const existing = bestByFeedbackId.get(feedId);
|
|
184
186
|
if (!existing) {
|
|
@@ -201,24 +203,25 @@ function deduplicateResults(results) {
|
|
|
201
203
|
const seenIds = new Set();
|
|
202
204
|
|
|
203
205
|
for (const r of results) {
|
|
204
|
-
const
|
|
206
|
+
const rawFeedId = extractFeedbackId(r.id || r.title || r.file || '');
|
|
207
|
+
const feedId = rawFeedId ? (r.projectKey || 'unassigned') + ':' + rawFeedId : null;
|
|
205
208
|
let recordToUse = r;
|
|
206
209
|
if (feedId) {
|
|
207
210
|
recordToUse = bestByFeedbackId.get(feedId);
|
|
208
|
-
if (seenIds.has(recordToUse.id)) continue;
|
|
211
|
+
if (seenIds.has((recordToUse.projectKey || 'unassigned') + ':' + recordToUse.id)) continue;
|
|
209
212
|
} else {
|
|
210
213
|
if (r.id && r.id !== 'null' && String(r.id).trim() !== '') {
|
|
211
|
-
if (seenIds.has(r.id)) continue;
|
|
214
|
+
if (seenIds.has((r.projectKey || 'unassigned') + ':' + r.id)) continue;
|
|
212
215
|
}
|
|
213
216
|
}
|
|
214
217
|
|
|
215
218
|
const normTitle = String(recordToUse.title || '').trim().toLowerCase();
|
|
216
219
|
const normContext = String(recordToUse.context || '').trim().toLowerCase();
|
|
217
|
-
const contentKey = `${normTitle}|${normContext}`;
|
|
220
|
+
const contentKey = `${recordToUse.projectKey || 'unassigned'}|${normTitle}|${normContext}`;
|
|
218
221
|
if (seenContent.has(contentKey)) continue;
|
|
219
222
|
|
|
220
223
|
if (recordToUse.id && recordToUse.id !== 'null' && String(recordToUse.id).trim() !== '') {
|
|
221
|
-
seenIds.add(recordToUse.id);
|
|
224
|
+
seenIds.add((recordToUse.projectKey || 'unassigned') + ':' + recordToUse.id);
|
|
222
225
|
}
|
|
223
226
|
seenContent.add(contentKey);
|
|
224
227
|
finalResults.push(recordToUse);
|
|
@@ -227,8 +230,8 @@ function deduplicateResults(results) {
|
|
|
227
230
|
return finalResults;
|
|
228
231
|
}
|
|
229
232
|
|
|
230
|
-
function getFeedbackResults(query, limit, signal, feedbackDir) {
|
|
231
|
-
const results = searchFeedbackLog(query, Math.max(limit * 3, limit), { feedbackDir });
|
|
233
|
+
function getFeedbackResults(query, limit, signal, feedbackDir, projectKey = null, includeMemories = false, localPathEvidence) {
|
|
234
|
+
const results = searchFeedbackLog(query, Math.max(limit * 3, limit), { feedbackDir, projectKey, signal, includeMemories, localPathEvidence });
|
|
232
235
|
const normalizedSignal = normalizeSignal(signal);
|
|
233
236
|
const filtered = normalizedSignal
|
|
234
237
|
? results.filter((record) => normalizeRecordSignal(record.signal) === normalizedSignal)
|
|
@@ -260,6 +263,8 @@ function searchThumbgate({
|
|
|
260
263
|
signal = null,
|
|
261
264
|
feedbackDir = null,
|
|
262
265
|
accessContext = null,
|
|
266
|
+
projectKey = null,
|
|
267
|
+
localPathEvidence,
|
|
263
268
|
} = {}) {
|
|
264
269
|
const trimmedQuery = String(query || '').trim();
|
|
265
270
|
if (!trimmedQuery) {
|
|
@@ -272,6 +277,12 @@ function searchThumbgate({
|
|
|
272
277
|
|
|
273
278
|
const fetchLimit = Math.max(100, normalizedLimit * 5);
|
|
274
279
|
|
|
280
|
+
if (projectKey != null) {
|
|
281
|
+
const unavailableSources = normalizedSource === 'all' ? ['context', 'rules', 'documents'] : ['context', 'rules', 'documents'].filter((item) => item === normalizedSource);
|
|
282
|
+
const rows = ['all', 'feedback'].includes(normalizedSource) ? getFeedbackResults(trimmedQuery, fetchLimit, normalizedSignal, feedbackDir, projectKey, normalizedSource === 'all', localPathEvidence) : [];
|
|
283
|
+
const results = deduplicateResults(sortResults(rows)).slice(0, normalizedLimit);
|
|
284
|
+
return { query: trimmedQuery, source: normalizedSource, signal: normalizedSignal, limit: normalizedLimit, engine: 'filesystem-search', returned: results.length, total: results.length, results, unavailableSources };
|
|
285
|
+
}
|
|
275
286
|
let results = [];
|
|
276
287
|
if (normalizedSource === 'feedback') {
|
|
277
288
|
const raw = getFeedbackResults(trimmedQuery, fetchLimit, normalizedSignal, feedbackDir);
|
|
@@ -318,7 +329,10 @@ async function searchThumbgateAsync({
|
|
|
318
329
|
embedder,
|
|
319
330
|
embedderId,
|
|
320
331
|
accessContext = null,
|
|
332
|
+
projectKey = null,
|
|
333
|
+
localPathEvidence,
|
|
321
334
|
} = {}) {
|
|
335
|
+
if (projectKey != null) return searchThumbgate({ query, source, limit, signal, feedbackDir, accessContext, projectKey, localPathEvidence });
|
|
322
336
|
const trimmedQuery = String(query || '').trim();
|
|
323
337
|
if (!trimmedQuery) throw new Error('query is required');
|
|
324
338
|
const normalizedSource = normalizeSource(source);
|
|
@@ -61,6 +61,7 @@ function recordToolCall({
|
|
|
61
61
|
writeRiskTier,
|
|
62
62
|
metadata,
|
|
63
63
|
feedbackDir,
|
|
64
|
+
projectKey, projectName, identitySource, cwd, hosted,
|
|
64
65
|
} = {}) {
|
|
65
66
|
const logPath = getKpiLogPath({ feedbackDir });
|
|
66
67
|
fs.mkdirSync(path.dirname(logPath), { recursive: true });
|
|
@@ -71,6 +72,7 @@ function recordToolCall({
|
|
|
71
72
|
metadata,
|
|
72
73
|
});
|
|
73
74
|
const entry = {
|
|
75
|
+
...require('./project-identity').projectForCapture({ projectKey, projectName, identitySource, cwd }, { hosted: hosted === undefined ? Boolean(require('./feedback-scope').tenantDataScope()) : Boolean(hosted) }),
|
|
74
76
|
id: `kpi_${Date.now()}_${crypto.randomBytes(4).toString('hex')}`,
|
|
75
77
|
timestamp: new Date().toISOString(),
|
|
76
78
|
toolName: toolName || 'unknown',
|
|
@@ -115,8 +117,8 @@ function pickDominantTier(tierCounts = {}) {
|
|
|
115
117
|
return best;
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
function computeToolKpis({ periodHours = 24, feedbackDir } = {}) {
|
|
119
|
-
const entries =
|
|
120
|
+
function computeToolKpis({ periodHours = 24, feedbackDir, projectKey } = {}) {
|
|
121
|
+
const entries = require('./project-catalog').readProjectRows(path.dirname(getKpiLogPath({ feedbackDir })), path.basename(getKpiLogPath({ feedbackDir })), { projectKey });
|
|
120
122
|
const cutoff = Date.now() - periodHours * 60 * 60 * 1000;
|
|
121
123
|
const recent = entries.filter((entry) => new Date(entry.timestamp).getTime() > cutoff);
|
|
122
124
|
const byTool = {};
|
|
@@ -210,6 +212,7 @@ function getAtRiskTools({
|
|
|
210
212
|
p95Threshold = 500,
|
|
211
213
|
periodHours = 24,
|
|
212
214
|
feedbackDir,
|
|
215
|
+
projectKey, projectName, identitySource, cwd, hosted,
|
|
213
216
|
} = {}) {
|
|
214
217
|
const { tools } = computeToolKpis({ periodHours, feedbackDir });
|
|
215
218
|
return tools.filter((tool) => tool.requestCount >= 3
|
package/scripts/tool-registry.js
CHANGED
|
@@ -468,6 +468,47 @@ const TOOLS = [
|
|
|
468
468
|
},
|
|
469
469
|
},
|
|
470
470
|
}),
|
|
471
|
+
readOnlyTool({
|
|
472
|
+
name: 'graphrag_traverse',
|
|
473
|
+
description: 'Answer a multi-hop question over a Neo4j graph with a schema-first ReAct loop. Only read-only Cypher runs (static guard plus READ session); stops after 3 failed attempts and names the missing link instead of guessing. Needs NEO4J_URI, neo4j-driver and model credentials; otherwise returns status "unavailable".',
|
|
474
|
+
inputSchema: {
|
|
475
|
+
type: 'object',
|
|
476
|
+
additionalProperties: false,
|
|
477
|
+
required: ['query'],
|
|
478
|
+
properties: {
|
|
479
|
+
query: { type: 'string', description: 'The multi-hop question to answer.' },
|
|
480
|
+
maxSteps: { type: 'integer', minimum: 1, maximum: 10, description: 'Upper bound on ReAct steps. Default: 10.' },
|
|
481
|
+
},
|
|
482
|
+
},
|
|
483
|
+
}),
|
|
484
|
+
readOnlyTool({
|
|
485
|
+
name: 'route_workload',
|
|
486
|
+
description: 'Decide whether a workload goes to Claude (code, tool use, strict JSON) or Gemini (huge payloads, raw logs), or splits into ordered sub-tasks. Deterministic rules first; an LLM router is used for ambiguous work only when useModel is true. Returns a validated routing decision; does not run the workload.',
|
|
487
|
+
inputSchema: {
|
|
488
|
+
type: 'object',
|
|
489
|
+
additionalProperties: false,
|
|
490
|
+
required: ['workload'],
|
|
491
|
+
properties: {
|
|
492
|
+
workload: { type: 'string', description: 'The task text or payload to route.' },
|
|
493
|
+
useModel: { type: 'boolean', description: 'Allow an LLM router call for ambiguous workloads. Default: false.' },
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
}),
|
|
497
|
+
readOnlyTool({
|
|
498
|
+
name: 'trim_context',
|
|
499
|
+
description: 'Compact retrieved context for one target operation before inference: drops metadata and boilerplate, collapses repeats, and keeps error lines, stack frames, trace ids and matching declarations verbatim. Deterministic unless useModel is true and the result is still over tokenBudget.',
|
|
500
|
+
inputSchema: {
|
|
501
|
+
type: 'object',
|
|
502
|
+
additionalProperties: false,
|
|
503
|
+
required: ['rawContext', 'targetOperation'],
|
|
504
|
+
properties: {
|
|
505
|
+
rawContext: { type: 'string', description: 'Raw retrieved text to compact.' },
|
|
506
|
+
targetOperation: { type: 'string', description: 'What the downstream model must do with the context.' },
|
|
507
|
+
tokenBudget: { type: 'integer', minimum: 1, description: 'Target size in estimated tokens. Default: 2000.' },
|
|
508
|
+
useModel: { type: 'boolean', description: 'Allow an LLM compaction pass when over budget. Default: false.' },
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
}),
|
|
471
512
|
readOnlyTool({
|
|
472
513
|
name: 'plan_agent_design_governance',
|
|
473
514
|
description: 'Evaluate an agent workflow before adding tools, autonomy, or subagents. Recommends single-agent vs manager/decentralized patterns, baseline evals, instruction fixes, and tool safeguards.',
|
|
@@ -552,7 +593,7 @@ const TOOLS = [
|
|
|
552
593
|
inputSchema: {
|
|
553
594
|
type: 'object',
|
|
554
595
|
properties: {
|
|
555
|
-
offer: { type: 'string', description: 'Offer to advertise, such as Pro or
|
|
596
|
+
offer: { type: 'string', description: 'Offer to advertise, such as Pro or Setup Sprint.' },
|
|
556
597
|
audience: { type: 'string', description: 'Audience segment to target.' },
|
|
557
598
|
budget: { type: 'number', description: 'Initial test budget.' },
|
|
558
599
|
keywords: { type: 'array', items: { type: 'string' }, description: 'High-intent conversational queries.' },
|