Skip to content

ykhli/cli-arcade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

cli-arcade

Screenshot 2025-10-08 at 2 00 18โ€ฏPM

An AI-powered CLI agent that generates and edits interactive CLI games from natural language prompts, with Relace integration for cloud-backed version control.

Stack: Relace Repos, OpenAI, Cursor

Table of Contents

Features

  • ๐ŸŽฎ Generate CLI games from natural language prompts
  • โœ๏ธ Edit existing games with AI assistance
  • โ˜๏ธ Relace integration as source of truth for version control
  • ๐Ÿ‘€ Live preview with auto-restart
  • ๐ŸŽจ Beautiful CLI interface with colored output
  • ๐ŸŽฏ Interactive mode for continuous development
  • ๐Ÿ”„ Smart diff-based updates (AI generates changes โ†’ Relace โ†’ local sync)

Installation

npm install

Setup

  1. Create a .env file with your API keys:
OPENAI_API_KEY=your_openai_api_key
RELACE_API_KEY=your_relace_api_key
  1. Install dependencies:
npm install

Usage

Interactive Mode (Recommended)

# Start interactive mode
npm start
# or
node src/index.js

Note: If API keys aren't configured, interactive mode will prompt you to enter them automatically!

Command Line Interface

# Generate a CLI game
vibe generate "Create a number guessing game"

# Start preview server
vibe preview

# List all local projects
npm run list

# Delete a single project
npm run delete


## Interactive Commands

When in interactive mode, you can use these commands:

### Creating New Games

- `generate <prompt>` - Generate a new CLI game from prompt

### Editing Existing Games

- `select` - Choose a game to work on
- `edit <prompt>` - Edit the selected game with AI (auto-runs preview after)

### Management

- `preview` - Start/restart preview server for current game
- `delete` - Delete a project (local + Relace repo)
- `status` - Show current status and selected project
- `help` - Show help message
- `exit` - Exit interactive mode

## Examples

### Generate CLI Games


vibe> generate "Create a number guessing game where the player has 5 tries"


vibe> generate "Create a word scramble game with a score system"


vibe> generate "Create a simple RPG battle game with health and attack commands"



### Edit an Existing Game


vibe> select


# Choose a game from the list

vibe> edit "add a timer that counts down from 60 seconds"

# AI generates diff โ†’ commits to Relace โ†’ pulls updated code โ†’ starts preview

vibe> edit "make the game harder by reducing tries to 3"

# Iteratively improve the selected game

vibe> edit "add colors using chalk to make output more fun"

# Keep editing with natural language

How the Edit Flow Works

When you run edit <prompt>:

  1. ๐Ÿค– AI generates JSON diff operations (not full code, just the changes)
  2. โ˜๏ธ Commits diff to Relace repo (Relace becomes source of truth)
  3. ๐Ÿ“ฅ Pulls latest code from Relace (syncs local files with cloud)
  4. ๐ŸŽฎ Starts preview server (runs the updated game)

This ensures Relace is always the authoritative source, enabling proper version control and multi-device workflows.

Generated Game Structure

Each CLI game is a single-file Node.js program saved in its own folder under vibe_projects/:


vibe_projects/
โ”œโ”€โ”€ a-number-guessing-2025-10-08T05-16-00-706Z/
โ”‚ โ”œโ”€โ”€ game.js # Single game file with all logic
โ”‚ โ”œโ”€โ”€ package.json # Dependencies and metadata
โ”‚ โ””โ”€โ”€ node_modules/ # Installed packages
โ””โ”€โ”€ a-word-scramble-2025-10-08T06-20-29-325Z/
โ”œโ”€โ”€ game.js
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ node_modules/

Simple structure:

  • game.js - The complete game in a single file
  • package.json - Dependencies (like chalk, inquirer) and Relace metadata
  • Project folders are named based on the prompt and timestamp to avoid conflicts

Relace Integration

Repo ID Tracking

Each generated project automatically stores its Relace repo ID in package.json:

{
  "name": "a-number-guessing-game",
  "version": "1.0.0",
  ...
  "vibe": {
    "generated": "2025-10-08T12:00:00.000Z",
    "relaceRepoId": "9195bae7-04f7-406e-a13b-9e77b8744320",
    "lastBackup": "2025-10-08T12:05:00.000Z"
  }
}

This metadata enables:

  • ๐Ÿ”— Track which Relace repo belongs to which local project
  • ๐Ÿ—‘๏ธ Delete the correct repo when deleting a project
  • ๐Ÿ”„ Update the same repo on subsequent edits
  • ๐Ÿ“ฆ Preserve local metadata when pulling from Relace

Source of Truth Architecture

Relace repos serve as the source of truth for game code:

  1. All edits go through Relace first - AI generates diff operations that are committed to Relace
  2. Local files sync from Relace - After committing, we pull the latest code from Relace
  3. Metadata preserved locally - Special handling ensures relaceRepoId is never lost during sync

API Integration

OpenAI

  • Used for generating and editing game code
  • Requires OpenAI API key
  • Uses GPT-4 for intelligent code generation
  • For edits: generates JSON diff operations instead of full code

Relace

  • Cloud-based version control for generated games
  • Requires Relace API key
  • Automatic backup after each generation
  • Diff-based updates for efficient editing
  • Clone operation to sync code from cloud to local

Preview Server

The preview server:

  • Runs CLI games in an isolated process
  • Auto-restarts when files change (during development)
  • Provides interactive terminal experience
  • Shows game output in real-time

Deleting Projects

To delete a single project:

npm run delete

Or in interactive mode:

vibe> delete

This will:

  1. Show you a list of available projects
  2. Let you select which one to delete
  3. Ask for confirmation
  4. Delete the local project folder
  5. Delete the associated Relace repo (reads relaceRepoId from package.json)

How Edit Works (Technical Details)

Relace as Source of Truth

  1. AI generates JSON diff operations
  2. Commit diff to Relace using @relace-ai/relace SDK
  3. Pull latest code from Relace using clone()
  4. Save files locally (preserving package.json metadata)
  5. Start preview server

Example Diff Operations:

[
  {
    "type": "write",
    "filename": "game.js",
    "content": "// Updated game code here"
  },
  {
    "type": "delete",
    "filename": "old-file.js"
  },
  {
    "type": "rename",
    "old_filename": "utils.js",
    "new_filename": "helpers.js"
  }
]

Troubleshooting

API Key Issues

# Start interactive mode, it will prompt for keys
npm start

"No Relace repo found" Error

Make sure to run preview at least once before editing:

vibe> select
vibe> preview
vibe> edit "your changes"

The first preview creates a Relace backup, subsequent edits update that same repo.

Relace Sync Issues

Check your Relace API key and ensure you have sufficient quota. The edit command will show detailed logs including the update result.

Development

# Run with detailed logs
node --no-deprecation src/index.js

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors