tractatus/scripts/analyze-doc-violations.js
TheFlow a78809a91f feat(docs): enhance violation fix script to handle all document fields
Updated fix-document-violations.js to fix violations in:
- content_markdown
- content_html
- search_index (new)
- excerpt (new)

This ensures complete compliance across all document fields.

Note: Export file handled separately due to contextual false positives
in headings and examples (e.g., "Architectural Safety Guarantees" as
topic description, not claim).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 21:57:41 +13:00

118 lines
4.2 KiB
JavaScript

/**
* Analyze which of the 22 public documents have inst_016/017/018 violations
*/
const { MongoClient } = require('mongodb');
const PUBLIC_SLUGS = [
// Getting Started (6)
'introduction', 'core-concepts', 'executive-summary-tractatus-inflection-point',
'implementation-guide-v1.1', 'implementation-guide', 'implementation-guide-python-examples',
// Research & Theory (7)
'tractatus-framework-research', 'pluralistic-values-research-foundations',
'the-27027-incident-a-case-study-in-pattern-recognition-bias',
'real-world-ai-governance-a-case-study-in-framework-failure-and-recovery',
'llm-integration-feasibility-research-scope',
'research-topic-concurrent-session-architecture',
'research-topic-rule-proliferation-transactional-overhead',
// Technical Reference (5)
'technical-architecture', 'api-reference-complete', 'api-javascript-examples',
'api-python-examples', 'openapi-specification',
// Advanced Topics (3)
'value-pluralism-faq', 'tractatus-ai-safety-framework-core-values-and-principles',
'organizational-theory-foundations',
// Business Leadership (1)
'business-case-tractatus-framework'
];
// Prohibited patterns
const PATTERNS = {
inst_016: [
/\b\d+%\b(?!.*\[NEEDS VERIFICATION\])/g, // Percentages without verification
/\b\d+\s*(million|billion|thousand)\b(?!.*\[NEEDS VERIFICATION\])/gi
],
inst_017: [
/\b(guarantee|guarantees|guaranteed|ensuring|ensures)\b/gi,
/\b(completely safe|totally secure|absolutely)\b/gi,
/\b(eliminate all|prevent all|never fail)\b/gi
],
inst_018: [
/\b(production-ready|production ready|battle-tested|proven solution|mature)\b/gi,
/\b(enterprise-grade|industry-leading|world-class)(?!.*evidence)\b/gi
]
};
async function run() {
const client = new MongoClient('mongodb://localhost:27017');
await client.connect();
const db = client.db('tractatus_dev');
const collection = db.collection('documents');
console.log('Analyzing 22 public documents for inst_016/017/018 violations...\n');
const results = [];
for (const slug of PUBLIC_SLUGS) {
const doc = await collection.findOne({ slug });
if (!doc) {
console.log(`⚠️ NOT FOUND: ${slug}`);
continue;
}
const content = (doc.content_markdown || '') + ' ' + (doc.content_html || '');
const violations = { inst_016: 0, inst_017: 0, inst_018: 0 };
// Check each pattern
for (const [rule, patterns] of Object.entries(PATTERNS)) {
for (const pattern of patterns) {
const matches = content.match(pattern);
if (matches) {
violations[rule] += matches.length;
}
}
}
const totalViolations = violations.inst_016 + violations.inst_017 + violations.inst_018;
if (totalViolations > 0) {
results.push({
slug,
title: doc.title,
category: doc.category,
violations,
total: totalViolations
});
}
}
// Sort by total violations
results.sort((a, b) => b.total - a.total);
console.log('═══════════════════════════════════════════════════════════');
console.log(' VIOLATION SUMMARY');
console.log('═══════════════════════════════════════════════════════════\n');
let grandTotal = 0;
for (const r of results) {
console.log(`${r.title}`);
console.log(` Slug: ${r.slug}`);
console.log(` Category: ${r.category}`);
console.log(` inst_016 (stats): ${r.violations.inst_016}`);
console.log(` inst_017 (assurance): ${r.violations.inst_017}`);
console.log(` inst_018 (maturity): ${r.violations.inst_018}`);
console.log(` TOTAL: ${r.total}\n`);
grandTotal += r.total;
}
console.log('═══════════════════════════════════════════════════════════');
console.log(`Documents with violations: ${results.length}/${PUBLIC_SLUGS.length}`);
console.log(`Total violations: ${grandTotal}\n`);
await client.close();
}
run().catch(console.error);