feat(quality): add document quality audit and resequencing scripts

- audit-inflection-point.js: Identify fictional content in research paper
- fix-inflection-point-fiction.js: Remove fabricated statistics
- audit-all-card-sequences.js: Check card sequence quality
- audit-card-category-sequences.js: Analyze pedagogical flow
- resequence-cards-pedagogically.js: Reorder cards for better learning flow
- apply-production-fixes.js: Production deployment script
- inspect-*: Helper scripts for analysis

Quality improvements:
- Removed fictional content from Inflection Point document (3 sections)
- Resequenced 21 documents pedagogically (22-67% jumpiness reduction)
- Implemented proper learning flow: concepts → warnings → technical → reference
This commit is contained in:
TheFlow 2025-10-25 22:40:36 +13:00
parent a78809a91f
commit 043d14a499
8 changed files with 1000 additions and 0 deletions

View file

@ -0,0 +1,184 @@
/**
* Apply all content fixes to production database
* 1. Remove fictional content from Inflection Point document
* 2. Resequence cards pedagogically in all documents
*/
const { MongoClient } = require('mongodb');
require('dotenv').config({ path: '/var/www/tractatus/.env' });
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017';
const DB_NAME = process.env.MONGODB_DB || 'tractatus_prod';
// Pedagogical ordering strategies
const ORDERING_STRATEGIES = {
'getting-started': ['conceptual', 'critical', 'practical', 'technical', 'reference'],
'research-theory': ['critical', 'conceptual', 'technical', 'practical', 'reference'],
'technical-reference': ['conceptual', 'technical', 'practical', 'critical', 'reference'],
'advanced-topics': ['critical', 'conceptual', 'technical', 'practical', 'reference'],
'business-leadership': ['conceptual', 'critical', 'practical', 'technical', 'reference']
};
function resequenceSections(sections, strategy) {
if (!sections || sections.length === 0) return sections;
const order = ORDERING_STRATEGIES[strategy] || ORDERING_STRATEGIES['getting-started'];
const priorityMap = {};
order.forEach((category, idx) => {
priorityMap[category] = idx;
});
const resequenced = [...sections].sort((a, b) => {
const priorityA = priorityMap[a.category] ?? 999;
const priorityB = priorityMap[b.category] ?? 999;
if (priorityA !== priorityB) {
return priorityA - priorityB;
}
return a.number - b.number;
});
resequenced.forEach((section, idx) => {
section.number = idx + 1;
});
return resequenced;
}
async function run() {
const client = new MongoClient(MONGODB_URI);
await client.connect();
const db = client.db(DB_NAME);
const collection = db.collection('documents');
console.log('═══════════════════════════════════════════════════════════');
console.log(' APPLYING PRODUCTION FIXES');
console.log('═══════════════════════════════════════════════════════════\n');
console.log(`Database: ${DB_NAME}`);
console.log(`URI: ${MONGODB_URI}\n`);
// Fix 1: Remove fictional content from Inflection Point document
console.log('\n📝 FIX 1: Inflection Point - Remove Fictional Content\n');
const inflectionDoc = await collection.findOne({ slug: 'executive-summary-tractatus-inflection-point' });
if (inflectionDoc && inflectionDoc.sections) {
const sectionsToRemove = [];
// Fix section 1: Remove "six months of production deployment"
const section1 = inflectionDoc.sections.find(s => s.title === 'The Key Finding');
if (section1) {
section1.excerpt = section1.excerpt
.replace(/After six months of production deployment,?\s*/i, '')
.replace(/we've reached/i, 'We\'ve identified')
.replace(/We've reached/i, 'We\'ve identified');
section1.content_html = section1.content_html
.replace(/After six months of production deployment,?\s*/i, '')
.replace(/we've reached/i, 'we\'ve identified')
.replace(/We've reached/i, 'We\'ve identified');
console.log(' ✓ Fixed: "The Key Finding" - removed fictional deployment claim');
}
// Remove section 2: "The Numbers That Matter"
const section2Idx = inflectionDoc.sections.findIndex(s => s.title === 'The Numbers That Matter');
if (section2Idx >= 0) {
sectionsToRemove.push(section2Idx);
console.log(' ✓ Removed: "The Numbers That Matter" - fabricated statistics table');
}
// Remove section 7: "Evidence That Matters: The Test That Changed Everything"
const section7Idx = inflectionDoc.sections.findIndex(s => s.title === 'Evidence That Matters: The Test That Changed Everything');
if (section7Idx >= 0) {
sectionsToRemove.push(section7Idx);
console.log(' ✓ Removed: "Evidence That Matters" - fabricated test results');
}
// Remove sections in reverse order
sectionsToRemove.sort((a, b) => b - a).forEach(idx => {
inflectionDoc.sections.splice(idx, 1);
});
// Renumber
inflectionDoc.sections.forEach((section, idx) => {
section.number = idx + 1;
});
await collection.updateOne(
{ slug: 'executive-summary-tractatus-inflection-point' },
{
$set: {
sections: inflectionDoc.sections,
updated_at: new Date()
}
}
);
console.log(`\n ✅ Inflection Point fixed: ${inflectionDoc.sections.length} sections remaining\n`);
} else {
console.log(' ⚠️ Inflection Point document not found\n');
}
// Fix 2: Resequence all documents pedagogically
console.log('\n📝 FIX 2: Resequence Cards Pedagogically\n');
const PUBLIC_SLUGS = [
'introduction', 'core-concepts', 'executive-summary-tractatus-inflection-point',
'implementation-guide-v1.1', 'implementation-guide', 'implementation-guide-python-examples',
'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-architecture', 'api-reference-complete', 'api-javascript-examples',
'api-python-examples', 'openapi-specification',
'value-pluralism-faq', 'tractatus-ai-safety-framework-core-values-and-principles',
'organizational-theory-foundations', 'business-case-tractatus-framework'
];
let resequencedCount = 0;
for (const slug of PUBLIC_SLUGS) {
const doc = await collection.findOne({ slug });
if (!doc || !doc.sections || doc.sections.length === 0) {
continue;
}
const strategy = doc.category || 'getting-started';
const resequencedSections = resequenceSections([...doc.sections], strategy);
await collection.updateOne(
{ slug },
{
$set: {
sections: resequencedSections,
updated_at: new Date()
}
}
);
resequencedCount++;
console.log(` ✓ Resequenced: ${doc.title}`);
}
console.log(`\n ✅ Resequenced ${resequencedCount} documents\n`);
console.log('═══════════════════════════════════════════════════════════');
console.log(' PRODUCTION FIXES COMPLETE');
console.log('═══════════════════════════════════════════════════════════\n');
console.log('Summary:');
console.log(' • Removed fictional content from Inflection Point');
console.log(` • Resequenced ${resequencedCount} documents pedagogically`);
console.log('');
await client.close();
}
run().catch(console.error);

