Project-specific conventions, runtime invariants, error codes, and verification commands. See AGENTS.md for repo layout and top-level boundaries.
Only the terms people commonly mix up:
- Plugin Hook vs. Script Event: a Plugin Hook is a Java method on
NekoJSPlugin(wrapping an Extension Point or lifecycle callback); a Script Event is a JS callback registered on an Event Group (ServerEvents.xxx(event => {})). - Extension Point vs. Contributor: an Extension Point collects one kind of plugin contribution (e.g. bindings, events, recipe schemas); a Contributor is the interface a plugin implements to supply items to that point.
globalvs.sharedvs.globalThis:globalis in-memory state shared across scripts of oneScriptType(STARTUP,SERVER,CLIENT,TEST);sharedis in-memory state shared acrossScriptTypes in one runtime. Neither is JSglobalThis, and neither is persisted to saves or synced over the network.
Keep existing public names and overloads backwards-compatible unless a breaking migration is planned (document migrations in the wiki, not in runtime error messages).
- Event groups (example: ServerEvents.java; Java plugin publication,
@ScriptOutput, and compiler/preflight hooks: plugins.md):- Scripts subscribe via
EventGroupName.eventName(event => {})(lower camel case), with required selectors before the callback. Put event-specific data/actions oneventand general helpers on a Binding. - Define groups in Java with
EventGroup.of(...), declare all events before freezing, and register the group once inregisterEvents(orregisterClientEventsfor client). - Plain
group.server(...)/client(...)/startup(...)declarations publish toversionedby default;stablerequires a portable declared payload or.view(...)converter.
- Scripts subscribe via
- Bindings (example: NekoJSCorePlugin.java):
- Register in
registerBinding(BindingRegistry). Third-party Binding modules usenekojs/plugins/<owner>/api/stableornekojs/plugins/<owner>/api/version(separate from event virtual modules). - For dynamic proxies, pass the exposed interface via
Binding.of(name, value, valueType)so generated declarations match runtime access.
- Register in
- Builders: put identifying arguments first and the configuration callback last (
event.create(id, build => { build.displayName = "Example"; })). Keep the event object and builder separate, and don't require a trailing.build()unless an existing API already does. - Bean properties: expose JavaBean accessors as properties (
getXxx()->obj.xxx,setXxx(v)->obj.xxx = v) matching actual read/write support, keeping parameterized methods as methods. Verify property access on the actual script-visible wrapper or proxy—a Java getter/setter name alone doesn't guarantee exposure.
Keep these invariants when touching engine lifecycle, reload, threading, or persistence:
- Root vs. plugin ownership: NekoRuntimeRoot owns root-level resources. NekoPluginRuntime survives ordinary script reloads and is not re-bootstrapped on reload.
- Generation cleanup: every per-generation GraalJS
Context, listener, timer, and handle must belong to ResourceTracker with an explicit cleanup path. Closing an old generation must not tear down root-owned plugin resources. - Safe reload handoff: build and validate the
candidategeneration before swapping it toactiveon the owning thread. Keep live callbacks, timers, bindings, and registry mutations onactiveuntil the swap. On failure, dispose the candidate and keepactiverunning with no duplicate callbacks. - Thread confinement: GraalJS
Contextand guest objects are single-threaded—concurrent collections do not make them thread-safe. Marshal cross-thread calls to the owning thread and serializeevaluate,reload, andcloseperScriptType, withclosetaking priority. - User-file safety: on error, preserve existing user files (configs, saves, pdata, packs, workspace files) instead of overwriting them or silently falling back to empty defaults. Persistent migrations must back up first and replace atomically.
- Shared state: GlobalStateStores tracks top-level keys only for
globalandsharedduring reload—nested object mutations, world/file side effects, and cross-process sync are neither rolled back nor synchronized.
Keep direct callback hooks separate from collection points. Adding a collection point requires updating four places together:
- Its
Extension Pointdefinition. - The default hook on NekoJSPlugin.
- Registration in NekoBuiltinPointsPlugin.
- Pairing coverage in PluginHookPairingTest.
Write all new or modified Java/Gradle/script code comments, /// doc comments, TODOs, and test assertion messages in English—do not mimic Chinese from surrounding legacy comments or let a Chinese prompt bleed into source files (only untouched legacy comments, localization files, and exact test fixtures stay in Chinese).
For Java documentation comments, use /// Markdown syntax (JEP 467) instead of /** ... */ across every module—including Java 21 modules like common/ and common-api-processor/ (javac 21 accepts /// as line comments, and /// avoids /* ... */ block-comment conflicts inside Stonecutter //? if guards; example: Binding.java):
- Use standard Markdown (
`code`, fenced```blocks, lists, and[Type#member]/[param]references) instead of HTML tags (<p>,<ul>) or{@code}/{@link}. @param,@return, and@throwstags still work inside///when needed; leave untouched/** ... */comments as-is unless already editing them.
Prefer i18n whenever the target surface supports localization (Component.translatable / TextValue.translatable backed by assets/nekojs/lang/{en_us,zh_cn}.json for player chat, command feedback, and in-game UI); otherwise write messages in English (developer logs, Java exceptions, CLI output, and standalone compile-time/annotation-processor diagnostics)—never hardcode Chinese text in Java code.
Use the module's logger (no System.out or printStackTrace). Problem logs should state what failed, the outcome, and locating context (file/line, ScriptType, generation, phase, owner), attaching the cause once at the reporting layer.
Every developer-facing runtime problem log or exception needs a stable [NEKO-nnnn] code (routine progress logs and localized player UI/chat messages have no code):
- Stability: never renumber a code when rewording or reuse it for a different failure. Use the same code for the same failure across all call sites and nodes.
- Areas (pick the next free code in the wiki table):
1xxxscript loading/reload ·2xxxlog limits & data fallbacks ·3xxxscript sync ·4xxxregistration/bindings ·5xxxrecipes/data ·6xxxclient JSX UI visual/resources ·7xxxclient JSX UI runtime/lifecycle ·8xxxUI inspector. - Message language: write new or rewritten messages in English (
[NEKO-10xx] Failed to reload SERVER scripts at server_scripts/main.js:42; generation 12 remains active.). Leave untouched legacy Chinese messages intact, and keep any message asserted verbatim by existing tests unchanged. - Wiki sync: update both wiki/error-reference_us.md and wiki/error-reference_cn.md in the same change.
Full CI commands and the active node matrix live in ci-build.yml and package.json. On Windows, use gradlew.bat (or ./gradlew.bat in PowerShell). CI gate CLI:
python3 tools/nekojs-ci-gates.py <all|subsets|processor|declaration|nodes|selftest>
python3 tools/nekojs-ci-gates.py source-roots --node <node>| Change area | Commands / checks |
|---|---|
| Common engine, ownership, or isolation | ./gradlew :common:check (runs isolation checks that :common:test skips); add guardLint for boundary/import/guard changes. |
| Annotation processor | ./gradlew :common-api-processor:test plus affected node builds. |
| Version facades, guards, or source roots | ./gradlew guardLint, affected :<node>:build, and python3 tools/nekojs-ci-gates.py <subsets|nodes|all> + source-roots --node <node>. |
| NBT codec | ./gradlew :1.21.1:nbtSmokeTest :26.1.2:nbtSmokeTest :26.2.0:nbtSmokeTest (NeoForge nodes only). |
| Plugin API or collection channels | PluginHookPairingTest and relevant plugin tests under :common:check. |
| Script API, declarations, or Probe | ApiManifestGoldenTest, relevant surface tests, and npm run test:probe-types (after :common:check); add npm run test:probe-recipe-filter (after :1.21.1:nativeRecipeProbeTest) or npm run test:probe-native-jsx when touching those surfaces. For intentional golden updates, run ./gradlew :common:regenerateGoldens, review the diff, and rerun :common:check. |
| Runtime reload, state, persistence, or threading | Targeted lifecycle/state/reload tests under :common:check; add :26.1.2:runGameTestServer when crossing into Minecraft. |
| Loader startup, Mixin, GUI/chat, or game behavior | Affected :<node>:build, Fabric :<node>:runServer smoke, and ./gradlew :26.1.2:runGameTestServer (check All <N> required tests passed in versions/26.1.2/run/logs/). |