Skip to content

Conversation

@simonfaltum
Copy link
Member

@simonfaltum simonfaltum commented Nov 21, 2025

Summary

Added convenience scripts to streamline the initial setup and daily development workflow for the Databricks Chatbot template.

New Scripts

1. scripts/quickstart.sh - Automated First-Time Setup

A comprehensive, linear setup script that guides users through the complete initial configuration. In an ideal scenario (full setup with database and deployment), the
script performs these steps:

1. Prerequisites Installation

  • Automatically installs required tools: jq (JSON parsing), nvm (Node Version Manager), and Databricks CLI
  • Uses Homebrew on macOS, or falls back to curl-based installation
  • Sets up Node.js 20 and activates it for the project

2. Configuration Files Setup

  • Creates .env.local from .env.example (if not already present)
  • Preserves existing configuration if .env.local already exists

3. Databricks Authentication

  • Detects existing Databricks CLI profiles
  • Allows selection from existing profiles or interactive login for new workspaces
  • Validates the selected profile by testing authentication
  • Re-authenticates expired profiles automatically
  • Saves the profile name to .env.local (e.g., DATABRICKS_CONFIG_PROFILE=default)

4. Application Configuration

  • Serving Endpoint:
    • Prompts for the AI Model Serving Endpoint name (e.g., databricks-gpt-4-turbo)
    • Validates that the endpoint exists in your workspace
    • Lists available endpoints if the specified one is not found
    • Updates both databricks.yml and .env.local with the endpoint name
  • Database Setup (Optional):
    • Asks whether to enable persistent chat history
    • If yes: Uncomments database configuration sections in databricks.yml
    • If no: Ensures database sections are commented out (ephemeral mode)
  • Dependencies:
    • Runs npm install to set up project dependencies

5. Deployment & Database Provisioning

  • Deployment (Optional):
    • Prompts whether to deploy resources to Databricks now
    • If yes: Runs databricks bundle deploy -t dev
    • Database provisioning takes 5-10 minutes on first deployment
  • Database Connection Discovery:
    • If database is enabled and deployment occurred:
      • Calculates the database instance name based on your username
      • Polls for database DNS hostname (PGHOST) with 10-minute timeout
      • Automatically writes connection details to .env.local:
        • PGUSER (your Databricks username)
        • PGHOST (database hostname)
        • PGDATABASE=databricks_postgres
        • PGPORT=5432
      • Runs npm run db:migrate to set up the database schema

Additional Features:

  • App Name Validation: Checks that the generated app name is ≤30 characters (Databricks Apps requirement)
  • Endpoint Validation: Soft-check to verify the serving endpoint exists before proceeding
  • Smart Configuration: Preserves existing configuration when re-running the script
  • Helpful Warnings: Notifies users about deployment costs and manual cleanup needs

Result: After the ideal flow completes, you have:

  • Fully configured local environment (.env.local)
  • Optionally: Deployed backend with provisioned database
  • Database schema migrations applied (if database enabled)
  • Ready to run npm run dev with full functionality

2. scripts/start-app.sh - Quick App Startup

A simple convenience script for daily development:

Files Changed

  • scripts/quickstart.sh - New comprehensive setup script (542 lines)
  • scripts/start-app.sh - New startup convenience script (23 lines)
  • README.md - Updated to feature these scripts as the recommended setup method
  • server/src/index.ts - Clarified backend server port in console output

Testing

Please test the following scenarios:

Scenario 1: Entirely Local (No Database, No Deployment)

  1. Run ./scripts/quickstart.sh
  2. Select No when asked about database
  3. Select No when asked about deployment
  4. Expected Result:
    • .env.local contains DATABRICKS_CONFIG_PROFILE and DATABRICKS_SERVING_ENDPOINT
    • No database environment variables in .env.local
    • App runs in ephemeral mode with npm run dev
    • Sidebar shows "No chat history available"

Scenario 2: Local with Existing Database

  1. Ensure database was previously deployed (databricks bundle deploy with database enabled)
  2. Run ./scripts/quickstart.sh
  3. Select Yes when asked about database
  4. Select No when asked about deployment
  5. Expected Result:
    • Script finds existing database instance
    • Writes PGHOST to .env.local (along with PGUSER, PGDATABASE, PGPORT)
    • Runs migrations successfully
    • App runs with persistent chat history

