Blackbird

Flight Manual · 04

Turn programs in Lua

Every turn in Blackbird is a short Lua 5.5.1 script read fresh into a clean VM at the start of the turn. Edit the file and the very next turn runs your version—no rebuild, no restart.

Run your own turn loop

Copy the installed turn.lua, edit it, and point Blackbird at your file—or switch live inside a session with /workflow FILE (/session shows the active path).

Shell · Copy & launch custom workflow
cp "$HOME/.local/lib/blackbird/current/share/blackbird/programs/turn.lua" my-turn.lua
blackbird --workflow my-turn.lua

Want to test an expression live? /lua CODE runs a one-off snippet right inside the session:

TUI · One-off Lua
/lua print(blackbird.json.encode(blackbird.stats()))

The default loop

The heart of programs/turn.lua (abridged; the shipped file also caps output sizes for exec and read_file):

Lua · programs/turn.lua
while true do
  local response = blackbird.request()
  local calls = 0
  for _, item in ipairs(response.output) do
    if item.type == "function_call" then
      calls = calls + 1
      local result = blackbird.call(item.name, item.arguments, { call_id = item.call_id })
      blackbird.append({
        { type = "function_call_output", call_id = item.call_id, output = result },
      })
    elseif item.type == "message" then
      blackbird.present(item)
    end
  end
  if blackbird.restarting() or calls == 0 then
    return
  end
end

Host API

FunctionRole
blackbird.request(opts)Call the model using live context; optionally override model, instructions or tools for that request.
blackbird.call(name, args)Invoke any tool the model has (read_file, write_file, edit_file, exec, etc.).
blackbird.append(items)Append items to the conversation context.
blackbird.present(item)Render a finished reply (blackbird.display(text) and print emit plain text).
blackbird.stats()Return exact context byte sizes.
blackbird.blocks(), read_block(id), compact(args), pin(ids)Inspect and compact context directly from Lua (Managing context).
blackbird.json.encode / decodeEncode and decode JSON.
blackbird.define_tool(def)Register a new Lua tool; available after the defining program exits cleanly and preserved across reopens.

The model has its own lua tool with the exact same API, so it can write small orchestration scripts on the fly.

VM rules & hooks

VM boundaries

Standard libraries are base, coroutine, table, string, math and utf8. There is no io, package, debug, dofile or loadfile, and os exposes only time, clock and difftime.

Globals reset every turn. Keep state in files or context—and remember Lua isn't a security sandbox because any script can call exec.

Five hook events

Hooks run on turn start, turn end, before tool call, after tool call, and context compaction. A hook can observe, transform context, or refuse a tool call before it runs.

Configure via program_config (active next turn). Inspect with /hooks, /hooks history, /hooks enable|disable NAME, and /hooks explain JSON.

Workflows as slash commands

Lua workflows can also expose themselves as slash commands. Every new session ships with /ultracode TASK, which runs the standard loop with extra instructions for careful, checked coding.