Skip to content

Refocus builder on video prompts and streamlined insights#22

Open
SPACEreact wants to merge 1 commit intomainfrom
codex/remove-audio-and-casting-features-jaxozt
Open

Refocus builder on video prompts and streamlined insights#22
SPACEreact wants to merge 1 commit intomainfrom
codex/remove-audio-and-casting-features-jaxozt

Conversation

@SPACEreact
Copy link
Copy Markdown
Owner

@SPACEreact SPACEreact commented Nov 6, 2025

User description

Summary

  • rebuild the main interface around story input, enhanced insight, and video prompt workflows with robust copy controls and loading states
  • modernize the story ideation modal to surface a single ranked suggestion, live summary, and clipboard helpers
  • replace the Gemini orchestration with lightweight local heuristics while dropping audio, casting, and image generation codepaths

Testing

  • npm run build (fails: missing npm packages in offline execution environment)

https://chatgpt.com/codex/tasks/task_e_690c3059da6c8326b105458ac833eb79


PR Type

Enhancement, Bug fix


Description

  • Replaced Gemini orchestration with lightweight local heuristics using HuggingFace and GenreIntelligence services

  • Removed audio, casting, and image generation codepaths; refocused on video prompts and story insights

  • Streamlined story ideation modal to surface single ranked suggestion with live summary and clipboard helpers

  • Enhanced UI with copy controls, loading states, and two-column layout for better context visibility


Diagram Walkthrough

flowchart LR
  A["Gemini Service<br/>1308 lines"] -->|"Replace with<br/>lightweight heuristics"| B["HuggingFace +<br/>GenreIntelligence"]
  C["Audio/Casting/<br/>Image Generation"] -->|"Remove"| D["Dropped Codepaths"]
  E["Story Ideation"] -->|"Refactor to<br/>single suggestion"| F["SmartSuggestion<br/>with rationale"]
  B -->|"Generate"| F
  F -->|"Display in"| G["Enhanced UI<br/>with copy controls"]
  H["Video Prompt<br/>Generation"] -->|"Simplify"| I["Local analysis<br/>+ structured output"]
Loading

File Walkthrough

Relevant files
Enhancement
4 files
geminiService.ts
Replace Gemini orchestration with local heuristics             
+114/-1281
storyIdeationService.ts
Refactor suggestions to single ranked SmartSuggestion       
+112/-15
StoryIdeation.tsx
Modernize UI with two-column layout and copy controls       
+202/-93
App.tsx
Update app integration for refactored services                     
+239/-3925
Refactoring
1 files
types.ts
Simplify types by removing audio and casting                         
+7/-239 
Tests
1 files
storyIdeationService.test.ts
Add test for structured suggestion object                               
+20/-0   
Configuration changes
1 files
.npmrc
Configuration changes for offline environment                       
+0/-2     
Additional files
35 files
SOUND_CASTING_FEATURES.md +0/-190 
CastingAssistant.tsx +0/-479 
CollaborationDashboard.tsx +0/-214 
DualProviderAudioGeneration.tsx +0/-595 
DualProviderImageGeneration.tsx +0/-449 
HistoryBrowser.tsx +0/-419 
OldSoundTab.tsx +0/-431 
ProgressBoxes.tsx +0/-158 
PromptsExport.tsx +0/-233 
SoundDesignModule.tsx +0/-372 
StarRating.tsx +0/-97   
StoryIdeationModal.tsx +0/-414 
VisualProgressTracker.tsx +0/-234 
AuthContext.tsx +0/-187 
use-mobile.tsx +0/-19   
dualProviderAudioService.ts +0/-562 
dualProviderCastingService.ts +0/-563 
dualProviderImageService.ts +0/-489 
enhancedGeminiService.ts +0/-291 
historyService.ts +0/-280 
moduleCollaborationService.ts +0/-282 
audioLDM2Provider.ts +0/-447 
geminiAudioProvider.ts +0/-442 
geminiCastingProvider.ts +0/-399 
geminiImageProvider.ts +0/-319 
llamaProvider.ts +0/-395 
stableDiffusionXLProvider.ts +0/-308 
storyService.ts +0/-141 
supabaseHistoryService.ts +0/-447 
supabaseService.ts +0/-177 
workingCastingService.ts +0/-309 
workingSoundService.ts +0/-287 
audioGeneration.ts +0/-385 
castingAssistant.ts +0/-430 
imageGeneration.ts +0/-332 