View file

@ -0,0 +1,133 @@
/**
* Audit card sequences for ALL public documents
* Identify poor/dumb sequences
*/
const { MongoClient } = require('mongodb');
const PUBLIC_SLUGS = [
'introduction', 'core-concepts', 'executive-summary-tractatus-inflection-point',
'implementation-guide-v1.1', 'implementation-guide', 'implementation-guide-python-examples',
'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-architecture', 'api-reference-complete', 'api-javascript-examples',
'api-python-examples', 'openapi-specification',
'value-pluralism-faq', 'tractatus-ai-safety-framework-core-values-and-principles',
'organizational-theory-foundations', 'business-case-tractatus-framework'
];
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('═══════════════════════════════════════════════════════════');
console.log(' CARD SEQUENCE AUDIT - ALL PUBLIC DOCUMENTS');
console.log('═══════════════════════════════════════════════════════════\n');
const issues = [];
for (const slug of PUBLIC_SLUGS) {
const doc = await collection.findOne({ slug });
if (!doc) {
console.log(`⚠️ NOT FOUND: ${slug}\n`);
continue;
}
console.log(`\n📄 ${doc.title}`);
console.log(` Slug: ${slug}`);
console.log(` Category: ${doc.category || 'none'}`);
if (!doc.sections || doc.sections.length === 0) {
console.log(` ❌ NO CARDS - Document has no sections!`);
issues.push({ slug, issue: 'No cards/sections' });
continue;
}
console.log(` Cards: ${doc.sections.length}`);
// Check card sequence quality
const cardIssues = [];
// Check for duplicate numbers
const numbers = doc.sections.map(s => s.number);
const duplicates = numbers.filter((n, i) => numbers.indexOf(n) !== i);
if (duplicates.length > 0) {
cardIssues.push(`Duplicate card numbers: ${duplicates.join(', ')}`);
}
// Check for missing numbers (gaps)
const maxNum = Math.max(...numbers);
for (let i = 1; i <= maxNum; i++) {
if (!numbers.includes(i)) {
cardIssues.push(`Missing card number: ${i}`);
}
}
// Check for poor titles
doc.sections.forEach((section, idx) => {
if (!section.title || section.title.length < 3) {
cardIssues.push(`Card ${section.number}: Title too short/empty`);
}
if (section.title.length > 100) {
cardIssues.push(`Card ${section.number}: Title too long (${section.title.length} chars)`);
}
// Check for generic/dumb titles
const dumbTitles = ['Section', 'Part', 'Chapter', 'Introduction', 'Overview', 'Summary'];
if (dumbTitles.some(dt => section.title === dt)) {
cardIssues.push(`Card ${section.number}: Generic title "${section.title}"`);
}
// Check for empty content
if (!section.content_html || section.content_html.trim().length < 10) {
cardIssues.push(`Card ${section.number}: Empty or minimal content`);
}
// Check category validity
const validCategories = ['conceptual', 'technical', 'critical', 'practical', 'reference'];
if (!validCategories.includes(section.category)) {
cardIssues.push(`Card ${section.number}: Invalid category "${section.category}"`);
}
});
if (cardIssues.length > 0) {
console.log(` ⚠️ ISSUES:`);
cardIssues.forEach(issue => console.log(` - ${issue}`));
issues.push({ slug, issues: cardIssues });
} else {
console.log(` ✅ Card sequence looks good`);
}
}
console.log('\n\n═══════════════════════════════════════════════════════════');
console.log(' SUMMARY');
console.log('═══════════════════════════════════════════════════════════\n');
console.log(`Documents audited: ${PUBLIC_SLUGS.length}`);
console.log(`Documents with issues: ${issues.length}\n`);
if (issues.length > 0) {
console.log('Issues found:\n');
issues.forEach(item => {
console.log(`${item.slug}:`);
if (item.issue) {
console.log(` - ${item.issue}`);
} else {
item.issues.forEach(issue => console.log(` - ${issue}`));
}
console.log('');
});
}
await client.close();
}
run().catch(console.error);

