Holy CRAP! This new replit workflow, eradicates ALL BUGS!

So this is the latest update I got from the developers forum for how to use the replit agent and assistant to develop your MVPS and avoid those pesky AI bugs that tend to break your software.

I’ll keep it brief use the agent only when you want to build functionality and use the assistant whenever you want to fix functionality that already exists which includes bugs, customizations, slight changes in the way something that already exists works, basically if you’ve already created the function you use the assistant from that point on.

Always provide context to the assistant before you start working, Before you talk about a feature you want to implement or change or a bug or problem first ask the Assistant to tell you everything it knows about that function, Then ask it not to do anything but walk you through how it would address what it is you want to change, Then ask it to make that change only after it has all of this context.

If you fork your project or you start a new agent chat ask the agent to read the code and familiarize itself with the application and to describe what it thinks the application does fully without making any changes. Then you can ask it to create a plan to implement the new feature you want to build, then approve that plan.

TL:DR - Use the agent to create, use the assistant to modify, always load up context of the existing code into the ai’s memory whenever starting a new chat. Doing this will prevent the AI from overwriting existing structures and creating problems in previously fixed.

21 Likes

This is generally my preferred workflow too for more complex projects. For simple projects that I think Agent can handle in 2-5 prompts, I just use agent. For example, I recently had Agent make me my own version of all the different sites like “download audio from YouTube” or “convert webp to PNG” because I don’t trust them, Agent was able to do each of them in 5 prompts max.

4 Likes

Very helpful thank you

1 Like

Sounds like a good system … a system the replit software should offer :slight_smile:

Would be nice in the future to just have one prompt field and replit determines whether its for the replit Agent or Replit Assistant. But what we have now is already extraordinary. Hats of to the Replit team.

1 Like

That would be dope!

I do prompt optimisasions for leaving less space to do interpretations. So your prompt excemple would look like this :slight_smile:

Context

You are building a self-hosted, privacy-focused web application — a personal utility toolkit that replicates common online converter/downloader sites. The user’s motivation is distrust of third-party utility websites (possible concerns include data harvesting, tracking, file retention, ads, or opaque server-side behavior — the exact threat model is unconfirmed).

Legal Notice: YouTube downloading violates YouTube’s Terms of Service (Section 5.B) and may violate copyright law (e.g., DMCA) in some jurisdictions. This tool is for personal use with content you have rights to. The developer assumes all legal responsibility. This disclaimer must be included in the application’s README and UI.

Technology Stack (Confirmed)

  • Language: Python 3.11+
  • Framework: FastAPI with uvicorn ASGI server
  • Frontend: Vanilla HTML/CSS/JavaScript (single-page app, no build step required) OR optionally Vue 3 with Vite if the user prefers a component framework
  • Key dependencies:
    • Media downloads: yt-dlp (subprocess, not a Python import — called via subprocess.run with parameterized args)
    • Audio/Video conversion: ffmpeg (subprocess)
    • Image processing: Pillow (Python-native)
    • PDF tools: pypdf (maintained successor to the deprecated PyPDF2) or pikepdf
    • Background removal (Tier 3 only): rembg (Python, runs locally but requires a one-time ~150-400MB model download on first use — this is an exception to the no-external-requests rule that must be documented)
  • Containerization: Dockerfile and docker-compose.yml provided

Why Python over Node.js: The critical dependencies (yt-dlp, Pillow, rembg, pypdf) are all Python-native. A Node.js backend would require Python sidecar processes for most features, adding unnecessary complexity.

Tool Tiers (Build Incrementally)

Tier 1 — Core (Explicitly Requested, Build First)

  1. YouTube Audio Downloader — Extract audio from YouTube URLs. Output: MP3, WAV, FLAC, OGG. Uses yt-dlp + ffmpeg.
  2. Image Format Converter — Convert between: WebP ↔ PNG, PNG ↔ JPG, HEIC → JPG, BMP → PNG, AVIF ↔ PNG. Uses Pillow.

