import { join } from 'node:path'; import type { WorkflowConfig } from '../types.js'; import { ensureDir } from '../lib/fs.js'; import { createWikiTemplate } from '../lib/template.js'; import { writeFileSync } from 'node:fs'; export function createWiki(title: string, config: WorkflowConfig, category: string): void { const today = new Date().toISOString().split('T')[0]; const slug = title .toLowerCase() .replace(/[^a-z0-9\u4e00-\u9fa5]+/g, '-') .replace(/^-+|-+$/g, ''); const filename = `${today}-${slug}.md`; const subdirMap: Record = { pattern: config.wikiSubdirs.patterns, faq: config.wikiSubdirs.faq, lesson: config.wikiSubdirs.lessons, patterns: config.wikiSubdirs.patterns, lessons: config.wikiSubdirs.lessons, }; const subdir = subdirMap[category]; if (!subdir) { console.error(`❌ Unknown category: ${category} Valid categories: pattern Reusable solutions and conventions faq Common questions lesson Retrospectives and post-mortems Usage: bunx @lythos/project-cortex wiki "" --category pattern|faq|lesson Example: bunx @lythos/project-cortex wiki "Dormancy property test" --category pattern Index regenerates automatically; to rebuild manually: bunx @lythos/project-cortex index wiki`); process.exit(1); } const filepath = join(config.wikiDir, subdir, filename); ensureDir(join(config.wikiDir, subdir)); const template = createWikiTemplate(title, today, category.replace(/s$/, '')); writeFileSync(filepath, template); console.log(`✅ Step 1/3: CLI created → ${filepath}`); console.log(`🔄 Step 2/3: YOUR TURN — edit the file, fill these sections:`); console.log(` Context / Details / When to Apply or Not / Related`); console.log(` After you complete Step 2, continue to:`); console.log(`⏳ Step 3/3: Verify with 'cortex probe' before commit`); }