View file

@ -0,0 +1,167 @@
/**
* Audit card category sequences across all public documents
* Show pedagogical flow issues
*/
const { MongoClient } = require('mongodb');
const PUBLIC_SLUGS = [
'introduction', 'core-concepts', 'executive-summary-tractatus-inflection-point',
'implementation-guide-v1.1', 'implementation-guide', 'implementation-guide-python-examples',
'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-architecture', 'api-reference-complete', 'api-javascript-examples',
'api-python-examples', 'openapi-specification',
'value-pluralism-faq', 'tractatus-ai-safety-framework-core-values-and-principles',
'organizational-theory-foundations', 'business-case-tractatus-framework'
];
const CATEGORY_ICONS = {
'conceptual': '📘',
'technical': '🔧',
'practical': '💡',
'reference': '📋',
'critical': '⚠️'
};
function analyzeSequence(sections) {
if (!sections || sections.length === 0) return null;
const sequence = sections.map(s => s.category);
const categoryChanges = [];
for (let i = 1; i < sequence.length; i++) {
if (sequence[i] !== sequence[i-1]) {
categoryChanges.push(i);
}
}
// Calculate "jumpiness" - how often categories change
const jumpiness = categoryChanges.length / (sections.length - 1);
// Identify poor patterns
const issues = [];
// Issue 1: Critical/warning at the end (should be near start)
const criticalIndices = sequence.map((cat, idx) => cat === 'critical' ? idx : -1).filter(i => i >= 0);
if (criticalIndices.some(idx => idx > sequence.length * 0.7)) {
issues.push('Critical content appears late in sequence');
}
// Issue 2: Reference at the beginning (should be at end)
const referenceIndices = sequence.map((cat, idx) => cat === 'reference' ? idx : -1).filter(i => i >= 0);
if (referenceIndices.some(idx => idx < sequence.length * 0.3)) {
issues.push('Reference content appears early (should be at end)');
}
// Issue 3: Technical before conceptual (usually bad pedagogy)
for (let i = 0; i < sequence.length - 1; i++) {
if (sequence[i] === 'technical' && i < 2) {
issues.push('Technical content appears before conceptual foundation');
break;
}
}
// Issue 4: High jumpiness (categories bouncing around)
if (jumpiness > 0.6) {
issues.push(`High category jumpiness (${Math.round(jumpiness * 100)}%) - cards bounce between types`);
}
return {
sequence,
categoryChanges: categoryChanges.length,
jumpiness: Math.round(jumpiness * 100),
issues
};
}
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('═══════════════════════════════════════════════════════════');
console.log(' CARD CATEGORY SEQUENCE AUDIT');
console.log('═══════════════════════════════════════════════════════════\n');
const poorSequences = [];
for (const slug of PUBLIC_SLUGS) {
const doc = await collection.findOne({ slug });
if (!doc || !doc.sections) continue;
console.log(`\n📄 ${doc.title}`);
console.log(` Slug: ${slug}`);
console.log(` Category: ${doc.category || 'none'}`);
console.log(` Cards: ${doc.sections.length}`);
const analysis = analyzeSequence(doc.sections);
if (!analysis) {
console.log(' ❌ No sections to analyze');
continue;
}
// Show category sequence visually
console.log(`\n Sequence:`);
const sequenceDisplay = analysis.sequence.map((cat, idx) => {
const icon = CATEGORY_ICONS[cat] || '❓';
return `${icon} ${cat}`;
}).join(' → ');
// Wrap long sequences
const parts = [];
let currentPart = '';
analysis.sequence.forEach((cat, idx) => {
const icon = CATEGORY_ICONS[cat] || '❓';
const item = `${icon}`;
if (currentPart.length + item.length > 50) {
parts.push(currentPart);
currentPart = ' ';
}
currentPart += item + ' ';
});
if (currentPart.trim()) parts.push(currentPart);
parts.forEach(part => console.log(part));
console.log(`\n Metrics:`);
console.log(` - Category changes: ${analysis.categoryChanges}`);
console.log(` - Jumpiness: ${analysis.jumpiness}%`);
if (analysis.issues.length > 0) {
console.log(`\n ⚠️ ISSUES:`);
analysis.issues.forEach(issue => console.log(` - ${issue}`));
poorSequences.push({ slug, doc: doc.title, issues: analysis.issues });
} else {
console.log(`\n ✅ Sequence looks reasonable`);
}
}
console.log('\n\n═══════════════════════════════════════════════════════════');
console.log(' SUMMARY');
console.log('═══════════════════════════════════════════════════════════\n');
console.log(`Documents audited: ${PUBLIC_SLUGS.length}`);
console.log(`Documents with poor sequences: ${poorSequences.length}\n`);
if (poorSequences.length > 0) {
console.log('Documents needing resequencing:\n');
poorSequences.forEach((item, idx) => {
console.log(`${idx + 1}. ${item.doc}`);
console.log(` Slug: ${item.slug}`);
item.issues.forEach(issue => console.log(` - ${issue}`));
console.log('');
});
}
await client.close();
}
run().catch(console.error);

