thumbgate 1.39.1 → 1.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.well-known/llms.txt +2 -2
- package/.well-known/mcp/server-card.json +1 -1
- package/README.md +5 -4
- package/adapters/claude/.mcp.json +6 -2
- package/adapters/codex/config.toml +5 -0
- package/adapters/forge/forge.yaml +4 -4
- package/adapters/future-agi/.mcp.json +1 -1
- package/adapters/future-agi/config.toml +1 -1
- package/adapters/future-agi/opencode.json +1 -1
- package/adapters/herdr/herdr-plugin.toml +2 -2
- package/adapters/mcp/server-stdio.js +82 -7
- package/adapters/opencode/opencode.json +1 -1
- package/bin/cli.js +128 -15
- package/config/brand-standards.json +131 -0
- package/config/gates/default.json +18 -1
- package/config/github-about.json +1 -1
- package/config/mcp-allowlists.json +16 -3
- package/config/merge-quality-checks.json +1 -0
- package/config/post-deploy-marketing-pages.json +3 -3
- package/config/schemas/task-outcome-receipt.schema.json +9 -0
- package/openapi/openapi.yaml +7 -3
- package/package.json +98 -31
- package/public/about.html +2 -2
- package/public/admin.html +771 -0
- package/public/agent-manager.html +3 -3
- package/public/agents-cost-savings.html +1 -1
- package/public/ai-malpractice-prevention.html +12 -12
- package/public/architecture.html +0 -1
- package/public/assets/diagrams/decision.svg +3 -3
- package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +1 -1
- package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +1 -1
- package/public/blog/git-at-agent-scale.html +2 -2
- package/public/blog/inside-your-boundary.html +1 -1
- package/public/blog/process-over-outcome-gates.html +1 -1
- package/public/case-studies.html +1 -2
- package/public/codex-enterprise.html +1 -1
- package/public/codex-plugin.html +1 -1
- package/public/dashboard.html +773 -481
- package/public/diagnostic.html +8 -3
- package/public/enterprise-governance.html +26 -174
- package/public/eval-scorecard.html +3 -4
- package/public/eval-scorecard.json +2 -2
- package/public/evaluations.html +0 -1
- package/public/founders.html +3 -3
- package/public/gaming-playbook.html +4 -4
- package/public/guide.html +3 -5
- package/public/index.html +181 -205
- package/public/install.html +12 -11
- package/public/js/buyer-intent.js +49 -8
- package/public/lessons.html +103 -46
- package/public/numbers.html +32 -33
- package/public/operator-framework.html +44 -72
- package/public/peter.html +3 -3
- package/public/platform-partners.html +1 -1
- package/public/pricing.html +61 -327
- package/public/pro.html +3 -1
- package/public/project-switcher.js +76 -0
- package/public/whitepaper.html +1 -2
- package/scripts/activation-quickstart.js +15 -3
- package/scripts/activation-tracker.js +280 -3
- package/scripts/agent-action-inventory.js +235 -143
- package/scripts/agent-operations-planner.js +1 -1
- package/scripts/agent-readiness.js +36 -6
- package/scripts/agentic-prompt-pipelines.js +901 -0
- package/scripts/analytics-report.js +363 -0
- package/scripts/analytics-window.js +7 -1
- package/scripts/async-job-runner.js +66 -11
- package/scripts/audit-trail.js +37 -24
- package/scripts/auto-context-packs.js +249 -0
- package/scripts/auto-promote-gates.js +37 -27
- package/scripts/backfill-lesson-scopes.js +122 -0
- package/scripts/billing-setup.js +137 -0
- package/scripts/billing.js +889 -132
- package/scripts/bot-detection.js +112 -0
- package/scripts/brand-standards-gate.js +571 -0
- package/scripts/chatgpt-ads-readiness-pack.js +1 -1
- package/scripts/check-update.js +236 -0
- package/scripts/cli-schema.js +1 -1
- package/scripts/commercial-offer.js +2 -2
- package/scripts/contextfs.js +9 -3
- package/scripts/conversion-rate-stats.js +442 -0
- package/scripts/cost-cli.js +147 -0
- package/scripts/creator-campaigns.js +239 -0
- package/scripts/cross-encoder-reranker.js +4 -0
- package/scripts/cuda-gate-batch.js +560 -0
- package/scripts/daemon-manager.js +108 -0
- package/scripts/dashboard-chat.js +11 -0
- package/scripts/dashboard.js +576 -169
- package/scripts/decision-journal.js +7 -4
- package/scripts/delegation-runtime.js +1036 -0
- package/scripts/dispatch-brief.js +159 -0
- package/scripts/distribution-surfaces.js +110 -0
- package/scripts/docker-sandbox-planner.js +3 -3
- package/scripts/egm-goldfish-packet.js +95 -0
- package/scripts/embeddinggemma-adapter.js +407 -0
- package/scripts/export-dpo-pairs.js +12 -7
- package/scripts/feedback-aggregate.js +4 -0
- package/scripts/feedback-attribution.js +6 -4
- package/scripts/feedback-history-distiller.js +18 -6
- package/scripts/feedback-loop.js +255 -89
- package/scripts/feedback-paths.js +8 -1
- package/scripts/feedback-sanitizer.js +5 -0
- package/scripts/feedback-scope.js +106 -0
- package/scripts/feedback-session.js +8 -2
- package/scripts/filesystem-search.js +13 -8
- package/scripts/financial-control-plane.js +707 -45
- package/scripts/funnel-analytics.js +35 -0
- package/scripts/gate-semantic-layer.js +292 -0
- package/scripts/gate-stats.js +8 -2
- package/scripts/gates-engine.js +694 -230
- package/scripts/generate-eval-scorecard.js +0 -1
- package/scripts/harness-tool-names.js +31 -5
- package/scripts/hybrid-feedback-context.js +5 -2
- package/scripts/implementation-notes.js +241 -0
- package/scripts/intent-router.js +518 -0
- package/scripts/intervention-policy.js +2 -1
- package/scripts/latency-budget.js +164 -0
- package/scripts/lesson-canonical.js +2 -2
- package/scripts/lesson-db.js +55 -14
- package/scripts/lesson-graph.js +2 -1
- package/scripts/lesson-retrieval.js +95 -9
- package/scripts/lesson-search.js +86 -22
- package/scripts/lesson-synthesis.js +21 -5
- package/scripts/mailer/index.js +17 -1
- package/scripts/mailer/resend-mailer.js +213 -179
- package/scripts/mcp-writeguard.js +158 -0
- package/scripts/migrate-project-scope.js +209 -0
- package/scripts/model-candidates.js +414 -0
- package/scripts/openrouter-armor-partnership-diode.js +2419 -0
- package/scripts/operational-dashboard.js +172 -0
- package/scripts/operational-integrity.js +436 -3
- package/scripts/operational-summary.js +190 -0
- package/scripts/operator-artifacts.js +622 -0
- package/scripts/optimize-context.js +17 -0
- package/scripts/override-audit.js +2 -0
- package/scripts/owner-admin.js +338 -0
- package/scripts/pr-manager.js +194 -1
- package/scripts/predictive-insights.js +449 -0
- package/scripts/profound-aeo-citation-engine.js +583 -0
- package/scripts/progressive-signoff.js +260 -0
- package/scripts/project-catalog.js +243 -0
- package/scripts/project-dashboard.js +61 -0
- package/scripts/project-evidence.js +172 -0
- package/scripts/project-identity.js +182 -0
- package/scripts/project-scope.js +381 -0
- package/scripts/prompt-guard.js +446 -52
- package/scripts/proof-report.js +232 -0
- package/scripts/provider-action-normalizer.js +14 -6
- package/scripts/pulse.js +80 -0
- package/scripts/rate-limiter.js +41 -0
- package/scripts/rrsi-doctor.js +2698 -0
- package/scripts/secret-redaction.js +171 -25
- package/scripts/secret-scanner.js +101 -42
- package/scripts/self-protection.js +2 -2
- package/scripts/seo-gsd.js +14 -14
- package/scripts/session-context-dedupe.js +66 -0
- package/scripts/session-report.js +120 -0
- package/scripts/settings-hierarchy.js +4 -2
- package/scripts/statusline-meta.js +34 -23
- package/scripts/subagent-profiles.js +79 -0
- package/scripts/task-outcomes.js +29 -2
- package/scripts/telemetry-analytics.js +238 -13
- package/scripts/third-author-cli.js +118 -0
- package/scripts/third-author-governance.js +437 -0
- package/scripts/thumbgate-dream.js +878 -0
- package/scripts/thumbgate-search.js +23 -9
- package/scripts/tool-kpi-tracker.js +5 -2
- package/scripts/tool-registry.js +42 -1
- package/scripts/triage-savings-calculator.js +1 -1
- package/scripts/vector-store.js +4 -1
- package/scripts/verified-lessons.js +270 -0
- package/scripts/verify-marketing-pages-deployed.js +2 -2
- package/scripts/workflow-sentinel.js +29 -10
- package/server.json +2 -2
- package/skills/thumbgate-daily-discoveries/SKILL.md +25 -41
- package/src/api/server.js +2371 -451
- package/src/feedback.js +21 -0
- package/src/hermes-sync-plane.js +2 -1
- package/src/index.js +2 -0
- package/src/lesson-search.js +9 -0
- package/src/mckinsey-top-company-ai-coding.js +493 -0
- package/src/mcp/server.js +3 -0
- package/src/mcp-writeguard.js +772 -11
- package/src/openshell-lovable-engine.js +1475 -0
- package/src/task-outcome.js +3 -0
- package/config/evals/agent-safety-eval.json +0 -447
- package/config/evals/retrieval-ranking-golden.json +0 -522
- package/config/progressive/01-wire-only.json +0 -11
- package/config/progressive/02-dashboard-empty-ok.json +0 -10
- package/config/progressive/03-one-lesson.json +0 -10
- package/config/progressive/04-warn-fires.json +0 -11
- package/config/progressive/05-strict-optional.json +0 -11
- package/config/progressive/README.md +0 -15
- package/public/assets/diagrams/agent-integration.png +0 -0
- package/public/assets/diagrams/thumbgate-architecture.png +0 -0
- package/scripts/install-thumbgate-daily-publish-launchd.sh +0 -83
- package/scripts/thumbgate-daily-discoveries-publish.js +0 -461
- package/scripts/thumbgate-daily-discoveries-publish.sh +0 -18
|
@@ -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 };
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gate Semantic Layer — Curated "Gold" Rule View
|
|
6
|
+
*
|
|
7
|
+
* Stolen from DATA+AI Summit principle: "Plug agents into Gold tables and
|
|
8
|
+
* semantic layers, not raw data." Instead of letting agents (or gate evaluators)
|
|
9
|
+
* read raw feedback JSON files directly, we provide a curated, pre-validated,
|
|
10
|
+
* deduplicated "Gold" layer of prevention rules.
|
|
11
|
+
*
|
|
12
|
+
* Key improvements over raw rule loading:
|
|
13
|
+
* 1. Query pushdown: Only rules matching the specific tool + category are loaded
|
|
14
|
+
* (stops SELECT * from the entire feedback store)
|
|
15
|
+
* 2. Tiered caching: Global (disk) → Shared (hot cache) → Thread-local (input hash)
|
|
16
|
+
* 3. Human-reviewed metadata: Each rule carries source confidence, last reviewed date
|
|
17
|
+
* 4. Analytical reasoning baked in: Rules are tagged with anomaly patterns so the
|
|
18
|
+
* gate engine can pre-filter based on common failure modes
|
|
19
|
+
*
|
|
20
|
+
* https://docs.nvidia.com/cuda/cuda-programming-guide/index.html
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const fs = require('node:fs');
|
|
24
|
+
const path = require('node:path');
|
|
25
|
+
const os = require('node:os');
|
|
26
|
+
|
|
27
|
+
const PKG_ROOT = path.join(__dirname, '..');
|
|
28
|
+
const FEEDBACK_DIR = path.join(PKG_ROOT, '.claude', 'memory', 'feedback');
|
|
29
|
+
const DEFAULT_RULES_FILE = path.join(PKG_ROOT, '.thumbgate', 'prevention-rules.json');
|
|
30
|
+
|
|
31
|
+
// CUDA L1 shared memory analog — hot cache for frequently accessed rules
|
|
32
|
+
const HOT_CACHE_TTL_MS = 60 * 1000;
|
|
33
|
+
const HOT_CACHE_MAX_ENTRIES = 1000;
|
|
34
|
+
|
|
35
|
+
// Sampling threshold: if feedback store exceeds this many entries, sample
|
|
36
|
+
// (stolen from DATA+AI Summit: "avoid naive row-by-row LLM calls at scale")
|
|
37
|
+
const SAMPLING_THRESHOLD = 100;
|
|
38
|
+
const SAMPLING_RATIO = 0.3; // 30% sample for large datasets
|
|
39
|
+
|
|
40
|
+
// Anomaly patterns baked into the semantic layer (DATA+AI Summit #3:
|
|
41
|
+
// "Bake common analytical reasoning into prompts")
|
|
42
|
+
const ANOMALY_PATTERNS = [
|
|
43
|
+
{
|
|
44
|
+
id: 'contradiction',
|
|
45
|
+
pattern: /(you[''re]?|you are)\s+(wrong|incorrect|mistaken)/gi,
|
|
46
|
+
severity: 'high',
|
|
47
|
+
description: 'User correction signals contradiction with prior guidance',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'regression',
|
|
51
|
+
pattern: /(regression|back.{0,5}regress|same error again|previously.{0,20}fixed)/gi,
|
|
52
|
+
severity: 'high',
|
|
53
|
+
description: 'Previously fixed issue reappeared — regression risk',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'cost-spike',
|
|
57
|
+
pattern: /(cost\s*(spike|overrun|explode|balloon)|expensive.{0,20}(call|request|token))/gi,
|
|
58
|
+
severity: 'medium',
|
|
59
|
+
description: 'Cost anomaly detected in agent behavior',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'security-bypass',
|
|
63
|
+
pattern: /(bypass|broke|override|circumvent).*?(gate|guard|check|proteCTION|auth)/gi,
|
|
64
|
+
severity: 'critical',
|
|
65
|
+
description: 'Security bypass attempt detected',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: 'boundary-violation',
|
|
69
|
+
pattern: /(read.{0,10}only|protect|never|don.t).*?(source|config|test|code)/gi,
|
|
70
|
+
severity: 'high',
|
|
71
|
+
description: 'Read-only boundary violation attempted',
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
// Tool capability tags (for pushdown filtering)
|
|
76
|
+
const TOOL_TAGS = {
|
|
77
|
+
Bash: ['command', 'shell', 'execution'],
|
|
78
|
+
Edit: ['file-modification', 'path', 'write'],
|
|
79
|
+
Write: ['file-creation', 'path', 'write'],
|
|
80
|
+
Read: ['file-read', 'path', 'read'],
|
|
81
|
+
MultiSearch: ['search', 'multi-edit', 'glob'],
|
|
82
|
+
NotebookExec: ['code-execution', 'ipython', 'cell'],
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Gold layer: A curated, pre-validated view of prevention rules.
|
|
87
|
+
* Instead of reading raw feedback JSON per-request, the Gold layer
|
|
88
|
+
* pre-processes rules with metadata: source confidence, last reviewed,
|
|
89
|
+
* anomaly tags, and tool applicability.
|
|
90
|
+
*
|
|
91
|
+
* @param {Object} opts - { rulesDir, feedbackDir, toolName, category }
|
|
92
|
+
* @returns {Array} Curated rules filtered by pushdown predicates
|
|
93
|
+
*/
|
|
94
|
+
function loadGoldRules(opts = {}) {
|
|
95
|
+
const { rulesDir = PKG_ROOT, feedbackDir = FEEDBACK_DIR, toolName, category, sample = true } = opts;
|
|
96
|
+
|
|
97
|
+
// Handle both cases: rulesDir as PKG_ROOT or as the .thumbgate dir itself
|
|
98
|
+
let rulesFile = path.join(rulesDir, '.thumbgate', 'prevention-rules.json');
|
|
99
|
+
if (!fs.existsSync(rulesFile)) {
|
|
100
|
+
// Maybe rulesDir IS the .thumbgate directory
|
|
101
|
+
const altPath = path.join(rulesDir, 'prevention-rules.json');
|
|
102
|
+
if (fs.existsSync(altPath)) {
|
|
103
|
+
rulesFile = altPath;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const allRules = [];
|
|
107
|
+
|
|
108
|
+
// --- Global memory: read full prevention-rules.json ---
|
|
109
|
+
if (fs.existsSync(rulesFile)) {
|
|
110
|
+
try {
|
|
111
|
+
const data = JSON.parse(fs.readFileSync(rulesFile, 'utf8'));
|
|
112
|
+
for (const rule of (data.rules || [])) {
|
|
113
|
+
allRules.push(annotateRule(rule, 'curated', rulesFile));
|
|
114
|
+
}
|
|
115
|
+
} catch (_e) { /* skip malformed */ }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// --- Global memory: read feedback-derived rules ---
|
|
119
|
+
if (fs.existsSync(feedbackDir)) {
|
|
120
|
+
const entries = fs.readdirSync(feedbackDir).filter(f => f.endsWith('.json'));
|
|
121
|
+
|
|
122
|
+
// Query pushdown: if toolName is specified, only load feedback entries
|
|
123
|
+
// relevant to that tool (avoids loading the entire feedback store)
|
|
124
|
+
let filesToLoad = entries;
|
|
125
|
+
if (toolName) {
|
|
126
|
+
filesToLoad = entries.filter(f => {
|
|
127
|
+
const fullPath = path.join(feedbackDir, f);
|
|
128
|
+
try {
|
|
129
|
+
const data = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
|
|
130
|
+
return ruleAppliesToTool(data, toolName);
|
|
131
|
+
} catch (_e) {
|
|
132
|
+
return true; // On parse error, include (fail open for safety)
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Sampling for large datasets (cost optimization)
|
|
138
|
+
if (sample && filesToLoad.length > SAMPLING_THRESHOLD) {
|
|
139
|
+
const sampleSize = Math.max(
|
|
140
|
+
MATH_FLOOR(filesToLoad.length * SAMPLING_RATIO),
|
|
141
|
+
SAMPLING_THRESHOLD
|
|
142
|
+
);
|
|
143
|
+
// Deterministic sampling: evenly spread across the dataset
|
|
144
|
+
const step = filesToLoad.length / sampleSize;
|
|
145
|
+
const sampled = [];
|
|
146
|
+
for (let i = 0; i < sampleSize; i++) {
|
|
147
|
+
const idx = Math.floor(i * step);
|
|
148
|
+
if (idx < filesToLoad.length) {
|
|
149
|
+
sampled.push(filesToLoad[idx]);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
filesToLoad = sampled;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (const entry of filesToLoad) {
|
|
156
|
+
try {
|
|
157
|
+
const fb = JSON.parse(fs.readFileSync(path.join(feedbackDir, entry), 'utf8'));
|
|
158
|
+
if (fb.type === 'prevention_rule' && fb.rule) {
|
|
159
|
+
allRules.push(annotateRule(fb.rule, 'feedback', entry, {
|
|
160
|
+
feedbackId: fb.feedbackId || fb.id,
|
|
161
|
+
confidence: computeConfidence(fb),
|
|
162
|
+
anomalyTags: detectAnomalies(fb),
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
} catch (_e) { /* skip malformed */ }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// --- Query pushdown: filter by tool + category ---
|
|
170
|
+
let filtered = allRules;
|
|
171
|
+
if (toolName) {
|
|
172
|
+
filtered = filtered.filter(r =>
|
|
173
|
+
ruleAppliesToTool(r, toolName) || r.tools === undefined
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (category) {
|
|
177
|
+
filtered = filtered.filter(r =>
|
|
178
|
+
(r.category || 'prevention') === category
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return filtered;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Annotate a rule with metadata (source, confidence, review date).
|
|
187
|
+
* Gold layer rules carry richer metadata than raw feedback entries.
|
|
188
|
+
*/
|
|
189
|
+
function annotateRule(rule, source, origin, extra = {}) {
|
|
190
|
+
return {
|
|
191
|
+
...rule,
|
|
192
|
+
id: rule.id || `rule-${source}-${Math.random().toString(36).slice(2, 8)}`,
|
|
193
|
+
type: rule.type || 'pattern',
|
|
194
|
+
source,
|
|
195
|
+
origin: origin,
|
|
196
|
+
confidence: extra.confidence || 0.5,
|
|
197
|
+
lastReviewed: rule.lastReviewed || new Date().toISOString(),
|
|
198
|
+
anomalyTags: extra.anomalyTags || [],
|
|
199
|
+
tools: rule.tools || [],
|
|
200
|
+
decision: rule.decision || 'deny',
|
|
201
|
+
category: rule.category || 'prevention',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Check if a rule applies to a specific tool.
|
|
207
|
+
* Rules with no tool restriction apply to all tools.
|
|
208
|
+
* Rules with tool restriction only apply to listed tools.
|
|
209
|
+
*/
|
|
210
|
+
function ruleAppliesToTool(rule, toolName) {
|
|
211
|
+
if (!rule.tools || rule.tools.length === 0) return true;
|
|
212
|
+
return rule.tools.includes(toolName);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Compute confidence score for a feedback-derived rule.
|
|
217
|
+
* Higher confidence = more frequently violated rule.
|
|
218
|
+
*/
|
|
219
|
+
function computeConfidence(feedbackEntry) {
|
|
220
|
+
const severity = feedbackEntry.severity || 1;
|
|
221
|
+
const recurrence = feedbackEntry.recurrenceCount || 1;
|
|
222
|
+
// Logarithmic scaling to avoid overfitting to outliers
|
|
223
|
+
return Math.min(0.99, 0.3 + Math.log(1 + recurrence * severity) / 10);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Detect anomaly patterns in feedback (DATA+AI Summit #3:
|
|
228
|
+
* bake analytical reasoning into prompts / tooling logic).
|
|
229
|
+
*/
|
|
230
|
+
function detectAnomalies(feedbackEntry) {
|
|
231
|
+
const text = JSON.stringify(feedbackEntry).toLowerCase();
|
|
232
|
+
const tags = [];
|
|
233
|
+
for (const { id, pattern, severity } of ANOMALY_PATTERNS) {
|
|
234
|
+
if (pattern.test(text)) {
|
|
235
|
+
tags.push({ id, severity, description: pattern.description || id });
|
|
236
|
+
}
|
|
237
|
+
pattern.lastIndex = 0; // Reset for reuse
|
|
238
|
+
}
|
|
239
|
+
return tags;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get the tool tags for a given tool name (pushdown filter optimization).
|
|
244
|
+
*/
|
|
245
|
+
function getToolTags(toolName) {
|
|
246
|
+
return TOOL_TAGS[toolName] || [];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Describe the Gold layer schema (semantic layer metadata).
|
|
251
|
+
* Mirrors the DATA+AI Summit principle of providing a curated
|
|
252
|
+
* semantic layer that agents can explore in a single call.
|
|
253
|
+
*/
|
|
254
|
+
function describeGoldLayer() {
|
|
255
|
+
return {
|
|
256
|
+
name: 'ThumbGate Prevention Rules — Gold Layer',
|
|
257
|
+
description: 'Curated, pre-validated, deduplicated prevention rules from feedback store and hand-authored rules',
|
|
258
|
+
version: '1.0',
|
|
259
|
+
sources: ['prevention-rules.json (curated)', '.claude/memory/feedback/ (feedback-derived)'],
|
|
260
|
+
ruleTypes: ['pattern', 'path', 'command', 'tool'],
|
|
261
|
+
categories: ['security', 'prevention', 'policy', 'compliance'],
|
|
262
|
+
anomalyPatterns: ANOMALY_PATTERNS.map(p => ({ id: p.id, severity: p.severity, description: p.description })),
|
|
263
|
+
sampling: {
|
|
264
|
+
threshold: SAMPLING_THRESHOLD,
|
|
265
|
+
ratio: SAMPLING_RATIO,
|
|
266
|
+
method: 'deterministic-even-sample',
|
|
267
|
+
},
|
|
268
|
+
pushdownFilters: ['toolName', 'category'],
|
|
269
|
+
cache: {
|
|
270
|
+
ttlMs: HOT_CACHE_TTL_MS,
|
|
271
|
+
maxEntries: HOT_CACHE_MAX_ENTRIES,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function MATH_FLOOR(x) { return Math.floor(x); }
|
|
277
|
+
|
|
278
|
+
module.exports = {
|
|
279
|
+
loadGoldRules,
|
|
280
|
+
annotateRule,
|
|
281
|
+
ruleAppliesToTool,
|
|
282
|
+
computeConfidence,
|
|
283
|
+
detectAnomalies,
|
|
284
|
+
getToolTags,
|
|
285
|
+
describeGoldLayer,
|
|
286
|
+
ANOMALY_PATTERNS,
|
|
287
|
+
TOOL_TAGS,
|
|
288
|
+
SAMPLING_THRESHOLD,
|
|
289
|
+
SAMPLING_RATIO,
|
|
290
|
+
HOT_CACHE_TTL_MS,
|
|
291
|
+
HOT_CACHE_MAX_ENTRIES,
|
|
292
|
+
};
|
package/scripts/gate-stats.js
CHANGED
|
@@ -68,7 +68,7 @@ function calculateStats(options = {}) {
|
|
|
68
68
|
totalBlocked = Math.max(totalBlocked, pBlocked);
|
|
69
69
|
}
|
|
70
70
|
if (Number.isFinite(persisted.distinctBlocks)) {
|
|
71
|
-
distinctBlocked = persisted.distinctBlocks;
|
|
71
|
+
distinctBlocked = Math.max(0, Math.trunc(persisted.distinctBlocks));
|
|
72
72
|
} else {
|
|
73
73
|
distinctBlocked = Math.max(0, totalBlocked - recurringBlocks);
|
|
74
74
|
}
|
|
@@ -224,6 +224,11 @@ function formatLastPromotion(promo) {
|
|
|
224
224
|
return label;
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
function toCount(value, fallback) {
|
|
228
|
+
const n = Number(value);
|
|
229
|
+
return Number.isFinite(n) ? Math.max(0, Math.trunc(n)) : fallback;
|
|
230
|
+
}
|
|
231
|
+
|
|
227
232
|
function formatStats(stats) {
|
|
228
233
|
const lines = [];
|
|
229
234
|
lines.push('Gate Statistics');
|
|
@@ -231,7 +236,8 @@ function formatStats(stats) {
|
|
|
231
236
|
lines.push(` Active gates: ${stats.totalGates} (${stats.manualGates} manual, ${stats.autoPromotedGates} auto-promoted)`);
|
|
232
237
|
lines.push(` Actions blocked: ${stats.totalBlocked}`);
|
|
233
238
|
if (stats.recurringBlocks !== undefined && stats.recurringBlocks > 0) {
|
|
234
|
-
const
|
|
239
|
+
const fallback = toCount(Math.max(0, stats.totalBlocked - stats.recurringBlocks), 0);
|
|
240
|
+
const distinct = toCount(stats.distinctBlocked, fallback);
|
|
235
241
|
lines.push(` Repeat blocks: ${stats.recurringBlocks} (${distinct} distinct first-time blocks)`);
|
|
236
242
|
}
|
|
237
243
|
lines.push(` Actions warned: ${stats.totalWarned}`);
|