Scenario 3: Full Deploy (First-Time Setup)

  1. Run ./scripts/quickstart.sh on a clean install
  2. Select Yes when asked about database
  3. Select Yes when asked about deployment
  4. Expected Result:
    • Script deploys bundle (takes 5-10 minutes for database provisioning)
    • Polls for database hostname (PGHOST) until available
    • Writes complete database configuration to .env.local
    • Runs migrations automatically
    • App is ready to start with npm run dev or ./scripts/start-app.sh

Additional Test Cases

  • Invalid Serving Endpoint: Enter a non-existent endpoint name
    • Script should warn and list available endpoints
    • Ask for confirmation before proceeding
  • App Name Too Long: Test with a Databricks username that would generate a >30 character app name
    • Script should error with clear message about modifying databricks.yml
  • Re-running Script: Run the script multiple times
    • Should preserve existing configuration
    • Should allow changing database configuration (enable → disable or vice versa)
  • Expired Authentication: Test with an expired Databricks profile
    • Script should detect failed authentication and prompt for re-login

Benefits

  1. Faster onboarding: New users can get started in minutes instead of following many manual steps
  2. Fewer errors: Automated validation prevents common configuration mistakes
  3. Better DX: Clear prompts and helpful error messages guide users through setup
  4. Flexible: Supports multiple workflows (local-only, with existing DB, full deploy)
  5. Idempotent: Safe to re-run the script to update configuration

simonfaltum and others added 14 commits November 13, 2025 12:24
Created scripts/setup-local-dev-env.sh - an interactive wizard that:
- Validates prerequisites (Databricks CLI, jq, authentication)
- Guides users through environment configuration
- Auto-detects workspace URL and database settings
- Creates .env.local with proper configuration

Updated README.md to document the new quick start process using the setup script.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Created scripts/setup.sh - a unified interactive setup wizard featuring:
- Arrow-key navigation with visual menu system
- Complete first-time setup workflow (auth, deployment, database, local env)
- Diagnostics and troubleshooting tools
- State persistence across sessions
- Smart auto-detection with manual override options

Removed scripts:
- setup-local-dev-env.sh (functionality integrated)
- enable-history-database.sh (functionality integrated)

Updated README.md to reference the new unified setup wizard throughout.

The new wizard provides a professional guided experience for:
• Prerequisites verification
• Databricks authentication
• Serving endpoint configuration
• Database mode selection (ephemeral/persistent)
• Bundle deployment with progress tracking
• Local environment setup
• Database migrations
• Status checks and diagnostics

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Improvements to make the menu system more robust:
- Fixed read_key() to not suppress stdin (removed 2>/dev/null from initial read)
- Improved arrow key detection by properly concatenating escape sequences
- Added direct number selection [0-9] as fallback for arrow keys
- Display menu item numbers to show available numeric shortcuts
- Updated help text to indicate both arrow and number navigation options

This resolves issues where the menu would hang waiting for input in
certain terminal environments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Changes:
- Separated echo prompt from read command for better compatibility
- Changed from 'read -p' to simple 'read -r' with preceding echo
- Added terminal interactivity check to fail fast if not in interactive mode
- Updated help text to emphasize number selection as alternative to arrows

This should resolve the hanging issue on macOS where the initial
Enter press wasn't being registered.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Use 'read -n1 -s' to read a single character instead of waiting for Enter.
This is more reliable across different terminal configurations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The bug: read -rsn1 returns a newline character (\n or \r) when Enter
is pressed, not an empty string. The original check for empty string
never matched, causing the menu to ignore Enter key presses.

Fixed by checking for both newline characters and empty string:
- Empty string: ""
- Newline: $'\n'
- Carriage return: $'\r'

This resolves the menu freezing issue on macOS.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Removed complex arrow key navigation which was incompatible with macOS
terminal buffering. The new menu system:
- Renders once per selection
- Uses standard 'read -r -p' for input
- Number-based selection (type 0-8 and press Enter)
- Simple, reliable, and compatible across all terminals