@qodo-code-review
Copy link
Copy Markdown

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Missing audit logs: New functions performing significant analyses and prompt generation do not emit any audit
logs for inputs, user, or outcomes, making reconstruction of events difficult.

Referred Code
export const getKnowledgeBasedSuggestions = async (
  script: string,
  context: Partial<StoryContext> = {}
): Promise<EnhancedInsight> => {
  const combinedSource = [script, ...Object.values(context)]
    .map(entry => entry?.trim())
    .filter(Boolean)
    .join('\n');

  if (!combinedSource) {
    return FALLBACK_INSIGHT;
  }

  await ensureInitialized();

  const narrative = await huggingFaceService.analyzeNarrative(combinedSource);
  const genreProfile = await genreService.detectGenre(combinedSource, context as Record<string, any>);

  const visualHook = narrative.visualCues[0]
    || genreProfile.characteristics.visualStyle[0]
    || 'bold composition';


 ... (clipped 74 lines)
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Generic throw: Error thrown on empty script lacks contextual details and no recovery or user-safe
handling path is provided.

Referred Code
if (!script) {
  throw new Error('A script or outline is required before Dreamer can build a video prompt.');
}

await ensureInitialized();
Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Limited validation: External inputs like request fields and combined context are used without explicit
validation/sanitization beyond a non-empty script check.

Referred Code
const summary = await huggingFaceService.summarizeText(script, 140);
const narrative = await huggingFaceService.analyzeNarrative(script);
const genreProfile = await genreService.detectGenre(script, request.context as Record<string, any>);

const duration = request.duration || '45-second';
const primaryVisual = request.visualStyle
  || genreProfile.characteristics.visualStyle[0]
  || 'cinematic framing';
const lightingCue = genreProfile.characteristics.lighting[0] || 'motivated lighting';
const cameraMove = genreProfile.suggestions.camera[0] || 'intentional camera movement';

const prompt = [
  `Craft a ${duration} ${genreProfile.genre} video.`,
  `Focus on ${summary.toLowerCase()}.`,
  `Use ${primaryVisual} with ${lightingCue} and ${cameraMove}.`,
  request.mood ? `Maintain a ${request.mood} mood throughout.` : '',
]
  .filter(Boolean)
  .join(' ')
  .replace(/\s+/g, ' ')
  .trim();


 ... (clipped 26 lines)
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Validate the pivot to local heuristics

The PR replaces a powerful external AI with simpler local heuristics, reducing
features and cost. The suggestion is to validate that this strategic trade-off
is intentional and that the new system's output quality is sufficient.

Examples:

src/services/geminiService.ts [1-141]
import { HuggingFaceService } from './huggingFaceService';
import { GenreIntelligenceService } from './genreIntelligenceService';
import type { StoryContext } from './storyIdeationService';

const huggingFaceService = HuggingFaceService.getInstance();
const genreService = GenreIntelligenceService.getInstance();

const ensureInitialized = async () => {
  await huggingFaceService.initialize();
};

 ... (clipped 131 lines)
src/App.tsx [1-281]
import React, { useMemo, useState } from 'react';
import {
  Film,
  Sparkles,
  Lightbulb,
  Copy,
  Check,
  Loader2,
  Video
} from 'lucide-react';

 ... (clipped 271 lines)

Solution Walkthrough:

Before:

// file: src/services/geminiService.ts
const ai = new GoogleGenAI({ apiKey: geminiApiKey });

export const getKnowledgeBasedSuggestions = async (context, question) => {
  // ... complex context building
  const aiResponse = await ai.models.generateContent({
      model: 'gemini-2.0-flash-exp',
      contents: `Based on this context, provide 2-3 cinematography-forward ideas...`,
  });
  // ...
};

export const generateImage = async (prompt) => {
  const response = await ai.models.generateImages({
    model: 'imagen-4.0-generate-001',
    prompt: `... ${prompt}`,
  });
  // ...
};

// ... many other functions for audio, casting, storyboards, etc.

After:

// file: src/services/geminiService.ts
const huggingFaceService = HuggingFaceService.getInstance();
const genreService = GenreIntelligenceService.getInstance();

export const getKnowledgeBasedSuggestions = async (script, context) => {
  // ... combine script and context
  await ensureInitialized();

  const narrative = await huggingFaceService.analyzeNarrative(combinedSource);
  const genreProfile = await genreService.detectGenre(combinedSource, context);

  // Construct recommendation and rationale from local analysis results using templates
  const recommendation = `Lean into a ${visualHook} that underscores the ${genreProfile.genre} energy...`;
  const rationale = `This builds on the ${narrative.emotionalTone} tone detected...`;

  return { recommendation, rationale, metadata: { ... } };
};

// ... only one other function `generateVideoPrompt` remains.
// ... No image, audio, or casting generation.
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies the PR's core strategic pivot from a powerful external AI to local heuristics and questions if the resulting quality meets the product's goals, which is the most critical concern.

High
Possible issue
Fix infinite loop in navigation

Fix an infinite loop in nextQuestion that occurs when the last question should
be skipped. The proposed change is to allow the question index to go beyond the
array length to terminate the sequence.

src/components/StoryIdeation.tsx [196-208]

 const nextQuestion = () => {
   if (currentQuestionIndex < storyIdeationQuestions.length - 1) {
-    // Skip questions that shouldn't be shown
     let nextIndex = currentQuestionIndex + 1;
     while (
       nextIndex < storyIdeationQuestions.length &&
       !StoryIdeationService.shouldShowQuestion(storyIdeationQuestions[nextIndex].id, context)
     ) {
       nextIndex++;
     }
-    setCurrentQuestionIndex(Math.min(nextIndex, storyIdeationQuestions.length - 1));
-    setUpcomingQuestion(findNextVisibleQuestion(Math.min(nextIndex, storyIdeationQuestions.length - 1), context));
+    setCurrentQuestionIndex(nextIndex);
+    setUpcomingQuestion(findNextVisibleQuestion(nextIndex, context));
   }
 };
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical infinite loop bug in the question navigation logic, but the proposed fix would cause a crash by setting an out-of-bounds array index.

High
Prevent incorrect backward navigation behavior

Modify prevQuestion to prevent navigating to the first question if all previous
questions should be skipped. Instead, do nothing if no valid previous question
is found.

src/components/StoryIdeation.tsx [210-223]

 const prevQuestion = () => {
   if (currentQuestionIndex > 0) {
     let prevIndex = currentQuestionIndex - 1;
     while (
       prevIndex >= 0 &&
       !StoryIdeationService.shouldShowQuestion(storyIdeationQuestions[prevIndex].id, context)
     ) {
       prevIndex--;
     }
-    const safeIndex = prevIndex >= 0 ? prevIndex : 0;
-    setCurrentQuestionIndex(safeIndex);
-    setUpcomingQuestion(findNextVisibleQuestion(safeIndex, context));
+    if (prevIndex >= 0) {
+      setCurrentQuestionIndex(prevIndex);
+      setUpcomingQuestion(findNextVisibleQuestion(prevIndex, context));
+    }
   }
 };
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a navigation bug where prevQuestion can incorrectly land on a skipped question, and the proposed fix is accurate and improves the component's robustness.

Medium
Prevent "undefined" in generated text

Add a fallback for narrative.narrativeElements[0] to prevent "undefined" from
appearing in the generated recommendation string.

src/services/geminiService.ts [69]

-const recommendation = `Lean into a ${visualHook} that underscores the ${genreProfile.genre} energy while highlighting ${narrative.narrativeElements[0]}.`;
+const primaryElement = narrative.narrativeElements[0] || 'the core theme';
+const recommendation = `Lean into a ${visualHook} that underscores the ${genreProfile.genre} energy while highlighting ${primaryElement}.`;
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies a missing null/undefined check that could lead to malformed output, and the proposed fix is consistent with the defensive coding style used elsewhere in the function.

Low
Prevent memory leaks from timers

Refactor the setTimeout calls into useEffect hooks to automatically clear the
timers on component unmount, preventing potential memory leaks and state updates
on unmounted components.

src/App.tsx [90-110]

+useEffect(() => {
+  if (!copiedInsight) return;
+  const timer = setTimeout(() => setCopiedInsight(false), 2000);
+  return () => clearTimeout(timer);
+}, [copiedInsight]);
+
+useEffect(() => {
+  if (!copiedPrompt) return;
+  const timer = setTimeout(() => setCopiedPrompt(false), 2000);
+  return () => clearTimeout(timer);
+}, [copiedPrompt]);
+
 const handleCopyInsight = () => {
   if (!insight) return;
   copyToClipboard(
     `${insight.recommendation}\n\n${insight.rationale}`,
-    () => {
-      setCopiedInsight(true);
-      setTimeout(() => setCopiedInsight(false), 2000);
-    }
+    () => setCopiedInsight(true)
   );
 };
 
 const handleCopyPrompt = () => {
   if (!videoPrompt) return;
   copyToClipboard(
     `${videoPrompt.prompt}\n\nBeats:\n${videoPrompt.beats.join('\n')}`,
-    () => {
-      setCopiedPrompt(true);
-      setTimeout(() => setCopiedPrompt(false), 2000);
-    }
+    () => setCopiedPrompt(true)
   );
 };
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies a potential memory leak from an un-cleared timer and proposes a robust solution using a useEffect hook for cleanup, which aligns with React best practices.

Low
General
Improve error handling for safety

Improve error handling by checking if the caught error is an instanceof Error
before accessing its message property, making the code safer and more robust.

src/App.tsx [56-63]

 try {
   const result = await getKnowledgeBasedSuggestions(storyOutline, storyContext);
   setInsight(result);
 } catch (error) {
-  setErrorMessage((error as Error).message || 'Unable to fetch enhanced insight.');
+  if (error instanceof Error) {
+    setErrorMessage(error.message);
+  } else {
+    setErrorMessage('An unknown error occurred while fetching enhanced insight.');
+  }
 } finally {
   setIsFetchingInsight(false);
 }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion improves error handling robustness by replacing an unsafe type assertion in a catch block with a proper instanceof check, which is a modern TypeScript best practice.

Medium
  • More

SPACEreact added a commit that referenced this pull request Nov 9, 2025
- Accept PR's refactored video-focused implementation
- Remove deprecated audio/casting references
- Align with new streamlined architecture
- Part of automated conflict resolution for PR #22
SPACEreact added a commit that referenced this pull request Nov 9, 2025
- Accept PR's refactored video-focused implementation
- Remove deprecated audio/casting references
- Align with new streamlined architecture
- Part of automated conflict resolution for PR #22
SPACEreact added a commit that referenced this pull request Nov 9, 2025
- Accept PR's refactored video-focused implementation
- Remove deprecated audio/casting references
- Align with new streamlined architecture
- Part of automated conflict resolution for PR #22
SPACEreact added a commit that referenced this pull request Nov 9, 2025
- Accept PR's refactored video-focused implementation
- Remove deprecated audio/casting references
- Align with new streamlined architecture
- Part of automated conflict resolution for PR #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant