santoku
santoku

santoku

A Lua framework for building applications end to end

Lua 5.1 from the build system to the server to the browser. Every example on this site runs in your browser. Edit one and run it.


santoku targets Lua 5.1, because 5.1 is the version its platforms actually share. LuaJIT implements 5.1 and OpenResty embeds LuaJIT, so server code, client code and the build harness all run the same language. Compiled to WebAssembly, the 5.1 core is smaller to embed, and its single number type sidesteps the integer and float split introduced in 5.3, which keeps numeric values crossing the JavaScript boundary simple. Support for newer versions is meant to come from compatibility shims layered over the 5.1 core rather than version branches in the tree; contributions and design ideas for that layer are welcome.

santoku-cli

View on LuaRocks

the toku command line: build, test, install, release, license notices, and scaffolding for santoku projects

santoku-cli ships toku, the command-line front end of the framework. Every santoku rock, and this documentation site itself, is built, tested and released with it. santoku-make drives the project lifecycle from a make.lua descriptor, and the standalone utilities expose santoku-template, santoku-bundle and an instrumented interpreter.

Details
  • The project lifecycle commands are init, test, install, pack, release, env and clean, plus build, start and stop for web projects.
  • The make.lua descriptor is plain Lua.
  • santoku-make renders sources into a build tree and installs dependencies with luarocks into a private lua_modules.
  • Specs run against that tree, and the same tree feeds install and the luarocks release flow.
  • The standalone utilities are template, bundle, lua and spec.
  • This tab covers the whole command surface, basics to advanced.
  • toku runs processes and touches the real filesystem, so every example here is for reading.

The command surface

The code lists every subcommand, with its description verbatim from the argparse declarations in bin/toku.tk.lua.

toku init       Initialize a new project
toku license    Write LICENSE, per-file SPDX headers and THIRD-PARTY-NOTICES.txt from make.lua
toku test       Run tests
toku spec       Run spec files, and the specs under directories, with the spec runner, outside any project build
toku install    Install the project
toku pack       Build rockspec and tarball without releasing
toku release    Release the project
toku env        Print shell exports of the project's test tree, the one toku run uses, for eval
toku clean      Clean build artifacts
toku build      Build the project, and reload the running server when the build changes the dist
toku start      Build and start the server, or rebuild and reload it when it already runs
toku stop       Stop the server
toku template   Process templates
toku bundle     Create standalone executables
toku lua        Run the lua interpreter on a file
toku run        Build the project's test tree, then run a command with the tree's bin, LUA_PATH and LUA_CPATH; lua runs the tree's interpreter
toku setup      Maintain the toku-managed lua 5.1 toolchain (provisioned by setup-toku.sh from santoku.dev)
toku skills     Install the santoku agent skills from santoku.dev into your home directory, never into a project
toku doctor     Diagnose the managed toolchain, PATH wiring and installed agent skills
toku luarocks   Run the managed luarocks
toku luac       Run the resolved luac
toku resty      Run the managed OpenResty resty script
toku openresty  Run the managed OpenResty nginx binary
toku serve      Serve a directory over HTTP with the managed OpenResty
Illustrative: runs outside the browser.
Details
  • Each rebuilt target prints one [make] line.
  • Commands that print phase lines write those trace lines to build/<env>/toku.log. toku env and toku run print them on stderr, so stdout carries only the exports or the command's output.
  • build, start and stop apply to web projects.
  • A server-only API project is a web project to the harness, so build, start and stop apply to it too.
  • install and pack apply to library projects only.
  • toku -v or --version prints santoku-cli and its version, then exits.
  • An unknown command word runs toku-<word> from PATH. The managed toolchain is on PATH, and the remaining arguments pass through.
  • So a toku-browser executable answers toku browser. With no such executable, toku reports the unknown command.
  • A failing command prints toku: and the error on stderr, then a hint to set TOKU_TRACE=1 for the full Lua traceback. It exits 1.

Scaffold a library

toku init extracts an example, renames every tokuboilerplate occurrence to your project name, and runs git init. The name must match ^[a-z][a-z0-9-]*$.

$ toku init my-lib
Initialized empty Git repository in /home/you/my-lib/.git/
warning: copyright is not set, so this project is all rights reserved with no notice; set it in make.lua
warning: license is not set, so this project is all rights reserved; set it in make.lua
Created my-lib from the lib example: A library with a command

Next steps:
  cd my-lib
  toku test     # Run tests
  toku install  # Install locally

$ find my-lib -type f -not -path "*/.git/*" | sort
my-lib/.gitignore
my-lib/bin/my-lib.lua
my-lib/lib/my_lib.lua
my-lib/lib/my_lib/capi.c
my-lib/lib/my_lib/migrations.tk.lua
my-lib/lib/my_lib/store.lua
my-lib/make.lua
my-lib/res/lib/migrations/0.0.1.sql
my-lib/test/spec/my_lib.lua
Illustrative: runs outside the browser.
Details
  • --example NAME picks the example. With no --example, toku init creates the lib example. --example needs santoku-cli 8.0.0 and santoku-make 13.0.0.
  • An unknown name lists every example with its summary and fails before init writes anything. toku init --help lists them too.
  • The examples page shows each example's files: https://santoku.dev/examples
  • --here uses the current directory and its name, and --dir picks the destination.
  • Either target must be empty or missing, or init refuses before it writes anything.
  • The scaffold is a working rock: a sqlite-backed library with a migration, a C extension (capi.c), a bin/ entry point and a passing spec suite.
  • --license ID --copyright HOLDER sets both fields in make.lua and writes LICENSE and SPDX headers.
  • --copyright alone writes a one-line all-rights-reserved LICENSE.
  • With neither flag, as in the code, the scaffold has no LICENSE and no license field, and toku warns.
  • --comments writes a note into each file that explains it and links the santoku.dev page that covers it. It needs santoku-cli 5.1.0 and santoku-make 9.1.0.
  • https://santoku.dev/santoku-cli/init shows every scaffold, with and without --comments.

Scaffold a resty tool since santoku-cli 8.0.0 and santoku-make 13.0.0

toku init --example resty scaffolds a library whose command and specs run under OpenResty's resty CLI, with santoku.async and santoku-http over santoku-resty.

$ toku init --example resty my-tool
$ cd my-tool
$ toku test --resty
$ toku install --bundled --resty
$ my-tool https://santoku.dev
$ find . -type f -not -path "./.git/*" -not -path "./build/*" | sort
./.gitignore
./bin/my-tool.lua
./lib/my_tool.lua
./make.lua
./test/spec/my_tool.resty.lua
Illustrative: runs outside the browser.
Details
  • lib/<mod>.lua takes a runtime and an http backend and fetches a list of URLs at once, one task per URL.
  • bin/<name>.lua passes santoku.resty.async and santoku.resty.socket and prints each status, byte count and URL.
  • test/spec/<mod>.resty.lua hands the module a fake backend whose requests sleep, and checks that the sleeps overlap.
  • toku test --resty runs the spec. A native toku test skips it by its .resty.lua name.
  • toku install --bundled --resty installs the command with its OpenResty tree.
  • --license, --copyright and --comments work as for every example.

The project descriptor

Everything toku knows about a project comes from make.lua, a plain Lua file that returns { env = ... }. The code is santoku-cli's own descriptor.

