tractatus/scripts/seed-architectural-safeguards-document.js
TheFlow 2af47035ac refactor: remove website code and fix critical startup crashes (Phase 8)
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>
2025-10-21 22:17:02 +13:00

124 lines
4.1 KiB
JavaScript

#!/usr/bin/env node
/**
* Seed Script: Add Architectural Safeguards Document to Database
* Adds both MD and PDF versions of the Architectural Safeguards Against LLM Hierarchical Dominance document
*/
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');
async function seedDocument() {
try {
console.log('\n=== Seeding Architectural Safeguards Document ===\n');
// Connect to database
await connect();
// Read the prose markdown file
const mdPath = path.join(__dirname, '..', 'docs', 'research', 'ARCHITECTURAL-SAFEGUARDS-Against-LLM-Hierarchical-Dominance-Prose.md');
const rawContent = await fs.readFile(mdPath, 'utf-8');
console.log('✓ Read markdown file');
// Convert to HTML
const htmlContent = markdownToHtml(rawContent);
// Extract table of contents
const tableOfContents = extractTOC(rawContent);
console.log('✓ Converted to HTML and extracted TOC');
// Generate slug
const slug = 'architectural-safeguards-against-llm-hierarchical-dominance-prose';
// Check if document already exists
const existing = await Document.findBySlug(slug);
if (existing) {
console.log(`\n⚠️ Document already exists with slug: ${slug}`);
console.log(' Delete it first or use a different slug.');
await close();
process.exit(0);
}
// Create document object
const doc = {
title: 'Architectural Safeguards Against LLM Hierarchical Dominance',
slug: slug,
quadrant: null, // Research document, not bound to specific quadrant
persistence: 'HIGH',
audience: 'leader', // Target audience: leaders, decision-makers
visibility: 'public',
category: 'research-theory', // Research and theory category
order: 10, // Higher priority (lower number = higher priority in display)
content_html: htmlContent,
content_markdown: rawContent,
toc: tableOfContents,
security_classification: {
contains_credentials: false,
contains_financial_info: false,
contains_vulnerability_info: false,
contains_infrastructure_details: false,
requires_authentication: false
},
metadata: {
author: 'Agentic Governance Research Team',
version: '1.0',
document_code: null,
related_documents: [
'executive-summary-pluralistic-deliberation-in-tractatus',
'phase-1-implementation-tickets',
'research-paper-outline-pluralistic-deliberation'
],
tags: [
'ai-safety',
'llm-governance',
'value-pluralism',
'deliberative-ai',
'hierarchical-dominance',
'pluralistic-deliberation',
'research'
]
},
translations: {},
search_index: rawContent.toLowerCase(),
download_formats: {
pdf: '/docs/research/ARCHITECTURAL-SAFEGUARDS-Against-LLM-Hierarchical-Dominance-Prose.pdf',
markdown: '/docs/research/ARCHITECTURAL-SAFEGUARDS-Against-LLM-Hierarchical-Dominance-Prose.md'
}
};
// Create document
const createdDoc = await Document.create(doc);
console.log('\n✓ Document created successfully!');
console.log(` Title: ${createdDoc.title}`);
console.log(` Slug: ${createdDoc.slug}`);
console.log(` Category: ${createdDoc.category}`);
console.log(` Audience: ${createdDoc.audience}`);
console.log(` PDF: ${doc.download_formats.pdf}`);
console.log(` Markdown: ${doc.download_formats.markdown}`);
console.log('\n✓ Document is now available at:');
console.log(` https://agenticgovernance.digital/docs.html?doc=${slug}`);
await close();
} catch (error) {
console.error('\n✗ Error seeding document:', error.message);
console.error(error.stack);
process.exit(1);
}
}
// Run if called directly
if (require.main === module) {
seedDocument();
}
module.exports = seedDocument;