SUMMARY:
Completed migration from deprecated 'public: true/false' field to modern
'visibility' field across entire codebase. Ensures single source of truth
for document visibility state.
MIGRATION EXECUTION:
✓ Created migration script with dry-run support
✓ Migrated 120 documents in database (removed deprecated field)
✓ Post-migration: 0 documents with 'public' field, 127 with 'visibility'
✓ Zero data loss - all documents already had visibility set correctly
CODE CHANGES:
1. Database Migration (scripts/migrate-public-to-visibility.js):
- Created safe migration with dry-run mode
- Handles documents with both fields (cleanup)
- Post-migration verification built-in
- Execution: node scripts/migrate-public-to-visibility.js --execute
2. Document Model (src/models/Document.model.js):
- Removed 'public' field from create() method
- Updated findByQuadrant() to use visibility: 'public'
- Updated findByAudience() to use visibility: 'public'
- Updated search() to use visibility: 'public'
3. API Controller (src/controllers/documents.controller.js):
- Removed legacy filter: { public: true, visibility: { $exists: false } }
- listDocuments() now uses clean filter: visibility: 'public'
- searchDocuments() now uses clean filter: visibility: 'public'
4. Scripts Updated:
- upload-document.js: Removed public: true
- seed-architectural-safeguards-document.js: Removed public: true
- import-5-archives.js: Removed public: true
- verify-34-documents.js: Updated query filter to use visibility
- query-all-documents.js: Updated query filter to use visibility
VERIFICATION:
✓ 0 remaining 'public: true/false' usages in src/ and scripts/
✓ All documents use visibility field exclusively
✓ API queries now filter on visibility only
✓ Backward compatibility code removed
DATA MODEL:
Before: { public: true, visibility: 'public' } (redundant)
After: { visibility: 'public' } (single source of truth)
BENEFITS:
- Cleaner data model
- Single source of truth for visibility
- Simplified API logic
- Removed backward compatibility overhead
- Consistent with document security model
FRAMEWORK COMPLIANCE:
Addresses SCHEDULED_TASKS.md item "Legacy public Field Migration"
Completes Sprint 2 Medium Priority task
NEXT STEPS (Optional):
- Deploy migration to production
- Monitor for any edge cases
- Consider adding visibility to database indexes
🤖 Generated with Claude Code (https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
124 lines
4.1 KiB
JavaScript
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;
|