View file

@ -0,0 +1,67 @@
/**
* Audit and fix the Inflection Point document
* Remove fictional statistics and claims
*/
const { MongoClient } = require('mongodb');
async function run() {
const client = new MongoClient('mongodb://localhost:27017');
await client.connect();
const db = client.db('tractatus_dev');
const collection = db.collection('documents');
const doc = await collection.findOne({ slug: 'executive-summary-tractatus-inflection-point' });
if (!doc) {
console.log('Document not found');
process.exit(1);
}
console.log('═══════════════════════════════════════════════════════════');
console.log(' AUDITING INFLECTION POINT DOCUMENT');
console.log('═══════════════════════════════════════════════════════════\n');
console.log('Title:', doc.title);
console.log('Slug:', doc.slug);
console.log('\nSections found:', doc.sections?.length || 0);
console.log('\n📋 Section Audit:\n');
if (doc.sections) {
doc.sections.forEach((section, idx) => {
console.log(`${idx + 1}. "${section.title}" (${section.category})`);
// Check for fictional content
const text = section.content_html + section.excerpt;
const issues = [];
if (/\d+%/.test(text) && !/\[NEEDS VERIFICATION\]/.test(text)) {
issues.push('Contains unverified statistics');
}
if (/Year 1|Timeline:|Months \d/.test(text)) {
issues.push('Contains fictional roadmap/timeline');
}
if (/reduction|target|metric|success/i.test(text) && /\d+%/.test(text)) {
issues.push('Contains fabricated performance metrics');
}
if (issues.length > 0) {
console.log(` ⚠️ ISSUES: ${issues.join(', ')}`);
}
});
}
console.log('\n📊 Fictional Content to Remove:\n');
console.log('1. Section "The Numbers That Matter" - Contains fabricated statistics');
console.log('2. "Value Proposition for Anthropic" section - Fictional business claims');
console.log('3. "Implementation Roadmap" - Completely fabricated timeline');
console.log('4. Performance metrics (95%, 100%, <10ms) - All unverified');
console.log('5. Market statistics (50%, 60%, 35%) - Fabricated numbers');
await client.close();
}
run().catch(console.error);

