#!/usr/bin/env node /** * Add Card View Sections to 17 Documents * * Adds card view sections to: * - 5 newly imported archives * - 12 existing documents without sections */ require('dotenv').config(); const fs = require('fs'); const path = require('path'); const { connect, close } = require('../src/utils/db.util'); const Document = require('../src/models/Document.model'); const { processMarkdownFile } = require('./generate-card-sections.js'); const DOCS_TO_PROCESS = [ // 5 newly imported archives { slug: 'case-studies-real-world-llm-failure-modes-appendix', mdPath: 'docs/markdown/case-studies.md' }, { slug: 'implementation-guide-python-examples', mdPath: 'docs/api/examples-python.md' }, { slug: 'tractatus-framework-enforcement-claude-code', mdPath: 'docs/claude-code-framework-enforcement.md' }, { slug: 'research-topic-concurrent-session-architecture', mdPath: 'docs/research/concurrent-session-architecture-limitations.md' }, { slug: 'research-topic-rule-proliferation-transactional-overhead', mdPath: 'docs/research/rule-proliferation-and-transactional-overhead.md' }, // 5 technical reference docs without sections { slug: 'implementation-roadmap-24-month-deployment-plan', mdPath: 'docs/markdown/implementation-roadmap-24-month-deployment-plan.md' }, { slug: 'api-reference-complete', mdPath: 'docs/markdown/api-reference-complete.md' }, { slug: 'api-javascript-examples', mdPath: 'docs/api/examples-javascript.md' }, { slug: 'api-python-examples', mdPath: 'docs/api/examples-python.md' }, { slug: 'openapi-specification', mdPath: 'docs/markdown/openapi-specification.md' }, // 5 case studies without sections { slug: 'the-27027-incident-a-case-study-in-pattern-recognition-bias', mdPath: 'docs/case-studies/27027-incident-detailed-analysis.md' }, { slug: 'when-frameworks-fail-and-why-thats-ok', mdPath: 'docs/case-studies/when-frameworks-fail-oct-2025.md' }, { slug: 'our-framework-in-action-detecting-and-correcting-ai-fabrications', mdPath: 'docs/case-studies/framework-in-action-oct-2025.md' }, { slug: 'real-world-ai-governance-a-case-study-in-framework-failure-and-recovery', mdPath: 'docs/case-studies/real-world-governance-case-study-oct-2025.md' }, { slug: 'case-studies-real-world-llm-failure-modes', mdPath: 'docs/markdown/case-studies.md' }, // 2 Phase 5 PoC summaries { slug: 'phase-5-poc-session-1-summary', mdPath: 'docs/markdown/phase-5-session1-summary.md' }, { slug: 'phase-5-poc-session-2-summary', mdPath: 'docs/markdown/phase-5-session2-summary.md' } ]; async function addSectionsToDocument(docInfo) { console.log(`\nšŸ“„ Processing: ${docInfo.slug}`); try { // Check if document exists const doc = await Document.findBySlug(docInfo.slug); if (!doc) { console.log(` āŒ Document not found in database`); return { success: false, reason: 'not_found' }; } // Check if already has sections if (doc.sections && doc.sections.length > 0) { console.log(` ā­ļø Already has ${doc.sections.length} sections, skipping`); return { success: false, reason: 'has_sections' }; } // Build full path to markdown file const fullPath = path.join('/home/theflow/projects/tractatus', docInfo.mdPath); // Check if markdown file exists if (!fs.existsSync(fullPath)) { console.log(` āŒ Markdown file not found: ${fullPath}`); return { success: false, reason: 'md_not_found' }; } // Generate sections console.log(` šŸ“ Generating sections from: ${docInfo.mdPath}`); const sections = await processMarkdownFile(fullPath); if (!sections || sections.length === 0) { console.log(` āš ļø No sections generated (possibly no H2 headers)`); return { success: false, reason: 'no_sections' }; } // Update document with sections const updated = await Document.update(doc._id.toString(), { sections }); if (!updated) { console.log(` āŒ Failed to update document`); return { success: false, reason: 'update_failed' }; } console.log(` āœ… Added ${sections.length} sections`); return { success: true, sections: sections.length }; } catch (error) { console.error(` āŒ Error: ${error.message}`); return { success: false, error: error.message }; } } async function main() { try { console.log('šŸš€ Adding Card View Sections to 17 Documents\n'); console.log('═══════════════════════════════════════════════════\n'); await connect(); let added = 0; let skipped = 0; let notFound = 0; let failed = 0; for (const docInfo of DOCS_TO_PROCESS) { const result = await addSectionsToDocument(docInfo); if (result.success) { added++; } else if (result.reason === 'has_sections') { skipped++; } else if (result.reason === 'not_found' || result.reason === 'md_not_found') { notFound++; } else { failed++; } } console.log('\n═══════════════════════════════════════════════════'); console.log('\nšŸ“Š Summary:'); console.log(` āœ… Added sections: ${added}`); console.log(` ā­ļø Skipped (already have sections): ${skipped}`); console.log(` āŒ Not found: ${notFound}`); console.log(` āŒ Failed: ${failed}`); console.log(` šŸ“¦ Total processed: ${DOCS_TO_PROCESS.length}`); await close(); } catch (error) { console.error('\nāŒ Fatal error:', error); process.exit(1); } } main();