Writing a config in VS Code
A config, and its transformation rules in particular, is plain JSON, so an integrator can write it in an
editor. The editor kit is a small directory you copy into your configuration repository so that VS Code
completes rule and field names, underlines a wrong shape, offers three rule patterns as snippets, and runs
Kindred's own checks from a menu. It is settings and data: there is no extension to install, and the rules stay the
state_transition_rules and field_map a config already holds. The kit is in
examples/editor-kit/ in the repository.
The editor only checks shape. The offline check and the mapping preview decide whether a config is sound, and neither decides whether it is right (see What the checks do not tell you).
What is in the kit
| Path | What it is |
|---|---|
schemas/ |
One JSON Schema file per Node Type, made from that Node Type's configuration schema by deployment/generate_editor_schemas.sh |
.vscode/settings.json |
Which config files are checked against which schema |
.vscode/kindred.code-snippets |
Three rule patterns: kindred-status-classifier, kindred-field-map and kindred-record-kinds |
.vscode/tasks.json |
Two tasks: the offline check and the mapping preview |
AGENTS.md |
Instructions for a coding agent that writes rules: the same page, named so that an agent reading AGENTS.md finds it |
Setting it up
- Copy
.vscode/,schemas/andAGENTS.mdinto the root of your configuration repository, and make sure the repository does not ignore.vscode/(a.gitignoreline of.vscode/needs!/.vscode/after it), or the settings, snippets and tasks stay on your machine. If the repository already has anAGENTS.md, merge the page into it and do not overwrite it. - Keep each config under
configs/<node-type>/, where<node-type>is the name of the Node Type's directory innode-types/:erp,mes,plc-generic-deviceorproduction-scheduling. Any depth and any file name ending in.jsonwill do. A file name ending in.enc.jsonis left alone: an encrypted file is not JSON the editor can read. - For the tasks, a Python has to import the engine, and the Node Type definitions have to be on disk. Use the
Python environment of a Kindred checkout at the tag your sites run, and give its
node-types/directory when a task asks for it. The tag has to carry the Node Type version your configs name, because a config for any other version is invalid (see the tag must match).
A config names its Node Type's version, and each schema holds that version, so a config for another version is underlined. When you move to a newer tag, regenerate the schemas and commit them:
PATH-TO-CHECKOUT/deployment/generate_editor_schemas.sh --node-types PATH-TO-CHECKOUT/node-types --out schemas
The script is in the Kindred checkout, not in the kit. Run the command from the root of your configuration
repository, so schemas is the one you copied.
--check writes nothing and exits 1 if a file is out of date, which makes it usable in a pipeline.
Starting points are not checked by the editor
A starting point has its own wrapper (starting_point_format, placeholders) and holds
placeholders that are not yet values, so the config schema would underline every one of them. Keep starting points
outside configs/, for example in starting-points/, and check them with check_config_repo.sh --template
(see Checking a configuration repository in CI).
What the editor does
- Completes and describes. Section and field names are offered as you type, and hovering shows what a field is for.
- Underlines a wrong shape. An unknown key, a value of the wrong type, a
thenvalue that is not text, a missing required field, a wrongnode_typeornode_type_version. - Does not check what a schema cannot say. That exactly one source section is present, that every source key
is read by the mapping, and that a name the mapping reads exists are findings of the offline check. A config that
uses shared fragments can show underlines where a fragment stands in;
the offline check with
--shared-diris the judge there.
The snippets
Type kindred- in a .json file under configs/ and press Ctrl+Space. Each snippet is inserted inside a
connector section, such as mqtt, and every placeholder is in capitals. Fill each one in; a placeholder left
as it is makes the file invalid JSON, so it stays underlined.
| Prefix | For |
|---|---|
kindred-status-classifier |
A status field whose codes mean different things, with a last rule that matches every other code |
kindred-field-map |
A source whose records already mean what Kindred's fields mean, so each field only needs renaming |
kindred-record-kinds |
One feed that carries more than one kind of record, told apart by one field |
Three things the snippets cannot do for you:
- A code has the type the record gives it.
4and"4"are different values, and a rule for one never matches the other. The placeholders for a code are not quoted, so you choose. - A record that matches no rule passes through unchanged and the preview reports it. The classifier ends with a
rule that matches everything; the record-kinds snippet does not, because whether a record of an unknown kind
should be labelled or reported is a choice. The preview prints a note for a rule set with no such rule, and the
note is not a gap. Add a rule with an empty
whenas the last rule to label them (see Data transformation layer). - The Kindred field names are the Node Type's. The names to put on the left of a
then, aliteralsentry or afield_mapare the event's fields, which the Node Type'sevent_typeslist in itsnode_type.jsonundernode-types/(the agent instructions say the same). The snippets name none of them.
The tasks
Run them from Terminal, Run Task. Both show the command's own output in a terminal panel, and both take its exit code. Nothing reads the printed text, because it can change between releases.
| Task | Runs | Asks for |
|---|---|---|
| Kindred: offline check of this file | python3 -m engine.offline_check_cli on the open file |
The Python to run, the directory of Node Type definitions (node-types/) |
| Kindred: mapping preview of this file | python3 -m engine.mapping_preview_cli on the open file |
The Python to run, the directory of Node Type definitions, a sample file, and extra options if any |
The exit codes are the commands' promise.
| Command | Code | Meaning |
|---|---|---|
| Offline check | 0 | The config is valid |
| 1 | The config is invalid | |
| 2 | The check could not run: a usage error, an unreadable file or a Node Type directory that cannot be used | |
| 5 | No verdict: the file is encrypted and no age key is available | |
| Mapping preview | 0 | No gaps found (a note about a missing catch-all can still be printed) |
| 1 | A gap or a flagged event was found, including a rule that is never reached | |
| 2 | The inputs could not be used |
The Python to run is python3 unless the engine is in a virtual environment; then give that environment's python.
A Python that cannot import the engine ends with "No module named 'engine'" and exit code 1, which is the same
code as an invalid config: if you see that message, the interpreter is wrong and the config has not been judged.
The offline check also has 3 and 4, which only --connect gives. The task does not use --connect, so it reaches
no target system.
The sample is a JSON array or JSON lines file. The preview's report never prints a value from it, but you and
any assistant that opens the file do see it, so use synthetic records, or a model your site controls if the
records are real. A Node Type with no fixed identity field (PLC / Generic Device and ERP) needs
--identity-field FIELD in the options box. If the config has more than one connector section, add --section.
Writing the rules with a coding agent
AGENTS.md is the instructions page, copied into the kit so that an agent that reads
AGENTS.md picks it up with no setup. An agent that reads another file name (some read CLAUDE.md or
.cursorrules) does not: copy the page under the name yours reads. It teaches the rule model, how a rule
matches, what a missing catch-all does and the loop of writing, checking and previewing, and it tells the agent to ask you what a status code means. It does not
make the agent's output right: you compare the rules with what the site told you. A sample file holds site data
that the agent can read, so use synthetic records, or a model your site controls if the records are real.
What the checks do not tell you
A config can pass the offline check and the preview and still be wrong. They find a rule set that cannot be
loaded, a key nothing reads, a rule that is never reached and a record nothing matches. They do not know what a status code means: that 4 is
a finished cycle comes from the vendor's documentation and from the people at the site, and a rule that says
otherwise passes both checks. Compare the rules with what the site tells you, and with a sample the site captured.
Passwords and keys
Do not put a password, an API key or a token into a file under configs/, or into anything an assistant in your
editor can open. Write the rules in the file, and set the credential on the appliance, through the
configuration page or the draft route of the management API, which stores it encrypted and never shows it back
(see The configuration page, the draft and
The configuration assistant, which never sees a credential). The schemas mark which
fields are credentials, but the editor does not warn when you fill one in, and the snippets have no place for one.
Release: v0.11.0