local release = require("santoku.make.release")

local env = {
  name = "santoku-cli",
  version = "5.0.0-1",
  wasm = false,
  variable_prefix = "TK_CLI",
  license = "MIT",
  copyright = "Birch Point SWE",
  dependencies = {
    "lua == 5.1",
    "santoku >= 4.0.0, < 5.0.0",
    "santoku-fs >= 2.2.0, < 3.0.0",
    "santoku-template >= 3.0.0, < 4.0.0",
    "santoku-bundle >= 3.0.0, < 4.0.0",
    "santoku-system >= 2.2.0, < 3.0.0",
    "santoku-test-runner >= 2.0.3, < 3.0.0",
    "santoku-make >= 9.0.0, < 10.0.0",
    "argparse >= 0.7.1-1, < 1.0.0",
    "lua-cjson >= 2.1.0",
  },
}

env.homepage = "https://santoku.dev/" .. env.name
env.release = {
  push = release.git_push(),
  host = release.s3_upload({ bucket = "birchpointswe-releases", base_url = "https://releases.santoku.dev" }),
  registry = release.luarocks_upload(),
}

return { env = env }
Illustrative: runs outside the browser.
Details
  • name and version become the rockspec.
  • dependencies are luarocks constraints.
  • env.release makes toku release available.
  • Computed fields are plain Lua expressions.
  • The rockspec's source url comes from the release host, so the descriptor never spells it out.

toku license

toku license writes LICENSE and a two-line SPDX header into every tracked source file, from make.lua's license and copyright. --check writes nothing, prints each problem and exits nonzero.

$ toku license --check
toku license: LICENSE doesn't name 2023 Birch Point SWE
toku license: lib/my_lib/capi.c: missing header

$ toku license
lib/my_lib/capi.c: added a header
LICENSE written for 2023 Birch Point SWE

$ head -2 lib/my_lib/capi.c
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2023 Birch Point SWE
Illustrative: runs outside the browser.
Details
  • The header lines are SPDX-License-Identifier and SPDX-FileCopyrightText.
  • The header uses the file's own comment syntax and goes after any shebang or tk directive.
  • LICENSE holds the license text, fetched from the SPDX license list, then one section per vendored entry.
  • A stale header is replaced.
  • A file that already carries another notice is left alone and reported.
  • make.lua holds the license, the copyright holder and license_exclude. toku license takes no flags for them.
  • --year defaults to the year of the first commit.
  • Name files to limit the run.
  • copyright alone writes a one-line all-rights-reserved LICENSE and no headers.
  • With neither license nor copyright set, nothing is written, and toku warns.
  • The make tab covers vendored and license_exclude: https://santoku.dev/santoku-make#santoku-make--license-and-header-keys
  • The make tab covers components and license_ids: https://santoku.dev/santoku-make#santoku-make--third-party-notices
  • Since santoku-make 7.8.0, when make.lua declares components, toku license also writes THIRD-PARTY-NOTICES.txt from the rock trees, the toolchain manifest, vendored and components. It does so even with no copyright set.
  • --env picks the build trees and the descriptor, so --env prod reads make.prod.lua and build/prod/.
  • Without components, --check fetches nothing. With components, it fetches the SPDX license list, plus the SPDX text of any component that has no text of its own.
  • --check also fails on a component with no SPDX id and no text.
  • --check also fails on a rockspec license that isn't an SPDX id and has no license_ids entry.
  • --check also fails on an MIT, BSD-*, Zlib, ISC or Apache-2.0 component with no copyright line, or an Apache-2.0 component with no notice.
  • --check also fails on a missing rock tree, and names the toku build --deps-only command that fills it.
  • Since santoku-make 7.11.4, a components entry with no scope gets that message too. Such an entry matches its rock only once the tree exists, so toku license and --check name the missing tree.
  • --check also fails on a stale THIRD-PARTY-NOTICES.txt: the regenerated text differs, a rock has no row, or a row matches no rock.

Environments and the build tree

Work happens under build/<env>/. --env prod reads make.prod.lua instead of make.lua and builds under build/prod/.

$ toku test
$ ls build/default
browser.flag   make.version     specs.flag  toku.log
build          profile.flag     stop.flag   trace.flag
config.stamp   make-stamps.txt  test
lua.flag       skip_check.flag
$ ls build/default/test
Makefile   check.sh  lua_modules     luacheck.lua  res     test
bin        lib       lua_modules.ok  luarocks.lua  run.sh
my-lib-0.0.1-1.rockspec
$ toku test --env prod
$ ls build
default  prod
Illustrative: runs outside the browser.
Details
  • Files that end in .tk render through santoku-template against the descriptor env, with the extension stripped.
  • So lib/my_lib/migrations.tk.lua lands as lib/my_lib/migrations.lua.
  • A .d sidecar next to each rendered file records what the template read through readfile and declared through depend. An edit to either restales the output.
  • The *.flag files keep CLI options like --skip-check and --trace. A change to them restales the generated run and check scripts.
  • specs.flag keeps the list of spec files, so a new spec restales run.sh.
  • config.stamp records the whole resolved descriptor and the configured rock servers. A changed descriptor value then restales every target that reads it.

Web and API build trees

A web or API project builds one tree per environment. It holds dist, server and client, and the spec trees sit under test.

