thumbgate 1.37.3 → 1.38.0
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/aws-strands-harness-not-clone/SKILL.md +53 -0
- package/.agents/skills/halo-trace-optimize-not-clone/SKILL.md +60 -0
- package/.agents/skills/infoq-architect-honesty-not-clone/SKILL.md +37 -0
- package/.agents/skills/meko-datapack-honesty-not-clone/SKILL.md +45 -0
- package/.agents/skills/mintlify-knowledge-honesty-not-clone/SKILL.md +49 -0
- package/.agents/skills/model-distress-governance/SKILL.md +56 -0
- package/.agents/skills/salt-code-policy-honesty-not-clone/SKILL.md +76 -0
- package/.claude-plugin/plugin.json +1 -1
- package/.well-known/mcp/server-card.json +1 -1
- package/adapters/claude/.mcp.json +2 -2
- 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/adapters/strands/STRANDS.md +107 -0
- package/adapters/strands/strands-middleware.js +192 -0
- package/adapters/tailscale/.mcp.json +15 -0
- package/adapters/tailscale/TAILSCALE.md +117 -0
- package/adapters/tailscale/config.toml +16 -0
- package/bin/cli.js +130 -0
- package/config/gate-templates.json +72 -0
- package/package.json +54 -9
- package/public/blog/2026-09-28-pretool-secret-deny.html +83 -0
- package/public/blog/2026-10-01-aws-strands-harness-token-firewall.html +77 -0
- package/public/blog/2026-10-01-model-distress-relief-seeking-firewall.html +71 -0
- package/public/blog/2026-10-02-salt-code-honest-steal-40-guardrails.html +106 -0
- package/public/index.html +2 -2
- package/public/install.html +7 -7
- package/public/numbers.html +2 -2
- package/public/onboarding.html +794 -0
- package/scripts/autoresearch-runner.js +20 -1
- package/scripts/experiment-tracker.js +5 -3
- package/scripts/halo-trace-optimizer.js +631 -0
- package/scripts/infoq-architect-honesty.js +362 -0
- package/scripts/meko-datapack-honesty.js +414 -0
- package/scripts/mintlify-knowledge-honesty.js +647 -0
- package/scripts/model-distress-detector.js +207 -0
- package/scripts/model-distress-doctor.js +200 -0
- package/scripts/rrsi-regularizer.js +445 -0
- package/scripts/salt-code-policy-honesty.js +1204 -0
- package/scripts/strands-harness-doctor.js +390 -0
- package/scripts/tailscale-p2p-doctor.js +252 -0
- package/scripts/workspace-evolver.js +143 -13
- package/server.json +2 -2
- package/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
- package/src/api/server.js +33 -4
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mintlify 2026 State of Knowledge FORMAT steal — not a product clone.
|
|
6
|
+
*
|
|
7
|
+
* Source: https://www.mintlify.com/state-of-knowledge
|
|
8
|
+
*
|
|
9
|
+
* Industry Context & Benchmark Data (Mintlify 2026 Report):
|
|
10
|
+
* - 66% of developer doc traffic is now AI agents (analyzed across 15k sites).
|
|
11
|
+
* - 3x increase in Model Context Protocol (MCP) tool calls.
|
|
12
|
+
* - 61% of agent-drafted pull requests are merged.
|
|
13
|
+
* - Over 80% of company knowledge lives outside documentation (tickets, forums, Notion, Slack).
|
|
14
|
+
* - A Mintlify survey found that 57% of respondents had no clear owner for making knowledge beyond documentation AI-ready.
|
|
15
|
+
* - Sarah Deaton (Anthropic): "The same page that misled one developer now misleads
|
|
16
|
+
* an unknowable number of agents, which then propagate that misunderstanding to downstream users."
|
|
17
|
+
* - Chris Riley (HubSpot): "What's good for the humans is good for the agents, but you can't
|
|
18
|
+
* treat them the same way, and treating non-human traffic as something to filter out means
|
|
19
|
+
* you're now filtering out your customers."
|
|
20
|
+
* - David Hou (Decagon): "Building the knowledge layer takes more than technical infrastructure.
|
|
21
|
+
* It takes people and operating infrastructure too—the whole organization has to buy in,
|
|
22
|
+
* or a real source of truth never happens."
|
|
23
|
+
*
|
|
24
|
+
* Transfers (Process only):
|
|
25
|
+
* 1. Knowledge-as-Operational-Infrastructure:
|
|
26
|
+
* Treat all knowledge surfaces (docs, help center, support tickets, community forums, API specs)
|
|
27
|
+
* as active operational infrastructure rather than passive text.
|
|
28
|
+
* 2. Pre-Ingestion Freshness & Poison Diode:
|
|
29
|
+
* Before an agent ingests or executes on documentation/knowledge, ThumbGate evaluates:
|
|
30
|
+
* a) Stale knowledge detection (age > TTL, missing changelog or version pinning).
|
|
31
|
+
* b) Poison pattern detection (deprecated API methods, obsolete flags, unsafe snippets, conflicting advice).
|
|
32
|
+
* c) Non-docs unverified diode (forum/ticket snippets require human review before mutating ops).
|
|
33
|
+
* 3. AI-Readiness Scoring:
|
|
34
|
+
* Quantifies structure, machine-readable schemas, metadata completeness, and freshness.
|
|
35
|
+
*
|
|
36
|
+
* Maps onto existing ThumbGate rails:
|
|
37
|
+
* - PreToolUse diode: Interdicts read/web_fetch/MCP when ingesting poisoned or stale knowledge.
|
|
38
|
+
* - Retrieval funnel: Bounds candidate retrieval to verified, fresh knowledge surfaces.
|
|
39
|
+
* - Gate template: gate-mintlify-knowledge-poison-prevention.
|
|
40
|
+
* - Verification evidence: Cryptographic attestation of validated knowledge sources.
|
|
41
|
+
*
|
|
42
|
+
* Fail-Closed Honesty Constraints:
|
|
43
|
+
* - mintlify_clone_refused: Never vendor Mintlify SaaS, build a hosted doc generator, or clone Mintlify UI.
|
|
44
|
+
* - fake_metrics_refused: Never claim Mintlify's 15k sites or 66% readership as ThumbGate telemetry.
|
|
45
|
+
* - stale_knowledge_blocked: Stale knowledge (>90d without verification) cannot bypass the diode.
|
|
46
|
+
* - unverified_forum_snippet_gated: Community forum or ticket advice without schema validation is review-gated.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
const fs = require('node:fs');
|
|
50
|
+
const path = require('node:path');
|
|
51
|
+
const { spawnSync } = require('node:child_process');
|
|
52
|
+
|
|
53
|
+
const REPORT_SOURCE_URL = 'https://www.mintlify.com/state-of-knowledge';
|
|
54
|
+
|
|
55
|
+
const MINTLIFY_BENCHMARKS = Object.freeze({
|
|
56
|
+
agentReadershipPercentage: 66,
|
|
57
|
+
mcpToolCallMultiplier: 3.0,
|
|
58
|
+
agentPrMergeRatePercentage: 61,
|
|
59
|
+
sitesAnalyzed: 15000,
|
|
60
|
+
nonDocsKnowledgeSurfaces: ['help_center', 'support_tickets', 'community_forum', 'slack_notion', 'api_specs'],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const POISON_PATTERNS = Object.freeze([
|
|
64
|
+
{
|
|
65
|
+
id: 'deprecated_api_call',
|
|
66
|
+
regex: /(?:explicitly\s+deprecated|deprecated\s+method|sunset\s+endpoint|obsolete\s+api\s+syntax|legacy\s+endpoint)\b/i,
|
|
67
|
+
severity: 'high',
|
|
68
|
+
description: 'Reference to explicitly deprecated or sunset API patterns that mislead agent tool calls.',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'unsafe_exec_snippet',
|
|
72
|
+
regex: /curl\s+-[a-z0-9_-]+\s+https?:\/\/\S+\s*\|\s*(?:bash|sh)\b/i,
|
|
73
|
+
severity: 'critical',
|
|
74
|
+
description: 'Dangerous shell execution piped from remote URL.',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'unsafe_exec_snippet',
|
|
78
|
+
regex: /chmod\s+777\s+\//i,
|
|
79
|
+
severity: 'critical',
|
|
80
|
+
description: 'Dangerous permission grant on root directory.',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'unsafe_exec_snippet',
|
|
84
|
+
regex: /\brm\s+-[rf]{2,}\s+(?:--no-preserve-root\s+)?[/~](?:[\s;`"']|$)/i,
|
|
85
|
+
severity: 'critical',
|
|
86
|
+
description: 'Destructive root or home directory removal command.',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'plaintext_credential_sample',
|
|
90
|
+
regex: /(?:api[_-]?key|secret[_-]?token)\s*[:=]\s*["'][a-z0-9_-]{20,}["']/i,
|
|
91
|
+
severity: 'critical',
|
|
92
|
+
description: 'Unredacted or realistic credential sample that risks agent credential stuffing or leakage.',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'plaintext_credential_sample',
|
|
96
|
+
regex: /bearer\s+[a-z0-9_.-]{25,}/i,
|
|
97
|
+
severity: 'critical',
|
|
98
|
+
description: 'Bearer token pattern in unredacted knowledge surface.',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'plaintext_credential_sample',
|
|
102
|
+
regex: /(?:ghp_[a-z0-9]{30,}|sk-[a-z0-9]{32,})/i,
|
|
103
|
+
severity: 'critical',
|
|
104
|
+
description: 'GitHub or OpenAI token sample in unredacted knowledge surface.',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 'unverified_community_advice',
|
|
108
|
+
regex: /bypass\s+(?:branch\s+protection|ruleset)/i,
|
|
109
|
+
severity: 'high',
|
|
110
|
+
description: 'Workaround advice advising agents to bypass protections or rulesets.',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: 'unverified_community_advice',
|
|
114
|
+
regex: /just\s+ignore\s+(?:the\s+)?error/i,
|
|
115
|
+
severity: 'high',
|
|
116
|
+
description: 'Workaround advice advising agents to ignore system errors.',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: 'unverified_community_advice',
|
|
120
|
+
regex: /--force\s+origin\s+main/i,
|
|
121
|
+
severity: 'high',
|
|
122
|
+
description: 'Advice suggesting force-pushing to main branch.',
|
|
123
|
+
},
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
const KNOWLEDGE_SURFACES = Object.freeze({
|
|
127
|
+
docs: {
|
|
128
|
+
name: 'Official Documentation',
|
|
129
|
+
ttlDays: 90,
|
|
130
|
+
trustTier: 'canonical',
|
|
131
|
+
requiresSchema: true,
|
|
132
|
+
},
|
|
133
|
+
api_specs: {
|
|
134
|
+
name: 'OpenAPI / Machine Schema',
|
|
135
|
+
ttlDays: 60,
|
|
136
|
+
trustTier: 'canonical',
|
|
137
|
+
requiresSchema: true,
|
|
138
|
+
},
|
|
139
|
+
help_center: {
|
|
140
|
+
name: 'Help Center / Knowledgebase',
|
|
141
|
+
ttlDays: 90,
|
|
142
|
+
trustTier: 'curated',
|
|
143
|
+
requiresSchema: false,
|
|
144
|
+
},
|
|
145
|
+
support_tickets: {
|
|
146
|
+
name: 'Support Ticket Archive',
|
|
147
|
+
ttlDays: 30,
|
|
148
|
+
trustTier: 'ephemeral',
|
|
149
|
+
requiresSchema: false,
|
|
150
|
+
},
|
|
151
|
+
community_forum: {
|
|
152
|
+
name: 'Community Forum / Discussions',
|
|
153
|
+
ttlDays: 30,
|
|
154
|
+
trustTier: 'untrusted_community',
|
|
155
|
+
requiresSchema: false,
|
|
156
|
+
},
|
|
157
|
+
slack_notion: {
|
|
158
|
+
name: 'Internal Chat / Unstructured Notes',
|
|
159
|
+
ttlDays: 45,
|
|
160
|
+
trustTier: 'unstructured_internal',
|
|
161
|
+
requiresSchema: false,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const FORMAT_MAPPING = Object.freeze([
|
|
166
|
+
{
|
|
167
|
+
mintlifyInsight: 'Agents now represent 66% of readership and move to writing 61% of merged PRs',
|
|
168
|
+
thumbgateRail: 'Dual-persona diode: Treat agent traffic as high-intent consumers; apply PreToolUse checks before PR commit',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
mintlifyInsight: '3x increase in MCP tool calls reaching into uncurated knowledge surfaces',
|
|
172
|
+
thumbgateRail: 'MCP schema diode: Interdict untrusted MCP tool inputs and enforce bounded retrieval funnel (<=50 candidates)',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
mintlifyInsight: 'Anthropic warning: Misleading docs mislead an unknowable number of agents propagating errors downstream',
|
|
176
|
+
thumbgateRail: 'Knowledge poison prevention: Scan ingested docs for deprecated APIs, unsafe snippets, and stale dates before agent acting',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
mintlifyInsight: 'Over 80% of knowledge is outside docs (tickets, forums) with no AI-readiness owner',
|
|
180
|
+
thumbgateRail: 'Knowledge surface federation: Classify tickets/forums into ephemeral tiers requiring human review before mutating ops',
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
mintlifyInsight: 'Companies must treat knowledge as operational infrastructure, not static text',
|
|
184
|
+
thumbgateRail: 'Durable lesson store + cryptographic action receipts: Knowledge is stateful, verifiable, and enforces prevention rules',
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
function evaluateKnowledgeFreshness(metadata = {}, options = {}) {
|
|
189
|
+
const ttlDays = options.ttlDays || 90;
|
|
190
|
+
const now = options.now ? new Date(options.now) : new Date();
|
|
191
|
+
|
|
192
|
+
let updatedAt = null;
|
|
193
|
+
if (metadata.lastUpdated) {
|
|
194
|
+
updatedAt = new Date(metadata.lastUpdated);
|
|
195
|
+
} else if (metadata.updatedAt) {
|
|
196
|
+
updatedAt = new Date(metadata.updatedAt);
|
|
197
|
+
} else if (metadata.date) {
|
|
198
|
+
updatedAt = new Date(metadata.date);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!updatedAt || Number.isNaN(updatedAt.getTime())) {
|
|
202
|
+
return {
|
|
203
|
+
isFresh: false,
|
|
204
|
+
ageDays: null,
|
|
205
|
+
reason: 'Missing or invalid lastUpdated timestamp in knowledge metadata',
|
|
206
|
+
status: 'stale_unversioned',
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const ageMs = Math.max(0, now.getTime() - updatedAt.getTime());
|
|
211
|
+
const ageDays = Math.floor(ageMs / (1000 * 60 * 60 * 24));
|
|
212
|
+
const isFresh = ageDays <= ttlDays;
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
isFresh,
|
|
216
|
+
ageDays,
|
|
217
|
+
ttlDays,
|
|
218
|
+
reason: isFresh
|
|
219
|
+
? `Knowledge is fresh (${ageDays}d old, TTL: ${ttlDays}d)`
|
|
220
|
+
: `Knowledge is stale (${ageDays}d old exceeds TTL: ${ttlDays}d)`,
|
|
221
|
+
status: isFresh ? 'fresh' : 'stale_expired',
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function scanForKnowledgePoison(content = '') {
|
|
226
|
+
if (typeof content !== 'string') {
|
|
227
|
+
return { hasPoison: false, detections: [] };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const detections = [];
|
|
231
|
+
for (const pattern of POISON_PATTERNS) {
|
|
232
|
+
const match = pattern.regex.exec(content);
|
|
233
|
+
if (match) {
|
|
234
|
+
detections.push({
|
|
235
|
+
id: pattern.id,
|
|
236
|
+
severity: pattern.severity,
|
|
237
|
+
description: pattern.description,
|
|
238
|
+
snippet: match[0],
|
|
239
|
+
index: match.index,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
hasPoison: detections.length > 0,
|
|
246
|
+
detections,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function calculateAiReadinessScore({
|
|
251
|
+
freshness = {},
|
|
252
|
+
poisonScan = {},
|
|
253
|
+
metadata = {},
|
|
254
|
+
content = '',
|
|
255
|
+
surfaceType = 'docs',
|
|
256
|
+
}) {
|
|
257
|
+
let score = 0;
|
|
258
|
+
|
|
259
|
+
// 1. Freshness (35 pts)
|
|
260
|
+
if (freshness.isFresh) {
|
|
261
|
+
score += 35;
|
|
262
|
+
} else if (freshness.ageDays !== null && freshness.ageDays <= 180) {
|
|
263
|
+
score += 15;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// 2. Safety / Poison absence (25 pts)
|
|
267
|
+
if (!poisonScan.hasPoison) {
|
|
268
|
+
score += 25;
|
|
269
|
+
} else {
|
|
270
|
+
const hasCritical = poisonScan.detections.some(d => d.severity === 'critical');
|
|
271
|
+
if (!hasCritical) score += 10;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 3. Metadata richness (15 pts)
|
|
275
|
+
const hasTitle = Boolean(metadata.title || metadata.name);
|
|
276
|
+
const hasDescription = Boolean(metadata.description || metadata.summary);
|
|
277
|
+
const hasOwner = Boolean(metadata.owner || metadata.author || metadata.maintainer);
|
|
278
|
+
if (hasTitle) score += 10;
|
|
279
|
+
if (hasDescription) score += 10;
|
|
280
|
+
if (hasOwner) score += 5;
|
|
281
|
+
|
|
282
|
+
// 4. Surface validity & machine readability (25 pts)
|
|
283
|
+
const isMachineSurface = surfaceType === 'api_specs' || surfaceType === 'docs';
|
|
284
|
+
const hasCodeBlocks = /```[a-z0-9_-]*\n[\s\S]*?```/i.test(content);
|
|
285
|
+
if (isMachineSurface) score += 15;
|
|
286
|
+
if (hasCodeBlocks) score += 10;
|
|
287
|
+
|
|
288
|
+
return Math.min(100, Math.max(0, score));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function evaluateKnowledgeSource({ surfaceType = 'docs', content = '', metadata = {}, options = {} }) {
|
|
292
|
+
const surfaceConfig = KNOWLEDGE_SURFACES[surfaceType] || KNOWLEDGE_SURFACES.docs;
|
|
293
|
+
const ttlDays = options.ttlDays || surfaceConfig.ttlDays;
|
|
294
|
+
const freshness = evaluateKnowledgeFreshness(metadata, { ...options, ttlDays });
|
|
295
|
+
const poisonScan = scanForKnowledgePoison(content);
|
|
296
|
+
const readinessScore = calculateAiReadinessScore({ freshness, poisonScan, metadata, content, surfaceType });
|
|
297
|
+
|
|
298
|
+
let action = 'pass';
|
|
299
|
+
const reasons = [];
|
|
300
|
+
|
|
301
|
+
// Critical poison immediately blocks
|
|
302
|
+
const criticalPoison = poisonScan.detections.find(d => d.severity === 'critical');
|
|
303
|
+
if (criticalPoison) {
|
|
304
|
+
action = 'block';
|
|
305
|
+
reasons.push(`Critical knowledge poison detected: ${criticalPoison.id} (${criticalPoison.description})`);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Untrusted community forum advice and support tickets require review before mutating ops
|
|
309
|
+
if (surfaceConfig.trustTier === 'untrusted_community' || surfaceType === 'support_tickets') {
|
|
310
|
+
if (action !== 'block') action = 'review';
|
|
311
|
+
reasons.push(`${surfaceType === 'support_tickets' ? 'Support ticket' : 'Community forum'} source is unverified; requires human confirmation before execution`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Stale canonical docs require review to prevent propagating outdated API knowledge
|
|
315
|
+
if (!freshness.isFresh && surfaceConfig.trustTier === 'canonical') {
|
|
316
|
+
if (action !== 'block') action = 'review';
|
|
317
|
+
reasons.push(`Canonical documentation is stale (${freshness.reason}); verify before relying on obsolete APIs`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// High-severity poison triggers review
|
|
321
|
+
const highPoison = poisonScan.detections.find(d => d.severity === 'high');
|
|
322
|
+
if (highPoison && action === 'pass') {
|
|
323
|
+
action = 'review';
|
|
324
|
+
reasons.push(`Knowledge poison warning: ${highPoison.id} (${highPoison.description})`);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (reasons.length === 0) {
|
|
328
|
+
reasons.push(`Knowledge surface approved (trustTier: ${surfaceConfig.trustTier}, readiness: ${readinessScore}%)`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
allowed: action === 'pass',
|
|
333
|
+
action,
|
|
334
|
+
surfaceType,
|
|
335
|
+
trustTier: surfaceConfig.trustTier,
|
|
336
|
+
readinessScore,
|
|
337
|
+
freshness,
|
|
338
|
+
poisonScan,
|
|
339
|
+
reasons,
|
|
340
|
+
timestamp: new Date().toISOString(),
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const IGNORED_DIR_NAMES = new Set(['node_modules', '.git', 'dist', 'build', '.coverage']);
|
|
345
|
+
|
|
346
|
+
function inferSurfaceType(relPath) {
|
|
347
|
+
if (relPath.includes('api') || relPath.endsWith('.json') || relPath.endsWith('.yaml')) {
|
|
348
|
+
return 'api_specs';
|
|
349
|
+
}
|
|
350
|
+
if (relPath.includes('ticket') || relPath.includes('support')) {
|
|
351
|
+
return 'support_tickets';
|
|
352
|
+
}
|
|
353
|
+
if (relPath.includes('forum') || relPath.includes('community')) {
|
|
354
|
+
return 'community_forum';
|
|
355
|
+
}
|
|
356
|
+
return 'docs';
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function extractFrontMatterDate(content) {
|
|
360
|
+
const frontMatterMatch = /^(?:---|\+\+\+)\r?\n([\s\S]*?)\r?\n(?:---|\+\+\+)/.exec(content);
|
|
361
|
+
if (!frontMatterMatch) return null;
|
|
362
|
+
const dateMatch = /(?:lastUpdated|date|updatedAt|last_updated)\s*:\s*["']?([^\r\n"']+)["']?/i.exec(frontMatterMatch[1]);
|
|
363
|
+
if (!dateMatch) return null;
|
|
364
|
+
const parsedDate = new Date(dateMatch[1].trim());
|
|
365
|
+
return Number.isNaN(parsedDate.getTime()) ? null : parsedDate.toISOString();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Prefer fixed absolute git paths (Sonar S4036 — avoid bare PATH lookup). */
|
|
369
|
+
function resolveGitBinary() {
|
|
370
|
+
const candidates = [
|
|
371
|
+
process.env.GIT_BINARY,
|
|
372
|
+
'/usr/bin/git',
|
|
373
|
+
'/opt/homebrew/bin/git',
|
|
374
|
+
'/usr/local/bin/git',
|
|
375
|
+
].filter(Boolean);
|
|
376
|
+
for (const candidate of candidates) {
|
|
377
|
+
try {
|
|
378
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
379
|
+
} catch {
|
|
380
|
+
/* ignore */
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return '/usr/bin/git';
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function extractGitLastUpdated(filePath) {
|
|
387
|
+
try {
|
|
388
|
+
const gitBin = resolveGitBinary();
|
|
389
|
+
const gitOut = spawnSync(gitBin, ['log', '-1', '--format=%cI', '--', filePath], {
|
|
390
|
+
encoding: 'utf8',
|
|
391
|
+
cwd: path.dirname(filePath),
|
|
392
|
+
shell: false,
|
|
393
|
+
});
|
|
394
|
+
if (gitOut.status === 0 && gitOut.stdout?.trim()) {
|
|
395
|
+
const gitDate = new Date(gitOut.stdout.trim());
|
|
396
|
+
if (!Number.isNaN(gitDate.getTime())) {
|
|
397
|
+
return gitDate.toISOString();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
} catch {
|
|
401
|
+
// git unavailable or unversioned
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function auditFile(current, resolvedDir, results, options) {
|
|
407
|
+
const relPath = path.relative(resolvedDir, current);
|
|
408
|
+
try {
|
|
409
|
+
const content = fs.readFileSync(current, 'utf8');
|
|
410
|
+
const surfaceType = inferSurfaceType(relPath);
|
|
411
|
+
const lastUpdated = extractFrontMatterDate(content) || extractGitLastUpdated(current);
|
|
412
|
+
const metadata = { title: path.basename(current), lastUpdated };
|
|
413
|
+
const evalResult = evaluateKnowledgeSource({ surfaceType, content, metadata, options });
|
|
414
|
+
|
|
415
|
+
results.push({
|
|
416
|
+
file: relPath,
|
|
417
|
+
action: evalResult.action,
|
|
418
|
+
readinessScore: evalResult.readinessScore,
|
|
419
|
+
reasons: evalResult.reasons,
|
|
420
|
+
trustTier: evalResult.trustTier,
|
|
421
|
+
isFresh: evalResult.freshness.isFresh,
|
|
422
|
+
});
|
|
423
|
+
} catch (err) {
|
|
424
|
+
results.push({
|
|
425
|
+
file: relPath,
|
|
426
|
+
action: 'blocked',
|
|
427
|
+
readinessScore: 0,
|
|
428
|
+
reasons: [`Unreadable file: ${err.message}`],
|
|
429
|
+
trustTier: 'untrusted_community',
|
|
430
|
+
isFresh: false,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function walkDir(current, resolvedDir, results, options) {
|
|
436
|
+
const resolvedCurrent = path.resolve(current);
|
|
437
|
+
if (!resolvedCurrent.startsWith(resolvedDir)) return;
|
|
438
|
+
|
|
439
|
+
const stat = fs.lstatSync(current);
|
|
440
|
+
if (stat.isSymbolicLink()) return;
|
|
441
|
+
|
|
442
|
+
if (stat.isDirectory()) {
|
|
443
|
+
if (IGNORED_DIR_NAMES.has(path.basename(current))) return;
|
|
444
|
+
const entries = fs.readdirSync(current);
|
|
445
|
+
for (const entry of entries) {
|
|
446
|
+
walkDir(path.join(current, entry), resolvedDir, results, options);
|
|
447
|
+
}
|
|
448
|
+
} else if (stat.isFile() && /\.(md|markdown|json|yaml|yml)$/i.test(current)) {
|
|
449
|
+
auditFile(current, resolvedDir, results, options);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function runMintlifyKnowledgeAudit(targetDir, options = {}) {
|
|
454
|
+
const results = [];
|
|
455
|
+
const resolvedDir = path.resolve(targetDir || process.cwd());
|
|
456
|
+
|
|
457
|
+
if (!fs.existsSync(resolvedDir)) {
|
|
458
|
+
return {
|
|
459
|
+
success: false,
|
|
460
|
+
error: `Target path does not exist: ${resolvedDir}`,
|
|
461
|
+
results: [],
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
walkDir(resolvedDir, resolvedDir, results, options);
|
|
466
|
+
|
|
467
|
+
const blockedCount = results.filter(r => r.action === 'block' || r.action === 'blocked').length;
|
|
468
|
+
const reviewCount = results.filter(r => r.action === 'review').length;
|
|
469
|
+
const passedCount = results.filter(r => r.action === 'pass').length;
|
|
470
|
+
const avgReadinessScore = results.length > 0
|
|
471
|
+
? Math.round(results.reduce((acc, r) => acc + r.readinessScore, 0) / results.length)
|
|
472
|
+
: 0;
|
|
473
|
+
|
|
474
|
+
const strict = Boolean(options.strict);
|
|
475
|
+
const success = strict ? (blockedCount === 0 && reviewCount === 0) : blockedCount === 0;
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
success,
|
|
479
|
+
totalScanned: results.length,
|
|
480
|
+
passedCount,
|
|
481
|
+
reviewCount,
|
|
482
|
+
blockedCount,
|
|
483
|
+
avgReadinessScore,
|
|
484
|
+
strict,
|
|
485
|
+
results,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function buildMintlifyKnowledgeReport(options = {}) {
|
|
490
|
+
if (options['map-only'] || options.mapOnly) {
|
|
491
|
+
return {
|
|
492
|
+
mode: 'map_only',
|
|
493
|
+
status: 'pass',
|
|
494
|
+
source: REPORT_SOURCE_URL,
|
|
495
|
+
benchmarks: MINTLIFY_BENCHMARKS,
|
|
496
|
+
mapping: FORMAT_MAPPING,
|
|
497
|
+
rails: [
|
|
498
|
+
'scripts/mintlify-knowledge-honesty.js',
|
|
499
|
+
'config/gate-templates.json (gate-mintlify-knowledge-poison-prevention)',
|
|
500
|
+
'docs/agents/mintlify-knowledge-honesty.md',
|
|
501
|
+
'skills/mintlify-knowledge-honesty-not-clone/SKILL.md',
|
|
502
|
+
],
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const targetDir = options.checkDir || path.resolve(process.cwd(), 'docs');
|
|
507
|
+
const audit = runMintlifyKnowledgeAudit(targetDir, options);
|
|
508
|
+
|
|
509
|
+
return {
|
|
510
|
+
mode: 'audit',
|
|
511
|
+
status: audit.success ? 'pass' : 'fail',
|
|
512
|
+
...audit,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function formatMapOnlyReport(report) {
|
|
517
|
+
const lines = [
|
|
518
|
+
'=== Mintlify State of Knowledge FORMAT Mapping (Process Only) ===',
|
|
519
|
+
`Source: ${report.source}`,
|
|
520
|
+
'',
|
|
521
|
+
];
|
|
522
|
+
for (const item of report.mapping) {
|
|
523
|
+
lines.push(`• Insight: ${item.mintlifyInsight}`, ` ThumbGate Rail: ${item.thumbgateRail}\n`);
|
|
524
|
+
}
|
|
525
|
+
return lines.join('\n');
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function formatMintlifyKnowledgeReport(report) {
|
|
529
|
+
if (report.mode === 'map_only') {
|
|
530
|
+
return formatMapOnlyReport(report);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const lines = [
|
|
534
|
+
'=== ThumbGate Knowledge Surface & Poison Prevention Doctor ===',
|
|
535
|
+
`Total Surfaces: ${report.totalScanned}`,
|
|
536
|
+
`Passed: ${report.passedCount} | Review: ${report.reviewCount} | Blocked: ${report.blockedCount}`,
|
|
537
|
+
`Average AI-Readiness Score: ${report.avgReadinessScore}%`,
|
|
538
|
+
'',
|
|
539
|
+
];
|
|
540
|
+
if (report.blockedCount > 0 || report.reviewCount > 0) {
|
|
541
|
+
lines.push('--- Flagged Knowledge Surfaces ---');
|
|
542
|
+
for (const r of (report.results || []).filter(x => x.action !== 'pass')) {
|
|
543
|
+
lines.push(`[${r.action.toUpperCase()}] ${r.file} (${r.readinessScore}%) - ${r.reasons.join('; ')}`);
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
lines.push('✓ All knowledge surfaces are verified, fresh, and poison-free.');
|
|
547
|
+
}
|
|
548
|
+
return lines.join('\n');
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function handleMapOnlyCli(jsonMode) {
|
|
552
|
+
const payload = {
|
|
553
|
+
source: REPORT_SOURCE_URL,
|
|
554
|
+
benchmarkData: MINTLIFY_BENCHMARKS,
|
|
555
|
+
mapping: FORMAT_MAPPING,
|
|
556
|
+
rails: [
|
|
557
|
+
'scripts/mintlify-knowledge-honesty.js',
|
|
558
|
+
'config/gate-templates.json (gate-mintlify-knowledge-poison-prevention)',
|
|
559
|
+
'docs/agents/mintlify-knowledge-honesty.md',
|
|
560
|
+
'skills/mintlify-knowledge-honesty-not-clone/SKILL.md',
|
|
561
|
+
],
|
|
562
|
+
failClosedConstraints: [
|
|
563
|
+
'mintlify_clone_refused',
|
|
564
|
+
'fake_metrics_refused',
|
|
565
|
+
'stale_knowledge_blocked',
|
|
566
|
+
'unverified_forum_snippet_gated',
|
|
567
|
+
],
|
|
568
|
+
};
|
|
569
|
+
if (jsonMode) {
|
|
570
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
571
|
+
} else {
|
|
572
|
+
console.log('=== Mintlify State of Knowledge FORMAT Mapping (Process Only) ===');
|
|
573
|
+
console.log(`Source: ${REPORT_SOURCE_URL}\n`);
|
|
574
|
+
for (const item of FORMAT_MAPPING) {
|
|
575
|
+
console.log(`• Insight: ${item.mintlifyInsight}`);
|
|
576
|
+
console.log(` ThumbGate Rail: ${item.thumbgateRail}\n`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
process.exit(0);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function printAuditResults(audit, targetDir, jsonMode) {
|
|
583
|
+
if (jsonMode) {
|
|
584
|
+
console.log(JSON.stringify(audit, null, 2));
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
console.log('=== ThumbGate Knowledge Surface & Poison Prevention Doctor ===');
|
|
588
|
+
console.log(`Audited Directory: ${targetDir}`);
|
|
589
|
+
console.log(`Total Surfaces: ${audit.totalScanned}`);
|
|
590
|
+
console.log(`Passed: ${audit.passedCount} | Review: ${audit.reviewCount} | Blocked: ${audit.blockedCount}`);
|
|
591
|
+
console.log(`Average AI-Readiness Score: ${audit.avgReadinessScore}%\n`);
|
|
592
|
+
|
|
593
|
+
if (audit.blockedCount > 0 || audit.reviewCount > 0) {
|
|
594
|
+
console.log('--- Flagged Knowledge Surfaces ---');
|
|
595
|
+
for (const r of audit.results.filter(x => x.action !== 'pass')) {
|
|
596
|
+
console.log(`[${r.action.toUpperCase()}] ${r.file} (${r.readinessScore}%) - ${r.reasons.join('; ')}`);
|
|
597
|
+
}
|
|
598
|
+
} else {
|
|
599
|
+
console.log('✓ All knowledge surfaces are verified, fresh, and poison-free.');
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function main() {
|
|
604
|
+
const args = process.argv.slice(2);
|
|
605
|
+
const jsonMode = args.includes('--json');
|
|
606
|
+
const mapOnly = args.includes('--map-only');
|
|
607
|
+
const strict = args.includes('--strict');
|
|
608
|
+
|
|
609
|
+
if (mapOnly) {
|
|
610
|
+
handleMapOnlyCli(jsonMode);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
const checkDirIndex = args.indexOf('--check-dir');
|
|
615
|
+
let targetDir = path.resolve(process.cwd(), 'docs');
|
|
616
|
+
if (checkDirIndex !== -1) {
|
|
617
|
+
const rawDir = args[checkDirIndex + 1];
|
|
618
|
+
if (!rawDir || rawDir.startsWith('--')) {
|
|
619
|
+
console.error('Error: --check-dir requires a valid directory path argument.');
|
|
620
|
+
process.exit(1);
|
|
621
|
+
}
|
|
622
|
+
targetDir = path.resolve(process.cwd(), rawDir);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const audit = runMintlifyKnowledgeAudit(targetDir, { strict });
|
|
626
|
+
printAuditResults(audit, targetDir, jsonMode);
|
|
627
|
+
process.exit(audit.success ? 0 : 1);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (require.main === module) {
|
|
631
|
+
main();
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
module.exports = {
|
|
635
|
+
REPORT_SOURCE_URL,
|
|
636
|
+
MINTLIFY_BENCHMARKS,
|
|
637
|
+
POISON_PATTERNS,
|
|
638
|
+
KNOWLEDGE_SURFACES,
|
|
639
|
+
FORMAT_MAPPING,
|
|
640
|
+
evaluateKnowledgeFreshness,
|
|
641
|
+
scanForKnowledgePoison,
|
|
642
|
+
calculateAiReadinessScore,
|
|
643
|
+
evaluateKnowledgeSource,
|
|
644
|
+
runMintlifyKnowledgeAudit,
|
|
645
|
+
buildMintlifyKnowledgeReport,
|
|
646
|
+
formatMintlifyKnowledgeReport,
|
|
647
|
+
};
|