Getting Started with Cloving CLI

Cloving is a CLI tool that helps you generate code using AI. It integrates with popular AI chat models to generate code snippets, unit tests, and more based on your prompts.

What makes it different from other code generation tools is that it understands the context of your project and generates code that is relevant to that context.

The prompts generated by the cloving cli are designed to automatically gather context and provide transparency into the code generation process by allowing you to review and modify the generated prompt before sending it to an AI API endpoint.

Quickstart Without an Existing Project

If you want to get going without reading the documentation, here are a few commands to get you started:

npm install -g cloving@latest # install cloving globally

cloving generate shell --prompt "Create a Next.js app called myapp" # create a new project
cd myapp # cd into the project directory

cloving init # set up cloving in your existing project
cloving generate code --prompt "Build a dynamic todo list" # generate some code

git init # initialize a new git repository
git add . # stage the changes
cloving commit # run git commit with AI generated commit message

Here is a screencast of these commands in action:

Quickstart With an Existing Project

If you have an existing project you want to work with, here are a few commands to get you started:

npm install -g cloving@latest # install cloving globally

cd path/to/a/software/project

cloving init # set up cloving in your existing project
cloving generate code --prompt "refactor for cleanliness" -f App.tsx # refactor a file

cloving commit # run git commit with AI generated commit message

Here is a screencast of these commands in action:

Prerequisites

  • Node.js (version 20 or higher)
  • Git
  • API access to AI chat models (e.g., OpenAI GPT-4, Claude, Ollama, etc.)

Installation

You can install Cloving CLI in three different ways:

1. Global Installation via npm

npm install -g cloving@latest

This allows you to run cloving commands from anywhere in your terminal.

2. Run with npx

npx cloving [command]

This method downloads and executes Cloving on-the-fly, ensuring you always use the latest version.

3. Clone and Install from Source

git clone https://github.com/cloving-ai/cloving-cli.git
cd cloving-cli
yarn install
yarn link

Configuration

After installation, configure Cloving with your API key and preferred model:

cloving config

Alternatively you can configure cloving yourself by editing ~/.clovingconfig:

globalSilent=false

[models.claude.claude-3-5:sonnet-20240620]
apiKey=sk-ant-api03-...
primary=true
priority=100
silent=false
trust=true

[models.openai.gpt:4o]
apiKey=sk-proj-...
primary=false
priority=90
silent=false
trust=false

[models.openai.gpt:4o-mini]
apiKey=sk-proj-...
primary=false
priority=80
silent=false
trust=false

[models.ollama.llama3\.1:70b]
apiKey=
primary=false
priority=95
silent=true
trust=true

[models.gemini.gemini-1\.5:pro-latest]
apiKey=xAIzaS...
primary=false
priority=10
silent=false
trust=false

[models.mistral.mistral:large-latest]
apiKey=LnFhva...
primary=false
priority=5
silent=false
trust=false

Getting Started Without an Existing Code Project

If you don't have an existing code project to work with, you can create one with the cloving cli easily using cloving generate shell.

This command uses AI to generate a shell command based on a specified prompt. So if you forget the exact command for how to create a basic Next.js app, you can just ask cloving to help you.

Here are some examples:

Create a Next.js App Template

Here is how you can start building a Node.js app from scratch:

cloving generate shell --prompt "Create a Next.js app called myapp"

Create a Rails App Template

Cloving has short cuts in case you don't want to type it all out. Here is a shortcut to the cloving generate shell command that also works:

cloving g shell --prompt "Create a Rails app called myblog"

Create a Django App Template

And if cloving g shell is still too much typing you can run:

cloving g sh --prompt "Create a Django app called fantasticsaas"

Create a React Native App Template

And if cloving g sh --prompt is still too much typing you can run:

cloving generate shell -p "Create a React Native app called mymobileapp"

Here is an example of what the output would look like when you run this:

Getting Started With an Existing Code Project

The first thing you need to do with the cloving cli once you have a code project to work with is:

cloving init

This will set up Cloving in the current directory and create a cloving.json file with metadata about your application and its defaults and context.

This file helps Cloving understand your project and its context better so that it can generate better and more relevant code for you. Here is an example of the cloving.json for the cloving cli itself:

{
  "languages": [
    {
      "name": "TypeScript",
      "version": "5.5.3",
      "primary": true,
      "directory": "src",
      "extension": ".ts"
    }
  ],
  "frameworks": [
    {
      "name": "Node.js",
      "type": "Runtime environment",
      "primary": true,
      "directory": "src",
      "extension": ".js"
    }
  ],
  "testingFrameworks": [
    {
      "name": "Jest",
      "type": "Testing framework",
      "version": "29.7.0",
      "directory": "tests"
    }
  ],
  "buildTools": [
    {
      "name": "TypeScript Compiler (tsc)",
      "type": "Transpiler"
    },
    {
      "name": "Vite",
      "type": "Build tool",
      "version": "5.3.3"
    }
  ],
  "packageManager": "Yarn",
  "linters": [
    {
      "name": "ESLint",
      "version": "9.6.0"
    }
  ],
  "projectType": "Command-line tool"
}

Running cloving init will create a similar file for your project with the relevant metadata and context.

Next Steps: Generating Code

Once you have set up Cloving in your project, you can start generating code with the following command:

cloving generate code --prompt "Setup a reactive todo list"

If you run that inside your Next.js app, it will already know you are working with a Next.js app and will generate code that is relevant to that context. If you run that inside your Rails app, it will generate code that is relevant to Rails. If you run that inside your Django app, it will generate code that is relevant to Django.

This is how Cloving works and how it helps you generate code that is relevant to your project and its context.

Next Steps: Generating Unit Tests

Once you have set up Cloving in your project, you can start generating unit tests with the following command:

cloving generate unit-tests -f src/utils/config_utils.ts src/utils/git_utils.ts

If you run that inside your project, Cloving will generate unit tests for the specified files. The generated unit tests will be relevant to the context of your project and the files you specified.

This is how Cloving works and how it helps you generate unit tests that are relevant to your project and its context.