View file

@ -0,0 +1,127 @@
/**
* Remove fictional content from Inflection Point document
* Fix inst_016/017/018 violations while preserving conceptual value
*/
const { MongoClient } = require('mongodb');
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('═══════════════════════════════════════════════════════════');
console.log(' FIXING INFLECTION POINT DOCUMENT');
console.log('═══════════════════════════════════════════════════════════\n');
const doc = await collection.findOne({ slug: 'executive-summary-tractatus-inflection-point' });
if (!doc) {
console.log('❌ Document not found');
process.exit(1);
}
console.log(`📄 Document: ${doc.title}`);
console.log(` Sections: ${doc.sections?.length || 0}\n`);
if (!doc.sections) {
console.log('❌ No sections found');
process.exit(1);
}
const updates = [];
const sectionsToRemove = [];
// Section 1: "The Key Finding" - Fix fictional "six months of production deployment"
const section1 = doc.sections.find(s => s.title === 'The Key Finding');
if (section1) {
console.log('🔧 Section 1: Fixing fictional production deployment claim...');
// Remove the "six months of production deployment" fiction
let cleanedExcerpt = section1.excerpt
.replace(/After six months of production deployment,?\s*/i, '')
.replace(/we've reached/i, 'We\'ve identified')
.replace(/We've reached/i, 'We\'ve identified');
let cleanedHtml = section1.content_html
.replace(/After six months of production deployment,?\s*/i, '')
.replace(/we've reached/i, 'we\'ve identified')
.replace(/We've reached/i, 'We\'ve identified');
updates.push({
section: section1,
field: 'excerpt + content_html',
oldValue: 'Removed "six months of production deployment" fiction',
newValue: 'Changed to "identified" instead of "reached after deployment"'
});
section1.excerpt = cleanedExcerpt;
section1.content_html = cleanedHtml;
}
// Section 2: "The Numbers That Matter" - REMOVE ENTIRELY (fabricated comparison table)
const section2Idx = doc.sections.findIndex(s => s.title === 'The Numbers That Matter');
if (section2Idx >= 0) {
console.log('🗑️ Section 2: Removing fabricated statistics table entirely...');
updates.push({
section: doc.sections[section2Idx],
field: 'REMOVED',
oldValue: 'The Numbers That Matter - fabricated comparison table',
newValue: 'Section removed - contained fictional performance metrics'
});
sectionsToRemove.push(section2Idx);
}
// Section 7: "Evidence That Matters: The Test That Changed Everything" - REMOVE ENTIRELY
const section7Idx = doc.sections.findIndex(s => s.title === 'Evidence That Matters: The Test That Changed Everything');
if (section7Idx >= 0) {
console.log('🗑️ Section 7: Removing fabricated test evidence...');
updates.push({
section: doc.sections[section7Idx],
field: 'REMOVED',
oldValue: 'Evidence That Matters - fabricated test results',
newValue: 'Section removed - contained fictional metrics'
});
sectionsToRemove.push(section7Idx);
}
// Remove sections in reverse order to avoid index shifting issues
sectionsToRemove.sort((a, b) => b - a).forEach(idx => {
doc.sections.splice(idx, 1);
});
// Renumber sections after removals
doc.sections.forEach((section, idx) => {
section.number = idx + 1;
});
// Update the document
const result = await collection.updateOne(
{ slug: 'executive-summary-tractatus-inflection-point' },
{
$set: {
sections: doc.sections,
updated_at: new Date()
}
}
);
console.log('\n═══════════════════════════════════════════════════════════');
console.log(' CLEANUP SUMMARY');
console.log('═══════════════════════════════════════════════════════════\n');
console.log(`Changes made: ${updates.length}`);
updates.forEach((update, idx) => {
console.log(`\n${idx + 1}. ${update.section.title || 'Section'}`);
console.log(` Field: ${update.field}`);
console.log(` ${update.oldValue}`);
});
console.log(`\n✅ Document updated: ${result.modifiedCount} document(s)`);
console.log(`📊 Final section count: ${doc.sections.length}\n`);
await client.close();
}
run().catch(console.error);

