Correspondents/scripts/generate-morgan-prompt.js
Nicholai dc9673005b fix: embed Morgan system prompt for Cloudflare deployment
Morgan's system prompt is now generated at build time and embedded directly
in the code, making it available in Cloudflare Worker environments where
file system access isn't available.

Changes:
- Add scripts/generate-morgan-prompt.js to generate TypeScript constant from markdown
- Generate src/lib/agents/morgan-system-prompt.ts with full Fortura Agent Bundle
- Update agent definitions to import and use the embedded constant
- Update package.json build scripts to generate prompt before building
- Remove runtime file system access (readFileSync) that failed on Cloudflare

This ensures Morgan agent has full system prompt capabilities on all deployments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-16 14:32:51 -07:00

44 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Build-time script to generate TypeScript file with Morgan's system prompt
* This embeds the markdown file as a constant for Cloudflare Worker deployment
*/
const fs = require('fs')
const path = require('path')
const sourceFile = path.join(__dirname, '..', '.fortura-core', 'web-agents', 'agent-architect-web.md')
const outputFile = path.join(__dirname, '..', 'src', 'lib', 'agents', 'morgan-system-prompt.ts')
try {
// Read the source markdown file
const content = fs.readFileSync(sourceFile, 'utf-8')
// Escape backticks and other special characters for TypeScript string
const escaped = content
.replace(/\\/g, '\\\\') // Escape backslashes first
.replace(/`/g, '\\`') // Escape backticks
.replace(/\$/g, '\\$') // Escape dollar signs (for template literals)
// Generate TypeScript file
const tsContent = `/**
* Morgan's System Prompt
* Generated at build time from .fortura-core/web-agents/agent-architect-web.md
* This is embedded here for Cloudflare Worker deployment compatibility
*/
export const MORGAN_SYSTEM_PROMPT = \`${escaped}\`
`
// Write the output file
fs.writeFileSync(outputFile, tsContent, 'utf-8')
console.log(`✓ Generated Morgan system prompt at ${outputFile}`)
console.log(` Size: ${(tsContent.length / 1024).toFixed(1)} KB`)
process.exit(0)
} catch (error) {
console.error('✗ Failed to generate Morgan system prompt:', error.message)
process.exit(1)
}