Core modules for the mlld prompt scripting language.
Easy AI integration for your mlld scripts:
/import { claude, llm, codex, gemini } from @mlld/ai-cli
/var @response = @claude.ask("What's the capital of France?")
/show `Claude says: @response`
/var @answer = @llm.ask("You are a helpful assistant", "Explain quantum computing in one sentence")
/show `LLM says: @answer`
Process data arrays with powerful operations:
/import { filter, sortBy, pluck, sum, groupBy } from @mlld/array
/var @users = [
{"name": "alice", "age": 30, "dept": "engineering"},
{"name": "bob", "age": 25, "dept": "design"},
{"name": "charlie", "age": 35, "dept": "engineering"}
]
/var @engineers = @filter(@users, "dept", "engineering")
/var @sortedByAge = @sortBy(@users, "age")
/var @names = @pluck(@users, "name")
/var @totalAge = @sum(@users, "age")
/show `Engineers: @engineers`
/show `Total age: @totalAge`
Essential utilities for building complex conditional logic in mlld:
/import { equals, contains, gt, and, isEmpty } from @mlld/conditions
/var @users = ["alice", "bob", "charlie"]
/var @threshold = 10
/var @count = 15
/when @and(@gt(@count, @threshold), @contains(@users, "alice")) => /show "High count with Alice present"
/when @isEmpty(@users) => /show "No users found"
/when @equals(@count, 15) => /show "Exact match!"
Essential environment management:
/import { env } from @mlld/env
>> Validate required variables
/var @valid = @env.validate(["API_KEY", "DATABASE_URL"])
/when @valid.valid => /show "All environment variables present"
/when !@valid.valid => /show `Missing: @valid.missing`
>> Get with fallback
/var @port = @env.get("PORT", "3000")
/show `Server running on port @port`
>> Check if in CI
/when @env.isCI() => /show "Running in CI environment"
Recalculates relative links when moving content between directories:
/import { fixRelativeLinks } from @mlld/fix-relative-links
/var @content = "See the [docs](../docs/guide.md) for details."
>> The function asks: "How do I get from dist/ to src/docs/guide.md?"
>> Answer: "../src/docs/guide.md"
/var @fixed = @fixRelativeLinks(@content, "src/modules", "dist")
>> ↑ ↑
>> where content thinks it is where it's actually going
Provides basic file system checks that return truthy/falsy values for use with conditions:
/import { fileExists, dirExists, pathExists } from @mlld/fs
/when @fileExists("config.json") => /show "Config file found!"
/when @dirExists("src") => /show "Source directory exists"
/when @pathExists("README.md") => /show "README is available"
Common GitHub operations made easy:
/import { github } from @mlld/github
>> Get PR information
/var @prData = @github.pr.view(123, "owner/repo")
/show `PR Title: @prData.title`
>> Post a comment
/run @github.pr.comment(123, "owner/repo", "LGTM! 🚀")
>> Check if user is a collaborator
/var @isCollab = @github.collab.check("octocat", "owner/repo")
/when @isCollab => /show "User has write access"
Quick HTTP requests with automatic JSON handling:
/import { http } from @mlld/http
/run @http.get("https://api.github.com/users/octocat")
/run @http.post("https://httpbin.org/post", {"message": "hello"})
/run @http.auth.get("https://api.github.com/user", @token)
/var @userData = @http.fetch.get("https://api.github.com/users/octocat")
/show `User: @userData.name`
Debug your pipelines by inserting logging between transformations:
/import { log, logVerbose, logJson } from @mlld/pipelog
>> Simple pipeline debugging
/var @result = @data | @json | @log | @uppercase | @log
>> Verbose logging with full context
/var @processed = @fetchData() | @logVerbose | @transform
>> Structured JSON logging for parsing
/var @output = @input | @logJson | @process
All loggers output to stderr, ensuring your pipeline data flows unchanged to stdout.
Common string operations:
/import { title, camelCase, split, join, trim, includes } from @mlld/string
/var @name = "john doe smith"
/var @formatted = @title(@name)
/var @slug = @camelCase(@formatted)
/var @words = @split(@name, " ")
/var @rejoined = @join(@words, "-")
/when @includes(@name, "doe") => /show "Contains 'doe'"
/show `Formatted: @formatted`
Test your mlld scripts with simple assertions:
/import { eq, deepEq, ok, contains } from @mlld/test
/var @result = @calculateSum(2, 3)
/when @eq(@result, 5) => /show "✓ Sum calculation correct"
/var @data = { "name": "test", "items": [1, 2, 3] }
/when @deepEq(@data.items, [1, 2, 3]) => /show "✓ Array matches"
/when @contains(@output, "success") => /show "✓ Output contains success message"
/import { time } from @mlld/time
>> Use the built-in @now
/var @today = @time.format(@now, "YYYY-MM-DD")
/var @tomorrow = @time.add(@now, { days: 1 })
>> Compare dates
/when @time.compare.before(@dateA, @dateB) => /show "DateA is earlier"
>> Human-readable relative time
/var @updated = @time.relative(@lastModified) >> "2 hours ago"
>> Work with durations
/var @workWeek = @time.duration.days(5)
/var @deadline = @time.add(@now, @workWeek)
Policy defaults for production:
/import policy @prod from "@mlld/production"
/show @mx.policy.activePolicies
Policy defaults for development:
/import policy @dev from "@mlld/development"
/show @mx.policy.activePolicies
Policy defaults for untrusted code:
/import policy @sandbox from "@mlld/sandbox"
/show @mx.policy.activePolicies
Generated by the llm/run/build.mld script.