cmo-lua
# cmo-lua
A small framework and [MCP](https://modelcontextprotocol.io) server for writing Command: Modern Operations scenarios in Lua.
Command stays the simulator. This project is the part an AI can edit: a folder of Lua event scripts, a check that the function names exist, and a reader for the `.scen` files already on your machine. The function list and the pages it fetches come from the community docs at [commandlua.github.io](https://commandlua.github.io/).
It does not include Command, the Command database, or any official scenario.
## What you can do
- Search the Command Lua API and open the official page for one function.
- Read a local `.scen` file: sides, missions, unit names, and the Lua inside its events.
- Replace one event's Lua and write a **new** scenario file beside the original.
- Keep a scenario as a project (`cmo-project.json` plus `scripts/*.lua`) and compile `install.lua`, which you run once in the Command Lua console.
## Project layout
```json
{
"format": 1,
"title": "Strait patrol",
"events": [
{
"name": "Patrol briefing",
"trigger": { "name": "Scenario loaded", "type": "ScenLoaded" },
"action": { "name": "Show briefing", "file": "scripts/briefing.lua" }
}
]
}
```
`examples/strait-patrol` is a complete one. Trigger types the compiler knows: `ScenLoaded`, `ScenEnded`, `Time`, `RegularTime`, `RandomTime`, `UnitDestroyed`, `UnitDamaged`, `UnitDetected`, `UnitEntersArea`, `UnitRemainsInArea`, `Points`.
## Use it from an editor
Build it, then add the server to your MCP client:
```bash
npm install
npm run build
npm test
```
```json
{
"mcpServers": {
"cmo-lua": {
"command": "node",
"args": ["<path-to>/cmo-lua/dist/index.js"]
}
}
}
```
On this machine that path is `C:/Velodona/cmo-lua/dist/index.js`.
Then ask for something like: look up `ScenEdit_AddUnit`, extract this scenario into a project, and add an event that posts a message when the scenario loads.
In Command, open the Lua console and run the generated `install.lua` with the scenario already loaded. The script removes and recreates only the events named in the project.
## Scenario files
A current Command scenario is XML. The body is compress version 5: LZ4 chunks inside AES, the same container described by the public [CMOScenTool](https://github.com/yiyuezhuo/CMOScenTool) project. `cmo_read_scenario` unpacks that so an assistant can see the events. `cmo_write_action_script` writes a separate `.cmo-lua.scen` and leaves the file you opened alone. Load the new file in Command before you throw away the original.
`cmo_list_scenarios` only reads the wrapper (title, setting, complexity), which is enough to find a file without unpacking it.
## Tools
| Tool | What it does |
| --- | --- |
| `cmo_search_api` | Search the function catalog |
| `cmo_get_function` | Fetch one official docs page |
| `cmo_list_scenarios` | List `.scen` files in a folder |
| `cmo_read_scenario` | Unpack one scenario |
| `cmo_write_action_script` | Replace one Lua action and write a new `.scen` |
| `cmo_extract_project` | Turn a scenario into a project folder |
| `cmo_read_project` | Read a project and its scripts |
| `cmo_write_script` | Write a Lua file into a project |
| `cmo_validate_project` | Check files and function names |
| `cmo_compile_loader` | Write `install.lua` |
There is also a prompt, `cmo_draft_event`, that tells the assistant to look functions up before it writes them.
## Develop
```bash
npm test
npm run build
npm run smoke
```
The Dong Hoi round-trip test runs only when that scenario is installed with Command. It does not copy the scenario into this repository.
TDQS
Scored across 10 tools
Most tools occupy clearly distinct roles: docs lookup (search_api/get_function) versus scenario inspection (list_scenarios/read_scenario) versus project workflows (extract/read/write/validate/compile). The main risk is cmo_write_action_script vs cmo_write_script, which both "write Lua" but differ in target (raw .scen event vs project file) — descriptions clarify but the names alone are close. cmo_read_scenario and cmo_read_project are also adjacent but resolvable from context.
Every tool uses the cmo_ prefix followed by a verb_noun snake_case pattern (search_api, get_function, list_scenarios, read_scenario, write_action_script, extract_project, read_project, write_script, validate_project, compile_loader). No camelCase or style mixing; the pattern is predictable throughout.
Ten tools is well within the ideal 3-15 range and each maps to a distinct step in the docs-lookup and scenario/project lifecycle. No tool feels redundant or like padding; the counts split naturally between reference lookup and file manipulation.
The surface covers the full workflow: look up real functions, inspect existing scenarios, extract to a project, edit scripts, validate function names, and compile a loader. Minor gaps exist — no tool to create a brand-new scenario from scratch, no delete/rename of events, and no direct write-back of a compiled .scen (by design, via install.lua). These are workaroundable but leave the lifecycle slightly one-directional.