$ ls -d build/default/*/
build/default/client/  build/default/dist/  build/default/server/  build/default/test/

$ ls build/default/dist
hash-manifest.lua  hash.ok  lua_modules  nginx-fg.conf  nginx.conf  public-staging
run.sh  static-files.ok

$ toku run lua scripts/load.lua
Illustrative: runs outside the browser.
Details
  • dist carries the server's lua_modules, because OpenResty runs dist with -p. The rendered nginx.conf refers to the lua_modules by relative path.
  • A server-only project still gets a client subtree, which holds little more than a lua_modules.ok stamp.
  • test holds server, client and root, one for each spec suite the project has, and run, the directory the test server runs in.
  • test/run has its own nginx.conf, logs, data and server.pid, and links dist's lua_modules and public.
  • The server.test.dependencies rocks install under test/server/lua_modules. Server specs load dist's modules first and that tree second, and nginx can't load it.
  • A script may need the project's own modules and its pinned rocks. toku run points LUA_PATH and LUA_CPATH at dist/lua_modules, then test/server/lua_modules.
  • dist also holds run.sh and nginx.conf, plus public/ when the project has a client.
  • The listings are the API scaffold's after toku test. toku start adds data, logs, temp and server.pid to dist.

The toku test pipeline

toku test renders sources into build/default/test and runs luarocks make for the test rockspec into a private lua_modules there. Then it runs sh run.sh and sh check.sh.

$ toku test
  select    1 spec
  deps      6 rocks (4 built)      24.4s
  build     16 targets              0.2s
  test      1 spec ok               0.0s
  check     luacheck 0/0            0.0s
  log       build/default/toku.log

$ toku test
  select    1 spec
  build     up to date              0.1s
  test      1 spec ok               0.0s
  check     luacheck 0/0            0.0s
  log       build/default/toku.log
Illustrative: runs outside the browser.
Details
  • run.sh names each selected spec file when it invokes the file runner: toku spec -i "$LUA" "test/spec/my_lib.lua".
  • check.sh runs luacheck over lib, bin and test/spec, unless --skip-check.
  • The runner writes one Test: line per spec file to build/default/toku.log and is silent on pass.
  • toku build and toku test also write one [rock] line there per rock, once per run, for each tree they use. The line holds the rock's name, its version and the tree.
  • A failing assertion writes the nested test tag chain, the error and a traceback to the log.
  • Every spec runs by default, so one command reports every failure. Pass -s to stop at the first one.
  • Since santoku-make 7.11.1, the next run repairs a dependency install that was killed partway. toku removes each rock version that the lua_modules manifest doesn't list and warns once per rock, and luarocks then installs it again. Before 7.11.1, every rerun failed with Repository inconsistency detected until you ran toku clean --deps.
  • The code is a fresh toku init library on its first run, then on a rerun with nothing to rebuild.

Phase lines and toku.log since santoku-cli 3.8.0

test, build, install, pack, release, start and stop print one line per phase, with a count and a time. The full output goes to build/<env>/toku.log. -v streams it to the terminal too.

$ toku test -v
[make]  test

Test:   test/spec/my_lib.lua

[make]  check

Total: 0 warnings / 0 errors in 5 files

  build     up to date              0.1s
  test      1 spec ok               0.0s
  check     luacheck 0/0            0.0s
  log       build/default/toku.log

$ head -1 build/default/toku.log
== 2026-10-30T18:01:54Z toku test (santoku-cli 3.8.0-1, santoku-make 7.9.0-1)
Illustrative: runs outside the browser.
Details
  • The phases print in this order when the command ends: deps, build, start, test, check, stop, install, pack, then the release steps.
PhaseCount
depsrocks installed, and how many of them compiled C
buildtargets rebuilt
testspecs run, or failed of run
checkluacheck warnings/errors
start, stopserver, or spec server for the test server
install, packthe rock or the tarball
preflight, tag, artifacts, push, host, registrydependencies, version, files, uploads
  • A line is two spaces, a label padded to 10 columns, then the text. A phase line pads its summary to 23 columns, then gives the time.
  • Notices print as they happen: a serving line per URL from start, the select line, the iterate lines, and a release's waiting lines.
  • Since santoku-cli 5.0.0, --show-logs adds access and server lines after the server specs.
  • Warnings print once each on stderr as warning lines.
  • They cover luarocks warnings except unmatched variable, and luacheck findings.
  • They also cover a build tree another santoku-make built, stale rocks, unset license fields and a vendor entry without sha256.
  • The output has no colour and no in-place updates, so a pipe, an agent or CI reads the lines a terminal shows.
  • -v, or TOKU_VERBOSE set to anything but 0 or empty, streams the full output to stdout as well.
  • -v goes after the command word: toku test -v streams, and toku -v still prints the version.
  • The log appends each run after a == line with the UTC time, the command and the santoku-cli and santoku-make versions.
  • toku moves a log past 8 MiB to toku.log.1 before it writes the next run.
  • --wasm, --browser, --resty and --cuda write the toku.log of build/<env>-wasm, build/<env>-resty or build/<env>-cuda.
  • toku lua, init, env, clean, license and spec print their own output, with no phase lines.

Failure output since santoku-cli 3.8.0

A failing run marks its phase failed. toku prints a spec line and an error line per failing spec. Then it prints the first failing spec's last 40 lines, the toku error and the log path.

$ toku test
  build     4 targets               0.2s
  test      failed: 1 of 2 specs    0.0s
  spec      test/spec/my_lib_sum.lua
  error     test/spec/my_lib_sum.lua:1: expected 3, got 4
  tail      last 8 lines of test/spec/my_lib_sum.lua
    Test:	test/spec/my_lib_sum.lua
    /home/you/.local/share/toku/lua/bin/lua: test/spec/my_lib_sum.lua:1: expected 3, got 4
    stack traceback:
    	[C]: in function 'error'
    	test/spec/my_lib_sum.lua:1: in main chunk
    	[C]: ?
    child process exited with unexpected status	exited	1

    toku: child process exited with unexpected status: exited: 1
      (set TOKU_TRACE=1 for the full Lua traceback)
  log       build/default/toku.log
Illustrative: runs outside the browser.
Details
  • The exit code is the one the run had before: 1 for a failing spec or a toku error.
  • The error line holds the test tag chain and the assertion for a santoku.test spec, and the interpreter's error line for a plain one.
  • Since santoku-make 7.11.4, the error line is the first line of a multi-line error.
  • Since santoku-make 7.11.4, the tail holds the first failing spec's own lines. Output from specs that ran after it stays in the log.
  • A phase that fails with no failing spec, such as a build error, prints the phase's last 40 lines.
  • -v already streamed the output, so it skips the tail.
  • The code is the fresh library plus a spec that calls error("expected 3, got 4").

Selecting and instrumenting tests since santoku-cli 5.0.0 and santoku-make 9.0.0

toku test PATH... runs the specs at or under each project path, and ^PATH leaves them out. --skip-check drops luacheck.

$ toku test test/spec/my_lib.lua
  select    1 spec; 3 outside the named paths
$ toku test test/spec/core -s
$ toku test ^test/spec/slow
  select    3 specs; ^test/spec/slow (command line) skips 1
$ toku test --skip-check --trace
$ toku spec -i luajit test/spec/core.lua
Test:   test/spec/core.lua
Illustrative: runs outside the browser.
Details
  • A PATH matches a spec whose path equals PATH or starts with PATH and a /. A leading ./ and a trailing / are dropped, and .tk is ignored on both sides.
  • There's no pattern and no substring match: test/spec/sync selects test/spec/sync/a.lua and leaves test/spec/syncer.lua out.
  • A spec runs when it matches a plain PATH and no ^PATH. With no plain PATH, every spec that no ^PATH matches runs.
  • A PATH that matches no spec stops the run before the build: "test/spec/nope (command line) selects no spec: a path names a spec file or a directory that holds specs".
Build flagSpecs the build leaves out
none.wasm.lua, .resty.lua
--wasm.browser.wasm.lua, .resty.lua
--browser.resty.lua
--resty.wasm.lua
--cuda.wasm.lua, .resty.lua
  • A named spec that the build leaves out stops the run: "no selected spec runs in this build: a .wasm.lua spec needs --wasm, a .browser.wasm.lua spec needs --browser, and a .resty.lua spec needs --resty".
  • *.browser.lua specs are skipped with a warning when TOKU_CHROMIUM and CI are unset. A plain PATH equal to the spec's path or its own directory runs it anyway, so it fails in place of the skip.
  • Every run prints one select line before the specs: the count that runs, then each exclusion with its source and count, the specs outside the named paths, each lifted make.lua entry and the suffix skips.
  • -v lists each skipped file as skipped PATH: REASON. The lines always go to toku.log.
  • make.lua's env.test.select holds default paths, in the next card.
  • -s stops at the first failure instead of running the whole suite.
  • --trace preloads santoku.trace into the test interpreter for a source trace.
  • toku spec FILE... runs spec files, and the specs under directories, with the spec runner. It needs no project and builds nothing.
  • toku spec -i runs each file under an interpreter command instead of dofile, and -s stops at the first failure. A missing path fails with "toku spec: no such spec: PATH".

Default spec selection since santoku-make 9.0.0

env.test.select in make.lua lists default PATHs for toku test, in the command-line syntax. A ^PATH entry leaves slow or flaky specs out of every bare run.

make.lua
local env = {
  name = "my-lib",
  version = "0.0.1-1",
  test = {
    select = { "^test/spec/slow" },
  },
}
return { env = env }
Shell
$ toku test
  select    3 specs; ^test/spec/slow (make.lua) skips 1
$ toku test test/spec/slow
  select    1 spec; 3 outside the named paths; ^test/spec/slow (make.lua) lifted by test/spec/slow
$ toku release test/spec/core
Illustrative: runs outside the browser.
Details
  • toku test and toku test --iterate always apply the list.
  • A plain command-line PATH at or inside one of the list's ^ entries lifts that entry for the run. toku test test/spec/slow and toku test test/spec/slow/big.lua run the slow specs, and toku test test keeps the entry.
  • Plain command-line PATHs replace the list's plain entries. A command-line ^PATH adds an exclusion.
  • An entry that matches no spec stops toku test, its loop and toku release before the build, and names make.lua as its source. toku build, toku start, install and pack don't check the list.
  • toku release ignores the list. Its command-line PATHs apply as for toku test, and --skip-tests stays.
  • The loop keeps its PATHs for its life. An edit to a spec that the selection leaves out prints nothing reads PATH, so nothing reruns.

The watch loop

toku test --iterate runs test plus check, then watches the files at the project root, lib, bin, test and res. It reruns on any change to a file the build reads.

$ toku test --iterate
  select    1 spec
  build     up to date              0.1s
  test      1 spec ok               0.0s
  check     luacheck 0/0            0.0s
  log       build/default/toku.log
  iterate   waiting for changes in ./make.lua, lib, bin, test, res
  build     3 targets               1.3s
  test      1 spec ok               0.0s
  check     luacheck 0/0            0.0s
  log       build/default/toku.log
  iterate   waiting for changes in ./make.lua, lib, bin, test, res
  iterate   nothing reads NOTES.md, so nothing reruns
  iterate   waiting for changes in ./make.lua, lib, bin, test, res
  iterate   make.lua changed, so the project reloads
Illustrative: runs outside the browser.
Details
  • Since santoku-make 10.2.1, --iterate polls the watched files every 0.5 s. A change to a file's device, inode, size, or nanosecond mtime or ctime starts a cycle.
  • Polling sees edits on any mount. That includes a bind mount from a macOS host under podman machine, where inotify events don't arrive.
  • After a poll sees a change, the loop waits 0.2 s and compares again, so a file that exists only between the two looks starts nothing.
  • A file whose name starts with a dot starts no cycle when it appears or disappears, so an editor's temp file and its rename start one cycle for the renamed file.
  • Writes that land during a cycle start one further cycle.
  • An edit to one selected spec runs that spec alone. toku test --iterate PATH... keeps its PATHs for the loop's life.
  • Each run prints its own phase lines and the log path, then an iterate line that says what it watches.
  • A change to a file that no target or .d sidecar names reruns nothing. The loop prints iterate nothing reads <file>.
  • A change to make.lua, or a file created or deleted in a watched directory, reloads the project and its target list before the next run.
  • It stops after two failures in a row with no file change between them.
  • In a web project, a failing run keeps the test server up.
  • For a web project, the standing dev loop is toku start --iterate.
  • Since santoku-make 10.2.1, toku start --iterate serves, then after each rebuild reloads the dev server and reruns the specs. It runs all specs, or only the spec file you edited.
  • Its spec server runs beside the dev server. Ctrl-C stops the loop, the server and the spec server.
  • toku test --iterate stays the spec-only loop.

toku test --wasm

toku test --wasm builds a parallel tree under build/default-wasm/, with the C toolchain swapped for clang with --target=wasm32-wasip1. The same suite then runs against the WebAssembly build.

$ toku test --wasm
$ grep Test: build/default-wasm/toku.log | tail -1
Test:   test/spec/my_lib.js
$ toku test --wasm test/spec/my_lib.lua
$ TOKU_CHROMIUM=chromium toku test --browser
$ grep Test: build/default-wasm/toku.log | tail -1
Test:   test-browser/test/spec/my_lib.js
$ TOKU_CHROMIUM=chromium TOKU_CHROMIUM_FLAGS=--no-sandbox toku test --browser
Illustrative: runs outside the browser.
Details
  • Dependencies compile to wasm32, and each spec is bundled to a .js file that runs it under node's WASI.
  • run.sh drives the specs with toku spec -i "<node> --expose-gc --no-warnings". <node> is the absolute path that toku setup --node recorded.
  • Without that node, the build stops with "wasm tests need the managed node; run: toku setup --node".
  • A PATH naming one .lua spec runs its .js twin.
  • --browser implies --wasm and uses the same tree, but links each spec for the web and runs it in headless Chromium.
  • --browser runs specs through toku-browser run from santoku-cdp, which must be installed in toku's tree.
  • TOKU_CHROMIUM names the browser command and is required.
  • TOKU_CHROMIUM_FLAGS adds flags, such as --no-sandbox when the run is root inside a container.
  • TOKU_BROWSER_TIMEOUT_MS bounds each spec, 60000 by default.
  • A spec named *.browser.wasm.lua needs a DOM. --browser runs it, and --wasm skips it by name.

toku test --resty since santoku-cli 6.0.0 and santoku-make 10.0.0

toku test --resty builds a parallel tree under build/default-resty/, compiled for OpenResty's LuaJIT, and runs every spec with OpenResty's resty CLI.

$ toku setup --resty
$ toku test --resty
$ grep -c luajit build/default-resty/test/luarocks.lua
2
$ toku clean --resty --all
Illustrative: runs outside the browser.
Details
  • ngx, its light threads, cosockets and semaphores work in each spec.
  • A spec named *.resty.lua runs only under --resty. A native run skips it by name.
  • --resty needs the managed OpenResty from toku setup --resty, or OPENRESTY_DIR.
  • make.lua's resty = false refuses --resty, as wasm = false refuses --wasm.
  • --wasm, --resty and --cuda each pick one tree, and they don't combine.
  • toku clean --resty removes build/default-resty.
  • The C rocks in that tree link libluajit. A release runs a resty profile when a .resty.lua spec exists.
  • toku init --example resty scaffolds a resty tool.

toku install

toku install runs test and check and renders the shippable tree under build/default/build. Then it runs luarocks make on the rockspec there, into the active rocks tree.

$ toku install
$ toku install --skip-tests
$ find ~/git/myapp/build -name luarocks.lua \
    -exec toku install --luarocks-config {} --skip-tests \;
Illustrative: runs outside the browser.
Details
  • --skip-tests goes straight to the build.
  • --luarocks-config points luarocks at another config.
  • --luarocks-config is how to pull a locally edited santoku rock into a project's build trees.
  • Run toku install from the library repo against each luarocks.lua found under the app's build/ directory.

Cache dependencies with --deps-only

toku install --deps-only and toku build --deps-only read only the descriptor and install the dependencies it declares. No project source is read or compiled.

COPY make.lua make.common.lua ./
COPY submodules/my-lib/make.lua submodules/my-lib/make.common.lua submodules/my-lib/
RUN toku build --env prod --deps-only
COPY . .
RUN toku build --env prod
Illustrative: runs outside the browser.
Details
  • The descriptor is make.lua and whatever it runfiles.
  • The dependencies go into the trees the matching full command uses, plus each local dep's own dependencies.
  • toku install --deps-only fills the active rocks tree for a library.
  • toku build --deps-only fills the server and client trees for a web project.
  • Since santoku-make 7.7.0, toku build --deps-only fills build/<env>/build/lua_modules for a library.
  • A later full build finds every dependency installed and builds only the project.
  • In a container build, copy the descriptor files first, run the deps-only step, then copy the rest. A source change then reuses the cached dependency layer.
  • Copy each local dep's make.lua too, plus every file any of these descriptors runfiles.
  • Keep those descriptors free of reads from other project files.

Standalone executables

toku install --bundled bundles every bin/*.lua through santoku-bundle into a native executable, instead of installing the rock. It copies each executable to <prefix>/bin.

$ toku install --bundled --prefix "$HOME/.local"
$ ls ~/.local/bin
my-lib
$ toku install --bundled --resty
$ cat ~/.local/bin/my-tool
#!/bin/sh
LUA_PATH='/home/me/.local/share/toku/apps/my-tool/lua_modules/share/lua/5.1/?.lua;...;;'
LUA_CPATH='/home/me/.local/share/toku/apps/my-tool/lua_modules/lib/lua/5.1/?.so;...;;'
export LUA_PATH LUA_CPATH
exec '/home/me/.local/share/toku/openresty/bin/resty' '/home/me/.local/share/toku/apps/my-tool/bin/my-tool.lua' "$@"
Illustrative: runs outside the browser.
Details
  • prefix defaults to $PREFIX when set, then $HOME/.local.
  • Lua modules are embedded.
  • C extensions link statically from the .o and vendored archives that each rock installs beside its .so. So the binary keeps working after the build tree is gone.
  • Lua itself links statically, since the managed toolchain ships only liblua.a.
  • So readelf -d lists libc and the system libraries your dependencies link, such as libopenblas.
  • The binary needs no Lua modules on disk and no LUA_PATH.
  • A dependency built before santoku-make 5.0.4 ships no .link file that lists such objects. The bundler links its .so dynamically.
  • Since santoku-bundle 3.2.2, that case prints "warning: no .link file, linking the shared object dynamically, so it must be present at runtime: <paths>".
  • The compiler is $CC, else cc. debug is never bundled.
  • With --wasm, the compiler is the clang of toku's wasm toolchain.
  • With --wasm, each entry point lands as a .js file plus a sh wrapper that execs the managed node by its absolute path. That path needs toku setup --node.
  • --wasm rebuilds the whole dependency tree for wasm32 into build/<env>-wasm. So the first run is slow even for a small project.
  • With --resty, toku builds the rock tree for OpenResty's LuaJIT in build/<env>-resty and copies it to <prefix>/share/toku/apps/<name>.
  • With --resty, each bin/*.lua lands in that directory, and <prefix>/bin/<script> is a sh launcher. It sets LUA_PATH and LUA_CPATH to the tree and execs the managed resty by its absolute path.
  • A --resty command runs in OpenResty's single worker, so santoku.resty.async gives it light threads and cosockets.
  • --wasm and --resty each need --bundled. install has no --browser target.

The release tarball

toku pack builds build/default/build and tars it as <name>-<version>.tar.gz, with no change to git or luarocks.org. The rockspec sits beside the tarball.

$ toku pack
$ ls build/default/build
Makefile  bin  lib  santoku-cli-4.0.0-1.rockspec  santoku-cli-4.0.0-1.tar.gz
$ tar -tzf build/default/build/santoku-cli-4.0.0-1.tar.gz | grep -v '/$' | sort
santoku-cli-4.0.0-1/LICENSE
santoku-cli-4.0.0-1/Makefile
santoku-cli-4.0.0-1/bin/Makefile
santoku-cli-4.0.0-1/bin/toku.lua
santoku-cli-4.0.0-1/lib/Makefile
santoku-cli-4.0.0-1/lib/santoku/cli/serve.lua
santoku-cli-4.0.0-1/lib/santoku/cli/setup.lua
santoku-cli-4.0.0-1/lib/santoku/cli/skills.lua
Illustrative: runs outside the browser.
Details
  • The tarball holds the sources with .tk stripped, the generated Makefile and LICENSE, all under a <name>-<version>/ prefix.
  • lib/Makefile and bin/Makefile join the generated Makefile when those trees exist.
  • The rockspec's source url is env.download.
  • When make.lua leaves env.download unset, toku derives it from the release host's download(name, version).
  • So a project hosted with s3_upload gets the base_url, name and version joined for it.
  • Since santoku-cli 4.0.0, toku pack --cache DIR also writes <name>-<version>.src.rock into DIR and rebuilds DIR's manifest.
  • It prints the rock's path and sha256 on a cache line. A consumer build then resolves the rock with TOKU_CACHE=DIR.

toku release hooks

toku release exists only when make.lua declares env.release. It runs test and check for every declared test profile, then pack, a preflight and a tag. The hooks then run phase by phase: artifacts, push, host, registry.

Shell
$ toku release
toku: release is not available (requires a non-wasm project with env.release in make.lua)
  (set TOKU_TRACE=1 for the full Lua traceback)

$ LUAROCKS_API_KEY=... AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... toku release
...
preflight: 12 dependencies resolve on https://luarocks.org
   03074fe..5191a0d  HEAD -> master
 * [new tag]         7.3.1-1 -> 7.3.1-1
uploaded: https://releases.santoku.dev/santoku-make/7.3.1-1/santoku-make-7.3.1-1.tar.gz
uploaded: https://releases.santoku.dev/santoku-make/7.3.1-1/santoku-make-7.3.1-1.rockspec
public: https://releases.santoku.dev/santoku-make/7.3.1-1/santoku-make-7.3.1-1.tar.gz
public: https://releases.santoku.dev/santoku-make/7.3.1-1/santoku-make-7.3.1-1.rockspec
Done: https://luarocks.org/modules/birchpointswe/santoku-make
public: https://luarocks.org/santoku-make-7.3.1-1.rockspec
make.lua (env.release block)
env.release = {
  artifacts = function (ctx)
    local fs = require("santoku.fs")
    local arr = require("santoku.array")
    arr.push(ctx.artifacts,
      { path = ctx.tarball, key = fs.basename(ctx.tarball), content_type = "application/gzip" },
      { path = ctx.rockspec, key = fs.basename(ctx.rockspec), content_type = "text/plain; charset=utf-8" },
      { path = "install.sh", key = "install.sh", content_type = "text/x-shellscript" })
  end,
  push = release.git_push(),
  host = release.s3_upload({ bucket = "my-releases", base_url = "https://releases.example.com" }),
  registry = release.luarocks_upload(),
}
Illustrative: runs outside the browser.
Details
  • Without env.release, toku release stops with "release is not available".
  • release refuses an env.homepage that still holds toku init's YOUR-HOMEPAGE placeholder.
  • --skip-tests skips every profile.
  • toku release PATH... runs only the specs those paths select, as toku test does. With no PATH every spec runs, and make.lua's env.test.select doesn't apply.
  • A release prints one select line per profile.
ProfileDeclared by
nativeevery project
--wasman env.test.wasm table in the descriptor, or a *.wasm.lua file in test/spec
--browsera *.browser.wasm.lua file in test/spec
--restya *.resty.lua file in test/spec, unless make.lua sets resty = false
  • A profile that fails stops the release before pack and the tag.
  • A *.browser.wasm.lua or *.browser.lua spec needs TOKU_CHROMIUM. When it's unset, or names a command that isn't on PATH, release stops before any test.
  • toku pack alone runs the native test and check, unless --skip-tests.
  • release refuses a tree with uncommitted or untracked files.
  • The preflight checks that every rockspec dependency has a version on luarocks.org that meets its constraint. It stops and names the ones that don't.
  • release tags the rock version. An existing tag on HEAD is reused, so a failed release reruns without a bump.
  • Each hook is a function of ctx, or a table with a run function.
  • ctx carries name, version, tag, commit, tarball, rockspec, build_dir, dir and artifacts.
  • An artifacts hook pushes { path, key, content_type } entries onto ctx.artifacts.
  • santoku.make.release supplies git_push, s3_upload, gh_release and luarocks_upload.
  • git_push pushes HEAD and the tag.
  • s3_upload PUTs ctx.artifacts when the artifacts phase added any, and otherwise the tarball and rockspec.
  • s3_upload sends If-None-Match, so a key is never overwritten. An existing key passes only when its bytes match.
  • An entry with mutable = true goes up after the others, at <name>/<key> with no version. It's a plain PUT with Cache-Control max-age=300.
  • s3_upload's latest = true option writes <name>/latest.txt the same way.
  • gh_release creates a GitHub release that carries both files, and points the rockspec's source url at it.
  • gh_release takes the repo from the origin remote or opts.repo.
  • luarocks_upload reads LUAROCKS_API_KEY, refuses to run without luasec, and uploads the rockspec alone.
  • luarocks_upload refuses a rockspec whose source url isn't https, since luarocks installs fetch the tarball from that url.
  • luarocks_upload also refuses when luarocks.org already serves different bytes for the version.
  • s3_upload and luarocks_upload then poll each public url. luarocks_upload also polls luarocks search for the version.
  • The polls retry after 1, 2, 4, 8, 16 and then 32 seconds, and fail when one never comes up.
  • A failure names the phases that completed. The local tag is removed only when no phase ran.
  • The env.release block publishes install.sh beside the tarball and rockspec.

Claude Code plugin archives

release.claude_plugin_archive({ plugin, base_url }) is an artifacts hook for a repo that holds plugins/<plugin>/ and .claude-plugin/marketplace.json. Users then install the plugin by URL.

make.lua
local release = require("santoku.make.release")
local env = {
  name = "fleet",
  version = release.json_field("plugins/fleet/.claude-plugin/plugin.json", "version"),
  license = "MIT",
}
env.release = {
  artifacts = release.claude_plugin_archive({ plugin = "fleet", base_url = "https://releases.example.com" }),
  push = release.git_push(),
  host = release.s3_upload({ bucket = "my-releases", base_url = "https://releases.example.com" }),
}
return { env = env }
Shell
$ claude plugin marketplace add https://releases.example.com/fleet/marketplace.json
Illustrative: runs outside the browser.
Details
  • The hook checks that plugin.json carries the plugin's name and env.version.
  • It zips the plugin directory with the plugin's root at the top of the zip.
  • It builds the same bytes on a rerun, so a retried release passes s3_upload's same-bytes check.
  • It then writes a marketplace.json whose entry for the plugin has an archive source: the zip's URL under base_url, and its sha256.
  • The zip uploads write-once under the version.
  • marketplace.json uploads as a mutable key at <name>/marketplace.json. So the marketplace URL stays fixed and moves to each new version within five minutes.
  • Users add that URL with claude plugin marketplace add.
  • The archive source needs Claude Code v2.1.224 or later.
  • The hook needs zip on the release host.

Claude Code plugin bundles

release.claude_plugin_bundle({ plugin, base_url }) is an artifacts hook for a client that installs from text rather than a URL. It writes the plugin as one text bundle, plus a paste.md.

install.md
Install Office {{version}}. The files follow; write each one,
and check its sha256 against its FILE line.

{{bundle}}
make.lua (env.release block)
env.release = {
  artifacts = release.claude_plugin_bundle({ plugin = "office", base_url = "https://releases.example.com" }),
  push = release.git_push(),
  host = release.s3_upload({ bucket = "my-releases", base_url = "https://releases.example.com" }),
}
Illustrative: runs outside the browser.
Details
  • The hook checks plugin.json the same way as claude_plugin_archive.
  • It writes <plugin>-<version>.txt, with every file under plugins/<plugin>/ in path order.
  • Each file appears as a FILE line with its path, byte count and sha256, then the exact contents, then an END line.
  • A file must end with a newline and must not contain the marker.
  • The hook also renders the repo's install.md into paste.md.
  • In install.md, {{url}} becomes the bundle's URL, {{version}} the version, and {{bundle}} the full bundle text.
  • {{bundle}} is inserted last, so a file that holds % or {{ passes through unchanged.
  • Any other placeholder fails the release.
  • Both files upload under the version.

Scaffold a web app

toku init --example web scaffolds a working todo app. client/ holds the Lua that compiles to WebAssembly, server/ the OpenResty side, and res/ the templates and migrations.

$ toku init --example web my-app
Created my-app from the web example: A web app

Next steps:
  cd my-app
  toku start             # Build and start the development server
  toku start --iterate   # The same, then rebuild and reload it on each edit
  toku test              # Run the specs beside it
  toku build --env prod  # Build the minified page to deploy

$ find my-app -type d -not -path "*/.git*" | sort
my-app
my-app/client
my-app/client/bin
my-app/client/lib
my-app/client/lib/my_app
my-app/client/static
my-app/res
my-app/res/client
my-app/res/client/partials
my-app/res/server
my-app/res/server/migrations
my-app/res/server/nginx
my-app/server
my-app/server/lib
my-app/server/lib/my_app
my-app/server/lib/my_app/web
my-app/server/test
my-app/server/test/spec
Illustrative: runs outside the browser.
Details
  • server/ holds its nginx.tk.conf and the store.
  • res/ holds the page template, its partials, the nginx config template and the migrations.
  • The page calls the store through POST /api/<name>.
  • make.common.lua holds the descriptor. make.lua merges minify = false over it for the local build, and make.prod.lua merges minify = true.
  • The pwa example moves the store and its migrations into a SQLite worker in the browser. It syncs the store with the server through POST /api/sync.
  • The pwa example also adds a service worker, so the app boots offline after a first visit.
  • Getting started covers TLS and the service worker: https://santoku.dev/start-web

