Built-in Functions
Core Functions
Section titled “Core Functions”These functions are always available without any import:
// No import needed - available everywhereprint("Hello, World!")let apiKey = env("ANTHROPIC_API_KEY")Print to console:
print("Hello, World!")print(someVariable)print({ key: "value" })| Parameter | Type | Description |
|---|---|---|
message | any | Value to print |
Get environment variable:
let apiKey = env("ANTHROPIC_API_KEY")let port = env("PORT", "3000") // With default value| Parameter | Type | Description |
|---|---|---|
name | text | Environment variable name |
defaultValue | text? | Default if not set |
| Returns | text | Variable value |
Access CLI arguments passed after the .vibe filename:
let all = args() // All args as text[]let first = args(0) // Arg at index (or null)let name = args("name") // Value of --name flag (or null)| Parameter | Type | Description |
|---|---|---|
| (none) | Returns all args as array | |
index | number | Returns arg at index (or null) |
name | text | Returns value of --name flag (or null) |
| Returns | text[] / text / null | Depends on argument |
Named flags return "" (empty string) for boolean-style flags like --dry-run. Returns null when the flag is not present.
hasArg
Section titled “hasArg”Check if a CLI flag is present:
if hasArg("verbose") { print("Verbose mode enabled")}| Parameter | Type | Description |
|---|---|---|
name | text | Flag name without dashes |
| Returns | boolean | Whether flag is present |
Utility Functions
Section titled “Utility Functions”Import from "system/utils":
import { uuid, now, random, jsonParse, jsonStringify } from "system/utils"Generate UUID v4:
let id = uuid() // "550e8400-e29b-41d4-a716-446655440000"| Returns | text | UUID string |
Current timestamp in milliseconds:
let timestamp = now() // 1705123456789| Returns | number | Unix timestamp (ms) |
random
Section titled “random”Generate random number:
let r = random() // 0.0 to 1.0let n = random(1, 10) // 1 to 10 (integer)| Parameter | Type | Description |
|---|---|---|
min | number? | Minimum (inclusive) |
max | number? | Maximum (inclusive) |
| Returns | number | Random number |
jsonParse
Section titled “jsonParse”Parse JSON string:
let data = jsonParse('{"name": "Alice"}')| Parameter | Type | Description |
|---|---|---|
text | text | JSON string |
| Returns | json | Parsed object |
jsonStringify
Section titled “jsonStringify”Convert to JSON string:
let str = jsonStringify({ name: "Alice" })let pretty = jsonStringify({ name: "Alice" }, true)| Parameter | Type | Description |
|---|---|---|
value | json | Value to stringify |
pretty | boolean? | Pretty print (default: false) |
| Returns | text | JSON string |
System Tools
Section titled “System Tools”Import from "system/tools" for AI tool use:
import { readFile, writeFile, bash } from "system/tools"
model agent = { tools: [readFile, writeFile, bash]}readFile
Section titled “readFile”Read file contents:
let content = readFile("data.txt")let lines = readFile("data.txt", 1, 10) // Lines 1-10| Parameter | Type | Description |
|---|---|---|
path | text | File path |
startLine | number? | Starting line (1-indexed) |
endLine | number? | Ending line |
| Returns | text | File contents |
writeFile
Section titled “writeFile”Write to file:
writeFile("output.txt", "Hello, World!")| Parameter | Type | Description |
|---|---|---|
path | text | File path |
content | text | Content to write |
| Returns | boolean | Success |
appendFile
Section titled “appendFile”Append to file:
appendFile("log.txt", "New entry\n")| Parameter | Type | Description |
|---|---|---|
path | text | File path |
content | text | Content to append |
| Returns | boolean | Success |
fileExists
Section titled “fileExists”Check if file exists:
if fileExists("config.json") { // ...}| Parameter | Type | Description |
|---|---|---|
path | text | File path |
| Returns | boolean | Exists |
listDir
Section titled “listDir”List directory contents:
let files = listDir("./src")| Parameter | Type | Description |
|---|---|---|
path | text | Directory path |
| Returns | text[] | File/folder names |
Edit specific lines in file:
edit("file.txt", 5, 10, "new content")| Parameter | Type | Description |
|---|---|---|
path | text | File path |
startLine | number | Start line (1-indexed) |
endLine | number | End line |
newText | text | Replacement text |
| Returns | text | Updated content |
Find files by pattern:
let tsFiles = glob("**/*.ts")let srcFiles = glob("*.js", "./src")| Parameter | Type | Description |
|---|---|---|
pattern | text | Glob pattern |
cwd | text? | Working directory |
| Returns | text[] | Matching paths |
Search file contents:
let matches = grep("TODO", "./src", true)| Parameter | Type | Description |
|---|---|---|
pattern | text | Search pattern |
path | text | File/directory |
ignoreCase | boolean? | Case insensitive |
| Returns | json[] | Matches with line info |
Create directory:
mkdir("./output")mkdir("./a/b/c", true) // Recursive| Parameter | Type | Description |
|---|---|---|
path | text | Directory path |
recursive | boolean? | Create parents |
| Returns | boolean | Success |
dirExists
Section titled “dirExists”Check if directory exists:
if dirExists("./output") { // ...}| Parameter | Type | Description |
|---|---|---|
path | text | Directory path |
| Returns | boolean | Exists |
Execute shell command:
let result = bash("npm run build")let result = bash("ls -la", "./src")let result = bash("slow-command", ".", 60000)| Parameter | Type | Description |
|---|---|---|
command | text | Shell command |
cwd | text? | Working directory |
timeout | number? | Timeout (ms) |
| Returns | json | { stdout, stderr, exitCode } |
runCode
Section titled “runCode”Run code snippet:
let result = runCode("python", "print('Hello')")let result = runCode("javascript", "console.log(1+1)")| Parameter | Type | Description |
|---|---|---|
language | text | Language name |
code | text | Code to run |
| Returns | json | Execution result |
Array Methods
Section titled “Array Methods”Add element to array (mutates array, returns array for chaining):
let items: text[] = []items.push("first")items.push("second")
// Chaininglet arr = [].push(1).push(2).push(3)| Parameter | Type | Description |
|---|---|---|
element | any | Element to add |
| Returns | array | The array (for chaining) |
Remove and return last element:
let items = [1, 2, 3]let last = items.pop() // 3// items is now [1, 2]| Returns | any | The removed element |
Get length of array or string:
let arr = [1, 2, 3, 4, 5]let count = arr.len() // 5
let str = "hello"let length = str.len() // 5| Returns | number | Length |