|
| 1 | +# Minecraft Metascript (MMS) — Workspace AI Rules |
| 2 | + |
| 3 | +These are project-specific rules and context the AI must follow when working in this repository. |
| 4 | + |
| 5 | +## Project Context |
| 6 | +- Language: Go (go 1.23) |
| 7 | +- Module path: `github.com/minecraftmetascript/mms` |
| 8 | +- Vendoring: `vendor/` is present; builds typically use vendored deps |
| 9 | +- Parsing: ANTLR4 grammars in `grammar/*.g4` generate Go code into `lang/grammar/` |
| 10 | +- CLI: Cobra-based entrypoint |
| 11 | +- WASM: Browser-targeted build via [main_wasm.go](cci:7://file:///Users/brian/code/minecraftmetascript/mms/main_wasm.go:0:0-0:0) and `wasm/` |
| 12 | +- Nix: Optional flake provides reproducible builds and ANTLR generation |
| 13 | + |
| 14 | +## Repository Layout (high-signal paths) |
| 15 | +- `lang/`: Core API (Project, File, traversal, constructs, generated grammar package) |
| 16 | + - `lang/grammar/`: GENERATED by ANTLR. Do not edit manually. |
| 17 | + - `lang/constructs/...`: Construct registry and implementations (e.g., worldgen/surface_rules) |
| 18 | + - `lang/traversal/...`: Parser traversal, construct registry, scopes |
| 19 | +- `grammar/`: Handwritten ANTLR grammars |
| 20 | +- `cmd/`: Cobra root command ([mms](cci:7://file:///Users/brian/code/minecraftmetascript/mms/test.mms:0:0-0:0)) |
| 21 | +- `wasm/`: JS glue (`mms.js`), package.json, and wasm artifacts |
| 22 | +- `examples/`: MMS examples (e.g., surface rules) for manual parsing checks |
| 23 | + |
| 24 | +## Absolute Rules (Do/Don’t) |
| 25 | +- DO keep all imports at the top of files; never insert imports mid-file. |
| 26 | +- DO run `gofmt`/`goimports` and `go vet` before committing or proposing changes. |
| 27 | +- DO regenerate grammar output rather than editing anything under `lang/grammar/`. |
| 28 | +- DO keep vendoring consistent. After editing [go.mod](cci:7://file:///Users/brian/code/minecraftmetascript/mms/go.mod:0:0-0:0)/[go.sum](cci:7://file:///Users/brian/code/minecraftmetascript/mms/go.sum:0:0-0:0): `go mod tidy` then `go mod vendor`. |
| 29 | +- DO cite files/paths with backticks like `path/to/file.go` in explanations and PR notes. |
| 30 | +- DON’T modify generated files under `lang/grammar/` directly. |
| 31 | +- DON’T break build tags: |
| 32 | + - [main.go](cci:7://file:///Users/brian/code/minecraftmetascript/mms/main.go:0:0-0:0): `//go:build !js && !wasm` |
| 33 | + - [main_wasm.go](cci:7://file:///Users/brian/code/minecraftmetascript/mms/main_wasm.go:0:0-0:0): `//go:build js && wasm` |
| 34 | + |
| 35 | +## Builds & Tasks (Preferred Flows) |
| 36 | +- Nix (recommended): |
| 37 | + - Native CLI: `nix build` → produces `./result/bin/mms` (runs ANTLR generation first) |
| 38 | + - WASM: `nix build ".#wasm"` → produces `./result/js/` with `dist/main.wasm` and assets |
| 39 | + - Dev shell: `nix develop` (provides `antlr-build`) |
| 40 | + - Regenerate grammar (Nix): `antlr-build` |
| 41 | +- Non-Nix ANTLR regeneration (if `antlr4` is in PATH): |
| 42 | + - Lexer: `antlr4 -Dlanguage=Go grammar/Main_Lexer.g4 -o lang -package grammar` |
| 43 | + - Parser: `antlr4 -Dlanguage=Go grammar/Main_Parser.g4 -lib lang/grammar -o lang -package grammar` |
| 44 | +- Vendoring: |
| 45 | + - After dependency changes: `go mod tidy && go mod vendor` |
| 46 | + |
| 47 | +## WASM Notes |
| 48 | +- [main_wasm.go](cci:7://file:///Users/brian/code/minecraftmetascript/mms/main_wasm.go:0:0-0:0) exports (js/wasm build tags): |
| 49 | + - `updateFile(filename: string, content: string, cb: (serializedProject: string) => void)` |
| 50 | + - `getFileDiag(filename: string, cb: (json: string) => void)` |
| 51 | +- `wasm/package.json` exposes `./mms.js` and `./dist/main.wasm` for NPM packaging. |
| 52 | + |
| 53 | +## Testing Guidance |
| 54 | +- Important API change: `Project.Diagnostics` is a METHOD now, not a field. |
| 55 | + - Replace: `len(p.Diagnostics)` → `len(p.Diagnostics())` |
| 56 | + - Replace: `for d := range p.Diagnostics { ... }` → range over `p.Diagnostics()` |
| 57 | +- Running tests: |
| 58 | + - Full (may fail due to legacy `test/` pkg): `go test ./...` |
| 59 | + - Preferred during migration: `go test ./lang` |
| 60 | + - Specific test: `go test ./lang -run TestName -v` |
| 61 | +- Pattern for new tests: |
| 62 | + - Create a `Project`, add a `File`, call `Parse()` |
| 63 | + - Assert on `File.Diagnostics`, `Project.Diagnostics()` |
| 64 | + - For exports, use `Project.BuildFsLike(root)` |
| 65 | + |
| 66 | +## Construct & Export Model |
| 67 | +- New constructs register via `traversal.ConstructRegistry.Register(...)` |
| 68 | +- `Project.BuildFsLike(root)` walks `GlobalScope` and calls `ExportSymbol` on constructs to build a directory-like export structure (used by WASM packaging) |
| 69 | + |
| 70 | +## Coding Style & Quality |
| 71 | +- Follow idiomatic Go. Keep functions cohesive and small. |
| 72 | +- Keep generated code in `lang/grammar/` untouched; regenerate via ANTLR on grammar changes. |
| 73 | +- Prefer package-local tests near code under test. |
| 74 | +- Keep explanations concise and always reference changed files and symbols with backticks. |
| 75 | + |
| 76 | +## Quick Commands Reference |
| 77 | +- Native build: `nix build` |
| 78 | +- WASM build: `nix build ".#wasm"` |
| 79 | +- Dev shell (Nix): `nix develop` |
| 80 | +- Regenerate grammar (Nix): `antlr-build` |
| 81 | +- Regenerate grammar (manual): |
| 82 | + - `antlr4 -Dlanguage=Go grammar/Main_Lexer.g4 -o lang -package grammar` |
| 83 | + - `antlr4 -Dlanguage=Go grammar/Main_Parser.g4 -lib lang/grammar -o lang -package grammar` |
| 84 | +- Core package tests: `go test ./lang -v` |
| 85 | + |
| 86 | +## AI Execution Preferences |
| 87 | +- When asked to modify code: |
| 88 | + - Respect vendoring and ANTLR regeneration steps. |
| 89 | + - Never place imports mid-file—add at the top and adjust separately if needed. |
| 90 | + - Avoid large monolithic diffs; break up edits logically. |
| 91 | +- When suggesting commands, prefer Nix flows where available. |
| 92 | +- If a change would touch `lang/grammar`, instruct to regenerate via ANTLR instead of manual edits. |
0 commit comments