The web loop

toku build renders the client to WASM and the server tree. toku start launches OpenResty against the built dist directory, toku test runs the suites, and toku stop stops the servers.

$ toku build
$ DB_FILE=tmp.db toku start
$ toku test
$ toku stop
$ toku start --fg
$ toku start --iterate
$ toku start --iterate --show-logs
Illustrative: runs outside the browser.
Details
  • build, start and stop act on the environment's one dist, build/<env>/dist. None of them takes --test.
  • start runs OpenResty through the dist's run.sh (openresty -p <dist> -c nginx.conf), in the background by default.
  • --fg execs OpenResty in the foreground, with the error log on stderr.
  • toku build reloads the environment's running server when the build changes the dist. Its build line then reads "<n> targets, server reloaded".
  • A build that changes nothing reloads nothing, and a build with no server running starts none.
  • toku start on a running server builds the project, reloads the server and prints "server already running, reloaded". The server keeps its pid.
  • Since santoku-cli 4.0.0, toku start --iterate starts the server, then rebuilds and reloads it on each change. --fg with --iterate is a usage error.
  • Since santoku-cli 6.0.4, --show-logs with --iterate prints each new line of the dev server's access.log and error.log while the loop waits. It needs --iterate.
  • Since santoku-make 10.2.1, toku start --iterate also reruns the specs after each rebuild, all of them or only the spec file you edited. Its spec server runs beside the dev server.
  • Ctrl-C ends the loop and stops the server and the spec server. toku prints "interrupted, so the loop and the server stopped" and exits with status 130. toku test --iterate does the same for the test server.
  • A loop with no terminal, such as one an agent starts, runs under setsid toku test --iterate. kill -INT -- -PGID then ends it with every child.
  • toku build also reloads a server started with --fg, in the terminal or container that runs it.
  • stop shuts down the server, and the test server when a failing run left it up.
  • Environment variables prefix the command as usual. A dev server runs as DB_FILE=tmp.db toku start.
  • toku test on a web project needs no manual start.
  • When server specs exist, toku test stops an old test server, starts a fresh one and waits for its pid file.
  • toku test fails fast if the server process dies. Check the nginx error log then.
  • Since santoku-make 9.0.0, toku start, and a toku test that starts the test server, check ps before the build. toku doctor reports a missing ps for a web project.
  • Since santoku-make 9.0.0, once the master's pid exists, the start reads what error.log gained. A [crit], [alert] or worker process N exited line fails the start with that line and stops the master.
  • A master that never answers fails the start with "server failed to start: no answer on URL after Ns". nginx.start_timeout sets N, 60 by default.
  • Under a failed server spec, the run prints the last 10 [error], [crit], [alert] and [emerg] lines that the spec server's error.log gained.
  • The web build loads every plain .lua module under client/lib, client/bin and lib. A syntax error fails the build with "syntax error in a client module", the path and the line.
  • toku test starts its own server from build/<env>/test/run. It doesn't stop a server you started, since the two listen on different ports.
  • When its build changes the dist, toku test reloads the server you started, as toku build does.
  • All of this applies to an API project unchanged.

