Create or change a shared code module
r3_module_writeCreate a shared code module (baseVersion 0) or write its next version (baseVersion = the version you read). The code is a FUNCTION BODY that returns the exports, e.g. return { createShip(host, config) { … return {start, update, dispose, api}; } };. It runs once per run with this undefined (it reaches no component: the importing script passes in what it needs) and the same globals as a script (Event, EntityManager, THREE, GraphicsThree). Variables at its top level are shared by every script that imports it; per-instance state goes in what its factory returns. A module cannot import another module. A write on an older version is refused with the current code, never merged. Projects that follow the latest version run the new one at once (open editors reload it); pinned projects and published releases keep their version.
PATCH a long module instead of sending all of it: replacements [{old, new, count?}] with baseVersion and baseSha256 (the version and sha256 r3_module_read answered), no code. They apply in order, each on the text the previous one left; each old must occur exactly count times (default 1), else nothing is saved and the answer names the replacement and how many it found. At most 200 replacements and 60000 characters of old + new text per call. See "HOWTO_CODE_MODULES.md".
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"name": "<name>",
"baseVersion": "<baseVersion>"
},
"name": "r3_module_write"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | The whole module: a function body that returns its exports object (at most 250000 characters; comments and readable names are fine). Omit it when you send replacements. | |
| name | Yes | The module name: lower-case letters, digits and hyphens, e.g. "ship-core". | |
| notes | No | What changed in this version (shown in the version list). | |
| baseSha256 | No | With replacements only: the sha256 r3_module_read answered for baseVersion (of the WHOLE code). | |
| baseVersion | Yes | 0 to create the module; otherwise the version r3_module_read answered (with replacements: the version they apply to, which must be the latest). | |
| description | No | What the module is for (one line). | |
| replacements | No | Instead of code: exact replacements on version baseVersion, in order (at most 200, 60000 characters of old + new in all). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| answer | Yes | This answer in words: what was done, what R3 measured, decided or refused, and what to do next. The same text as the result's text block. Read it: the fields beside it are the data, this is the guidance. | |
| sha256 | Yes | ||
| created | Yes | ||
| version | Yes | ||
| moduleId | Yes | ||
| unchanged | Yes | ||
| totalChars | Yes | ||
| occurrences | Yes | ||
| replacements | Yes |