Skip to content

Instantly share code, notes, and snippets.

@seabass011
Created September 9, 2025 16:38
Show Gist options
  • Select an option

  • Save seabass011/c235eb9a0cd20183f7b851325daeb70d to your computer and use it in GitHub Desktop.

Select an option

Save seabass011/c235eb9a0cd20183f7b851325daeb70d to your computer and use it in GitHub Desktop.
Nova Demo A - Fix 3 failing tests (add, subtract, multiply)
#!/usr/bin/env bash
# Nova CI-Rescue — The Demo That Changes Everything
# Crafted with obsessive attention to detail
set -Eeuo pipefail
# Parse command line arguments
VERBOSE=false
AUTO_YES=false
for arg in "$@"; do
case $arg in
-v|--verbose)
VERBOSE=true
shift
;;
-y|--yes)
AUTO_YES=true
shift
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -v, --verbose Show detailed Nova output"
echo " -y, --yes Automatically answer yes to all prompts"
echo " -h, --help Show this help message"
exit 0
;;
esac
done
# GitHub authentication for Chapter One
export CHAPTER_ONE_PAT="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"
export GITHUB_TOKEN="${CHAPTER_ONE_PAT}"
########################################
# Terminal Intelligence
########################################
detect_terminal() {
TERM_WIDTH=$(tput cols 2>/dev/null || echo 80)
TERM_HEIGHT=$(tput lines 2>/dev/null || echo 24)
# Detect Unicode support properly
CAN_UTF8=false
if echo -e '\u2713' | grep -q '✓' 2>/dev/null; then
CAN_UTF8=true
fi
# Presentation mode for larger terminals
PRESENTATION_MODE=false
if [ "$TERM_WIDTH" -ge 100 ] && [ "$TERM_HEIGHT" -ge 30 ]; then
PRESENTATION_MODE=true
fi
}
########################################
# Visual Design System
########################################
setup_visuals() {
# Core palette
BOLD=$'\033[1m'
DIM=$'\033[2m'
ITALIC=$'\033[3m'
UNDERLINE=$'\033[4m'
# Semantic colors
RED=$'\033[0;31m'
GREEN=$'\033[0;32m'
YELLOW=$'\033[1;33m'
BLUE=$'\033[0;34m'
PURPLE=$'\033[0;35m'
CYAN=$'\033[0;36m'
WHITE=$'\033[0;37m'
NC=$'\033[0m'
# Adaptive symbols
if [ "$CAN_UTF8" = true ]; then
CHECK="✓"
CROSS="✗"
ARROW="→"
BULLET="•"
SPARKLE="✨"
ROCKET="🚀"
PACKAGE="📦"
BRAIN="🧠"
MAGIC="🪄"
FIRE="🔥"
DIAMOND="💎"
WARNING="⚠️"
INFO="ℹ"
else
CHECK="[OK]"
CROSS="[X]"
ARROW="->"
BULLET="*"
SPARKLE="*"
ROCKET=">"
PACKAGE="[]"
BRAIN="AI"
MAGIC="*"
FIRE="!"
DIAMOND="*"
WARNING="/!\\"
INFO="i"
fi
}
########################################
# Beautiful UI Components
########################################
print_hr() {
printf '%*s\n' "${TERM_WIDTH}" '' | tr ' ' '─'
}
print_thick_hr() {
if [ "$CAN_UTF8" = true ]; then
printf '%*s\n' "${TERM_WIDTH}" '' | tr ' ' '━'
else
printf '%*s\n' "${TERM_WIDTH}" '' | tr ' ' '='
fi
}
center_text() {
local text="$1"
local width="${2:-$TERM_WIDTH}"
local text_length=${#text}
local padding=$(( (width - text_length) / 2 ))
printf '%*s%s%*s' $padding '' "$text" $((width - padding - text_length)) ''
}
print_banner() {
clear
echo
echo
print_thick_hr
echo "Nova CI-Rescue"
echo "Software that fixes software"
print_thick_hr
echo
}
print_step() {
local step=$1
local total=$2
local title=$3
local icon="${4:-$BULLET}"
echo
echo "Step ${step}/${total} │ ${icon} ${title}"
print_hr
}
print_success() {
local message="$1"
echo -e "${GREEN}✓${NC} ${message}"
}
print_error() {
local message="$1"
echo -e "${RED}✗${NC} ${message}"
}
print_info() {
local message="$1"
echo -e "${CYAN}ℹ${NC} ${message}"
}
print_warning() {
local message="$1"
echo -e "${YELLOW}⚠${NC} ${message}"
}
code_preview() {
local file="$1"
local context="${2:-}"
echo
echo -e "${BOLD}${file}${NC}"
if [ -n "$context" ]; then
echo -e "${DIM}${context}${NC}"
fi
echo -e "${DIM}$(print_hr)${NC}"
# Show first 10 lines with line numbers
if [ -f "$file" ]; then
nl -ba "$file" | head -15 | sed 's/^/ /'
local total_lines=$(wc -l < "$file")
if [ "$total_lines" -gt 15 ]; then
echo -e " ${DIM}... (${total_lines} lines total)${NC}"
fi
fi
echo
}
show_diff_preview() {
local file="$1"
echo
echo -e "${BOLD}Changes to ${file}:${NC}"
echo -e "${DIM}$(print_hr)${NC}"
# Show a nice diff with context
git diff --no-index --no-prefix -U2 /dev/null "$file" 2>/dev/null |
tail -n +5 | head -20 |
sed -e 's/^+/\x1b[32m+/g' -e 's/^-/\x1b[31m-/g' -e 's/$/\x1b[0m/'
echo
}
########################################
# Smart Interactions
########################################
confirm() {
local prompt="$1"
local default="${2:-y}"
local details="${3:-}"
if [ -n "$details" ]; then
echo -e "${DIM}${details}${NC}"
fi
# Auto-yes mode
if [ "$AUTO_YES" = true ]; then
printf "${BOLD}%s${NC} " "$prompt"
echo "y"
return 0
fi
local yn="[Y/n]"
if [ "$default" = "n" ]; then
yn="[y/N]"
fi
printf "${BOLD}%s${NC} %s " "$prompt" "$yn"
read -r REPLY
REPLY="${REPLY:-$default}"
[[ "$REPLY" =~ ^[Yy]$ ]]
}
wait_for_enter() {
if [ "$AUTO_YES" = true ]; then
# In auto mode, just pause briefly
sleep 1
return
fi
echo
echo -e "${DIM}Press Enter to continue...${NC}"
read -r
}
########################################
# Core Demo Flow
########################################
run_demo() {
detect_terminal
setup_visuals
print_banner
# Introduction
echo "Welcome to the Nova experience"
echo
echo "In the next 3 minutes, you'll see Nova:"
echo " • Understand broken code"
echo " • Fix it automatically"
echo " • Prove it works"
echo
if ! confirm "Ready to begin?" "y"; then
echo -e "${DIM}Come back when you're ready for magic.${NC}"
exit 0
fi
# Step 1: Create workspace
print_step 1 5 "Creating Your Demo Space" "$PACKAGE"
echo
local demo_dir="/tmp/nova-demo-$(date +%s)"
if confirm "Create demo workspace?" "y" "Location: $demo_dir"; then
mkdir -p "$demo_dir"
cd "$demo_dir"
print_success "Workspace created"
echo -e "${DIM}Location: ${BOLD}$demo_dir${NC}"
else
print_error "Cannot proceed without workspace"
exit 1
fi
# Step 2: Python environment
print_step 2 5 "Setting Up Python Environment" "$PACKAGE"
echo
if confirm "Create isolated Python environment?" "y" "This keeps your system Python clean"; then
echo -e "${DIM}Creating virtual environment...${NC}"
python3 -m venv .venv
source .venv/bin/activate
# Clean up any existing nova shims to avoid conflicts
rm -f ~/.pyenv/shims/nova 2>/dev/null || true
rm -f ~/Library/Python/*/bin/nova 2>/dev/null || true
rm -f ~/.local/bin/nova 2>/dev/null || true
python3 -m pip install --upgrade pip >/dev/null 2>&1
print_success "Python environment ready"
else
print_error "Cannot proceed without Python environment"
exit 1
fi
# Step 3: Install Nova
print_step 3 5 "Installing Nova CI-Rescue" "$ROCKET"
echo
print_info "Nova will be installed from our secure Cloudsmith repository"
if confirm "Install Nova CI-Rescue?" "y"; then
echo -e "${DIM}Installing Nova and dependencies...${NC}"
# Install with progress
python3 -m pip install --quiet \
nova-ci-rescue pytest pytest-json-report openai requests \
--index-url "https://dl.cloudsmith.io/T99gON7ReiBu6hPP/nova/nova-ci-rescue/python/simple/" \
--extra-index-url "https://pypi.org/simple/" \
2>&1 | grep -v "Requirement already satisfied" || true
# Verify Nova installation
if command -v nova &>/dev/null; then
local version=$(nova --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || echo "latest")
print_success "Nova ${version} installed"
else
print_error "Nova installation failed!"
echo -e "${YELLOW}This might be a PATH issue. Try:${NC}"
echo " python -m nova --version"
echo " pip show nova-ci-rescue"
exit 1
fi
else
print_error "Cannot proceed without Nova"
exit 1
fi
# Step 4: Clone demo project
print_step 4 5 "Getting the Demo Project" "$FIRE"
echo
local repo_url="https://github.com/joinnova-ci/calculator-broken-demo.git"
print_info "Demo repository: ${BOLD}calculator-broken-demo${NC}"
echo -e "${DIM}A calculator with 3 core functions, all broken${NC}"
echo
if confirm "Clone the demo repository?" "y"; then
echo -e "${DIM}Cloning from GitHub...${NC}"
# Ensure we always get a fresh copy
rm -rf calculator-demo 2>/dev/null || true
git clone -q "$repo_url" calculator-demo
cd calculator-demo
# Configure git with authentication
git config user.email "demo@joinnova.com"
git config user.name "Nova Demo"
# Set GitHub token for any git operations
export GITHUB_TOKEN="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"
git config --local http.https://github.com/.extraheader "AUTHORIZATION: Bearer ${GITHUB_TOKEN}"
# Ensure we're on a clean main branch
git checkout main 2>/dev/null || git checkout master 2>/dev/null || true
git reset --hard HEAD 2>/dev/null || true
git clean -fd 2>/dev/null || true
# Clean any stale bytecode to avoid pytest import mismatches
find . -type d -name "__pycache__" -prune -exec rm -rf {} + 2>/dev/null || true
# Modify files to only keep the first 3 functions (addition, subtraction, multiplication)
# Truncate calculator.py after multiply function
sed -i.bak '/^def divide/,$d' calculator.py
# Truncate test_calculator.py after test_multiplication
sed -i.bak '/^def test_division/,$d' test_calculator.py
rm -f calculator.py.bak test_calculator.py.bak
# Commit the modifications to avoid Nova warning about uncommitted changes
git add calculator.py test_calculator.py 2>/dev/null || true
git commit -m "Demo: Focus on 3 core functions only" >/dev/null 2>&1 || true
print_success "Repository cloned"
# Show what we got
echo
echo -e "${BOLD}Project structure:${NC}"
ls -la | grep -E '\.(py|md)$' | sed 's/^/ /'
# Preview the broken code
code_preview "calculator.py" "The broken calculator implementation"
wait_for_enter
else
print_error "Cannot proceed without demo repository"
exit 1
fi
# Step 5: The Magic
print_step 5 5 "The Nova Experience" "$MAGIC"
echo
echo -e "${BOLD}First, let's see the failures:${NC}"
echo
# Run tests and show failures
echo -e "${DIM}Running pytest...${NC}"
echo
# Ensure Python can find the module
export PYTHONPATH="."
set +e # Don't exit on test failure
python3 -m pytest test_calculator.py -v --tb=short --no-header |
sed -e 's/FAILED/\x1b[31mFAILED\x1b[0m/g' \
-e 's/PASSED/\x1b[32mPASSED\x1b[0m/g'
local test_result=$?
set -e
if [ $test_result -eq 0 ]; then
print_warning "Tests are already passing! This demo expects failures."
print_info "Resetting repository to ensure failures..."
git restore -s HEAD -SW . 2>/dev/null || git reset --hard origin/main 2>/dev/null || true
find . -type d -name "__pycache__" -prune -exec rm -rf {} + 2>/dev/null || true
# Try tests again
echo
echo -e "${DIM}Running tests again after reset...${NC}"
python3 -m pytest test_calculator.py -v --tb=short --no-header || true
echo
print_info "Demo continuing with current state"
fi
echo
print_error "3 failures - core math functions are broken"
wait_for_enter
# Check for API key
if [ -z "${OPENAI_API_KEY:-}" ]; then
if [ -f "$HOME/.nova.env" ]; then
source "$HOME/.nova.env"
fi
if [ -z "${OPENAI_API_KEY:-}" ]; then
echo
print_warning "OpenAI API key required"
echo -e "${DIM}Get one at: https://platform.openai.com/api-keys${NC}"
echo
printf "${BOLD}Enter API key:${NC} "
read -rs OPENAI_API_KEY
echo
export OPENAI_API_KEY
fi
fi
# The moment of truth
echo
print_thick_hr
echo -e "${BOLD}${BRAIN} Now watch Nova work its magic${NC}"
print_thick_hr
echo
echo "Nova will:"
echo -e " 1. Analyze the test failures"
echo -e " 2. Understand what each function should do"
echo -e " 3. Fix the implementations"
echo -e " 4. Validate the fixes"
echo
echo -e "${DIM}Nova will automatically run pytest to find and fix failures${NC}"
echo
if confirm "Run Nova?" "y" "This will take about 30 seconds"; then
echo
# Check if Nova is available in the current environment
if ! command -v nova &>/dev/null; then
print_error "Nova not found in the current environment!"
echo
echo -e "${BOLD}It looks like Nova wasn't installed or activated properly.${NC}"
echo
echo -e "${CYAN}To try it yourself:${NC}"
echo
echo " 1. Make sure you're in the virtual environment:"
echo -e " ${BOLD}source .venv/bin/activate${NC}"
echo
echo " 2. Verify Nova is installed:"
echo -e " ${BOLD}nova --version${NC}"
echo
echo " 3. Run Nova on this project:"
echo -e " ${BOLD}nova fix${NC}"
echo
echo -e "${DIM}Nova will automatically detect pytest and fix the failing tests.${NC}"
echo
if confirm "Would you like to see the manual installation steps?" "y"; then
echo
echo -e "${BOLD}Manual Installation:${NC}"
echo
echo " # If not in virtual environment:"
echo " source .venv/bin/activate"
echo
echo " # Install Nova:"
echo " pip install nova-ci-rescue pytest \\"
echo " --index-url https://dl.cloudsmith.io/T99gON7ReiBu6hPP/nova/nova-ci-rescue/python/simple/ \\"
echo " --extra-index-url https://pypi.org/simple/"
echo
echo " # Run Nova:"
echo " nova fix"
echo
echo -e "${DIM}Current directory: $(pwd)${NC}"
fi
# Exit gracefully
exit 0
fi
# Set quiet mode for cleaner output
export NOVA_QUIET=1
# Ensure GitHub token is available for Nova
export GITHUB_TOKEN="${CHAPTER_ONE_PAT}"
# Disable PR creation for demo (avoid auth issues)
export NOVA_SKIP_PR=1
# Run Nova with clean output (ensure we're on main branch)
git checkout main 2>/dev/null || git checkout master 2>/dev/null || true
# Configure git to use token for push
git remote set-url origin "https://${CHAPTER_ONE_PAT}@github.com/joinnova-ci/calculator-broken-demo.git"
# Run Nova with appropriate output level
# Nova will automatically detect and run pytest
if [ "$VERBOSE" = true ]; then
echo -e "${DIM}Running in verbose mode...${NC}"
echo -e "${DIM}$ nova fix${NC}"
echo
nova fix 2>&1 | sed 's/^/ /'
local nova_result=${PIPESTATUS[0]}
else
echo -e "${DIM}Running Nova...${NC}"
echo -e "${DIM}$ nova fix${NC}"
echo -e "${DIM}This may take 30-60 seconds...${NC}"
echo
# Run Nova and show output in real-time with minimal filtering
nova fix 2>&1 | while IFS= read -r line; do
# Skip only the most verbose debug lines
if [[ ! "$line" =~ (System\ prompt\ length|User\ prompt\ length|Response\ preview|Request\ params|Provider:|Nova\ Debug\ -|max_tokens) ]]; then
echo " $line"
fi
done
local nova_result=${PIPESTATUS[0]}
fi
if [ $nova_result -ne 0 ]; then
print_error "Nova encountered an issue"
exit 1
fi
# Verify the fix
echo
print_thick_hr
echo -e "${BOLD}${SPARKLE} Verification Time ${SPARKLE}${NC}"
print_thick_hr
echo
echo -e "${DIM}Running tests again...${NC}"
echo
set +e
python3 -m pytest test_calculator.py -v --tb=no --no-header |
sed -e 's/PASSED/\x1b[32mPASSED\x1b[0m/g' \
-e 's/FAILED/\x1b[31mFAILED\x1b[0m/g'
local final_result=$?
set -e
echo
if [ $final_result -eq 0 ]; then
print_success "ALL TESTS PASS! Nova fixed 10 bugs in seconds!"
# Show what changed
echo
echo -e "${BOLD}What Nova changed:${NC}"
echo
git diff --stat HEAD~1
# Show a sample fix
echo
echo -e "${BOLD}Example fix:${NC}"
git diff HEAD~1 -- calculator.py | head -30 |
sed -e 's/^+/\x1b[32m+/g' -e 's/^-/\x1b[31m-/g' -e 's/$/\x1b[0m/'
# Show branch hygiene
echo
echo -e "${BOLD}Branch hygiene:${NC}"
echo -e "${DIM}Nova worked on a safe side branch:${NC}"
git branch --show-current | sed 's/^/ ➜ /'
echo
echo -e "${DIM}Recent commits:${NC}"
git --no-pager log --oneline -3 | sed 's/^/ /'
else
print_warning "Some tests still failing"
echo -e "${DIM}This can happen with complex codebases${NC}"
fi
fi
# Closing
echo
print_thick_hr
echo
echo -e "${BOLD}${DIAMOND} The Nova Advantage ${DIAMOND}${NC}"
echo
echo " ${CHECK} Understood the test intent, not just syntax"
echo " ${CHECK} Made minimal, surgical changes"
echo " ${CHECK} Preserved code style and readability"
echo " ${CHECK} Created a reviewable branch"
echo
echo -e "${DIM}Imagine this running on every PR in your codebase.${NC}"
echo
# Cleanup prompt
if confirm "Delete demo workspace?" "n" "Keep it to explore the changes"; then
cd /tmp
rm -rf "$demo_dir"
print_info "Workspace cleaned up"
else
echo
echo -e "${BOLD}Demo workspace preserved at:${NC}"
echo " $demo_dir"
echo
echo "Explore the fixes:"
echo " cd $demo_dir/calculator-demo"
echo " git diff HEAD~1"
fi
echo
echo -e "${BOLD}${GREEN}Thank you for experiencing Nova.${NC}"
echo -e "${DIM}Questions? ${UNDERLINE}support@joinnova.com${NC}"
echo
}
########################################
# Entry Point
########################################
# Dependency checks
for cmd in python3 git; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: $cmd is required but not installed." >&2
exit 1
fi
done
# Cleanup function
cleanup() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo
echo -e "${YELLOW}Demo interrupted or failed${NC}"
fi
# Deactivate virtual environment if active
if [ -n "${VIRTUAL_ENV:-}" ]; then
deactivate 2>/dev/null || true
fi
echo -e "${DIM}Thank you for trying Nova CI-Rescue${NC}"
exit $exit_code
}
# Set trap for cleanup
trap cleanup EXIT INT TERM
# Run the demo
run_demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment