3.3 KiB
3.3 KiB
CLAUDE.md
Concise guidance for agents working in this repository.
Project
ComputerCraft / CC:Tweaked Lua APIs, servers, and programs for Minecraft 1.21. Code runs in the ComputerCraft sandbox, not standard Lua.
Use docs/README.md as the entrypoint for CC:Tweaked, CraftOS-PC, Advanced Peripherals, and Create integration documentation links. Use docs/adrs/README.md for repository architecture decisions.
Constraints
- Do not add a standalone Lua test harness unless asked. Local execution happens through the CraftOS-PC harness (see
docs/install-craftos-pc.md,docs/craftos_pc_glossary.md, and ADR-0005); code otherwise executes in-game. - Do not run
just replas an LLM agent; it is a human-only interactive CraftOS-PC wrapper. Usejust craftos --headless ...for automated probes. - When changing behavior, add as many useful CraftOS-PC tests as practical. It is acceptable to skip tests that require human-only validation, such as complex turtle motion, in-game UX feel, or visual approval, but still add unit-style non-regression tests for deterministic parts when possible.
- Use
/apis/libtest.luafor test scripts undertests/;/programs/runtest.luaprints__TRAPOS_TEST_OK__only after the suite passes. - After editing Lua, run
just checkand fix allluacheckwarnings. - Use 2-space indent, semicolons, and
local function. requirepaths are absolute ComputerCraft paths, for examplerequire('/apis/net')().- Most API modules return factories; call the required module once before use.
Architecture
apis/eventloop.luais the single-threaded event loop aroundos.pullEventRaw; consider using it everywhere async behavior is needed. A handler that returnsapi.STOPauto-unregisters.apis/libtest.luais the lightweight test helper used by scripts undertests/;/programs/runtest.luadiscovers tests, renders suite output, and owns the__TRAPOS_TEST_OK__success marker.apis/net.luabuilds modem packet messaging, routing, and request/response RPC on the event loop.sendRequestreturnsok, result, packetand defaults to a 0.5s timeout.- A router (
/programs/router.lua) must be running somewhere on the network; without it, packets lackrouterId,isPacketOkrejects them, and cross-machine messaging silently fails. servers/listen for requests and start loops;programs/are clients that send requests and exit.- Well-known channels:
9ping,10router/default routing. Keep duplicated constants in sync.
Boot And Install
startup/servers.luastarts/programs, the shell, and configured servers viaparallel.waitForAll.- Preserve
periphemuguards used for CraftOS-PC emulation; seedocs/craftos_pc_glossary.mdfor upstream emulator references. install.luadownloads files listed inLIST_FILESfrommasterby default, or fromnextwith--beta; add shipped files there.- Add new servers to
startup/servers.luaas needed.
Conventions
- Bump
local _VERSION = '...'when changing module behavior. - Programs support
-version/--versionand-help/--help; router also supports-silent/--silent. - French or English comments are fine; match surrounding code.
- Commit messages use lightweight conventional style:
topic(scope): descriptionortopic: description.
See DEVELOPMENT.md for local setup.