Scripting start and stop

toku start returns once dist/server.pid exists. It fails after nginx.start_timeout seconds, 60 by default, with the [emerg] line from the error log.

Shell, through toku
$ toku start >/dev/null 2>&1
$ curl -s http://127.0.0.1:8080/items
$ toku stop
Shell, through run.sh
$ cd build/default/dist
$ setsid nohup sh run.sh >/dev/null 2>&1
$ cat server.pid
$ kill -15 "$(cat server.pid)"
Illustrative: runs outside the browser.
Details
  • --fg, or TOKU_FG set to anything but 0 or empty, execs openresty instead and never returns. A container needs that.
  • The backgrounded server inherits the standard output it started with.
  • So a piped or non-interactive call, such as ssh host "toku start; curl ...", hangs on the open pipe. It hangs though toku itself has already exited.
  • Redirect the server's output, or drive dist/run.sh yourself.
  • run.sh is a plain script, and it writes the same pid file. stop reads that file to send SIGTERM.
  • setsid detaches run.sh from the calling shell.
  • toku start serves on 8080.

Web test suites

A web project has three suites: test/spec at the root for shared lib code, client/test/spec and server/test/spec. toku test test, client and server select them.

$ toku test test
$ toku test client
$ toku test server --show-logs
$ toku test client/test/spec/my_app.lua
$ toku test server/test/spec/my_app.lua
$ toku test ^server/test/spec/page.browser.lua
Illustrative: runs outside the browser.
Details
  • client/test/spec compiles to WASM and runs under the managed node.
  • server/test/spec runs against the live test server.
  • A web project selects once over the three suites by project path, such as server, client/test/spec/sync or test/spec. A suite runs when one of its specs is selected.
  • A PATH that selects no spec stops the run: toku test client in a project with no client specs stops with "client (command line) selects no spec".
  • The test server starts when a server spec is selected.
  • A run takes the client specs, the root and server plain specs, then the .browser.lua specs as phase test browser. A failed pass doesn't stop the later passes.
  • toku test server skips the scaffold's .browser.lua specs without TOKU_CHROMIUM. toku test server/test/spec names their directory, so it runs them.
  • Since santoku-cli 5.0.0, --show-logs prints the access.log and error.log lines the test server wrote during the run, as access and server lines after the server specs. It doesn't turn on -v.
  • Server specs run under the interpreter the server itself uses: OpenResty's LuaJIT when OPENRESTY_DIR or the managed OpenResty resolves.
  • So a rock that loads in nginx also loads in the specs.
  • Root specs run under the plain interpreter.

