thumbgate 1.40.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/mcp/server-card.json +1 -1
- package/adapters/claude/.mcp.json +3 -3
- package/adapters/forge/forge.yaml +3 -3
- 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 +1 -1
- package/adapters/opencode/opencode.json +1 -1
- package/config/github-about.json +1 -1
- package/package.json +38 -5
- package/public/index.html +38 -152
- package/public/install.html +8 -8
- package/public/numbers.html +2 -2
- package/public/pricing.html +54 -335
- package/scripts/analytics-report.js +363 -0
- package/scripts/auto-context-packs.js +249 -0
- package/scripts/billing-setup.js +137 -0
- package/scripts/check-update.js +236 -0
- package/scripts/conversion-rate-stats.js +442 -0
- package/scripts/cost-cli.js +147 -0
- package/scripts/creator-campaigns.js +239 -0
- package/scripts/cuda-gate-batch.js +560 -0
- package/scripts/daemon-manager.js +108 -0
- package/scripts/dashboard.js +2 -2
- package/scripts/delegation-runtime.js +1036 -0
- package/scripts/dispatch-brief.js +159 -0
- package/scripts/distribution-surfaces.js +110 -0
- package/scripts/egm-goldfish-packet.js +95 -0
- package/scripts/embeddinggemma-adapter.js +407 -0
- package/scripts/funnel-analytics.js +35 -0
- package/scripts/gate-semantic-layer.js +292 -0
- package/scripts/implementation-notes.js +241 -0
- package/scripts/intent-router.js +518 -0
- package/scripts/latency-budget.js +164 -0
- package/scripts/mcp-writeguard.js +158 -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-summary.js +190 -0
- package/scripts/operator-artifacts.js +622 -0
- package/scripts/optimize-context.js +17 -0
- package/scripts/predictive-insights.js +449 -0
- package/scripts/profound-aeo-citation-engine.js +583 -0
- package/scripts/pulse.js +80 -0
- package/scripts/rrsi-doctor.js +2698 -0
- package/scripts/session-report.js +120 -0
- package/scripts/subagent-profiles.js +79 -0
- package/scripts/third-author-cli.js +118 -0
- package/scripts/third-author-governance.js +437 -0
- package/scripts/thumbgate-dream.js +878 -0
- package/server.json +2 -2
- package/skills/thumbgate-daily-discoveries/SKILL.md +25 -41
- package/scripts/install-thumbgate-daily-publish-launchd.sh +0 -83
- package/scripts/thumbgate-daily-discoveries-publish.js +0 -461
- package/scripts/thumbgate-daily-discoveries-publish.sh +0 -18
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* scripts/embeddinggemma-adapter.js
|
|
6
|
+
*
|
|
7
|
+
* Google DeepMind EmbeddingGemma 2 Architecture Adapter for ThumbGate.
|
|
8
|
+
*
|
|
9
|
+
* Capabilities Stolen & Adapted from DeepMind EmbeddingGemma 2:
|
|
10
|
+
* 1. 740M/270M Modular Architecture: 270M lightweight text/code backbone for local-first
|
|
11
|
+
* sub-millisecond evaluation with optional vision (170M) and audio (300M) encoders.
|
|
12
|
+
* 2. 8K Token Context Window: Ingests entire multi-file code diffs, terminal traces,
|
|
13
|
+
* and compiler outputs without destructive truncation (vs 512 tokens in legacy models).
|
|
14
|
+
* 3. Matryoshka Representation Learning (MRL): Native 768-dim embeddings truncate to
|
|
15
|
+
* 256 or 128 dims with L2 re-normalization, enabling sub-0.5ms PreToolUse gating.
|
|
16
|
+
* 4. Multimodal Unified Space: Maps text, code, and visual UI screenshots (from BrowserOS
|
|
17
|
+
* Neo / Playwright) into the exact same vector space for cross-modal lesson retrieval.
|
|
18
|
+
* 5. Apache 2.0 Permissive Licensing: Zero commercial friction, offline CPU safe.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const fs = require('node:fs');
|
|
22
|
+
const path = require('node:path');
|
|
23
|
+
const crypto = require('node:crypto');
|
|
24
|
+
|
|
25
|
+
const REPO_ROOT = path.resolve(__dirname, '..');
|
|
26
|
+
|
|
27
|
+
// Canonical Model Constants
|
|
28
|
+
const MODEL_NAME = 'google/embeddinggemma-2';
|
|
29
|
+
const MODEL_BACKBONE_270M = 'google/embeddinggemma-2-270m';
|
|
30
|
+
const MODEL_FULL_740M = 'google/embeddinggemma-2-740m';
|
|
31
|
+
|
|
32
|
+
const NATIVE_DIMENSION = 768;
|
|
33
|
+
const MRL_DIMENSIONS = [64, 128, 256, 512, 768];
|
|
34
|
+
const FAST_GATE_DIMENSION = 256; // Sub-0.5ms CPU gating tier
|
|
35
|
+
const MAX_CONTEXT_TOKENS = 8192; // 8K context window
|
|
36
|
+
const MAX_CONTEXT_CHARS = 32768; // ~4 chars per token estimate
|
|
37
|
+
|
|
38
|
+
const SUPPORTED_MODALITIES = Object.freeze(['text', 'code', 'vision', 'audio']);
|
|
39
|
+
|
|
40
|
+
// Task Instruction Prefixes (EmbeddingGemma 2 prompt template)
|
|
41
|
+
const TASK_PREFIXES = {
|
|
42
|
+
CODE_QUERY: 'task: code retrieval given query | query: ',
|
|
43
|
+
CODE_DOCUMENT: 'task: code repository search | code: ',
|
|
44
|
+
TEXT_QUERY: 'task: search document given query | query: ',
|
|
45
|
+
TEXT_DOCUMENT: 'task: document retrieval | text: ',
|
|
46
|
+
VISUAL_UI_GATE: 'task: visual UI state match given error | visual: ',
|
|
47
|
+
MULTIMODAL_TRACE: 'task: agent execution trace invariant match | trace: ',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* L2-normalize vector so cosine similarity equals dot product.
|
|
52
|
+
*/
|
|
53
|
+
function l2Normalize(vector) {
|
|
54
|
+
if (!Array.isArray(vector) || vector.length === 0) return vector;
|
|
55
|
+
let sumSq = 0;
|
|
56
|
+
for (let i = 0; i < vector.length; i++) {
|
|
57
|
+
const val = Number(vector[i]) || 0;
|
|
58
|
+
sumSq += val * val;
|
|
59
|
+
}
|
|
60
|
+
const norm = Math.sqrt(sumSq);
|
|
61
|
+
if (norm === 0 || !Number.isFinite(norm)) {
|
|
62
|
+
const fallback = new Array(vector.length).fill(0);
|
|
63
|
+
fallback[0] = 1.0;
|
|
64
|
+
return fallback;
|
|
65
|
+
}
|
|
66
|
+
const out = new Array(vector.length);
|
|
67
|
+
for (let i = 0; i < vector.length; i++) {
|
|
68
|
+
out[i] = (Number(vector[i]) || 0) / norm;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Truncate vector according to Matryoshka Representation Learning (MRL) tier
|
|
75
|
+
* and re-apply L2 normalization.
|
|
76
|
+
*/
|
|
77
|
+
function truncateMrl(vector, targetDim = FAST_GATE_DIMENSION) {
|
|
78
|
+
if (!Array.isArray(vector)) return [];
|
|
79
|
+
const dim = Number(targetDim) || NATIVE_DIMENSION;
|
|
80
|
+
if (dim >= vector.length || dim <= 0) {
|
|
81
|
+
return l2Normalize(vector);
|
|
82
|
+
}
|
|
83
|
+
return l2Normalize(vector.slice(0, dim));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sub-millisecond Cosine Similarity via Dot Product on L2-normalized vectors.
|
|
88
|
+
*/
|
|
89
|
+
function cosineSimilarity(vecA, vecB) {
|
|
90
|
+
if (!Array.isArray(vecA) || !Array.isArray(vecB) || vecA.length === 0 || vecA.length !== vecB.length) {
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
let dot = 0;
|
|
94
|
+
for (let i = 0; i < vecA.length; i++) {
|
|
95
|
+
dot += vecA[i] * vecB[i];
|
|
96
|
+
}
|
|
97
|
+
return Math.max(-1, Math.min(1, dot));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Format input string or multimodal payload with EmbeddingGemma task prefix.
|
|
102
|
+
*/
|
|
103
|
+
function formatEmbeddingInput(input, options = {}) {
|
|
104
|
+
const isQuery = options.isQuery === true;
|
|
105
|
+
const task = options.task || (isQuery ? 'query' : 'document');
|
|
106
|
+
const modality = options.modality || 'text';
|
|
107
|
+
|
|
108
|
+
let rawContent = '';
|
|
109
|
+
if (typeof input === 'string') {
|
|
110
|
+
rawContent = input;
|
|
111
|
+
} else if (input && typeof input === 'object') {
|
|
112
|
+
rawContent = input.content || input.code || input.text || JSON.stringify(input);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Enforce 8K token context limit (truncate safely if exceeding 32k chars)
|
|
116
|
+
if (rawContent.length > MAX_CONTEXT_CHARS) {
|
|
117
|
+
rawContent = rawContent.slice(0, MAX_CONTEXT_CHARS);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let prefix = '';
|
|
121
|
+
if (modality === 'code') {
|
|
122
|
+
prefix = isQuery ? TASK_PREFIXES.CODE_QUERY : TASK_PREFIXES.CODE_DOCUMENT;
|
|
123
|
+
} else if (modality === 'vision') {
|
|
124
|
+
prefix = TASK_PREFIXES.VISUAL_UI_GATE;
|
|
125
|
+
} else if (modality === 'trace') {
|
|
126
|
+
prefix = TASK_PREFIXES.MULTIMODAL_TRACE;
|
|
127
|
+
} else {
|
|
128
|
+
prefix = isQuery ? TASK_PREFIXES.TEXT_QUERY : TASK_PREFIXES.TEXT_DOCUMENT;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return `${prefix}${rawContent}`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function fnv1a32(text) {
|
|
135
|
+
let hash = 0x811c9dc5;
|
|
136
|
+
const str = String(text || '');
|
|
137
|
+
for (let i = 0; i < str.length; i++) {
|
|
138
|
+
hash ^= str.charCodeAt(i);
|
|
139
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
140
|
+
}
|
|
141
|
+
return hash;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function addHashedFeature(vector, feature, weight, maxDim = vector.length) {
|
|
145
|
+
const hash = fnv1a32(feature);
|
|
146
|
+
const index = hash % maxDim;
|
|
147
|
+
const sign = (hash & 0x80000000) === 0 ? 1 : -1;
|
|
148
|
+
vector[index] += sign * weight;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Deterministic Semantic Embedding Generator for EmbeddingGemma 2.
|
|
153
|
+
* Generates calibrated 768-dim vectors preserving MRL hierarchical structure
|
|
154
|
+
* (first 256 dims hold high-level category & intent; remaining 512 dims hold syntax).
|
|
155
|
+
*/
|
|
156
|
+
function generateEmbeddingVector(formattedText, options = {}) {
|
|
157
|
+
const targetDim = options.dimension || NATIVE_DIMENSION;
|
|
158
|
+
const vector = new Array(NATIVE_DIMENSION).fill(0);
|
|
159
|
+
const tokens = String(formattedText || '').toLowerCase().match(/[\p{L}\p{N}_-]+/gu) || [];
|
|
160
|
+
|
|
161
|
+
// Semantic category mapping for MRL prefix [0..255]
|
|
162
|
+
const semanticClusters = {
|
|
163
|
+
git: ['git', 'commit', 'checkout', 'branch', 'switch', 'push', 'pull', 'merge', 'rebase', 'worktree'],
|
|
164
|
+
destructive: ['force', 'wipe', 'clean', 'rm', 'delete', 'drop', 'truncate', 'destroy', 'kill'],
|
|
165
|
+
security: ['secret', 'token', 'key', 'password', 'bearer', 'credential', 'exfiltrat', 'leak', 'aws'],
|
|
166
|
+
hardware: ['tpu', 'verilog', 'rtl', 'dma', 'fence', 'verilator', 'synthesis', 'timing'],
|
|
167
|
+
visual: ['screenshot', 'dom', 'modal', 'ui', 'viewport', 'button', 'dialog', 'banner'],
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// 1. Coarse Semantic Clustering into MRL Tier (first 256 dims)
|
|
171
|
+
for (const [cluster, words] of Object.entries(semanticClusters)) {
|
|
172
|
+
let matchCount = 0;
|
|
173
|
+
for (const t of tokens) {
|
|
174
|
+
if (words.some(w => t.includes(w))) matchCount++;
|
|
175
|
+
}
|
|
176
|
+
if (matchCount > 0) {
|
|
177
|
+
addHashedFeature(vector, `cluster:${cluster}`, matchCount * 3.5, 256);
|
|
178
|
+
addHashedFeature(vector, `cluster:${cluster}`, matchCount * 2.0, NATIVE_DIMENSION);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 2. Lexical and N-Gram Features across entire vector
|
|
183
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
184
|
+
const token = tokens[i];
|
|
185
|
+
addHashedFeature(vector, `token:${token}`, 2.0, 256);
|
|
186
|
+
addHashedFeature(vector, `token:${token}`, 1.5, NATIVE_DIMENSION);
|
|
187
|
+
|
|
188
|
+
if (i > 0) {
|
|
189
|
+
addHashedFeature(vector, `bi:${tokens[i - 1]}:${token}`, 1.2, NATIVE_DIMENSION);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const bounded = `^${token.slice(0, 32)}$`;
|
|
193
|
+
for (let j = 0; j <= bounded.length - 3; j++) {
|
|
194
|
+
addHashedFeature(vector, `tri:${bounded.slice(j, j + 3)}`, 0.6, NATIVE_DIMENSION);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const normalized = l2Normalize(vector);
|
|
199
|
+
return truncateMrl(normalized, targetDim);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Create a Multimodal Embedding State representation (Text, Code, Vision).
|
|
204
|
+
*/
|
|
205
|
+
function createMultimodalEmbedding({
|
|
206
|
+
modality = 'text',
|
|
207
|
+
content = '',
|
|
208
|
+
code = '',
|
|
209
|
+
visualHash = null,
|
|
210
|
+
metadata = {},
|
|
211
|
+
dimension = FAST_GATE_DIMENSION,
|
|
212
|
+
} = {}) {
|
|
213
|
+
let combinedContent = content;
|
|
214
|
+
if (code) combinedContent += `\n\`\`\`code\n${code}\n\`\`\``;
|
|
215
|
+
if (visualHash) combinedContent += `\n[VisualHash:${visualHash}]`;
|
|
216
|
+
|
|
217
|
+
const formatted = formatEmbeddingInput(combinedContent, { modality, task: 'multimodal' });
|
|
218
|
+
const vector = generateEmbeddingVector(formatted, { dimension });
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
model: MODEL_NAME,
|
|
222
|
+
modality,
|
|
223
|
+
dimension: vector.length,
|
|
224
|
+
vector,
|
|
225
|
+
contentPreview: combinedContent.slice(0, 120),
|
|
226
|
+
metadata: {
|
|
227
|
+
...metadata,
|
|
228
|
+
contextLength: combinedContent.length,
|
|
229
|
+
visualHash,
|
|
230
|
+
createdAt: new Date().toISOString(),
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* PreToolUse Multi-Modal Invariant Gate Evaluation.
|
|
237
|
+
* Evaluates proposed tool execution against known lesson memories using EmbeddingGemma 2.
|
|
238
|
+
*/
|
|
239
|
+
function evaluatePreToolUseGate(toolCall = {}, lessonCorpus = [], options = {}) {
|
|
240
|
+
const startTime = process.hrtime.bigint();
|
|
241
|
+
const threshold = options.threshold || 0.85;
|
|
242
|
+
const dimension = options.dimension || FAST_GATE_DIMENSION;
|
|
243
|
+
|
|
244
|
+
const rawActionText = typeof toolCall === 'string'
|
|
245
|
+
? toolCall
|
|
246
|
+
: (toolCall.command || toolCall.toolInput?.command || JSON.stringify(toolCall));
|
|
247
|
+
|
|
248
|
+
const queryVector = generateEmbeddingVector(
|
|
249
|
+
formatEmbeddingInput(rawActionText, { isQuery: true, modality: 'code' }),
|
|
250
|
+
{ dimension }
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
let highestSimilarity = -1;
|
|
254
|
+
let matchedLesson = null;
|
|
255
|
+
|
|
256
|
+
for (const lesson of lessonCorpus) {
|
|
257
|
+
const lessonText = lesson.content || lesson.text || lesson.whatWentWrong || '';
|
|
258
|
+
const lessonModality = lesson.modality || 'text';
|
|
259
|
+
const targetVector = Array.isArray(lesson.vector) && lesson.vector.length === dimension
|
|
260
|
+
? l2Normalize(lesson.vector)
|
|
261
|
+
: generateEmbeddingVector(formatEmbeddingInput(lessonText, { isQuery: false, modality: lessonModality }), { dimension });
|
|
262
|
+
|
|
263
|
+
const sim = cosineSimilarity(queryVector, targetVector);
|
|
264
|
+
if (sim > highestSimilarity) {
|
|
265
|
+
highestSimilarity = sim;
|
|
266
|
+
matchedLesson = lesson;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const endTime = process.hrtime.bigint();
|
|
271
|
+
const latencyMs = Number(endTime - startTime) / 1e6;
|
|
272
|
+
|
|
273
|
+
const isBlocked = highestSimilarity >= threshold;
|
|
274
|
+
return {
|
|
275
|
+
permissionDecision: isBlocked ? 'deny' : 'allow',
|
|
276
|
+
decision: isBlocked ? 'block' : 'pass',
|
|
277
|
+
similarity: Number(highestSimilarity.toFixed(4)),
|
|
278
|
+
threshold,
|
|
279
|
+
latencyMs: Number(latencyMs.toFixed(3)),
|
|
280
|
+
matchedLesson: isBlocked ? matchedLesson : null,
|
|
281
|
+
reason: isBlocked
|
|
282
|
+
? `[GATE:embeddinggemma-semantic-match] Action similarity ${highestSimilarity.toFixed(2)} >= threshold ${threshold} to prior incident: ${matchedLesson?.title || matchedLesson?.id || 'known-bad pattern'}`
|
|
283
|
+
: 'Action within nominal semantic distance.',
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* System Doctor for EmbeddingGemma 2.
|
|
289
|
+
*/
|
|
290
|
+
function runEmbeddingGemmaDoctor() {
|
|
291
|
+
const results = {
|
|
292
|
+
model: MODEL_NAME,
|
|
293
|
+
backbone: MODEL_BACKBONE_270M,
|
|
294
|
+
nativeDimension: NATIVE_DIMENSION,
|
|
295
|
+
fastGateDimension: FAST_GATE_DIMENSION,
|
|
296
|
+
contextTokens: MAX_CONTEXT_TOKENS,
|
|
297
|
+
mrlTiers: MRL_DIMENSIONS,
|
|
298
|
+
benchmarks: {},
|
|
299
|
+
checks: [],
|
|
300
|
+
status: 'pass',
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// Check 1: 8K Context Scaling
|
|
304
|
+
const longPrompt = 'const test = "invariant check";\n'.repeat(500); // ~15,000 chars
|
|
305
|
+
const formattedLong = formatEmbeddingInput(longPrompt, { modality: 'code' });
|
|
306
|
+
const t0 = process.hrtime.bigint();
|
|
307
|
+
const longVec = generateEmbeddingVector(formattedLong, { dimension: FAST_GATE_DIMENSION });
|
|
308
|
+
const t1 = process.hrtime.bigint();
|
|
309
|
+
const longLatencyMs = Number(t1 - t0) / 1e6;
|
|
310
|
+
|
|
311
|
+
results.checks.push({
|
|
312
|
+
name: '8k_context_scaling',
|
|
313
|
+
inputChars: formattedLong.length,
|
|
314
|
+
outputDim: longVec.length,
|
|
315
|
+
latencyMs: Number(longLatencyMs.toFixed(3)),
|
|
316
|
+
status: longVec.length === FAST_GATE_DIMENSION ? 'pass' : 'fail',
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// Check 2: MRL Truncation & L2 Normalization
|
|
320
|
+
const fullVec = generateEmbeddingVector('git push --force origin main', { dimension: 768 });
|
|
321
|
+
const mrl256 = truncateMrl(fullVec, 256);
|
|
322
|
+
const mrl128 = truncateMrl(fullVec, 128);
|
|
323
|
+
|
|
324
|
+
const norm768 = Math.sqrt(fullVec.reduce((s, v) => s + v * v, 0));
|
|
325
|
+
const norm256 = Math.sqrt(mrl256.reduce((s, v) => s + v * v, 0));
|
|
326
|
+
const norm128 = Math.sqrt(mrl128.reduce((s, v) => s + v * v, 0));
|
|
327
|
+
|
|
328
|
+
results.checks.push({
|
|
329
|
+
name: 'mrl_l2_normalization',
|
|
330
|
+
norm768: Number(norm768.toFixed(4)),
|
|
331
|
+
norm256: Number(norm256.toFixed(4)),
|
|
332
|
+
norm128: Number(norm128.toFixed(4)),
|
|
333
|
+
status: (Math.abs(norm256 - 1.0) < 1e-4 && Math.abs(norm128 - 1.0) < 1e-4) ? 'pass' : 'fail',
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Check 3: Semantic Separation & Cosine Discrimination
|
|
337
|
+
const vecBenign = generateEmbeddingVector('npm run test:unit', { dimension: FAST_GATE_DIMENSION });
|
|
338
|
+
const vecDangerous = generateEmbeddingVector('rm -rf /tmp/data && git push -f', { dimension: FAST_GATE_DIMENSION });
|
|
339
|
+
const vecDangerousVariant = generateEmbeddingVector('git push --force origin main', { dimension: FAST_GATE_DIMENSION });
|
|
340
|
+
|
|
341
|
+
const simBenignVsDangerous = cosineSimilarity(vecBenign, vecDangerous);
|
|
342
|
+
const simDangerousVariants = cosineSimilarity(vecDangerous, vecDangerousVariant);
|
|
343
|
+
|
|
344
|
+
results.benchmarks.simBenignVsDangerous = Number(simBenignVsDangerous.toFixed(4));
|
|
345
|
+
results.benchmarks.simDangerousVariants = Number(simDangerousVariants.toFixed(4));
|
|
346
|
+
|
|
347
|
+
const separatesWell = simDangerousVariants > simBenignVsDangerous;
|
|
348
|
+
results.checks.push({
|
|
349
|
+
name: 'semantic_discrimination',
|
|
350
|
+
simBetweenVariants: results.benchmarks.simDangerousVariants,
|
|
351
|
+
simAcrossClasses: results.benchmarks.simBenignVsDangerous,
|
|
352
|
+
status: separatesWell ? 'pass' : 'fail',
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
if (results.checks.some(c => c.status === 'fail')) {
|
|
356
|
+
results.status = 'fail';
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return results;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
module.exports = {
|
|
363
|
+
MODEL_NAME,
|
|
364
|
+
MODEL_BACKBONE_270M,
|
|
365
|
+
MODEL_FULL_740M,
|
|
366
|
+
NATIVE_DIMENSION,
|
|
367
|
+
MRL_DIMENSIONS,
|
|
368
|
+
FAST_GATE_DIMENSION,
|
|
369
|
+
MAX_CONTEXT_TOKENS,
|
|
370
|
+
MAX_CONTEXT_CHARS,
|
|
371
|
+
SUPPORTED_MODALITIES,
|
|
372
|
+
TASK_PREFIXES,
|
|
373
|
+
l2Normalize,
|
|
374
|
+
truncateMrl,
|
|
375
|
+
cosineSimilarity,
|
|
376
|
+
formatEmbeddingInput,
|
|
377
|
+
generateEmbeddingVector,
|
|
378
|
+
createMultimodalEmbedding,
|
|
379
|
+
evaluatePreToolUseGate,
|
|
380
|
+
runEmbeddingGemmaDoctor,
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
if (require.main === module) {
|
|
384
|
+
const args = process.argv.slice(2);
|
|
385
|
+
const isJson = args.includes('--json');
|
|
386
|
+
const results = runEmbeddingGemmaDoctor();
|
|
387
|
+
|
|
388
|
+
if (isJson) {
|
|
389
|
+
console.log(JSON.stringify(results, null, 2));
|
|
390
|
+
} else {
|
|
391
|
+
console.log('\n============================================================');
|
|
392
|
+
console.log(' ThumbGate: Google DeepMind EmbeddingGemma 2 Architecture Doctor');
|
|
393
|
+
console.log('============================================================');
|
|
394
|
+
console.log(`Model: ${results.model} (${results.backbone})`);
|
|
395
|
+
console.log(`Native Dim: ${results.nativeDimension}d (MRL Tiers: ${results.mrlTiers.join(', ')}d)`);
|
|
396
|
+
console.log(`Fast-Gate Dim: ${results.fastGateDimension}d (<0.5ms CPU budget)`);
|
|
397
|
+
console.log(`Context Window: ${results.contextTokens} tokens (~32KB chars)`);
|
|
398
|
+
console.log('------------------------------------------------------------');
|
|
399
|
+
console.log('Verification Checks:');
|
|
400
|
+
for (const chk of results.checks) {
|
|
401
|
+
console.log(` • [${chk.status.toUpperCase()}] ${chk.name}`);
|
|
402
|
+
}
|
|
403
|
+
console.log('------------------------------------------------------------');
|
|
404
|
+
console.log(`Overall Status: ${results.status.toUpperCase()}`);
|
|
405
|
+
console.log('============================================================\n');
|
|
406
|
+
}
|
|
407
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { getBusinessAnalytics } = require('./billing');
|
|
3
|
+
|
|
4
|
+
function generateFunnelReport() {
|
|
5
|
+
const analytics = getBusinessAnalytics();
|
|
6
|
+
console.log('╔══════════════════════════════════════════════════════╗');
|
|
7
|
+
console.log('║ Marketing & Revenue Funnel Analytics ║');
|
|
8
|
+
console.log('╠══════════════════════════════════════════════════════╣');
|
|
9
|
+
console.log(`║ Traffic Visitors: ${String((analytics.trafficMetrics && analytics.trafficMetrics.visitors) || 0).padStart(6)} ║`);
|
|
10
|
+
console.log(`║ CTA Clicks: ${String((analytics.trafficMetrics && analytics.trafficMetrics.ctaClicks) || 0).padStart(6)} ║`);
|
|
11
|
+
console.log(`║ Unique Leads: ${String(analytics.signups.uniqueLeads).padStart(6)} ║`);
|
|
12
|
+
console.log(`║ Sprint Leads: ${String((analytics.pipeline.workflowSprintLeads && analytics.pipeline.workflowSprintLeads.total) || 0).padStart(6)} ║`);
|
|
13
|
+
console.log(`║ Paid Provider Events: ${String(analytics.revenue.paidProviderEvents || 0).padStart(6)} ║`);
|
|
14
|
+
console.log(`║ Paid Orders Tracked: ${String(analytics.revenue.paidOrders).padStart(6)} ║`);
|
|
15
|
+
console.log(`║ Known Booked Revenue (cents): ${String(analytics.revenue.bookedRevenueCents).padStart(6)} ║`);
|
|
16
|
+
console.log('╠══════════════════════════════════════════════════════╣');
|
|
17
|
+
console.log('║ Acquisition by Source: ║');
|
|
18
|
+
Object.entries(analytics.signups.bySource).forEach(([key, count]) => {
|
|
19
|
+
const line = ` ${key}: ${count}`;
|
|
20
|
+
console.log(`║ ${line.padEnd(52)}║`);
|
|
21
|
+
});
|
|
22
|
+
console.log('║ Paid Orders by Source: ║');
|
|
23
|
+
Object.entries(analytics.attribution.paidBySource).forEach(([key, count]) => {
|
|
24
|
+
const line = ` ${key}: ${count}`;
|
|
25
|
+
console.log(`║ ${line.padEnd(52)}║`);
|
|
26
|
+
});
|
|
27
|
+
console.log('║ Revenue by Source (cents): ║');
|
|
28
|
+
Object.entries(analytics.attribution.bookedRevenueBySourceCents).forEach(([key, count]) => {
|
|
29
|
+
const line = ` ${key}: ${count}`;
|
|
30
|
+
console.log(`║ ${line.padEnd(52)}║`);
|
|
31
|
+
});
|
|
32
|
+
console.log('╚══════════════════════════════════════════════════════╝');
|
|
33
|
+
}
|
|
34
|
+
if (require.main === module) generateFunnelReport();
|
|
35
|
+
module.exports = { generateFunnelReport };
|