thumbgate 1.39.1 → 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/.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 +62 -28
- 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 +159 -69
- 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 +75 -60
- 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-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/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-schema.js +1 -1
- package/scripts/commercial-offer.js +2 -2
- package/scripts/contextfs.js +9 -3
- 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/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 +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/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/mailer/index.js +17 -1
- package/scripts/mailer/resend-mailer.js +213 -179
- package/scripts/migrate-project-scope.js +209 -0
- 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/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/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/task-outcomes.js +29 -2
- package/scripts/telemetry-analytics.js +238 -13
- 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 +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/lesson-search.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { tenantDataScope, assertScopedDataPath } = require('./feedback-scope');
|
|
4
|
+
|
|
3
5
|
const path = require('node:path');
|
|
4
6
|
const { readJSONL, getFeedbackPaths } = require('./feedback-loop');
|
|
5
7
|
const { buildMemoryLifecycleView, scoreHybridMemoryMatch } = require('./agent-memory-lifecycle');
|
|
@@ -148,22 +150,11 @@ function buildLessonQuery(memory, parsed, sourceFeedback) {
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
function resolveLessonPaths(options = {}) {
|
|
151
|
-
|
|
152
|
-
const feedbackDir = path.resolve(String(options.feedbackDir));
|
|
153
|
-
return {
|
|
154
|
-
FEEDBACK_DIR: feedbackDir,
|
|
155
|
-
FEEDBACK_LOG_PATH: path.join(feedbackDir, 'feedback-log.jsonl'),
|
|
156
|
-
MEMORY_LOG_PATH: path.join(feedbackDir, 'memory-log.jsonl'),
|
|
157
|
-
PREVENTION_RULES_PATH: path.join(feedbackDir, 'prevention-rules.md'),
|
|
158
|
-
AUTO_GATES_PATH: path.join(feedbackDir, 'auto-promoted-gates.json'),
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const paths = getFeedbackPaths();
|
|
153
|
+
const paths = getFeedbackPaths(options.feedbackDir ? { feedbackDir: path.resolve(String(options.feedbackDir)) } : {});
|
|
163
154
|
return {
|
|
164
155
|
...paths,
|
|
165
|
-
PREVENTION_RULES_PATH: path.join(paths.FEEDBACK_DIR, 'prevention-rules.md'),
|
|
166
|
-
AUTO_GATES_PATH: path.join(paths.FEEDBACK_DIR, 'auto-promoted-gates.json'),
|
|
156
|
+
PREVENTION_RULES_PATH: assertScopedDataPath(path.join(paths.FEEDBACK_DIR, 'prevention-rules.md')),
|
|
157
|
+
AUTO_GATES_PATH: assertScopedDataPath(path.join(paths.FEEDBACK_DIR, 'auto-promoted-gates.json')),
|
|
167
158
|
};
|
|
168
159
|
}
|
|
169
160
|
|
|
@@ -200,6 +191,7 @@ function readPreventionRuleMatches(queryText, limit = 3, options = {}) {
|
|
|
200
191
|
}
|
|
201
192
|
|
|
202
193
|
function readAutoGates(options = {}) {
|
|
194
|
+
if (options.projectKey != null) return { gates: require('./project-catalog').readProjectGates(resolveLessonPaths(options).FEEDBACK_DIR, options).filter(require('./project-identity').isGeneratedGate) };
|
|
203
195
|
const { AUTO_GATES_PATH } = resolveLessonPaths(options);
|
|
204
196
|
try {
|
|
205
197
|
return JSON.parse(require('node:fs').readFileSync(AUTO_GATES_PATH, 'utf-8'));
|
|
@@ -241,6 +233,8 @@ function buildGateMatches(memory, parsed, limit = 3, options = {}) {
|
|
|
241
233
|
.sort((a, b) => b.score - a.score)
|
|
242
234
|
.slice(0, limit)
|
|
243
235
|
.map(({ gate, score }) => ({
|
|
236
|
+
...require('./project-identity').projectForRecord(gate),
|
|
237
|
+
scope: gate.scope || (gate.projectKey ? 'project' : 'global'),
|
|
244
238
|
id: gate.id,
|
|
245
239
|
action: gate.action,
|
|
246
240
|
pattern: gate.pattern,
|
|
@@ -429,7 +423,7 @@ function scoreLesson(queryText, memory, parsed, sourceFeedback) {
|
|
|
429
423
|
function buildLessonResult(memory, sourceFeedback, options = {}) {
|
|
430
424
|
const parsed = parseLessonContent(memory.content);
|
|
431
425
|
const lessonQuery = buildLessonQuery(memory, parsed, sourceFeedback);
|
|
432
|
-
const ruleMatches = readPreventionRuleMatches(lessonQuery, Number(options.ruleLimit || 3), options);
|
|
426
|
+
const ruleMatches = options.projectKey != null ? [] : readPreventionRuleMatches(lessonQuery, Number(options.ruleLimit || 3), options);
|
|
433
427
|
const gateMatches = buildGateMatches(memory, parsed, Number(options.gateLimit || 3), options);
|
|
434
428
|
const { score, evidenceScore, priorScore, matchedTokens } = scoreLesson(options.query || '', memory, parsed, sourceFeedback);
|
|
435
429
|
const harnessRecommendations = buildHarnessRecommendations(memory, parsed, sourceFeedback, ruleMatches, gateMatches);
|
|
@@ -437,8 +431,9 @@ function buildLessonResult(memory, sourceFeedback, options = {}) {
|
|
|
437
431
|
const memoryLifecycle = buildMemoryLifecycleView(memory, { query: options.query || '' });
|
|
438
432
|
|
|
439
433
|
return {
|
|
434
|
+
...require('./project-identity').projectForRecord(memory),
|
|
440
435
|
id: memory.id,
|
|
441
|
-
title: memory.title,
|
|
436
|
+
title: (function() { const isStale = memory.lastVerifiedAt && ((new Date((options.now || Date.now())).getTime() - new Date(memory.lastVerifiedAt).getTime()) / 86400000 > 30); return (isStale ? "[STALE] " : "") + memory.title; })(),
|
|
442
437
|
category: memory.category,
|
|
443
438
|
importance: memory.importance,
|
|
444
439
|
tags: Array.isArray(memory.tags) ? memory.tags : [],
|
|
@@ -448,6 +443,26 @@ function buildLessonResult(memory, sourceFeedback, options = {}) {
|
|
|
448
443
|
evidenceScore: Number(evidenceScore.toFixed(4)),
|
|
449
444
|
priorScore: Number(priorScore.toFixed(4)),
|
|
450
445
|
matchedTokens,
|
|
446
|
+
verificationStatus: memory.verificationStatus || (Number(memory.verificationCount || 0) > 0 ? 'verified' : 'unverified'),
|
|
447
|
+
verificationCount: Number(memory.verificationCount || 0),
|
|
448
|
+
verifications: Array.isArray(memory.verifications) ? memory.verifications : [],
|
|
449
|
+
lastVerifiedAt: memory.lastVerifiedAt || null,
|
|
450
|
+
badge: (function() {
|
|
451
|
+
const count = Number(memory.verificationCount || 0);
|
|
452
|
+
if (count <= 0 || !memory.lastVerifiedAt) return 'unverified';
|
|
453
|
+
return `verified ${count}x, last ${String(memory.lastVerifiedAt).split('T')[0]}`;
|
|
454
|
+
})(),
|
|
455
|
+
stale: (function() {
|
|
456
|
+
if (!memory.lastVerifiedAt) return false;
|
|
457
|
+
const t = new Date(memory.lastVerifiedAt).getTime();
|
|
458
|
+
if (!Number.isFinite(t)) return false;
|
|
459
|
+
const nowDate = (options.now instanceof Date ? options.now : new Date(options.now || Date.now())).getTime();
|
|
460
|
+
return (nowDate - t) / (1000 * 60 * 60 * 24) > 30;
|
|
461
|
+
})(),
|
|
462
|
+
upVotes: Number(memory.upVotes || 0),
|
|
463
|
+
downVotes: Number(memory.downVotes || 0),
|
|
464
|
+
netVotes: Number(memory.upVotes || 0) - Number(memory.downVotes || 0),
|
|
465
|
+
demoted: (memory.demoted === true) || (Number(memory.downVotes || 0) > Number(memory.upVotes || 0)),
|
|
451
466
|
lesson: {
|
|
452
467
|
summary: parsed.summary,
|
|
453
468
|
content: memory.content,
|
|
@@ -485,13 +500,18 @@ function searchLessons(query = '', options = {}) {
|
|
|
485
500
|
const { MEMORY_LOG_PATH, FEEDBACK_DIR, FEEDBACK_LOG_PATH } = resolveLessonPaths(options);
|
|
486
501
|
|
|
487
502
|
// Try SQLite FTS5 first — falls back to JSONL Jaccard if unavailable
|
|
488
|
-
const sqliteResults = tryFts5Search(query, options);
|
|
503
|
+
const sqliteResults = options.projectKey != null ? null : tryFts5Search(query, options);
|
|
489
504
|
if (sqliteResults) return sqliteResults;
|
|
490
505
|
|
|
491
|
-
|
|
506
|
+
// Exact error lookup (Search before solving)
|
|
507
|
+
const { lookupLessonByError } = require('./verified-lessons');
|
|
508
|
+
const exactErrorMatch = options.projectKey != null ? null : lookupLessonByError(query, { feedbackDir: FEEDBACK_DIR, now: options.now });
|
|
509
|
+
|
|
510
|
+
const allMemories = require('./project-catalog').readProjectRows(FEEDBACK_DIR, 'memory-log.jsonl', options);
|
|
492
511
|
const memories = selectRetrievalMemories(allMemories, options);
|
|
493
|
-
const feedbackEntries =
|
|
494
|
-
const
|
|
512
|
+
const feedbackEntries = require('./project-catalog').readProjectRows(FEEDBACK_DIR, 'feedback-log.jsonl', options);
|
|
513
|
+
const feedbackKey = (projectKey, id) => `${projectKey}\0${id}`;
|
|
514
|
+
const feedbackById = new Map(feedbackEntries.map((entry) => [feedbackKey(entry.projectKey, entry.id), entry]));
|
|
495
515
|
const parsedLimit = Number(options.limit || 10);
|
|
496
516
|
const limit = Number.isFinite(parsedLimit) && parsedLimit > 0 ? parsedLimit : 10;
|
|
497
517
|
const category = options.category ? String(options.category).trim() : '';
|
|
@@ -503,10 +523,13 @@ function searchLessons(query = '', options = {}) {
|
|
|
503
523
|
.filter(Boolean);
|
|
504
524
|
|
|
505
525
|
let results = memories
|
|
506
|
-
.map((memory) => buildLessonResult(memory, feedbackById.get(memory.sourceFeedbackId), {
|
|
526
|
+
.map((memory) => buildLessonResult(memory, feedbackById.get(feedbackKey(memory.projectKey, memory.sourceFeedbackId)), {
|
|
507
527
|
query,
|
|
528
|
+
projectKey: options.projectKey,
|
|
508
529
|
ruleLimit: options.ruleLimit,
|
|
509
530
|
gateLimit: options.gateLimit,
|
|
531
|
+
now: options.now,
|
|
532
|
+
feedbackDir: FEEDBACK_DIR,
|
|
510
533
|
}));
|
|
511
534
|
|
|
512
535
|
if (category) {
|
|
@@ -539,6 +562,47 @@ function searchLessons(query = '', options = {}) {
|
|
|
539
562
|
results = [...reranked, ...tail];
|
|
540
563
|
}
|
|
541
564
|
|
|
565
|
+
if (exactErrorMatch) {
|
|
566
|
+
const existingMatch = results.find((r) => r.id === exactErrorMatch.id);
|
|
567
|
+
if (existingMatch) {
|
|
568
|
+
results = [existingMatch, ...results.filter((r) => r.id !== exactErrorMatch.id)];
|
|
569
|
+
} else {
|
|
570
|
+
const formattedExact = {
|
|
571
|
+
id: exactErrorMatch.id,
|
|
572
|
+
title: (exactErrorMatch.stale ? '[STALE] ' : '') + exactErrorMatch.title,
|
|
573
|
+
category: exactErrorMatch.category || 'error',
|
|
574
|
+
importance: exactErrorMatch.importance || 'high',
|
|
575
|
+
tags: exactErrorMatch.tags || [],
|
|
576
|
+
timestamp: exactErrorMatch.timestamp || null,
|
|
577
|
+
score: 1.0,
|
|
578
|
+
evidenceScore: 1.0,
|
|
579
|
+
verificationStatus: exactErrorMatch.verificationStatus,
|
|
580
|
+
verificationCount: exactErrorMatch.verificationCount,
|
|
581
|
+
verifications: exactErrorMatch.verifications,
|
|
582
|
+
lastVerifiedAt: exactErrorMatch.lastVerifiedAt,
|
|
583
|
+
badge: exactErrorMatch.badge,
|
|
584
|
+
stale: exactErrorMatch.stale,
|
|
585
|
+
upVotes: exactErrorMatch.upVotes,
|
|
586
|
+
downVotes: exactErrorMatch.downVotes,
|
|
587
|
+
netVotes: exactErrorMatch.netVotes,
|
|
588
|
+
lesson: {
|
|
589
|
+
summary: exactErrorMatch.title,
|
|
590
|
+
content: exactErrorMatch.content,
|
|
591
|
+
whatWentWrong: exactErrorMatch.errorPattern,
|
|
592
|
+
howToAvoid: exactErrorMatch.fix,
|
|
593
|
+
},
|
|
594
|
+
systemResponse: {
|
|
595
|
+
promotedToMemory: true,
|
|
596
|
+
linkedPreventionRules: [],
|
|
597
|
+
linkedAutoGates: [],
|
|
598
|
+
harnessRecommendations: [],
|
|
599
|
+
correctiveActions: [{ type: 'verified_fix', source: 'verified_seed', text: exactErrorMatch.fix, fix: exactErrorMatch.fix }],
|
|
600
|
+
},
|
|
601
|
+
};
|
|
602
|
+
results = [formattedExact, ...results];
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
542
606
|
return {
|
|
543
607
|
query: String(query || ''),
|
|
544
608
|
limit,
|
|
@@ -570,7 +634,7 @@ function tryFts5Search(query, options) {
|
|
|
570
634
|
let db = null;
|
|
571
635
|
try {
|
|
572
636
|
const { initDB, searchLessons: fts5Search, getStats } = require('./lesson-db');
|
|
573
|
-
db = initDB();
|
|
637
|
+
db = tenantDataScope() ? initDB(path.join(resolveLessonPaths(options).FEEDBACK_DIR, 'lessons.sqlite')) : initDB();
|
|
574
638
|
const stats = getStats(db);
|
|
575
639
|
|
|
576
640
|
// If DB is empty, skip (not yet backfilled)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
|
+
const { projectForRecord, matchesProject } = require('./project-identity');
|
|
5
|
+
const { iterateRows, accountAttribution, attributionForFile } = require('./project-catalog');
|
|
4
6
|
const { canonicalHash, findCanonicalDuplicate } = require('./lesson-canonical');
|
|
5
7
|
|
|
6
8
|
const SIMILARITY_THRESHOLD = 0.6;
|
|
@@ -48,8 +50,19 @@ function appendJSONLLocal(filePath, record) {
|
|
|
48
50
|
* The canonical pass runs first because it's O(N) with constant work per
|
|
49
51
|
* entry and rejects trivial duplicates before we pay the Jaccard price.
|
|
50
52
|
*/
|
|
53
|
+
function readLessonsInFile(memoryLogPath, projectKey) {
|
|
54
|
+
if (!fs.existsSync(memoryLogPath) || fs.lstatSync(memoryLogPath).isSymbolicLink()) return [];
|
|
55
|
+
const attribution = accountAttribution(path.dirname(memoryLogPath));
|
|
56
|
+
const rows = [];
|
|
57
|
+
for (const record of iterateRows(memoryLogPath)) {
|
|
58
|
+
const row = { ...record, ...projectForRecord(record, attributionForFile(attribution, memoryLogPath)) };
|
|
59
|
+
if (row.projectKey === projectKey) rows.push(row);
|
|
60
|
+
}
|
|
61
|
+
return rows;
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
function findSimilarLesson(memoryLogPath, newRecord) {
|
|
52
|
-
const existing =
|
|
65
|
+
const existing = readLessonsInFile(memoryLogPath, projectForRecord(newRecord).projectKey).slice(-200);
|
|
53
66
|
|
|
54
67
|
// Layer 1: canonical-hash exact match (normalization-invariant).
|
|
55
68
|
const canonicalMatch = findCanonicalDuplicate(existing, newRecord);
|
|
@@ -143,14 +156,16 @@ function synthesizePreventionRule(lesson) {
|
|
|
143
156
|
/**
|
|
144
157
|
* Update a single record in a JSONL file by ID.
|
|
145
158
|
*/
|
|
146
|
-
function updateRecordInJsonl(filePath, recordId, updatedRecord) {
|
|
159
|
+
function updateRecordInJsonl(filePath, recordId, updatedRecord, options = {}) {
|
|
147
160
|
if (!fs.existsSync(filePath)) return false;
|
|
148
161
|
const lines = fs.readFileSync(filePath, 'utf-8').split('\n').filter(Boolean);
|
|
162
|
+
const projectKey = options.projectKey ?? updatedRecord.projectKey;
|
|
163
|
+
const attribution = attributionForFile(options.attribution || accountAttribution(path.dirname(filePath)), filePath);
|
|
149
164
|
let found = false;
|
|
150
165
|
const updated = lines.map(function(line) {
|
|
151
166
|
try {
|
|
152
167
|
const obj = JSON.parse(line);
|
|
153
|
-
if (obj.id === recordId) {
|
|
168
|
+
if (obj.id === recordId && matchesProject(projectForRecord(obj, attribution), projectKey)) {
|
|
154
169
|
found = true;
|
|
155
170
|
return JSON.stringify(updatedRecord);
|
|
156
171
|
}
|
|
@@ -166,13 +181,14 @@ function updateRecordInJsonl(filePath, recordId, updatedRecord) {
|
|
|
166
181
|
/**
|
|
167
182
|
* Delete a single record from a JSONL file by ID.
|
|
168
183
|
*/
|
|
169
|
-
function deleteRecordFromJsonl(filePath, recordId) {
|
|
184
|
+
function deleteRecordFromJsonl(filePath, recordId, options = {}) {
|
|
170
185
|
if (!fs.existsSync(filePath)) return false;
|
|
171
186
|
const lines = fs.readFileSync(filePath, 'utf-8').split('\n').filter(Boolean);
|
|
187
|
+
const attribution = attributionForFile(options.attribution || accountAttribution(path.dirname(filePath)), filePath);
|
|
172
188
|
const filtered = lines.filter(function(line) {
|
|
173
189
|
try {
|
|
174
190
|
const obj = JSON.parse(line);
|
|
175
|
-
return obj.id !== recordId;
|
|
191
|
+
return obj.id !== recordId || !matchesProject(projectForRecord(obj, attribution), options.projectKey);
|
|
176
192
|
} catch { return true; }
|
|
177
193
|
});
|
|
178
194
|
if (filtered.length === lines.length) return false;
|
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
|
};
|