6.8 KiB
CraftOS Just Recipes Plan
Goal
Add repository-local CraftOS-PC launch recipes:
just craftoslaunches CraftOS-PC with repo-local save data under.craftos.just repllaunches the same environment with--clifor human interactive use only.just installdelegates tool validation to a newjust check-installrecipe.
Findings
CraftOS-PC docs confirm -d / --directory changes the save data root. With -d .craftos, generated files should be under .craftos/config/global.json, .craftos/config/0.json, and .craftos/computer/0/, not directly as .craftos/global.json.
CraftOS-PC docs describe -C as a CCEmuX compatibility flag for the computer-data directory. Do not make -C . the default unless an isolated probe proves it gives the desired repo layout without polluting the repository root.
just runs recipes from the Justfile directory by default, and justfile_directory() is available. Use it to anchor .craftos and mount paths to the repository root even when just is invoked from a subdirectory.
manifest.json already lists the shipped files. Its top-level directories are currently startup, servers, programs, and apis.
Recommended Approach
Use --directory for persistent CraftOS-PC state and command-line mounts for repository files.
Do not use -C . as the normal path to expose this repository. It controls saved computer contents, while --mount-ro directly models the intended behavior: make repo files available in the ComputerCraft filesystem without copying them into a VM save.
Mount the repository root at /trapos so existing code can read /trapos/manifest.json. Also mount each manifest top-level directory at its ComputerCraft root path, for example /apis, /programs, /servers, and /startup.
Prefer read-only mounts by default. Use explicit caller-provided args for unusual cases.
Implementation Steps
- Add
.craftos/.gitignoreso the directory exists in the repo while generated CraftOS-PC state stays untracked.
*
!.gitignore
-
Add
check-jqtoJustfile. -
Add
check-luachecktoJustfileso install checks every host-side CLI requirement explicitly.check-jqandcheck-luacheckare tool-presence checks only (verify the binary is on$PATH), mirroring the shape of the existingcheck-craftos. They do not run lint. -
Add
check-install: check-craftos check-jq check-luacheck. -
Change
installfrominstall-git-hooks check-craftostoinstall-git-hooks check-install. -
Change
checkto depend oncheck-luacheckand keepluacheck .as the command. Becausecheck-luacheckonly verifies presence (step 3), no lint runs twice.Leave
ci: check-craftos checkunchanged.cideliberately does not pull incheck-jq: the pre-commit path does not usejq, so adding it would inflate the hook's required tooling for no benefit. The two dep chains (install → check-install,ci → check-craftos + check → check-luacheck) are intentional, not an oversight to unify later. -
Add
craftos *args: check-install.
Recommended behavior:
- Use
--directory "{{justfile_directory()}}/.craftos". - Keep the existing macOS
--rom /Applications/CraftOS-PC.app/Contents/Resourcesworkaround. - Add
--mount-ro "/trapos={{justfile_directory()}}". - Use
jqovermanifest.jsonto derive unique top-level directories and add one--mount-ro "/<dir>={{justfile_directory()}}/<dir>"per directory. - Forward user args after the recipe defaults.
justforwards flags to variadic recipes normally, so callers should use commands likejust craftos --headlessandjust craftos --exec 'print("__READY__"); os.shutdown()'without an extra--separator.
Build the recipe-generated argv with quoted arguments and invoke craftos with forwarded user args as "$@" so paths and --exec code containing spaces survive. Do not use unquoted $mount_args word splitting, and do not use {{args}} for forwarding because it does not preserve shell quoting.
Sketch:
# Launch CraftOS-PC with repo-local data and read-only repo mounts.
# Pass args through to `craftos`, for example:
# just craftos --headless --exec 'print("__READY__"); os.shutdown()'
[positional-arguments]
craftos *args: check-install
#!/usr/bin/env bash
set -euo pipefail
repo='{{justfile_directory()}}'
argv=(--directory "$repo/.craftos")
if [ "$(uname -s)" = "Darwin" ]; then
argv+=(--rom /Applications/CraftOS-PC.app/Contents/Resources)
fi
argv+=(--mount-ro "/trapos=$repo")
while IFS= read -r dir; do
argv+=(--mount-ro "/$dir=$repo/$dir")
done < <(jq -r '.files[] | split("/")[0]' manifest.json | sort -u)
exec craftos "${argv[@]}" "$@"
Verify the shebang recipe receives variadic args as "$@" before committing. If it does not, use a linewise [positional-arguments] recipe that delegates to bash -c '...' craftos "$@"; do not fall back to {{args}}.
- Add
replas an interactive human-only wrapper.
# Human-only interactive REPL. LLM agents must not execute this command.
repl:
@just craftos --cli
-
Add the same
just replrestriction toCLAUDE.mdunder constraints or boot/install guidance. -
Update
DEVELOPMENT.mdrequirements to includejq. -
If the final mount behavior changes the local harness contract, update
docs/install-craftos-pc.mdor ADR-0005 accordingly.
Probe Before Finalizing Mounts
Run probes in /var/folders/l7/c5f9hw8j52zg5rx0vwz7_4d40000gn/T/opencode, not in the repository first.
Compare these cases:
- Plain repo-local data directory:
craftos -d <temp-data> --headless --exec 'print("__READY__"); os.shutdown()'
- CCEmuX computer-data override:
craftos -d <temp-data> -C <temp-computers> --headless --exec 'print("__READY__"); os.shutdown()'
- Explicit mounts:
craftos -d <temp-data> \
--mount-ro /trapos=<repo> \
--mount-ro /apis=<repo>/apis \
--mount-ro /programs=<repo>/programs \
--mount-ro /servers=<repo>/servers \
--mount-ro /startup=<repo>/startup \
--headless \
--exec 'print(fs.exists("/apis/net.lua")); print(fs.exists("/trapos/manifest.json")); os.shutdown()'
- macOS
-d+--romcombo (the recipe's actual shape):
craftos -d <temp-data> \
--rom /Applications/CraftOS-PC.app/Contents/Resources \
--mount-ro /trapos=<repo> \
--headless \
--exec 'print(fs.exists("/trapos/manifest.json")); os.shutdown()'
This must succeed before committing the macOS branch of the recipe — -d changes data-root resolution, and the existing test recipe only proves --rom works without -d.
Choose mounts unless -C demonstrably gives the desired repo-root ComputerCraft layout without repository pollution.
Verification
Run:
just --listjust check-installjust craftos --helpjust craftos --headless --exec 'print("__READY__"); os.shutdown()'just testgit status --short
Do not run just repl as an LLM agent.