flua
AGENTS.md1 starsChanged 15 days agoMITView on GitHub
Guidance for AI agents (any framework — Claude Code, Codex, Copilot, DeepSeek, or plain LLM tooling) working on flua. Humans: see CONTRIBUTING.md and USAGE.md. flua is a Lua engine for Fibaro HC3 QuickApps: lupa (bundled Lua) hosted in Python with an asyncio pump, a virtual clock, a message-passing bridge, and a simulated HC3 REST API. The same QA file runs offline in the sim, online against a real HC3, or in proxy mode (a mirror QA on the HC3). -…
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,439 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository18 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- code-tourSkill
- flua-setupSkill
- flua-troubleshootingSkill
- hc3-lua-scenesSkill
- hc3-rest-apiSkill
- hc3-write-safetySkill
- lua-basicsSkill
- network-device-testSkill
- plua-migrationSkill
- quickapp-apiSkill
- quickapp-patternsSkill
- quickapp-testSkill
- quickapp-troubleshootingSkill
- quickapp-typesSkill
- quickapp-uiSkill
- qwikchildSkill
- skill-creatorSkill
The file
We split this AGENTS.md into the rules it gives an agent
10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 71
Treat CLI flags, --%% directives, public Python APIs, and Lua runtime APIs as compatibility-sensitive.
- Very specific: line 117
Run ruff check and the relevant tests before and after any change.
- Very specific: line 128
Keep _PY (the Lua↔Python bridge surface) minimal.
- Distinctive: line 138
Use this workflow regardless of the agent framework (Copilot, Codex, Claude Code, Cursor, or another tool):
- Very specific: line 141
Read this file and CONTRIBUTING.md, then inspect the relevant source and existing tests before proposing a change.
- Distinctive: line 144
Add or update a deterministic test for behavior changes.
- Distinctive: line 146
Update the appropriate documentation when behavior, directives, CLI flags, or compatibility contracts change.
- Very specific: line 148
Run the narrowest relevant test first, then ruff check src/ tests/ and pytest tests/ -q when practical.
- Distinctive: line 158
When a behavior is intentional-but-surprising (e.g.
- Distinctive: line 161
Do not touch the live HC3 from tests or scripts unless explicitly asked.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — working in the flua repository
Guidance for AI agents (any framework — Claude Code, Codex, Copilot, DeepSeek, or plain LLM tooling) working on flua. Humans: see CONTRIBUTING.md and USAGE.md.
What this repo is
flua is a Lua engine for Fibaro HC3 QuickApps: lupa (bundled Lua) hosted in
Python with an asyncio pump, a virtual clock, a message-passing bridge, and a
simulated HC3 REST API. The same QA file runs offline in the sim, online
against a real HC3, or in proxy mode (a mirror QA on the HC3).
- Runtime:
src/flua/— Python engine + the HC3 runtime insrc/flua/lua/. - Docs:
USAGE.md(user guide),ARCHITECTURE.md(internals),docs/concurrency.md(threading/execution model, blocking rules, graceful exit),docs/walkthroughs.md(guided traces of key flows),docs/invariants.md(behavioral contracts with their pinning tests),docs/rest-endpoints.md(real vs shape-only-stub REST routes),docs/mcp.md(the flua-mcp server: protocol, tools, host setup),docs/decisions/(ADR-lite — update when a decision changes).README.md(overview). - Examples:
examples/— runnable QuickApps; the test suite treats them as living fixtures, so keep them terminating unless their purpose is to run forever. - Specs/references:
docs/specs/— includinghc3-api.json, the checked-in structural reference of the HC3 REST API (endpoints, parameters, response codes, schema fields) distilled from the official swagger.
Commands
python3 -m venv .venv && .venv/bin/pip install -e ".[dev]" # first time
.venv/bin/pytest tests/ -q # full suite (live-HC3 skipped)
.venv/bin/pytest tests/ -q --serial # one process (debugging; -n 0 also works)
.venv/bin/pytest tests/ -q -m "not slow" # fast gate: skips wall-clock-bound tests
.venv/bin/pytest tests/test_qa.py -q # one file
.venv/bin/ruff check src/ tests/ # lint (must pass)
.venv/bin/ruff format src/ tests/ # format (line length 100)
.venv/bin/flua --check file.lua # static check a QAPython 3.11+. lupa is the only runtime dependency.
Repository map
| Area | Purpose | Typical changes |
src/flua/engine.py | Lua VM, queues, and message pump | Engine and scheduling behavior |
src/flua/mcp/ | The MCP server (flua-mcp): stdio + Streamable HTTP transports, tool registry, resources, prompts | New tools, protocol surface |
vscode/ | VS Code extension: explorer tool menus, check-on-save diagnostics, .fqa schema | Extension features |
src/flua/api/ | Simulated and hybrid HC3 REST API | API routes and simulated state |
src/flua/api/routes/ | Pure REST route handlers | New or changed endpoints |
src/flua/lua/ | HC3-compatible Lua runtime | QuickApp, fibaro, timer, and network behavior |
src/flua/cli.py | flua command-line interface | CLI flags and commands |
src/flua/tools/ | QA download/upload/update tools | HC3 file-management tools |
src/flua/proxy.py | Proxy-mode deployment and callbacks | Proxy synchronization |
tests/ | Behavioral and compatibility contract | Regression and feature tests |
examples/ | Runnable QuickApp fixtures | User-facing examples |
docs/specs/ | Checked-in HC3 API reference | Endpoint and schema reference |
dev/ | Local scratch space | Temporary probes only; never commit |
Compatibility
- Python 3.11 or newer is supported.
lupais the only runtime dependency; avoid adding dependencies without discussing the trade-off in the change.- Preserve HC3 behavior where practical. If flua intentionally differs, make
the difference explicit in tests and document it in
USAGE.mdorARCHITECTURE.md. - Treat CLI flags,
--%%directives, public Python APIs, and Lua runtime APIs as compatibility-sensitive. Do not change them silently.
How the tests work
- Almost everything runs offline: QAs against the simulated HC3, and online/proxy tests against local mock HC3 servers (threaded HTTP servers defined in the test files themselves). Never hit a real controller.
- Tests run in parallel by default (
-n autoin addopts; ~20s on 8 cores).--serial(or-n 0) runs one process for debugging;-m "not slow"skips the tests that deliberately spend wall-clock time (real sleeps, protocol settles, socket timeouts) — they carry theslowmarker. tests/test_hc3_live.py/tests/test_hc3_compat.pyare opt-in live-HC3 suites (setHC3_TEST=1and configure credentials).- Many tests bind localhost sockets (mock servers, emulator callback servers). A sandbox that denies socket binds will fail them — run with local socket access.
- Tests assert on QA stdout (
capsys) and on mock-server request records — follow that pattern for new behavior: deterministic, no sleeps where await_until/wait_for_outputhelper exists.
Architecture map (read before changing)
src/flua/engine.py—LuaEngine: the lupa VM, message queues, pump. Single-entry discipline: Lua is entered only from_PY.dispatch(batch).src/flua/messages.py— the wire format; everything crossing the bridge is a JSON-compatible dict. Never cross a Lua function reference.src/flua/api/— the HC3 REST API.state.pyis the sim world;routes/*.pyare pure(SimState, ApiRequest) -> (data, status)handlers;Api.dispatchdoes hybrid routing (sim first, real HC3 as fallback, offline-pinned QAs never reach the HC3).src/flua/lua/— the HC3 runtime in Lua:init.lua(pump handlers, timers, per-QA environments),quickapp.lua,fibaro.lua,net.lua,mqtt.lua.src/flua/cli.py— thefluacommand.src/flua/tools/— the--toolcommands (downloadQA/uploadQA/updateQA): one module per tool, auto-discovered by the package registry; shared helpers live intools/common.py.src/flua/config.py—--%%directive parsing,--%%includedefaults,.flua-directivesoverrides, mode normalization (--%%mode:online|offline|proxy).src/flua/proxy.py— proxy mode: proxy QA deployment on the HC3, state mirroring, callback server.
Conventions and invariants
- Run
ruff checkand the relevant tests before and after any change; add a test for new behavior (the suite is the contract). - API handlers stay pure; side effects go through
req.emit/req.remote/forward_to_proxy. - QA ids: engine-assigned from 5000; proxy QAs run under their HC3 id; the sim shadow and the HC3 device are the same id.
- A QA's
api.*calls with a remote backend (online/proxy mode) suspend only the calling QA — the pump and other QAs keep running (per-QA coroutines + the shared deferral machinery,init.lua). Engine-side remote calls and the debugger still block the pump — keep those LAN-local and rare. - Keep
_PY(the Lua↔Python bridge surface) minimal; convenience lives in Lua. dev/is scratch. Do not commit probes.- Docs: behavior changes belong in
USAGE.md(user-facing) and/orARCHITECTURE.md(internals); new contracts, event shapes, or identity rules belong indocs/invariants.mdwith a pinning test; concurrency changes belong indocs/concurrency.md. Directive changes belong in the directive table.
Workflow for AI agents
Use this workflow regardless of the agent framework (Copilot, Codex, Claude Code, Cursor, or another tool):
- Read this file and
CONTRIBUTING.md, then inspect the relevant source and existing tests before proposing a change. - Make the smallest focused change; do not refactor unrelated code.
- Add or update a deterministic test for behavior changes. Do not use a live HC3 unless the user explicitly requests it.
- Update the appropriate documentation when behavior, directives, CLI flags, or compatibility contracts change.
- Run the narrowest relevant test first, then
ruff check src/ tests/andpytest tests/ -qwhen practical. - Review the diff for secrets, accidental probes, live-controller access, and generated files.
- Report changed files, tests run, and any validation that could not run.
Working with the user
- The project owner is the author and main developer; changes are reviewed commit-by-commit. Prefer small, focused, verifiable changes.
- When a behavior is intentional-but-surprising (e.g. a proxy QA sharing its HC3 device id with the sim shadow), document it rather than silently changing it.
- Do not touch the live HC3 from tests or scripts unless explicitly asked.
Repo-specific agent files
.github/copilot-instructions.md— GitHub Copilot workspace instructions..github/instructions/quickapp-dev.instructions.md— auto-applied to all*.luafiles in Copilot..github/skills/— Copilot slash-command skills (flua-setup, flua-troubleshooting, quickapp-*, hc3-rest-api, ...)..github/prompts/install-qa-skills.prompt.md— installs the above into another workspace.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