Tier 2 — Strongly Implied (Build Second)

  1. YouTube Video Downloader — Download video in selectable quality. Output: MP4, WEBM.
  2. Audio Format Converter — Convert between MP3, WAV, FLAC, OGG, AAC, M4A. Uses ffmpeg.
  3. Video Format Converter — Convert between MP4, WEBM, MOV, AVI, MKV. Uses ffmpeg.
  4. Image Resizer/Compressor — Resize dimensions, compress with quality slider. Uses Pillow.

Tier 3 — Nice-to-Have (Build if User Confirms)

  1. PDF Merger/Splitter — Merge PDFs, split by page range. Uses pypdf.
  2. PDF ↔ Image Converter — PDF pages to images, images to PDF.
  3. Video to GIF — Extract clip, convert to GIF with frame rate/size controls. Uses ffmpeg.
  4. Background Remover — Local ML-based background removal. Uses rembg. Note: Adds ~400MB+ to Docker image size.
  5. QR Code Generator — Generate QR codes from text/URLs. Uses qrcode library.
  6. Hash GeneratorMD5, SHA-1, SHA-256, SHA-512 for text and files. Uses Python hashlib.
  7. JSON/YAML/CSV Converter — Convert between data formats with pretty-printing.
  8. Base64 Encoder/Decoder — Encode/decode text and files.
  9. Markdown → PDF — Render Markdown to styled PDF.
  10. General Video/Audio Downloader — Additional platforms via yt-dlp.

Existing alternatives worth knowing about: MeTube (YouTube downloader), Stirling-PDF (PDF tools), File Converter (format conversion). The user may prefer integrating these existing open-source tools behind a unified dashboard rather than reimplementing everything.

Security & Privacy Requirements

Authentication (Confirmed: Security-Critical)

  • Implement basic authentication using a single configurable API key/password stored in the .env file
  • All API endpoints and the web UI must require this credential
  • CORS is not a security boundary — it is only enforced by browsers, not by curl/scripts
  • Default bind address: 127.0.0.1 (NOT 0.0.0.0). If the user explicitly wants LAN access, they must opt in and the auth becomes mandatory

SSRF Protection (Confirmed: Security-Critical)

  • The download endpoint accepts arbitrary URLs via yt-dlp. This creates Server-Side Request Forgery risk
  • Required mitigations:
    • Validate URLs against a deny-list of private/internal IP ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8, 169.254.0.0/16, ::1, fd00::/8)
    • Resolve DNS before passing to yt-dlp and validate the resolved IP is not in denied ranges (prevents DNS rebinding)
    • Optionally: allowlist of permitted domains (youtube.com, youtu.be, soundcloud.com, vimeo.com)

File Upload Security (Confirmed: Security-Critical)

  • Filename sanitization: Strip all path components, restrict to alphanumeric + .-_, truncate to 255 chars
  • File type validation: Validate via magic bytes (not just extension). Use python-magic or filetype library
  • Decompression bomb protection: Set max decompressed size limit
  • Path traversal prevention: All temp files written to a sandboxed temp directory; never construct paths from user input
  • Max file size: Configurable, default 200MB (adjusted from 500MB — more appropriate for single-user; tunable via config)

Zero-Trust Principles

  • Zero telemetry, zero analytics, zero external requests at runtime (exception: yt-dlp fetching requested media, rembg first-run model download)
  • No user accounts/registration
  • Subprocess calls must use list-form arguments (subprocess.run(['yt-dlp', '--extract-audio', url])) — never shell=True or string interpolation
  • Content-Security-Policy, X-Content-Type-Options, X-Frame-Options headers set
  • Docker container must run as a non-root user

Resource Management

  • Concurrent job limit: Maximum 2 simultaneous ffmpeg/yt-dlp subprocesses (configurable). Queue additional requests.
  • Disk space pre-check: Before processing, verify available disk space exceeds 2x the input file size (or a minimum of 1GB free)
  • Process-level resource limits: In Docker, set memory limits via docker-compose.yml (mem_limit). For non-Docker, document ulimit recommendations.
  • Timeout: Configurable per-operation timeout, default 5 minutes. Kill subprocess if exceeded.