View file

@ -0,0 +1,55 @@
/**
* Inspect Inflection Point document sections
*/
const { MongoClient } = require('mongodb');
async function run() {
const client = new MongoClient('mongodb://localhost:27017');
await client.connect();
const db = client.db('tractatus_dev');
const collection = db.collection('documents');
const doc = await collection.findOne({ slug: 'executive-summary-tractatus-inflection-point' });
if (!doc) {
console.log('Document not found');
process.exit(1);
}
console.log('═══════════════════════════════════════════════════════════');
console.log(' INFLECTION POINT SECTIONS');
console.log('═══════════════════════════════════════════════════════════\n');
console.log(`Title: ${doc.title}`);
console.log(`Sections: ${doc.sections?.length || 0}\n`);
if (doc.sections) {
doc.sections.forEach((section, idx) => {
console.log(`${section.number}. "${section.title}"`);
console.log(` Category: ${section.category}`);
console.log(` Reading time: ${section.readingTime}`);
console.log(` Excerpt: ${section.excerpt.substring(0, 80)}...`);
// Check for fictional content markers
const text = section.content_html + section.excerpt;
const hasStats = /\d+%/.test(text);
const hasTimeline = /Year 1|Timeline:|Months \d|Phase \d/i.test(text);
const hasMetrics = /reduction|target|metric|success/i.test(text) && hasStats;
if (hasStats || hasTimeline || hasMetrics) {
console.log(` ⚠️ Contains:`, [
hasStats && 'Statistics',
hasTimeline && 'Timeline',
hasMetrics && 'Performance metrics'
].filter(Boolean).join(', '));
}
console.log('');
});
}
await client.close();
}
run().catch(console.error);

View file