This eliminates all the issues with:
- read -rsn1 hanging
- Escape sequences being split across reads
- Terminal-specific buffering problems

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
All DEBUG messages now go to /tmp/setup-wizard-debug.log (file descriptor 3)
instead of stderr. This prevents DEBUG output from interfering with the
terminal display and menu rendering.

Users can still monitor debug output with:
  tail -f /tmp/setup-wizard-debug.log

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…p/bundle names, and auto-start

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link
Contributor

@bbqiu bbqiu left a comment

Choose a reason for hiding this comment

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

from running through this myself, a few nits:

  1. when i selected "y" for customizing the name, the script did not wait for my input
  2. script did not wait for me to select an option when deploying the app to databricks
  3. can we change the default to not be gpt-5-1 if it doesn't work right now (tracked in https://databricks.atlassian.net/browse/ML-59783)

- Move name validation to after user customization choice
- Auto-truncate default app names that exceed 30 char limit
- Add validation loops for custom app/bundle names with clear length limits
- Update top-level bundle name in databricks.yml (fixes deployment path)
- Clear .databricks cache before deployment to prevent stale state
- Change default endpoint to databricks-claude-sonnet-4
- Allow users to press Enter to accept default endpoint

Fixes issues where:
- Script would fail if default name was too long
- Custom names weren't validated for length
- Deployment used wrong workspace path after customization
- Bundle cache caused deployment to use old names

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@simonfaltum
Copy link
Member Author

from running through this myself, a few nits:

  1. when i selected "y" for customizing the name, the script did not wait for my input
  2. script did not wait for me to select an option when deploying the app to databricks
  3. can we change the default to not be gpt-5-1 if it doesn't work right now (tracked in https://databricks.atlassian.net/browse/ML-59783)

I couldn't reproduce but I have done some more testing and made the customizing name more robust.
I don't think there is any "option" when deploying the app to databricks?
I have changed to claude 4 sonnet as default.

I also only tried this with zsh but it should work across macOS and linux

@simonfaltum simonfaltum requested a review from bbqiu November 21, 2025 21:43
Copy link
Contributor

@bbqiu bbqiu left a comment

Choose a reason for hiding this comment

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

ah going through this again, if you type any letters other than y or n, the script treats it as a yes (don't have to be "y" or "n", it'll proceed to the next steps). if we fix this, i think this looks great!

@simonfaltum simonfaltum requested a review from bbqiu November 25, 2025 11:02
@bbqiu
Copy link
Contributor

bbqiu commented Nov 26, 2025

from a quick runthrough again, i think the same behavior is still present:
image

claude suggested something like this to require the user to specifically type "y" or "n":

while true; do
      read -p "Enable database? (y/N): " -n 1 -r
      echo
      case $REPLY in
          [Yy]) USE_DATABASE=true; break ;;
          [Nn]|"") USE_DATABASE=false; break ;;
          *) echo "❌ Please enter 'y' or 'n'" ;;
      esac
  done

@simonfaltum
Copy link
Member Author

I can't reproduce it?

Screen.Recording.2025-11-27.at.16.05.00.mov

Copy link
Contributor

@eLysgaard eLysgaard left a comment

Choose a reason for hiding this comment

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

Can you add an entry in CLAUDE.md that mentions, suggests, and instructs claude how to this script?

Added comprehensive documentation for the three new convenience scripts:
- quickstart.sh: Interactive setup wizard for first-time users
- start-app.sh: Simple local development server starter
- cleanup-database.sh: Database instance cleanup tool

Updated Essential Commands section with Quick Start Scripts subsection
and added Convenience Scripts to File Locations Reference.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@simonfaltum simonfaltum requested a review from eLysgaard December 3, 2025 09:23
Added guidance for Claude Code to ask users 4 key questions before
running the quickstart script:
1. Serving endpoint availability and name
2. App/bundle name customization preferences
3. Persistent chat history (database) requirements
4. Deployment timing (now vs later)

This ensures the script runs smoothly and matches user expectations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@simonfaltum
Copy link
Member Author

jenkins merge

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.

3 participants