toku run

toku run builds the project's test tree if needed, then runs a command with the tree's lua_modules/bin first on PATH and LUA_PATH and LUA_CPATH pointing at the tree. toku env prints export lines for the same tree.

$ toku run my-tool --help
$ toku run lua scripts/seed.lua
$ toku run --env prod lua -e 'print(require("my_app.db"))'
$ eval "$(toku env)"
Illustrative: runs outside the browser.
Details
  • So ad-hoc scripts and the project's own executables see the same rendered sources and pinned rocks as the specs.
  • A library's test tree holds the rock itself, so each bin/<name>.lua runs as <name>.
  • A web or API project's test tree is dist/lua_modules, then the server.test.dependencies rocks under test/server.
  • When the command is lua, toku run starts the tree's interpreter: the plain one for a library, resty for an OpenResty library, and OpenResty's luajit for a web project.
  • The first word that isn't a toku run option starts the command. Every word after it passes through, including dash words and a literal --.
  • stdin, stdout, stderr and the exit code are the command's own.
  • Paths are absolute, and the command runs in your current directory.
  • --env, --dir and --config pick the build environment as they do elsewhere.
  • eval the export lines of toku env to put the tree on your shell's PATH, LUA_PATH and LUA_CPATH.

toku clean

By default, toku clean removes the generated files inside build/<env>/ and keeps the expensive lua_modules trees.