File Lifecycle & Cleanup

  • Uploaded files and generated outputs stored in a configurable temp directory (default: ./tmp/)
  • Cleanup strategy: Delete files that have not been accessed (read/downloaded) within the TTL window (default: 30 minutes). Use last-access-time, not creation-time, to prevent deleting files during active downloads.
  • Active download detection: Do not delete files that are currently being streamed to a client. Implement reference counting or file locking.

Error Handling

Startup Health Checks (Required)

  • On application start, verify the following binaries are available and log their versions:
    • ffmpeg -version
    • yt-dlp --version
  • If any required binary is missing: refuse to start and print clear error message with installation instructions for the user’s platform

Runtime Error Handling

  • Unsupported format: Return HTTP 400 with supported format list
  • File too large: Return HTTP 413 with configured limit
  • yt-dlp failure: Return HTTP 502 with sanitized error message (strip file paths from yt-dlp stderr). Common failure: “yt-dlp may need updating — run yt-dlp -U
  • ffmpeg failure: Return HTTP 500 with sanitized error. Log full stderr server-side at DEBUG level.
  • URL invalid/unreachable: Return HTTP 400 with user-friendly message
  • Disk full: Return HTTP 507 with message
  • Timeout exceeded: Return HTTP 504 with timeout value
  • All errors: Return structured JSON: {"error": true, "code": "...", "message": "...", "suggestion": "..."}
  • Logging: Structured JSON logs with levels (INFO, WARN, ERROR). Never log file contents, URLs with credentials, or full file paths in production mode.

Client-Side

  • Show progress indicators for uploads and long-running conversions
  • Display estimated time remaining where possible (based on file size heuristics)
  • Show clear error messages with actionable suggestions

Maintenance

  • yt-dlp updates: YouTube frequently changes its API. Include:
    • A /api/health endpoint that reports yt-dlp version and last-checked date
    • Documentation for updating: docker-compose exec app yt-dlp -U or manual update steps
    • Consider a UI button to trigger yt-dlp -U (behind authentication)
  • Dependency version pinning: Pin all Python dependencies in requirements.txt with exact versions. Document update procedure.

UI/UX Guidelines

  • Homepage: Dashboard listing available tools as cards with icons and brief descriptions
  • Each tool page: Clear instructions, file upload zone (drag-and-drop where applicable), format selection dropdowns, prominent Download button
  • Responsive: Mobile-friendly layout
  • Dark mode: Support via CSS prefers-color-scheme media query (automatic, no toggle needed for Tier 1)
  • No ads, no popups, no cookie banners, no tracking
  • Progress bars for upload → processing → download stages

Output & Deliverables

  1. Complete, runnable project with organized directory structure:

    /app
      /api          # FastAPI route handlers (one file per tool category)
      /services     # Business logic (download, convert, etc.)
      /utils        # Shared utilities (file handling, validation, security)
      /static       # Frontend HTML/CSS/JS
      /templates    # (if using server-side rendering)
    /tests          # Unit and integration tests
    /docker
      Dockerfile
      docker-compose.yml
    .env.example
    config.yaml
    requirements.txt
    README.md
    
  2. README.md with: setup instructions (Docker and non-Docker), dependency list, configuration reference, legal disclaimer, security notes, update procedures

  3. .env.example with all configurable values documented:

    • PORT (default: 8080)
    • BIND_ADDRESS (default: 127.0.0.1)
    • AUTH_SECRET (required, no default)
    • TEMP_DIR (default: ./tmp)
    • MAX_FILE_SIZE_MB (default: 200)
    • CLEANUP_TTL_MINUTES (default: 30)
    • OPERATION_TIMEOUT_SECONDS (default: 300)
    • MAX_CONCURRENT_JOBS (default: 2)
  4. Dockerfile with all dependencies pre-installed (ffmpeg, yt-dlp, Python libs), running as non-root user

  5. Well-commented code with type hints on all function signatures

Assumptions (Verify Before Building)

  • The user has a machine (local PC or home server) capable of running Docker or Python 3.11+
  • The user is comfortable with basic terminal commands for initial setup
  • The user wants a web-based interface (inferred from ‘sites’ — if CLI is preferred, the architecture changes significantly)
  • Tier 1 tools are the priority; Tier 2 and 3 should be built only after Tier 1 is confirmed working