UNPKG

story-weaver-ai

Version:

A narrative development system for AI-driven storytelling with Jungian psychology

110 lines (96 loc) 3.34 kB
/** * Handle analyze-plot command to identify plot holes and inconsistencies * @param {Array} args - Command arguments * @returns {Promise<Object>} Command result */ async function handleAnalyzePlot(args) { try { const options = parseCommandOptions(args, { elements: { type: 'string', alias: 'e', description: 'Path to elements file' }, ids: { type: 'array', alias: 'i', description: 'IDs of specific elements to analyze' } }); if (!options.elements) { return { status: 'error', message: 'Please specify an elements file with --elements or -e' }; } const elementsPath = resolvePath(options.elements); log('info', `Analyzing plot holes in ${elementsPath}`); const elementIds = options.ids || []; const result = await taskManager.analyzeForPlotHoles(elementsPath, elementIds); return { status: 'success', message: result.message, data: { outputPath: result.outputPath, plotHoles: result.analysisResult.plotHoles.length, suggestions: result.analysisResult.suggestions.length } }; } catch (error) { return { status: 'error', message: `Failed to analyze plot: ${error.message}` }; } } /** * Handle refine-story command to improve story elements * @param {Array} args - Command arguments * @returns {Promise<Object>} Command result */ async function handleRefineStory(args) { try { const options = parseCommandOptions(args, { elements: { type: 'string', alias: 'e', description: 'Path to elements file' }, concept: { type: 'string', alias: 'c', description: 'Path to concept file' }, phase: { type: 'string', alias: 'p', description: 'Refinement phase (world, characters, plot, themes, all)', default: 'all' }, focus: { type: 'string', alias: 'f', description: 'Focus area within the phase' } }); if (!options.elements && !options.concept) { return { status: 'error', message: 'Please specify at least one of: --elements (-e) or --concept (-c)' }; } const elementsPath = options.elements ? resolvePath(options.elements) : null; const conceptPath = options.concept ? resolvePath(options.concept) : null; // Validate phase const validPhases = ['world', 'characters', 'plot', 'themes', 'all']; if (!validPhases.includes(options.phase)) { return { status: 'error', message: `Invalid phase: ${options.phase}. Must be one of: ${validPhases.join(', ')}` }; } log('info', `Refining story phase: ${options.phase}`); // Additional options to pass to the refinement function const refinementOptions = {}; if (options.focus) { refinementOptions.focus = options.focus; } const result = await taskManager.refineStory(elementsPath, conceptPath, options.phase, refinementOptions); return { status: 'success', message: result.message, data: result }; } catch (error) { return { status: 'error', message: `Failed to refine story: ${error.message}` }; } } // Command handlers mapping const commandHandlers = { // ... existing commands ... 'analyze-plot': handleAnalyzePlot, 'refine-story': handleRefineStory };