$ toku clean --dry-run
Would remove:
  build/default/test/lib/my_lib.lua
  build/default/test/bin/my-lib.lua
  build/default/test/luarocks.lua
  build/default/test/luacheck.lua
$ toku clean --deps
Removed:
  build/default/test/lua_modules
  build/default/test/lua_modules.ok
$ toku clean --all
Removed:
  build
$ toku clean
Removed:
  (nothing to clean)
Illustrative: runs outside the browser.
Details
  • The generated files are rendered .lua sources, .d sidecars, stamp files, and the generated luarocks.lua and luacheck.lua.
  • --deps removes exactly those lua_modules trees instead.
  • --all removes the whole build directory.
  • --dry-run prints without removing.
  • In a lib project, --wasm or --browser, --resty and --cuda pick build/<env>-wasm, build/<env>-resty or build/<env>-cuda.
  • Web projects add --wasm, --client and --server to scope the sweep.
  • toku clean refuses any path outside the project directory outright.

toku serve

toku serve serves a directory over HTTP with the managed OpenResty. Use it for a scratch site, a built web project's dist/public-staging, or a page a browser test drives.

$ toku serve build/default/dist/public-staging --port 8080
serving /home/me/my-app/build/default/dist/public-staging at http://127.0.0.1:8080/
Illustrative: runs outside the browser.
Details
  • It writes a temporary nginx prefix: one worker, error log on stderr, no access log, directory listings on, index.html as the index, Cache-Control: no-store.
  • It runs openresty in the foreground and prints the URL. Ctrl-C stops it, and the prefix is removed.
  • --host defaults to 127.0.0.1, and --port to 8000.
  • It needs the managed OpenResty, which toku setup --resty installs.
  • It refuses a path that isn't a directory, with "serve: not a directory".
  • It refuses a path that holds a space, semicolon or quote, with "serve: paths with spaces or quotes are not supported". The path goes into nginx.conf unquoted.
  • If openresty exits with an error, such as a port already in use, its own message prints on stderr. toku exits nonzero after it removes the prefix.

