Skip to content

Creating Habits

This guide covers all the ways to create habits: writing YAML/JSON directly (Habit as Code) or using the visual Base editor.

Option #1: HaC/WaC/AaC: Habit as Code

The most powerful way to create habits is writing them directly as YAML or JSON files. This approach, called Habit as Code (HaC), Workflow as Code (WaC) or Automation as Code (AaC), gives you:

  • Version control - Track changes with Git, review PRs, rollback easily
  • Reproducibility - Same config always produces same behavior
  • Templating - Use environment variables and dynamic values
  • CI/CD integration - Deploy habits through your existing pipelines

Quick Start: Your First WaC Habit

yaml
id: hello-world
name: Hello World Demo
description: A simple hello world habit using @ha-bits/bit-hello-world

# This habit demonstrates the bit-hello-world module:
# - Returns "hello there" when param1="hello" and param2="world"
# - Returns "Nah!" otherwise

input:
  - name: param1
    type: string
    displayAs: text
    label: First Parameter
    description: Enter the first word (use "hello" for greeting)
    default: hello
    required: true

  - name: param2
    type: string
    displayAs: text
    label: Second Parameter
    description: Enter the second word (use "world" for greeting)
    default: world
    required: true

nodes:
  - id: say-hello
    type: action
    data:
      framework: bits
      source: npm
      module: "@ha-bits/bit-hello-world"
      operation: greet
      params:
        param1: "{{habits.input.param1}}"
        param2: "{{habits.input.param2}}"

edges: []

output:
  greeting:
    value: "{{say-hello}}"
    type: string
    displayAs: text
    label: Greeting
yaml
version: "1.0"
name: "Hello World"
workflows:
  - id: hello-world
    path: ./habit.yaml
    enabled: true
  - id: hello-world-env
    path: ./habit-env.yaml
    enabled: true
    
server:
  port: 13000
  host: "0.0.0.0"
  frontend: ./frontend

logging:
  level: info
  outputs: [console]
  format: text
  colorize: true

Run it:

bash
npx habits cortex --config stack.yaml

Test it:

bash
curl http://localhost:13000/api/hello-world

Key WaC Concepts

ConceptDescription
workflowsArray of automation workflows or paths to workflow files
nodesSequential steps in the workflow
inputsInput parameters with types and defaults
paramsConfiguration for each node using {{habits.input.x}} syntax

Using Environment Variables

Reference secrets and config without hardcoding:

yaml
Authorization: "Bearer {{habits.env.API_TOKEN}}"

Then set in your environment:

bash
export API_TOKEN=secret123

For more details on the schema, see the Habit Schema reference.


Option #2: Visual Builder: Base UI

Base is the visual builder component that allows you to construct habits from individual bits. It provides an intuitive interface for designing automation workflows without writing code.

Base Overview


Getting Started with Base

Prerequisites

  • Node.js 18 or higher
  • pnpm (recommended) or npm
  • Git

Running Base

bash

# Option #1: Run base using habits if installed globally 
habits base

# Option #2: Run base using npx
npx habits base

# Option #3: Start the Base UI (development mode), after cloning code
pnpm nx dev @ha-bits/base

Access Points

EndpointURLDescription
Base UIhttp://localhost:3001Visual Workflow Builder
Base APIhttp://localhost:3001/api (Proxied to http://localhost:3000)REST API Backend

Accessing Base

To access the Base builder:

  1. Navigate to http://localhost:3001 in your browser
  2. You'll be presented with the habit builder interface

Creating a New Habit

Step 1: Start a New Habit

Click the "Reset" button to create a fresh automation workflow.

Step 2: Add Bits to Your Habit

Bits are the individual nodes that make up your habit. Each bit represents a single action or step in your automation.

  1. Browse the available bits in the sidebar
  2. Drag and drop bits onto the canvas
  3. Connect bits together to define the flow

Step 3: Configure Each Bit

Click on any bit to configure its settings:

  • Select Doer: Each bit can have multiple Doers/Actions and Watchers/Triggers.
  • Input parameters: Define what data the bit receives
  • Output mapping: Specify how the bit's output is used
  • Credentials: Set up authentication if required

Step 4: Connect Bits Together

Create connections between bits to define the execution flow:

  1. Click on a bit's output handle
  2. Drag to another bit's input handle
  3. Release to create the connection

Editing Existing Habits

Opening a Habit for Editing

  1. Navigate to your habits list
  2. Click on the habit you want to edit
  3. The habit will open in the Base editor

Modifying Bits

  • Edit: Click on a bit to modify its configuration
  • Delete: Select a bit and press Delete or use the context menu
  • Move: Drag bits to reposition them on the canvas
  • Delete Edge: Click on a connection and press Delete
  • Reroute Edge: Delete the existing connection and create a new one

Creating Frontend

You can use base also to edit UI of the habit by clicking the UI button. This is still experimental.

Habits Base UI EditorHabits Base UI Editor - Automation Frontend Builder

You can use AI to directly generate a UI that can work with the logic. Use Intersect for best results, if not possible, use Anthropic Opus or Gemini Pro models.

Best Practices

  1. Start Simple: Begin with small habits and gradually add complexity
  2. Name Your Bits: Use descriptive names to make your habit readable
  3. Test Incrementally: Test each bit as you add it to catch issues early
  4. Document Your Habits: Add comments or descriptions to explain the workflow purpose

Troubleshooting

Common Issues

IssueSolution
Bits not connectingEnsure you're connecting output to input handles
Configuration not savingCheck for validation errors in the bit settings
Habit not appearing in listRefresh the page and try saving again

Next Steps

Once you've created your habit, learn how to run it using Cortex in the Running Automations guide.

Released under the AGPL-3.0 License.