Language Reference
A complete, condensed reference for the Vibe programming language.
Variables
Section titled “Variables”let count = 0 // Mutablelet name: text = "Alice" // With type annotationconst MAX: number = 100 // Immutableprivate let secret = "hidden" // Hidden from AI contextlet maybe: text = null // Null requires type annotation| Type | Description | Example |
|---|---|---|
text | String | "hello", 'world', `template` |
number | Numeric | 42, -3.14 |
boolean | Boolean | true, false |
json | Object/array | { key: "value" }, [1, 2] |
null | Null value | null |
text[] | Array of type | ["a", "b"] |
TypeName | Named structural type | let x: MyType |
Structural Types
Section titled “Structural Types”type Result { valid: boolean message: text}
// Nested typestype Outer { inner: Inner // Reference named type metadata: { // Inline nested object timestamp: number }}
// Arrays of typestype Team { players: Player[] }Strings & Interpolation
Section titled “Strings & Interpolation”let s1 = "double quotes"let s2 = 'single quotes'let s3 = `backticks formulti-line strings`
// All support {var} interpolationlet greeting = "Hello {name}!"
// Escape braces with backslashlet literal = "Use \{braces\} literally"Operators
Section titled “Operators”// Arithmetica + b a - b a * b a / b a % b
// Comparisona == b a != b a < b a > b a <= b a >= b
// Logical (keywords, not symbols)a and b a or b not aArrays & Objects
Section titled “Arrays & Objects”let arr = [1, 2, 3]let first = arr[0] // Index accesslet last = arr[-1] // Negative indexlet slice = arr[1:3] // Slice [2, 3]let concat = [1, 2] + [3, 4] // [1, 2, 3, 4]
let obj = { name: "Alice", age: 30 }let name = obj.name // Member access
// Array methodsarr.push(4) // Add element (mutates, returns array)let x = arr.pop() // Remove and return lastlet n = arr.len() // LengthControl Flow
Section titled “Control Flow”// If/else (conditions must be boolean)if count > 0 { print("positive")} else if count == 0 { print("zero")} else { print("negative")}
// For-in loopfor item in items { print(item)}
// Range loopfor i in 1..5 { print(i) // 1, 2, 3, 4, 5}
// While loopwhile count < 10 { count = count + 1}
// Break exits innermost loopfor i in items { if i == target { break }}Loop Context Modifiers
Section titled “Loop Context Modifiers”for item in items { ... } forget // Clear AI context each iterationfor item in items { ... } compress // Summarize contextfor item in items { ... } verbose // Keep full history (default)Functions
Section titled “Functions”function greet(name: text): text { return "Hello, " + name}
function add(a: number, b: number): number { return a + b}
// Export for use in other filesexport function helper(x: text): text { return x}AI Expressions
Section titled “AI Expressions”do - Single AI call
Section titled “do - Single AI call”let answer = do "Explain quantum computing"
// With type annotation (AI returns parsed value)let count: number = do "How many planets?"let items: text[] = do "List 5 programming languages"let data: json = do "Return a person object"
// With specific modellet result = do "Complex analysis" smartModel
// With context modelet result = do "Summarize" model default // Full historylet result = do "Process" model local // Current scope onlyvibe - Agentic AI with tools
Section titled “vibe - Agentic AI with tools”model agent = { name: "claude-sonnet-4-20250514", provider: "anthropic", apiKey: env("ANTHROPIC_API_KEY"), tools: [readFile, writeFile, bash]}
vibe "Read the config and update the version" agentPrompt Interpolation
Section titled “Prompt Interpolation”let article = "long text..."
// Reference syntax: AI sees variable in context (preferred)do "Summarize {article}"
// Expansion syntax: Value inlined into prompt textdo "Hello !{name}"Models
Section titled “Models”model myModel = { name: "claude-sonnet-4-20250514", // Required provider: "anthropic", // Required: anthropic, openai, google apiKey: env("ANTHROPIC_API_KEY"), // Required url: "http://custom/v1", // Optional: custom endpoint maxRetriesOnError: 3, // Optional: auto-retry thinkingLevel: "high", // Optional: none, low, medium, high, max tools: [tool1, tool2] // Optional: available tools}tool fetchUrl(url: text): text @description "Fetch content from a URL" @param url "The URL to fetch"{ ts(url) { const response = await fetch(url); return await response.text(); }}TypeScript Blocks
Section titled “TypeScript Blocks”// Pass Vibe variables as parameters (values are automatically resolved)let result = ts(x, y) { return x + y;}
// Named bindings with expressions (member, index, slice)let items = [10, 20, 30, 40]let first = ts(x=items[0]) { return x * 2; }let last = ts(x=items[-1]) { return x + 1; }let sub = ts(arr=items[1:3]) { return arr.length; }
// Complex operationslet parsed = ts(jsonString) { return JSON.parse(jsonString);}
// Async operationslet data = ts() { const response = await fetch('https://api.example.com'); return await response.json();}
// Dynamic importslet files = ts() { const { readdirSync } = await import('fs'); return readdirSync('.');}Async Execution
Section titled “Async Execution”// Parallel AI callsasync let a = do "Task A"async let b = do "Task B"async let c = do "Task C"// All run concurrently, auto-awaited when usedlet combined = process(a, b, c)
// Fire-and-forgetasync do "Log event" loggerasync vibe "Background task" agentError Handling
Section titled “Error Handling”Every value can carry error information:
let result = do "Risky operation"
// Check for errors (err is boolean)if result.err { let msg = result.errDetails.message let type = result.errDetails.type print("Error: " + msg)}
// Errors propagate through expressionslet a: number = nulllet b = 10let sum = a + b // sum.err is truelet doubled = sum * 2 // doubled.err is true (propagated)Imports
Section titled “Imports”// TypeScript filesimport { helper } from "./utils.ts"
// Vibe filesimport { myFunction, myModel } from "./lib.vibe"
// Utility functionsimport { uuid, now, random, jsonParse, jsonStringify } from "system/utils"
// AI toolsimport { readFile, writeFile, bash, glob, grep } from "system/tools"Core Functions
Section titled “Core Functions”Always available without import:
| Function | Description |
|---|---|
env(name, default?) | Get environment variable |
print(message) | Print to console |
Utility Functions
Section titled “Utility Functions”Import from "system/utils":
| Function | Description |
|---|---|
uuid() | Generate UUID v4 |
now() | Current timestamp (ms) |
random() / random(min, max) | Random number |
jsonParse(text) | Parse JSON string |
jsonStringify(value, pretty?) | Convert to JSON |
System Tools
Section titled “System Tools”| Tool | Description |
|---|---|
readFile(path, start?, end?) | Read file contents |
writeFile(path, content) | Write to file |
appendFile(path, content) | Append to file |
fileExists(path) | Check file exists |
listDir(path) | List directory |
edit(path, start, end, text) | Edit file lines |
glob(pattern, cwd?) | Find files |
grep(pattern, path, ignoreCase?) | Search contents |
mkdir(path, recursive?) | Create directory |
dirExists(path) | Check directory exists |
bash(cmd, cwd?, timeout?) | Run shell command |
Destructuring
Section titled “Destructuring”// From AI responselet { title: text, body: text } = do "Generate article"
// With private fieldslet { private apiKey: text, name: text } = do "Get credentials"
// Async destructuringasync let { x: number, y: number } = do "Get coordinates"Comments
Section titled “Comments”// Single-line commentlet x = 42 // Inline comment
/* Multi-line block comment */Operator Precedence
Section titled “Operator Precedence”- Assignment (
=) - Logical OR (
or) - Logical AND (
and) - Equality (
==,!=) - Comparison (
<,>,<=,>=) - Addition (
+,-) - Multiplication (
*,/,%) - Unary (
not,-) - Range (
..) - Postfix (
.,[],())