@ -0,0 +1,57 @@
/**
* Inspect the "Overview" cards to understand their content
* so we can create better titles
*/
const { MongoClient } = require('mongodb');
const DOCS_WITH_OVERVIEW = ['core-concepts', 'implementation-guide-v1.1', 'technical-architecture'];
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('═══════════════════════════════════════════════════════════');
console.log(' INSPECTING OVERVIEW CARDS');
console.log('═══════════════════════════════════════════════════════════\n');
for (const slug of DOCS_WITH_OVERVIEW) {
const doc = await collection.findOne({ slug });
if (!doc) {
console.log(`⚠️ NOT FOUND: ${slug}\n`);
continue;
}
console.log(`\n📄 ${doc.title}`);
console.log(` Slug: ${slug}`);
const overviewCard = doc.sections?.find(s => s.title === 'Overview');
if (overviewCard) {
console.log(`\n Card #${overviewCard.number}: "${overviewCard.title}"`);
console.log(` Category: ${overviewCard.category}`);
console.log(`\n Excerpt:`);
console.log(` ${overviewCard.excerpt}\n`);
console.log(` Content preview (first 300 chars):`);
const textContent = overviewCard.content_html
.replace(/<[^>]+>/g, ' ')
.replace(/\s+/g, ' ')
.trim();
console.log(` ${textContent.substring(0, 300)}...\n`);
console.log(` Full content length: ${overviewCard.content_html.length} chars\n`);
} else {
console.log(` ❌ No "Overview" card found!\n`);
}
console.log(' ---');
}
await client.close();
}
run().catch(console.error);

View file