toku skills

toku skills fetches the santoku agent skills from santoku.dev and installs them into your home directory. It never writes into a project.

$ toku skills
[skills]	fetching https://santoku.dev/skills.txt
[skills]	fetching https://santoku.dev/AGENTS.md
[skills]	wrote /home/you/.claude/skills/toku-setup/SKILL.md
...
[skills]	wrote /home/you/.codex/AGENTS.md
Illustrative: runs outside the browser.
Details
  • Claude Code gets one SKILL.md per skill under ~/.claude/skills.
  • Codex, and the other tools that read that standard, get one AGENTS.md under ~/.codex.
  • A manifest beside the installed skills records what toku skills put there.
  • So a later run removes skills that are no longer published, rather than leaving stale guidance behind.
  • It refuses to overwrite an AGENTS.md it didn't write, unless you pass --force.
  • --claude-dir and --codex-dir override the target directories.
  • --dry-run shows what would happen.

toku doctor since santoku-cli 3.9.0

toku doctor compares each installed SKILL.md with the copy santoku.dev serves. Its skills line names each stale or missing skill and prints the refresh command, toku skills.

$ toku doctor
toku doctor
  ...
  build prerequisites: ok
  skills: /home/you/.claude/skills (9 current; stale toku-project), run: toku skills
no problems found
Illustrative: runs outside the browser.
Details
  • The served copy is https://santoku.dev/skills.txt, the bundle toku skills installs from. One fetch covers every skill.
  • A skill counts as stale when its SKILL.md differs from the served text, and as missing when the file is absent.
  • A skill that the manifest lists and santoku.dev no longer publishes shows as unpublished. toku skills removes it.
  • With every skill current, the line shows the count and no command.
  • When the fetch fails, the line reads skills: not checked (offline).
  • The skills line never counts as a problem, so it never changes doctor's exit status.
  • The toolchain checks, including the santoku-make that the stored setup-toku.sh pins, are on the install tab: https://santoku.dev/install#install--doctor-repair-uninstall

toku lua

toku lua runs a string or file under the configured interpreter, and --lua overrides the interpreter. The instruments --trace and --serialize become -l preloads.

$ toku lua scripts/load.lua
$ toku lua --string 'print(1 + 2)'
3
$ toku lua --serialize --string 'print({ a = 1, b = { 2, 3 } })'
$ toku lua --trace scripts/step-through.lua
$ toku lua scripts/report.lua input.csv 10
$ toku lua -- scripts/report.lua -v input.csv
$ toku lua --string 'x()' extra
toku: toku lua takes no script arguments with --string: extra
  (set TOKU_TRACE=1 for the full Lua traceback)
Illustrative: runs outside the browser.
Details
  • The file comes positionally or with --file.
  • Positionals after the file reach the script as arg[1], arg[2] and so on. With --file, every positional is an argument.
  • Put -- before the file when an argument starts with a dash.
  • --string takes no arguments.
  • To run against the project's test tree, use toku run lua: https://santoku.dev/santoku-cli#santoku-cli--toku-run
  • Without --lua, toku lua puts your LUA_PATH and LUA_CPATH first.
  • The managed rocks tree comes next, then Lua's default path, ";;".
  • toku lua leaves out the default path when your value already holds ";;".
  • --trace loads santoku.trace for line tracing.
  • --serialize loads santoku.autoserialize, which wraps the global print. Tables then print as readable Lua literals instead of table: 0x... addresses.

toku template

toku template exposes the engine that expands .tk files in the build. -f renders one file, and -d renders a directory tree.

$ echo '<% return "hello" %>' | toku template -f - -o -
hello
$ toku template -d res/tmpl -t res/tmpl -o build/out -c cfg.lua
$ toku template -f res/index.tk.html -o build/index.html -M
$ cat build/index.html.d
res/index.tk.html: res/header.html
Illustrative: runs outside the browser.
Details
  • For -f, - is stdin or stdout.
  • With -d, -t trims a prefix from the output paths.
  • -c loads a Lua config whose env table becomes the render environment.
  • -M writes a make-style .d file next to each output. The file is one line that names the source and every file the template read through readfile.
  • toku template injects readfile only. depend exists in project builds.

toku bundle

toku bundle is the CLI face of santoku-bundle. It merges an entry script and every Lua module it requires into a generated C program, and compiles that program into an executable.

$ toku bundle --input bin/tool.lua --output-directory out \
    --path "lua_modules/share/lua/5.1/?.lua" \
    --cpath "lua_modules/lib/lua/5.1/?.so" \
    --luac-default \
    --flags="-O2 -I$(luarocks config variables.LUA_INCDIR) \
             -L$(luarocks config variables.LUA_LIBDIR) -llua5.1 -lm" \
    --env TOOL_HOME /opt/tool \
    --mod tool.plugins --ignore debug
cc out/tool.c -O2 -I... -L... -llua5.1 -lm \
    lua_modules/lib/lua/5.1/tool/capi.o -o out/tool
$ ls out
tool  tool.c  tool.lua  tool.luac
Illustrative: runs outside the browser.
Details
  • The santoku-bundle tab covers the library: https://santoku.dev/santoku-bundle
  • toku bundle scans the entry for string-literal require calls and resolves them against --path and --cpath.
  • It merges every Lua module into one file through package.preload.
  • It embeds the merged Lua in a generated C program, as bytecode under --luac or --luac-default. The program also preloads the luaopen_ symbols of the C extensions.
  • It compiles the program and prints the compile command.
  • --input, --output-directory, --path and --cpath are required.
  • Unlike toku install --bundled, this command derives no compile flags for you. So --flags is the complete list.
  • --flags must carry the -I that finds lua.h and the -l that supplies liblua, or the compile fails before it starts.
  • Dynamic requires need --mod.
  • Names to leave to the runtime take --ignore.
  • --env NAME VALUE bakes in a setenv at startup.
  • --deps writes a make .d file that covers every bundled module, and --deps-target names its target.
  • --luac-default compiles with the resolved luac as luac -s -o %output %input.
  • --luac takes your own command template.
  • With neither flag, the bundle embeds the merged source.
  • --cc picks the compiler, $CC by default, then cc.
  • --output-prefix names the outputs, and defaults to the entry's base name.
  • --close calls lua_close when main returns, and --no-close leaves the state open. With neither, an atexit handler closes it.
  • A C extension that ships a .link sidecar links statically. Where a C extension ships none, its .so links directly and a warning names it.