Repository navigation
Description
Plan 2026-08-18, closed 2026-09-12, shipped.
Step 5 and step 10 of #167.
Goal
Edit a MoonLive script on the module's own card and watch the fixture change on save. Two things blocked it, and only one is about the editor: the File Manager's editor was welded to a <dialog>, and saving a file's contents notified nothing, so nothing recompiled unless the script was renamed.
Outcome
A filepath control type: a picker over a directory filtered by extension, a create and a delete button, and the File Manager's editor mounted inline. A written or deleted file asks the module tree to re-derive, so saving is all it takes. The three MoonLive bindings hold one MoonLiveScript with one rule, "if the file changed, recompile", which removed 116 lines and fixed two bindings that had the rule wrong (the effect had no content hash; the layout cleared its hash only on a rename). Verified on all four boards, flashed, wiped and re-seeded with the 17 role-named scripts; a save on the S3 took lines.mle from 1233 B to 107 B with no /api/control call.
Decisions
- A core seam, not a client-side nudge. The browser re-posting the unchanged path to
/api/controlafter a save was rejected on CLAUDE.md principle 3: core enforces "a change to persistent state re-derives what depends on it" for a control write, and a file write is the next path. A nudge also works only for whoever remembers it, socurl, MoonDeck and the File Manager's modal would each leave a stale program. - A whole-tree request, not a path-to-module registry. A registry needs an association nothing keeps, and
prepare()is the cold path that exists to be re-entered. The hook has the path in hand to narrow later. - The seam needed nothing built. The plan specified a
FileChangedFnhook,main.cppwiring and a coalescing mechanism.HttpServerModulealready held the scheduler andrequestPrepareTree()already coalesces through an atomic flagtick()consumes. The seam is one call at the write success branch, extracted intoapplyFileChangedso it is provable without a socket. It fires on DELETE too, which the plan missed and the pre-merge review caught. ControlType::FilePath, a separate type rather than a flag onTextArea. They store opposite things: a TextArea's value is the body; a FilePath's value is a ~40-byte reference, and the body cannot enter/api/control(413 above the request buffer). Every existing flag leaves the value's meaning untouched.auxcarries{directory, extension}asSelectcarries its options, so no new descriptor field.- Save on blur, Ctrl/Cmd+S and the Save button, never per keystroke. A save writes flash and re-derives, against a half-typed file that is usually invalid.
- A held helper, not a shared base: the bindings derive from three sibling bases under
MoonModule. What differs is how many places ask, a layout being asked fromlightCount()andplaceLights()as well asprepare(), since a container walks its children before they have prepared. The modifier'sneedsRebuild_is what it does after a recompile, sosync()returning "a new program was installed" serves it with no special case, and the cycle-break betweenprepare()and the Layer'sapplyState()is enforced by the return value rather than a comment. - A script's role is its file extension (
.mle,.mll,.mlm), corrected by the product owner. Deriving it from the entry point would tie a UI filter to a language feature: the day a modifier wantstick(), every modifier appears in effect pickers. One language, three extensions, as GLSL uses.vertand.frag. setXYZlost its always-zero index, as a distinctStoreFirstop rather than a flag hiding an argument, since "the one slot I was given" differs from "slot number zero". The emitted code got smaller, Xtensa 163 to 124 bytes formirror.mlm.- A new file is a working example per role, not an empty file that fails to parse the moment it is created.
- Scripts stay inside
kScriptDir: a path separator is refused, so a control value cannot reach../.config/NetworkModule.json.
Where it lives
| What | Home |
|---|---|
The filepath control: what it stores, how it renders, the shared editor guards |
Web UI, Control types |
| A script reaches the device like any other control change | MoonLive architecture |
The one rule, sync(), and why the hash is held by value |
MoonLiveScript.h |
kScriptPick, the hash without a compile, the path refusal |
MoonLiveScriptFile.h |
addFilePath and the type's registration points |
Control.h |
| The seam at the write and delete success branches | HttpServerModule.cpp |
| The control's tests: a name never a body, persistence, no directory means no picker | unit_Control_filepath.cpp |
| The seam's tests | unit_HttpServerModule_apply.cpp |
| "editing a script's text recompiles it, without renaming the file" | unit_MoonLiveLayout.cpp |
The editor extracted from its dialog: fmLoadInto, fmSaveFrom, fmMountEditor, fmCreateFile |
app.js |
Steps
- The filesystem seam and the
MoonLiveScriptconvergence -
ControlType::FilePathand the JS editor extraction, the File Manager unchanged - The card control replacing
addText("script", ...)in the three bindings - Hardware: type in the card, blur, the fixture changes, on all four boards
Shipped in
#67 (commits f94eb6c, 66dd789), #68 (575b447).
The pre-merge review found four defects tests and the bench had missed, all fixed: StoreCtrl reported kArg4 as its first source, so every member assignment stored the wrong register once spilling engaged; the seeding mask was a uint32_t after the arena grew to 64 bytes; a uint16_t initializer was cast to a byte, so phase = 1000 started at 232; and sizeof(MoonLive) had grown to 1440 bytes, held by value in every scripted module and probed on the main task's stack, which was the P4 boot loop (784 bytes after re-indexing the seeded-member table by member). CI added an ASan global-buffer-overflow and a CodeQL read-before-bound, both fixed.
Still open
- The compile-failure latch (a failed script is tried once, not every sweep) cannot be proven on the host: The compile-failure latch is not provable on the host.
- The File Manager's deferred capabilities: File Manager follow-ups.
- Rewriting the
scriptcontrol on a live effect leaves it rendering the previous script: Changing a live MoonLiveEffect's script does not rebind it.
Activity