Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ All notable changes to the Coreflux plugin for Cursor are documented here. The f
### Changed

- The LoT and broker skills are now a pinned copy of
[coreflux-skills](https://github.com/CorefluxCommunity/coreflux-skills) (tag `2.21.16-rc.186`),
[coreflux-skills](https://github.com/CorefluxCommunity/coreflux-skills) (GA tag `2.22.0`),
generated from the broker: `broker-tools`, `lot-actions`, `lot-models`, `lot-routes`,
`lot-rules`, `lot-agents`, `lot-things`, `lot-panels`, `lot-themes`, `python-scripts`.
`npm run skills:sync` updates the copy and `npm run skills:check` (in CI) fails on drift.
- Bundled Coreflux skills updated to 2.22.0 (GA), adding `broker-operations`. The pin must be a
GA tag: `npm run skills:sync` refuses branches and release candidates (ENG-573).

### Removed

Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ npm run e2e # deploys throw-away entities, drives them, removes them
synced from [coreflux-skills](https://github.com/CorefluxCommunity/coreflux-skills), which is
generated from the broker. Do not edit them here; `npm run skills:check` fails on any drift.
Fix the skill in the broker (`src/CorefluxCentral/Agents/Skills/*.md`, `audience: [broker, external]`),
then, once a broker release has tagged coreflux-skills, run `npm run skills:sync -- --ref <tag>`.
then, once a broker GA release has tagged coreflux-skills, run `npm run skills:sync -- --ref <GA tag>`.
Pin GA tags only (`MAJOR.MINOR.PATCH`); the sync script refuses branches and release candidates.
- Plugin-only guidance (this plugin's MCP tools, hooks, profiles) goes in
`skills/coreflux-cursor-tools`, a rule, an agent or a command.
- Keep examples copy-pastable. Prefer realistic names (`PackagingLine`, `PLC_Modbus`) over
Expand Down
8 changes: 5 additions & 3 deletions plugins/coreflux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ workspace file `active` → user file `active` → `default` → `workspace` →

The LoT and broker skills are a pinned copy of
[CorefluxCommunity/coreflux-skills](https://github.com/CorefluxCommunity/coreflux-skills), which is
generated from the broker and tagged per broker release; the tag in use is `brokerVersion` in
`skills/skills.json`. Do not edit them here — fix the broker's skill and move the pin with
`npm run skills:sync -- --ref <tag>`. CI fails when the bundle drifts from the pinned tag.
generated from the broker and tagged per broker GA release; the tag in use is `brokerVersion` in
`skills/skills.json`. Only GA tags are pinned, never a branch or a release candidate. Do not edit
them here — fix the broker's skill and move the pin with `npm run skills:sync -- --ref <GA tag>`.
CI fails when the bundle drifts from the pinned tag.

| Skill | Source | Use |
|-------|--------|-----|
| `broker-tools` | coreflux-skills | The broker's tool surfaces, registry commands, safe deploy workflow |
| `broker-operations` | coreflux-skills | Operating a broker over MQTT: `$SYS/Coreflux/Command` payloads and replies |
| `lot-actions` / `lot-models` / `lot-routes` / `lot-rules` | coreflux-skills | LoT syntax per entity kind |
| `lot-agents` / `lot-things` | coreflux-skills | `DEFINE AGENT`, `DEFINE THING` |
| `lot-panels` / `lot-themes` | coreflux-skills | LoTV dashboards |
Expand Down
274 changes: 274 additions & 0 deletions plugins/coreflux/skills/broker-operations/SKILL.md

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions plugins/coreflux/skills/broker-tools/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: broker-tools
description: Complete reference for the tools you can call on a Coreflux broker: the MCP tool surface the Hub assistant and MCP clients use (validate_lot, deploy_lot, explore_topics, diagnose, provision_data_source and one tool per registry command), the broker__ tools a DEFINE AGENT is granted (read_mqtt, write_mqtt, read_lot, create_lot, execute_routes, execute_actions), Insight vs Agent mode, and the mandatory workflow for deploying LoT safely.
description: "Complete reference for the tools you can call on a Coreflux broker: the MCP tool surface the Hub assistant and MCP clients use (validate_lot, deploy_lot, explore_topics, diagnose, provision_data_source and one tool per registry command), the broker__ tools a DEFINE AGENT is granted (read_mqtt, write_mqtt, read_lot, create_lot, execute_routes, execute_actions), Insight vs Agent mode, and the mandatory workflow for deploying LoT safely."
---

# Broker Tools — Complete Reference
Expand Down Expand Up @@ -74,7 +74,12 @@ Which skill to load before each kind:
(and `get_route_template("TYPE")` over MCP) · Rule → `lot-rules` · Panel → `lot-panels`
· Theme → `lot-themes` · Agent → `lot-agents` · Python script → `python-scripts`
- Before explaining or changing a DEFINE THING, or an entity it owns → `lot-things`
- A vendor REST API (Airtable, ServiceNow, SAP, …) → `rest-api-connectors`
- A vendor REST API (Airtable, ServiceNow, SAP, …) → `rest-api-connectors` on the Hub and in
a DEFINE AGENT. Elsewhere that skill is not available; get the same information from
`list_route_templates` (REST API apps carry `connector: true`) and
`get_route_template("<APP_CODE>")` (`-routeCode <APP_CODE>` over MQTT)
- Raw MQTT commands on `$SYS/Coreflux/Command`, the `$SYS` topic map, users and permission
flags, env vs secrets, projects and `.lotnb` notebooks → `broker-operations`

---

Expand Down
84 changes: 79 additions & 5 deletions plugins/coreflux/skills/lot-actions/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: lot-actions
description: How to write LOT actions: triggers, variables, topic operations, control flow, callable actions, and integrations (Python, MCP, LLM).
description: "How to write LOT actions: triggers, variables, topic operations, control flow, callable actions, and integrations (Python, MCP, LLM)."
---

# LOT Actions — Complete Reference
Expand Down Expand Up @@ -175,6 +175,9 @@ ON TOPIC "sensors/+/data" DO
```
Use `+` for single-level wildcard in topic patterns.
PAYLOAD gives the message content. TOPIC POSITION N extracts segment N (1-based).
PAYLOAD exists only in ON TOPIC and ON CHANGE actions. In ON EVERY, ON START, session triggers and
callable actions there is no message: a bare PAYLOAD fails to compile, and a typed `PAYLOAD AS DOUBLE`
compiles but never holds data. Read the last value with `GET TOPIC "…"` instead.

### ON CHANGE (MQTT-triggered only when payload bytes change)
```
Expand All @@ -193,6 +196,42 @@ ON START DO
```
In a cluster, ON START runs once per cluster start, on one node, at most once. A node that restarts, or a definition deployed later, does not run it again.

### ON CONNECT / ON DISCONNECT / ON SUBSCRIBE (client session events)
```
DEFINE ACTION AuditConnect
ON CONNECT DO
PUBLISH TOPIC "audit/connect/" + CLIENTID WITH USER + "@" + ENDPOINT
KEEP TOPIC "sessions/" + CLIENTID + "/clean" WITH CLEANSESSION

DEFINE ACTION AuditDisconnect
ON DISCONNECT DO
PUBLISH TOPIC "audit/disconnect/" + CLIENTID WITH DISCONNECTREASON

DEFINE ACTION AuditSensorSubscriptions
ON SUBSCRIBE "sensors/#" DO
PUBLISH TOPIC "audit/subscriptions" WITH CLIENTID + " -> " + SUBSCRIBETOPIC + " qos=" + SUBSCRIBEQOS
```
ON CONNECT runs after the broker accepts a client's CONNECT; ON DISCONNECT when the client goes away
(clean, unclean or session takeover); ON SUBSCRIBE after the subscribe permission check allows a
subscription. `ON SUBSCRIBE "pattern"` fires when the subscribed topic filter matches the pattern
(`+`/`#` allowed); bare `ON SUBSCRIBE DO` fires for every allowed subscription.

Session keywords (no braces — they are keywords, not variables):

| Keyword | Value |
|---------|-------|
| CLIENTID | The client that connected, disconnected or subscribed |
| USER | That client's username (`USER IN GROUP "g"` / `USER IS "name"` work too) |
| ENDPOINT | Client address (`ip:port`) |
| CLEANSESSION | `"true"` / `"false"` from the CONNECT packet |
| DISCONNECTREASON | ON DISCONNECT only, e.g. `Clean (NormalDisconnection)`, `NotClean`, `Takeover` |
| SUBSCRIBETOPIC | ON SUBSCRIBE only: the topic filter the client subscribed to |
| SUBSCRIBEQOS | ON SUBSCRIBE only: the granted QoS (0, 1, 2); -1 elsewhere |

These actions have no triggering message: PAYLOAD fails to compile in them and TOPIC POSITION is
empty. The broker
only runs the session hooks while at least one action uses them, so there is no cost when unused.

### Callable actions (INPUT / RETURN / OUTPUT)

Callable actions have no MQTT trigger. Use INPUT lines, DO body, then RETURN with one OUTPUT per line (one variable each). Comma-separated RETURN OUTPUT and single-line RETURN OUTPUT result are rejected.
Expand Down Expand Up @@ -315,6 +354,19 @@ payload with PUBLISH MODEL (below) or return a dict from CALL PYTHON. Do not han
JSON with escaped quotes (`"{\"a\": 1}"`) — a `\"` in a string literal fails to compile.
RETAIN / QOS apply to PUBLISH TOPIC only, never to KEEP TOPIC.

### PAYLOAD AS BYTES — forward binary payloads unchanged
```
DEFINE ACTION ForwardCameraFrame
ON TOPIC "cameras/+/frame" DO
SET "cam" WITH TOPIC POSITION 2
PUBLISH TOPIC "archive/cameras/" + {cam} + "/frame" WITH PAYLOAD AS BYTES
KEEP TOPIC "state/cameras/" + {cam} + "/last" WITH PAYLOAD AS BYTES
```
Plain PAYLOAD goes through a UTF-8 string, which corrupts images, protobuf and other binary data.
`WITH PAYLOAD AS BYTES` on PUBLISH TOPIC or KEEP TOPIC passes the bytes through bit for bit. A string
transformation after it (`PAYLOAD AS BYTES TRIM`, FILTER, REPLACE) is a parse error, and an empty
payload is not published or kept.

### KEEP TOPIC — stored without broadcast, readable by GET TOPIC from any action
```
KEEP TOPIC "state/mode" WITH "running"
Expand Down Expand Up @@ -439,7 +491,19 @@ All timestamps are UTC; there is no local-time format. An unrecognised string is
```
CALL ACTION "CalcAvg" WITH value1 = {a}, value2 = {b} RETURN avg
```
The callable must be deployed first (deploy fails with "Callable action … not found").
Unlike CALL PYTHON, the one-line form is valid here. For long argument lists, WITH and RETURN may also go
on indented lines; several outputs are comma-separated after RETURN:
```
DEFINE ACTION CheckBoilerTemp
ON TOPIC "boiler/+/temp" DO
SET "temp" WITH PAYLOAD AS DOUBLE
CALL ACTION AnalyzeReading
WITH value = {temp}, threshold = 85
RETURN is_above, difference, percentage
IF {is_above} == TRUE THEN
PUBLISH TOPIC "boiler/" + TOPIC POSITION 2 + "/alarm" WITH "over by " + {difference}
```
(`AnalyzeReading` is the callable from "Callable actions" above.) The callable must be deployed first (deploy fails with "Callable action … not found").
Calling the same callable twice in one action currently fails to compile — split it.

### CALL PYTHON — invoke a Python function
Expand All @@ -459,7 +523,13 @@ CALL MCP "MyMcpRoute.search"
WITH (query = "test")
RETURN AS {result}
```
"RouteName.ToolName" in one string; named arguments inside parentheses.
"RouteName.ToolName" in one string; named arguments inside parentheses. There is no TOOL keyword:
`CALL MCP "MyMcpRoute" TOOL "search"` is rejected (the string must contain exactly one dot).

To find the tool names and their parameters, read the retained topics the MCP connector publishes once
it connects: `$SYS/Coreflux/Routes/<Route>/Tools` (summary with the `tools` list) and
`$SYS/Coreflux/Routes/<Route>/Tools/<tool>` (description and `parameters`). Its `usage_example` and
`trigger_example` fields are ready to paste.

### CALL LLM — invoke an LLM route
```
Expand All @@ -477,9 +547,9 @@ CALL AGENT "MyAgent.execute"

### TRIGGER — trigger a route event
```
TRIGGER "MyDB" WITH "sensor1" FOR "ReadSensors"
TRIGGER "MyDB" TO "sensor1" FOR "ReadSensors"
```
Order: route name, WITH the data to send, FOR the route event/mapping name.
Order: connector name, TO the data to send, FOR the route event/mapping name. `WITH` is accepted in place of `TO`, but the data still comes before `FOR`. Writing the event name first and the data after `FOR` still parses, but sends the event name as the data to an event named after the data.

## PUBLISH MODEL — publish a model instance
```
Expand All @@ -497,6 +567,7 @@ JSON reshaping, external library math, or multi-step data processing.
Every script MUST have `# Script Name: <Name>` in the first 10 lines.
Deploy with `broker.add_python(argument=...)` — the argument is the whole script, header included;
the name is read from the header (letters, digits, `_`; must not start with a digit).
In a project (`.lotnb`), Python cells load after the actions; project loading is covered by `broker-operations`.

```python
# Script Name: SensorUtils
Expand Down Expand Up @@ -659,6 +730,9 @@ RETURN
| SWITCH {x} / CASE | IF … ELSE IF … ELSE | SWITCH is not an action statement |
| PAYLOAD AND_THEN TRIM | PAYLOAD TRIM, or FILTER … AND THEN TRIM | Chain keyword is AND THEN (two words) |
| WITH { "k": {v} } | PUBLISH MODEL, or a dict from CALL PYTHON | No JSON object literal |
| PAYLOAD inside ON EVERY / ON START / ON CONNECT | GET TOPIC "…" AS DOUBLE | Only ON TOPIC / ON CHANGE have a message |
| CALL MCP "Route" TOOL "search" | CALL MCP "Route.search" (WITH / RETURN AS indented) | There is no TOOL keyword |
| PUBLISH … WITH PAYLOAD (binary data) | PUBLISH … WITH PAYLOAD AS BYTES | Plain PAYLOAD is decoded as UTF-8 text |

### Trigger indentation - the most common AI mistake

Expand Down
2 changes: 1 addition & 1 deletion plugins/coreflux/skills/lot-agents/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: lot-agents
description: How to write a DEFINE AGENT: the TYPE LLM connector it uses, required clauses, ADD TOOL grants scoped to topics or targets, delegation peers, CALL AGENT from actions, and how agents are added, updated and removed.
description: "How to write a DEFINE AGENT: the TYPE LLM connector it uses, required clauses, ADD TOOL grants scoped to topics or targets, delegation peers, CALL AGENT from actions, and how agents are added, updated and removed."
---

# LOT Agents — DEFINE AGENT
Expand Down
38 changes: 37 additions & 1 deletion plugins/coreflux/skills/lot-models/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: lot-models
description: How to write LOT models: data schemas, field types, MQTT topic bindings, triggers, behaviors (Default, Keep, Collapsed), storage, and inheritance.
description: "How to write LOT models: data schemas, field types, MQTT topic bindings, triggers, behaviors (Default, Keep, Collapsed), storage, and inheritance."
---

# LOT Models — Complete Reference
Expand Down Expand Up @@ -51,6 +51,23 @@ Models define data schemas that map MQTT topics to typed fields.
`ADD JSON "x"` and `ADD TIMESTAMP "x"` are parse errors — use OBJECT and STRING.
The type may be omitted (`ADD "x" WITH TOPIC "t"`); it is then inferred from the value.

To embed JSON you received (not a string of it), assign the JSON text to an OBJECT or ARRAY field in
PUBLISH MODEL. The text is parsed into the document; text that is not valid JSON becomes `{}` / `[]`.
```
DEFINE MODEL GatewayEnvelope COLLAPSED
ADD STRING "gateway"
ADD OBJECT "data"
ADD STRING "received" WITH TIMESTAMP "ISO"

DEFINE ACTION WrapGatewayData
ON TOPIC "gateways/+/raw" DO
SET "gw" WITH TOPIC POSITION 2
PUBLISH MODEL GatewayEnvelope TO "gateways/" + {gw} + "/envelope" WITH
gateway = {gw}
data = (GET JSON "data" IN PAYLOAD AS STRING)
```
`GET JSON … AS STRING` on a nested object returns its JSON text, so `data` is published as an object.

## Field Bindings

### WITH TOPIC — bind field to an MQTT topic
Expand All @@ -65,6 +82,24 @@ ADD DOUBLE "temperature" WITH TOPIC "sensors/temp" AS TRIGGER
When a message arrives on the trigger topic, the model re-evaluates and publishes.
At least one field must be AS TRIGGER for the model to auto-publish.

Several fields may be AS TRIGGER; a message on any one of them publishes the model, with the other
fields at their last known values:
```
DEFINE MODEL MachineSnapshot COLLAPSED WITH TOPIC "machines/press1/snapshot"
ADD DOUBLE "temperature" WITH TOPIC "machines/press1/temp" AS TRIGGER
ADD DOUBLE "pressure" WITH TOPIC "machines/press1/pressure" AS TRIGGER
ADD STRING "timestamp" WITH TIMESTAMP "ISO"
```

### WITH COLLECTION TO TOPIC — build an array from numbered subtopics
```
DEFINE MODEL LineOrders COLLAPSED WITH TOPIC "line1/orders/summary"
ADD STRING "line" WITH TOPIC "line1/orders/updated" AS TRIGGER
ADD ARRAY "orders" WITH COLLECTION TO TOPIC "line1/orders/item"
```
The array is read from `line1/orders/item/0`, `line1/orders/item/1`, … and stops at the first missing
index. Declare the field ARRAY, and publish one JSON object per index.

### WITH (static or computed default) — NO VALUE keyword
Static defaults use WITH directly. Never use WITH VALUE — the parser rejects it for anything but a plain literal.
```
Expand Down Expand Up @@ -324,6 +359,7 @@ ON TOPIC "machines/+/cycle" DO
| ADD STRING "ok" WITH VALUE "ok" | ADD STRING "ok" WITH "ok" — VALUE only takes a literal; drop it |
| No AS TRIGGER on any field (topic-bound model) | At least one field must have AS TRIGGER |
| ADD JSON "cfg" / ADD TIMESTAMP "ts" | ADD OBJECT "cfg" / ADD STRING "ts" WITH TIMESTAMP "ISO" |
| ADD STRING "data" for received JSON (published as an escaped string) | ADD OBJECT "data" — JSON text assigned to it is parsed |
| DEFINE MODEL Device / DEFINE MODEL Event | Keyword names are rejected — DeviceInfo, EventRecord |
| DEFINE child before parent | Define parent model first |
| COLLAPSED when subtopics are needed | Only use COLLAPSED when you want one JSON blob |
41 changes: 40 additions & 1 deletion plugins/coreflux/skills/lot-panels/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: lot-panels
description: How to write LoTV panel definitions: DEFINE PANEL, ADD COMPONENT, BIND, ON events, WITH VISIBILITY, WITH INTERACT, and the mandatory workflow for deploying panels via broker.add_panel.
description: "How to write LoTV panel definitions: DEFINE PANEL, ADD COMPONENT, BIND, ON events, WITH VISIBILITY, WITH INTERACT, and the mandatory workflow for deploying panels via broker.add_panel."
---

# LoTV Panel Authoring — Coreflux Visual Language
Expand Down Expand Up @@ -710,6 +710,7 @@ Ask these questions in order. Stop at the first YES that applies:
"show a button to start machine" WITH TYPE "button" + ON CLICK DO PUBLISH (only if user explicitly asked for a control)
"show a switch to turn on light" WITH TYPE "switch" + ON TOGGLE DO PUBLISH ... WITH STATE (only if user explicitly asked; NEVER auto-add next to an indicator)
"navigate between screens" WITH TYPE "button" + ON CLICK DO NAVIGATE
"button that asks an agent" WITH TYPE "button" + SET AWAIT "AnswerText" (+ "text" with SET MARKDOWN true)

### Quick reference — layout and navigation

Expand Down Expand Up @@ -1675,6 +1676,44 @@ DEFINE PANEL "LineOverview"
clicking user. It is refused (logged, not run) for an event whose name starts with `_`
and for an agent route.

### Slow answers — `SET AWAIT` on a button, `SET MARKDOWN` on text

When a button starts something that answers later on another topic (an agent
brief, a route reply), name the components that answer lands in with
`SET AWAIT`. When the answer is markdown (agent output usually is), add
`SET MARKDOWN true` to the `text` component that shows it.

```lot
ADD COMPONENT "Briefing" WITH TYPE "card"
SET TITLE "Coordinator briefing"
ADD COMPONENT "BriefingText" WITH TYPE "text"
SET MARKDOWN true
BIND CONTENT TO TOPIC "site/out/briefing"
ADD COMPONENT "AskBriefing" WITH TYPE "button"
SET LABEL "Brief me now"
SET AWAIT "BriefingText"
SET AWAIT_TIMEOUT 300
ON CLICK DO
PUBLISH TOPIC "site/requests/briefing" WITH "operator request from the panel"
```

- `SET AWAIT "Id[, Id…]"` (buttons only): on click the Hub disables the button
with a spinner and marks each named component as waiting (dimmed, spinner and
elapsed seconds; an empty `text` shows a skeleton instead of `---`). A
component settles on the next message on any topic it is bound to, even an
identical payload. The button frees up once every named component settled.
- `SET AWAIT_TIMEOUT <seconds>` (default 120, 1–3600): after it the button frees
up and a component that is still waiting shows "No update after N s" until its
next value. Set it a little above the agent's `TASK_TIMEOUT` or the route's
worst case.
- Every `AWAIT` id must be a component of the same panel with a `BIND`; the
parser warns otherwise. If the action can skip publishing (a cooldown, a
guard), publish something on the awaited topic in that branch too, or the
panel waits until the timeout.
- `SET MARKDOWN true` renders bold, italics, lists, headings, links and code.
Raw HTML is never rendered (it shows as text) and images are dropped. Without
it, text stays plain.

---

## Visibility Decision Tree
Expand Down
Loading
Loading