CRITICAL FIX: Server would CRASH ON STARTUP (multiple import errors)
REMOVED (2 scripts):
1. scripts/framework-watchdog.js
- Monitored .claude/session-state.json (OUR Claude Code setup)
- Monitored .claude/token-checkpoints.json (OUR file structure)
- Implementers won't have our .claude/ directory
2. scripts/init-db.js
- Created website collections: blog_posts, media_inquiries, case_submissions
- Created website collections: resources, moderation_queue, users, citations
- Created website collections: translations, koha_donations
- Next steps referenced deleted scripts (npm run seed:admin)
REWRITTEN (2 files):
src/models/index.js (29 lines → 27 lines)
- REMOVED imports: Document, BlogPost, MediaInquiry, CaseSubmission, Resource
- REMOVED imports: ModerationQueue, User (all deleted in Phase 2)
- KEPT imports: AuditLog, DeliberationSession, GovernanceLog, GovernanceRule
- KEPT imports: Precedent, Project, SessionState, VariableValue, VerificationLog
- Result: Only framework models exported
src/server.js (284 lines → 163 lines, 43% reduction)
- REMOVED: Imports to deleted middleware (csrf-protection, response-sanitization)
- REMOVED: Stripe webhook handling (/api/koha/webhook)
- REMOVED: Static file caching (for deleted public/ directory)
- REMOVED: Static file serving (public/ deleted in Phase 6)
- REMOVED: CSRF token endpoint
- REMOVED: Website homepage with "auth, documents, blog, admin" references
- REMOVED: Instruction sync (scripts/sync-instructions-to-db.js reference)
- REMOVED: Hardcoded log path (${process.env.HOME}/var/log/tractatus/...)
- REMOVED: Website-specific security middleware
- KEPT: Security headers, rate limiting, CORS, body parsers
- KEPT: API routes, governance services, MongoDB connections
- RESULT: Clean framework-only server
RESULT: Repository can now start without crashes, all imports resolve
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
186 lines
6.2 KiB
JavaScript
186 lines
6.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Import 5 Missing Archives Documents
|
|
*
|
|
* Imports the 5 MD files that are in Archives but not in the database:
|
|
* 1. Case Studies - Real-World LLM Failure Modes
|
|
* 2. Python API Integration Examples
|
|
* 3. Tractatus Framework Enforcement for Claude Code
|
|
* 4. Concurrent Session Architecture Limitations
|
|
* 5. Rule Proliferation and Transactional Overhead
|
|
*/
|
|
|
|
require('dotenv').config();
|
|
|
|
const fs = require('fs').promises;
|
|
const path = require('path');
|
|
const { connect, close } = require('../src/utils/db.util');
|
|
const Document = require('../src/models/Document.model');
|
|
const { markdownToHtml, extractTOC, generateSlug } = require('../src/utils/markdown.util');
|
|
|
|
const FILES_TO_IMPORT = [
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/markdown/case-studies.md',
|
|
slug: 'case-studies-real-world-llm-failure-modes-appendix',
|
|
title: 'Appendix B: Case Studies - Real-World LLM Failure Modes',
|
|
category: 'archives',
|
|
order: 2,
|
|
archiveNote: 'Internal project tracking document. Not relevant for public documentation.'
|
|
},
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/api/examples-python.md',
|
|
slug: 'implementation-guide-python-examples',
|
|
title: 'Implementation Guide: Python Code Examples',
|
|
category: 'archives',
|
|
order: 3,
|
|
archiveNote: 'Internal project tracking document. Not relevant for public documentation.'
|
|
},
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/claude-code-framework-enforcement.md',
|
|
slug: 'tractatus-framework-enforcement-claude-code',
|
|
title: 'Tractatus Framework Enforcement for Claude Code',
|
|
category: 'archives',
|
|
order: 4,
|
|
archiveNote: 'Development tool documentation. See Implementation Guide for production deployment.'
|
|
},
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/research/concurrent-session-architecture-limitations.md',
|
|
slug: 'research-topic-concurrent-session-architecture',
|
|
title: 'Research Topic: Concurrent Session Architecture Limitations in Claude Code Governance',
|
|
category: 'archives',
|
|
order: 5,
|
|
archiveNote: 'Research analysis. See Architectural Overview for current framework status.'
|
|
},
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/research/rule-proliferation-and-transactional-overhead.md',
|
|
slug: 'research-topic-rule-proliferation-transactional-overhead',
|
|
title: 'Research Topic: Rule Proliferation and Transactional Overhead in AI Governance',
|
|
category: 'archives',
|
|
order: 6,
|
|
archiveNote: 'Research analysis. See Architectural Overview for current framework status.'
|
|
}
|
|
];
|
|
|
|
function extractFrontMatter(content) {
|
|
const frontMatterRegex = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
|
|
const match = content.match(frontMatterRegex);
|
|
|
|
if (!match) {
|
|
return { frontMatter: {}, content };
|
|
}
|
|
|
|
const frontMatterText = match[1];
|
|
const remainingContent = match[2];
|
|
|
|
const frontMatter = {};
|
|
frontMatterText.split('\n').forEach(line => {
|
|
const [key, ...valueParts] = line.split(':');
|
|
if (key && valueParts.length > 0) {
|
|
const value = valueParts.join(':').trim();
|
|
frontMatter[key.trim()] = value.replace(/^["']|["']$/g, '');
|
|
}
|
|
});
|
|
|
|
return { frontMatter, content: remainingContent };
|
|
}
|
|
|
|
async function importDocument(fileInfo) {
|
|
console.log(`\n📄 Importing: ${fileInfo.title}`);
|
|
console.log(` File: ${fileInfo.path}`);
|
|
|
|
try {
|
|
// Read markdown file
|
|
const rawContent = await fs.readFile(fileInfo.path, 'utf-8');
|
|
const { frontMatter, content } = extractFrontMatter(rawContent);
|
|
|
|
// Convert to HTML
|
|
const content_html = markdownToHtml(content);
|
|
|
|
// Extract TOC
|
|
const toc = extractTOC(content);
|
|
|
|
// Check if document already exists
|
|
const existing = await Document.findBySlug(fileInfo.slug);
|
|
if (existing) {
|
|
console.log(` ⚠️ Document already exists: ${fileInfo.slug}`);
|
|
console.log(` Skipping import.`);
|
|
return { success: false, reason: 'exists' };
|
|
}
|
|
|
|
// Create document
|
|
const doc = await Document.create({
|
|
title: fileInfo.title,
|
|
slug: fileInfo.slug,
|
|
quadrant: frontMatter.quadrant || null,
|
|
persistence: frontMatter.persistence || 'MEDIUM',
|
|
audience: frontMatter.audience || 'general',
|
|
visibility: 'archived',
|
|
category: fileInfo.category,
|
|
order: fileInfo.order,
|
|
archiveNote: fileInfo.archiveNote,
|
|
content_html,
|
|
content_markdown: content,
|
|
toc,
|
|
metadata: {
|
|
author: frontMatter.author || 'John Stroh',
|
|
version: frontMatter.version || '1.0',
|
|
document_code: frontMatter.identifier || null,
|
|
tags: [],
|
|
original_filename: path.basename(fileInfo.path),
|
|
migrated_at: new Date()
|
|
},
|
|
search_index: content.toLowerCase(),
|
|
translations: {},
|
|
download_formats: {}
|
|
});
|
|
|
|
console.log(` ✅ Imported successfully`);
|
|
console.log(` ID: ${doc._id}`);
|
|
console.log(` Slug: ${doc.slug}`);
|
|
|
|
return { success: true, doc };
|
|
|
|
} catch (error) {
|
|
console.error(` ❌ Error importing: ${error.message}`);
|
|
return { success: false, error: error.message };
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
try {
|
|
console.log('🚀 Importing 5 Missing Archives Documents\n');
|
|
console.log('═══════════════════════════════════════════════════\n');
|
|
|
|
await connect();
|
|
|
|
let imported = 0;
|
|
let skipped = 0;
|
|
let failed = 0;
|
|
|
|
for (const fileInfo of FILES_TO_IMPORT) {
|
|
const result = await importDocument(fileInfo);
|
|
if (result.success) {
|
|
imported++;
|
|
} else if (result.reason === 'exists') {
|
|
skipped++;
|
|
} else {
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
console.log('\n═══════════════════════════════════════════════════');
|
|
console.log('\n📊 Import Summary:');
|
|
console.log(` ✅ Imported: ${imported}`);
|
|
console.log(` ⏭️ Skipped (already exists): ${skipped}`);
|
|
console.log(` ❌ Failed: ${failed}`);
|
|
console.log(` 📦 Total: ${FILES_TO_IMPORT.length}`);
|
|
|
|
await close();
|
|
|
|
} catch (error) {
|
|
console.error('\n❌ Fatal error:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|