@ -0,0 +1,210 @@
/**
* Resequence cards in documents for better pedagogical flow
*
* Pedagogical principles:
* 1. Conceptual foundation FIRST (context setting)
* 2. Critical constraints EARLY (understand boundaries)
* 3. Technical details MIDDLE (implementation)
* 4. Practical examples LATE (application)
* 5. Reference material LAST (lookup info)
*/
const { MongoClient } = require('mongodb');
// Define pedagogical ordering by document category
const ORDERING_STRATEGIES = {
'getting-started': {
name: 'Introduction/Tutorial Flow',
order: ['conceptual', 'critical', 'practical', 'technical', 'reference'],
description: 'Start with concepts, warn early, show examples, then technical details'
},
'research-theory': {
name: 'Research Paper Flow',
order: ['critical', 'conceptual', 'technical', 'practical', 'reference'],
description: 'Problem first, theory second, analysis third'
},
'technical-reference': {
name: 'Technical Documentation Flow',
order: ['conceptual', 'technical', 'practical', 'critical', 'reference'],
description: 'Overview, details, examples, edge cases, reference'
},
'advanced-topics': {
name: 'Advanced Concepts Flow',
order: ['critical', 'conceptual', 'technical', 'practical', 'reference'],
description: 'Warnings first, theory, implementation, applications'
},
'business-leadership': {
name: 'Business Case Flow',
order: ['conceptual', 'critical', 'practical', 'technical', 'reference'],
description: 'Vision, constraints, use cases, implementation, details'
}
};
/**
* Resequence sections for better pedagogical flow
*/
function resequenceSections(sections, strategy) {
if (!sections || sections.length === 0) return sections;
const order = ORDERING_STRATEGIES[strategy]?.order || ORDERING_STRATEGIES['getting-started'].order;
// Create priority map
const priorityMap = {};
order.forEach((category, idx) => {
priorityMap[category] = idx;
});
// Sort by category priority, then by original order within category
const resequenced = [...sections].sort((a, b) => {
const priorityA = priorityMap[a.category] ?? 999;
const priorityB = priorityMap[b.category] ?? 999;
if (priorityA !== priorityB) {
return priorityA - priorityB;
}
// Within same category, maintain original order
return a.number - b.number;
});
// Renumber
resequenced.forEach((section, idx) => {
section.number = idx + 1;
});
return resequenced;
}
/**
* Analyze sequence improvement
*/
function analyzeImprovement(originalSections, resequencedSections) {
const originalSeq = originalSections.map(s => s.category);
const resequencedSeq = resequencedSections.map(s => s.category);
// Calculate jumpiness
const calculateJumpiness = (seq) => {
let changes = 0;
for (let i = 1; i < seq.length; i++) {
if (seq[i] !== seq[i-1]) changes++;
}
return Math.round((changes / (seq.length - 1)) * 100);
};
const originalJumpiness = calculateJumpiness(originalSeq);
const resequencedJumpiness = calculateJumpiness(resequencedSeq);
return {
originalJumpiness,
resequencedJumpiness,
improvement: originalJumpiness - resequencedJumpiness,
originalSeq,
resequencedSeq
};
}
async function run() {
const args = process.argv.slice(2);
const dryRun = !args.includes('--apply');
const client = new MongoClient('mongodb://localhost:27017');
await client.connect();
const db = client.db('tractatus_dev');
const collection = db.collection('documents');
console.log('═══════════════════════════════════════════════════════════');
console.log(' RESEQUENCING CARDS FOR PEDAGOGICAL FLOW');
console.log('═══════════════════════════════════════════════════════════\n');
if (dryRun) {
console.log('🔍 DRY RUN MODE - No changes will be saved');
console.log(' Add --apply to commit changes\n');
} else {
console.log('✍️ APPLY MODE - Changes will be saved to database\n');
}
const PUBLIC_SLUGS = [
'introduction', 'core-concepts', 'executive-summary-tractatus-inflection-point',
'implementation-guide-v1.1', 'implementation-guide', 'implementation-guide-python-examples',
'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-architecture', 'api-reference-complete', 'api-javascript-examples',
'api-python-examples', 'openapi-specification',
'value-pluralism-faq', 'tractatus-ai-safety-framework-core-values-and-principles',
'organizational-theory-foundations', 'business-case-tractatus-framework'
];
let updatedCount = 0;
let improvedCount = 0;
for (const slug of PUBLIC_SLUGS) {
const doc = await collection.findOne({ slug });
if (!doc || !doc.sections || doc.sections.length === 0) {
continue;
}
const strategy = doc.category || 'getting-started';
const strategyInfo = ORDERING_STRATEGIES[strategy] || ORDERING_STRATEGIES['getting-started'];
console.log(`\n📄 ${doc.title}`);
console.log(` Strategy: ${strategyInfo.name}`);
console.log(` ${strategyInfo.description}`);
const originalSections = [...doc.sections];
const resequencedSections = resequenceSections(doc.sections, strategy);
const analysis = analyzeImprovement(originalSections, resequencedSections);
console.log(`\n Original sequence:`);
const ICONS = { conceptual: '📘', technical: '🔧', practical: '💡', reference: '📋', critical: '⚠️' };
console.log(` ${analysis.originalSeq.map(c => ICONS[c] || '❓').join(' ')}`);
console.log(` Jumpiness: ${analysis.originalJumpiness}%`);
console.log(`\n Resequenced:`);
console.log(` ${analysis.resequencedSeq.map(c => ICONS[c] || '❓').join(' ')}`);
console.log(` Jumpiness: ${analysis.resequencedJumpiness}%`);
if (analysis.improvement > 0) {
console.log(`\n ✅ Improvement: ${analysis.improvement}% reduction in jumpiness`);
improvedCount++;
if (!dryRun) {
await collection.updateOne(
{ slug },
{
$set: {
sections: resequencedSections,
updated_at: new Date()
}
}
);
console.log(` 💾 Saved to database`);
updatedCount++;
}
} else {
console.log(`\n No significant improvement needed`);
}
}
console.log('\n\n═══════════════════════════════════════════════════════════');
console.log(' SUMMARY');
console.log('═══════════════════════════════════════════════════════════\n');
console.log(`Documents analyzed: ${PUBLIC_SLUGS.length}`);
console.log(`Documents improved: ${improvedCount}`);
if (dryRun) {
console.log(`\n💡 Run with --apply to save changes`);
} else {
console.log(`\n✅ Documents updated: ${updatedCount}`);
}
await client.close();
}
run().catch(console.error);