Skip to content

Fix code_generator.py to produce unique, tutorial-specific output instead of identical boilerplate - #79

Closed
groupthinking with Claude wants to merge 3 commits into
mainfrom
claude/fix-code-generator-output
Closed

groupthinking with Claude wants to merge 3 commits into
mainfrom
claude/fix-code-generator-output

Conversation

@Claude

@Claude Claude AI commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

The code generator was extracting tutorial_steps from video analysis but only displaying them as static text. Every video produced identical boilerplate code regardless of tutorial content.

Changes

Tutorial Step Analysis

  • Added _extract_step_action() to classify tutorial steps by action type (create, state, API, event, form, list, style)
  • Each action type maps to specific code patterns and implementations

React Generation

  • _generate_step_components_jsx(): Generates interactive step cards with working code demos
  • _generate_step_specific_code(): Creates unique JSX per step based on action type
  • Added progress tracking with useState hooks and step completion handlers

Example output for "Add useState hook" step:

<div className="code-demo">
  <pre className="code-block">{`
const [step1Value, setStep1Value] = useState('');
const handleChange = (e) => {
  setStep1Value(e.target.value);
};`}</pre>
  <div className="demo-output">
    <input type="text" placeholder="Type here..." />
  </div>
</div>

Vanilla JS Generation

  • _generate_vanilla_step_function(): Generates step-specific init functions with real implementations
  • _generate_step_initializations(): Auto-executes tutorial functions on page load
  • Event handlers, API calls, form submissions based on step content

FastAPI Generation

  • Added tutorial-specific endpoints: /api/tutorial/steps, /api/tutorial/progress
  • Root endpoint now reflects actual tutorial title and features from video analysis

Styling & Documentation

  • 200+ lines of CSS for interactive tutorial elements (code blocks, demos, progress indicators)
  • Enhanced README generation to emphasize tutorial-specific nature and list implemented steps

Verification

Test suite validates unique output across different tutorial types:

  • React state management vs API integration → Different components
  • Form handling vs event handling → Different vanilla JS functions
  • Different FastAPI endpoint implementations based on features

Each video now generates code matching its tutorial content rather than generic templates.

Original prompt

This section details on the original issue you should resolve

<issue_title>code_generator.py</issue_title>
<issue_description>fix code_generator.py so each video produces unique, tutorial-specific output instead of identical boilerplate. @claude </issue_description>

Comments on the Issue (you are @claude[agent] in this section)

@vercel

vercel Bot commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v0-uvai Ready Ready Preview, Comment, Open in v0 Mar 20, 2026 9:32am

- Enhanced React component generation with tutorial-specific implementations
- Added step-by-step code generation based on tutorial actions (create, state, API, event, form, list, style)
- Updated vanilla JS to generate unique functions per tutorial step with real implementations
- Enhanced FastAPI generator with tutorial-specific endpoints
- Improved CSS with styles for interactive tutorial elements
- Updated README generation to highlight tutorial-specific nature of code
- Each video now produces unique code based on extracted tutorial_steps instead of identical boilerplate

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
- Added test suite verifying unique output per tutorial
- Tests validate React, vanilla JS, and FastAPI generation
- Added detailed solution summary documenting changes
- All tests passing successfully

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Fix code_generator.py to produce unique tutorial-specific output Fix code_generator.py to produce unique, tutorial-specific output instead of identical boilerplate Mar 20, 2026
@Claude
Claude AI requested a review from groupthinking March 20, 2026 09:32
"description": "This API was generated by UVAI from a YouTube tutorial",
"endpoints": ["/docs", "/api/messages", "/api/health"]
"description": "This API was generated from a YouTube tutorial with unique implementations",
"endpoints": [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Features list is embedded directly in generated FastAPI code without proper JSON serialization, using Python list syntax instead of JSON array format

Fix on Vercel

"""Generate unique code implementation for each tutorial step"""

# Generate tutorial-specific code based on the step's action
if action == 'create':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String escaping vulnerability in _generate_step_specific_code: Step variable embedded directly in template literals without escaping, allowing backticks or special characters to break JSX/JavaScript syntax

Fix on Vercel

Comment on lines +371 to +374
component_jsx = f''' <div className="step-card" data-step="{{idx}}" key="{{idx}}">
<div className="step-header">
<span className="step-number">Step {{idx + 1}}</span>
<h3>{{completedSteps.includes(idx) ? '✓ ' : ''}}{step[:60]}{{'{step[60:]}' if len(step) > 60 else ''}}</h3>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
component_jsx = f''' <div className="step-card" data-step="{{idx}}" key="{{idx}}">
<div className="step-header">
<span className="step-number">Step {{idx + 1}}</span>
<h3>{{completedSteps.includes(idx) ? '✓ ' : ''}}{step[:60]}{{'{step[60:]}' if len(step) > 60 else ''}}</h3>
# Pre-evaluate Python logic before using in f-string to avoid syntax errors
step_title = step[:60]
step_remainder = step[60:] if len(step) > 60 else ''
component_jsx = f''' <div className="step-card" data-step="{{idx}}" key="{{idx}}">
<div className="step-header">
<span className="step-number">Step {{idx + 1}}</span>
<h3>{{completedSteps.includes(idx) ? '✓ ' : ''}}{step_title}{step_remainder}</h3>

Invalid JSX generation with embedded Python conditional syntax produces malformed JavaScript when rendered

Fix on Vercel

@groupthinking

Copy link
Copy Markdown
Owner

Closing: superseded by PR #113 which ported the UUID suffix fix + _build_title helper from YOUTUBE-EXTENSION PR #706. The root cause (timestamp % 10000 collision + generic fallback title) is fixed.

@github-actions
github-actions Bot deleted the claude/fix-code-generator-output branch June 2, 2026 09:24

This branch was successfully deployed

1 active deployment
Preview — 843c6c13 Deployed Mar 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

code_generator.py

2 participants