6.5 KiB
6.5 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 trapos-exec '<lua>'for automated probes against the TrapOS dev environment, orjust craftos-exec '<lua>'for probes against vanilla CraftOS (no TrapOS mounts). These wrappers shut down the machine and include a host watchdog. Headless probes are the recommended way to verify hypotheses about CC:Tweaked behavior; see ADR-0005. - 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. libtestcancels each case after3s (--timeout <s>/--no-timeoutto override); never commit a hanging test totests/. Slow harness fixtures go intests/harness/behind dedicated recipes. See ADR-0007.- Git hooks own commit/push verification: pre-commit runs
just check test, and pre-push runsjust ci. When explicitly asked to commit and/or push, do not runjust testmanually first; rely on the hooks. See ADR-0011. - After editing Lua or Markdown, run
just checkand fix allluacheckwarnings andlycheebroken-link reports (markdown link validation is offline-only viajust lint-markdown). - 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.startup/servers.luacreates a single boot eventloop at_G.bootEventLoopand runs it alongside the shell viaparallel.waitForAny. Servers register handlers on it and return; programs call services viaos.pullEventwithout touching the loop. See ADR-0002.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.luais a service-name bus on a single channel (10).net.serve(name, handler)registers a server handler;net.call(name, payload, { destId, timeout })andnet.send(name, payload, { destId })are the client surface.require('/apis/net')()returns a singleton bound to_G.bootEventLoopwhen present, otherwise an ephemeral instance.- A router (
/programs/router.lua) must be running somewhere on the network; it registers amodem_messagehandler that stampsrouterId, resolves label-addressed packets via a TTL map populated byservers/net-registrar.lua, and rebroadcasts. Without it, packets stay unrouted and consumers ignore them. servers/register handlers on the boot eventloop and return;programs/are clients that exit.- Single well-known channel:
10(the bus). Service multiplexing happens inside the packet body.
Boot And Install
startup/servers.luacreates the boot eventloop, runs autostart server files (which register handlers and return), then runs the shell and the eventloop in parallel viaparallel.waitForAny.- Preserve
periphemuguards used for CraftOS-PC emulation; seedocs/craftos_pc_glossary.mdfor upstream emulator references. - TrapOS ships as packages, each described by
packages/<name>/ccpm.json(name,version,dependencies,files,autostart);packages/index.jsonlists them. Source files stay in place — descriptors only reference them. To ship a new file, add it to the right package'sfiles(andautostartif it is a server).packages/trapos/ccpm.jsonis the full OS meta-package. See ADR-0010. install-ccpm.luais the one-time wget bootstrap. It installs onlytrapos-core/ccpm, seeds the defaultguillaumearm/cc-libsregistry onmaster(ornextwith--beta), and tells users to runccpm updatethenccpm install trapos.ccpm(intrapos-core) is the package manager:apis/libccpm.luais the testable core (factory with injectablehttp/stateDir/installRoot),programs/ccpm.luathe CLI. State:/trapos/ccpm.json(registries),/trapos/ccpm.lock.json(installed packages), and/trapos/ccpm.cache.json(available packages fromccpm update). Never use the word "manifest" in ccpm — it is reserved for the OS manifest.- Add new servers to
startup/servers.luaas needed.
Conventions
- Bump the owning
packages/<name>/ccpm.jsonversion (and mirror it inpackages/index.json) when changing module behavior; programs report it at runtime viarequire('/apis/libversion')().forSelf().install-ccpm.luais the only file that still carries its own_VERSIONbecause it is the wget bootstrap and lives outside the package system. - 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. - Reference other
.mdfiles (andADR-####) with[text](path)link syntax sojust lint-markdown(lychee) can validate them. See ADR-0011.
See DEVELOPMENT.md for local setup.