/mass-balance:mass-balancefrom mass-balance
Performs mass/material balances on chemical or process plants using historian data and process context (P&ID, PFD, tag list, knowledge graph). Converts meters to mass basis, reconciles measurements, detects meter errors, analyzer drift, and material losses.
Ships in mass-balance. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
The scripts do the arithmetic: unit conversion, the volume-to-mass basis, inventories, reconciliation, gross error tests, detection and charts. You do the engineering judgement: which streams cross the balance boundary, which are utilities, where densities and accuracies come from, and whether the findings make physical sense. Show the user every judgement call and ask them to confirm the ones that matter.
All scripts live in scripts/ next to this file. Run them with full paths. Work in a folder in the user's directory, for example mass_balance/<plant>, and give every --out as an absolute path inside that folder, so nothing is written into the skill's own folder.
Setup (do it yourself, silently unless something is missing). Python 3.10 or newer, then pip install -r <this skill>/scripts/requirements.txt in a virtual environment. Check with python scripts/mb.py doctor. If Python is missing, ask the user to install it from python.org and stop.
The people using this are usually process engineers. Talk in engineering terms, run every command yourself, and never ask them to edit JSON or code.
- [ ] 0. Inputs: find the data, the tag list, the process context
- [ ] 1. Graph: use the knowledge graph, or build one from the P&ID (bundled pid-to-kg), or write topology.json
- [ ] 2. Streams: python scripts/mb.py streams --kg <graph> -> confirm boundary and utilities
- [ ] 3. Draft: python scripts/mb.py draft --kg <graph> --tags <tags> --data <history> --out model.json
- [ ] 4. Complete: fill every TODO from the process description, data sheets or the user; record the source
- [ ] 5. Check: python scripts/mb.py check --model model.json
- [ ] 6. Run: python scripts/mb.py run --model model.json --out <job folder>/results --open
- [ ] 7. Review: read results/supporting_files/results.json and the charts; test every finding against the physics;
add an engineer's note only if the review finds something the takeaways miss
- [ ] 8. Report: answer in the fixed layout in step 8: the takeaways and actions first, then the details
Ask for, or find in the folder:
tag, timestamp, value[, quality]) or wide (one column per tag). Compressed exports are fine; the loader interpolates between stored points and never across a bad-quality sample.graph.json or a kg/ folder from pid-to-kg, or GraphML): use it.../pid-to-kg/SKILL.md and follow it completely, including its QA loop, with its work directory inside this job's folder. Its scripts are in ../pid-to-kg/scripts/. Then continue here with <work>/kg.topology.json with the user from the tag list and process description (format in references/input_contract.md). Keep it to the streams that cross the balance boundary, the meters on them and the vessels with level.mb.py streams lists every material path between equipment and battery limits, with the instruments and control valves on it. Pumps are folded into the stream they move. Decide with the user:
"free" if nothing is known. A free stream absorbs its envelope's imbalance and removes that balance's ability to test anything. Say so to the user.mb.py draft writes model.json with every stream, the historian tag mapped to each drawing instrument, meter types and default accuracies where the drawing names the meter, inventories, and the envelope. It maps a field transmitter on the drawing (FT-201) to the tag that carries its reading in the historian (FIC-201.PV) through the signal lines and loop membership. Check every mapping in the printout.
What the draft cannot know is left as TODO. Fill each one and add a "source" note saying where the value came from:
| TODO | Where to get it |
|---|---|
| Density for a volumetric meter | An inline density tag on the same line; else a density relation from the process description or a property table, with the stream's temperature and composition tags; else a fixed value. See references/properties.md. Never leave a volumetric meter on a volume basis. |
| Meter accuracy | Data sheet or process description; else the defaults in references/meter_uncertainty.md, and say they are defaults. |
| Analyzer accuracy | Data sheet; else 1 to 2 % of reading. |
| Vessel geometry | Data sheet or process description: diameter, the volume below the level zero (heads, cones, heaters, circulation loop), or a strapping table. |
| Contents density and composition | Usually the outlet stream's, at the vessel temperature. |
| Composition of streams without an analyzer | Zero for a pure solvent or vapour stream, or a fixed value from the process description. Without a composition on every crossing stream, the component balance is skipped. |
| Baseline | A documented normal period, or ask. |
Ask the user only for what the documents do not give, in one short message.
mb.py check refuses to run while a TODO remains or a tag is missing from the data. mb.py run clears its own earlier files from the output folder, then writes:
results/
├── mass_balance_report.html the report: the one file the user opens
└── supporting_files/
├── results.json everything, machine-readable (schema 1.1, references/output_format.md)
├── README.txt what each supporting file is
├── mass_balance_report.md the report as Markdown
├── chart_*.png the charts (also embedded in the HTML)
└── *.csv residuals, measured values, daily mass flows, detection statistics
The report opens with Key takeaways and Actions, written by the script from the results by fixed rules: the same results always give the same bullets. They are also in results.json as takeaways and actions. --open opens the report in the user's browser when the session runs on their computer; it does nothing harmful elsewhere.
Never edit results.json or the report by hand. If something in them is wrong, fix the model and run again.
Read supporting_files/results.json and look at the charts. Start with takeaways, actions and findings: one finding per incident, plus one for significant drift, each with an id (mass-balance-1, ...), kind, category, times, severity, tags, summary, evidence and checks. The balance-specific detail is in baseline_closure, volume_vs_mass, reconciliation_baseline, incidents and drift. For each item, check it against the process:
Engineer's note. If the review turns up something the takeaways do not say, such as an incident that lines up with a setpoint change, a finding the trends do not support, or a default value that matters, add it to the top of the report:
python scripts/mb.py note --results <job folder>/results "One or two plain sentences."
The note appears in the key takeaways, marked as an engineer's note, and in results.json as engineer_notes. Keep it to what changes the reader's conclusion or actions. Do not restate the takeaways. --clear removes earlier notes.
Always answer in this layout, so every run reads the same. Plain engineering language; take every number from results.json, never recompute it.
## Mass balance: <plant>
**Key takeaways**
<every entry of `takeaways`, as bullets, word for word, in order; then each engineer's note>
**Actions**
<every entry of `actions`, numbered, word for word, in order>
**Open the report:** <absolute path to mass_balance_report.html>
### Details
<only what the user needs beyond the takeaways, briefly: what was balanced and which values
were defaults or assumptions; for each incident that needs more than its bullet, the
evidence that decided it and the alternatives that could not be ruled out, citing its id
(mass-balance-1, ...); what would make the balance more decisive (a meter, a density
meter, an analyzer)>
These are statistical signatures in plant data. Confirm them in the field before acting.
Do not reword, reorder or drop the takeaways and actions: the user sees the same bullets at the top of the report. If you disagree with one, say why in an engineer's note (step 7).
references/methods.md: basis conversion, inventory, reconciliation, the global, measurement and GLR tests, the trailing reference, equivalence and tie-breaking, with sources.references/input_contract.md: data formats, model.json schema, topology.json format.references/meter_uncertainty.md: default accuracies by meter type and how to treat them.references/properties.md: density relations and how to fit one from a property table.references/interpreting_results.md: what each result means and common pitfalls.references/output_format.md: every output file and the results.json schema.references/input_contract.md (opens in a new tab)references/interpreting_results.md (opens in a new tab)references/meter_uncertainty.md (opens in a new tab)references/methods.md (opens in a new tab)references/output_format.md (opens in a new tab)references/properties.md (opens in a new tab)scripts/massbal/__init__.py (opens in a new tab)scripts/massbal/data.py (opens in a new tab)scripts/massbal/diagnose.py (opens in a new tab)scripts/massbal/engine.py (opens in a new tab)scripts/massbal/kg.py (opens in a new tab)scripts/massbal/model.py (opens in a new tab)scripts/massbal/pipeline.py (opens in a new tab)scripts/massbal/properties.py (opens in a new tab)scripts/massbal/reconcile.py (opens in a new tab)scripts/massbal/report.py (opens in a new tab)scripts/massbal/result.py (opens in a new tab)scripts/massbal/takeaways.py (opens in a new tab)scripts/massbal/units.py (opens in a new tab)scripts/mb.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
2 skills in this plugin
Other plugins' skills for the same job
Claude Code refuses to install this plugin
.claude-plugin/plugin.json: skills.0: Invalid string: must start with "./", skills.1: Invalid string: must start with "./"
Checked against Claude Code 2.1.332's install rules. The listing below is what the repository ships; Claude Code cannot install it as published.