diff --git a/.agents/skills/formchem-harness/EVALS.json b/.agents/skills/formchem-harness/EVALS.json
index 8e288d02..e5060c3b 100644
--- a/.agents/skills/formchem-harness/EVALS.json
+++ b/.agents/skills/formchem-harness/EVALS.json
@@ -1,6 +1,6 @@
{
"skill_name": "formchem-harness",
- "notes": "Run with the FormChem engine and window open (./formchem) and the formchem MCP server connected with the agent token, version 0.10.0. Expected behaviours are observable in the tool calls and the final answer. FormChem 0.10.0 has 60 tools: agents draw with draw_from_smiles, draw_from_molfile, draw_from_name and add_reaction, edit by id with get_atoms and the 14 edit tools, check with render, get_structure and validate, name with name_structure, predict NMR with predict_nmr and predict_spectrum, work on spectra with open_spectrum and the spectrum tools, work in 3D with build_3d, conformers_3d, minimise_3d, scan_dihedral, measure_3d, open_3d_structure, extract_ligand and export_3d, and still reach the window's commands, reactions, analysis and extensions; several evals check that the agent draws with the tools and checks before it claims. Evals 13 and 14 need a drawn esterification scheme (acetic acid + ethanol, arrow, ethyl acetate + water); evals 15 to 18 need ibuprofen inserted with insert-smiles CC(C)Cc1ccc(cc1)[C@@H](C)C(=O)O; eval 20 needs an SD file at the path it names; eval 28 needs ethyl acetate drawn; eval 29 needs a JCAMP-DX 1H NMR file of ethanol at the path it names; eval 33 needs a PDB file with a protein chain and a benzamidine ligand (BEN) at the path it names; eval 34 needs butane drawn.",
+ "notes": "Run with the FormChem engine and window open (./formchem) and the formchem MCP server connected with the agent token, version 0.12.0. Expected behaviours are observable in the tool calls and the final answer. FormChem 0.12.0 has 77 tools: agents draw with draw_from_smiles, draw_from_molfile, draw_from_name and add_reaction, edit by id with get_atoms and the 14 edit tools, check with render, get_structure and validate, name with name_structure, predict NMR with predict_nmr and predict_spectrum, work on spectra with open_spectrum and the spectrum tools, work in 3D with build_3d, conformers_3d, minimise_3d, scan_dihedral, measure_3d, open_3d_structure, extract_ligand and export_3d, work with structure databases and the notebook with db_list, db_create, db_open, db_import, db_search, db_get_record, db_add_record, db_update_record, db_export, nb_add_entry and nb_search, keep the shared structure library with library_list, library_add and live_structure_object, draw biopolymers with draw_from_helm, run xtb and CREST (only when installed) with xtb_optimise and crest_conformers, and still reach the window's commands, reactions, analysis and extensions; several evals check that the agent draws with the tools and checks before it claims. Evals 13 and 14 need a drawn esterification scheme (acetic acid + ethanol, arrow, ethyl acetate + water); evals 15 to 18 need ibuprofen inserted with insert-smiles CC(C)Cc1ccc(cc1)[C@@H](C)C(=O)O; eval 20 needs an SD file at the path it names; eval 28 needs ethyl acetate drawn; eval 29 needs a JCAMP-DX 1H NMR file of ethanol at the path it names; eval 33 needs a PDB file with a protein chain and a benzamidine ligand (BEN) at the path it names; eval 34 needs butane drawn; evals 36 to 40 need an SD file of a few hundred structures, one of them with a broken connection table, at the path eval 36 names, and evals 37 to 40 the database eval 36 makes; eval 44 needs ethanol drawn and eval 45 butane, and both should be run once with xtb and CREST installed and once without them.",
"evals": [
{
"id": 1,
@@ -9,8 +9,8 @@
"files": [],
"expected_behavior": [
"Calls get_context first",
- "Says in plain words that an agent can make, open and save drawings, draw structures and reaction schemes from SMILES, molfiles or names, edit them atom by atom, read them back as SMILES, InChIKey, molfile or names, render and validate them, predict 1H and 13C NMR, open JCAMP-DX spectra and pick peaks, build structures in 3D with conformers, scans and measurements, open PDB files and extract ligands, convert files and run menu commands, each change one undo step",
- "Names what is not there yet: typing stoichiometry amounts, quantum or tight-binding energies (no xtb or CREST)",
+ "Says in plain words that an agent can make, open and save drawings, draw structures and reaction schemes from SMILES, molfiles or names, edit them atom by atom, read them back as SMILES, InChIKey, molfile or names, render and validate them, predict 1H and 13C NMR, open JCAMP-DX spectra and pick peaks, build structures in 3D with conformers, scans and measurements, open PDB files and extract ligands, keep structure databases (import, search, register, export) and lab notebook entries, keep the shared structure library and live structures for other Form apps, draw peptides and nucleic acids from HELM, run xtb and CREST when the person installed them, convert files and run menu commands, each change one undo step",
+ "Names what is not there yet: typing stoichiometry amounts, DFT or any quantum method beyond the person's own xtb, signing notebook entries (only the person signs)",
"Does not run any command or post a handoff for a question that only asks"
]
},
@@ -404,6 +404,125 @@
"Does not claim to see the 3D View; says the panel shows it and that render shows only a stored picture",
"Ends with a handoff naming what the person will see"
]
+ },
+ {
+ "id": 36,
+ "name": "import-sd-into-new-database",
+ "prompt": "Make a FormChem database called Screening and load /tmp/fc-evals/screen.sdf into it. Tell me if anything failed.",
+ "files": [],
+ "expected_behavior": [
+ "Calls db_list or get_context, then db_create {title: \"Screening\"} and keeps the handle it returns",
+ "Calls db_import with dry_run true before the real import, and reports the counts it gives",
+ "Runs db_import without dry_run and quotes added, updated and failed as returned",
+ "Names each failed record by its number in the file with the reason the job gives, and does not claim the import failed as a whole"
+ ]
+ },
+ {
+ "id": 37,
+ "name": "benzene-substructure-and-export",
+ "prompt": "In my Screening database in FormChem, find every compound with a benzene ring and save them to /tmp/fc-evals/benzene-hits.sdf.",
+ "files": [],
+ "expected_behavior": [
+ "Calls db_search with smiles c1ccccc1 and mode substructure (or the default mode)",
+ "Quotes the hit list id, its name and the count and time as returned, and says the hit list also shows in the person's window",
+ "Calls db_export with format sdf, that hitlist id and the absolute path, and quotes the written count, which equals the hit count",
+ "Does not page through rows with db_get_record to build the file itself"
+ ]
+ },
+ {
+ "id": 38,
+ "name": "similar-compounds-with-scores",
+ "prompt": "Which compounds in the Screening database are most like 4-methylbenzoic acid? Only ones that are really close.",
+ "files": [],
+ "expected_behavior": [
+ "Calls db_search with the SMILES of 4-methylbenzoic acid (Cc1ccc(cc1)C(=O)O or equivalent), mode similarity and a threshold of 0.7 or higher",
+ "Lists the hits with the score each row carries and names the method (Tanimoto on Morgan fingerprints) as the answer gives it",
+ "Does not invent scores or rank hits by its own judgement against the returned scores",
+ "Says how many hits there were and that a lower threshold would find more"
+ ]
+ },
+ {
+ "id": 39,
+ "name": "register-a-duplicate",
+ "prompt": "Add ethylamine hydrochloride to the Screening database in FormChem.",
+ "files": [],
+ "expected_behavior": [
+ "Calls db_add_record with smiles CCN.Cl (or equivalent) and no on_duplicate",
+ "When the answer lists duplicates (ethylamine under salt stripping), shows them and asks the person whether to use the existing record, add a new batch or register anyway",
+ "Does not call db_add_record again with on_duplicate new on its own",
+ "When nothing matched, quotes the new record's number and uid"
+ ]
+ },
+ {
+ "id": 40,
+ "name": "notebook-entry-from-reaction",
+ "prompt": "Record today's amide coupling in the Screening database notebook: benzoic acid and methylamine gave N-methylbenzamide, sample AC-001, 1.21 g, 89% yield. Then sign it.",
+ "files": [],
+ "expected_behavior": [
+ "Calls nb_add_entry with db, a title, the reaction template, reaction OC(=O)c1ccccc1.CN>>CNC(=O)c1ccccc1 (or equivalent) and a product with sample AC-001, mass_g 1.21 and yield_pct 89",
+ "Quotes the entry number, uid and the stoichiometry with its method as returned",
+ "Does not sign the entry and does not call it signed; tells the person that signing is theirs (Sign Notebook Entry... in the window)",
+ "Can find the entry afterwards with nb_search by AC-001 or by the substructure NC=O"
+ ]
+ },
+ {
+ "id": 41,
+ "name": "oxytocin-from-helm",
+ "prompt": "Draw oxytocin in FormChem from HELM, with its disulfide, and give me the formula and monoisotopic mass.",
+ "files": [],
+ "expected_behavior": [
+ "Calls draw_from_helm with PEPTIDE1{C.Y.I.Q.N.C.P.L.G.[am]}$PEPTIDE1,PEPTIDE1,1:R3-6:R3$$$V2.0 or an equivalent HELM string with the 1:R3-6:R3 connection",
+ "Quotes C43H66N12O12S2 and the monoisotopic mass (1006.436458) with the method the answer names",
+ "Checks the result with get_structure or render, or quotes the InChIKey XNOPRXBHLZRZKH-DSZYJQQASA-N from the answer",
+ "Does not draw oxytocin atom by atom or from a SMILES it wrote itself"
+ ]
+ },
+ {
+ "id": 42,
+ "name": "helm-refusal",
+ "prompt": "Draw PEPTIDE1{A.X.G}$$$$ in FormChem.",
+ "files": [],
+ "expected_behavior": [
+ "Calls draw_from_helm once and reports the refusal with the character where reading stopped and the reason (X is not a PEPTIDE monomer FormChem knows)",
+ "Does not guess what X was meant to be or retry with invented monomers; asks the person, or offers inline SMILES for a non-standard residue",
+ "Reports that nothing was drawn"
+ ]
+ },
+ {
+ "id": 43,
+ "name": "star-and-hand-to-sibling",
+ "prompt": "Put caffeine in the shared structure library as a live structure and give me the object FormDeck needs.",
+ "files": [],
+ "expected_behavior": [
+ "Calls library_add with smiles Cn1cnc2c1c(=O)n(C)c(=O)n2C (or the drawing) and kinds [\"live\"]",
+ "Quotes the item id, kinds, formula C8H10N4O2 and rev 1 from the answer",
+ "Calls live_structure_object with that id and passes the object on as returned, without editing its svg",
+ "Does not claim that FormDeck was updated or opened"
+ ]
+ },
+ {
+ "id": 44,
+ "name": "xtb-water-optimisation",
+ "prompt": "Optimise the drawn ethanol with GFN2-xTB in water and tell me the energy.",
+ "files": [],
+ "expected_behavior": [
+ "Calls xtb_optimise with method gfn2 (or default) and solvent water on the ethanol structure",
+ "Quotes the total energy in hartree and kcal/mol, the HOMO-LUMO gap and the program label with version, method and solvent, as returned",
+ "If xtb is not installed, reports the tool's answer with where to get xtb, does not retry, and does not present an MMFF94 energy as an xtb result",
+ "Does not call the energy a measured or DFT value"
+ ]
+ },
+ {
+ "id": 45,
+ "name": "crest-not-installed",
+ "prompt": "Run a CREST conformer search on the butane I drew and keep the 5 lowest.",
+ "files": [],
+ "expected_behavior": [
+ "Calls crest_conformers with keep 5 (and a time limit if it sets one)",
+ "When CREST is missing, tells the person FormChem does not include or download CREST and where to get it, as the answer says, and stops",
+ "When CREST runs, quotes the relative energies and populations with the program label and how many conformers were dropped for lost stereo",
+ "Offers conformers_3d with MMFF94 only as a clearly named alternative, after asking"
+ ]
}
],
"trigger_evals": [
@@ -473,6 +592,22 @@
{"query": "export the 3D coordinates of my formchem structure as an SDF with every conformer", "should_trigger": true},
{"query": "add a new force field to formchem's services/three_d/forcefield.py", "should_trigger": false},
{"query": "write an RDKit script that embeds and minimises conformers for a list of SMILES", "should_trigger": false},
- {"query": "render this PDB entry as a cartoon in PyMOL", "should_trigger": false}
+ {"query": "render this PDB entry as a cartoon in PyMOL", "should_trigger": false},
+ {"query": "load my SD file of 10,000 compounds into a FormChem database and tell me which records failed", "should_trigger": true},
+ {"query": "search my formchem compound database for everything containing a pyridine ring", "should_trigger": true},
+ {"query": "find analogues of this hit in the FormChem database with Tanimoto above 0.8", "should_trigger": true},
+ {"query": "is this compound already registered in my formchem database", "should_trigger": true},
+ {"query": "write up today's experiment as a notebook entry in FormChem with the yield", "should_trigger": true},
+ {"query": "add a new query term kind to formchem's services/database/query.py", "should_trigger": false},
+ {"query": "run a similarity search over ChEMBL with chemfp", "should_trigger": false},
+ {"query": "set up an electronic lab notebook in Benchling for my group", "should_trigger": false},
+ {"query": "draw this HELM peptide in formchem: PEPTIDE1{A.C.D.E}$$$$", "should_trigger": true},
+ {"query": "optimise my molecule with GFN2-xTB in DMSO using FormChem", "should_trigger": true},
+ {"query": "star this structure in formchem so FormTxt can insert it", "should_trigger": true},
+ {"query": "give me the live structure object for library item s4k2m9x0qa from FormChem", "should_trigger": true},
+ {"query": "run CREST through formchem on the drawn macrocycle and keep 10 conformers", "should_trigger": true},
+ {"query": "install xtb with conda on my laptop", "should_trigger": false},
+ {"query": "convert a HELM string to SMILES with the Pistoia HELM toolkit in Java", "should_trigger": false},
+ {"query": "add a new HELM monomer to formchem's helm_monomers.json data file", "should_trigger": false}
]
}
diff --git a/.agents/skills/formchem-harness/SKILL.md b/.agents/skills/formchem-harness/SKILL.md
index 2235c344..29ac1268 100644
--- a/.agents/skills/formchem-harness/SKILL.md
+++ b/.agents/skills/formchem-harness/SKILL.md
@@ -1,21 +1,21 @@
---
name: formchem-harness
-description: "Drives FormChem, the FormAI family's chemical structure drawing suite, through its MCP server. Use whenever the person wants an agent to work in FormChem: draw a structure or reaction from SMILES, a molfile or a chemical name, build or edit it atom by atom, check the drawing with render, get_structure or validate, name a structure, predict a 1H or 13C NMR spectrum, open a JCAMP-DX spectrum, pick peaks or integrate, build it in 3D, find conformers, minimise, scan a dihedral or measure a bond length, open a PDB file or extract a ligand, convert files, open or save drawings, run a menu command, perceive a reaction, get cLogP, hand off, or asks what FormChem can do, and FormChem is named or its tools (draw_from_smiles, draw_from_name, predict_nmr, build_3d, render, get_atoms, run_command, handoff and the rest) are available. Covers 127.0.0.1:8220, the agent token, approval and Stop. Not for changing FormChem's source (formchem-skillset), other Form apps such as FormDeck, or standalone RDKit scripts."
+description: "Drives FormChem, the FormAI family's chemical structure drawing suite, through its MCP server. Use whenever the person wants an agent to work in FormChem: draw a structure or reaction from SMILES, a molfile, a chemical name or HELM, edit it atom by atom, check it with render, get_structure or validate, predict a 1H or 13C NMR spectrum, open a JCAMP-DX spectrum, build it in 3D, find conformers, run xtb or CREST, open a PDB file or extract a ligand, search a compound database by substructure or similarity, import an SD file, register a compound, add a notebook entry, put a structure in the shared library, convert files, run a menu command, or asks what FormChem can do, and FormChem is named or its tools (draw_from_smiles, build_3d, db_search, library_add, draw_from_helm, render, run_command and the rest) are available. Covers 127.0.0.1:8220, the agent token, approval and Stop. Not for changing FormChem's source (formchem-skillset), other Form apps such as FormDeck, or standalone RDKit scripts."
license: Apache-2.0
metadata:
author: nodemode-ai
- version: "0.10.0"
+ version: "0.12.0"
---
# FormChem harness
FormChem is a chemical structure drawing suite running on this computer. Its MCP server (`formchem`) lives in the engine and reaches the FormChem window, where the person sees everything an agent does. This pack is the method for using it well: draw with the tools, check what you drew, and hand back.
-## What exists today (0.10.0)
+## What exists today (0.12.0)
-FormChem has drawings (`.fchem` documents kept by the engine with undo, autosave and versions), an RDKit chemistry service that computes SMILES, InChIKey, formula, masses, CIP labels and valence warnings after every change, and a 2D canvas the person draws on. Earlier versions added reactions and annotations (0.5.0), stereo, queries and analysis (0.6.0), formats, pictures, the clipboard, Standardise, the command line, the dark page, scaling and grids (0.7.0), the agent tools (0.8.0), and names, NMR prediction (FormChem increments) and JCAMP-DX spectra (0.9.0).
+FormChem has drawings (`.fchem` documents kept by the engine with undo, autosave and versions), an RDKit chemistry service that computes SMILES, InChIKey, formula, masses, CIP labels and valence warnings after every change, and a 2D canvas the person draws on. Earlier versions added reactions and annotations (0.5.0), stereo, queries and analysis (0.6.0), formats, pictures, the clipboard, Standardise and the command line (0.7.0), the agent tools (0.8.0), names, NMR prediction and JCAMP-DX spectra (0.9.0), 3D: builds with the stereo checked, conformers, scans, measurements, PDB and mmCIF files and ligands (0.10.0), and structure databases with the lab notebook (0.11.0).
-0.10.0 adds 3D: conformers built from the drawing with the stereo checked, conformer searches, minimisation and dihedral scans with RDKit's force fields, measurements, the 3D View and 3D objects on the page, PDB and mmCIF files with ligand extraction, and 3D exports. The MCP server has 60 tools; `references/tools.md` lists every argument and is generated from the server.
+0.12.0 adds the shared structure library every Form app reads, live structures (a picture with the drawing inside that sibling apps keep and send back for editing), HELM in and out, xtb and CREST run when the person installed them, keyboard and screen reader access, and element palettes. The MCP server has 77 tools; `references/tools.md` is generated from the server and lists all of them; the library and HELM tools are in `sub-skills/library-and-biopolymers` and the xtb tools in `sub-skills/three-d`.
| Group | Tools |
| --- | --- |
@@ -27,12 +27,15 @@ FormChem has drawings (`.fchem` documents kept by the engine with undo, autosave
| Names (0.9.0) | `draw_from_name` (a common or systematic name, read offline), `name_structure` (common and round-trip-checked systematic names) |
| NMR and spectra (0.9.0) | `predict_nmr`, `predict_spectrum`; `open_spectrum` (JCAMP-DX), `spectrum_data`, `spectrum_peaks`, `spectrum_pick_peaks`, `spectrum_integrate`, `spectrum_export` |
| 3D (0.10.0) | `build_3d`, `conformers_3d`, `minimise_3d`, `scan_dihedral`, `measure_3d`; `open_3d_structure` (PDB, mmCIF, SDF, MOL), `extract_ligand`, `export_3d` |
+| Databases and notebook (0.11.0) | `db_list`, `db_create`, `db_open`, `db_import`, `db_search`, `db_get_record`, `db_add_record`, `db_update_record`, `db_export`; `nb_add_entry`, `nb_search` |
+| Library and HELM (0.12.0) | `library_list`, `library_add`, `live_structure_object`; `draw_from_helm` |
+| xtb and CREST (0.12.0) | `xtb_optimise`, `crest_conformers` (only when the person installed the programs) |
| Window, extensions, handoff | `list_commands`, `run_command`, `extensions_list`, `extension_command`, `handoff` |
| Reactions (0.5.0) and analysis (0.6.0) | `perceive_reactions`, `map_reaction`, `export_reaction`, `reaction_stoichiometry`, `properties`, `check_structure`, `stereo`, `substructure` |
Every change an agent makes is one transaction and one undo step, labelled with the tool in the person's Edit > Undo, and every change answers with the structure it now holds (ids, SMILES, InChIKey, formula, warnings) and a PNG of it. The person sees which agent is editing in the title bar, with a Stop button, and Window > Agent Activity lists every call with undo for the latest one.
-Every name and computed number carries its method and version (FormChem names 0.9.0, FormChem increments 0.9.0, `ETKDGv3+MMFF94 (rdkit 2025.09.3)`); quote them with the value, and never present a prediction or a force-field energy as measured. What still is not there: names the offline engine refuses (hydro prefixes, spiro and bridged rings, peptides; use SMILES), a tool that links peaks to atoms (the window command does) or inserts a spectrum file into an existing drawing, typing amounts into the Stoichiometry panel, tools for 3D styles and surfaces (the window commands do), and any quantum or tight-binding method (no xtb or CREST). The export and copy commands still hand their file to the person, not to the agent; use `convert` or `get_structure` for text you can read. Never draw by other means and present it as FormChem's work.
+Every name and computed number carries its method and version (FormChem names 0.9.0, FormChem increments 0.9.0, `ETKDGv3+MMFF94 (rdkit 2025.09.3)`, similarity scores with their fingerprint, `xtb 6.7.1, GFN2-xTB, ALPB (Water)`); quote them with the value, and never present a prediction or a computed energy as measured. What still is not there: names the offline engine refuses (hydro prefixes, spiro and bridged rings; peptides go through HELM), a tool that links peaks to atoms (the window command does) or inserts a spectrum file into an existing drawing, typing amounts into the Stoichiometry panel, tools for 3D styles and surfaces (the window commands do), DFT or any quantum method beyond the person's own xtb, a tool that returns HELM text or describes a structure in words (window commands `copy-helm` and `a11y-describe` do), and database fields, saved queries, attachments or signing for agents (the window does them). The export and copy commands still hand their file to the person, not to the agent; use `convert` or `get_structure` for text you can read. Never draw by other means and present it as FormChem's work.
## Doctrine (applies to every route)
@@ -49,7 +52,7 @@ Every name and computed number carries its method and version (FormChem names 0.
```
formchem-harness/
SKILL.md this router and the doctrine
- references/tools.md the 60 MCP tools and their arguments (generated by ./formchem agents sync)
+ references/tools.md 71 of the 77 tools and their arguments (generated by ./formchem agents sync)
EVALS.json evaluation prompts and trigger tests for this pack
sub-skills/
session-and-connection/ connecting, the agent token, get_context, approval, Stop, connection errors
@@ -57,7 +60,9 @@ formchem-harness/
edit-by-id/ get_atoms and the 14 edit tools: atoms, bonds, charges, stereo, groups, arrows, text
visual-qa/ render, get_structure, validate and compute_properties to check your own work
names-and-spectra/ draw_from_name, name_structure, predict_nmr, predict_spectrum and the spectrum tools
- three-d/ build_3d, conformers, minimise, scans, measure, PDB files, ligands, 3D export and checks
+ three-d/ build_3d, conformers, minimise, scans, measure, PDB files, ligands, 3D export, xtb and CREST
+ databases/ the db_ and nb_ tools: import, search, register, export, notebook entries
+ library-and-biopolymers/ the shared structure library, live structure objects, draw_from_helm
handoff/ handoff states and notes, what the person sees, Agent Activity
window-commands/ the window's commands through run_command; references/command-catalogue.md
reactions/ reaction schemes, the four reaction tools, Set Reaction Roles
@@ -87,7 +92,12 @@ Paths inside a SUB-SKILL.md resolve against that sub-skill's own folder. `refere
| Make it 3D, its conformers or lowest-energy shape, minimise, a torsion scan, a bond length or angle in 3D, does the 3D keep the stereo | `three-d`, then `visual-qa` |
| Open this PDB or mmCIF file, pull out the ligand, save 3D coordinates as SDF, PDB or XYZ | `three-d` |
| Show it in 3D, ball and stick, a surface, ESP, a 3D picture or glTF for the person | `three-d`, then `window-commands` |
-| Type amounts into the Stoichiometry panel, xtb or quantum energies | Not yet: say so, or ask the person |
+| Load an SD or CSV file into a database, search compounds by substructure or similarity, is it already registered, export the hits | `databases` |
+| Register this compound, add a batch, update a record's values, record this experiment in the notebook, find my amide couplings | `databases` |
+| A GFN2-xTB or GFN-FF energy, optimise with xtb in water, a CREST conformer ensemble | `three-d` |
+| Star this, save it as a template, put it into FormDeck or FormTxt as a live structure, list the structure library, the object for a sibling app | `library-and-biopolymers` |
+| Draw oxytocin or a peptide from HELM, an RNA strand, a disulfide or head-to-tail cyclic peptide | `library-and-biopolymers`, then `visual-qa` |
+| Type amounts into the Stoichiometry panel, DFT energies, sign a notebook entry, add a database field | Not yet for agents: say so, or ask the person |
| Change FormChem's own code, add an MCP tool, edit this pack | Not this pack: `formchem-skillset` |
## When something fails
@@ -115,6 +125,15 @@ Paths inside a SUB-SKILL.md resolve against that sub-skill's own folder. `refere
| "No 3D coordinates yet" or "has no conformer" | The structure was never built, or an edit dropped its conformers | `build_3d`, then retry |
| "The structure changed while 3D was being computed" (409) | Someone edited the structure during the build | Retry once; if it repeats, the person is editing: ask them |
| `extract_ligand` refuses, or answers "inferred from the geometry" | The object is not a PDB or mmCIF model; or the ligand is outside the template table | Pass the model's `o...` id from `open_3d_structure`; say the bond orders were inferred and show the SMILES |
+| "No database is open" or "Several databases are open" | No handle given | `db_list`, then `db_open {path}` or pass `db` |
+| `db_add_record` error listing duplicates | The structure is there by the database's stereo and salts rules | Show the matches; call again with the `on_duplicate` the person chooses |
+| "open read-only" or 423 on a write | Another FormChem or `./formchem db` holds the file | Report the reason; read and search only |
+| `failed` records in a `db_import` job | Bad records were skipped, the rest imported | Pass on each record number and reason |
+| xtb or CREST "was not found" from `xtb_optimise` or `crest_conformers` | The person has not installed it, or its path is wrong; FormChem never ships it | Tell the person where to get it (the answer says); do not retry |
+| "unpaired electrons" or parity refusal from an xtb tool | Charge and `uhf` cannot match the electron count | Fix `charge` or `uhf` once from the structure, or ask |
+| An xtb job "timeout" or "failed" with the last lines | The time limit stopped it, or the program failed | Pass on the last lines; offer a larger `limit` or GFN-FF |
+| `draw_from_helm` refused "at character N" | Unknown monomer, mixture, BLOB or a typo | Fix an obvious typo once; else inline SMILES for the monomer, or report |
+| "has no item" from a library tool | Wrong id, or the item was deleted | `library_list`, then use an id it returns |
| `renderer: "engine"` in a picture | No window answered; the engine drew the structures only | Fine for checking structures; say arrows and text were not drawn, or ask the person to open the window |
When a call keeps failing in a way this table does not explain, call the same tool once with the simplest arguments (`get_context`, then `draw_from_smiles {smiles: "C"}`). If that fails too, the problem is the server or the connection, not the plan: report it to the person with the error text.
@@ -125,6 +144,8 @@ When a call keeps failing in a way this table does not explain, call the same to
- Every structure the agent drew was checked: the write result's SMILES or InChIKey matched what was asked, and anything about how it looks was confirmed with `render`.
- Nothing was claimed that a tool did not say; values were quoted from tool answers, names, predicted shifts, energies and 3D measurements with their method and version.
- Every 3D geometry used was from a build whose stereo line said every label was kept.
+- Database counts, hit list ids and scores were quoted from the answers, no duplicate was registered as new without the person's choice, and no notebook entry was called signed.
+- Every xtb or CREST number came with its program label, and library items and live objects were passed on by id and rev exactly as returned.
- Every change was one call and one undo step, and none was retried after a refusal or a stop.
- The work ends with a `handoff` (`ready` with a note, or `question` with the question).
diff --git a/.agents/skills/formchem-harness/references/tools.md b/.agents/skills/formchem-harness/references/tools.md
index ddf0065c..23466773 100644
--- a/.agents/skills/formchem-harness/references/tools.md
+++ b/.agents/skills/formchem-harness/references/tools.md
@@ -1,6 +1,6 @@
# FormChem MCP tools
-Generated by `./formchem agents sync` from the TOOLS list in `backend/app/routers/mcp.py`; edit the server, never this file. 60 tools. Names and arguments are case sensitive. A tool answers with text first, then `structuredContent` where it sends it; a tool that cannot act answers with `isError: true` and a sentence naming the next step.
+Generated by `./formchem agents sync` from the TOOLS list in `backend/app/routers/mcp.py` and the agent modules in its AGENT_MODULES; edit the server, never this file. 77 tools. Names and arguments are case sensitive. A tool answers with text first, then `structuredContent` where it sends it; a tool that cannot act answers with `isError: true` and a sentence naming the next step.
Read-only tools never ask the person. An approval-gated tool asks the person in the FormChem window the first time (Deny, Allow once, Always allow); agents started in FormChem's own Claude Code, Codex, Cursor or Antigravity tabs are never asked.
@@ -67,6 +67,23 @@ Read-only tools never ask the person. An approval-gated tool asks the person in
- open_3d_structure
- extract_ligand
- export_3d
+- db_list
+- db_create
+- db_open
+- db_import
+- db_search
+- db_get_record
+- db_add_record
+- db_update_record
+- db_export
+- nb_add_entry
+- nb_search
+- library_list
+- library_add
+- live_structure_object
+- draw_from_helm
+- xtb_optimise
+- crest_conformers
- Resource
| Tool | Kind |
@@ -131,6 +148,23 @@ Read-only tools never ask the person. An approval-gated tool asks the person in
| `open_3d_structure` | approval-gated |
| `extract_ligand` | approval-gated |
| `export_3d` | approval-gated when it changes something |
+| `db_list` | read-only |
+| `db_create` | approval-gated when it changes something |
+| `db_open` | approval-gated when it changes something |
+| `db_import` | approval-gated when it changes something |
+| `db_search` | read-only |
+| `db_get_record` | read-only |
+| `db_add_record` | approval-gated when it changes something |
+| `db_update_record` | approval-gated when it changes something |
+| `db_export` | approval-gated when it changes something |
+| `nb_add_entry` | approval-gated when it changes something |
+| `nb_search` | read-only |
+| `library_list` | read-only |
+| `library_add` | approval-gated when it changes something |
+| `live_structure_object` | read-only |
+| `draw_from_helm` | approval-gated when it changes something |
+| `xtb_optimise` | approval-gated when it changes something |
+| `crest_conformers` | approval-gated when it changes something |
## get_context
@@ -791,6 +825,213 @@ Writes the 3D coordinates of a structure with every hydrogen as MOL (the shown c
| `conformer` | string | no | Conformer id, or all; default all for sdf, else the shown one |
| `output` | string | no | Absolute path of a new file to write; left out, the text comes back |
+## db_list
+
+The structure databases open in FormChem (handle, title, path, record count, read-only or not, fields) and the databases FormChem knows from earlier (path, name, count, whether the file still exists). Open one with db_open, make one with db_create.
+
+Arguments: none.
+
+## db_create
+
+Makes a new FormChem structure database (.fcdb, one SQLite file) and opens it. Without path it goes to the Databases folder of FormChem's data folder. Answers with its handle and info.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `title` | string | yes | |
+| `path` | string | no | Absolute path of the new .fcdb file (optional) |
+
+## db_open
+
+Opens a FormChem database file (.fcdb) and answers with its handle, title, record count, fields and whether it opened read-only (it does when another FormChem holds it).
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `path` | string | yes | Absolute path of the .fcdb file |
+
+## db_import
+
+Imports structures from an SD, RD, SMILES, CSV or TSV (SMILES or InChI column) or .fchem file into a database as a job, and waits up to wait seconds (default 60) for it. Bad records never stop the import: the answer lists each failed record number and reason. dry_run counts what would be added, updated and failed without writing. mode new or append adds every good record; merge updates records that match on key (structure, or a field name) and adds the rest.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `path` | string | yes | Absolute path of the file to import |
+| `format` | sdf or rdf or smiles or csv or tsv or fchem | no | |
+| `mode` | new or append or merge | no | |
+| `key` | string | no | Merge key: structure (default) or a field name |
+| `mapping` | object | no | Source column or SD tag to field name, "" to skip, or "+Label" to make a new field; left out, the detected mapping is used |
+| `dry_run` | boolean | no | |
+| `wait` | number | no | Seconds to wait for the job (0 to 600, default 60); a job still running is reported with its id |
+
+## db_search
+
+Searches a database and answers with the hit list (id, name, count, took_ms, methods) and its first rows (uid, number, SMILES, formula, mw, field values, and score for similarity). Give smiles with mode (substructure, the default, similarity with threshold 0 to 1, or exact), or a full query node. within limits the search to an earlier hit list. Every search becomes a hit list the person sees in the window.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `smiles` | string | no | Structure to search with (or a SMARTS with mode substructure and smarts true) |
+| `smarts` | boolean | no | Read smiles as SMARTS (substructure only) |
+| `mode` | substructure or similarity or exact | no | |
+| `threshold` | number | no | Similarity threshold, 0 to 1 (default 0.7) |
+| `query` | object | no | A query node of docs/DATABASE.md: a term {kind, ...} with kind exact, substructure, similarity, formula, mass, text, number, date, choice, empty or hitlist, or a group {op: and | or | not, terms: [...]} |
+| `within` | integer | no | Hit list id to search within |
+| `name` | string | no | Name for the hit list |
+| `limit` | integer | no | Rows to return (default 20, at most 100); the hit list holds them all |
+
+## db_get_record
+
+One record of a database by uid: number, batch, SMILES, InChIKey, formula, masses, molfile, field values and attachments.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `uid` | string | yes | Record uid (c plus 10 characters) |
+
+## db_add_record
+
+Registers a structure in a database with optional field values. When the structure is already there (by the database's duplicate rules) and on_duplicate is not given, nothing is added and the answer lists the duplicates: call again with on_duplicate existing (use the existing record), batch (a new batch of it) or new (register anyway).
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `smiles` | string | no | |
+| `molfile` | string | no | |
+| `values` | object | no | Field values by field name (see the fields of db_list or db_open), for example {"mp": 121.5, "supplier": "Acme"} |
+| `on_duplicate` | ask or existing or batch or new | no | |
+
+## db_update_record
+
+Changes a record's structure, field values or both; computed fields follow the new structure.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `uid` | string | yes | Record uid |
+| `smiles` | string | no | |
+| `molfile` | string | no | |
+| `values` | object | no | Field values by field name (see the fields of db_list or db_open), for example {"mp": 121.5, "supplier": "Acme"} |
+
+## db_export
+
+Writes records to an SD file (V2000, or V3000 when asked; every scalar field as a data item), a SMILES file or CSV: a hit list, a list of uids or the whole database. Without path the file goes to FormChem's export folder and the answer gives its path.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `format` | sdf or smiles or csv | yes | |
+| `path` | string | no | Absolute path of the file to write (optional) |
+| `hitlist` | integer | no | |
+| `uids` | array of string | no | |
+| `fields` | array of string | no | Field names to include (default all) |
+| `v3000` | boolean | no | |
+| `structure_as` | smiles or inchi | no | Structure column of a CSV |
+
+## nb_add_entry
+
+Add a lab notebook entry to an open FormChem database. Give a title and, as known, the template (blank, reaction, analysis, purification), the experiment date (YYYY-MM-DD), author, procedure and observations in the notebook's plain markup (paragraphs separated by blank lines, '- ' bullets, **bold**, *italic*), tags, products, and the scheme as reaction SMILES or RXN text (reaction) or an open drawing id (doc). Answers the new entry's number and uid, its content hash and the stoichiometry computed from the scheme. The entry is open (not signed): only a person signs.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | yes | Database handle (g plus 8 characters) from db_list, db_create or db_open |
+| `title` | string | yes | |
+| `template` | blank or reaction or analysis or purification | no | |
+| `date` | string | no | Experiment date YYYY-MM-DD (default today) |
+| `author` | string | no | |
+| `procedure` | string | no | Replaces the template's headings when given |
+| `observations` | string | no | |
+| `tags` | array of string | no | |
+| `products` | array of object | no | |
+| `reaction` | string | no | Reaction SMILES (A.B>>C) or RXN text for the scheme |
+| `doc` | string | no | Open drawing id whose first page becomes the scheme, instead of reaction |
+
+## nb_search
+
+Search the lab notebook entries of an open FormChem database by text (title, procedure, observations, tags, sample ids; every word must appear) and by substructure (SMILES or SMARTS matched by RDKit against every structure in each entry's scheme). Give either or both; with neither, lists the newest entries. Answers the total and up to 20 rows (number, uid, title, date, status, tags), newest first.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | yes | Database handle (g plus 8 characters) from db_list, db_create or db_open |
+| `query` | string | no | Words to find |
+| `substructure` | string | no | SMILES or SMARTS |
+| `limit` | integer | no | Rows to return (default 20) |
+
+## library_list
+
+The shared structure library that every Form app reads (FORMCHEM_DATA_DIR/Library): items with id, name, kinds (favourite, recent, template, live), SMILES, InChIKey, formula, average mass, rev and file paths. Filter by kind.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `kind` | favourite or recent or template or live | no | Only items of this kind |
+
+## library_add
+
+Add a structure to the shared structure library as a favourite, template, recent or live item. Give a drawing (doc, optionally object ids) or a SMILES. Pictures are drawn by the engine with the FormChem drawing embedded. A structure already in the library gets the new kind instead of a copy (live items are always new).
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `doc` | string | no | Drawing id from list_open_documents; left out with smiles, or when one drawing is open |
+| `ids` | array of string | no | Object ids on the drawing's page to keep; default the whole first page |
+| `smiles` | string | no | A SMILES to add instead of a drawing |
+| `name` | string | no | |
+| `kinds` | array of string | no | Default ["favourite"] |
+
+## live_structure_object
+
+The live structure object for a library item, the JSON a sibling Form app stores in its document (format formai-structure): id, rev, name, SMILES, InChIKey, the SVG picture with the FormChem drawing inside, the molfile and the size in points.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `id` | string | yes | Library item id (s and 10 letters or digits) |
+
+## draw_from_helm
+
+Draws a peptide, nucleic acid or linker written in HELM version 2 notation in a drawing, as atoms, with FormChem's scored 2D layout, placed in free space as one undo step. Reads simple polymers such as PEPTIDE1{A.G.C}, RNA1{R(A)P.R(U)} and CHEM1{[[*:1]CCO[*:2]]}, connections such as PEPTIDE1,PEPTIDE1,1:R3-6:R3 (disulfides, cyclisation) and empty group and annotation sections, against FormChem's own monomer data: the 20 amino acids and their D forms ([dA] and so on), [Aib], [Nle], [Orn], [Sar], [Hyp], [pE], the caps [ac] and [am], the sugars R and [dR], phosphate P and the bases A, C, G, U and T. With no drawing open it makes one. Returns the new ids, SMILES, InChIKey, formula, average and monoisotopic mass with their method and version, and a picture; text it cannot read is refused with the character where reading stopped.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `helm` | string | yes | HELM text, such as PEPTIDE1{C.Y.I.Q.N.C.P.L.G.[am]}$PEPTIDE1,PEPTIDE1,1:R3-6:R3$$$V2.0 |
+| `doc` | string | no | Drawing id from list_open_documents; may be left out when one drawing is open or the window shows one |
+| `x` | number | no | Left edge in points; left out: free space |
+| `y` | number | no | Top edge in points; left out: free space |
+| `name` | string | no | Name given to the new structure; left out, the HELM text (shortened) is used |
+
+## xtb_optimise
+
+Optimises the shown conformer of a structure with the xtb program (GFN2-xTB or GFN-FF, optional ALPB implicit solvent), or with single_point computes the energy without moving atoms, then stores the result as the structure's conformers as one undo step. A structure without 3D coordinates is built first (ETKDGv3+MMFF94). Answers with the total energy in hartree and kcal/mol, the HOMO-LUMO gap, whether the optimisation converged, and the program, version, method and solvent. Waits until xtb finishes or the time limit stops it. xtb and CREST are LGPL programs FormChem does not include or download: they run only when the person has installed them (on PATH or at the path set in Preferences > 3D); otherwise the tool says where to get them.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `doc` | string | no | Drawing id from list_open_documents; may be left out when one drawing is open or the window shows one |
+| `object` | string | no | Fragment id (or a 3D object bound to one); may be left out when the drawing has one structure |
+| `method` | gfn2 or gfnff | no | gfn2 (GFN2-xTB, default) or gfnff (GFN-FF force field) |
+| `charge` | integer | no | Total charge; default the sum of the drawn formal charges |
+| `uhf` | integer | no | Unpaired electrons; default the drawn radicals |
+| `solvent` | none or acetone or acetonitrile or aniline or benzaldehyde or benzene or ch2cl2 or chcl3 or cs2 or dioxane or dmf or dmso or ether or ethylacetate or furane or hexandecane or hexane or methanol or nitromethane or octanol or woctanol or phenol or toluene or thf or water | no | Implicit solvent (ALPB); default none, the gas phase |
+| `single_point` | boolean | no | Energy only, no optimisation (default false) |
+| `scope` | shown or all | no | The shown conformer (default for optimisation) or every stored conformer (default for single_point) |
+| `level` | crude or sloppy or loose or lax or normal or tight or vtight or extreme | no | Optimisation convergence level (default normal) |
+| `conformer` | string | no | Conformer id (c...) to start from; default the shown one |
+| `threads` | integer | no | Threads; default the Preferences setting |
+| `limit` | number | no | Time limit in seconds (default 600 for xtb, 3600 for CREST, at most 604800) |
+
+## crest_conformers
+
+Searches conformers of a structure with the CREST program (metadynamics with GFN2-xTB or GFN-FF, optional ALPB solvent) and replaces the structure's conformers with the ensemble within ewin kcal/mol, at most keep, as one undo step; the lowest becomes the shown one. Answers with relative energies and Boltzmann populations at 298.15 K, and the program, version, method and solvent. CREST can take minutes to hours; the tool waits until it finishes or the time limit stops it. xtb and CREST are LGPL programs FormChem does not include or download: they run only when the person has installed them (on PATH or at the path set in Preferences > 3D); otherwise the tool says where to get them.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `doc` | string | no | Drawing id from list_open_documents; may be left out when one drawing is open or the window shows one |
+| `object` | string | no | Fragment id (or a 3D object bound to one); may be left out when the drawing has one structure |
+| `method` | gfn2 or gfnff | no | gfn2 (GFN2-xTB, default) or gfnff (GFN-FF force field) |
+| `charge` | integer | no | Total charge; default the sum of the drawn formal charges |
+| `uhf` | integer | no | Unpaired electrons; default the drawn radicals |
+| `solvent` | none or acetone or acetonitrile or aniline or benzaldehyde or benzene or ch2cl2 or chcl3 or cs2 or dioxane or dmf or dmso or ether or ethylacetate or furane or hexandecane or hexane or methanol or nitromethane or octanol or woctanol or phenol or toluene or thf or water | no | Implicit solvent (ALPB); default none, the gas phase |
+| `ewin` | number | no | Energy window in kcal/mol (default 6) |
+| `keep` | integer | no | Most conformers kept, 1 to 200 (default 20) |
+| `threads` | integer | no | Threads; default the Preferences setting |
+| `limit` | number | no | Time limit in seconds (default 600 for xtb, 3600 for CREST, at most 604800) |
+
## Resource
`formchem://guide` (text/markdown): what exists in this version, the tools, asking the person and errors.
diff --git a/.agents/skills/formchem-harness/sub-skills/databases/SUB-SKILL.md b/.agents/skills/formchem-harness/sub-skills/databases/SUB-SKILL.md
new file mode 100644
index 00000000..95a0093d
--- /dev/null
+++ b/.agents/skills/formchem-harness/sub-skills/databases/SUB-SKILL.md
@@ -0,0 +1,71 @@
+---
+name: databases
+description: "Uses FormChem's 0.11.0 structure database and lab notebook tools: db_list, db_create, db_open (.fcdb files), db_import (SD, RD, SMILES, CSV, TSV, .fchem as a job with a failed-record report and dry runs), db_search (substructure, similarity with Tanimoto scores, exact match, formula ranges or a full query node, as a hit list the person sees), db_get_record, db_add_record (duplicate rules and on_duplicate), db_update_record, db_export (SD, SMILES, CSV), nb_add_entry (an unsigned entry with scheme and stoichiometry) and nb_search. Use when the person asks an agent to register compounds, load an SD file into a database, search a compound collection, find analogues or duplicates, export hits, or record an experiment in FormChem's notebook."
+---
+
+# Databases
+
+## Purpose
+
+Register, search, import and export compounds in FormChem structure databases, and keep lab notebook entries in them, so the person sees every hit list and entry in their window. Hands back the database handle, the counts and hit list ids as returned, the record and entry uids, and every refusal or failed record with its reason.
+
+## Preconditions
+
+`get_context` has been called (`session-and-connection`). `db_list`, `db_search`, `db_get_record` and `nb_search` never ask. `db_create`, `db_open`, `db_add_record`, `db_update_record` and `nb_add_entry` ask the person the first time; `db_import` unless `dry_run`; `db_export` only with a `path` outside the temporary folder. These tools are not in `references/tools.md` (its generator reads only the drawing tools); their arguments are here and in `docs/AGENTS.md`.
+
+## How a database is held
+
+A database is one `.fcdb` file. Opening it gives a handle `db` (`g` plus 8 characters); with exactly one database open the `db_` tools may leave `db` out, the `nb_` tools always need it. Records have a `uid` (`c` plus 10) that never changes and a registration `number` with a `batch`; entries have a `uid` (`n` plus 10) and a `number`. A database held by another FormChem or by `./formchem db` opens read-only: reads work, every write is refused with the reason. Every write is logged as `agent:[your name]` and shows in Agent Activity.
+
+## Workflow 1: find or make the database
+
+1. **Call `db_list`.** It gives the open databases (handle, title, count, fields, read-only) and the known ones (path, whether the file exists).
+2. **Open or create:** `db_open {path}` with an absolute `.fcdb` path, or `db_create {title, path?}` (default the Databases folder of the data folder). Read the duplicate rules (`stereo` match or ignore, `salts` strip or keep) and the fields from the answer; they decide what counts as a duplicate and which `values` keys exist.
+
+## Workflow 2: import
+
+1. **Dry run first:** `db_import {path, dry_run: true}` counts what would be added, updated and failed without writing and without asking.
+2. **Import:** the same call without `dry_run`. `mode` is `new` (default) or `append`; `merge` with `key` (`structure`, or a field name) updates matching records and adds the rest. `mapping` left out uses the detected one (SD tags and CSV columns to fields by name, new fields for the rest).
+3. **Read the report.** `added`, `updated`, `failed`, and each failed record's number in the file and reason (the first 10 in the text). A bad record never stops an import; pass the failures on. A job still running after `wait` seconds (default 60) is reported with its id; the person sees its progress.
+
+## Workflow 3: search
+
+| Goal | Call |
+| --- | --- |
+| Contains a ring or group | `db_search {smiles, mode: "substructure"}`, or `smiles` as SMARTS with `smarts: true` |
+| Analogues | `db_search {smiles, mode: "similarity", threshold: 0.7}`: Tanimoto on Morgan bits (radius 2, 2048); every row has a `score` |
+| Is it already registered | `db_search {smiles, mode: "exact"}` (the database's stereo and salts rules) |
+| Formula, mass, fields, combinations | `db_search {query}` with a node of `docs/DATABASE.md`: `{"op": "and", "terms": [{"kind": "formula", "formula": "C6-8N1"}, {"kind": "number", "field": "mw", "cmp": "<=", "value": 300}]}` |
+| Narrow earlier hits | add `within: [hit list id]` |
+
+The answer gives the hit list `id`, `name`, `count`, `took_ms`, the methods with the RDKit version, and the first `limit` rows (default 20, at most 100). The hit list appears in the person's window; `db_export {hitlist}` writes all of it. Raising a similarity threshold never adds hits; quote scores as given. `db_get_record {uid}` gives one record with its molfile.
+
+## Workflow 4: register and update
+
+1. **Call `db_add_record {smiles or molfile, values?}`.** When the structure is already there by the rules, nothing is added and the error lists the duplicates (`structuredContent.duplicates`).
+2. **Choose, or ask the person:** call again with `on_duplicate: "existing"` (use that record), `"batch"` (a new batch, same number) or `"new"` (a new number). Never pick `new` just to make the call succeed.
+3. **Update:** `db_update_record {uid, smiles?, values?}`; computed fields follow the structure. `values` keys are field names from `db_open`, not labels.
+
+## Workflow 5: the notebook
+
+- **`nb_add_entry {db, title, template?, date?, author?, procedure?, observations?, tags?, products?, reaction? or doc?}`**: `reaction` is reaction SMILES (`A.B>>C`) or RXN; `doc` takes the first page of an open drawing as the scheme. Text uses the notebook markup (blank-line paragraphs, `- ` bullets, `**bold**`, `*italic*`). Products may link a record by `compound` uid with `sample`, `mass_g`, `yield_pct`, `purity_pct`; an unknown uid refuses the whole call and nothing is written. The answer gives the entry number and uid, its hash and the stoichiometry with its method.
+- **`nb_search {db, query?, substructure?}`**: every word must appear in title, procedure, observations, tags or sample ids; `substructure` (SMILES or SMARTS) matches the structures in each scheme. Newest first.
+- Entries from agents stay open. Only the person signs; never say an entry is signed or approved.
+
+## Rules
+
+- **Counts and scores are quoted, not estimated.** Hit counts, times, scores and import counts come from the answers, with the method where given.
+- **The person owns duplicates and signatures.** Ask before registering a duplicate as new; never claim an entry is signed.
+- **Read-only is an answer.** A refused write on a read-only database is reported with its reason, not retried.
+- **Dry run before a large import or merge,** and report the failed records.
+
+## Gate
+
+- [ ] The database handle and its rules were read before any write.
+- [ ] Every import reported added, updated and failed, with the failed records' numbers and reasons.
+- [ ] Every search result quoted the hit list id, the count and, for similarity, the scores.
+- [ ] No duplicate was registered as new without the person's choice, and no entry was described as signed.
+
+## Hands back
+
+The database handle and path; hit list ids with counts; record and entry uids and numbers; import and export counts and paths; every refusal and failed record as returned.
diff --git a/.agents/skills/formchem-harness/sub-skills/library-and-biopolymers/SUB-SKILL.md b/.agents/skills/formchem-harness/sub-skills/library-and-biopolymers/SUB-SKILL.md
new file mode 100644
index 00000000..d65e3323
--- /dev/null
+++ b/.agents/skills/formchem-harness/sub-skills/library-and-biopolymers/SUB-SKILL.md
@@ -0,0 +1,56 @@
+---
+name: library-and-biopolymers
+description: "Uses FormChem's 0.12.0 shared structure library and HELM tools: library_list (favourites, recent, templates and live items every Form app reads), library_add (a drawing or SMILES as a favourite, template, recent or live item with pictures that keep the drawing inside), live_structure_object (the formai-structure JSON a sibling app stores) and draw_from_helm (peptides, nucleic acids and linkers from HELM 2 as atoms, one undo step, with formula and masses). Use when the person asks an agent to star or save a structure for the other Form apps, put a structure into FormDeck, FormTxt or form.md as a live structure, list the structure library, hand a sibling app its object, or draw oxytocin, a cyclic peptide, a disulfide-bridged peptide or an RNA or DNA strand from HELM in FormChem."
+---
+
+# Library and biopolymers
+
+## Purpose
+
+Keep structures in the shared structure library that every Form app reads, hand sibling apps the live structure object, and draw biopolymers written in HELM, so the person sees each structure in their window and in the library. Hands back library item ids with their kinds and revisions, the object's id and rev, and for HELM the new fragment ids with formula, masses and their method.
+
+## Preconditions
+
+`get_context` has been called (`session-and-connection`). `library_list` and `live_structure_object` never ask; `library_add` and `draw_from_helm` ask the person the first time. These tools are not in the pack root's `references/tools.md` at 0.12.0 (its generator cannot read their modules yet); their arguments are here and in `docs/AGENTS.md`.
+
+## How the library is held
+
+The library is plain files in the data folder: `Library/library.json` and, per item, an SVG and a 512 pixel PNG (both with the FormChem drawing inside) and a molfile. Items have an `id` (`s` plus 10 lower-case letters or digits) that is never reused, `kinds` (any of `favourite`, `recent`, `template`, `live`), a `rev` that rises on every change, and SMILES, InChIKey, formula and average mass with the method that computed them. An item with no kinds left is deleted. Sibling apps read the folder without FormChem running; only FormChem writes it. The contract is `docs/LIVE_STRUCTURES.md` in the FormChem repository.
+
+## Workflow 1: add to the library
+
+1. **Call `library_add`** with `smiles` (no drawing needed), or with `doc` and optionally `ids` (objects of the drawing's page; default the whole first page). `doc` may be left out only when exactly one drawing is open. `kinds` defaults to `["favourite"]`; `name` names the item.
+2. **Read the answer.** It names the item id, kinds, formula, average mass with its method, and rev. A non-live structure already in the library gains the kind instead of becoming a second item; a `live` add is always a new item, so two sibling documents never share an id.
+3. **Pictures** come from the engine (RDKit) with the drawing embedded when an agent adds the item; items the person adds in the window carry the window's own pictures. Either way the drawing inside is complete.
+
+## Workflow 2: list and hand out
+
+- `library_list {kind?}` lists items (the text shows the first 40) with the folder path.
+- `live_structure_object {id}` returns the JSON a sibling app keeps in its document: `format` `formai-structure`, `format_version` 1, `id`, `rev`, `app`, `name`, `kind`, `smiles`, `inchikey`, `svg` (the picture, drawing inside), `molfile`, `width` and `height` in points. Give it to a sibling app as returned; never edit the SVG, because the drawing inside it is what makes the structure editable again.
+- Opening an item for editing is the person's, a sibling's or `./formchem edit-live ID`'s act; from an agent, `run_command {id: "open-live-structure", params: {id, from}}` asks the window to do it. Saving that drawing (the person's Save) raises the item's rev.
+
+## Workflow 3: draw from HELM
+
+1. **Call `draw_from_helm {helm, doc?, x?, y?, name?}`** with HELM version 2 text: `PEPTIDE1{G.G}$$$$`, `RNA1{R(A)P.R(U)}$$$$`, or with connections `PEPTIDE1{C.Y.I.Q.N.C.P.L.G.[am]}$PEPTIDE1,PEPTIDE1,1:R3-6:R3$$$V2.0` (oxytocin). With no drawing open it makes one. One undo step ("Draw from HELM").
+2. **Know the monomers.** FormChem's own 55: the 20 amino acids (one letter), their D forms `[dA]` and so on (no `[dG]`), `[Aib]`, `[Nle]`, `[Orn]`, `[Sar]`, `[Hyp]`, `[pE]`, caps `[ac]` (R2 only) and `[am]` (R1 only); RNA sugars `R` and `[dR]`, phosphate `P`, bases `A`, `C`, `G`, `U`, `T`. R3 sits on C, K, D, E and Orn side chains, for disulfide and lactam bridges. Anything else goes in as inline SMILES with numbered attachment points (`[[*:1]CCO[*:2]]`).
+3. **Read the answer.** New ids, SMILES, InChIKey, formula, average and monoisotopic mass with the reader, monomer data version and RDKit version. Check it like any structure (`visual-qa`).
+4. **A refusal names the character** where reading stopped (counted from 1) and why: "X is not a PEPTIDE monomer FormChem knows", mixtures in parentheses, BLOBs, repeat ranges, hydrogen-bond pairs, `?` attachment points. Fix an obvious typo once; otherwise report it.
+
+To turn a drawn peptide or nucleic acid back into HELM, use `run_command {id: "copy-helm"}` with it selected: FormChem copies HELM only when it reads back to the same InChIKey, and otherwise says which piece it could not match. There is no agent tool that returns HELM text.
+
+## Rules
+
+- **The drawing inside is the structure.** Never pass a sibling a picture without its embedded drawing, or an object with a hand-edited SVG.
+- **Revisions only go up.** A lower or equal rev never overwrites the library; do not try to roll an item back by sending an old object.
+- **Monomers are FormChem's.** Do not claim a monomer FormChem does not list; use inline SMILES and say so.
+- **Methods travel with the numbers.** Quote masses with the method the answer names.
+
+## Gate
+
+- [ ] Every library item named by id with its kinds and rev as returned.
+- [ ] Every HELM drawing checked with its InChIKey or formula from the answer, and every refusal reported with its character and reason.
+- [ ] No object or picture was altered on the way to a sibling app.
+
+## Hands back
+
+Library item ids, kinds and revs; live structure objects as returned; HELM fragment ids, formula, masses and methods; refusals with their reasons.
diff --git a/.agents/skills/formchem-harness/sub-skills/session-and-connection/SUB-SKILL.md b/.agents/skills/formchem-harness/sub-skills/session-and-connection/SUB-SKILL.md
index 9c8d91bd..0836ac92 100644
--- a/.agents/skills/formchem-harness/sub-skills/session-and-connection/SUB-SKILL.md
+++ b/.agents/skills/formchem-harness/sub-skills/session-and-connection/SUB-SKILL.md
@@ -52,5 +52,5 @@ Agents started from FormChem's own Claude Code, Codex, Cursor or Antigravity tab
## Gate
- [ ] `get_context` was the first call.
-- [ ] The plan uses only the 60 tools in the pack root's `references/tools.md` and the commands and extensions they report.
+- [ ] The plan uses only the 77 tools (the 71 in the pack root's `references/tools.md`, the library and HELM tools in `library-and-biopolymers` and the xtb tools in `three-d`) and the commands and extensions they report.
- [ ] No change was attempted after a refusal or a stop, and the agent token never appeared in a reply or a note.
diff --git a/.agents/skills/formchem-harness/sub-skills/three-d/SUB-SKILL.md b/.agents/skills/formchem-harness/sub-skills/three-d/SUB-SKILL.md
index 01f82aa8..cb82ea98 100644
--- a/.agents/skills/formchem-harness/sub-skills/three-d/SUB-SKILL.md
+++ b/.agents/skills/formchem-harness/sub-skills/three-d/SUB-SKILL.md
@@ -1,6 +1,6 @@
---
name: three-d
-description: "Uses FormChem's 0.10.0 3D tools: build_3d (a conformer from the 2D drawing with ETKDGv3 and MMFF94, MMFF94s or UFF, with the stereo check), conformers_3d (an ensemble in an energy window with populations), minimise_3d, scan_dihedral (a relaxed scan with its barrier), measure_3d (distance, angle, dihedral), open_3d_structure (PDB, mmCIF, SDF, MOL), extract_ligand and export_3d (MOL, SDF, PDB, XYZ), plus the 3D window commands for styles, surfaces and PNG or glTF. Use when the person asks an agent to make a structure 3D, find its conformers or lowest-energy shape, minimise it, scan a torsion, measure a bond length or angle, open a PDB or mmCIF file, pull a ligand out of a protein, or save 3D coordinates in FormChem, and to check that a 3D geometry kept the drawn stereo."
+description: "Uses FormChem's 0.10.0 3D tools: build_3d (a conformer from the 2D drawing with ETKDGv3 and MMFF94, MMFF94s or UFF, with the stereo check), conformers_3d (an ensemble in an energy window with populations), minimise_3d, scan_dihedral (a relaxed scan with its barrier), measure_3d (distance, angle, dihedral), open_3d_structure (PDB, mmCIF, SDF, MOL), extract_ligand and export_3d (MOL, SDF, PDB, XYZ), the 0.12.0 xtb_optimise and crest_conformers (xtb and CREST when the person installed them), plus the 3D window commands for styles, surfaces and PNG or glTF. Use when the person asks an agent to make a structure 3D, find its conformers or lowest-energy shape, minimise it, scan a torsion, measure a bond length or angle, open a PDB or mmCIF file, pull a ligand out of a protein, get a GFN2-xTB energy or a CREST ensemble, or save 3D coordinates in FormChem, and to check that a 3D geometry kept the drawn stereo."
---
# Three-d
@@ -11,11 +11,11 @@ Turn drawn structures into 3D geometry FormChem stores in the drawing, work on t
## Preconditions
-`get_context` has been called (`session-and-connection`), and the structure is drawn (`drawing`, `edit-by-id`, `names-and-spectra`). `build_3d`, `conformers_3d`, `minimise_3d`, `open_3d_structure` and `extract_ligand` ask the person the first time; `scan_dihedral` only with `store: true`; `export_3d` only when it writes a file outside the temporary folder; `measure_3d` never asks.
+`get_context` has been called (`session-and-connection`), and the structure is drawn (`drawing`, `edit-by-id`, `names-and-spectra`). `build_3d`, `conformers_3d`, `minimise_3d`, `open_3d_structure` and `extract_ligand` ask the person the first time; `scan_dihedral` only with `store: true`; `export_3d` only when it writes a file outside the temporary folder; `measure_3d` never asks; `xtb_optimise` and `crest_conformers` ask the first time.
## How 3D is held
-A structure's 3D coordinates are its `conformers`, each with an id (`c...`), an energy in kcal/mol, a `method` (`ETKDG` when only embedded, `MMFF94`, `MMFF94s`, `UFF`, or `file` when read from a file) and `converged`; `conformer` names the shown one. Atoms are the fragment atom ids from `get_atoms`; a hydrogen is `a1:h0` (the first hydrogen of `a1`), an atom inside an expanded abbreviation `a5:x0`. Any later edit to the structure's atoms or bonds (element, charge, bond order, wedge, adding or deleting) removes its conformers in the same undo step; moves and colours keep them. So: finish editing, then build.
+A structure's 3D coordinates are its `conformers`, each with an id (`c...`), an energy in kcal/mol, a `method` (`ETKDG` when only embedded, `MMFF94`, `MMFF94s`, `UFF`, `xtb` for an xtb or CREST result, or `file` when read from a file) and `converged`; an xtb conformer also carries `program` (name, version, method, solvent, charge, uhf, energy in hartree, gap); `conformer` names the shown one. Atoms are the fragment atom ids from `get_atoms`; a hydrogen is `a1:h0` (the first hydrogen of `a1`), an atom inside an expanded abbreviation `a5:x0`. Any later edit to the structure's atoms or bonds (element, charge, bond order, wedge, adding or deleting) removes its conformers in the same undo step; moves and colours keep them. So: finish editing, then build.
## Workflow 1: build and check
@@ -35,6 +35,17 @@ A structure's 3D coordinates are its `conformers`, each with an id (`c...`), an
MMFF94 energies compare conformers of one structure under one force field. They are not heats of formation and do not compare across structures, compositions or force fields. Say that when a person compares them.
+## Workflow 3a: xtb and CREST (0.12.0)
+
+xtb and CREST are LGPL-3.0 programs FormChem never ships or downloads. They run only when the person has installed them (PATH, a conda environment, or the path in Preferences > 3D > Tight-Binding Programs).
+
+1. **Call `xtb_optimise {object, method?, solvent?, charge?, uhf?, single_point?, level?, limit?}`**. `method` is `gfn2` (GFN2-xTB, default) or `gfnff`; `solvent` is `none` or an ALPB key (`water`, `methanol`, `acetonitrile`, `dmso`, `ch2cl2`, `chcl3`, `thf`, `toluene` and the rest of xtb's 24). Charge defaults to the drawn formal charges, `uhf` to the drawn radicals; a pair that cannot match the electron count is refused before anything runs, with the reason. A structure with no conformer is built first (ETKDGv3+MMFF94). The tool waits (default limit 600 s) and stores the result as the structure's only conformer, one undo step.
+2. **Call `crest_conformers {object, method?, solvent?, ewin?, keep?, limit?}`** for an ensemble: window 6 kcal/mol, at most 20 kept by default, limit 3600 s. CREST can take minutes to hours on anything flexible; set `limit` to what the person will wait for. Conformers that lost the drawn stereo are dropped and the answer counts them.
+3. **Quote the label.** Every answer names the program, version, method and solvent ("xtb 6.7.1, GFN2-xTB, ALPB (Water)"), the total energy in hartree and kcal/mol, the HOMO-LUMO gap and whether the optimisation converged. Pass all of it on.
+4. **Not installed** is an answer, not a failure to retry: the tool says where to get the program (https://github.com/grimme-lab/xtb, https://github.com/crest-lab/crest). Tell the person; never suggest FormChem can download it. Fall back to `conformers_3d` and `minimise_3d` only if the person agrees, and say the energies are then MMFF94.
+
+Tight-binding total energies are in hartree for one structure, charge and solvent model; compare them only between conformers or structures computed with the same method and solvent. An optimisation replaces the MMFF94 conformers, so earlier force-field numbers no longer belong to the drawing.
+
## Workflow 3: protein files and ligands
1. **Call `open_3d_structure {path}`** with an absolute `.pdb`, `.ent`, `.cif` or `.mmcif` path. One undo step: a 3D object (`o...`) over the file kept byte for byte, cartoon for a protein, ligands ball and stick, waters hidden, the primary ligand focused. Read the chains, ligand keys (`A:ATP:301`) and the reader's warnings and pass them on. An `.sdf` or `.mol` opens as structures whose conformers are the file's coordinates (method `file`).
@@ -52,13 +63,14 @@ MMFF94 energies compare conformers of one structure under one force field. They
- **Method and version travel with the number.** Every energy, barrier, population and measurement names its force field and engine version as FormChem gave them.
- **Stereo before geometry.** A build is usable only when its stereo line says every label was kept.
- **Build after editing.** An edit to atoms or bonds drops the conformers; rebuild rather than reuse numbers from before the edit.
-- **No quantum claims.** FormChem has no xtb, CREST or other quantum method; do not describe a force-field energy as anything more.
+- **No quantum claims beyond xtb.** A force-field energy is only that. xtb and CREST are semiempirical tight binding, run only on the person's own installation; FormChem has no DFT or other quantum method.
## Gate
- [ ] Every build reported its stereo line, and a lost label stopped the work with the reason.
- [ ] Every energy, barrier and measurement was quoted from a tool answer with its method and engine version.
- [ ] Inferred ligand bond orders and unspecified stereocentres were passed on to the person.
+- [ ] Every xtb or CREST number carried its program label, and a missing program was reported with where to get it, not retried.
- [ ] Each changing call was one undo step, and the handoff says what the person will see in the 3D View or on the page.
## Hands back
diff --git a/.agents/skills/formchem-harness/sub-skills/window-commands/SUB-SKILL.md b/.agents/skills/formchem-harness/sub-skills/window-commands/SUB-SKILL.md
index f18eede1..de8c9a18 100644
--- a/.agents/skills/formchem-harness/sub-skills/window-commands/SUB-SKILL.md
+++ b/.agents/skills/formchem-harness/sub-skills/window-commands/SUB-SKILL.md
@@ -30,6 +30,8 @@ Most canvas commands act on the canvas selection. The agent sets the selection t
| Draw from a name | Use `draw_from_name` (`names-and-spectra`). `run_command {id: "insert-name", params: {name}}` inserts it the window's way (centred like a template, selected); without `name` it opens Structure from Name for the person. `copy-name` puts the selection's name on the person's clipboard |
| Spectrum commands: edit, pick peaks, integrate, link a peak, y axis, export, predict, refresh | Prefer the spectrum and NMR tools (`names-and-spectra`). The commands remain for what they add: `link-peak-to-atoms {object, peak, fragment, atoms}` (no tool links), `open-spectrum {path}` (inserts a file into the open drawing), `spectrum-y-mode {object, mode}`, `edit-spectrum` (opens the Spectrum editor for the person), `nmr-refresh` (with a predicted spectrum selected) |
| Show it in 3D, change the 3D style or surface, put a 3D view on the page, save a 3D picture | Build and measure with the 3D tools (`three-d`). Then `view-3d` (opens the 3D View on the selection), `style-wire`, `style-stick`, `style-ballstick`, `style-spacefill`, `style-cartoon`, `surface-none`, `surface-vdw`, `surface-sas`, `surface-ses`, `surface-esp` (on only while the 3D View is open), `insert-3d-view` (a 3D object beside the selected structure), `export-3d-png {transparent}` and `export-gltf` (saved for the person). `export-3d-file {format, all}` saves MOL, SDF, PDB or XYZ for the person; `export_3d` gives the agent the text |
+| Show the database, a view of it, its dialogs, or the notebook to the person | Work with the database tools (`databases`). Then `show-databases`, `db-view-table`, `db-view-gallery`, `db-view-form`, `db-view-plot`, `db-view-notebook`, `db-search {text}`, `db-import {path}`, `db-export`, `database-fields`, `database-settings` (the person's dialogs); `nb-sign-entry` asks the person to sign and is never run in their place |
+| Copy a live structure for another Form app, open a library item for editing, HELM text of a drawn peptide, show the Structure Library or the Structure Summary, change the element colours | Library and HELM tools first (`library-and-biopolymers`). Then `copy-live-structure`, `open-live-structure {id, from}`, `copy-helm`, `structure-library {tab}`, `a11y-describe`, `element-palette-high-contrast` and its two siblings |
| Stack or group objects | `bring-front`, `bring-forward`, `send-backward`, `send-back`, `group`, `ungroup` on the selection; off with "Select something on the canvas first" when nothing is selected |
| Anything about the reaction in the drawing | Load `reactions` |
| Undo the last change | `run_command {id: "undo"}`: one transaction, whoever made it |
diff --git a/.agents/skills/formchem-harness/sub-skills/window-commands/references/command-catalogue.md b/.agents/skills/formchem-harness/sub-skills/window-commands/references/command-catalogue.md
index 929cca42..2ef1d85c 100644
--- a/.agents/skills/formchem-harness/sub-skills/window-commands/references/command-catalogue.md
+++ b/.agents/skills/formchem-harness/sub-skills/window-commands/references/command-catalogue.md
@@ -1,6 +1,6 @@
# Commands that touch a drawing
-The window's command registry, as far as it concerns drawings, for FormChem 0.10.0 (the commands of 0.7.0, plus `agent-activity` from 0.8.0, which opens Window > Agent Activity for the person, plus the name, spectrum and NMR commands of 0.9.0, plus the 3D commands of 0.10.0). From 0.8.0 the agent's own tools draw, edit, read back, render and convert; this page covers what the window's commands add. This page is a map, not the authority: `list_commands` is. A command marked `off now` there is not available in the running build, whatever this page says, and a command that lists `params` there takes exactly those.
+The window's command registry, as far as it concerns drawings, for FormChem 0.12.0 (the commands of 0.7.0, plus `agent-activity` from 0.8.0, which opens Window > Agent Activity for the person, plus the name, spectrum and NMR commands of 0.9.0, the 3D commands of 0.10.0, the database and notebook commands of 0.11.0, and the library, live structure, HELM, xtb and accessibility commands of 0.12.0). From 0.8.0 the agent's own tools draw, edit, read back, render and convert; this page covers what the window's commands add. This page is a map, not the authority: `list_commands` is. A command marked `off now` there is not available in the running build, whatever this page says, and a command that lists `params` there takes exactly those.
## Contents
@@ -14,6 +14,8 @@ The window's command registry, as far as it concerns drawings, for FormChem 0.10
- Standardise and size on the sheet
- Names, spectra and NMR prediction
- 3D
+- Databases and the notebook
+- Library, live structures, HELM, xtb and accessibility
- The canvas, the view and the grid
- Registered but off until a later version
- What no command does yet
@@ -170,6 +172,45 @@ From 0.10.0, group `3D`. Building, conformers, minimising, scans, measuring, ope
| `export-gltf` | | saves the 3D View as binary glTF (`.glb`) for the person (while the 3D View is open) |
| `export-3d-file` | `format` (`mol`, `sdf`, `pdb`, `xyz`), `all` (every conformer) | saves the selected structure's 3D coordinates for the person, or a PDB or mmCIF model's original file; without `format` it opens the dialog. For text the agent reads, `export_3d` |
+## Databases and the notebook
+
+From 0.11.0, groups `Database` and `Notebook`. Creating, opening, importing, searching, registering, exporting and notebook entries also have MCP tools (`databases`); prefer them, because they answer with the counts, ids and reasons. The commands show the person the database workspace and its dialogs. The search, import, export, plot, query and hit list commands are off until a database is open, and import and save query are off on a read-only one.
+
+| Command | Params | What it does |
+| --- | --- | --- |
+| `show-databases` | | shows or hides the database workspace (Shift+Mod+D) |
+| `new-database`, `open-database`, `close-database` | | the New and Open Database dialogs for the person; close releases the database's lock. For an agent, `db_create` and `db_open` |
+| `add-to-database` | | registers the selected structure, or the page as one record, in the current database; a duplicate opens the person's choice dialog. For an agent, `db_add_record` |
+| `database-settings`, `database-fields` | | the person's dialogs for the title and duplicate rules, and for fields (no MCP tool changes fields) |
+| `db-view-table`, `db-view-gallery`, `db-view-form`, `db-view-plot`, `db-view-notebook` | | shows the workspace in that view |
+| `db-search` | `text` (optional) | puts the cursor in the workspace search box; with `text`, runs it as plain text (text fields, uid, formula, SMILES) and shows the hit list. Structure and query searches: `db_search` |
+| `db-advanced-search`, `db-save-query`, `db-combine-hitlists` | | the query builder, Save Query and Combine Hit Lists dialogs for the person |
+| `db-import` | `path` (absolute, optional) | opens the Import dialog, previewing `path` at once; the person maps and imports. For an agent, `db_import` |
+| `db-export` | | opens the Export dialog for the person; for an agent, `db_export` |
+| `nb-new-entry` | | the New Notebook Entry dialog; for an agent, `nb_add_entry` |
+| `nb-sign-entry` | | asks the person to sign the shown entry with their name; never run it to sign on the person's behalf |
+| `nb-export-entry` | `format` (`html` default, or `json`) | saves the shown entry for the person |
+| `nb-save-scheme` | | saves the drawing opened with Edit Scheme back into its entry (on only while that drawing is active) |
+
+## Library, live structures, HELM, xtb and accessibility
+
+From 0.12.0. Adding to the library, the live structure object, drawing from HELM and the xtb and CREST runs also have MCP tools (`library-and-biopolymers`, `three-d`); prefer them, because they answer with ids, formulas and energies. The commands add the clipboard, the Structure Library dialog, opening a live drawing, HELM text out, and the person's accessibility views.
+
+| Command | Params | What it does |
+| --- | --- | --- |
+| `copy-live-structure` | | copies the selection (or the page) as a live structure: the picture with the drawing inside, the object, SMILES and molfile on the clipboard, and adds it to the library as live and recent. For an agent, `library_add {kinds: ["live"]}` and `live_structure_object` |
+| `star-structure` | | adds the selection (or the drawing) to the library as a favourite. For an agent, `library_add` |
+| `library-save-template` | `name` (asked when left out) | saves the selection (or the drawing) to the library as a template |
+| `structure-library` | `tab` (`favourite`, `recent`, `template`, `live`) | opens the Structure Library dialog for the person |
+| `open-live-structure` | `id` (required), `from` | opens a library item as a live drawing (the title shows the sibling); the person's Save then raises its rev. Answers "Opened live structure [id] rev [n] as drawing [doc]" |
+| `insert-helm` | `helm` (optional) | with `helm`, inserts it as atoms, one undo step; without, opens the Biopolymer from HELM dialog. For an agent, `draw_from_helm` answers with the numbers |
+| `copy-helm` | | copies the selected peptide or nucleic acid as HELM, only when it reads back to the same structure; with params from an agent it throws the reason instead of a toast |
+| `xtb-optimise` | `method`, `single_point`, `charge`, `uhf`, `solvent`, `level`, `limit` | with params, runs xtb on the selected structure without the dialog and waits; without, the dialog. For an agent, `xtb_optimise` |
+| `crest-conformers` | `method`, `charge`, `uhf`, `solvent`, `ewin`, `keep`, `limit` | the same for CREST. For an agent, `crest_conformers` |
+| `a11y-focus-structure`, `a11y-next-atom`, `a11y-previous-atom` | | put the keyboard focus ring on the drawing and walk atoms, for the person (Alt+Mod+A, Alt+Mod+], Alt+Mod+[) |
+| `a11y-describe` | | speaks and shows the Structure Summary (formula, name, rings, groups, stereo) for the person (Alt+Mod+S) |
+| `element-palette-standard`, `element-palette-high-contrast`, `element-palette-colour-blind` | | the element colours on this device (checked items under View > Element Colours) |
+
## The canvas, the view and the grid
| Command | What it does |
@@ -195,4 +236,4 @@ From 0.10.0, group `3D`. Building, conformers, minimising, scans, measuring, ope
## What no command does yet
-Selecting particular atoms or objects, typing stoichiometry amounts, and filling the person's dialogs (atom list, R-group, abbreviation label). Drawing atoms, bonds, arrows and text at given positions, reading the structure back, rendering and converting are not commands: the 0.8.0 tools do them (`drawing`, `edit-by-id`, `visual-qa`). Reading a spectrum's points, its peaks or the predicted shifts as data is not a command either: the 0.9.0 tools do it (`names-and-spectra`). Nor is reading conformer energies, a scan profile or a 3D measurement as data, or 3D coordinates as text: the 0.10.0 tools do it (`three-d`). Picking atoms in the 3D View, choosing the shown conformer and running a scan from the dialog belong to the person. An installed extension with the `document` permission can also read and change the drawing (`extension-drawings`).
+Selecting particular atoms or objects, typing stoichiometry amounts, and filling the person's dialogs (atom list, R-group, abbreviation label). Drawing atoms, bonds, arrows and text at given positions, reading the structure back, rendering and converting are not commands: the 0.8.0 tools do them (`drawing`, `edit-by-id`, `visual-qa`). Reading a spectrum's points, its peaks or the predicted shifts as data is not a command either: the 0.9.0 tools do it (`names-and-spectra`). Nor is reading conformer energies, a scan profile or a 3D measurement as data, or 3D coordinates as text: the 0.10.0 tools do it (`three-d`). Nor is reading database records, hit list rows or notebook entries as data: the 0.11.0 tools do it (`databases`). Nor is reading library items, live structure objects or xtb energies as data: the 0.12.0 tools do it (`library-and-biopolymers`, `three-d`). Picking atoms in the 3D View, choosing the shown conformer and running a scan from the dialog belong to the person. An installed extension with the `document` permission can also read and change the drawing (`extension-drawings`).
diff --git a/.agents/skills/formchem-skillset/EVALS.json b/.agents/skills/formchem-skillset/EVALS.json
index 3b0745e9..15b53e67 100644
--- a/.agents/skills/formchem-skillset/EVALS.json
+++ b/.agents/skills/formchem-skillset/EVALS.json
@@ -1,6 +1,6 @@
{
"skill_name": "formchem-skillset",
- "notes": "Run in a FormChem checkout at 0.10.0 with CLAUDE.md present. Expected behaviours are observable in the files read, the edits made and the commits.",
+ "notes": "Run in a FormChem checkout at 0.12.0 with CLAUDE.md present; evals 32 to 36 need no fixtures, and eval 35 must not install xtb. Expected behaviours are observable in the files read, the edits made and the commits.",
"evals": [
{
"id": 1,
@@ -303,6 +303,108 @@
"Finds that SUFFIXES in backend/app/routers/files.py lacks .usdz (as it lacked .glb, .cif, .mmcif and .ent until 0.10.0) and adds it by hand",
"Updates the extension list in docs/FORMATS.md and writes a backend HASHOUT entry"
]
+ },
+ {
+ "id": 28,
+ "name": "new-database-field-type",
+ "prompt": "Add a 'range' field type to FormChem databases that holds a low and a high number, like a melting point range.",
+ "files": [],
+ "expected_behavior": [
+ "Loads databases and reads docs/DATABASE.md before any code, and treats it as the contract",
+ "Edits the field table in DATABASE.md, schema.FIELD_TYPES with a raised FORMAT_VERSION and a migrate step, and FieldType in database-api.ts in the same change",
+ "Updates fields.py (_check_spec, coerce, detect, rebuild_view), exports.text_of, the type groups in query.py, columns.ts and the Fields dialog's type list",
+ "Checks by creating a scratch database under a scratch data folder, never ~/formchem"
+ ]
+ },
+ {
+ "id": 29,
+ "name": "new-query-term",
+ "prompt": "I want FormChem database searches to find records by ring count, like 'rings between 2 and 4'.",
+ "files": [],
+ "expected_behavior": [
+ "Loads databases and checks whether a number term on an existing column or computed field already covers it before adding a new kind",
+ "If a new kind is added: the term table in DATABASE.md, query.KINDS and _term with a named 422, _term_name, a mask in search.py with a _cost that keeps structure terms last, TERM and toQuery in query-model.ts, term-editor.ts and describeQuery",
+ "Does not compute ring counts outside chem.register_values or the computed descriptors",
+ "Checks the new term on a scratch database and confirms that hit counts match a brute-force count"
+ ]
+ },
+ {
+ "id": 30,
+ "name": "slow-substructure-after-edit",
+ "prompt": "After I update a record in my FormChem database, the next substructure search takes over a second again on 100,000 records. Why?",
+ "files": [],
+ "expected_behavior": [
+ "Loads databases and reads search.py screen, _gate and advance, and backend HASHOUT entries 237 and 238",
+ "Explains that a person's write moves the audit head, so the screening cache reloads (and the pickled molecule holder is rebuilt in the background), which is by design",
+ "Does not remove the audit row from the write or skip the freshness check, because every compound write must call store.audit inside its transaction",
+ "Proposes any speed-up as a measured change on a scratch 100,000 record copy, with a HASHOUT entry"
+ ]
+ },
+ {
+ "id": 31,
+ "name": "new-notebook-template",
+ "prompt": "Add a 'crystallisation' template to the FormChem lab notebook.",
+ "files": [],
+ "expected_behavior": [
+ "Loads databases and edits templates.py (NAMES, _HEADINGS, _OBSERVATIONS, LABELS) with headings in the plain markup",
+ "Adds it to EntryTemplate and TEMPLATES in the notebook window with its label through t(), to the template enum of nb_add_entry, and to DATABASE.md's template list",
+ "Runs ./formchem agents sync after the MCP tool change and commits the mirror"
+ ]
+ },
+ {
+ "id": 32,
+ "name": "new-live-object-field",
+ "prompt": "FormDeck wants a 'formula' field in the FormChem live structure object. Add it.",
+ "files": [],
+ "expected_behavior": [
+ "Loads family-integration and reads docs/LIVE_STRUCTURES.md first",
+ "Edits LIVE_STRUCTURES.md (the object), live_structures.live_object and the LiveObject type in app/live-structures.ts in one change, without raising format_version (an old reader ignores the new field)",
+ "Checks with a scratch script against a scratch FORMCHEM_DATA_DIR, not ~/formchem, and logs the decision in backend/HASHOUT_LOG.md"
+ ]
+ },
+ {
+ "id": 33,
+ "name": "agent-token-write-path",
+ "prompt": "Let ./formchem edit-live also save a drawing through the agent token, so a sibling can save without the window.",
+ "files": [],
+ "expected_behavior": [
+ "Loads family-integration and names law 4: the agent token writes only under /api/structures",
+ "Either keeps the change under /api/structures (save_live through the structures routes) or stops and asks, because widening core/window_key.py AGENT_WRITES is a SECURITY.md change",
+ "Does not add another path to AGENT_WRITES without a SECURITY.md edit in the same change"
+ ]
+ },
+ {
+ "id": 34,
+ "name": "new-helm-monomer",
+ "prompt": "Add N-methylalanine ([meA]) as a HELM monomer in FormChem.",
+ "files": [],
+ "expected_behavior": [
+ "Loads chemistry-engine and clean-room; writes the monomer itself from the structure, not from a HELM monomer library",
+ "Adds smiles with [*:1] and [*:2], the capped form, attachments R1 H and R2 OH and a source sentence to data/helm_monomers.json, and runs helm.monomers.library() so the load-time check passes",
+ "Round-trips a peptide containing [meA] through read and from_mol to the same InChIKey in a scratch script, and updates docs/HELM.md, the agent_helm description and the NOTICE.md count"
+ ]
+ },
+ {
+ "id": 35,
+ "name": "xtb-option",
+ "prompt": "Let FormChem's xtb optimisation take an electronic temperature (--etemp).",
+ "files": [],
+ "expected_behavior": [
+ "Loads three-d and follows the xtb option recipe: constant and validation in services/xtb, the argv in inputs.xtb_argv as a list item, never a shell string",
+ "Exposes it in the dialog, the xtb-optimise command params and agent_xtb's schema and KEYS, and records it in the program record only with FORMAT.md, model.ts and model.py changed together",
+ "Checks with a stand-in xtb on a temporary PATH, not by downloading xtb, and says a real run was not made if none was"
+ ]
+ },
+ {
+ "id": 36,
+ "name": "palette-flash",
+ "prompt": "Switching to the colour-blind element palette in FormChem makes the canvas flicker. Fix it.",
+ "files": [],
+ "expected_behavior": [
+ "Loads family-integration and canvas; looks at canvas/a11y/palette.ts applyPalette and the measure epoch rather than rebuilding the canvas",
+ "Checks under 4x CPU throttling with a MutationObserver that a switch adds or removes no node and changes only fills",
+ "Writes the reason in frontend/HASHOUT_LOG.md, not in a comment"
+ ]
}
],
"trigger_evals": [
@@ -358,6 +460,18 @@
{"query": "the 3D object on the formchem page flashes when I change its style", "should_trigger": true},
{"query": "add a surface option to FormChem's 3D View panel in frontend/src/ui", "should_trigger": true},
{"query": "give me the lowest-energy conformer of the structure in my open FormChem drawing", "should_trigger": false},
- {"query": "open this PDB file in formchem and extract the ligand for me", "should_trigger": false}
+ {"query": "open this PDB file in formchem and extract the ligand for me", "should_trigger": false},
+ {"query": "add a new query term to formchem's database search in services/database/query.py", "should_trigger": true},
+ {"query": "the formchem database table flashes when records load while scrolling", "should_trigger": true},
+ {"query": "an SD import into a formchem .fcdb reports the wrong record numbers in its failure report", "should_trigger": true},
+ {"query": "change how formchem hashes a notebook entry when it is signed", "should_trigger": true},
+ {"query": "search my FormChem database for compounds with a pyridine ring", "should_trigger": false},
+ {"query": "design a SQLite schema for a generic inventory app", "should_trigger": false},
+ {"query": "the formai://formchem/edit link opens the wrong drawing in FormChem's desktop app, fix handleDeepLink", "should_trigger": true},
+ {"query": "add a functional group to formchem's describe.py so the screen reader names sulfonamides", "should_trigger": true},
+ {"query": "FormChem's xtb job leaves its process running after cancel, look at services/xtb/runner.py", "should_trigger": true},
+ {"query": "Copy as HELM refuses a stapled peptide in formchem, fix the writer cuts", "should_trigger": true},
+ {"query": "draw oxytocin from HELM in FormChem for me", "should_trigger": false},
+ {"query": "make FormDeck read the formai structure library folder", "should_trigger": false}
]
}
diff --git a/.agents/skills/formchem-skillset/SKILL.md b/.agents/skills/formchem-skillset/SKILL.md
index 68284afc..79679f99 100644
--- a/.agents/skills/formchem-skillset/SKILL.md
+++ b/.agents/skills/formchem-skillset/SKILL.md
@@ -1,42 +1,44 @@
---
name: formchem-skillset
-description: "Guides development of the FormChem codebase, the FormAI family's chemical structure drawing suite. Use whenever a task changes, fixes or explains FormChem code: the document format (FORMAT.md, model.ts, model.py, ops, undo), the RDKit service (identifiers, the scored 2D layout, CIP, stereo groups, abbreviations, queries, R-groups, properties), reactions, file formats and loss reports, picture export, the clipboard, the command line, Standardise, the SVG canvas, grids, scaling, tools, annotations, names (dictionary, parser, namer), NMR prediction (increments), JCAMP-DX spectra, 3D (build, conformers, force fields, PDB and mmCIF, the 3D View, glTF), the shell, menus, the dock, Form extensions, the MCP server and agent tools (agent_edits, agent_log, the agent token), the Tauri shell, or a release. Trigger on FormChem or formchem with backend/app, frontend/src, src-tauri, FORMAT.md, port 8220 or 5220. Not for using FormChem (formchem-harness), other Form apps such as FormDeck, or standalone RDKit scripts."
+description: "Guides development of the FormChem codebase, the FormAI family's chemical structure drawing suite. Use whenever a task changes, fixes or explains FormChem code: the document format (FORMAT.md, model.ts, model.py, ops), the RDKit service (identifiers, the 2D layout, CIP, stereo groups, abbreviations, queries, properties), reactions, file formats, the clipboard, the command line, the SVG canvas, annotations, names, NMR prediction, JCAMP-DX spectra, 3D (conformers, force fields, PDB, xtb and CREST), the structure database and notebook (.fcdb, search, import, signing hashes), live structures and the shared library (LIVE_STRUCTURES.md, formai:// links, edit-live), keyboard access and palettes, HELM, the shell, menus, extensions, the MCP server and agent tools, the Tauri shell, or a release and its CHANGELOG. Trigger on FormChem or formchem with backend/app, frontend/src, src-tauri, FORMAT.md or port 8220. Not for using FormChem (formchem-harness), other Form apps such as FormDeck, or standalone RDKit scripts."
license: Apache-2.0
metadata:
author: nodemode-ai
- version: "0.10.0"
+ version: "0.12.0"
---
# FormChem skillset
Route every change to FormChem's code through this file. It maps the subsystems that exist today, states the laws that hold everywhere and names the specialist to load. FormChem is a Python 3.12 FastAPI engine (`backend/`, port 8220), a vanilla TypeScript and Vite window (`frontend/`, port 5220, no framework) that talks to the engine over REST and one WebSocket, and a Tauri 2 shell (`src-tauri/`) that runs the frozen engine from a folder inside the app on macOS and as a sidecar elsewhere.
-**Where FormChem is (0.10.0).** Through 0.9.0: the family shell, the document format, store and RDKit service, the canvas, reactions, stereo and analysis, formats and pictures, the agent tools with Agent Activity and the token, names, NMR prediction and spectra (`CHANGELOG.md`). 0.10.0 adds 3D: builds from 2D with a stereo check, conformers, force fields, scans, PDB and mmCIF files, the 3D View, model3d objects and eight more MCP tools (60). The structure database (0.11.0) comes later (`DEV_PLAN.md`). Do not write a later phase's code ahead of it; its commands stay registered and disabled.
+**Where FormChem is (0.12.0).** Through 0.11.0: the shell, format, store and RDKit service, canvas, reactions, analysis, formats, agent tools, names, NMR, spectra, 3D, databases and the notebook (`CHANGELOG.md`). 0.12.0 adds live structures and the shared library (`docs/LIVE_STRUCTURES.md`), accessibility, HELM, xtb and CREST by path and six MCP tools (77). Desktop builds and the manual (0.13.0) come later (`DEV_PLAN.md`); do not write them ahead.
## Subsystem map
| Subsystem | Root | Specialist |
| --- | --- | --- |
| Engine core: config, guards, window key, settings and seal, live socket, bridge, library | `backend/app/main.py`, `core/`, `routers/system.py`, `routers/live.py`, `services/hub.py`, `services/bridge.py`, `routers/library.py`, `backend/formchem_engine.py` | `engine` |
-| Engine document store: open documents, transactions, undo and redo, autosave, versions, recovery, the `.fchem` package, importers, the live `tx` messages | `backend/app/services/store.py`, `services/history.py`, `services/package.py`, `services/importers.py`, `routers/documents.py`, `core/files.py` | `engine` |
+| Engine document store: open documents, transactions, undo, autosave, versions, the `.fchem` package, importers | `backend/app/services/store.py`, `services/history.py`, `services/package.py`, `services/importers.py`, `routers/documents.py`, `core/files.py` | `engine` |
| The format contract: document.json, styles, ids, ops and inverses, transactions, validation, coalescing, the derived cache shape | `docs/FORMAT.md`, `frontend/src/engine/model.ts`, `engine/ops.ts`, `backend/app/services/model.py`, `services/ops.py` | `document-format` |
| Chemistry engine on RDKit: conversion, sanitising, valence, aromaticity, identifiers, formula, masses, layout, file reading and writing, the derived cache | `backend/app/services/chem/`, `backend/app/routers/chem.py` | `chemistry-engine` |
-| Window documents and chemistry: the document client, File and Insert actions, the Analysis panel, local valence, rings and formula | `frontend/src/engine/client.ts`, `engine/session.ts`, `engine/client-api.ts`, `app/documents.ts`, `ui/analysis-panel.ts`, `frontend/src/chem/` | `window-shell` (chemistry rules in `chemistry-engine`) |
-| Canvas: SVG renderer, drawing tools and hover hotkeys, view, hit testing, selection, text editor, canvas context menus, tool rail; from 0.7.0 the dark page, grids and snapping, scale handles | `frontend/src/canvas/` (`render/`, `tools/`, `view.ts`, `hit.ts`, `selection.ts`, `context.ts`, the grid and dark page files), `ui/tool-rail.ts`, `styles/canvas*.css`, `public/fonts/` | `canvas` |
-| Drawn objects: the object kind registry and kind modules, anchors, bounds, drawn-outline hits, annotation tools and handles, captions, z-order and groups, the template library, media | `frontend/src/canvas/render/objects.ts` and its kind modules, `canvas/hit-objects.ts`, `canvas/tools/objects.ts`, `tools/handles.ts`, `app/object-commands.ts`, `ui/template-*.ts`, `backend/app/services/templates.py`, `routers/templates.py`, `backend/app/data/templates/`, the media routes in `routers/documents.py` | `annotations` |
-| Reactions: perception, atom mapping, balance, stoichiometry (engine and window), reaction SMILES and RXN, the Reaction menu, the MCP reaction tools | `backend/app/services/chem/` (`geometry`, `reactions`, `mapping`, `balance`, `stoich`, `rxnio`, `scheme`), `routers/reactions.py`, `frontend/src/chem/stoich.ts`, `ui/stoich-panel.ts`, `app/reaction-commands.ts`, `engine/reactions-api.ts`, `docs/REACTIONS.md` | `reactions` |
-| Stereo, queries and analysis: stereo groups, CIP, wedges, abbreviations, hydrogens, queries, SMARTS, Markush, properties, the structure check, the isotope pattern, their routes, commands, marks and panels | `backend/app/services/chem/` (`stereo`, `superatom`, `hydrogens`, `query`, `search`, `v3000`, `markush`, `props`, `check`, `isotopes`), `routers/analysis.py`, `frontend/src/engine/analysis-api.ts`, `app/chem-*.ts`, `canvas/render/marks-*.ts`, `docs/ANALYSIS.md` | `stereo-and-queries` |
-| Formats and export: the formats table, report items, readers and writers (CDXML and CDX through Indigo, RD, CML), the export, parse, import and file write routes, pictures with the embedded drawing, the save path, print, File > Import | `backend/app/services/chem/` (`formats`, `report`, `io`, `writers`, `cdxio`, `rdfio`, `cml`), `services/embedded_source.py`, `services/pictures/`, `services/importers.py`, `routers/files.py`, `routers/pictures.py`, `frontend/src/app/` (`picture`, `embedded-source`, `save-file`, `export-commands`, `print`, `import-files`), `ui/export-dialog.ts`, `ui/import-report.ts`, `docs/FORMATS.md` | `formats-and-export` |
-| Clipboard: the native payload and paste plan, text formats, flavours per platform, Copy As, Paste Special, Duplicate | `frontend/src/app/clip-*.ts`, `app/clipboard.ts`, `ui/paste-special-dialog.ts`, `ui/native-menu.ts` `ALWAYS_NATIVE` | `clipboard` |
-| Names, NMR prediction and spectra: name engines, dictionary, parser, namer; increments and predicted spectra; the JCAMP-DX reader, peaks, integrals; the name dialog, spectrum kind, atom links, Spectrum editor | `backend/app/services/` (`names/`, `nmr/`, `spectra/`), `data/names/`, `routers/` (`names`, `nmr`, `spectra`), the window files in the specialist's file map, `docs/NAMES.md`, `docs/SPECTRA.md` | `names-and-spectra` |
+| Window documents and chemistry: the document client, File and Insert actions, the Analysis panel, local valence and rings | `frontend/src/engine/client.ts`, `session.ts`, `client-api.ts`, `app/documents.ts`, `ui/analysis-panel.ts`, `frontend/src/chem/` | `window-shell` (rules in `chemistry-engine`) |
+| Canvas: SVG renderer, tools and hover keys, view, hit testing, selection, text editor, context menus, tool rail, the dark page, grids, scale handles | `frontend/src/canvas/` (`render/`, `tools/`, `view.ts`, `hit.ts`, `selection.ts`, `context.ts`, the grid and dark page files), `ui/tool-rail.ts`, `styles/canvas*.css`, `public/fonts/` | `canvas` |
+| Drawn objects: the kind registry, anchors, bounds, annotation tools and handles, captions, z-order and groups, templates, media | `canvas/render/objects.ts` and kind modules, `hit-objects.ts`, `tools/objects.ts`, `handles.ts`, `app/object-commands.ts`, `ui/template-*.ts`, `services/templates.py`, `data/templates/` | `annotations` |
+| Reactions: perception, mapping, balance, stoichiometry, reaction SMILES and RXN, the Reaction menu and tools | `services/chem/` (`geometry`, `reactions`, `mapping`, `balance`, `stoich`, `rxnio`, `scheme`), `routers/reactions.py`, `chem/stoich.ts`, `ui/stoich-panel.ts`, `app/reaction-commands.ts`, `engine/reactions-api.ts`, `docs/REACTIONS.md` | `reactions` |
+| Stereo, queries and analysis: stereo groups, CIP, wedges, abbreviations, hydrogens, queries, SMARTS, Markush, properties, the check, isotopes | `services/chem/` (`stereo`, `superatom`, `hydrogens`, `query`, `search`, `v3000`, `markush`, `props`, `check`, `isotopes`), `routers/analysis.py`, `engine/analysis-api.ts`, `app/chem-*.ts`, `render/marks-*.ts`, `docs/ANALYSIS.md` | `stereo-and-queries` |
+| Formats and export: the formats table, reports, readers and writers (CDXML and CDX through Indigo, RD, CML), the exchange routes, pictures with the embedded drawing, print, File > Import | `services/chem/` (`formats`, `report`, `io`, `writers`, `cdxio`, `rdfio`, `cml`), `services/pictures/`, `embedded_source.py`, `importers.py`, `routers/files.py`, `pictures.py`, the window's export, print and import files, `docs/FORMATS.md` | `formats-and-export` |
+| Clipboard: the native payload, paste plan, flavours per platform, Copy As, Paste Special, Duplicate | `frontend/src/app/clip-*.ts`, `app/clipboard.ts`, `ui/paste-special-dialog.ts`, `ui/native-menu.ts` `ALWAYS_NATIVE` | `clipboard` |
+| Names, NMR prediction and spectra: name engines, namer; increments and predicted spectra; JCAMP-DX, peaks, integrals, atom links, the Spectrum editor | `backend/app/services/` (`names/`, `nmr/`, `spectra/`), `data/names/`, `routers/` (`names`, `nmr`, `spectra`), the window files in the specialist's file map, `docs/NAMES.md`, `docs/SPECTRA.md` | `names-and-spectra` |
| 3D: builds, conformers, force fields, scans, measurements, PDB and mmCIF, ligands, the stale-conformer rule; the 3D View, model3d snapshots, glTF | `backend/app/services/three_d/`, `routers/three_d.py`, `frontend/src/ui/view3d-*.ts`, `canvas/render/model3d.ts`, `io/glb.ts`, `engine/three-api.ts`, `engine/stale.ts`, `docs/3D.md` | `three-d` |
-| Command line and batch: convert, batch, descriptors, render, the stream reader, Standardise (engine, route, dialog) | `backend/app/cli.py`, `services/batch.py`, `services/chem/` (`stream`, `records`, `standardise`, `depict`), `setup/convert`, `frontend/src/ui/standardise-dialog.ts`, `app/standardise-command.ts`, `docs/CLI.md` | `command-line` |
+| Databases and notebook: the `.fcdb` store, registration, fields, import, export, search, hit lists, plot, entries and signing; the workspace, search and notebook views | `backend/app/services/database/`, `services/notebook/`, `routers/databases.py`, `db_search.py`, `notebook.py`, `frontend/src/ui/database*/`, `ui/notebook/`, `engine/database-api.ts`, `docs/DATABASE.md` | `databases` |
+| Family integration: the shared Library folder, live structures, edit-live, the `formai://` link, the file watch; accessibility keys, speech, the summary, palettes | `services/live_structures.py`, `file_watch.py`, `describe.py`, `routers/structures.py`, `app/live-structures.ts`, `ui/library-dialog.ts`, `canvas/a11y/`, `docs/LIVE_STRUCTURES.md` | `family-integration` |
+| Command line and batch: convert, batch, descriptors, render, the stream reader, Standardise | `backend/app/cli.py`, `services/batch.py`, `services/chem/` (`stream`, `records`, `standardise`, `depict`), `setup/convert`, `ui/standardise-dialog.ts`, `docs/CLI.md` | `command-line` |
| Window shell: app root, command registry, palette, Home, title bar, status bar, Preferences, dialogs, themes, i18n, styles | `frontend/src/app.ts`, `app/commands-shell.ts`, `commands/registry.ts`, `io/`, `ui/`, `i18n/`, `styles/` | `window-shell` |
| Menus: in-window menu bar, native macOS menus, context menus | `frontend/src/ui/menu.ts`, `ui/native-menu.ts`, `ui/context-menu.ts`, `app/menus.ts`, `styles/menu.css` | `menus` |
| Terminal and agent dock | `frontend/src/dock/` (vendored), `frontend/src/dock-adapter.ts`, `backend/app/routers/terminal.py`, `services/terminal.py`, `services/claude_code.py`, `services/agent_programs.py`, `services/agent_lookup.py` (vendored) | `dock` |
| Form extensions (host API 1) | `frontend/src/extensions/`, `backend/app/routers/extensions.py`, `services/formext_host.py` (vendored), `docs/EXTENSIONS.md` | `extensions` |
-| MCP server, agent tools, the call log and Agent Activity, the agent token, commands catalogue, agent setup and skills | `backend/app/routers/mcp.py`, `services/agent_*.py`, `core/agent_token.py`, `routers/agent_activity.py`, `routers/commands.py`, `frontend/src/app/agent-*.ts`, `ui/agent-*.ts`, `canvas/agent-marks.ts`, `setup/mcp_stdio.py`, `setup/agents.py`, `docs/AGENTS.md`, `.claude/skills` | `agents` |
-| Desktop app, the macOS engine folder and the sidecar | `src-tauri/` (`packaged.rs`, `tauri.macos.conf.json`), `backend/formchem_engine.py`, `setup/freeze_backend`, `setup/lib.sh`, `setup/desktop_*`, `build_app` | `desktop` |
+| MCP server, agent tools, the call log, Agent Activity, the token, the catalogue, skills | `backend/app/routers/mcp.py`, `services/agent_*.py`, `core/agent_token.py`, `routers/agent_activity.py`, `routers/commands.py`, `frontend/src/app/agent-*.ts`, `ui/agent-*.ts`, `canvas/agent-marks.ts`, `setup/mcp_stdio.py`, `setup/agents.py`, `docs/AGENTS.md`, `.claude/skills` | `agents` |
+| Desktop app, the macOS engine folder and the sidecar | `src-tauri/` (`packaged.rs`, `tauri.macos.conf.json`), `formchem_engine.py`, `setup/freeze_backend`, `lib.sh`, `desktop_*`, `build_app` | `desktop` |
| Versions, changelog, notices, CI, formcompiler | `.docs/BRANCHING.md`, `CHANGELOG.md`, `NOTICE.md`, `setup/notices.py`, `.github/workflows/` | `release` |
| Where any FormChem feature may come from | the owner's clean-room specifications | `clean-room` |
@@ -47,9 +49,8 @@ frontend commands/registry.ts -> nothing (DOM free; the cli and workers may impo
engine/model.ts, engine/ops.ts -> nothing (pure, DOM free; the contract)
chem/ -> engine/model.ts only (pure, no t(), no DOM)
engine/client.ts, session.ts -> model, ops, client-api, io/api, io/live
-canvas/render -> canvas/types.ts, engine/model, engine/ops (its own geom, valence, rings);
- render/table.ts also chem/stoich.ts, the one window stoichiometry source;
- render/marks-layer.ts also canvas/marks-options.ts (view toggles only)
+canvas/render -> canvas/types.ts, engine/model, engine/ops (own geom, valence, rings); table.ts
+ also chem/stoich.ts; marks-layer.ts also canvas/marks-options.ts
engine/analysis-api.ts -> io/api, model, ops; the only caller of /api/analysis
canvas/tools -> canvas/types.ts, engine/model, engine/ops, canvas/geom.ts
canvas/view.ts, ui/tool-rail -> canvas/types.ts, hit.ts, selection.ts, ui/dom, ui/icons, i18n
@@ -60,9 +61,8 @@ backend services/model.py, ops.py -> nothing (pure; the contract)
services/store.py -> model, ops, package, history, importers, hub; chem.derive imported lazily
services/chem/ -> rdkit, indigo, model (never the store or routers)
backend routers -> core, services (hub, bridge, library, store, chem, terminal, formext_host)
-mcp.py -> commands, extensions, consent, claude_code (in-app tokens), bridge, hub, agent_token;
- routers/analysis and the agent_* services imported lazily by the tools
-services/agent_*.py -> store, bridge, chem (agent_edits is pure: model and chem only); agent_log hooks AFTER_CHANGE
+mcp.py -> commands, extensions, consent, claude_code, bridge, hub, agent_token; agent_* lazily
+services/agent_*.py -> store, bridge, chem (agent_edits pure); agent_log hooks AFTER_CHANGE
app/picture.ts -> canvas/render (a fresh renderer off screen), never the live canvas view
app/clip-*.ts, import-files -> engine/model, ops, the export and parse routes; one paste plan (clip-data.ts)
services/chem/writers, stream -> formats, report, io, rdkit, indigo (never the store)
@@ -70,6 +70,9 @@ services/batch.py, app/cli.py -> chem/stream, records, standardise, depict, prop
services/pictures/ -> fontTools and the bundled fonts only
services/names, nmr, spectra -> rdkit, numpy, chem (never routers); nmr registers its hook in spectra.source.PREDICTORS
services/three_d -> rdkit, numpy, chem (never routers); store.apply_now runs three_d.stale
+services/database, notebook -> sqlite3, rdkit, numpy, chem (never routers or the document store)
+services/helm, xtb, describe -> rdkit, chem (xtb also three_d); xtb starts programs only as separate processes
+canvas/a11y -> canvas view and render, ui/a11y-announcer; installed before mountCanvas
ui/view3d-lib.ts -> 3dmol by dynamic import only (nothing 3D at startup)
window-only abilities -> reach the engine as window tools over /api/live (bridge.window_call)
desktop shell -> frozen engine (formchem_engine.py) -> serves frontend/dist
@@ -103,22 +106,24 @@ The window reaches the engine only through `frontend/src/io/api.ts` (REST with t
| How a bond, label or wedge renders, a drawing tool, a hover key, hit testing, selection, zoom, the tool rail, canvas context menus | `canvas` |
| An arrow, bracket, shape, table, TLC plate, orbital, picture or caption, its handles and tool; z-order, groups, templates | `annotations`, with `canvas` for the laws it builds on |
| Reaction roles, atom mapping, balance, the stoichiometry panel or grid, reaction SMILES or RXN, a reaction route, command or MCP tool | `reactions`, with `chemistry-engine` for RDKit and `agents` for a tool |
-| A CIP label, stereo group, wedge, abbreviation, explicit hydrogen, atom list, query bond, SMARTS, substructure hit, R-group, property, check issue or isotope peak; an `/api/analysis` route, an analysis MCP tool, a stereo or query mark | `stereo-and-queries`, with `chemistry-engine` for the converter and `agents` for a tool |
+| A CIP label, stereo group, wedge, abbreviation, hydrogen, query atom or bond, SMARTS, R-group, property, check issue or isotope peak; an `/api/analysis` route or tool | `stereo-and-queries` (`chemistry-engine` for the converter, `agents` for a tool) |
| A file that opens wrong or loses something, an export or import report, a new format, File > Import, picture export, the drawing inside a picture, saving in the desktop app, print | `formats-and-export`, with `chemistry-engine` for RDKit and `clean-room` for a new format |
| Copy, Cut, Paste, Copy As, Paste Special, Duplicate, a clipboard flavour on one platform | `clipboard`, with `formats-and-export` for the text formats and pictures |
| `./formchem convert`, `batch`, `descriptors`, `render`, the stream reader, per-record failures, Standardise | `command-line`, with `chemistry-engine` for RDKit |
| A name read wrong, a dictionary entry, a ring parent, OPSIN; a predicted shift, an increment, a predictor; a JCAMP-DX file, the spectrum plot, peaks, integrals, atom links, the Spectrum editor | `names-and-spectra` (`clean-room` first; `canvas` for the renderer, `document-format` for the spectrum object) |
| A 3D build, conformer, scan, measurement or surface; a PDB or mmCIF file or ligand; the 3D View, a 3D object on the page, glTF; conformers after an edit | `three-d` (`document-format` for `conformers` and `model3d`, `agents` for a tool) |
+| A database field, query term, import or export format, hit list, duplicate rule, notebook template or signing; the workspace table, search or plot | `databases` (`agents` for a tool) |
+| The Library folder, Copy as Live Structure, a live Save, edit-live, the deep link, the file bar; a focus key, a spoken sentence, the summary, a palette | `family-integration` (`agents` for a tool) |
+| A HELM string or monomer; an xtb or CREST option or job | `chemistry-engine`; `three-d` |
| A crowded or crossing 2D layout, Lay Out or Clean Up | `chemistry-engine` (the scored layout) |
| The dark page, a grid type, snapping, scale handles, Scale Up and Down | `canvas`, with `document-format` for `style.grid` |
| New, Open, Save, Insert from SMILES, the Analysis panel, the status bar formula, the dirty mark | `window-shell`, with `chemistry-engine` for the values |
| Home, the title bar, status bar, palette, Preferences, About, dialogs, themes, translations, styles | `window-shell` |
-| A menu item, a submenu, a shortcut label, macOS native menus, menu overlap | `menus`, then `window-shell` for the command |
+| A menu item, submenu or shortcut label, native macOS menus, a menu that clips the title, More menus, keys with a menu open | `menus`, then `window-shell` for the command |
| Terminal tabs, Claude Code, Codex, Cursor or Antigravity tabs, the consent dialog, chat | `dock` |
| The extensions pane, an extension API call, FormPortal or form.ext integration | `extensions` |
| An MCP tool, an edit builder, agent render or placement, the call log, Agent Activity, Stop, the token, `./formchem agents`, skills | `agents` |
-| Desktop build, `build_app`, a slow desktop start, the macOS engine folder and its flatten rule, the Tauri CLI version, sidecar, updater, Tauri commands, title bar overlay | `desktop` |
-| A menu that clips or overlaps the title, More menus, Escape or arrows with a menu open | `menus` |
+| Desktop build, `build_app`, a slow start, the macOS engine folder, sidecar, updater, Tauri commands, title bar overlay | `desktop` |
| A release, version sites, CHANGELOG, NOTICE, CI | `release` |
| Any chemistry feature, a file format, a name for a command or panel | `clean-room` first |
| Use FormChem: draw or edit a structure with the agent tools, run a menu command, hand off in the window | Not this pack: `formchem-harness` |
@@ -131,7 +136,8 @@ formchem-skillset/
references/repo-laws.md each law with its reason and exact format
EVALS.json evaluation prompts and the trigger tests (should and should not load)
sub-skills/ engine, document-format, chemistry-engine, reactions, stereo-and-queries, formats-and-export,
- clipboard, command-line, names-and-spectra, three-d, canvas, annotations, window-shell, menus, dock,
+ clipboard, command-line, names-and-spectra, three-d, databases, family-integration, canvas, annotations,
+ window-shell, menus, dock,
extensions, agents, desktop, release, clean-room
chemistry-engine/references/warning-codes.md every ChemWarning code and where it comes from
stereo-and-queries/references/routes-and-codes.md the /api/analysis routes, check codes and service warning codes
@@ -159,7 +165,7 @@ cd frontend && npx tsc --noEmit type-check
backend/venv/bin/python -m compileall -q backend/app setup
```
-Scratch engines for checks: `FORMCHEM_PORT=[port] FORMCHEM_DATA_DIR=[scratch]/data venv/bin/python -m uvicorn app.main:app --port [port]` from `backend/`. `backend/venv/bin/python backend/formchem_engine.py --selfcheck` confirms RDKit and Indigo import. Never point a check at `~/formchem`, the person's data folder.
+Scratch engines: `FORMCHEM_PORT=[port] FORMCHEM_DATA_DIR=[scratch]/data venv/bin/python -m uvicorn app.main:app --port [port]` from `backend/`; never point a check at `~/formchem`, the person's data folder.
## Done means
diff --git a/.agents/skills/formchem-skillset/sub-skills/agents/SUB-SKILL.md b/.agents/skills/formchem-skillset/sub-skills/agents/SUB-SKILL.md
index 2ae35fca..15017f09 100644
--- a/.agents/skills/formchem-skillset/sub-skills/agents/SUB-SKILL.md
+++ b/.agents/skills/formchem-skillset/sub-skills/agents/SUB-SKILL.md
@@ -31,9 +31,9 @@ Give agents an honest tool surface that only describes what FormChem can do now,
| `docs/AGENTS.md` | the public reference of every tool, the token and the call log |
| `.claude/skills/formchem-harness`, `formchem-skillset` | the packs; `.agents/skills` is a mirror written by sync. Made and repaired only through the god-tier-skill-creator pipeline; its `scripts/validate_skill.py` reports zero FAIL before a commit |
-## The tool surface (0.10.0)
+## The tool surface (0.12.0)
-60 tools: the six of the shell (`get_context`, `list_commands`, `run_command`, `extensions_list`, `extension_command`, `handoff`); the reaction tools of 0.5.0 and the analysis tools of 0.6.0 (owned by `reactions` and `stereo-and-queries`); and the 28 of 0.8.0: `list_open_documents`, `new_document`, `open_document`, `save_document`, `close_document`, `draw_from_smiles`, `draw_from_molfile`, `render`, `get_structure`, `validate`, `compute_properties`, `convert`, `batch_convert`, `get_atoms` and the 14 edit tools `add_atom`, `add_bond`, `set_charge`, `set_atom`, `set_stereo`, `replace_substructure`, `delete`, `move`, `scale`, `align`, `clean_layout`, `add_arrow`, `add_text`, `add_reaction`; and the 10 of 0.9.0, whose services `names-and-spectra` owns: `draw_from_name` (through `_draw`), `name_structure` (the route's `name_mol`), `predict_nmr`, `predict_spectrum` (`nmr.document.spectrum_ops`), `open_spectrum`, `spectrum_data`, `spectrum_peaks`, `spectrum_pick_peaks`, `spectrum_integrate` (`spectra.peak_ops`, `integral_ops`) and `spectrum_export`; and the 8 of 0.10.0, whose services `three-d` owns: `build_3d`, `conformers_3d`, `minimise_3d`, `scan_dihedral`, `measure_3d`, `open_3d_structure` (`three_d.open_bytes`) and `extract_ligand` call the `routers/three_d.py` functions through `_three_d` with an `AgentCall` in the body, so the route's `commit` applies with origin `agent` and the agent's name, and `export_3d` calls `export.write` directly. The writing ones are in `MUTATING` (`scan_dihedral` only with `store`, `export_3d` only with an `output` outside the temporary folder, through `_mutating`); a tool never builds its own copy of a route's ops.
+77 tools: the six of the shell (`get_context`, `list_commands`, `run_command`, `extensions_list`, `extension_command`, `handoff`); the reaction tools of 0.5.0 and the analysis tools of 0.6.0 (owned by `reactions` and `stereo-and-queries`); and the 28 of 0.8.0: `list_open_documents`, `new_document`, `open_document`, `save_document`, `close_document`, `draw_from_smiles`, `draw_from_molfile`, `render`, `get_structure`, `validate`, `compute_properties`, `convert`, `batch_convert`, `get_atoms` and the 14 edit tools `add_atom`, `add_bond`, `set_charge`, `set_atom`, `set_stereo`, `replace_substructure`, `delete`, `move`, `scale`, `align`, `clean_layout`, `add_arrow`, `add_text`, `add_reaction`; and the 10 of 0.9.0, whose services `names-and-spectra` owns: `draw_from_name` (through `_draw`), `name_structure` (the route's `name_mol`), `predict_nmr`, `predict_spectrum` (`nmr.document.spectrum_ops`), `open_spectrum`, `spectrum_data`, `spectrum_peaks`, `spectrum_pick_peaks`, `spectrum_integrate` (`spectra.peak_ops`, `integral_ops`) and `spectrum_export`; and the 8 of 0.10.0, whose services `three-d` owns: `build_3d`, `conformers_3d`, `minimise_3d`, `scan_dihedral`, `measure_3d`, `open_3d_structure` (`three_d.open_bytes`) and `extract_ligand` call the `routers/three_d.py` functions through `_three_d` with an `AgentCall` in the body, so the route's `commit` applies with origin `agent` and the agent's name, and `export_3d` calls `export.write` directly. The writing ones are in `MUTATING` (`scan_dihedral` only with `store`, `export_3d` only with an `output` outside the temporary folder, through `_mutating`); a tool never builds its own copy of a route's ops. And the 11 of 0.11.0, whose services `databases` owns, in agent modules rather than in `mcp.py`: `services/agent_db.py` (`db_list`, `db_create`, `db_open`, `db_import`, `db_search`, `db_get_record`, `db_add_record`, `db_update_record`, `db_export`) and `services/agent_notebook.py` (`nb_add_entry`, `nb_search`). Each module offers `TOOLS` in the `_tool` shape, frozen `NAMES`, `mutating(name, args)` and `async call(name, args, agent_name)`, which runs the database services on a worker thread and writes as `agent:[name]`; `mcp.py` walks `AGENT_MODULES` for the list, the gate and dispatch, so a new module adds one name there. They touch no drawing (except `nb_add_entry {doc}`, which reads one), so they answer with `_ok` text and `structuredContent`, not `write_result`. And the 6 of 0.12.0, in three more agent modules: `agent_library.py` (`library_list`, `library_add`, `live_structure_object`; `family-integration` owns the service), `agent_helm.py` (`draw_from_helm`, through `mcp._draw`; `chemistry-engine` owns `services/helm`) and `agent_xtb.py` (`xtb_optimise`, `crest_conformers`, through `_three_d` with the xtb job routes; `three-d` owns `services/xtb`). HELM and xtb build `mcp.Agent("", agent_name)` in `call` because `_draw`, `_apply` and `_three_d` read only the name. `setup/agents.py` reads `mcp.py`'s own `TOOLS` by AST, and each agent module's finished `TOOLS` by importing it with the backend venv's Python (`_module_tools`), so `references/tools.md` and `agents/manifest.json` hold all 77 tools.
## Laws of the agent tools
diff --git a/.agents/skills/formchem-skillset/sub-skills/chemistry-engine/SUB-SKILL.md b/.agents/skills/formchem-skillset/sub-skills/chemistry-engine/SUB-SKILL.md
index e16e9fbc..6ea4d544 100644
--- a/.agents/skills/formchem-skillset/sub-skills/chemistry-engine/SUB-SKILL.md
+++ b/.agents/skills/formchem-skillset/sub-skills/chemistry-engine/SUB-SKILL.md
@@ -1,6 +1,6 @@
---
name: chemistry-engine
-description: "FormChem's chemistry: the RDKit service in backend/app/services/chem (conversion from fragments, sanitising, valence, aromaticity, stereo and CIP, canonical SMILES, CXSMILES, InChI and InChIKey, Hill formula, masses, m/z, elemental analysis, isotope pattern, 2D clean-up and the scored layout: CoordGen and RDKit candidates, layout_score and layout_refine), the /api/chem routes, the derived cache broadcast after every transaction, and the window's local valence, ring and label rules in frontend/src/chem. Use when a computed value is wrong, a warning or valence error appears or is missing, a structure reads upside down or loses atoms, a layout is crowded, crosses bonds or moves the wrong atoms, or a new chemistry computation is added."
+description: "FormChem's chemistry: the RDKit service in backend/app/services/chem (conversion from fragments, sanitising, valence, aromaticity, stereo and CIP, canonical SMILES, CXSMILES, InChI and InChIKey, Hill formula, masses, m/z, elemental analysis, isotope pattern, 2D clean-up and the scored layout: CoordGen and RDKit candidates, layout_score and layout_refine), the /api/chem routes, the derived cache broadcast after every transaction, and the window's local valence, ring and label rules in frontend/src/chem, and from 0.12.0 the HELM reader and writer in services/helm over data/helm_monomers.json. Use when a computed value is wrong, a warning or valence error appears or is missing, a structure reads upside down or loses atoms, a layout is crowded, crosses bonds or moves the wrong atoms, a HELM string is refused or a peptide will not copy as HELM, a monomer is added, or a new chemistry computation is added."
---
# Chemistry engine
@@ -29,6 +29,7 @@ Compute everything chemical in one place, from the drawing as the person drew it
| `frontend/src/canvas/render/valence.ts`, `render/rings.ts` | The renderer's own fast implicit-H table and ring perception, used while drawing |
| `references/warning-codes.md` | Every warning code, the module that raises it and when. Open before adding or interpreting a warning |
| Reaction modules (0.5.0) | `chem/geometry.py`, `reactions.py`, `mapping.py`, `balance.py`, `stoich.py`, `rxnio.py`, `scheme.py`, `derive.reaction_checks` and `routers/reactions.py` belong to the `reactions` specialist; they reuse `convert.to_mol` and the rules here |
+| HELM (0.12.0) | `data/helm_monomers.json` (55 monomers written for FormChem, each with `smiles`, `capped`, `attachments`, `source`); `services/helm/monomers.py` (`_monomer` checks every capped form at load, `inline`), `parser.py` (`parse`, positioned `HelmError`, limits), `assemble.py` (`Chem.molzip` over shared map numbers, exported as `build_molecule`), `writer.py` (`CUTS`, `_assign`, `_topology`, `write`), `__init__.py` (`read`, `from_mol` with the InChIKey read-back); `routers/helm.py`, `services/agent_helm.py`, `frontend/src/ui/helm-dialog.ts`, `app/helm-commands.ts`; `docs/HELM.md`; HASHOUT backend 265 to 269, frontend 296 and 297 |
| Analysis modules (0.6.0) | `chem/stereo.py`, `superatom.py`, `hydrogens.py`, `query.py`, `search.py`, `v3000.py`, `markush.py`, `props.py`, `check.py`, `isotopes.py` and `routers/analysis.py` belong to the `stereo-and-queries` specialist. Here they changed `convert.py` (stereo groups and the chiral flag after perception, query atoms and bare `*` as generics), `perceive.py` (`stereo_unknown`, `undefined_double_bond`, cumulenes skipped, charged atoms judged by the allowed list so Na+ is no valence error) and `derive.content_key` (`FRAGMENT_FIELDS`) |
## Rules
@@ -50,6 +51,13 @@ Compute everything chemical in one place, from the drawing as the person drew it
3. A new derived field is a contract change: add it to the derived cache table in `docs/FORMAT.md` and to `DerivedFragment` in `model.ts` (`document-format`).
4. Time it: `derive_document` on a 250-atom fragment stays well under 100 ms warm.
+## A HELM monomer or a new cut (0.12.0)
+
+1. **Write the monomer yourself** from a textbook structure (`clean-room`): never copy a HELM monomer library, whose licence was never cleared. Give `smiles` with `[*:n]`, the `capped` form with each leaving group put back, `attachments` (R label to `H` or `OH`) and a `source` sentence; mirror-image D forms in full. The loader refuses the whole file when a capped form differs, so run `helm.monomers.library()` in the engine venv after the edit.
+2. **Reading** needs nothing more; **writing** needs the piece to come out of `writer._cuts`. A new bond kind is a `CUTS` row (SMARTS, the two cut atoms, the leaving group each side) and, if it pairs labels unusually, a `PARTNER` entry; cut only bonds that are always between monomers.
+3. **Round-trip check.** A scratch script under `/tmp` reads the HELM, writes it back and compares InChIKeys, for the new monomer and for oxytocin, ApU, a chain of all 20 L and 19 D residues, a head-to-tail cyclic peptide and the two lactam bridges. `from_mol` must never offer HELM that reads back differently.
+4. Update the monomer table in `docs/HELM.md`, the tool description in `agent_helm.py` and the count in NOTICE.md's own-data line.
+
## Gate
- [ ] `backend/venv/bin/python -m compileall -q backend/app` is clean and `backend/formchem_engine.py --selfcheck` exits 0.
diff --git a/.agents/skills/formchem-skillset/sub-skills/databases/SUB-SKILL.md b/.agents/skills/formchem-skillset/sub-skills/databases/SUB-SKILL.md
new file mode 100644
index 00000000..1d5ea236
--- /dev/null
+++ b/.agents/skills/formchem-skillset/sub-skills/databases/SUB-SKILL.md
@@ -0,0 +1,85 @@
+---
+name: databases
+description: "FormChem's 0.11.0 structure database and lab notebook code: the engine packages services/database (schema, store, chem.register_values, computed, fields, forms, records, attachments, thumbs, jobs, imports, exports, uploads, info, query, search, hitlists, saved, plot, dbcli) and services/notebook (templates, content hash, scheme, products, entries, export), routers databases.py, db_search.py and notebook.py, agent_db.py and agent_notebook.py, and the window's ui/database (workspace, table, gallery, form, dialogs), ui/database-find (search bar, query builder, hit lists, import, export, plot) and ui/notebook, against the contract docs/DATABASE.md. Use when adding a field type, a query term, an import or export format, a notebook template, a database route or MCP tool, fixing a slow or wrong search, an import report, a duplicate rule, a hit list, a table that flashes, or signing and the entry hash."
+---
+
+# Databases
+
+## Purpose
+
+Change FormChem's databases and notebook without breaking the contract: one `.fcdb` SQLite file that any SQLite browser reads, every write in one transaction with an audit row, keys and fingerprints from one function, searches that never add hits as a threshold rises, and a 10,000 record table that never rebuilds. Hands back the change, the checks that prove it and HASHOUT entries.
+
+## Preconditions
+
+`clean-room` loaded (the database and notebook sections of the clean-room specifications). `docs/DATABASE.md` read in full: it is the contract, and when code disagrees with it the code is the bug. `database-api.ts`, `workspace-types.ts` and `services/database/schema.py` are contract files too.
+
+## File map
+
+| Path | Holds |
+| --- | --- |
+| `services/database/schema.py`, `store.py` | tables, `FORMAT_VERSION`, `migrate`; handles, the lock file, `writing`, `reading`, `next_number`, `audit`, `notify`, `close_all` |
+| `database/chem.py`, `computed.py` | `register_values` (keys, formula, masses, counts, both fingerprints); descriptor fields over `chem/props.measure` |
+| `database/fields.py`, `forms.py`, `records.py`, `attachments.py`, `thumbs.py`, `info.py` | fields and the `records` view; generated forms; add, update, duplicates, paging; files; themed thumbnails; Info, create, open |
+| `database/jobs.py`, `imports.py`, `exports.py`, `uploads.py` | worker jobs; preview, mapping, batches of 250, the report, `plain`; SD, SMILES, CSV and one-time downloads; browser uploads and `adopt` |
+| `database/query.py`, `search.py`, `hitlists.py`, `saved.py`, `plot.py` | `normalise`, the formula grammar, `name_of`; the screening cache, `_evaluate`, `run`; hit lists with temp tables when read-only; saved queries; plot points |
+| `database/dbcli.py`, `app/cli.py` | `./formchem db` |
+| `services/notebook/` | `templates`, `content` (the eleven-key hash), `scheme` (molecules, stoichiometry, pictures), `products`, `entries` (`sign`, `after_change`, `listing`), `attachments`, `markup`, `export` |
+| `routers/databases.py`, `db_search.py`, `notebook.py`; `core/window_key.py` `require_view` | thin routes, `GUARD` and `VIEW_GUARD` |
+| `services/agent_db.py`, `agent_notebook.py`; `routers/mcp.py` `AGENT_MODULES` | the eleven tools, `mutating`, `call` |
+| `frontend/src/engine/database-api.ts` | types and one function per route, `DuplicateError` |
+| `frontend/src/ui/database/` | `workspace.ts`, `workspace-types.ts`, `record-source.ts` (blocks of 100), `selection.ts`, `columns.ts`, `table.ts`, `gallery.ts`, `form-view.ts`, `thumbs.ts`, the dialogs; `app/database-commands.ts` |
+| `frontend/src/ui/database-find/` | `search-bar.ts`, `query-text.ts`, `query-model.ts`, `term-editor.ts`, `query-builder.ts`, `hitlists.ts`, `queries.ts`, `import-dialog.ts`, `export-dialog.ts`, `files.ts`, `plot.ts`, `plot-math.ts` |
+| `frontend/src/ui/notebook/` | `notebook.ts`, `entry-list.ts`, `entry-editor.ts`, `scheme-view.ts`, `notebook-api.ts`, `markup.ts`, `commands.ts` |
+| `docs/DATABASE.md`, `docs/DATABASES.md` | the contract; the person's guide. HASHOUT backend 223 to 255, frontend 245 to 276 |
+
+## Laws
+
+1. **One transaction per write.** Every write runs inside `store.writing(db)` (BEGIN IMMEDIATE ... COMMIT under `db.lock`) and calls `store.audit` in it; reads use `store.reading`. The search cache trusts the audit head, so a write without an audit row leaves searches stale. Long work commits in batches, each its own transaction, and registers chemistry outside the lock.
+2. **Notify after commit.** `store.notify(db, change, uids)` is called once the transaction committed, never inside it, with the `change` names of DATABASE.md; the window refetches only what it names.
+3. **The contract wins.** A table, column or JSON shape change edits DATABASE.md, the engine and `database-api.ts` in one change, raises `FORMAT_VERSION` and adds a step to `schema.migrate`; an older file must still open (read-only when newer).
+4. **Fingerprints only through `chem.register_values`.** Stored rows and exact queries are keyed by that one function; never compute an InChIKey, parent key or fingerprint elsewhere.
+5. **Search stays monotonic and named.** Raising a similarity threshold never adds hits; every structure result names its method and the RDKit version.
+6. **The window never rebuilds.** Rows and tiles are pooled and keyed by uid, records arrive in blocks with stale blocks kept on screen, and a live change refetches only its blocks.
+7. **Agents never sign.** Signing is the person's statement; `nb_add_entry` writes open entries only.
+
+## Recipes
+
+### A new field type
+
+1. DATABASE.md's field table, `schema.FIELD_TYPES` and `NUMERIC_TYPES` (with a format version step), and `FieldType` in `database-api.ts`.
+2. Engine: `fields._check_spec`, `stores_text`, `coerce` (and its import path `text=True`), `detect`, `rebuild_view`; `exports.text_of` and `NON_SCALAR`; the type groups in `query.py`.
+3. Window: `columns.ts` (format, parse, `EDITABLE`), the type list in `fields-dialog.ts`, the import dialog's type names, the term editor's field groups in `database-find/shared.ts`.
+
+### A new query term
+
+1. DATABASE.md's term table first.
+2. `query.KINDS` and `_term` (defaults and the 422 naming the bad key), `_term_name` for the hit list name.
+3. `search.py`: a mask function in `FIELD_TERMS` or a branch in `_evaluate`, with a `_cost` that keeps structure terms last.
+4. Window: `TERM` and `toQuery` in `query-model.ts`, the row in `term-editor.ts`, `describeQuery` in `query-text.ts`; the `_QUERY` description in `agent_db.py`.
+
+### A new import or export format
+
+Import: `imports.FORMATS` and `format_of`, items from `chem/records.py` `iter_records` (streaming, a reason per bad record), `IMPORT_EXTENSIONS` in `files.ts`, the `--format` help in `dbcli.py`, the `format` enum of `db_import`, DATABASE.md and `docs/FORMATS.md`. Export: `exports.FORMATS` and `_write`, the export dialog, `db_export`'s enum, and a round trip into a new database that keeps every InChIKey and value.
+
+### A new notebook template
+
+`templates.NAMES`, `_HEADINGS`, `_OBSERVATIONS` and `LABELS`; `EntryTemplate` and `TEMPLATES` in the notebook window with its label through `t()`; the `template` enum of `nb_add_entry`; DATABASE.md's template list. Headings are plain markup (`**Heading**`), never HTML.
+
+### A database route or MCP tool
+
+A thin route with `GUARD` (or `VIEW_GUARD` for a picture) on a worker thread, `DatabaseError` turned into its status; the function in `database-api.ts`; a tool in `agent_db.TOOLS` or `agent_notebook.TOOLS` with `mutating` deciding consent, writing as `agent:[name]`; then `./formchem agents sync` (its generated `tools.md` reads only mcp.py's own `TOOLS`, so module tools are documented in `docs/AGENTS.md` and the harness `databases` sub-skill).
+
+## Checks
+
+Scratch data folders only (`FORMCHEM_DATA_DIR=[scratch]/data`). Import a 10,000 record SD file with three broken records: 9,997 added and three plain reasons. Benzene substructure equals a brute-force `HasSubstructMatch` on a 2,000 record copy; thresholds 0.3 to 0.9 never rise. A second process opens the file read-only and gets 423 on writes. The table under 4x CPU throttling: layout shift 0 while scrolling, no row nodes added on sort. An entry signed, then changed, keeps one `edited-after-signing` version with the signed hash.
+
+## Gate
+
+- [ ] DATABASE.md, the engine and `database-api.ts` agree; a shape change raised the format version with a migration.
+- [ ] Every new write is one transaction with an audit row and a notify after commit.
+- [ ] New numbers name their method and version; similarity stays monotonic.
+- [ ] The checks above ran on scratch data, and HASHOUT entries are written.
+
+## Hands back
+
+The change, the check output with numbers, and the HASHOUT entries.
diff --git a/.agents/skills/formchem-skillset/sub-skills/family-integration/SUB-SKILL.md b/.agents/skills/formchem-skillset/sub-skills/family-integration/SUB-SKILL.md
new file mode 100644
index 00000000..7881ade5
--- /dev/null
+++ b/.agents/skills/formchem-skillset/sub-skills/family-integration/SUB-SKILL.md
@@ -0,0 +1,84 @@
+---
+name: family-integration
+description: "FormChem's 0.12.0 family integration code: live structures and the shared structure library (services/live_structures.py, routers/structures.py, agent_library.py, app/live-structures.ts, ui/library-dialog.ts, the contract docs/LIVE_STRUCTURES.md), the agent token's one write path (core/window_key.py AGENT_WRITES), formchem edit-live, the formai:// deep link (tauri-plugin-deep-link, followDeepLinks, handleDeepLink), the file watch and its bar (services/file_watch.py, ui/file-changed-bar.ts), and accessibility (canvas/a11y: the key route, navigation, spoken atoms and bonds, the focus ring, element palettes; ui/a11y-announcer.ts, ui/structure-summary.ts, services/describe.py). Use when changing what a sibling Form app reads, the clipboard flavours of Copy as Live Structure, the library folder or library.json, a live drawing's Save, edit-live or the deep link, the file changed bar, a keyboard focus key, a spoken sentence, the Structure Summary, a functional group or ring name, or an element palette."
+---
+
+# Family integration
+
+## Purpose
+
+Change how FormChem works with the other Form apps and with assistive technology without breaking what they rely on: the Library folder and the live structure object stay readable by apps that never run FormChem code, a live drawing saves to its item and nothing else, the agent token writes nowhere but `/api/structures`, the keyboard route runs before the canvas's, every spoken sentence is a whole `t()` template, and switching palettes or showing the file bar never moves a node. Hands back the change, the checks that prove it and HASHOUT entries.
+
+## Preconditions
+
+`clean-room` loaded (the family and accessibility sections of the clean-room specifications, spec C 9.4). `docs/LIVE_STRUCTURES.md` read in full: it is the contract sibling apps code against, and when code disagrees with it, fix one of them in the same change and say which in the HASHOUT log.
+
+## File map
+
+| Path | Holds |
+| --- | --- |
+| `backend/app/services/live_structures.py` | `folder` (`FORMCHEM_DATA_DIR/Library`, not the recent-drawings `library.json`), `read_index`, `write_file`, `write_index` (atomic, index last), `add` (merges kinds for non-live, live always new), `prune` (`RECENT_CAP` 50 by `used`), `describe` (perceive, ids, `mass.average_mass`), `engine_pictures`, `live_object`, `adopt` (id kept, higher rev wins), `open_live`, `save_live`, `LINKS`, `links`, `open_request`, `edit_live` |
+| `backend/app/routers/structures.py` | the contract routes plus `links`, the unkeyed `picture.svg/png`, `GET /api/files/watch` and `POST .../{reload or keep}`; `_guard` takes the window key or the agent token |
+| `backend/app/core/window_key.py` | `AGENT_WRITES`, `agent_may_write`: the global guard lets a valid bearer token through on `/api/structures` and below only |
+| `backend/app/services/file_watch.py`, `app/main.py` lifespan | the 1 s poll of open drawings' files, own saves recognised by `document.json` `modified`, `reload` (one undoable transaction), `keep` |
+| `backend/app/services/agent_library.py` | `library_list`, `library_add`, `live_structure_object` in the agent module shape |
+| `backend/app/cli.py`, `formchem`, `formchem.bat` | `edit-live` |
+| `src-tauri/` (Cargo.toml, main.rs, tauri.conf.json, capabilities) | tauri-plugin-deep-link 2.6.3, the `formai` scheme, single-instance with `deep-link`, `register_all()` on Linux |
+| `frontend/src/app/live-structures.ts` | `structuresApi`, `copyLiveStructure` (one `writeClipboard`), `starStructure`, `saveTemplateToLibrary`, `saveLive`, `liveActive`, `mountLiveDrops`, `deepLinkTarget`, `handleDeepLink`, `LIVE_MIME`, `WEB_LIVE_MIME` |
+| `frontend/src/app.ts` `followDeepLinks`; `app/documents.ts` `DocumentHooks.save` | deep links in the main window only; closing a dirty live drawing saves its item |
+| `frontend/src/ui/library-dialog.ts`, `ui/file-changed-bar.ts`, `styles/library.css` | the Structure Library (built once, tiles keyed by id, fixed 132 px rows); the bar inside `.fc-stage` |
+| `frontend/src/canvas/a11y/` | `index.ts` (`prepareA11y` before `mountCanvas`, `mountA11y`), `controller.ts` (`installA11yKeys`, `CanvasA11y`, `relayCanvasPrompts`), `nav.ts`, `speech.ts`, `elements.ts`, `ring.ts`, `palette.ts`, `commands.ts` (`PALETTE_COMMAND_IDS`), `describe-api.ts` |
+| `frontend/src/canvas/render/atom.ts` | `ELEMENT_PALETTES` (standard, high-contrast, colour-blind), `setElementPalette` |
+| `frontend/src/ui/a11y-announcer.ts`, `ui/structure-summary.ts`, `styles/a11y.css` | the shared live regions; the summary dialog; focus ring, outlines, 24 px targets |
+| `backend/app/services/describe.py`, `routers/describe.py` | `GROUPS` (42 SMARTS), `RING_NAMES` (51 skeletons), `functional_groups` (priority, claimed atoms), `ring_name`, `stereo`, `describe`; `POST /api/describe` |
+| `docs/LIVE_STRUCTURES.md`, `LIVE-STRUCTURES.md`, `ACCESSIBILITY.md` | the contract; the person's pages. HASHOUT backend 256 to 264 and 276 to 278, frontend 277 to 295 and 300 |
+
+## Laws
+
+1. **The folder is the contract.** Every Library file is written through `core/files.write_atomic`, item files first and `library.json` last; deletes write the index first. Readers skip items whose files are missing. A field a sibling reads changes LIVE_STRUCTURES.md, `live_structures.py` and `live-structures.ts` together, and `format_version` rises only for a change an old reader would misread.
+2. **The drawing inside is the structure.** Every item SVG and PNG carries the FormChem source in the carriers of FORMATS.md, whoever drew it (the window's pictures, or `engine_pictures` without a window). A picture without it is a bug, not a lighter item.
+3. **A live drawing is ordinary.** Nothing is written into the drawing; the link lives in `LINKS` and the window's map. Save goes to `save_live` (rev + 1, `live-structure` broadcast), Save As stays an ordinary copy, closing calls the `DocumentHooks.save` hook. Revisions only rise: `adopt` keeps the higher rev.
+4. **The agent token has one write path.** Only `/api/structures` and below; every other changing route still needs the window key. Widening `AGENT_WRITES` is a SECURITY.md change.
+5. **The deep link only opens.** `deepLinkTarget` accepts `formai://formchem/edit?id=s[10]&from=...` and nothing else; other `formai` hosts pass on; only the `main` window listens. A link never carries a path, a command or a setting.
+6. **The key route goes first.** `prepareA11y()` runs before `mountCanvas` so its capture listener precedes the view's; handled keys get `preventDefault` only (`stopImmediatePropagation` breaks the menu bar's Alt detection); Tab past the last atom leaves, so focus is never trapped. The focus is the view's keyboard cursor, not a second one.
+7. **Speak whole sentences from fresh data.** Every spoken part is one `t()` template; derived values (hydrogens, CIP, aromaticity) only when `derived.rev` equals the client's and nothing is unconfirmed. One announcer for the window; the canvas's own region stays hidden and its prompts are relayed.
+8. **Palettes patch fills.** The choice is read before the canvas exists (localStorage `formchem.elementPalette`); a switch bumps the measure epoch so only fills change. High contrast stays at 7:1 or more on white; the colour-blind palette keeps Okabe-Ito hues of 3:1 or more and leaves paler ones to the ink.
+9. **Nothing moves.** The file bar is absolutely placed in the stage with a local z token; the library dialog patches tiles by id; the summary reserves its rows.
+
+## Recipes
+
+### A field or flavour a sibling reads
+
+LIVE_STRUCTURES.md first, then `live_object` or `describe` and `LiveObject` or `LibraryItem` in `live-structures.ts`, then `copyLiveStructure`'s flavour list. Browsers accept custom clipboard types only with the `web ` prefix and drop `chemical/x-mdl-molfile`; keep the object in the HTML flavour's `data-formai-structure` too. Check `library.json` field by field against the contract with a scratch script, and the clipboard in Chromium under 4x throttling.
+
+### A new way to open a live structure
+
+Route it to `open_live` (engine) or `openLiveStructure` (window), never a second opener. Command-line paths go through `open_request` and post with the agent token like `edit_live`; a desktop path goes through the deep link plugin and `handleDeepLink`.
+
+### A keyboard key or a spoken sentence
+
+Keys live in `controller.ts` (`installA11yKeys` and the handlers); registry commands in `commands.ts` with a key the 312-command registry does not already use (check `GET /api/commands`, and macOS reserved combinations such as Option-Command-D). Sentences go in `speech.ts` or `structure-summary.ts` as whole templates; element names in `elements.ts`. Check with Playwright reading `.fc-announcer-polite`, and say in the notes that no real screen reader ran unless one did.
+
+### A functional group or ring name
+
+Write the SMARTS or skeleton for FormChem (`clean-room`); a group marks its core atoms with map numbers and sits in priority order in `GROUPS`; a ring goes through the same `_skeleton_key` as the table. Re-run the 25-molecule scratch check (aspirin acid and ester, caffeine urea and purine, L-alanine S) and update the counts in NOTICE.md and ACCESSIBILITY.md.
+
+### An element palette
+
+A map in `ELEMENT_PALETTES` with contrast ratios computed on white in a scratch script, the choice in `PALETTE_CHOICES`, the Preferences option in `ui/prefs/sections.ts`. Check 0 nodes added or removed per switch under 4x throttling.
+
+## Checks
+
+From `backend/` on a scratch engine and data folder: `edit_live` against an item (exit 0), an unknown id (exit 1) and an unreadable file (exit 2); curl `/api/structures` without a key 403, with the token 200, and the token on `/api/helm/parse` and `/api/structuresX` 403; an outside rewrite of an open `.fchem` shows the bar within about a second and an own save does not. In the built window under 4x CPU throttling: Copy as Live Structure, paste back, open from the Live tab and Save raises rev; the keyboard-only ethanol speaks every atom and Describe reads its formula; palette switches and the file bar give layout shift 0. `npx tsc --noEmit` clean.
+
+## Gate
+
+- [ ] LIVE_STRUCTURES.md, the engine and the window agree; `library.json` written by FormChem passes a field-by-field check.
+- [ ] No route other than `/api/structures` accepts the agent token for writes; the deep link still opens only.
+- [ ] Keys still route before the canvas, Tab still leaves, and every new sentence is one `t()` template.
+- [ ] No node added or removed by a palette switch or the file bar; tiles patched by id.
+- [ ] HASHOUT entries and the docs updated; NOTICE.md own-data counts still true.
+
+## Hands back
+
+The change, the check results, the HASHOUT entries and the commit list.
diff --git a/.agents/skills/formchem-skillset/sub-skills/three-d/SUB-SKILL.md b/.agents/skills/formchem-skillset/sub-skills/three-d/SUB-SKILL.md
index 48ca1508..d4adf2ff 100644
--- a/.agents/skills/formchem-skillset/sub-skills/three-d/SUB-SKILL.md
+++ b/.agents/skills/formchem-skillset/sub-skills/three-d/SUB-SKILL.md
@@ -1,6 +1,6 @@
---
name: three-d
-description: "FormChem's 0.10.0 3D code: the engine package services/three_d (molecule labels, forcefield, build, verify, conformers, minimise, scan, measure, export, structure, pdb, mmcif, molfile3d, ligand, readers, document, stale), routers/three_d.py, the stale-conformer rule in the store and in engine/stale.ts, the window's 3D View panel over a lazily loaded 3Dmol.js (view3d-lib, view3d-viewer, view3d-panel, dialogs, scan plot), the model3d page renderer and its snapshots, the glb writer and the 3D commands. Use when adding a display style, a surface, a force field or method, a structure file reader, a 3D MCP tool or route, fixing a build that loses stereo, a conformer or scan result, a PDB summary or ligand, a 3D object that flashes on the page, or the conformer drop after an edit."
+description: "FormChem's 0.10.0 3D code: the engine package services/three_d (molecule labels, forcefield, build, verify, conformers, minimise, scan, measure, export, structure, pdb, mmcif, molfile3d, ligand, readers, document, stale), routers/three_d.py, the stale-conformer rule in the store and in engine/stale.ts, the window's 3D View panel over a lazily loaded 3Dmol.js (view3d-lib, view3d-viewer, view3d-panel, dialogs, scan plot), the model3d page renderer and its snapshots, the glb writer and the 3D commands, and from 0.12.0 services/xtb (discovery, runner, jobs, parse, writeback) with routers/xtb.py, agent_xtb.py and the xtb dialogs. Use when adding a display style, a surface, a force field or method, an xtb or CREST option, a structure file reader, a 3D MCP tool or route, fixing a build that loses stereo, a conformer or scan result, a PDB summary or ligand, an xtb job that hangs or misreads output, a 3D object that flashes on the page, or the conformer drop after an edit."
---
# Three-d
@@ -11,7 +11,7 @@ Change FormChem's 3D without breaking its promises: every energy and measurement
## Preconditions
-`clean-room` loaded (the 3D sections of the clean-room specifications). Licence rule: permissive anywhere; LGPL only as a separate process the person installs (xtb and CREST stay user-installed by path while plan question Q9 is open); GPL and AGPL never (no Open Babel code); gemmi (MPL-2.0) is not vetted. Ligand templates are written for FormChem; the Chemical Component Dictionary is CC0 but nothing was copied from it.
+`clean-room` loaded (the 3D sections of the clean-room specifications). Licence rule: permissive anywhere; LGPL only as a separate process the person installs (xtb and CREST are user-installed by path, plan question Q9's default; never bundle, download or link them); GPL and AGPL never (no Open Babel code); gemmi (MPL-2.0) is not vetted. Ligand templates are written for FormChem; the Chemical Component Dictionary is CC0 but nothing was copied from it.
## File map
@@ -29,7 +29,9 @@ Change FormChem's 3D without breaking its promises: every energy and measurement
| `frontend/src/canvas/render/model3d.ts` | the page object (snapshot, or a placeholder) |
| `frontend/src/io/glb.ts`, `chem/elements3d.ts`, `chem/geom3d.ts`, `chem/conformer-mol.ts` | glTF writer, palette and radii, measurement maths, local molfile |
| `frontend/src/app/view3d-commands.ts`, `app/menus.ts` | `VIEW3D_COMMAND_IDS`, the commands, `DISPLAY_3D`, `SURFACE_3D` |
-| `docs/3D.md`, `docs/FORMAT.md` | the reference; `conformers`, `conformer` and `model3d`. HASHOUT backend 199 to 222, frontend 222 to 244 |
+| `backend/app/services/xtb/` (0.12.0) | `__init__` (methods, levels, limits, settings keys), `solvents` (24 ALPB), `discovery` (`find`, `_locate`, `child_env`), `inputs` (start geometry in label order, `electrons_check`, argv), `runner` (`Process`, own process group, `stop_all`), `jobs` (one at a time, `_collect`, `_prune`), `parse`, `writeback` (`records`, `program`, `label`) |
+| `routers/xtb.py`, `services/agent_xtb.py`, `frontend/src/app/xtb-commands.ts`, `ui/xtb-dialog.ts`, `ui/prefs/xtb.ts` | the xtb routes and `_applier` over `three_d.commit`; the two tools; the client and commands; the dialogs; the Preferences rows |
+| `docs/3D.md`, `docs/FORMAT.md` | the reference; `conformers` (with the xtb `program` record), `conformer` and `model3d`. HASHOUT backend 199 to 222 and 270 to 275, frontend 222 to 244, 298 and 299 |
## Laws
@@ -50,11 +52,19 @@ Change FormChem's 3D without breaking its promises: every energy and measurement
### A force field or method
-Add it to `METHODS` and `forcefield.setup` with its own fallback reason, to `FORCE_FIELDS` in `three-api.ts`, the panel's select, `_FF` in `mcp.py`, and `docs/3D.md`. An external program (xtb) runs as a separate process found by a path the person sets, never bundled or linked, and its energy is stored under its own `method`.
+Add it to `METHODS` and `forcefield.setup` with its own fallback reason, to `FORCE_FIELDS` in `three-api.ts`, the panel's select, `_FF` in `mcp.py`, and `docs/3D.md`. An external program runs as a separate process found by a path the person sets, never bundled or linked, and its energy is stored under its own `method`, as xtb does (below).
+
+### An xtb or CREST option (0.12.0)
+
+1. Constants first: `xtb/__init__.py` (`METHODS`, `OPT_LEVELS`, limits) or `solvents.ALPB` (only solvents xtb documents).
+2. `jobs.options` validates it (422 with the reason), `inputs.xtb_argv` or `crest_argv` passes it; never build a shell string, always an argv list.
+3. Output: a new value is read in `parse.py` from the documented file layout and checked on a hand-written file under `/tmp`; it travels in the job's `conformers` table and, when it belongs with the geometry, in `writeback.program` (then FORMAT.md, `model.ts` `ConformerProgram` and `model.py` in one change).
+4. Expose it: the dialog field in `xtb-dialog.ts` (built once; polling patches text only), the command `params` in `xtb-commands.ts`, the tool schema and `KEYS` in `agent_xtb.py`, `docs/3D.md` and `docs/AGENTS.md`.
+5. Laws that stay: one job at a time; a failed job keeps its folder until it is forgotten; results map back by element order or the job fails (502); write-back goes through `three_d.commit` with the stale signature, so an edit mid-run fails the job instead of storing stale conformers. Check with a stand-in program on a temporary PATH (a script printing `xtb version X` and writing `xtbopt.xyz` and the log lines), never only with a real installation.
### A structure file reader
-A parser returning `Structure` (with `summary` working on it), a `detect` rule and rows in `EXTENSIONS` and `MIMES`, `readers.read`, `document.MODEL_FORMATS` and `importers.MODELS_3D`, `package.EXT_BY_MIME`, the window's `OPEN_EXTENSIONS` and `STRUCTURE_ACCEPT`, and `routers/files.py` `SUFFIXES` so the desktop save accepts it (that list still lacks `.glb`, `.cif`, `.mmcif` and `.ent` at 0.10.0). The bytes stay as media; never rewrite the file.
+A parser returning `Structure` (with `summary` working on it), a `detect` rule and rows in `EXTENSIONS` and `MIMES`, `readers.read`, `document.MODEL_FORMATS` and `importers.MODELS_3D`, `package.EXT_BY_MIME`, the window's `OPEN_EXTENSIONS` and `STRUCTURE_ACCEPT`, and `routers/files.py` `SUFFIXES` so the desktop save accepts it. The bytes stay as media; never rewrite the file.
### A 3D MCP tool or route
diff --git a/.claude/skills/formchem-harness/EVALS.json b/.claude/skills/formchem-harness/EVALS.json
index 8e288d02..e5060c3b 100644
--- a/.claude/skills/formchem-harness/EVALS.json
+++ b/.claude/skills/formchem-harness/EVALS.json
@@ -1,6 +1,6 @@
{
"skill_name": "formchem-harness",
- "notes": "Run with the FormChem engine and window open (./formchem) and the formchem MCP server connected with the agent token, version 0.10.0. Expected behaviours are observable in the tool calls and the final answer. FormChem 0.10.0 has 60 tools: agents draw with draw_from_smiles, draw_from_molfile, draw_from_name and add_reaction, edit by id with get_atoms and the 14 edit tools, check with render, get_structure and validate, name with name_structure, predict NMR with predict_nmr and predict_spectrum, work on spectra with open_spectrum and the spectrum tools, work in 3D with build_3d, conformers_3d, minimise_3d, scan_dihedral, measure_3d, open_3d_structure, extract_ligand and export_3d, and still reach the window's commands, reactions, analysis and extensions; several evals check that the agent draws with the tools and checks before it claims. Evals 13 and 14 need a drawn esterification scheme (acetic acid + ethanol, arrow, ethyl acetate + water); evals 15 to 18 need ibuprofen inserted with insert-smiles CC(C)Cc1ccc(cc1)[C@@H](C)C(=O)O; eval 20 needs an SD file at the path it names; eval 28 needs ethyl acetate drawn; eval 29 needs a JCAMP-DX 1H NMR file of ethanol at the path it names; eval 33 needs a PDB file with a protein chain and a benzamidine ligand (BEN) at the path it names; eval 34 needs butane drawn.",
+ "notes": "Run with the FormChem engine and window open (./formchem) and the formchem MCP server connected with the agent token, version 0.12.0. Expected behaviours are observable in the tool calls and the final answer. FormChem 0.12.0 has 77 tools: agents draw with draw_from_smiles, draw_from_molfile, draw_from_name and add_reaction, edit by id with get_atoms and the 14 edit tools, check with render, get_structure and validate, name with name_structure, predict NMR with predict_nmr and predict_spectrum, work on spectra with open_spectrum and the spectrum tools, work in 3D with build_3d, conformers_3d, minimise_3d, scan_dihedral, measure_3d, open_3d_structure, extract_ligand and export_3d, work with structure databases and the notebook with db_list, db_create, db_open, db_import, db_search, db_get_record, db_add_record, db_update_record, db_export, nb_add_entry and nb_search, keep the shared structure library with library_list, library_add and live_structure_object, draw biopolymers with draw_from_helm, run xtb and CREST (only when installed) with xtb_optimise and crest_conformers, and still reach the window's commands, reactions, analysis and extensions; several evals check that the agent draws with the tools and checks before it claims. Evals 13 and 14 need a drawn esterification scheme (acetic acid + ethanol, arrow, ethyl acetate + water); evals 15 to 18 need ibuprofen inserted with insert-smiles CC(C)Cc1ccc(cc1)[C@@H](C)C(=O)O; eval 20 needs an SD file at the path it names; eval 28 needs ethyl acetate drawn; eval 29 needs a JCAMP-DX 1H NMR file of ethanol at the path it names; eval 33 needs a PDB file with a protein chain and a benzamidine ligand (BEN) at the path it names; eval 34 needs butane drawn; evals 36 to 40 need an SD file of a few hundred structures, one of them with a broken connection table, at the path eval 36 names, and evals 37 to 40 the database eval 36 makes; eval 44 needs ethanol drawn and eval 45 butane, and both should be run once with xtb and CREST installed and once without them.",
"evals": [
{
"id": 1,
@@ -9,8 +9,8 @@
"files": [],
"expected_behavior": [
"Calls get_context first",
- "Says in plain words that an agent can make, open and save drawings, draw structures and reaction schemes from SMILES, molfiles or names, edit them atom by atom, read them back as SMILES, InChIKey, molfile or names, render and validate them, predict 1H and 13C NMR, open JCAMP-DX spectra and pick peaks, build structures in 3D with conformers, scans and measurements, open PDB files and extract ligands, convert files and run menu commands, each change one undo step",
- "Names what is not there yet: typing stoichiometry amounts, quantum or tight-binding energies (no xtb or CREST)",
+ "Says in plain words that an agent can make, open and save drawings, draw structures and reaction schemes from SMILES, molfiles or names, edit them atom by atom, read them back as SMILES, InChIKey, molfile or names, render and validate them, predict 1H and 13C NMR, open JCAMP-DX spectra and pick peaks, build structures in 3D with conformers, scans and measurements, open PDB files and extract ligands, keep structure databases (import, search, register, export) and lab notebook entries, keep the shared structure library and live structures for other Form apps, draw peptides and nucleic acids from HELM, run xtb and CREST when the person installed them, convert files and run menu commands, each change one undo step",
+ "Names what is not there yet: typing stoichiometry amounts, DFT or any quantum method beyond the person's own xtb, signing notebook entries (only the person signs)",
"Does not run any command or post a handoff for a question that only asks"
]
},
@@ -404,6 +404,125 @@
"Does not claim to see the 3D View; says the panel shows it and that render shows only a stored picture",
"Ends with a handoff naming what the person will see"
]
+ },
+ {
+ "id": 36,
+ "name": "import-sd-into-new-database",
+ "prompt": "Make a FormChem database called Screening and load /tmp/fc-evals/screen.sdf into it. Tell me if anything failed.",
+ "files": [],
+ "expected_behavior": [
+ "Calls db_list or get_context, then db_create {title: \"Screening\"} and keeps the handle it returns",
+ "Calls db_import with dry_run true before the real import, and reports the counts it gives",
+ "Runs db_import without dry_run and quotes added, updated and failed as returned",
+ "Names each failed record by its number in the file with the reason the job gives, and does not claim the import failed as a whole"
+ ]
+ },
+ {
+ "id": 37,
+ "name": "benzene-substructure-and-export",
+ "prompt": "In my Screening database in FormChem, find every compound with a benzene ring and save them to /tmp/fc-evals/benzene-hits.sdf.",
+ "files": [],
+ "expected_behavior": [
+ "Calls db_search with smiles c1ccccc1 and mode substructure (or the default mode)",
+ "Quotes the hit list id, its name and the count and time as returned, and says the hit list also shows in the person's window",
+ "Calls db_export with format sdf, that hitlist id and the absolute path, and quotes the written count, which equals the hit count",
+ "Does not page through rows with db_get_record to build the file itself"
+ ]
+ },
+ {
+ "id": 38,
+ "name": "similar-compounds-with-scores",
+ "prompt": "Which compounds in the Screening database are most like 4-methylbenzoic acid? Only ones that are really close.",
+ "files": [],
+ "expected_behavior": [
+ "Calls db_search with the SMILES of 4-methylbenzoic acid (Cc1ccc(cc1)C(=O)O or equivalent), mode similarity and a threshold of 0.7 or higher",
+ "Lists the hits with the score each row carries and names the method (Tanimoto on Morgan fingerprints) as the answer gives it",
+ "Does not invent scores or rank hits by its own judgement against the returned scores",
+ "Says how many hits there were and that a lower threshold would find more"
+ ]
+ },
+ {
+ "id": 39,
+ "name": "register-a-duplicate",
+ "prompt": "Add ethylamine hydrochloride to the Screening database in FormChem.",
+ "files": [],
+ "expected_behavior": [
+ "Calls db_add_record with smiles CCN.Cl (or equivalent) and no on_duplicate",
+ "When the answer lists duplicates (ethylamine under salt stripping), shows them and asks the person whether to use the existing record, add a new batch or register anyway",
+ "Does not call db_add_record again with on_duplicate new on its own",
+ "When nothing matched, quotes the new record's number and uid"
+ ]
+ },
+ {
+ "id": 40,
+ "name": "notebook-entry-from-reaction",
+ "prompt": "Record today's amide coupling in the Screening database notebook: benzoic acid and methylamine gave N-methylbenzamide, sample AC-001, 1.21 g, 89% yield. Then sign it.",
+ "files": [],
+ "expected_behavior": [
+ "Calls nb_add_entry with db, a title, the reaction template, reaction OC(=O)c1ccccc1.CN>>CNC(=O)c1ccccc1 (or equivalent) and a product with sample AC-001, mass_g 1.21 and yield_pct 89",
+ "Quotes the entry number, uid and the stoichiometry with its method as returned",
+ "Does not sign the entry and does not call it signed; tells the person that signing is theirs (Sign Notebook Entry... in the window)",
+ "Can find the entry afterwards with nb_search by AC-001 or by the substructure NC=O"
+ ]
+ },
+ {
+ "id": 41,
+ "name": "oxytocin-from-helm",
+ "prompt": "Draw oxytocin in FormChem from HELM, with its disulfide, and give me the formula and monoisotopic mass.",
+ "files": [],
+ "expected_behavior": [
+ "Calls draw_from_helm with PEPTIDE1{C.Y.I.Q.N.C.P.L.G.[am]}$PEPTIDE1,PEPTIDE1,1:R3-6:R3$$$V2.0 or an equivalent HELM string with the 1:R3-6:R3 connection",
+ "Quotes C43H66N12O12S2 and the monoisotopic mass (1006.436458) with the method the answer names",
+ "Checks the result with get_structure or render, or quotes the InChIKey XNOPRXBHLZRZKH-DSZYJQQASA-N from the answer",
+ "Does not draw oxytocin atom by atom or from a SMILES it wrote itself"
+ ]
+ },
+ {
+ "id": 42,
+ "name": "helm-refusal",
+ "prompt": "Draw PEPTIDE1{A.X.G}$$$$ in FormChem.",
+ "files": [],
+ "expected_behavior": [
+ "Calls draw_from_helm once and reports the refusal with the character where reading stopped and the reason (X is not a PEPTIDE monomer FormChem knows)",
+ "Does not guess what X was meant to be or retry with invented monomers; asks the person, or offers inline SMILES for a non-standard residue",
+ "Reports that nothing was drawn"
+ ]
+ },
+ {
+ "id": 43,
+ "name": "star-and-hand-to-sibling",
+ "prompt": "Put caffeine in the shared structure library as a live structure and give me the object FormDeck needs.",
+ "files": [],
+ "expected_behavior": [
+ "Calls library_add with smiles Cn1cnc2c1c(=O)n(C)c(=O)n2C (or the drawing) and kinds [\"live\"]",
+ "Quotes the item id, kinds, formula C8H10N4O2 and rev 1 from the answer",
+ "Calls live_structure_object with that id and passes the object on as returned, without editing its svg",
+ "Does not claim that FormDeck was updated or opened"
+ ]
+ },
+ {
+ "id": 44,
+ "name": "xtb-water-optimisation",
+ "prompt": "Optimise the drawn ethanol with GFN2-xTB in water and tell me the energy.",
+ "files": [],
+ "expected_behavior": [
+ "Calls xtb_optimise with method gfn2 (or default) and solvent water on the ethanol structure",
+ "Quotes the total energy in hartree and kcal/mol, the HOMO-LUMO gap and the program label with version, method and solvent, as returned",
+ "If xtb is not installed, reports the tool's answer with where to get xtb, does not retry, and does not present an MMFF94 energy as an xtb result",
+ "Does not call the energy a measured or DFT value"
+ ]
+ },
+ {
+ "id": 45,
+ "name": "crest-not-installed",
+ "prompt": "Run a CREST conformer search on the butane I drew and keep the 5 lowest.",
+ "files": [],
+ "expected_behavior": [
+ "Calls crest_conformers with keep 5 (and a time limit if it sets one)",
+ "When CREST is missing, tells the person FormChem does not include or download CREST and where to get it, as the answer says, and stops",
+ "When CREST runs, quotes the relative energies and populations with the program label and how many conformers were dropped for lost stereo",
+ "Offers conformers_3d with MMFF94 only as a clearly named alternative, after asking"
+ ]
}
],
"trigger_evals": [
@@ -473,6 +592,22 @@
{"query": "export the 3D coordinates of my formchem structure as an SDF with every conformer", "should_trigger": true},
{"query": "add a new force field to formchem's services/three_d/forcefield.py", "should_trigger": false},
{"query": "write an RDKit script that embeds and minimises conformers for a list of SMILES", "should_trigger": false},
- {"query": "render this PDB entry as a cartoon in PyMOL", "should_trigger": false}
+ {"query": "render this PDB entry as a cartoon in PyMOL", "should_trigger": false},
+ {"query": "load my SD file of 10,000 compounds into a FormChem database and tell me which records failed", "should_trigger": true},
+ {"query": "search my formchem compound database for everything containing a pyridine ring", "should_trigger": true},
+ {"query": "find analogues of this hit in the FormChem database with Tanimoto above 0.8", "should_trigger": true},
+ {"query": "is this compound already registered in my formchem database", "should_trigger": true},
+ {"query": "write up today's experiment as a notebook entry in FormChem with the yield", "should_trigger": true},
+ {"query": "add a new query term kind to formchem's services/database/query.py", "should_trigger": false},
+ {"query": "run a similarity search over ChEMBL with chemfp", "should_trigger": false},
+ {"query": "set up an electronic lab notebook in Benchling for my group", "should_trigger": false},
+ {"query": "draw this HELM peptide in formchem: PEPTIDE1{A.C.D.E}$$$$", "should_trigger": true},
+ {"query": "optimise my molecule with GFN2-xTB in DMSO using FormChem", "should_trigger": true},
+ {"query": "star this structure in formchem so FormTxt can insert it", "should_trigger": true},
+ {"query": "give me the live structure object for library item s4k2m9x0qa from FormChem", "should_trigger": true},
+ {"query": "run CREST through formchem on the drawn macrocycle and keep 10 conformers", "should_trigger": true},
+ {"query": "install xtb with conda on my laptop", "should_trigger": false},
+ {"query": "convert a HELM string to SMILES with the Pistoia HELM toolkit in Java", "should_trigger": false},
+ {"query": "add a new HELM monomer to formchem's helm_monomers.json data file", "should_trigger": false}
]
}
diff --git a/.claude/skills/formchem-harness/SKILL.md b/.claude/skills/formchem-harness/SKILL.md
index 2235c344..29ac1268 100644
--- a/.claude/skills/formchem-harness/SKILL.md
+++ b/.claude/skills/formchem-harness/SKILL.md
@@ -1,21 +1,21 @@
---
name: formchem-harness
-description: "Drives FormChem, the FormAI family's chemical structure drawing suite, through its MCP server. Use whenever the person wants an agent to work in FormChem: draw a structure or reaction from SMILES, a molfile or a chemical name, build or edit it atom by atom, check the drawing with render, get_structure or validate, name a structure, predict a 1H or 13C NMR spectrum, open a JCAMP-DX spectrum, pick peaks or integrate, build it in 3D, find conformers, minimise, scan a dihedral or measure a bond length, open a PDB file or extract a ligand, convert files, open or save drawings, run a menu command, perceive a reaction, get cLogP, hand off, or asks what FormChem can do, and FormChem is named or its tools (draw_from_smiles, draw_from_name, predict_nmr, build_3d, render, get_atoms, run_command, handoff and the rest) are available. Covers 127.0.0.1:8220, the agent token, approval and Stop. Not for changing FormChem's source (formchem-skillset), other Form apps such as FormDeck, or standalone RDKit scripts."
+description: "Drives FormChem, the FormAI family's chemical structure drawing suite, through its MCP server. Use whenever the person wants an agent to work in FormChem: draw a structure or reaction from SMILES, a molfile, a chemical name or HELM, edit it atom by atom, check it with render, get_structure or validate, predict a 1H or 13C NMR spectrum, open a JCAMP-DX spectrum, build it in 3D, find conformers, run xtb or CREST, open a PDB file or extract a ligand, search a compound database by substructure or similarity, import an SD file, register a compound, add a notebook entry, put a structure in the shared library, convert files, run a menu command, or asks what FormChem can do, and FormChem is named or its tools (draw_from_smiles, build_3d, db_search, library_add, draw_from_helm, render, run_command and the rest) are available. Covers 127.0.0.1:8220, the agent token, approval and Stop. Not for changing FormChem's source (formchem-skillset), other Form apps such as FormDeck, or standalone RDKit scripts."
license: Apache-2.0
metadata:
author: nodemode-ai
- version: "0.10.0"
+ version: "0.12.0"
---
# FormChem harness
FormChem is a chemical structure drawing suite running on this computer. Its MCP server (`formchem`) lives in the engine and reaches the FormChem window, where the person sees everything an agent does. This pack is the method for using it well: draw with the tools, check what you drew, and hand back.
-## What exists today (0.10.0)
+## What exists today (0.12.0)
-FormChem has drawings (`.fchem` documents kept by the engine with undo, autosave and versions), an RDKit chemistry service that computes SMILES, InChIKey, formula, masses, CIP labels and valence warnings after every change, and a 2D canvas the person draws on. Earlier versions added reactions and annotations (0.5.0), stereo, queries and analysis (0.6.0), formats, pictures, the clipboard, Standardise, the command line, the dark page, scaling and grids (0.7.0), the agent tools (0.8.0), and names, NMR prediction (FormChem increments) and JCAMP-DX spectra (0.9.0).
+FormChem has drawings (`.fchem` documents kept by the engine with undo, autosave and versions), an RDKit chemistry service that computes SMILES, InChIKey, formula, masses, CIP labels and valence warnings after every change, and a 2D canvas the person draws on. Earlier versions added reactions and annotations (0.5.0), stereo, queries and analysis (0.6.0), formats, pictures, the clipboard, Standardise and the command line (0.7.0), the agent tools (0.8.0), names, NMR prediction and JCAMP-DX spectra (0.9.0), 3D: builds with the stereo checked, conformers, scans, measurements, PDB and mmCIF files and ligands (0.10.0), and structure databases with the lab notebook (0.11.0).
-0.10.0 adds 3D: conformers built from the drawing with the stereo checked, conformer searches, minimisation and dihedral scans with RDKit's force fields, measurements, the 3D View and 3D objects on the page, PDB and mmCIF files with ligand extraction, and 3D exports. The MCP server has 60 tools; `references/tools.md` lists every argument and is generated from the server.
+0.12.0 adds the shared structure library every Form app reads, live structures (a picture with the drawing inside that sibling apps keep and send back for editing), HELM in and out, xtb and CREST run when the person installed them, keyboard and screen reader access, and element palettes. The MCP server has 77 tools; `references/tools.md` is generated from the server and lists all of them; the library and HELM tools are in `sub-skills/library-and-biopolymers` and the xtb tools in `sub-skills/three-d`.
| Group | Tools |
| --- | --- |
@@ -27,12 +27,15 @@ FormChem has drawings (`.fchem` documents kept by the engine with undo, autosave
| Names (0.9.0) | `draw_from_name` (a common or systematic name, read offline), `name_structure` (common and round-trip-checked systematic names) |
| NMR and spectra (0.9.0) | `predict_nmr`, `predict_spectrum`; `open_spectrum` (JCAMP-DX), `spectrum_data`, `spectrum_peaks`, `spectrum_pick_peaks`, `spectrum_integrate`, `spectrum_export` |
| 3D (0.10.0) | `build_3d`, `conformers_3d`, `minimise_3d`, `scan_dihedral`, `measure_3d`; `open_3d_structure` (PDB, mmCIF, SDF, MOL), `extract_ligand`, `export_3d` |
+| Databases and notebook (0.11.0) | `db_list`, `db_create`, `db_open`, `db_import`, `db_search`, `db_get_record`, `db_add_record`, `db_update_record`, `db_export`; `nb_add_entry`, `nb_search` |
+| Library and HELM (0.12.0) | `library_list`, `library_add`, `live_structure_object`; `draw_from_helm` |
+| xtb and CREST (0.12.0) | `xtb_optimise`, `crest_conformers` (only when the person installed the programs) |
| Window, extensions, handoff | `list_commands`, `run_command`, `extensions_list`, `extension_command`, `handoff` |
| Reactions (0.5.0) and analysis (0.6.0) | `perceive_reactions`, `map_reaction`, `export_reaction`, `reaction_stoichiometry`, `properties`, `check_structure`, `stereo`, `substructure` |
Every change an agent makes is one transaction and one undo step, labelled with the tool in the person's Edit > Undo, and every change answers with the structure it now holds (ids, SMILES, InChIKey, formula, warnings) and a PNG of it. The person sees which agent is editing in the title bar, with a Stop button, and Window > Agent Activity lists every call with undo for the latest one.
-Every name and computed number carries its method and version (FormChem names 0.9.0, FormChem increments 0.9.0, `ETKDGv3+MMFF94 (rdkit 2025.09.3)`); quote them with the value, and never present a prediction or a force-field energy as measured. What still is not there: names the offline engine refuses (hydro prefixes, spiro and bridged rings, peptides; use SMILES), a tool that links peaks to atoms (the window command does) or inserts a spectrum file into an existing drawing, typing amounts into the Stoichiometry panel, tools for 3D styles and surfaces (the window commands do), and any quantum or tight-binding method (no xtb or CREST). The export and copy commands still hand their file to the person, not to the agent; use `convert` or `get_structure` for text you can read. Never draw by other means and present it as FormChem's work.
+Every name and computed number carries its method and version (FormChem names 0.9.0, FormChem increments 0.9.0, `ETKDGv3+MMFF94 (rdkit 2025.09.3)`, similarity scores with their fingerprint, `xtb 6.7.1, GFN2-xTB, ALPB (Water)`); quote them with the value, and never present a prediction or a computed energy as measured. What still is not there: names the offline engine refuses (hydro prefixes, spiro and bridged rings; peptides go through HELM), a tool that links peaks to atoms (the window command does) or inserts a spectrum file into an existing drawing, typing amounts into the Stoichiometry panel, tools for 3D styles and surfaces (the window commands do), DFT or any quantum method beyond the person's own xtb, a tool that returns HELM text or describes a structure in words (window commands `copy-helm` and `a11y-describe` do), and database fields, saved queries, attachments or signing for agents (the window does them). The export and copy commands still hand their file to the person, not to the agent; use `convert` or `get_structure` for text you can read. Never draw by other means and present it as FormChem's work.
## Doctrine (applies to every route)
@@ -49,7 +52,7 @@ Every name and computed number carries its method and version (FormChem names 0.
```
formchem-harness/
SKILL.md this router and the doctrine
- references/tools.md the 60 MCP tools and their arguments (generated by ./formchem agents sync)
+ references/tools.md 71 of the 77 tools and their arguments (generated by ./formchem agents sync)
EVALS.json evaluation prompts and trigger tests for this pack
sub-skills/
session-and-connection/ connecting, the agent token, get_context, approval, Stop, connection errors
@@ -57,7 +60,9 @@ formchem-harness/
edit-by-id/ get_atoms and the 14 edit tools: atoms, bonds, charges, stereo, groups, arrows, text
visual-qa/ render, get_structure, validate and compute_properties to check your own work
names-and-spectra/ draw_from_name, name_structure, predict_nmr, predict_spectrum and the spectrum tools
- three-d/ build_3d, conformers, minimise, scans, measure, PDB files, ligands, 3D export and checks
+ three-d/ build_3d, conformers, minimise, scans, measure, PDB files, ligands, 3D export, xtb and CREST
+ databases/ the db_ and nb_ tools: import, search, register, export, notebook entries
+ library-and-biopolymers/ the shared structure library, live structure objects, draw_from_helm
handoff/ handoff states and notes, what the person sees, Agent Activity
window-commands/ the window's commands through run_command; references/command-catalogue.md
reactions/ reaction schemes, the four reaction tools, Set Reaction Roles
@@ -87,7 +92,12 @@ Paths inside a SUB-SKILL.md resolve against that sub-skill's own folder. `refere
| Make it 3D, its conformers or lowest-energy shape, minimise, a torsion scan, a bond length or angle in 3D, does the 3D keep the stereo | `three-d`, then `visual-qa` |
| Open this PDB or mmCIF file, pull out the ligand, save 3D coordinates as SDF, PDB or XYZ | `three-d` |
| Show it in 3D, ball and stick, a surface, ESP, a 3D picture or glTF for the person | `three-d`, then `window-commands` |
-| Type amounts into the Stoichiometry panel, xtb or quantum energies | Not yet: say so, or ask the person |
+| Load an SD or CSV file into a database, search compounds by substructure or similarity, is it already registered, export the hits | `databases` |
+| Register this compound, add a batch, update a record's values, record this experiment in the notebook, find my amide couplings | `databases` |
+| A GFN2-xTB or GFN-FF energy, optimise with xtb in water, a CREST conformer ensemble | `three-d` |
+| Star this, save it as a template, put it into FormDeck or FormTxt as a live structure, list the structure library, the object for a sibling app | `library-and-biopolymers` |
+| Draw oxytocin or a peptide from HELM, an RNA strand, a disulfide or head-to-tail cyclic peptide | `library-and-biopolymers`, then `visual-qa` |
+| Type amounts into the Stoichiometry panel, DFT energies, sign a notebook entry, add a database field | Not yet for agents: say so, or ask the person |
| Change FormChem's own code, add an MCP tool, edit this pack | Not this pack: `formchem-skillset` |
## When something fails
@@ -115,6 +125,15 @@ Paths inside a SUB-SKILL.md resolve against that sub-skill's own folder. `refere
| "No 3D coordinates yet" or "has no conformer" | The structure was never built, or an edit dropped its conformers | `build_3d`, then retry |
| "The structure changed while 3D was being computed" (409) | Someone edited the structure during the build | Retry once; if it repeats, the person is editing: ask them |
| `extract_ligand` refuses, or answers "inferred from the geometry" | The object is not a PDB or mmCIF model; or the ligand is outside the template table | Pass the model's `o...` id from `open_3d_structure`; say the bond orders were inferred and show the SMILES |
+| "No database is open" or "Several databases are open" | No handle given | `db_list`, then `db_open {path}` or pass `db` |
+| `db_add_record` error listing duplicates | The structure is there by the database's stereo and salts rules | Show the matches; call again with the `on_duplicate` the person chooses |
+| "open read-only" or 423 on a write | Another FormChem or `./formchem db` holds the file | Report the reason; read and search only |
+| `failed` records in a `db_import` job | Bad records were skipped, the rest imported | Pass on each record number and reason |
+| xtb or CREST "was not found" from `xtb_optimise` or `crest_conformers` | The person has not installed it, or its path is wrong; FormChem never ships it | Tell the person where to get it (the answer says); do not retry |
+| "unpaired electrons" or parity refusal from an xtb tool | Charge and `uhf` cannot match the electron count | Fix `charge` or `uhf` once from the structure, or ask |
+| An xtb job "timeout" or "failed" with the last lines | The time limit stopped it, or the program failed | Pass on the last lines; offer a larger `limit` or GFN-FF |
+| `draw_from_helm` refused "at character N" | Unknown monomer, mixture, BLOB or a typo | Fix an obvious typo once; else inline SMILES for the monomer, or report |
+| "has no item" from a library tool | Wrong id, or the item was deleted | `library_list`, then use an id it returns |
| `renderer: "engine"` in a picture | No window answered; the engine drew the structures only | Fine for checking structures; say arrows and text were not drawn, or ask the person to open the window |
When a call keeps failing in a way this table does not explain, call the same tool once with the simplest arguments (`get_context`, then `draw_from_smiles {smiles: "C"}`). If that fails too, the problem is the server or the connection, not the plan: report it to the person with the error text.
@@ -125,6 +144,8 @@ When a call keeps failing in a way this table does not explain, call the same to
- Every structure the agent drew was checked: the write result's SMILES or InChIKey matched what was asked, and anything about how it looks was confirmed with `render`.
- Nothing was claimed that a tool did not say; values were quoted from tool answers, names, predicted shifts, energies and 3D measurements with their method and version.
- Every 3D geometry used was from a build whose stereo line said every label was kept.
+- Database counts, hit list ids and scores were quoted from the answers, no duplicate was registered as new without the person's choice, and no notebook entry was called signed.
+- Every xtb or CREST number came with its program label, and library items and live objects were passed on by id and rev exactly as returned.
- Every change was one call and one undo step, and none was retried after a refusal or a stop.
- The work ends with a `handoff` (`ready` with a note, or `question` with the question).
diff --git a/.claude/skills/formchem-harness/references/tools.md b/.claude/skills/formchem-harness/references/tools.md
index ddf0065c..23466773 100644
--- a/.claude/skills/formchem-harness/references/tools.md
+++ b/.claude/skills/formchem-harness/references/tools.md
@@ -1,6 +1,6 @@
# FormChem MCP tools
-Generated by `./formchem agents sync` from the TOOLS list in `backend/app/routers/mcp.py`; edit the server, never this file. 60 tools. Names and arguments are case sensitive. A tool answers with text first, then `structuredContent` where it sends it; a tool that cannot act answers with `isError: true` and a sentence naming the next step.
+Generated by `./formchem agents sync` from the TOOLS list in `backend/app/routers/mcp.py` and the agent modules in its AGENT_MODULES; edit the server, never this file. 77 tools. Names and arguments are case sensitive. A tool answers with text first, then `structuredContent` where it sends it; a tool that cannot act answers with `isError: true` and a sentence naming the next step.
Read-only tools never ask the person. An approval-gated tool asks the person in the FormChem window the first time (Deny, Allow once, Always allow); agents started in FormChem's own Claude Code, Codex, Cursor or Antigravity tabs are never asked.
@@ -67,6 +67,23 @@ Read-only tools never ask the person. An approval-gated tool asks the person in
- open_3d_structure
- extract_ligand
- export_3d
+- db_list
+- db_create
+- db_open
+- db_import
+- db_search
+- db_get_record
+- db_add_record
+- db_update_record
+- db_export
+- nb_add_entry
+- nb_search
+- library_list
+- library_add
+- live_structure_object
+- draw_from_helm
+- xtb_optimise
+- crest_conformers
- Resource
| Tool | Kind |
@@ -131,6 +148,23 @@ Read-only tools never ask the person. An approval-gated tool asks the person in
| `open_3d_structure` | approval-gated |
| `extract_ligand` | approval-gated |
| `export_3d` | approval-gated when it changes something |
+| `db_list` | read-only |
+| `db_create` | approval-gated when it changes something |
+| `db_open` | approval-gated when it changes something |
+| `db_import` | approval-gated when it changes something |
+| `db_search` | read-only |
+| `db_get_record` | read-only |
+| `db_add_record` | approval-gated when it changes something |
+| `db_update_record` | approval-gated when it changes something |
+| `db_export` | approval-gated when it changes something |
+| `nb_add_entry` | approval-gated when it changes something |
+| `nb_search` | read-only |
+| `library_list` | read-only |
+| `library_add` | approval-gated when it changes something |
+| `live_structure_object` | read-only |
+| `draw_from_helm` | approval-gated when it changes something |
+| `xtb_optimise` | approval-gated when it changes something |
+| `crest_conformers` | approval-gated when it changes something |
## get_context
@@ -791,6 +825,213 @@ Writes the 3D coordinates of a structure with every hydrogen as MOL (the shown c
| `conformer` | string | no | Conformer id, or all; default all for sdf, else the shown one |
| `output` | string | no | Absolute path of a new file to write; left out, the text comes back |
+## db_list
+
+The structure databases open in FormChem (handle, title, path, record count, read-only or not, fields) and the databases FormChem knows from earlier (path, name, count, whether the file still exists). Open one with db_open, make one with db_create.
+
+Arguments: none.
+
+## db_create
+
+Makes a new FormChem structure database (.fcdb, one SQLite file) and opens it. Without path it goes to the Databases folder of FormChem's data folder. Answers with its handle and info.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `title` | string | yes | |
+| `path` | string | no | Absolute path of the new .fcdb file (optional) |
+
+## db_open
+
+Opens a FormChem database file (.fcdb) and answers with its handle, title, record count, fields and whether it opened read-only (it does when another FormChem holds it).
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `path` | string | yes | Absolute path of the .fcdb file |
+
+## db_import
+
+Imports structures from an SD, RD, SMILES, CSV or TSV (SMILES or InChI column) or .fchem file into a database as a job, and waits up to wait seconds (default 60) for it. Bad records never stop the import: the answer lists each failed record number and reason. dry_run counts what would be added, updated and failed without writing. mode new or append adds every good record; merge updates records that match on key (structure, or a field name) and adds the rest.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `path` | string | yes | Absolute path of the file to import |
+| `format` | sdf or rdf or smiles or csv or tsv or fchem | no | |
+| `mode` | new or append or merge | no | |
+| `key` | string | no | Merge key: structure (default) or a field name |
+| `mapping` | object | no | Source column or SD tag to field name, "" to skip, or "+Label" to make a new field; left out, the detected mapping is used |
+| `dry_run` | boolean | no | |
+| `wait` | number | no | Seconds to wait for the job (0 to 600, default 60); a job still running is reported with its id |
+
+## db_search
+
+Searches a database and answers with the hit list (id, name, count, took_ms, methods) and its first rows (uid, number, SMILES, formula, mw, field values, and score for similarity). Give smiles with mode (substructure, the default, similarity with threshold 0 to 1, or exact), or a full query node. within limits the search to an earlier hit list. Every search becomes a hit list the person sees in the window.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `smiles` | string | no | Structure to search with (or a SMARTS with mode substructure and smarts true) |
+| `smarts` | boolean | no | Read smiles as SMARTS (substructure only) |
+| `mode` | substructure or similarity or exact | no | |
+| `threshold` | number | no | Similarity threshold, 0 to 1 (default 0.7) |
+| `query` | object | no | A query node of docs/DATABASE.md: a term {kind, ...} with kind exact, substructure, similarity, formula, mass, text, number, date, choice, empty or hitlist, or a group {op: and | or | not, terms: [...]} |
+| `within` | integer | no | Hit list id to search within |
+| `name` | string | no | Name for the hit list |
+| `limit` | integer | no | Rows to return (default 20, at most 100); the hit list holds them all |
+
+## db_get_record
+
+One record of a database by uid: number, batch, SMILES, InChIKey, formula, masses, molfile, field values and attachments.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `uid` | string | yes | Record uid (c plus 10 characters) |
+
+## db_add_record
+
+Registers a structure in a database with optional field values. When the structure is already there (by the database's duplicate rules) and on_duplicate is not given, nothing is added and the answer lists the duplicates: call again with on_duplicate existing (use the existing record), batch (a new batch of it) or new (register anyway).
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `smiles` | string | no | |
+| `molfile` | string | no | |
+| `values` | object | no | Field values by field name (see the fields of db_list or db_open), for example {"mp": 121.5, "supplier": "Acme"} |
+| `on_duplicate` | ask or existing or batch or new | no | |
+
+## db_update_record
+
+Changes a record's structure, field values or both; computed fields follow the new structure.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `uid` | string | yes | Record uid |
+| `smiles` | string | no | |
+| `molfile` | string | no | |
+| `values` | object | no | Field values by field name (see the fields of db_list or db_open), for example {"mp": 121.5, "supplier": "Acme"} |
+
+## db_export
+
+Writes records to an SD file (V2000, or V3000 when asked; every scalar field as a data item), a SMILES file or CSV: a hit list, a list of uids or the whole database. Without path the file goes to FormChem's export folder and the answer gives its path.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | no | Database handle (g plus 8 characters) from db_list, db_create or db_open; may be left out when one database is open |
+| `format` | sdf or smiles or csv | yes | |
+| `path` | string | no | Absolute path of the file to write (optional) |
+| `hitlist` | integer | no | |
+| `uids` | array of string | no | |
+| `fields` | array of string | no | Field names to include (default all) |
+| `v3000` | boolean | no | |
+| `structure_as` | smiles or inchi | no | Structure column of a CSV |
+
+## nb_add_entry
+
+Add a lab notebook entry to an open FormChem database. Give a title and, as known, the template (blank, reaction, analysis, purification), the experiment date (YYYY-MM-DD), author, procedure and observations in the notebook's plain markup (paragraphs separated by blank lines, '- ' bullets, **bold**, *italic*), tags, products, and the scheme as reaction SMILES or RXN text (reaction) or an open drawing id (doc). Answers the new entry's number and uid, its content hash and the stoichiometry computed from the scheme. The entry is open (not signed): only a person signs.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | yes | Database handle (g plus 8 characters) from db_list, db_create or db_open |
+| `title` | string | yes | |
+| `template` | blank or reaction or analysis or purification | no | |
+| `date` | string | no | Experiment date YYYY-MM-DD (default today) |
+| `author` | string | no | |
+| `procedure` | string | no | Replaces the template's headings when given |
+| `observations` | string | no | |
+| `tags` | array of string | no | |
+| `products` | array of object | no | |
+| `reaction` | string | no | Reaction SMILES (A.B>>C) or RXN text for the scheme |
+| `doc` | string | no | Open drawing id whose first page becomes the scheme, instead of reaction |
+
+## nb_search
+
+Search the lab notebook entries of an open FormChem database by text (title, procedure, observations, tags, sample ids; every word must appear) and by substructure (SMILES or SMARTS matched by RDKit against every structure in each entry's scheme). Give either or both; with neither, lists the newest entries. Answers the total and up to 20 rows (number, uid, title, date, status, tags), newest first.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `db` | string | yes | Database handle (g plus 8 characters) from db_list, db_create or db_open |
+| `query` | string | no | Words to find |
+| `substructure` | string | no | SMILES or SMARTS |
+| `limit` | integer | no | Rows to return (default 20) |
+
+## library_list
+
+The shared structure library that every Form app reads (FORMCHEM_DATA_DIR/Library): items with id, name, kinds (favourite, recent, template, live), SMILES, InChIKey, formula, average mass, rev and file paths. Filter by kind.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `kind` | favourite or recent or template or live | no | Only items of this kind |
+
+## library_add
+
+Add a structure to the shared structure library as a favourite, template, recent or live item. Give a drawing (doc, optionally object ids) or a SMILES. Pictures are drawn by the engine with the FormChem drawing embedded. A structure already in the library gets the new kind instead of a copy (live items are always new).
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `doc` | string | no | Drawing id from list_open_documents; left out with smiles, or when one drawing is open |
+| `ids` | array of string | no | Object ids on the drawing's page to keep; default the whole first page |
+| `smiles` | string | no | A SMILES to add instead of a drawing |
+| `name` | string | no | |
+| `kinds` | array of string | no | Default ["favourite"] |
+
+## live_structure_object
+
+The live structure object for a library item, the JSON a sibling Form app stores in its document (format formai-structure): id, rev, name, SMILES, InChIKey, the SVG picture with the FormChem drawing inside, the molfile and the size in points.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `id` | string | yes | Library item id (s and 10 letters or digits) |
+
+## draw_from_helm
+
+Draws a peptide, nucleic acid or linker written in HELM version 2 notation in a drawing, as atoms, with FormChem's scored 2D layout, placed in free space as one undo step. Reads simple polymers such as PEPTIDE1{A.G.C}, RNA1{R(A)P.R(U)} and CHEM1{[[*:1]CCO[*:2]]}, connections such as PEPTIDE1,PEPTIDE1,1:R3-6:R3 (disulfides, cyclisation) and empty group and annotation sections, against FormChem's own monomer data: the 20 amino acids and their D forms ([dA] and so on), [Aib], [Nle], [Orn], [Sar], [Hyp], [pE], the caps [ac] and [am], the sugars R and [dR], phosphate P and the bases A, C, G, U and T. With no drawing open it makes one. Returns the new ids, SMILES, InChIKey, formula, average and monoisotopic mass with their method and version, and a picture; text it cannot read is refused with the character where reading stopped.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `helm` | string | yes | HELM text, such as PEPTIDE1{C.Y.I.Q.N.C.P.L.G.[am]}$PEPTIDE1,PEPTIDE1,1:R3-6:R3$$$V2.0 |
+| `doc` | string | no | Drawing id from list_open_documents; may be left out when one drawing is open or the window shows one |
+| `x` | number | no | Left edge in points; left out: free space |
+| `y` | number | no | Top edge in points; left out: free space |
+| `name` | string | no | Name given to the new structure; left out, the HELM text (shortened) is used |
+
+## xtb_optimise
+
+Optimises the shown conformer of a structure with the xtb program (GFN2-xTB or GFN-FF, optional ALPB implicit solvent), or with single_point computes the energy without moving atoms, then stores the result as the structure's conformers as one undo step. A structure without 3D coordinates is built first (ETKDGv3+MMFF94). Answers with the total energy in hartree and kcal/mol, the HOMO-LUMO gap, whether the optimisation converged, and the program, version, method and solvent. Waits until xtb finishes or the time limit stops it. xtb and CREST are LGPL programs FormChem does not include or download: they run only when the person has installed them (on PATH or at the path set in Preferences > 3D); otherwise the tool says where to get them.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `doc` | string | no | Drawing id from list_open_documents; may be left out when one drawing is open or the window shows one |
+| `object` | string | no | Fragment id (or a 3D object bound to one); may be left out when the drawing has one structure |
+| `method` | gfn2 or gfnff | no | gfn2 (GFN2-xTB, default) or gfnff (GFN-FF force field) |
+| `charge` | integer | no | Total charge; default the sum of the drawn formal charges |
+| `uhf` | integer | no | Unpaired electrons; default the drawn radicals |
+| `solvent` | none or acetone or acetonitrile or aniline or benzaldehyde or benzene or ch2cl2 or chcl3 or cs2 or dioxane or dmf or dmso or ether or ethylacetate or furane or hexandecane or hexane or methanol or nitromethane or octanol or woctanol or phenol or toluene or thf or water | no | Implicit solvent (ALPB); default none, the gas phase |
+| `single_point` | boolean | no | Energy only, no optimisation (default false) |
+| `scope` | shown or all | no | The shown conformer (default for optimisation) or every stored conformer (default for single_point) |
+| `level` | crude or sloppy or loose or lax or normal or tight or vtight or extreme | no | Optimisation convergence level (default normal) |
+| `conformer` | string | no | Conformer id (c...) to start from; default the shown one |
+| `threads` | integer | no | Threads; default the Preferences setting |
+| `limit` | number | no | Time limit in seconds (default 600 for xtb, 3600 for CREST, at most 604800) |
+
+## crest_conformers
+
+Searches conformers of a structure with the CREST program (metadynamics with GFN2-xTB or GFN-FF, optional ALPB solvent) and replaces the structure's conformers with the ensemble within ewin kcal/mol, at most keep, as one undo step; the lowest becomes the shown one. Answers with relative energies and Boltzmann populations at 298.15 K, and the program, version, method and solvent. CREST can take minutes to hours; the tool waits until it finishes or the time limit stops it. xtb and CREST are LGPL programs FormChem does not include or download: they run only when the person has installed them (on PATH or at the path set in Preferences > 3D); otherwise the tool says where to get them.
+
+| Argument | Type | Required | Notes |
+| --- | --- | --- | --- |
+| `doc` | string | no | Drawing id from list_open_documents; may be left out when one drawing is open or the window shows one |
+| `object` | string | no | Fragment id (or a 3D object bound to one); may be left out when the drawing has one structure |
+| `method` | gfn2 or gfnff | no | gfn2 (GFN2-xTB, default) or gfnff (GFN-FF force field) |
+| `charge` | integer | no | Total charge; default the sum of the drawn formal charges |
+| `uhf` | integer | no | Unpaired electrons; default the drawn radicals |
+| `solvent` | none or acetone or acetonitrile or aniline or benzaldehyde or benzene or ch2cl2 or chcl3 or cs2 or dioxane or dmf or dmso or ether or ethylacetate or furane or hexandecane or hexane or methanol or nitromethane or octanol or woctanol or phenol or toluene or thf or water | no | Implicit solvent (ALPB); default none, the gas phase |
+| `ewin` | number | no | Energy window in kcal/mol (default 6) |
+| `keep` | integer | no | Most conformers kept, 1 to 200 (default 20) |
+| `threads` | integer | no | Threads; default the Preferences setting |
+| `limit` | number | no | Time limit in seconds (default 600 for xtb, 3600 for CREST, at most 604800) |
+
## Resource
`formchem://guide` (text/markdown): what exists in this version, the tools, asking the person and errors.
diff --git a/.claude/skills/formchem-harness/sub-skills/databases/SUB-SKILL.md b/.claude/skills/formchem-harness/sub-skills/databases/SUB-SKILL.md
new file mode 100644
index 00000000..95a0093d
--- /dev/null
+++ b/.claude/skills/formchem-harness/sub-skills/databases/SUB-SKILL.md
@@ -0,0 +1,71 @@
+---
+name: databases
+description: "Uses FormChem's 0.11.0 structure database and lab notebook tools: db_list, db_create, db_open (.fcdb files), db_import (SD, RD, SMILES, CSV, TSV, .fchem as a job with a failed-record report and dry runs), db_search (substructure, similarity with Tanimoto scores, exact match, formula ranges or a full query node, as a hit list the person sees), db_get_record, db_add_record (duplicate rules and on_duplicate), db_update_record, db_export (SD, SMILES, CSV), nb_add_entry (an unsigned entry with scheme and stoichiometry) and nb_search. Use when the person asks an agent to register compounds, load an SD file into a database, search a compound collection, find analogues or duplicates, export hits, or record an experiment in FormChem's notebook."
+---
+
+# Databases
+
+## Purpose
+
+Register, search, import and export compounds in FormChem structure databases, and keep lab notebook entries in them, so the person sees every hit list and entry in their window. Hands back the database handle, the counts and hit list ids as returned, the record and entry uids, and every refusal or failed record with its reason.
+
+## Preconditions
+
+`get_context` has been called (`session-and-connection`). `db_list`, `db_search`, `db_get_record` and `nb_search` never ask. `db_create`, `db_open`, `db_add_record`, `db_update_record` and `nb_add_entry` ask the person the first time; `db_import` unless `dry_run`; `db_export` only with a `path` outside the temporary folder. These tools are not in `references/tools.md` (its generator reads only the drawing tools); their arguments are here and in `docs/AGENTS.md`.
+
+## How a database is held
+
+A database is one `.fcdb` file. Opening it gives a handle `db` (`g` plus 8 characters); with exactly one database open the `db_` tools may leave `db` out, the `nb_` tools always need it. Records have a `uid` (`c` plus 10) that never changes and a registration `number` with a `batch`; entries have a `uid` (`n` plus 10) and a `number`. A database held by another FormChem or by `./formchem db` opens read-only: reads work, every write is refused with the reason. Every write is logged as `agent:[your name]` and shows in Agent Activity.
+
+## Workflow 1: find or make the database
+
+1. **Call `db_list`.** It gives the open databases (handle, title, count, fields, read-only) and the known ones (path, whether the file exists).
+2. **Open or create:** `db_open {path}` with an absolute `.fcdb` path, or `db_create {title, path?}` (default the Databases folder of the data folder). Read the duplicate rules (`stereo` match or ignore, `salts` strip or keep) and the fields from the answer; they decide what counts as a duplicate and which `values` keys exist.
+
+## Workflow 2: import
+
+1. **Dry run first:** `db_import {path, dry_run: true}` counts what would be added, updated and failed without writing and without asking.
+2. **Import:** the same call without `dry_run`. `mode` is `new` (default) or `append`; `merge` with `key` (`structure`, or a field name) updates matching records and adds the rest. `mapping` left out uses the detected one (SD tags and CSV columns to fields by name, new fields for the rest).
+3. **Read the report.** `added`, `updated`, `failed`, and each failed record's number in the file and reason (the first 10 in the text). A bad record never stops an import; pass the failures on. A job still running after `wait` seconds (default 60) is reported with its id; the person sees its progress.
+
+## Workflow 3: search
+
+| Goal | Call |
+| --- | --- |
+| Contains a ring or group | `db_search {smiles, mode: "substructure"}`, or `smiles` as SMARTS with `smarts: true` |
+| Analogues | `db_search {smiles, mode: "similarity", threshold: 0.7}`: Tanimoto on Morgan bits (radius 2, 2048); every row has a `score` |
+| Is it already registered | `db_search {smiles, mode: "exact"}` (the database's stereo and salts rules) |
+| Formula, mass, fields, combinations | `db_search {query}` with a node of `docs/DATABASE.md`: `{"op": "and", "terms": [{"kind": "formula", "formula": "C6-8N1"}, {"kind": "number", "field": "mw", "cmp": "<=", "value": 300}]}` |
+| Narrow earlier hits | add `within: [hit list id]` |
+
+The answer gives the hit list `id`, `name`, `count`, `took_ms`, the methods with the RDKit version, and the first `limit` rows (default 20, at most 100). The hit list appears in the person's window; `db_export {hitlist}` writes all of it. Raising a similarity threshold never adds hits; quote scores as given. `db_get_record {uid}` gives one record with its molfile.
+
+## Workflow 4: register and update
+
+1. **Call `db_add_record {smiles or molfile, values?}`.** When the structure is already there by the rules, nothing is added and the error lists the duplicates (`structuredContent.duplicates`).
+2. **Choose, or ask the person:** call again with `on_duplicate: "existing"` (use that record), `"batch"` (a new batch, same number) or `"new"` (a new number). Never pick `new` just to make the call succeed.
+3. **Update:** `db_update_record {uid, smiles?, values?}`; computed fields follow the structure. `values` keys are field names from `db_open`, not labels.
+
+## Workflow 5: the notebook
+
+- **`nb_add_entry {db, title, template?, date?, author?, procedure?, observations?, tags?, products?, reaction? or doc?}`**: `reaction` is reaction SMILES (`A.B>>C`) or RXN; `doc` takes the first page of an open drawing as the scheme. Text uses the notebook markup (blank-line paragraphs, `- ` bullets, `**bold**`, `*italic*`). Products may link a record by `compound` uid with `sample`, `mass_g`, `yield_pct`, `purity_pct`; an unknown uid refuses the whole call and nothing is written. The answer gives the entry number and uid, its hash and the stoichiometry with its method.
+- **`nb_search {db, query?, substructure?}`**: every word must appear in title, procedure, observations, tags or sample ids; `substructure` (SMILES or SMARTS) matches the structures in each scheme. Newest first.
+- Entries from agents stay open. Only the person signs; never say an entry is signed or approved.
+
+## Rules
+
+- **Counts and scores are quoted, not estimated.** Hit counts, times, scores and import counts come from the answers, with the method where given.
+- **The person owns duplicates and signatures.** Ask before registering a duplicate as new; never claim an entry is signed.
+- **Read-only is an answer.** A refused write on a read-only database is reported with its reason, not retried.
+- **Dry run before a large import or merge,** and report the failed records.
+
+## Gate
+
+- [ ] The database handle and its rules were read before any write.
+- [ ] Every import reported added, updated and failed, with the failed records' numbers and reasons.
+- [ ] Every search result quoted the hit list id, the count and, for similarity, the scores.
+- [ ] No duplicate was registered as new without the person's choice, and no entry was described as signed.
+
+## Hands back
+
+The database handle and path; hit list ids with counts; record and entry uids and numbers; import and export counts and paths; every refusal and failed record as returned.
diff --git a/.claude/skills/formchem-harness/sub-skills/library-and-biopolymers/SUB-SKILL.md b/.claude/skills/formchem-harness/sub-skills/library-and-biopolymers/SUB-SKILL.md
new file mode 100644
index 00000000..d65e3323
--- /dev/null
+++ b/.claude/skills/formchem-harness/sub-skills/library-and-biopolymers/SUB-SKILL.md
@@ -0,0 +1,56 @@
+---
+name: library-and-biopolymers
+description: "Uses FormChem's 0.12.0 shared structure library and HELM tools: library_list (favourites, recent, templates and live items every Form app reads), library_add (a drawing or SMILES as a favourite, template, recent or live item with pictures that keep the drawing inside), live_structure_object (the formai-structure JSON a sibling app stores) and draw_from_helm (peptides, nucleic acids and linkers from HELM 2 as atoms, one undo step, with formula and masses). Use when the person asks an agent to star or save a structure for the other Form apps, put a structure into FormDeck, FormTxt or form.md as a live structure, list the structure library, hand a sibling app its object, or draw oxytocin, a cyclic peptide, a disulfide-bridged peptide or an RNA or DNA strand from HELM in FormChem."
+---
+
+# Library and biopolymers
+
+## Purpose
+
+Keep structures in the shared structure library that every Form app reads, hand sibling apps the live structure object, and draw biopolymers written in HELM, so the person sees each structure in their window and in the library. Hands back library item ids with their kinds and revisions, the object's id and rev, and for HELM the new fragment ids with formula, masses and their method.
+
+## Preconditions
+
+`get_context` has been called (`session-and-connection`). `library_list` and `live_structure_object` never ask; `library_add` and `draw_from_helm` ask the person the first time. These tools are not in the pack root's `references/tools.md` at 0.12.0 (its generator cannot read their modules yet); their arguments are here and in `docs/AGENTS.md`.
+
+## How the library is held
+
+The library is plain files in the data folder: `Library/library.json` and, per item, an SVG and a 512 pixel PNG (both with the FormChem drawing inside) and a molfile. Items have an `id` (`s` plus 10 lower-case letters or digits) that is never reused, `kinds` (any of `favourite`, `recent`, `template`, `live`), a `rev` that rises on every change, and SMILES, InChIKey, formula and average mass with the method that computed them. An item with no kinds left is deleted. Sibling apps read the folder without FormChem running; only FormChem writes it. The contract is `docs/LIVE_STRUCTURES.md` in the FormChem repository.
+
+## Workflow 1: add to the library
+
+1. **Call `library_add`** with `smiles` (no drawing needed), or with `doc` and optionally `ids` (objects of the drawing's page; default the whole first page). `doc` may be left out only when exactly one drawing is open. `kinds` defaults to `["favourite"]`; `name` names the item.
+2. **Read the answer.** It names the item id, kinds, formula, average mass with its method, and rev. A non-live structure already in the library gains the kind instead of becoming a second item; a `live` add is always a new item, so two sibling documents never share an id.
+3. **Pictures** come from the engine (RDKit) with the drawing embedded when an agent adds the item; items the person adds in the window carry the window's own pictures. Either way the drawing inside is complete.
+
+## Workflow 2: list and hand out
+
+- `library_list {kind?}` lists items (the text shows the first 40) with the folder path.
+- `live_structure_object {id}` returns the JSON a sibling app keeps in its document: `format` `formai-structure`, `format_version` 1, `id`, `rev`, `app`, `name`, `kind`, `smiles`, `inchikey`, `svg` (the picture, drawing inside), `molfile`, `width` and `height` in points. Give it to a sibling app as returned; never edit the SVG, because the drawing inside it is what makes the structure editable again.
+- Opening an item for editing is the person's, a sibling's or `./formchem edit-live ID`'s act; from an agent, `run_command {id: "open-live-structure", params: {id, from}}` asks the window to do it. Saving that drawing (the person's Save) raises the item's rev.
+
+## Workflow 3: draw from HELM
+
+1. **Call `draw_from_helm {helm, doc?, x?, y?, name?}`** with HELM version 2 text: `PEPTIDE1{G.G}$$$$`, `RNA1{R(A)P.R(U)}$$$$`, or with connections `PEPTIDE1{C.Y.I.Q.N.C.P.L.G.[am]}$PEPTIDE1,PEPTIDE1,1:R3-6:R3$$$V2.0` (oxytocin). With no drawing open it makes one. One undo step ("Draw from HELM").
+2. **Know the monomers.** FormChem's own 55: the 20 amino acids (one letter), their D forms `[dA]` and so on (no `[dG]`), `[Aib]`, `[Nle]`, `[Orn]`, `[Sar]`, `[Hyp]`, `[pE]`, caps `[ac]` (R2 only) and `[am]` (R1 only); RNA sugars `R` and `[dR]`, phosphate `P`, bases `A`, `C`, `G`, `U`, `T`. R3 sits on C, K, D, E and Orn side chains, for disulfide and lactam bridges. Anything else goes in as inline SMILES with numbered attachment points (`[[*:1]CCO[*:2]]`).
+3. **Read the answer.** New ids, SMILES, InChIKey, formula, average and monoisotopic mass with the reader, monomer data version and RDKit version. Check it like any structure (`visual-qa`).
+4. **A refusal names the character** where reading stopped (counted from 1) and why: "X is not a PEPTIDE monomer FormChem knows", mixtures in parentheses, BLOBs, repeat ranges, hydrogen-bond pairs, `?` attachment points. Fix an obvious typo once; otherwise report it.
+
+To turn a drawn peptide or nucleic acid back into HELM, use `run_command {id: "copy-helm"}` with it selected: FormChem copies HELM only when it reads back to the same InChIKey, and otherwise says which piece it could not match. There is no agent tool that returns HELM text.
+
+## Rules
+
+- **The drawing inside is the structure.** Never pass a sibling a picture without its embedded drawing, or an object with a hand-edited SVG.
+- **Revisions only go up.** A lower or equal rev never overwrites the library; do not try to roll an item back by sending an old object.
+- **Monomers are FormChem's.** Do not claim a monomer FormChem does not list; use inline SMILES and say so.
+- **Methods travel with the numbers.** Quote masses with the method the answer names.
+
+## Gate
+
+- [ ] Every library item named by id with its kinds and rev as returned.
+- [ ] Every HELM drawing checked with its InChIKey or formula from the answer, and every refusal reported with its character and reason.
+- [ ] No object or picture was altered on the way to a sibling app.
+
+## Hands back
+
+Library item ids, kinds and revs; live structure objects as returned; HELM fragment ids, formula, masses and methods; refusals with their reasons.
diff --git a/.claude/skills/formchem-harness/sub-skills/session-and-connection/SUB-SKILL.md b/.claude/skills/formchem-harness/sub-skills/session-and-connection/SUB-SKILL.md
index 9c8d91bd..0836ac92 100644
--- a/.claude/skills/formchem-harness/sub-skills/session-and-connection/SUB-SKILL.md
+++ b/.claude/skills/formchem-harness/sub-skills/session-and-connection/SUB-SKILL.md
@@ -52,5 +52,5 @@ Agents started from FormChem's own Claude Code, Codex, Cursor or Antigravity tab
## Gate
- [ ] `get_context` was the first call.
-- [ ] The plan uses only the 60 tools in the pack root's `references/tools.md` and the commands and extensions they report.
+- [ ] The plan uses only the 77 tools (the 71 in the pack root's `references/tools.md`, the library and HELM tools in `library-and-biopolymers` and the xtb tools in `three-d`) and the commands and extensions they report.
- [ ] No change was attempted after a refusal or a stop, and the agent token never appeared in a reply or a note.
diff --git a/.claude/skills/formchem-harness/sub-skills/three-d/SUB-SKILL.md b/.claude/skills/formchem-harness/sub-skills/three-d/SUB-SKILL.md
index 01f82aa8..cb82ea98 100644
--- a/.claude/skills/formchem-harness/sub-skills/three-d/SUB-SKILL.md
+++ b/.claude/skills/formchem-harness/sub-skills/three-d/SUB-SKILL.md
@@ -1,6 +1,6 @@
---
name: three-d
-description: "Uses FormChem's 0.10.0 3D tools: build_3d (a conformer from the 2D drawing with ETKDGv3 and MMFF94, MMFF94s or UFF, with the stereo check), conformers_3d (an ensemble in an energy window with populations), minimise_3d, scan_dihedral (a relaxed scan with its barrier), measure_3d (distance, angle, dihedral), open_3d_structure (PDB, mmCIF, SDF, MOL), extract_ligand and export_3d (MOL, SDF, PDB, XYZ), plus the 3D window commands for styles, surfaces and PNG or glTF. Use when the person asks an agent to make a structure 3D, find its conformers or lowest-energy shape, minimise it, scan a torsion, measure a bond length or angle, open a PDB or mmCIF file, pull a ligand out of a protein, or save 3D coordinates in FormChem, and to check that a 3D geometry kept the drawn stereo."
+description: "Uses FormChem's 0.10.0 3D tools: build_3d (a conformer from the 2D drawing with ETKDGv3 and MMFF94, MMFF94s or UFF, with the stereo check), conformers_3d (an ensemble in an energy window with populations), minimise_3d, scan_dihedral (a relaxed scan with its barrier), measure_3d (distance, angle, dihedral), open_3d_structure (PDB, mmCIF, SDF, MOL), extract_ligand and export_3d (MOL, SDF, PDB, XYZ), the 0.12.0 xtb_optimise and crest_conformers (xtb and CREST when the person installed them), plus the 3D window commands for styles, surfaces and PNG or glTF. Use when the person asks an agent to make a structure 3D, find its conformers or lowest-energy shape, minimise it, scan a torsion, measure a bond length or angle, open a PDB or mmCIF file, pull a ligand out of a protein, get a GFN2-xTB energy or a CREST ensemble, or save 3D coordinates in FormChem, and to check that a 3D geometry kept the drawn stereo."
---
# Three-d
@@ -11,11 +11,11 @@ Turn drawn structures into 3D geometry FormChem stores in the drawing, work on t
## Preconditions
-`get_context` has been called (`session-and-connection`), and the structure is drawn (`drawing`, `edit-by-id`, `names-and-spectra`). `build_3d`, `conformers_3d`, `minimise_3d`, `open_3d_structure` and `extract_ligand` ask the person the first time; `scan_dihedral` only with `store: true`; `export_3d` only when it writes a file outside the temporary folder; `measure_3d` never asks.
+`get_context` has been called (`session-and-connection`), and the structure is drawn (`drawing`, `edit-by-id`, `names-and-spectra`). `build_3d`, `conformers_3d`, `minimise_3d`, `open_3d_structure` and `extract_ligand` ask the person the first time; `scan_dihedral` only with `store: true`; `export_3d` only when it writes a file outside the temporary folder; `measure_3d` never asks; `xtb_optimise` and `crest_conformers` ask the first time.
## How 3D is held
-A structure's 3D coordinates are its `conformers`, each with an id (`c...`), an energy in kcal/mol, a `method` (`ETKDG` when only embedded, `MMFF94`, `MMFF94s`, `UFF`, or `file` when read from a file) and `converged`; `conformer` names the shown one. Atoms are the fragment atom ids from `get_atoms`; a hydrogen is `a1:h0` (the first hydrogen of `a1`), an atom inside an expanded abbreviation `a5:x0`. Any later edit to the structure's atoms or bonds (element, charge, bond order, wedge, adding or deleting) removes its conformers in the same undo step; moves and colours keep them. So: finish editing, then build.
+A structure's 3D coordinates are its `conformers`, each with an id (`c...`), an energy in kcal/mol, a `method` (`ETKDG` when only embedded, `MMFF94`, `MMFF94s`, `UFF`, `xtb` for an xtb or CREST result, or `file` when read from a file) and `converged`; an xtb conformer also carries `program` (name, version, method, solvent, charge, uhf, energy in hartree, gap); `conformer` names the shown one. Atoms are the fragment atom ids from `get_atoms`; a hydrogen is `a1:h0` (the first hydrogen of `a1`), an atom inside an expanded abbreviation `a5:x0`. Any later edit to the structure's atoms or bonds (element, charge, bond order, wedge, adding or deleting) removes its conformers in the same undo step; moves and colours keep them. So: finish editing, then build.
## Workflow 1: build and check
@@ -35,6 +35,17 @@ A structure's 3D coordinates are its `conformers`, each with an id (`c...`), an
MMFF94 energies compare conformers of one structure under one force field. They are not heats of formation and do not compare across structures, compositions or force fields. Say that when a person compares them.
+## Workflow 3a: xtb and CREST (0.12.0)
+
+xtb and CREST are LGPL-3.0 programs FormChem never ships or downloads. They run only when the person has installed them (PATH, a conda environment, or the path in Preferences > 3D > Tight-Binding Programs).
+
+1. **Call `xtb_optimise {object, method?, solvent?, charge?, uhf?, single_point?, level?, limit?}`**. `method` is `gfn2` (GFN2-xTB, default) or `gfnff`; `solvent` is `none` or an ALPB key (`water`, `methanol`, `acetonitrile`, `dmso`, `ch2cl2`, `chcl3`, `thf`, `toluene` and the rest of xtb's 24). Charge defaults to the drawn formal charges, `uhf` to the drawn radicals; a pair that cannot match the electron count is refused before anything runs, with the reason. A structure with no conformer is built first (ETKDGv3+MMFF94). The tool waits (default limit 600 s) and stores the result as the structure's only conformer, one undo step.
+2. **Call `crest_conformers {object, method?, solvent?, ewin?, keep?, limit?}`** for an ensemble: window 6 kcal/mol, at most 20 kept by default, limit 3600 s. CREST can take minutes to hours on anything flexible; set `limit` to what the person will wait for. Conformers that lost the drawn stereo are dropped and the answer counts them.
+3. **Quote the label.** Every answer names the program, version, method and solvent ("xtb 6.7.1, GFN2-xTB, ALPB (Water)"), the total energy in hartree and kcal/mol, the HOMO-LUMO gap and whether the optimisation converged. Pass all of it on.
+4. **Not installed** is an answer, not a failure to retry: the tool says where to get the program (https://github.com/grimme-lab/xtb, https://github.com/crest-lab/crest). Tell the person; never suggest FormChem can download it. Fall back to `conformers_3d` and `minimise_3d` only if the person agrees, and say the energies are then MMFF94.
+
+Tight-binding total energies are in hartree for one structure, charge and solvent model; compare them only between conformers or structures computed with the same method and solvent. An optimisation replaces the MMFF94 conformers, so earlier force-field numbers no longer belong to the drawing.
+
## Workflow 3: protein files and ligands
1. **Call `open_3d_structure {path}`** with an absolute `.pdb`, `.ent`, `.cif` or `.mmcif` path. One undo step: a 3D object (`o...`) over the file kept byte for byte, cartoon for a protein, ligands ball and stick, waters hidden, the primary ligand focused. Read the chains, ligand keys (`A:ATP:301`) and the reader's warnings and pass them on. An `.sdf` or `.mol` opens as structures whose conformers are the file's coordinates (method `file`).
@@ -52,13 +63,14 @@ MMFF94 energies compare conformers of one structure under one force field. They
- **Method and version travel with the number.** Every energy, barrier, population and measurement names its force field and engine version as FormChem gave them.
- **Stereo before geometry.** A build is usable only when its stereo line says every label was kept.
- **Build after editing.** An edit to atoms or bonds drops the conformers; rebuild rather than reuse numbers from before the edit.
-- **No quantum claims.** FormChem has no xtb, CREST or other quantum method; do not describe a force-field energy as anything more.
+- **No quantum claims beyond xtb.** A force-field energy is only that. xtb and CREST are semiempirical tight binding, run only on the person's own installation; FormChem has no DFT or other quantum method.
## Gate
- [ ] Every build reported its stereo line, and a lost label stopped the work with the reason.
- [ ] Every energy, barrier and measurement was quoted from a tool answer with its method and engine version.
- [ ] Inferred ligand bond orders and unspecified stereocentres were passed on to the person.
+- [ ] Every xtb or CREST number carried its program label, and a missing program was reported with where to get it, not retried.
- [ ] Each changing call was one undo step, and the handoff says what the person will see in the 3D View or on the page.
## Hands back
diff --git a/.claude/skills/formchem-harness/sub-skills/window-commands/SUB-SKILL.md b/.claude/skills/formchem-harness/sub-skills/window-commands/SUB-SKILL.md
index f18eede1..de8c9a18 100644
--- a/.claude/skills/formchem-harness/sub-skills/window-commands/SUB-SKILL.md
+++ b/.claude/skills/formchem-harness/sub-skills/window-commands/SUB-SKILL.md
@@ -30,6 +30,8 @@ Most canvas commands act on the canvas selection. The agent sets the selection t
| Draw from a name | Use `draw_from_name` (`names-and-spectra`). `run_command {id: "insert-name", params: {name}}` inserts it the window's way (centred like a template, selected); without `name` it opens Structure from Name for the person. `copy-name` puts the selection's name on the person's clipboard |
| Spectrum commands: edit, pick peaks, integrate, link a peak, y axis, export, predict, refresh | Prefer the spectrum and NMR tools (`names-and-spectra`). The commands remain for what they add: `link-peak-to-atoms {object, peak, fragment, atoms}` (no tool links), `open-spectrum {path}` (inserts a file into the open drawing), `spectrum-y-mode {object, mode}`, `edit-spectrum` (opens the Spectrum editor for the person), `nmr-refresh` (with a predicted spectrum selected) |
| Show it in 3D, change the 3D style or surface, put a 3D view on the page, save a 3D picture | Build and measure with the 3D tools (`three-d`). Then `view-3d` (opens the 3D View on the selection), `style-wire`, `style-stick`, `style-ballstick`, `style-spacefill`, `style-cartoon`, `surface-none`, `surface-vdw`, `surface-sas`, `surface-ses`, `surface-esp` (on only while the 3D View is open), `insert-3d-view` (a 3D object beside the selected structure), `export-3d-png {transparent}` and `export-gltf` (saved for the person). `export-3d-file {format, all}` saves MOL, SDF, PDB or XYZ for the person; `export_3d` gives the agent the text |
+| Show the database, a view of it, its dialogs, or the notebook to the person | Work with the database tools (`databases`). Then `show-databases`, `db-view-table`, `db-view-gallery`, `db-view-form`, `db-view-plot`, `db-view-notebook`, `db-search {text}`, `db-import {path}`, `db-export`, `database-fields`, `database-settings` (the person's dialogs); `nb-sign-entry` asks the person to sign and is never run in their place |
+| Copy a live structure for another Form app, open a library item for editing, HELM text of a drawn peptide, show the Structure Library or the Structure Summary, change the element colours | Library and HELM tools first (`library-and-biopolymers`). Then `copy-live-structure`, `open-live-structure {id, from}`, `copy-helm`, `structure-library {tab}`, `a11y-describe`, `element-palette-high-contrast` and its two siblings |
| Stack or group objects | `bring-front`, `bring-forward`, `send-backward`, `send-back`, `group`, `ungroup` on the selection; off with "Select something on the canvas first" when nothing is selected |
| Anything about the reaction in the drawing | Load `reactions` |
| Undo the last change | `run_command {id: "undo"}`: one transaction, whoever made it |
diff --git a/.claude/skills/formchem-harness/sub-skills/window-commands/references/command-catalogue.md b/.claude/skills/formchem-harness/sub-skills/window-commands/references/command-catalogue.md
index 929cca42..2ef1d85c 100644
--- a/.claude/skills/formchem-harness/sub-skills/window-commands/references/command-catalogue.md
+++ b/.claude/skills/formchem-harness/sub-skills/window-commands/references/command-catalogue.md
@@ -1,6 +1,6 @@
# Commands that touch a drawing
-The window's command registry, as far as it concerns drawings, for FormChem 0.10.0 (the commands of 0.7.0, plus `agent-activity` from 0.8.0, which opens Window > Agent Activity for the person, plus the name, spectrum and NMR commands of 0.9.0, plus the 3D commands of 0.10.0). From 0.8.0 the agent's own tools draw, edit, read back, render and convert; this page covers what the window's commands add. This page is a map, not the authority: `list_commands` is. A command marked `off now` there is not available in the running build, whatever this page says, and a command that lists `params` there takes exactly those.
+The window's command registry, as far as it concerns drawings, for FormChem 0.12.0 (the commands of 0.7.0, plus `agent-activity` from 0.8.0, which opens Window > Agent Activity for the person, plus the name, spectrum and NMR commands of 0.9.0, the 3D commands of 0.10.0, the database and notebook commands of 0.11.0, and the library, live structure, HELM, xtb and accessibility commands of 0.12.0). From 0.8.0 the agent's own tools draw, edit, read back, render and convert; this page covers what the window's commands add. This page is a map, not the authority: `list_commands` is. A command marked `off now` there is not available in the running build, whatever this page says, and a command that lists `params` there takes exactly those.
## Contents
@@ -14,6 +14,8 @@ The window's command registry, as far as it concerns drawings, for FormChem 0.10
- Standardise and size on the sheet
- Names, spectra and NMR prediction
- 3D
+- Databases and the notebook
+- Library, live structures, HELM, xtb and accessibility
- The canvas, the view and the grid
- Registered but off until a later version
- What no command does yet
@@ -170,6 +172,45 @@ From 0.10.0, group `3D`. Building, conformers, minimising, scans, measuring, ope
| `export-gltf` | | saves the 3D View as binary glTF (`.glb`) for the person (while the 3D View is open) |
| `export-3d-file` | `format` (`mol`, `sdf`, `pdb`, `xyz`), `all` (every conformer) | saves the selected structure's 3D coordinates for the person, or a PDB or mmCIF model's original file; without `format` it opens the dialog. For text the agent reads, `export_3d` |
+## Databases and the notebook
+
+From 0.11.0, groups `Database` and `Notebook`. Creating, opening, importing, searching, registering, exporting and notebook entries also have MCP tools (`databases`); prefer them, because they answer with the counts, ids and reasons. The commands show the person the database workspace and its dialogs. The search, import, export, plot, query and hit list commands are off until a database is open, and import and save query are off on a read-only one.
+
+| Command | Params | What it does |
+| --- | --- | --- |
+| `show-databases` | | shows or hides the database workspace (Shift+Mod+D) |
+| `new-database`, `open-database`, `close-database` | | the New and Open Database dialogs for the person; close releases the database's lock. For an agent, `db_create` and `db_open` |
+| `add-to-database` | | registers the selected structure, or the page as one record, in the current database; a duplicate opens the person's choice dialog. For an agent, `db_add_record` |
+| `database-settings`, `database-fields` | | the person's dialogs for the title and duplicate rules, and for fields (no MCP tool changes fields) |
+| `db-view-table`, `db-view-gallery`, `db-view-form`, `db-view-plot`, `db-view-notebook` | | shows the workspace in that view |
+| `db-search` | `text` (optional) | puts the cursor in the workspace search box; with `text`, runs it as plain text (text fields, uid, formula, SMILES) and shows the hit list. Structure and query searches: `db_search` |
+| `db-advanced-search`, `db-save-query`, `db-combine-hitlists` | | the query builder, Save Query and Combine Hit Lists dialogs for the person |
+| `db-import` | `path` (absolute, optional) | opens the Import dialog, previewing `path` at once; the person maps and imports. For an agent, `db_import` |
+| `db-export` | | opens the Export dialog for the person; for an agent, `db_export` |
+| `nb-new-entry` | | the New Notebook Entry dialog; for an agent, `nb_add_entry` |
+| `nb-sign-entry` | | asks the person to sign the shown entry with their name; never run it to sign on the person's behalf |
+| `nb-export-entry` | `format` (`html` default, or `json`) | saves the shown entry for the person |
+| `nb-save-scheme` | | saves the drawing opened with Edit Scheme back into its entry (on only while that drawing is active) |
+
+## Library, live structures, HELM, xtb and accessibility
+
+From 0.12.0. Adding to the library, the live structure object, drawing from HELM and the xtb and CREST runs also have MCP tools (`library-and-biopolymers`, `three-d`); prefer them, because they answer with ids, formulas and energies. The commands add the clipboard, the Structure Library dialog, opening a live drawing, HELM text out, and the person's accessibility views.
+
+| Command | Params | What it does |
+| --- | --- | --- |
+| `copy-live-structure` | | copies the selection (or the page) as a live structure: the picture with the drawing inside, the object, SMILES and molfile on the clipboard, and adds it to the library as live and recent. For an agent, `library_add {kinds: ["live"]}` and `live_structure_object` |
+| `star-structure` | | adds the selection (or the drawing) to the library as a favourite. For an agent, `library_add` |
+| `library-save-template` | `name` (asked when left out) | saves the selection (or the drawing) to the library as a template |
+| `structure-library` | `tab` (`favourite`, `recent`, `template`, `live`) | opens the Structure Library dialog for the person |
+| `open-live-structure` | `id` (required), `from` | opens a library item as a live drawing (the title shows the sibling); the person's Save then raises its rev. Answers "Opened live structure [id] rev [n] as drawing [doc]" |
+| `insert-helm` | `helm` (optional) | with `helm`, inserts it as atoms, one undo step; without, opens the Biopolymer from HELM dialog. For an agent, `draw_from_helm` answers with the numbers |
+| `copy-helm` | | copies the selected peptide or nucleic acid as HELM, only when it reads back to the same structure; with params from an agent it throws the reason instead of a toast |
+| `xtb-optimise` | `method`, `single_point`, `charge`, `uhf`, `solvent`, `level`, `limit` | with params, runs xtb on the selected structure without the dialog and waits; without, the dialog. For an agent, `xtb_optimise` |
+| `crest-conformers` | `method`, `charge`, `uhf`, `solvent`, `ewin`, `keep`, `limit` | the same for CREST. For an agent, `crest_conformers` |
+| `a11y-focus-structure`, `a11y-next-atom`, `a11y-previous-atom` | | put the keyboard focus ring on the drawing and walk atoms, for the person (Alt+Mod+A, Alt+Mod+], Alt+Mod+[) |
+| `a11y-describe` | | speaks and shows the Structure Summary (formula, name, rings, groups, stereo) for the person (Alt+Mod+S) |
+| `element-palette-standard`, `element-palette-high-contrast`, `element-palette-colour-blind` | | the element colours on this device (checked items under View > Element Colours) |
+
## The canvas, the view and the grid
| Command | What it does |
@@ -195,4 +236,4 @@ From 0.10.0, group `3D`. Building, conformers, minimising, scans, measuring, ope
## What no command does yet
-Selecting particular atoms or objects, typing stoichiometry amounts, and filling the person's dialogs (atom list, R-group, abbreviation label). Drawing atoms, bonds, arrows and text at given positions, reading the structure back, rendering and converting are not commands: the 0.8.0 tools do them (`drawing`, `edit-by-id`, `visual-qa`). Reading a spectrum's points, its peaks or the predicted shifts as data is not a command either: the 0.9.0 tools do it (`names-and-spectra`). Nor is reading conformer energies, a scan profile or a 3D measurement as data, or 3D coordinates as text: the 0.10.0 tools do it (`three-d`). Picking atoms in the 3D View, choosing the shown conformer and running a scan from the dialog belong to the person. An installed extension with the `document` permission can also read and change the drawing (`extension-drawings`).
+Selecting particular atoms or objects, typing stoichiometry amounts, and filling the person's dialogs (atom list, R-group, abbreviation label). Drawing atoms, bonds, arrows and text at given positions, reading the structure back, rendering and converting are not commands: the 0.8.0 tools do them (`drawing`, `edit-by-id`, `visual-qa`). Reading a spectrum's points, its peaks or the predicted shifts as data is not a command either: the 0.9.0 tools do it (`names-and-spectra`). Nor is reading conformer energies, a scan profile or a 3D measurement as data, or 3D coordinates as text: the 0.10.0 tools do it (`three-d`). Nor is reading database records, hit list rows or notebook entries as data: the 0.11.0 tools do it (`databases`). Nor is reading library items, live structure objects or xtb energies as data: the 0.12.0 tools do it (`library-and-biopolymers`, `three-d`). Picking atoms in the 3D View, choosing the shown conformer and running a scan from the dialog belong to the person. An installed extension with the `document` permission can also read and change the drawing (`extension-drawings`).
diff --git a/.claude/skills/formchem-skillset/EVALS.json b/.claude/skills/formchem-skillset/EVALS.json
index 3b0745e9..15b53e67 100644
--- a/.claude/skills/formchem-skillset/EVALS.json
+++ b/.claude/skills/formchem-skillset/EVALS.json
@@ -1,6 +1,6 @@
{
"skill_name": "formchem-skillset",
- "notes": "Run in a FormChem checkout at 0.10.0 with CLAUDE.md present. Expected behaviours are observable in the files read, the edits made and the commits.",
+ "notes": "Run in a FormChem checkout at 0.12.0 with CLAUDE.md present; evals 32 to 36 need no fixtures, and eval 35 must not install xtb. Expected behaviours are observable in the files read, the edits made and the commits.",
"evals": [
{
"id": 1,
@@ -303,6 +303,108 @@
"Finds that SUFFIXES in backend/app/routers/files.py lacks .usdz (as it lacked .glb, .cif, .mmcif and .ent until 0.10.0) and adds it by hand",
"Updates the extension list in docs/FORMATS.md and writes a backend HASHOUT entry"
]
+ },
+ {
+ "id": 28,
+ "name": "new-database-field-type",
+ "prompt": "Add a 'range' field type to FormChem databases that holds a low and a high number, like a melting point range.",
+ "files": [],
+ "expected_behavior": [
+ "Loads databases and reads docs/DATABASE.md before any code, and treats it as the contract",
+ "Edits the field table in DATABASE.md, schema.FIELD_TYPES with a raised FORMAT_VERSION and a migrate step, and FieldType in database-api.ts in the same change",
+ "Updates fields.py (_check_spec, coerce, detect, rebuild_view), exports.text_of, the type groups in query.py, columns.ts and the Fields dialog's type list",
+ "Checks by creating a scratch database under a scratch data folder, never ~/formchem"
+ ]
+ },
+ {
+ "id": 29,
+ "name": "new-query-term",
+ "prompt": "I want FormChem database searches to find records by ring count, like 'rings between 2 and 4'.",
+ "files": [],
+ "expected_behavior": [
+ "Loads databases and checks whether a number term on an existing column or computed field already covers it before adding a new kind",
+ "If a new kind is added: the term table in DATABASE.md, query.KINDS and _term with a named 422, _term_name, a mask in search.py with a _cost that keeps structure terms last, TERM and toQuery in query-model.ts, term-editor.ts and describeQuery",
+ "Does not compute ring counts outside chem.register_values or the computed descriptors",
+ "Checks the new term on a scratch database and confirms that hit counts match a brute-force count"
+ ]
+ },
+ {
+ "id": 30,
+ "name": "slow-substructure-after-edit",
+ "prompt": "After I update a record in my FormChem database, the next substructure search takes over a second again on 100,000 records. Why?",
+ "files": [],
+ "expected_behavior": [
+ "Loads databases and reads search.py screen, _gate and advance, and backend HASHOUT entries 237 and 238",
+ "Explains that a person's write moves the audit head, so the screening cache reloads (and the pickled molecule holder is rebuilt in the background), which is by design",
+ "Does not remove the audit row from the write or skip the freshness check, because every compound write must call store.audit inside its transaction",
+ "Proposes any speed-up as a measured change on a scratch 100,000 record copy, with a HASHOUT entry"
+ ]
+ },
+ {
+ "id": 31,
+ "name": "new-notebook-template",
+ "prompt": "Add a 'crystallisation' template to the FormChem lab notebook.",
+ "files": [],
+ "expected_behavior": [
+ "Loads databases and edits templates.py (NAMES, _HEADINGS, _OBSERVATIONS, LABELS) with headings in the plain markup",
+ "Adds it to EntryTemplate and TEMPLATES in the notebook window with its label through t(), to the template enum of nb_add_entry, and to DATABASE.md's template list",
+ "Runs ./formchem agents sync after the MCP tool change and commits the mirror"
+ ]
+ },
+ {
+ "id": 32,
+ "name": "new-live-object-field",
+ "prompt": "FormDeck wants a 'formula' field in the FormChem live structure object. Add it.",
+ "files": [],
+ "expected_behavior": [
+ "Loads family-integration and reads docs/LIVE_STRUCTURES.md first",
+ "Edits LIVE_STRUCTURES.md (the object), live_structures.live_object and the LiveObject type in app/live-structures.ts in one change, without raising format_version (an old reader ignores the new field)",
+ "Checks with a scratch script against a scratch FORMCHEM_DATA_DIR, not ~/formchem, and logs the decision in backend/HASHOUT_LOG.md"
+ ]
+ },
+ {
+ "id": 33,
+ "name": "agent-token-write-path",
+ "prompt": "Let ./formchem edit-live also save a drawing through the agent token, so a sibling can save without the window.",
+ "files": [],
+ "expected_behavior": [
+ "Loads family-integration and names law 4: the agent token writes only under /api/structures",
+ "Either keeps the change under /api/structures (save_live through the structures routes) or stops and asks, because widening core/window_key.py AGENT_WRITES is a SECURITY.md change",
+ "Does not add another path to AGENT_WRITES without a SECURITY.md edit in the same change"
+ ]
+ },
+ {
+ "id": 34,
+ "name": "new-helm-monomer",
+ "prompt": "Add N-methylalanine ([meA]) as a HELM monomer in FormChem.",
+ "files": [],
+ "expected_behavior": [
+ "Loads chemistry-engine and clean-room; writes the monomer itself from the structure, not from a HELM monomer library",
+ "Adds smiles with [*:1] and [*:2], the capped form, attachments R1 H and R2 OH and a source sentence to data/helm_monomers.json, and runs helm.monomers.library() so the load-time check passes",
+ "Round-trips a peptide containing [meA] through read and from_mol to the same InChIKey in a scratch script, and updates docs/HELM.md, the agent_helm description and the NOTICE.md count"
+ ]
+ },
+ {
+ "id": 35,
+ "name": "xtb-option",
+ "prompt": "Let FormChem's xtb optimisation take an electronic temperature (--etemp).",
+ "files": [],
+ "expected_behavior": [
+ "Loads three-d and follows the xtb option recipe: constant and validation in services/xtb, the argv in inputs.xtb_argv as a list item, never a shell string",
+ "Exposes it in the dialog, the xtb-optimise command params and agent_xtb's schema and KEYS, and records it in the program record only with FORMAT.md, model.ts and model.py changed together",
+ "Checks with a stand-in xtb on a temporary PATH, not by downloading xtb, and says a real run was not made if none was"
+ ]
+ },
+ {
+ "id": 36,
+ "name": "palette-flash",
+ "prompt": "Switching to the colour-blind element palette in FormChem makes the canvas flicker. Fix it.",
+ "files": [],
+ "expected_behavior": [
+ "Loads family-integration and canvas; looks at canvas/a11y/palette.ts applyPalette and the measure epoch rather than rebuilding the canvas",
+ "Checks under 4x CPU throttling with a MutationObserver that a switch adds or removes no node and changes only fills",
+ "Writes the reason in frontend/HASHOUT_LOG.md, not in a comment"
+ ]
}
],
"trigger_evals": [
@@ -358,6 +460,18 @@
{"query": "the 3D object on the formchem page flashes when I change its style", "should_trigger": true},
{"query": "add a surface option to FormChem's 3D View panel in frontend/src/ui", "should_trigger": true},
{"query": "give me the lowest-energy conformer of the structure in my open FormChem drawing", "should_trigger": false},
- {"query": "open this PDB file in formchem and extract the ligand for me", "should_trigger": false}
+ {"query": "open this PDB file in formchem and extract the ligand for me", "should_trigger": false},
+ {"query": "add a new query term to formchem's database search in services/database/query.py", "should_trigger": true},
+ {"query": "the formchem database table flashes when records load while scrolling", "should_trigger": true},
+ {"query": "an SD import into a formchem .fcdb reports the wrong record numbers in its failure report", "should_trigger": true},
+ {"query": "change how formchem hashes a notebook entry when it is signed", "should_trigger": true},
+ {"query": "search my FormChem database for compounds with a pyridine ring", "should_trigger": false},
+ {"query": "design a SQLite schema for a generic inventory app", "should_trigger": false},
+ {"query": "the formai://formchem/edit link opens the wrong drawing in FormChem's desktop app, fix handleDeepLink", "should_trigger": true},
+ {"query": "add a functional group to formchem's describe.py so the screen reader names sulfonamides", "should_trigger": true},
+ {"query": "FormChem's xtb job leaves its process running after cancel, look at services/xtb/runner.py", "should_trigger": true},
+ {"query": "Copy as HELM refuses a stapled peptide in formchem, fix the writer cuts", "should_trigger": true},
+ {"query": "draw oxytocin from HELM in FormChem for me", "should_trigger": false},
+ {"query": "make FormDeck read the formai structure library folder", "should_trigger": false}
]
}
diff --git a/.claude/skills/formchem-skillset/SKILL.md b/.claude/skills/formchem-skillset/SKILL.md
index 68284afc..79679f99 100644
--- a/.claude/skills/formchem-skillset/SKILL.md
+++ b/.claude/skills/formchem-skillset/SKILL.md
@@ -1,42 +1,44 @@
---
name: formchem-skillset
-description: "Guides development of the FormChem codebase, the FormAI family's chemical structure drawing suite. Use whenever a task changes, fixes or explains FormChem code: the document format (FORMAT.md, model.ts, model.py, ops, undo), the RDKit service (identifiers, the scored 2D layout, CIP, stereo groups, abbreviations, queries, R-groups, properties), reactions, file formats and loss reports, picture export, the clipboard, the command line, Standardise, the SVG canvas, grids, scaling, tools, annotations, names (dictionary, parser, namer), NMR prediction (increments), JCAMP-DX spectra, 3D (build, conformers, force fields, PDB and mmCIF, the 3D View, glTF), the shell, menus, the dock, Form extensions, the MCP server and agent tools (agent_edits, agent_log, the agent token), the Tauri shell, or a release. Trigger on FormChem or formchem with backend/app, frontend/src, src-tauri, FORMAT.md, port 8220 or 5220. Not for using FormChem (formchem-harness), other Form apps such as FormDeck, or standalone RDKit scripts."
+description: "Guides development of the FormChem codebase, the FormAI family's chemical structure drawing suite. Use whenever a task changes, fixes or explains FormChem code: the document format (FORMAT.md, model.ts, model.py, ops), the RDKit service (identifiers, the 2D layout, CIP, stereo groups, abbreviations, queries, properties), reactions, file formats, the clipboard, the command line, the SVG canvas, annotations, names, NMR prediction, JCAMP-DX spectra, 3D (conformers, force fields, PDB, xtb and CREST), the structure database and notebook (.fcdb, search, import, signing hashes), live structures and the shared library (LIVE_STRUCTURES.md, formai:// links, edit-live), keyboard access and palettes, HELM, the shell, menus, extensions, the MCP server and agent tools, the Tauri shell, or a release and its CHANGELOG. Trigger on FormChem or formchem with backend/app, frontend/src, src-tauri, FORMAT.md or port 8220. Not for using FormChem (formchem-harness), other Form apps such as FormDeck, or standalone RDKit scripts."
license: Apache-2.0
metadata:
author: nodemode-ai
- version: "0.10.0"
+ version: "0.12.0"
---
# FormChem skillset
Route every change to FormChem's code through this file. It maps the subsystems that exist today, states the laws that hold everywhere and names the specialist to load. FormChem is a Python 3.12 FastAPI engine (`backend/`, port 8220), a vanilla TypeScript and Vite window (`frontend/`, port 5220, no framework) that talks to the engine over REST and one WebSocket, and a Tauri 2 shell (`src-tauri/`) that runs the frozen engine from a folder inside the app on macOS and as a sidecar elsewhere.
-**Where FormChem is (0.10.0).** Through 0.9.0: the family shell, the document format, store and RDKit service, the canvas, reactions, stereo and analysis, formats and pictures, the agent tools with Agent Activity and the token, names, NMR prediction and spectra (`CHANGELOG.md`). 0.10.0 adds 3D: builds from 2D with a stereo check, conformers, force fields, scans, PDB and mmCIF files, the 3D View, model3d objects and eight more MCP tools (60). The structure database (0.11.0) comes later (`DEV_PLAN.md`). Do not write a later phase's code ahead of it; its commands stay registered and disabled.
+**Where FormChem is (0.12.0).** Through 0.11.0: the shell, format, store and RDKit service, canvas, reactions, analysis, formats, agent tools, names, NMR, spectra, 3D, databases and the notebook (`CHANGELOG.md`). 0.12.0 adds live structures and the shared library (`docs/LIVE_STRUCTURES.md`), accessibility, HELM, xtb and CREST by path and six MCP tools (77). Desktop builds and the manual (0.13.0) come later (`DEV_PLAN.md`); do not write them ahead.
## Subsystem map
| Subsystem | Root | Specialist |
| --- | --- | --- |
| Engine core: config, guards, window key, settings and seal, live socket, bridge, library | `backend/app/main.py`, `core/`, `routers/system.py`, `routers/live.py`, `services/hub.py`, `services/bridge.py`, `routers/library.py`, `backend/formchem_engine.py` | `engine` |
-| Engine document store: open documents, transactions, undo and redo, autosave, versions, recovery, the `.fchem` package, importers, the live `tx` messages | `backend/app/services/store.py`, `services/history.py`, `services/package.py`, `services/importers.py`, `routers/documents.py`, `core/files.py` | `engine` |
+| Engine document store: open documents, transactions, undo, autosave, versions, the `.fchem` package, importers | `backend/app/services/store.py`, `services/history.py`, `services/package.py`, `services/importers.py`, `routers/documents.py`, `core/files.py` | `engine` |
| The format contract: document.json, styles, ids, ops and inverses, transactions, validation, coalescing, the derived cache shape | `docs/FORMAT.md`, `frontend/src/engine/model.ts`, `engine/ops.ts`, `backend/app/services/model.py`, `services/ops.py` | `document-format` |
| Chemistry engine on RDKit: conversion, sanitising, valence, aromaticity, identifiers, formula, masses, layout, file reading and writing, the derived cache | `backend/app/services/chem/`, `backend/app/routers/chem.py` | `chemistry-engine` |
-| Window documents and chemistry: the document client, File and Insert actions, the Analysis panel, local valence, rings and formula | `frontend/src/engine/client.ts`, `engine/session.ts`, `engine/client-api.ts`, `app/documents.ts`, `ui/analysis-panel.ts`, `frontend/src/chem/` | `window-shell` (chemistry rules in `chemistry-engine`) |
-| Canvas: SVG renderer, drawing tools and hover hotkeys, view, hit testing, selection, text editor, canvas context menus, tool rail; from 0.7.0 the dark page, grids and snapping, scale handles | `frontend/src/canvas/` (`render/`, `tools/`, `view.ts`, `hit.ts`, `selection.ts`, `context.ts`, the grid and dark page files), `ui/tool-rail.ts`, `styles/canvas*.css`, `public/fonts/` | `canvas` |
-| Drawn objects: the object kind registry and kind modules, anchors, bounds, drawn-outline hits, annotation tools and handles, captions, z-order and groups, the template library, media | `frontend/src/canvas/render/objects.ts` and its kind modules, `canvas/hit-objects.ts`, `canvas/tools/objects.ts`, `tools/handles.ts`, `app/object-commands.ts`, `ui/template-*.ts`, `backend/app/services/templates.py`, `routers/templates.py`, `backend/app/data/templates/`, the media routes in `routers/documents.py` | `annotations` |
-| Reactions: perception, atom mapping, balance, stoichiometry (engine and window), reaction SMILES and RXN, the Reaction menu, the MCP reaction tools | `backend/app/services/chem/` (`geometry`, `reactions`, `mapping`, `balance`, `stoich`, `rxnio`, `scheme`), `routers/reactions.py`, `frontend/src/chem/stoich.ts`, `ui/stoich-panel.ts`, `app/reaction-commands.ts`, `engine/reactions-api.ts`, `docs/REACTIONS.md` | `reactions` |
-| Stereo, queries and analysis: stereo groups, CIP, wedges, abbreviations, hydrogens, queries, SMARTS, Markush, properties, the structure check, the isotope pattern, their routes, commands, marks and panels | `backend/app/services/chem/` (`stereo`, `superatom`, `hydrogens`, `query`, `search`, `v3000`, `markush`, `props`, `check`, `isotopes`), `routers/analysis.py`, `frontend/src/engine/analysis-api.ts`, `app/chem-*.ts`, `canvas/render/marks-*.ts`, `docs/ANALYSIS.md` | `stereo-and-queries` |
-| Formats and export: the formats table, report items, readers and writers (CDXML and CDX through Indigo, RD, CML), the export, parse, import and file write routes, pictures with the embedded drawing, the save path, print, File > Import | `backend/app/services/chem/` (`formats`, `report`, `io`, `writers`, `cdxio`, `rdfio`, `cml`), `services/embedded_source.py`, `services/pictures/`, `services/importers.py`, `routers/files.py`, `routers/pictures.py`, `frontend/src/app/` (`picture`, `embedded-source`, `save-file`, `export-commands`, `print`, `import-files`), `ui/export-dialog.ts`, `ui/import-report.ts`, `docs/FORMATS.md` | `formats-and-export` |
-| Clipboard: the native payload and paste plan, text formats, flavours per platform, Copy As, Paste Special, Duplicate | `frontend/src/app/clip-*.ts`, `app/clipboard.ts`, `ui/paste-special-dialog.ts`, `ui/native-menu.ts` `ALWAYS_NATIVE` | `clipboard` |
-| Names, NMR prediction and spectra: name engines, dictionary, parser, namer; increments and predicted spectra; the JCAMP-DX reader, peaks, integrals; the name dialog, spectrum kind, atom links, Spectrum editor | `backend/app/services/` (`names/`, `nmr/`, `spectra/`), `data/names/`, `routers/` (`names`, `nmr`, `spectra`), the window files in the specialist's file map, `docs/NAMES.md`, `docs/SPECTRA.md` | `names-and-spectra` |
+| Window documents and chemistry: the document client, File and Insert actions, the Analysis panel, local valence and rings | `frontend/src/engine/client.ts`, `session.ts`, `client-api.ts`, `app/documents.ts`, `ui/analysis-panel.ts`, `frontend/src/chem/` | `window-shell` (rules in `chemistry-engine`) |
+| Canvas: SVG renderer, tools and hover keys, view, hit testing, selection, text editor, context menus, tool rail, the dark page, grids, scale handles | `frontend/src/canvas/` (`render/`, `tools/`, `view.ts`, `hit.ts`, `selection.ts`, `context.ts`, the grid and dark page files), `ui/tool-rail.ts`, `styles/canvas*.css`, `public/fonts/` | `canvas` |
+| Drawn objects: the kind registry, anchors, bounds, annotation tools and handles, captions, z-order and groups, templates, media | `canvas/render/objects.ts` and kind modules, `hit-objects.ts`, `tools/objects.ts`, `handles.ts`, `app/object-commands.ts`, `ui/template-*.ts`, `services/templates.py`, `data/templates/` | `annotations` |
+| Reactions: perception, mapping, balance, stoichiometry, reaction SMILES and RXN, the Reaction menu and tools | `services/chem/` (`geometry`, `reactions`, `mapping`, `balance`, `stoich`, `rxnio`, `scheme`), `routers/reactions.py`, `chem/stoich.ts`, `ui/stoich-panel.ts`, `app/reaction-commands.ts`, `engine/reactions-api.ts`, `docs/REACTIONS.md` | `reactions` |
+| Stereo, queries and analysis: stereo groups, CIP, wedges, abbreviations, hydrogens, queries, SMARTS, Markush, properties, the check, isotopes | `services/chem/` (`stereo`, `superatom`, `hydrogens`, `query`, `search`, `v3000`, `markush`, `props`, `check`, `isotopes`), `routers/analysis.py`, `engine/analysis-api.ts`, `app/chem-*.ts`, `render/marks-*.ts`, `docs/ANALYSIS.md` | `stereo-and-queries` |
+| Formats and export: the formats table, reports, readers and writers (CDXML and CDX through Indigo, RD, CML), the exchange routes, pictures with the embedded drawing, print, File > Import | `services/chem/` (`formats`, `report`, `io`, `writers`, `cdxio`, `rdfio`, `cml`), `services/pictures/`, `embedded_source.py`, `importers.py`, `routers/files.py`, `pictures.py`, the window's export, print and import files, `docs/FORMATS.md` | `formats-and-export` |
+| Clipboard: the native payload, paste plan, flavours per platform, Copy As, Paste Special, Duplicate | `frontend/src/app/clip-*.ts`, `app/clipboard.ts`, `ui/paste-special-dialog.ts`, `ui/native-menu.ts` `ALWAYS_NATIVE` | `clipboard` |
+| Names, NMR prediction and spectra: name engines, namer; increments and predicted spectra; JCAMP-DX, peaks, integrals, atom links, the Spectrum editor | `backend/app/services/` (`names/`, `nmr/`, `spectra/`), `data/names/`, `routers/` (`names`, `nmr`, `spectra`), the window files in the specialist's file map, `docs/NAMES.md`, `docs/SPECTRA.md` | `names-and-spectra` |
| 3D: builds, conformers, force fields, scans, measurements, PDB and mmCIF, ligands, the stale-conformer rule; the 3D View, model3d snapshots, glTF | `backend/app/services/three_d/`, `routers/three_d.py`, `frontend/src/ui/view3d-*.ts`, `canvas/render/model3d.ts`, `io/glb.ts`, `engine/three-api.ts`, `engine/stale.ts`, `docs/3D.md` | `three-d` |
-| Command line and batch: convert, batch, descriptors, render, the stream reader, Standardise (engine, route, dialog) | `backend/app/cli.py`, `services/batch.py`, `services/chem/` (`stream`, `records`, `standardise`, `depict`), `setup/convert`, `frontend/src/ui/standardise-dialog.ts`, `app/standardise-command.ts`, `docs/CLI.md` | `command-line` |
+| Databases and notebook: the `.fcdb` store, registration, fields, import, export, search, hit lists, plot, entries and signing; the workspace, search and notebook views | `backend/app/services/database/`, `services/notebook/`, `routers/databases.py`, `db_search.py`, `notebook.py`, `frontend/src/ui/database*/`, `ui/notebook/`, `engine/database-api.ts`, `docs/DATABASE.md` | `databases` |
+| Family integration: the shared Library folder, live structures, edit-live, the `formai://` link, the file watch; accessibility keys, speech, the summary, palettes | `services/live_structures.py`, `file_watch.py`, `describe.py`, `routers/structures.py`, `app/live-structures.ts`, `ui/library-dialog.ts`, `canvas/a11y/`, `docs/LIVE_STRUCTURES.md` | `family-integration` |
+| Command line and batch: convert, batch, descriptors, render, the stream reader, Standardise | `backend/app/cli.py`, `services/batch.py`, `services/chem/` (`stream`, `records`, `standardise`, `depict`), `setup/convert`, `ui/standardise-dialog.ts`, `docs/CLI.md` | `command-line` |
| Window shell: app root, command registry, palette, Home, title bar, status bar, Preferences, dialogs, themes, i18n, styles | `frontend/src/app.ts`, `app/commands-shell.ts`, `commands/registry.ts`, `io/`, `ui/`, `i18n/`, `styles/` | `window-shell` |
| Menus: in-window menu bar, native macOS menus, context menus | `frontend/src/ui/menu.ts`, `ui/native-menu.ts`, `ui/context-menu.ts`, `app/menus.ts`, `styles/menu.css` | `menus` |
| Terminal and agent dock | `frontend/src/dock/` (vendored), `frontend/src/dock-adapter.ts`, `backend/app/routers/terminal.py`, `services/terminal.py`, `services/claude_code.py`, `services/agent_programs.py`, `services/agent_lookup.py` (vendored) | `dock` |
| Form extensions (host API 1) | `frontend/src/extensions/`, `backend/app/routers/extensions.py`, `services/formext_host.py` (vendored), `docs/EXTENSIONS.md` | `extensions` |
-| MCP server, agent tools, the call log and Agent Activity, the agent token, commands catalogue, agent setup and skills | `backend/app/routers/mcp.py`, `services/agent_*.py`, `core/agent_token.py`, `routers/agent_activity.py`, `routers/commands.py`, `frontend/src/app/agent-*.ts`, `ui/agent-*.ts`, `canvas/agent-marks.ts`, `setup/mcp_stdio.py`, `setup/agents.py`, `docs/AGENTS.md`, `.claude/skills` | `agents` |
-| Desktop app, the macOS engine folder and the sidecar | `src-tauri/` (`packaged.rs`, `tauri.macos.conf.json`), `backend/formchem_engine.py`, `setup/freeze_backend`, `setup/lib.sh`, `setup/desktop_*`, `build_app` | `desktop` |
+| MCP server, agent tools, the call log, Agent Activity, the token, the catalogue, skills | `backend/app/routers/mcp.py`, `services/agent_*.py`, `core/agent_token.py`, `routers/agent_activity.py`, `routers/commands.py`, `frontend/src/app/agent-*.ts`, `ui/agent-*.ts`, `canvas/agent-marks.ts`, `setup/mcp_stdio.py`, `setup/agents.py`, `docs/AGENTS.md`, `.claude/skills` | `agents` |
+| Desktop app, the macOS engine folder and the sidecar | `src-tauri/` (`packaged.rs`, `tauri.macos.conf.json`), `formchem_engine.py`, `setup/freeze_backend`, `lib.sh`, `desktop_*`, `build_app` | `desktop` |
| Versions, changelog, notices, CI, formcompiler | `.docs/BRANCHING.md`, `CHANGELOG.md`, `NOTICE.md`, `setup/notices.py`, `.github/workflows/` | `release` |
| Where any FormChem feature may come from | the owner's clean-room specifications | `clean-room` |
@@ -47,9 +49,8 @@ frontend commands/registry.ts -> nothing (DOM free; the cli and workers may impo
engine/model.ts, engine/ops.ts -> nothing (pure, DOM free; the contract)
chem/ -> engine/model.ts only (pure, no t(), no DOM)
engine/client.ts, session.ts -> model, ops, client-api, io/api, io/live
-canvas/render -> canvas/types.ts, engine/model, engine/ops (its own geom, valence, rings);
- render/table.ts also chem/stoich.ts, the one window stoichiometry source;
- render/marks-layer.ts also canvas/marks-options.ts (view toggles only)
+canvas/render -> canvas/types.ts, engine/model, engine/ops (own geom, valence, rings); table.ts
+ also chem/stoich.ts; marks-layer.ts also canvas/marks-options.ts
engine/analysis-api.ts -> io/api, model, ops; the only caller of /api/analysis
canvas/tools -> canvas/types.ts, engine/model, engine/ops, canvas/geom.ts
canvas/view.ts, ui/tool-rail -> canvas/types.ts, hit.ts, selection.ts, ui/dom, ui/icons, i18n
@@ -60,9 +61,8 @@ backend services/model.py, ops.py -> nothing (pure; the contract)
services/store.py -> model, ops, package, history, importers, hub; chem.derive imported lazily
services/chem/ -> rdkit, indigo, model (never the store or routers)
backend routers -> core, services (hub, bridge, library, store, chem, terminal, formext_host)
-mcp.py -> commands, extensions, consent, claude_code (in-app tokens), bridge, hub, agent_token;
- routers/analysis and the agent_* services imported lazily by the tools
-services/agent_*.py -> store, bridge, chem (agent_edits is pure: model and chem only); agent_log hooks AFTER_CHANGE
+mcp.py -> commands, extensions, consent, claude_code, bridge, hub, agent_token; agent_* lazily
+services/agent_*.py -> store, bridge, chem (agent_edits pure); agent_log hooks AFTER_CHANGE
app/picture.ts -> canvas/render (a fresh renderer off screen), never the live canvas view
app/clip-*.ts, import-files -> engine/model, ops, the export and parse routes; one paste plan (clip-data.ts)
services/chem/writers, stream -> formats, report, io, rdkit, indigo (never the store)
@@ -70,6 +70,9 @@ services/batch.py, app/cli.py -> chem/stream, records, standardise, depict, prop
services/pictures/ -> fontTools and the bundled fonts only
services/names, nmr, spectra -> rdkit, numpy, chem (never routers); nmr registers its hook in spectra.source.PREDICTORS
services/three_d -> rdkit, numpy, chem (never routers); store.apply_now runs three_d.stale
+services/database, notebook -> sqlite3, rdkit, numpy, chem (never routers or the document store)
+services/helm, xtb, describe -> rdkit, chem (xtb also three_d); xtb starts programs only as separate processes
+canvas/a11y -> canvas view and render, ui/a11y-announcer; installed before mountCanvas
ui/view3d-lib.ts -> 3dmol by dynamic import only (nothing 3D at startup)
window-only abilities -> reach the engine as window tools over /api/live (bridge.window_call)
desktop shell -> frozen engine (formchem_engine.py) -> serves frontend/dist
@@ -103,22 +106,24 @@ The window reaches the engine only through `frontend/src/io/api.ts` (REST with t
| How a bond, label or wedge renders, a drawing tool, a hover key, hit testing, selection, zoom, the tool rail, canvas context menus | `canvas` |
| An arrow, bracket, shape, table, TLC plate, orbital, picture or caption, its handles and tool; z-order, groups, templates | `annotations`, with `canvas` for the laws it builds on |
| Reaction roles, atom mapping, balance, the stoichiometry panel or grid, reaction SMILES or RXN, a reaction route, command or MCP tool | `reactions`, with `chemistry-engine` for RDKit and `agents` for a tool |
-| A CIP label, stereo group, wedge, abbreviation, explicit hydrogen, atom list, query bond, SMARTS, substructure hit, R-group, property, check issue or isotope peak; an `/api/analysis` route, an analysis MCP tool, a stereo or query mark | `stereo-and-queries`, with `chemistry-engine` for the converter and `agents` for a tool |
+| A CIP label, stereo group, wedge, abbreviation, hydrogen, query atom or bond, SMARTS, R-group, property, check issue or isotope peak; an `/api/analysis` route or tool | `stereo-and-queries` (`chemistry-engine` for the converter, `agents` for a tool) |
| A file that opens wrong or loses something, an export or import report, a new format, File > Import, picture export, the drawing inside a picture, saving in the desktop app, print | `formats-and-export`, with `chemistry-engine` for RDKit and `clean-room` for a new format |
| Copy, Cut, Paste, Copy As, Paste Special, Duplicate, a clipboard flavour on one platform | `clipboard`, with `formats-and-export` for the text formats and pictures |
| `./formchem convert`, `batch`, `descriptors`, `render`, the stream reader, per-record failures, Standardise | `command-line`, with `chemistry-engine` for RDKit |
| A name read wrong, a dictionary entry, a ring parent, OPSIN; a predicted shift, an increment, a predictor; a JCAMP-DX file, the spectrum plot, peaks, integrals, atom links, the Spectrum editor | `names-and-spectra` (`clean-room` first; `canvas` for the renderer, `document-format` for the spectrum object) |
| A 3D build, conformer, scan, measurement or surface; a PDB or mmCIF file or ligand; the 3D View, a 3D object on the page, glTF; conformers after an edit | `three-d` (`document-format` for `conformers` and `model3d`, `agents` for a tool) |
+| A database field, query term, import or export format, hit list, duplicate rule, notebook template or signing; the workspace table, search or plot | `databases` (`agents` for a tool) |
+| The Library folder, Copy as Live Structure, a live Save, edit-live, the deep link, the file bar; a focus key, a spoken sentence, the summary, a palette | `family-integration` (`agents` for a tool) |
+| A HELM string or monomer; an xtb or CREST option or job | `chemistry-engine`; `three-d` |
| A crowded or crossing 2D layout, Lay Out or Clean Up | `chemistry-engine` (the scored layout) |
| The dark page, a grid type, snapping, scale handles, Scale Up and Down | `canvas`, with `document-format` for `style.grid` |
| New, Open, Save, Insert from SMILES, the Analysis panel, the status bar formula, the dirty mark | `window-shell`, with `chemistry-engine` for the values |
| Home, the title bar, status bar, palette, Preferences, About, dialogs, themes, translations, styles | `window-shell` |
-| A menu item, a submenu, a shortcut label, macOS native menus, menu overlap | `menus`, then `window-shell` for the command |
+| A menu item, submenu or shortcut label, native macOS menus, a menu that clips the title, More menus, keys with a menu open | `menus`, then `window-shell` for the command |
| Terminal tabs, Claude Code, Codex, Cursor or Antigravity tabs, the consent dialog, chat | `dock` |
| The extensions pane, an extension API call, FormPortal or form.ext integration | `extensions` |
| An MCP tool, an edit builder, agent render or placement, the call log, Agent Activity, Stop, the token, `./formchem agents`, skills | `agents` |
-| Desktop build, `build_app`, a slow desktop start, the macOS engine folder and its flatten rule, the Tauri CLI version, sidecar, updater, Tauri commands, title bar overlay | `desktop` |
-| A menu that clips or overlaps the title, More menus, Escape or arrows with a menu open | `menus` |
+| Desktop build, `build_app`, a slow start, the macOS engine folder, sidecar, updater, Tauri commands, title bar overlay | `desktop` |
| A release, version sites, CHANGELOG, NOTICE, CI | `release` |
| Any chemistry feature, a file format, a name for a command or panel | `clean-room` first |
| Use FormChem: draw or edit a structure with the agent tools, run a menu command, hand off in the window | Not this pack: `formchem-harness` |
@@ -131,7 +136,8 @@ formchem-skillset/
references/repo-laws.md each law with its reason and exact format
EVALS.json evaluation prompts and the trigger tests (should and should not load)
sub-skills/ engine, document-format, chemistry-engine, reactions, stereo-and-queries, formats-and-export,
- clipboard, command-line, names-and-spectra, three-d, canvas, annotations, window-shell, menus, dock,
+ clipboard, command-line, names-and-spectra, three-d, databases, family-integration, canvas, annotations,
+ window-shell, menus, dock,
extensions, agents, desktop, release, clean-room
chemistry-engine/references/warning-codes.md every ChemWarning code and where it comes from
stereo-and-queries/references/routes-and-codes.md the /api/analysis routes, check codes and service warning codes
@@ -159,7 +165,7 @@ cd frontend && npx tsc --noEmit type-check
backend/venv/bin/python -m compileall -q backend/app setup
```
-Scratch engines for checks: `FORMCHEM_PORT=[port] FORMCHEM_DATA_DIR=[scratch]/data venv/bin/python -m uvicorn app.main:app --port [port]` from `backend/`. `backend/venv/bin/python backend/formchem_engine.py --selfcheck` confirms RDKit and Indigo import. Never point a check at `~/formchem`, the person's data folder.
+Scratch engines: `FORMCHEM_PORT=[port] FORMCHEM_DATA_DIR=[scratch]/data venv/bin/python -m uvicorn app.main:app --port [port]` from `backend/`; never point a check at `~/formchem`, the person's data folder.
## Done means
diff --git a/.claude/skills/formchem-skillset/sub-skills/agents/SUB-SKILL.md b/.claude/skills/formchem-skillset/sub-skills/agents/SUB-SKILL.md
index 2ae35fca..15017f09 100644
--- a/.claude/skills/formchem-skillset/sub-skills/agents/SUB-SKILL.md
+++ b/.claude/skills/formchem-skillset/sub-skills/agents/SUB-SKILL.md
@@ -31,9 +31,9 @@ Give agents an honest tool surface that only describes what FormChem can do now,
| `docs/AGENTS.md` | the public reference of every tool, the token and the call log |
| `.claude/skills/formchem-harness`, `formchem-skillset` | the packs; `.agents/skills` is a mirror written by sync. Made and repaired only through the god-tier-skill-creator pipeline; its `scripts/validate_skill.py` reports zero FAIL before a commit |
-## The tool surface (0.10.0)
+## The tool surface (0.12.0)
-60 tools: the six of the shell (`get_context`, `list_commands`, `run_command`, `extensions_list`, `extension_command`, `handoff`); the reaction tools of 0.5.0 and the analysis tools of 0.6.0 (owned by `reactions` and `stereo-and-queries`); and the 28 of 0.8.0: `list_open_documents`, `new_document`, `open_document`, `save_document`, `close_document`, `draw_from_smiles`, `draw_from_molfile`, `render`, `get_structure`, `validate`, `compute_properties`, `convert`, `batch_convert`, `get_atoms` and the 14 edit tools `add_atom`, `add_bond`, `set_charge`, `set_atom`, `set_stereo`, `replace_substructure`, `delete`, `move`, `scale`, `align`, `clean_layout`, `add_arrow`, `add_text`, `add_reaction`; and the 10 of 0.9.0, whose services `names-and-spectra` owns: `draw_from_name` (through `_draw`), `name_structure` (the route's `name_mol`), `predict_nmr`, `predict_spectrum` (`nmr.document.spectrum_ops`), `open_spectrum`, `spectrum_data`, `spectrum_peaks`, `spectrum_pick_peaks`, `spectrum_integrate` (`spectra.peak_ops`, `integral_ops`) and `spectrum_export`; and the 8 of 0.10.0, whose services `three-d` owns: `build_3d`, `conformers_3d`, `minimise_3d`, `scan_dihedral`, `measure_3d`, `open_3d_structure` (`three_d.open_bytes`) and `extract_ligand` call the `routers/three_d.py` functions through `_three_d` with an `AgentCall` in the body, so the route's `commit` applies with origin `agent` and the agent's name, and `export_3d` calls `export.write` directly. The writing ones are in `MUTATING` (`scan_dihedral` only with `store`, `export_3d` only with an `output` outside the temporary folder, through `_mutating`); a tool never builds its own copy of a route's ops.
+77 tools: the six of the shell (`get_context`, `list_commands`, `run_command`, `extensions_list`, `extension_command`, `handoff`); the reaction tools of 0.5.0 and the analysis tools of 0.6.0 (owned by `reactions` and `stereo-and-queries`); and the 28 of 0.8.0: `list_open_documents`, `new_document`, `open_document`, `save_document`, `close_document`, `draw_from_smiles`, `draw_from_molfile`, `render`, `get_structure`, `validate`, `compute_properties`, `convert`, `batch_convert`, `get_atoms` and the 14 edit tools `add_atom`, `add_bond`, `set_charge`, `set_atom`, `set_stereo`, `replace_substructure`, `delete`, `move`, `scale`, `align`, `clean_layout`, `add_arrow`, `add_text`, `add_reaction`; and the 10 of 0.9.0, whose services `names-and-spectra` owns: `draw_from_name` (through `_draw`), `name_structure` (the route's `name_mol`), `predict_nmr`, `predict_spectrum` (`nmr.document.spectrum_ops`), `open_spectrum`, `spectrum_data`, `spectrum_peaks`, `spectrum_pick_peaks`, `spectrum_integrate` (`spectra.peak_ops`, `integral_ops`) and `spectrum_export`; and the 8 of 0.10.0, whose services `three-d` owns: `build_3d`, `conformers_3d`, `minimise_3d`, `scan_dihedral`, `measure_3d`, `open_3d_structure` (`three_d.open_bytes`) and `extract_ligand` call the `routers/three_d.py` functions through `_three_d` with an `AgentCall` in the body, so the route's `commit` applies with origin `agent` and the agent's name, and `export_3d` calls `export.write` directly. The writing ones are in `MUTATING` (`scan_dihedral` only with `store`, `export_3d` only with an `output` outside the temporary folder, through `_mutating`); a tool never builds its own copy of a route's ops. And the 11 of 0.11.0, whose services `databases` owns, in agent modules rather than in `mcp.py`: `services/agent_db.py` (`db_list`, `db_create`, `db_open`, `db_import`, `db_search`, `db_get_record`, `db_add_record`, `db_update_record`, `db_export`) and `services/agent_notebook.py` (`nb_add_entry`, `nb_search`). Each module offers `TOOLS` in the `_tool` shape, frozen `NAMES`, `mutating(name, args)` and `async call(name, args, agent_name)`, which runs the database services on a worker thread and writes as `agent:[name]`; `mcp.py` walks `AGENT_MODULES` for the list, the gate and dispatch, so a new module adds one name there. They touch no drawing (except `nb_add_entry {doc}`, which reads one), so they answer with `_ok` text and `structuredContent`, not `write_result`. And the 6 of 0.12.0, in three more agent modules: `agent_library.py` (`library_list`, `library_add`, `live_structure_object`; `family-integration` owns the service), `agent_helm.py` (`draw_from_helm`, through `mcp._draw`; `chemistry-engine` owns `services/helm`) and `agent_xtb.py` (`xtb_optimise`, `crest_conformers`, through `_three_d` with the xtb job routes; `three-d` owns `services/xtb`). HELM and xtb build `mcp.Agent("", agent_name)` in `call` because `_draw`, `_apply` and `_three_d` read only the name. `setup/agents.py` reads `mcp.py`'s own `TOOLS` by AST, and each agent module's finished `TOOLS` by importing it with the backend venv's Python (`_module_tools`), so `references/tools.md` and `agents/manifest.json` hold all 77 tools.
## Laws of the agent tools
diff --git a/.claude/skills/formchem-skillset/sub-skills/chemistry-engine/SUB-SKILL.md b/.claude/skills/formchem-skillset/sub-skills/chemistry-engine/SUB-SKILL.md
index e16e9fbc..6ea4d544 100644
--- a/.claude/skills/formchem-skillset/sub-skills/chemistry-engine/SUB-SKILL.md
+++ b/.claude/skills/formchem-skillset/sub-skills/chemistry-engine/SUB-SKILL.md
@@ -1,6 +1,6 @@
---
name: chemistry-engine
-description: "FormChem's chemistry: the RDKit service in backend/app/services/chem (conversion from fragments, sanitising, valence, aromaticity, stereo and CIP, canonical SMILES, CXSMILES, InChI and InChIKey, Hill formula, masses, m/z, elemental analysis, isotope pattern, 2D clean-up and the scored layout: CoordGen and RDKit candidates, layout_score and layout_refine), the /api/chem routes, the derived cache broadcast after every transaction, and the window's local valence, ring and label rules in frontend/src/chem. Use when a computed value is wrong, a warning or valence error appears or is missing, a structure reads upside down or loses atoms, a layout is crowded, crosses bonds or moves the wrong atoms, or a new chemistry computation is added."
+description: "FormChem's chemistry: the RDKit service in backend/app/services/chem (conversion from fragments, sanitising, valence, aromaticity, stereo and CIP, canonical SMILES, CXSMILES, InChI and InChIKey, Hill formula, masses, m/z, elemental analysis, isotope pattern, 2D clean-up and the scored layout: CoordGen and RDKit candidates, layout_score and layout_refine), the /api/chem routes, the derived cache broadcast after every transaction, and the window's local valence, ring and label rules in frontend/src/chem, and from 0.12.0 the HELM reader and writer in services/helm over data/helm_monomers.json. Use when a computed value is wrong, a warning or valence error appears or is missing, a structure reads upside down or loses atoms, a layout is crowded, crosses bonds or moves the wrong atoms, a HELM string is refused or a peptide will not copy as HELM, a monomer is added, or a new chemistry computation is added."
---
# Chemistry engine
@@ -29,6 +29,7 @@ Compute everything chemical in one place, from the drawing as the person drew it
| `frontend/src/canvas/render/valence.ts`, `render/rings.ts` | The renderer's own fast implicit-H table and ring perception, used while drawing |
| `references/warning-codes.md` | Every warning code, the module that raises it and when. Open before adding or interpreting a warning |
| Reaction modules (0.5.0) | `chem/geometry.py`, `reactions.py`, `mapping.py`, `balance.py`, `stoich.py`, `rxnio.py`, `scheme.py`, `derive.reaction_checks` and `routers/reactions.py` belong to the `reactions` specialist; they reuse `convert.to_mol` and the rules here |
+| HELM (0.12.0) | `data/helm_monomers.json` (55 monomers written for FormChem, each with `smiles`, `capped`, `attachments`, `source`); `services/helm/monomers.py` (`_monomer` checks every capped form at load, `inline`), `parser.py` (`parse`, positioned `HelmError`, limits), `assemble.py` (`Chem.molzip` over shared map numbers, exported as `build_molecule`), `writer.py` (`CUTS`, `_assign`, `_topology`, `write`), `__init__.py` (`read`, `from_mol` with the InChIKey read-back); `routers/helm.py`, `services/agent_helm.py`, `frontend/src/ui/helm-dialog.ts`, `app/helm-commands.ts`; `docs/HELM.md`; HASHOUT backend 265 to 269, frontend 296 and 297 |
| Analysis modules (0.6.0) | `chem/stereo.py`, `superatom.py`, `hydrogens.py`, `query.py`, `search.py`, `v3000.py`, `markush.py`, `props.py`, `check.py`, `isotopes.py` and `routers/analysis.py` belong to the `stereo-and-queries` specialist. Here they changed `convert.py` (stereo groups and the chiral flag after perception, query atoms and bare `*` as generics), `perceive.py` (`stereo_unknown`, `undefined_double_bond`, cumulenes skipped, charged atoms judged by the allowed list so Na+ is no valence error) and `derive.content_key` (`FRAGMENT_FIELDS`) |
## Rules
@@ -50,6 +51,13 @@ Compute everything chemical in one place, from the drawing as the person drew it
3. A new derived field is a contract change: add it to the derived cache table in `docs/FORMAT.md` and to `DerivedFragment` in `model.ts` (`document-format`).
4. Time it: `derive_document` on a 250-atom fragment stays well under 100 ms warm.
+## A HELM monomer or a new cut (0.12.0)
+
+1. **Write the monomer yourself** from a textbook structure (`clean-room`): never copy a HELM monomer library, whose licence was never cleared. Give `smiles` with `[*:n]`, the `capped` form with each leaving group put back, `attachments` (R label to `H` or `OH`) and a `source` sentence; mirror-image D forms in full. The loader refuses the whole file when a capped form differs, so run `helm.monomers.library()` in the engine venv after the edit.
+2. **Reading** needs nothing more; **writing** needs the piece to come out of `writer._cuts`. A new bond kind is a `CUTS` row (SMARTS, the two cut atoms, the leaving group each side) and, if it pairs labels unusually, a `PARTNER` entry; cut only bonds that are always between monomers.
+3. **Round-trip check.** A scratch script under `/tmp` reads the HELM, writes it back and compares InChIKeys, for the new monomer and for oxytocin, ApU, a chain of all 20 L and 19 D residues, a head-to-tail cyclic peptide and the two lactam bridges. `from_mol` must never offer HELM that reads back differently.
+4. Update the monomer table in `docs/HELM.md`, the tool description in `agent_helm.py` and the count in NOTICE.md's own-data line.
+
## Gate
- [ ] `backend/venv/bin/python -m compileall -q backend/app` is clean and `backend/formchem_engine.py --selfcheck` exits 0.
diff --git a/.claude/skills/formchem-skillset/sub-skills/databases/SUB-SKILL.md b/.claude/skills/formchem-skillset/sub-skills/databases/SUB-SKILL.md
new file mode 100644
index 00000000..1d5ea236
--- /dev/null
+++ b/.claude/skills/formchem-skillset/sub-skills/databases/SUB-SKILL.md
@@ -0,0 +1,85 @@
+---
+name: databases
+description: "FormChem's 0.11.0 structure database and lab notebook code: the engine packages services/database (schema, store, chem.register_values, computed, fields, forms, records, attachments, thumbs, jobs, imports, exports, uploads, info, query, search, hitlists, saved, plot, dbcli) and services/notebook (templates, content hash, scheme, products, entries, export), routers databases.py, db_search.py and notebook.py, agent_db.py and agent_notebook.py, and the window's ui/database (workspace, table, gallery, form, dialogs), ui/database-find (search bar, query builder, hit lists, import, export, plot) and ui/notebook, against the contract docs/DATABASE.md. Use when adding a field type, a query term, an import or export format, a notebook template, a database route or MCP tool, fixing a slow or wrong search, an import report, a duplicate rule, a hit list, a table that flashes, or signing and the entry hash."
+---
+
+# Databases
+
+## Purpose
+
+Change FormChem's databases and notebook without breaking the contract: one `.fcdb` SQLite file that any SQLite browser reads, every write in one transaction with an audit row, keys and fingerprints from one function, searches that never add hits as a threshold rises, and a 10,000 record table that never rebuilds. Hands back the change, the checks that prove it and HASHOUT entries.
+
+## Preconditions
+
+`clean-room` loaded (the database and notebook sections of the clean-room specifications). `docs/DATABASE.md` read in full: it is the contract, and when code disagrees with it the code is the bug. `database-api.ts`, `workspace-types.ts` and `services/database/schema.py` are contract files too.
+
+## File map
+
+| Path | Holds |
+| --- | --- |
+| `services/database/schema.py`, `store.py` | tables, `FORMAT_VERSION`, `migrate`; handles, the lock file, `writing`, `reading`, `next_number`, `audit`, `notify`, `close_all` |
+| `database/chem.py`, `computed.py` | `register_values` (keys, formula, masses, counts, both fingerprints); descriptor fields over `chem/props.measure` |
+| `database/fields.py`, `forms.py`, `records.py`, `attachments.py`, `thumbs.py`, `info.py` | fields and the `records` view; generated forms; add, update, duplicates, paging; files; themed thumbnails; Info, create, open |
+| `database/jobs.py`, `imports.py`, `exports.py`, `uploads.py` | worker jobs; preview, mapping, batches of 250, the report, `plain`; SD, SMILES, CSV and one-time downloads; browser uploads and `adopt` |
+| `database/query.py`, `search.py`, `hitlists.py`, `saved.py`, `plot.py` | `normalise`, the formula grammar, `name_of`; the screening cache, `_evaluate`, `run`; hit lists with temp tables when read-only; saved queries; plot points |
+| `database/dbcli.py`, `app/cli.py` | `./formchem db` |
+| `services/notebook/` | `templates`, `content` (the eleven-key hash), `scheme` (molecules, stoichiometry, pictures), `products`, `entries` (`sign`, `after_change`, `listing`), `attachments`, `markup`, `export` |
+| `routers/databases.py`, `db_search.py`, `notebook.py`; `core/window_key.py` `require_view` | thin routes, `GUARD` and `VIEW_GUARD` |
+| `services/agent_db.py`, `agent_notebook.py`; `routers/mcp.py` `AGENT_MODULES` | the eleven tools, `mutating`, `call` |
+| `frontend/src/engine/database-api.ts` | types and one function per route, `DuplicateError` |
+| `frontend/src/ui/database/` | `workspace.ts`, `workspace-types.ts`, `record-source.ts` (blocks of 100), `selection.ts`, `columns.ts`, `table.ts`, `gallery.ts`, `form-view.ts`, `thumbs.ts`, the dialogs; `app/database-commands.ts` |
+| `frontend/src/ui/database-find/` | `search-bar.ts`, `query-text.ts`, `query-model.ts`, `term-editor.ts`, `query-builder.ts`, `hitlists.ts`, `queries.ts`, `import-dialog.ts`, `export-dialog.ts`, `files.ts`, `plot.ts`, `plot-math.ts` |
+| `frontend/src/ui/notebook/` | `notebook.ts`, `entry-list.ts`, `entry-editor.ts`, `scheme-view.ts`, `notebook-api.ts`, `markup.ts`, `commands.ts` |
+| `docs/DATABASE.md`, `docs/DATABASES.md` | the contract; the person's guide. HASHOUT backend 223 to 255, frontend 245 to 276 |
+
+## Laws
+
+1. **One transaction per write.** Every write runs inside `store.writing(db)` (BEGIN IMMEDIATE ... COMMIT under `db.lock`) and calls `store.audit` in it; reads use `store.reading`. The search cache trusts the audit head, so a write without an audit row leaves searches stale. Long work commits in batches, each its own transaction, and registers chemistry outside the lock.
+2. **Notify after commit.** `store.notify(db, change, uids)` is called once the transaction committed, never inside it, with the `change` names of DATABASE.md; the window refetches only what it names.
+3. **The contract wins.** A table, column or JSON shape change edits DATABASE.md, the engine and `database-api.ts` in one change, raises `FORMAT_VERSION` and adds a step to `schema.migrate`; an older file must still open (read-only when newer).
+4. **Fingerprints only through `chem.register_values`.** Stored rows and exact queries are keyed by that one function; never compute an InChIKey, parent key or fingerprint elsewhere.
+5. **Search stays monotonic and named.** Raising a similarity threshold never adds hits; every structure result names its method and the RDKit version.
+6. **The window never rebuilds.** Rows and tiles are pooled and keyed by uid, records arrive in blocks with stale blocks kept on screen, and a live change refetches only its blocks.
+7. **Agents never sign.** Signing is the person's statement; `nb_add_entry` writes open entries only.
+
+## Recipes
+
+### A new field type
+
+1. DATABASE.md's field table, `schema.FIELD_TYPES` and `NUMERIC_TYPES` (with a format version step), and `FieldType` in `database-api.ts`.
+2. Engine: `fields._check_spec`, `stores_text`, `coerce` (and its import path `text=True`), `detect`, `rebuild_view`; `exports.text_of` and `NON_SCALAR`; the type groups in `query.py`.
+3. Window: `columns.ts` (format, parse, `EDITABLE`), the type list in `fields-dialog.ts`, the import dialog's type names, the term editor's field groups in `database-find/shared.ts`.
+
+### A new query term
+
+1. DATABASE.md's term table first.
+2. `query.KINDS` and `_term` (defaults and the 422 naming the bad key), `_term_name` for the hit list name.
+3. `search.py`: a mask function in `FIELD_TERMS` or a branch in `_evaluate`, with a `_cost` that keeps structure terms last.
+4. Window: `TERM` and `toQuery` in `query-model.ts`, the row in `term-editor.ts`, `describeQuery` in `query-text.ts`; the `_QUERY` description in `agent_db.py`.
+
+### A new import or export format
+
+Import: `imports.FORMATS` and `format_of`, items from `chem/records.py` `iter_records` (streaming, a reason per bad record), `IMPORT_EXTENSIONS` in `files.ts`, the `--format` help in `dbcli.py`, the `format` enum of `db_import`, DATABASE.md and `docs/FORMATS.md`. Export: `exports.FORMATS` and `_write`, the export dialog, `db_export`'s enum, and a round trip into a new database that keeps every InChIKey and value.
+
+### A new notebook template
+
+`templates.NAMES`, `_HEADINGS`, `_OBSERVATIONS` and `LABELS`; `EntryTemplate` and `TEMPLATES` in the notebook window with its label through `t()`; the `template` enum of `nb_add_entry`; DATABASE.md's template list. Headings are plain markup (`**Heading**`), never HTML.
+
+### A database route or MCP tool
+
+A thin route with `GUARD` (or `VIEW_GUARD` for a picture) on a worker thread, `DatabaseError` turned into its status; the function in `database-api.ts`; a tool in `agent_db.TOOLS` or `agent_notebook.TOOLS` with `mutating` deciding consent, writing as `agent:[name]`; then `./formchem agents sync` (its generated `tools.md` reads only mcp.py's own `TOOLS`, so module tools are documented in `docs/AGENTS.md` and the harness `databases` sub-skill).
+
+## Checks
+
+Scratch data folders only (`FORMCHEM_DATA_DIR=[scratch]/data`). Import a 10,000 record SD file with three broken records: 9,997 added and three plain reasons. Benzene substructure equals a brute-force `HasSubstructMatch` on a 2,000 record copy; thresholds 0.3 to 0.9 never rise. A second process opens the file read-only and gets 423 on writes. The table under 4x CPU throttling: layout shift 0 while scrolling, no row nodes added on sort. An entry signed, then changed, keeps one `edited-after-signing` version with the signed hash.
+
+## Gate
+
+- [ ] DATABASE.md, the engine and `database-api.ts` agree; a shape change raised the format version with a migration.
+- [ ] Every new write is one transaction with an audit row and a notify after commit.
+- [ ] New numbers name their method and version; similarity stays monotonic.
+- [ ] The checks above ran on scratch data, and HASHOUT entries are written.
+
+## Hands back
+
+The change, the check output with numbers, and the HASHOUT entries.
diff --git a/.claude/skills/formchem-skillset/sub-skills/family-integration/SUB-SKILL.md b/.claude/skills/formchem-skillset/sub-skills/family-integration/SUB-SKILL.md
new file mode 100644
index 00000000..7881ade5
--- /dev/null
+++ b/.claude/skills/formchem-skillset/sub-skills/family-integration/SUB-SKILL.md
@@ -0,0 +1,84 @@
+---
+name: family-integration
+description: "FormChem's 0.12.0 family integration code: live structures and the shared structure library (services/live_structures.py, routers/structures.py, agent_library.py, app/live-structures.ts, ui/library-dialog.ts, the contract docs/LIVE_STRUCTURES.md), the agent token's one write path (core/window_key.py AGENT_WRITES), formchem edit-live, the formai:// deep link (tauri-plugin-deep-link, followDeepLinks, handleDeepLink), the file watch and its bar (services/file_watch.py, ui/file-changed-bar.ts), and accessibility (canvas/a11y: the key route, navigation, spoken atoms and bonds, the focus ring, element palettes; ui/a11y-announcer.ts, ui/structure-summary.ts, services/describe.py). Use when changing what a sibling Form app reads, the clipboard flavours of Copy as Live Structure, the library folder or library.json, a live drawing's Save, edit-live or the deep link, the file changed bar, a keyboard focus key, a spoken sentence, the Structure Summary, a functional group or ring name, or an element palette."
+---
+
+# Family integration
+
+## Purpose
+
+Change how FormChem works with the other Form apps and with assistive technology without breaking what they rely on: the Library folder and the live structure object stay readable by apps that never run FormChem code, a live drawing saves to its item and nothing else, the agent token writes nowhere but `/api/structures`, the keyboard route runs before the canvas's, every spoken sentence is a whole `t()` template, and switching palettes or showing the file bar never moves a node. Hands back the change, the checks that prove it and HASHOUT entries.
+
+## Preconditions
+
+`clean-room` loaded (the family and accessibility sections of the clean-room specifications, spec C 9.4). `docs/LIVE_STRUCTURES.md` read in full: it is the contract sibling apps code against, and when code disagrees with it, fix one of them in the same change and say which in the HASHOUT log.
+
+## File map
+
+| Path | Holds |
+| --- | --- |
+| `backend/app/services/live_structures.py` | `folder` (`FORMCHEM_DATA_DIR/Library`, not the recent-drawings `library.json`), `read_index`, `write_file`, `write_index` (atomic, index last), `add` (merges kinds for non-live, live always new), `prune` (`RECENT_CAP` 50 by `used`), `describe` (perceive, ids, `mass.average_mass`), `engine_pictures`, `live_object`, `adopt` (id kept, higher rev wins), `open_live`, `save_live`, `LINKS`, `links`, `open_request`, `edit_live` |
+| `backend/app/routers/structures.py` | the contract routes plus `links`, the unkeyed `picture.svg/png`, `GET /api/files/watch` and `POST .../{reload or keep}`; `_guard` takes the window key or the agent token |
+| `backend/app/core/window_key.py` | `AGENT_WRITES`, `agent_may_write`: the global guard lets a valid bearer token through on `/api/structures` and below only |
+| `backend/app/services/file_watch.py`, `app/main.py` lifespan | the 1 s poll of open drawings' files, own saves recognised by `document.json` `modified`, `reload` (one undoable transaction), `keep` |
+| `backend/app/services/agent_library.py` | `library_list`, `library_add`, `live_structure_object` in the agent module shape |
+| `backend/app/cli.py`, `formchem`, `formchem.bat` | `edit-live` |
+| `src-tauri/` (Cargo.toml, main.rs, tauri.conf.json, capabilities) | tauri-plugin-deep-link 2.6.3, the `formai` scheme, single-instance with `deep-link`, `register_all()` on Linux |
+| `frontend/src/app/live-structures.ts` | `structuresApi`, `copyLiveStructure` (one `writeClipboard`), `starStructure`, `saveTemplateToLibrary`, `saveLive`, `liveActive`, `mountLiveDrops`, `deepLinkTarget`, `handleDeepLink`, `LIVE_MIME`, `WEB_LIVE_MIME` |
+| `frontend/src/app.ts` `followDeepLinks`; `app/documents.ts` `DocumentHooks.save` | deep links in the main window only; closing a dirty live drawing saves its item |
+| `frontend/src/ui/library-dialog.ts`, `ui/file-changed-bar.ts`, `styles/library.css` | the Structure Library (built once, tiles keyed by id, fixed 132 px rows); the bar inside `.fc-stage` |
+| `frontend/src/canvas/a11y/` | `index.ts` (`prepareA11y` before `mountCanvas`, `mountA11y`), `controller.ts` (`installA11yKeys`, `CanvasA11y`, `relayCanvasPrompts`), `nav.ts`, `speech.ts`, `elements.ts`, `ring.ts`, `palette.ts`, `commands.ts` (`PALETTE_COMMAND_IDS`), `describe-api.ts` |
+| `frontend/src/canvas/render/atom.ts` | `ELEMENT_PALETTES` (standard, high-contrast, colour-blind), `setElementPalette` |
+| `frontend/src/ui/a11y-announcer.ts`, `ui/structure-summary.ts`, `styles/a11y.css` | the shared live regions; the summary dialog; focus ring, outlines, 24 px targets |
+| `backend/app/services/describe.py`, `routers/describe.py` | `GROUPS` (42 SMARTS), `RING_NAMES` (51 skeletons), `functional_groups` (priority, claimed atoms), `ring_name`, `stereo`, `describe`; `POST /api/describe` |
+| `docs/LIVE_STRUCTURES.md`, `LIVE-STRUCTURES.md`, `ACCESSIBILITY.md` | the contract; the person's pages. HASHOUT backend 256 to 264 and 276 to 278, frontend 277 to 295 and 300 |
+
+## Laws
+
+1. **The folder is the contract.** Every Library file is written through `core/files.write_atomic`, item files first and `library.json` last; deletes write the index first. Readers skip items whose files are missing. A field a sibling reads changes LIVE_STRUCTURES.md, `live_structures.py` and `live-structures.ts` together, and `format_version` rises only for a change an old reader would misread.
+2. **The drawing inside is the structure.** Every item SVG and PNG carries the FormChem source in the carriers of FORMATS.md, whoever drew it (the window's pictures, or `engine_pictures` without a window). A picture without it is a bug, not a lighter item.
+3. **A live drawing is ordinary.** Nothing is written into the drawing; the link lives in `LINKS` and the window's map. Save goes to `save_live` (rev + 1, `live-structure` broadcast), Save As stays an ordinary copy, closing calls the `DocumentHooks.save` hook. Revisions only rise: `adopt` keeps the higher rev.
+4. **The agent token has one write path.** Only `/api/structures` and below; every other changing route still needs the window key. Widening `AGENT_WRITES` is a SECURITY.md change.
+5. **The deep link only opens.** `deepLinkTarget` accepts `formai://formchem/edit?id=s[10]&from=...` and nothing else; other `formai` hosts pass on; only the `main` window listens. A link never carries a path, a command or a setting.
+6. **The key route goes first.** `prepareA11y()` runs before `mountCanvas` so its capture listener precedes the view's; handled keys get `preventDefault` only (`stopImmediatePropagation` breaks the menu bar's Alt detection); Tab past the last atom leaves, so focus is never trapped. The focus is the view's keyboard cursor, not a second one.
+7. **Speak whole sentences from fresh data.** Every spoken part is one `t()` template; derived values (hydrogens, CIP, aromaticity) only when `derived.rev` equals the client's and nothing is unconfirmed. One announcer for the window; the canvas's own region stays hidden and its prompts are relayed.
+8. **Palettes patch fills.** The choice is read before the canvas exists (localStorage `formchem.elementPalette`); a switch bumps the measure epoch so only fills change. High contrast stays at 7:1 or more on white; the colour-blind palette keeps Okabe-Ito hues of 3:1 or more and leaves paler ones to the ink.
+9. **Nothing moves.** The file bar is absolutely placed in the stage with a local z token; the library dialog patches tiles by id; the summary reserves its rows.
+
+## Recipes
+
+### A field or flavour a sibling reads
+
+LIVE_STRUCTURES.md first, then `live_object` or `describe` and `LiveObject` or `LibraryItem` in `live-structures.ts`, then `copyLiveStructure`'s flavour list. Browsers accept custom clipboard types only with the `web ` prefix and drop `chemical/x-mdl-molfile`; keep the object in the HTML flavour's `data-formai-structure` too. Check `library.json` field by field against the contract with a scratch script, and the clipboard in Chromium under 4x throttling.
+
+### A new way to open a live structure
+
+Route it to `open_live` (engine) or `openLiveStructure` (window), never a second opener. Command-line paths go through `open_request` and post with the agent token like `edit_live`; a desktop path goes through the deep link plugin and `handleDeepLink`.
+
+### A keyboard key or a spoken sentence
+
+Keys live in `controller.ts` (`installA11yKeys` and the handlers); registry commands in `commands.ts` with a key the 312-command registry does not already use (check `GET /api/commands`, and macOS reserved combinations such as Option-Command-D). Sentences go in `speech.ts` or `structure-summary.ts` as whole templates; element names in `elements.ts`. Check with Playwright reading `.fc-announcer-polite`, and say in the notes that no real screen reader ran unless one did.
+
+### A functional group or ring name
+
+Write the SMARTS or skeleton for FormChem (`clean-room`); a group marks its core atoms with map numbers and sits in priority order in `GROUPS`; a ring goes through the same `_skeleton_key` as the table. Re-run the 25-molecule scratch check (aspirin acid and ester, caffeine urea and purine, L-alanine S) and update the counts in NOTICE.md and ACCESSIBILITY.md.
+
+### An element palette
+
+A map in `ELEMENT_PALETTES` with contrast ratios computed on white in a scratch script, the choice in `PALETTE_CHOICES`, the Preferences option in `ui/prefs/sections.ts`. Check 0 nodes added or removed per switch under 4x throttling.
+
+## Checks
+
+From `backend/` on a scratch engine and data folder: `edit_live` against an item (exit 0), an unknown id (exit 1) and an unreadable file (exit 2); curl `/api/structures` without a key 403, with the token 200, and the token on `/api/helm/parse` and `/api/structuresX` 403; an outside rewrite of an open `.fchem` shows the bar within about a second and an own save does not. In the built window under 4x CPU throttling: Copy as Live Structure, paste back, open from the Live tab and Save raises rev; the keyboard-only ethanol speaks every atom and Describe reads its formula; palette switches and the file bar give layout shift 0. `npx tsc --noEmit` clean.
+
+## Gate
+
+- [ ] LIVE_STRUCTURES.md, the engine and the window agree; `library.json` written by FormChem passes a field-by-field check.
+- [ ] No route other than `/api/structures` accepts the agent token for writes; the deep link still opens only.
+- [ ] Keys still route before the canvas, Tab still leaves, and every new sentence is one `t()` template.
+- [ ] No node added or removed by a palette switch or the file bar; tiles patched by id.
+- [ ] HASHOUT entries and the docs updated; NOTICE.md own-data counts still true.
+
+## Hands back
+
+The change, the check results, the HASHOUT entries and the commit list.
diff --git a/.claude/skills/formchem-skillset/sub-skills/three-d/SUB-SKILL.md b/.claude/skills/formchem-skillset/sub-skills/three-d/SUB-SKILL.md
index 48ca1508..d4adf2ff 100644
--- a/.claude/skills/formchem-skillset/sub-skills/three-d/SUB-SKILL.md
+++ b/.claude/skills/formchem-skillset/sub-skills/three-d/SUB-SKILL.md
@@ -1,6 +1,6 @@
---
name: three-d
-description: "FormChem's 0.10.0 3D code: the engine package services/three_d (molecule labels, forcefield, build, verify, conformers, minimise, scan, measure, export, structure, pdb, mmcif, molfile3d, ligand, readers, document, stale), routers/three_d.py, the stale-conformer rule in the store and in engine/stale.ts, the window's 3D View panel over a lazily loaded 3Dmol.js (view3d-lib, view3d-viewer, view3d-panel, dialogs, scan plot), the model3d page renderer and its snapshots, the glb writer and the 3D commands. Use when adding a display style, a surface, a force field or method, a structure file reader, a 3D MCP tool or route, fixing a build that loses stereo, a conformer or scan result, a PDB summary or ligand, a 3D object that flashes on the page, or the conformer drop after an edit."
+description: "FormChem's 0.10.0 3D code: the engine package services/three_d (molecule labels, forcefield, build, verify, conformers, minimise, scan, measure, export, structure, pdb, mmcif, molfile3d, ligand, readers, document, stale), routers/three_d.py, the stale-conformer rule in the store and in engine/stale.ts, the window's 3D View panel over a lazily loaded 3Dmol.js (view3d-lib, view3d-viewer, view3d-panel, dialogs, scan plot), the model3d page renderer and its snapshots, the glb writer and the 3D commands, and from 0.12.0 services/xtb (discovery, runner, jobs, parse, writeback) with routers/xtb.py, agent_xtb.py and the xtb dialogs. Use when adding a display style, a surface, a force field or method, an xtb or CREST option, a structure file reader, a 3D MCP tool or route, fixing a build that loses stereo, a conformer or scan result, a PDB summary or ligand, an xtb job that hangs or misreads output, a 3D object that flashes on the page, or the conformer drop after an edit."
---
# Three-d
@@ -11,7 +11,7 @@ Change FormChem's 3D without breaking its promises: every energy and measurement
## Preconditions
-`clean-room` loaded (the 3D sections of the clean-room specifications). Licence rule: permissive anywhere; LGPL only as a separate process the person installs (xtb and CREST stay user-installed by path while plan question Q9 is open); GPL and AGPL never (no Open Babel code); gemmi (MPL-2.0) is not vetted. Ligand templates are written for FormChem; the Chemical Component Dictionary is CC0 but nothing was copied from it.
+`clean-room` loaded (the 3D sections of the clean-room specifications). Licence rule: permissive anywhere; LGPL only as a separate process the person installs (xtb and CREST are user-installed by path, plan question Q9's default; never bundle, download or link them); GPL and AGPL never (no Open Babel code); gemmi (MPL-2.0) is not vetted. Ligand templates are written for FormChem; the Chemical Component Dictionary is CC0 but nothing was copied from it.
## File map
@@ -29,7 +29,9 @@ Change FormChem's 3D without breaking its promises: every energy and measurement
| `frontend/src/canvas/render/model3d.ts` | the page object (snapshot, or a placeholder) |
| `frontend/src/io/glb.ts`, `chem/elements3d.ts`, `chem/geom3d.ts`, `chem/conformer-mol.ts` | glTF writer, palette and radii, measurement maths, local molfile |
| `frontend/src/app/view3d-commands.ts`, `app/menus.ts` | `VIEW3D_COMMAND_IDS`, the commands, `DISPLAY_3D`, `SURFACE_3D` |
-| `docs/3D.md`, `docs/FORMAT.md` | the reference; `conformers`, `conformer` and `model3d`. HASHOUT backend 199 to 222, frontend 222 to 244 |
+| `backend/app/services/xtb/` (0.12.0) | `__init__` (methods, levels, limits, settings keys), `solvents` (24 ALPB), `discovery` (`find`, `_locate`, `child_env`), `inputs` (start geometry in label order, `electrons_check`, argv), `runner` (`Process`, own process group, `stop_all`), `jobs` (one at a time, `_collect`, `_prune`), `parse`, `writeback` (`records`, `program`, `label`) |
+| `routers/xtb.py`, `services/agent_xtb.py`, `frontend/src/app/xtb-commands.ts`, `ui/xtb-dialog.ts`, `ui/prefs/xtb.ts` | the xtb routes and `_applier` over `three_d.commit`; the two tools; the client and commands; the dialogs; the Preferences rows |
+| `docs/3D.md`, `docs/FORMAT.md` | the reference; `conformers` (with the xtb `program` record), `conformer` and `model3d`. HASHOUT backend 199 to 222 and 270 to 275, frontend 222 to 244, 298 and 299 |
## Laws
@@ -50,11 +52,19 @@ Change FormChem's 3D without breaking its promises: every energy and measurement
### A force field or method
-Add it to `METHODS` and `forcefield.setup` with its own fallback reason, to `FORCE_FIELDS` in `three-api.ts`, the panel's select, `_FF` in `mcp.py`, and `docs/3D.md`. An external program (xtb) runs as a separate process found by a path the person sets, never bundled or linked, and its energy is stored under its own `method`.
+Add it to `METHODS` and `forcefield.setup` with its own fallback reason, to `FORCE_FIELDS` in `three-api.ts`, the panel's select, `_FF` in `mcp.py`, and `docs/3D.md`. An external program runs as a separate process found by a path the person sets, never bundled or linked, and its energy is stored under its own `method`, as xtb does (below).
+
+### An xtb or CREST option (0.12.0)
+
+1. Constants first: `xtb/__init__.py` (`METHODS`, `OPT_LEVELS`, limits) or `solvents.ALPB` (only solvents xtb documents).
+2. `jobs.options` validates it (422 with the reason), `inputs.xtb_argv` or `crest_argv` passes it; never build a shell string, always an argv list.
+3. Output: a new value is read in `parse.py` from the documented file layout and checked on a hand-written file under `/tmp`; it travels in the job's `conformers` table and, when it belongs with the geometry, in `writeback.program` (then FORMAT.md, `model.ts` `ConformerProgram` and `model.py` in one change).
+4. Expose it: the dialog field in `xtb-dialog.ts` (built once; polling patches text only), the command `params` in `xtb-commands.ts`, the tool schema and `KEYS` in `agent_xtb.py`, `docs/3D.md` and `docs/AGENTS.md`.
+5. Laws that stay: one job at a time; a failed job keeps its folder until it is forgotten; results map back by element order or the job fails (502); write-back goes through `three_d.commit` with the stale signature, so an edit mid-run fails the job instead of storing stale conformers. Check with a stand-in program on a temporary PATH (a script printing `xtb version X` and writing `xtbopt.xyz` and the log lines), never only with a real installation.
### A structure file reader
-A parser returning `Structure` (with `summary` working on it), a `detect` rule and rows in `EXTENSIONS` and `MIMES`, `readers.read`, `document.MODEL_FORMATS` and `importers.MODELS_3D`, `package.EXT_BY_MIME`, the window's `OPEN_EXTENSIONS` and `STRUCTURE_ACCEPT`, and `routers/files.py` `SUFFIXES` so the desktop save accepts it (that list still lacks `.glb`, `.cif`, `.mmcif` and `.ent` at 0.10.0). The bytes stay as media; never rewrite the file.
+A parser returning `Structure` (with `summary` working on it), a `detect` rule and rows in `EXTENSIONS` and `MIMES`, `readers.read`, `document.MODEL_FORMATS` and `importers.MODELS_3D`, `package.EXT_BY_MIME`, the window's `OPEN_EXTENSIONS` and `STRUCTURE_ACCEPT`, and `routers/files.py` `SUFFIXES` so the desktop save accepts it. The bytes stay as media; never rewrite the file.
### A 3D MCP tool or route
diff --git a/.docs/wiki/3D.md b/.docs/wiki/3D.md
index e5d0e18a..a92bbf85 100644
--- a/.docs/wiki/3D.md
+++ b/.docs/wiki/3D.md
@@ -64,13 +64,22 @@ Select a PDB or mmCIF model and choose 3D > Extract Ligand.... With several liga
3D coordinates belong to the structure they were built from. Change an element, a charge, a bond or a wedge, or add or delete atoms, and the structure's conformers are removed in the same undo step; build again. Moving atoms and changing colours keep them, and Undo brings them back.
+## xtb and CREST
+
+From 0.12.0 FormChem runs xtb and CREST when you have installed them; it never includes or downloads them (they are LGPL-3.0 programs of the Grimme group). Get them from https://github.com/grimme-lab/xtb and https://github.com/crest-lab/crest (or conda-forge), then check Preferences > 3D > Tight-Binding Programs: each row shows the version and path FormChem found, or where to get the program. Set a path there when the program is not on your PATH.
+
+- **3D > Optimise with xtb...**: GFN2-xTB or GFN-FF, charge, unpaired electrons, an ALPB solvent (water, DMSO, chloroform and 21 more) or the gas phase, and either an optimisation or a single point energy. The result replaces the structure's conformers, as one undo step, with the energy in hartree and kcal/mol, the HOMO-LUMO gap and a label such as "xtb 6.7.1, GFN2-xTB, ALPB (Water)".
+- **3D > Conformer Search with CREST...**: the same settings plus the energy window (6 kcal/mol) and how many to keep (20). The ensemble replaces the conformers, lowest first, with populations; conformers whose stereo no longer matches the drawing are left out and counted.
+
+The dialog shows progress and the program's last lines, Cancel Job stops a run, and a failed run keeps its folder so you can read the program's own files.
+
## Not yet
-- xtb and CREST are not offered; every energy is a force-field energy.
+- xtb and CREST were checked with stand-in programs, not real installations.
- Surfaces on large proteins take a while and hold the window meanwhile.
- Measurements on a structure without a 3D object on the page last only while the panel is open.
- Atropisomers and allene axial chirality are not recognised.
## For agents
-`build_3d`, `conformers_3d`, `minimise_3d`, `scan_dihedral` and `measure_3d` work on a structure's conformers, `open_3d_structure` opens PDB, mmCIF, SD and MOL files, `extract_ligand` takes a ligand out, and `export_3d` writes MOL, SD, PDB or XYZ. See [Agents](Agents).
+`build_3d`, `conformers_3d`, `minimise_3d`, `scan_dihedral` and `measure_3d` work on a structure's conformers, `open_3d_structure` opens PDB, mmCIF, SD and MOL files, `extract_ligand` takes a ligand out, and `export_3d` writes MOL, SD, PDB or XYZ. From 0.12.0 `xtb_optimise` and `crest_conformers` run xtb and CREST when they are installed. See [Agents](Agents).
diff --git a/.docs/wiki/Accessibility.md b/.docs/wiki/Accessibility.md
new file mode 100644
index 00000000..b7481171
--- /dev/null
+++ b/.docs/wiki/Accessibility.md
@@ -0,0 +1,37 @@
+# Accessibility
+
+From 0.12.0 FormChem can be used from the keyboard alone, speaks what it focuses through your screen reader, describes a whole structure in words, and offers element colours that stay apart. The full guide is [`docs/ACCESSIBILITY.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/ACCESSIBILITY.md).
+
+## Keys
+
+`Mod` is Cmd on a Mac and Ctrl elsewhere.
+
+| Key | What it does |
+| --- | --- |
+| `Alt+Mod+A` | View > Focus Structure: the focus ring goes onto the drawing |
+| Tab, Shift+Tab | next or previous atom, in reading order |
+| an arrow | the bonded atom in that direction |
+| Ctrl, Cmd or Alt with an arrow | the bond in that direction |
+| Space | select or deselect the focused atom or bond |
+| Enter, then an arrow | draw a new bond in that direction (Enter on an empty drawing adds a carbon) |
+| O, N, Cl and the other hover keys | change the focused atom |
+| `Alt+Mod+]`, `Alt+Mod+[` | View > Next Atom, Previous Atom |
+| `Alt+Mod+S` | View > Describe Structure |
+
+## What you hear
+
+Each move is spoken, for example "Oxygen. 1 hydrogen. Single bond to Carbon. Not in a ring. Atom 3 of 3." Describe Structure speaks and shows the formula, the name, the charge, the ring systems (named when FormChem knows them: benzene, pyridine, piperidine and others), the functional groups and the stereocentres with their R or S labels, each with the method behind it; Copy copies the text.
+
+## Element colours
+
+Preferences > Interface > Element colours, or View > Element Colours: Standard, High contrast (every element colour at 7:1 or more on white) or Colour-blind safe (the Okabe-Ito blue, vermillion, bluish green and reddish purple). They apply when Colour atoms by element is on, also to pictures and copies.
+
+## Focus and targets
+
+Every dialog control shows a 2 pixel outline from the keyboard; colour swatches and tool buttons are at least 24 pixels.
+
+## Not yet
+
+- Checked by reading what FormChem says, not with VoiceOver, NVDA or Orca.
+- On many European Windows keyboards Ctrl+Alt is AltGr, so `Ctrl+Alt+[` and `]` may not type; use the View menu or the command palette.
+- The 3D View has no keyboard rotation yet.
diff --git a/.docs/wiki/Agents.md b/.docs/wiki/Agents.md
index 80316343..005d9bf2 100644
--- a/.docs/wiki/Agents.md
+++ b/.docs/wiki/Agents.md
@@ -1,6 +1,6 @@
# Agents
-FormChem's engine is an MCP server (`backend/app/routers/mcp.py`), over HTTP at `http://127.0.0.1:8220/mcp` and over stdio with `./formchem mcp` (`setup/mcp_stdio.py`, which starts the engine when needed). An agent works in the same window you see. From 0.8.0 it draws there directly: it makes and opens drawings, draws structures and reaction schemes from SMILES or molfiles, edits them atom by atom by id, reads them back in machine form and checks its work with a picture drawn by the window's own renderer. From 0.9.0 it also draws from chemical names and names what is drawn, predicts 1H and 13C NMR spectra, and opens JCAMP-DX spectra, picks their peaks and integrates them. From 0.10.0 it builds structures in 3D, searches conformers, minimises, scans dihedrals and measures, opens PDB, mmCIF and 3D SD files, extracts ligands and writes 3D files. Every change is one undo step, every call is listed in [Agent Activity](Agent-Activity), and you can stop an agent from the title bar.
+FormChem's engine is an MCP server (`backend/app/routers/mcp.py`), over HTTP at `http://127.0.0.1:8220/mcp` and over stdio with `./formchem mcp` (`setup/mcp_stdio.py`, which starts the engine when needed). An agent works in the same window you see. From 0.8.0 it draws there directly: it makes and opens drawings, draws structures and reaction schemes from SMILES or molfiles, edits them atom by atom by id, reads them back in machine form and checks its work with a picture drawn by the window's own renderer. From 0.9.0 it also draws from chemical names and names what is drawn, predicts 1H and 13C NMR spectra, and opens JCAMP-DX spectra, picks their peaks and integrates them. From 0.10.0 it builds structures in 3D, searches conformers, minimises, scans dihedrals and measures, opens PDB, mmCIF and 3D SD files, extracts ligands and writes 3D files. From 0.11.0 it creates and opens structure databases, imports into them, searches them, registers and updates records, exports them, and adds and finds lab notebook entries. From 0.12.0 it keeps structures in the shared structure library, hands out live structure objects for sibling Form apps, draws peptides and nucleic acids from HELM, and runs xtb and CREST when you have installed them. Every change is one undo step, every call is listed in [Agent Activity](Agent-Activity), and you can stop an agent from the title bar.
The full reference, with every tool's arguments and result shape and the recorded examples, is [`docs/AGENTS.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/AGENTS.md).
@@ -20,7 +20,7 @@ The full reference, with every tool's arguments and result shape and the recorde
## Tools
-60 tools. Reading never asks you; a tool that changes something asks you in the window the first time (Consent, below).
+77 tools. Reading never asks you; a tool that changes something asks you in the window the first time (Consent, below).
| Group | Tools | Kind |
| --- | --- | --- |
@@ -34,6 +34,11 @@ The full reference, with every tool's arguments and result shape and the recorde
| NMR prediction (0.9.0) | `predict_nmr` (read); `predict_spectrum` (change) | |
| Spectra (0.9.0) | `open_spectrum`, `spectrum_pick_peaks`, `spectrum_integrate` (change); `spectrum_data`, `spectrum_peaks`, `spectrum_export` (read) | |
| 3D (0.10.0) | `build_3d`, `conformers_3d`, `minimise_3d`, `open_3d_structure`, `extract_ligand` (change); `measure_3d` (read); `scan_dihedral` (change only with `store`); `export_3d` (change only when it writes outside the temporary folder) | |
+| Databases (0.11.0) | `db_create`, `db_open`, `db_add_record`, `db_update_record` (change); `db_list`, `db_search`, `db_get_record` (read); `db_import` (change unless `dry_run`); `db_export` (change only when it writes outside the temporary folder) | |
+| Notebook (0.11.0) | `nb_add_entry` (change); `nb_search` (read) | |
+| Library (0.12.0) | `library_add` (change); `library_list`, `live_structure_object` (read) | |
+| HELM (0.12.0) | `draw_from_helm` | change |
+| xtb and CREST (0.12.0) | `xtb_optimise`, `crest_conformers` (need the programs installed) | change |
| Window and extensions | `list_commands`, `extensions_list` (read); `run_command`, `extension_command` (change) | |
| Handoff | `handoff` | change with a state |
| Reactions (0.5.0) | `perceive_reactions`, `map_reaction` (change); `export_reaction`, `reaction_stoichiometry` (read) | |
@@ -78,6 +83,21 @@ The full reference, with every tool's arguments and result shape and the recorde
| `open_3d_structure {path, doc?, as?, x?, y?}` | a PDB or mmCIF file as a 3D object (cartoon, ligand in focus, the file kept as it is), or SD and MOL records as structures with their file coordinates |
| `extract_ligand {doc?, object?, ligand?}` | a ligand of a PDB or mmCIF model as a structure beside it, with its SMILES and whether its bond orders were inferred |
| `export_3d {doc?, object?, format?, conformer?, output?}` | MOL, SD, PDB or XYZ text with every hydrogen, or a new file |
+| `db_list`, `db_create {title, path?}`, `db_open {path}` | the open and known databases; make or open an `.fcdb` file and get its handle, record count, fields and whether it is read-only ([Databases](Databases)) |
+| `db_import {path, db?, format?, mode?, key?, mapping?, dry_run?, wait?}` | SD, RD, SMILES, CSV, TSV or `.fchem` records as a job: added, updated and failed, with each failed record's number and reason |
+| `db_search {db?, smiles?, mode?, threshold?, smarts?, query?, within?, name?, limit?}` | substructure, similarity (with scores), exact or a full query; the hit list with its first rows, which you also see in the window |
+| `db_get_record {uid, db?}` | one record with its molfile, keys, field values and files |
+| `db_add_record {smiles or molfile, db?, values?, on_duplicate?}` | registers a structure; a duplicate is refused with the matches until the agent chooses existing, batch or new |
+| `db_update_record {uid, db?, smiles?, molfile?, values?}` | changes a record's structure or field values |
+| `db_export {format, db?, path?, hitlist?, uids?, fields?, v3000?, structure_as?}` | SD, SMILES or CSV of a hit list, some records or the whole database |
+| `nb_add_entry {db, title, template?, date?, author?, procedure?, observations?, tags?, products?, reaction? or doc?}` | an open (unsigned) notebook entry with its scheme and the stoichiometry computed from it ([Lab Notebook](Lab-Notebook)) |
+| `nb_search {db, query?, substructure?, limit?}` | notebook entries by words or by a substructure of their scheme, newest first |
+| `library_list {kind?}` | the shared structure library's items ([Live Structures](Live-Structures)) |
+| `library_add {smiles or doc, ids?, name?, kinds?}` | adds a structure as a favourite, template, recent or live item, with pictures that keep the drawing inside |
+| `live_structure_object {id}` | the JSON a sibling Form app stores for a live structure |
+| `draw_from_helm {helm, doc?, x?, y?, name?}` | a peptide or nucleic acid from HELM as atoms, one undo step ([Biopolymers](Biopolymers)) |
+| `xtb_optimise {object?, method?, charge?, uhf?, solvent?, single_point?, level?, limit?}` | an xtb optimisation or single point stored as the structure's conformer, with the energy in hartree and kcal/mol ([3D](3D)) |
+| `crest_conformers {object?, method?, solvent?, ewin?, keep?, limit?}` | a CREST conformer ensemble with populations |
| `list_commands`, `run_command` | the window's command catalogue, the same commands as the menus |
| `extensions_list`, `extension_command` | Form extensions and their commands |
| `handoff {state?, note?}` | working, ready or question, with a note the person sees |
@@ -98,6 +118,10 @@ From 0.9.0: `draw_from_name {name: "ethyl ethanoate"}` draws a name exactly as `
From 0.10.0: `build_3d {object}` builds a conformer and says whether every drawn stereocentre was kept ("all 11 stereo labels kept" for Taxol), so an agent checks that line before using the geometry; `measure_3d {atoms: [C, O]}` then reads ethanol's C-O as 1.42 Å with the method. `conformers_3d`, `minimise_3d` and `scan_dihedral` give energies with their force field and engine version; a scan stores nothing unless `store` is true. `open_3d_structure {path}` opens a PDB or mmCIF file as a 3D object and lists its chains, ligands and waters, `extract_ligand` turns one ligand into a structure (saying when its bond orders were inferred), and `export_3d` returns MOL, SD, PDB or XYZ text. An edit to a structure's atoms or bonds removes its conformers, so build again after editing. Styles, surfaces and the PNG and glTF exports of the 3D View are window commands (`style-ballstick`, `surface-vdw`, `export-gltf` and the rest) for `run_command`.
+From 0.11.0: `db_open {path}` (or `db_create {title}`) gives a database handle; with one database open the other `db_` tools can leave `db` out. `db_import {path, dry_run: true}` counts what would be added and failed before the real import, and a bad record never stops it. `db_search {smiles: "c1ccccc1"}` answers the hit list, its count, the time and the method, and the hit list appears in your window too. `db_add_record` refuses a duplicate and lists the matches until the agent chooses `on_duplicate`. `nb_add_entry` writes an open entry from reaction SMILES or a drawing; only you sign entries. Every write is recorded with the agent's name in the database's log and in Agent Activity.
+
+From 0.12.0: `library_add {smiles: "Oc1ccccc1", name: "Phenol"}` adds a structure to the shared library (asking you the first time), `library_list` lists it and `live_structure_object {id}` returns the object a sibling app stores. `draw_from_helm {helm: "PEPTIDE1{G.G}$$$$"}` draws glycylglycine; bad HELM is refused with the character where reading stopped. `xtb_optimise` and `crest_conformers` wait for xtb or CREST and store the result as conformers in one undo step; when the programs are not installed they say where to get them, because FormChem never includes or downloads them.
+
Which drawing: `doc` when given; else the only open drawing; else the drawing the window shows; else the tool asks for `doc`. Coordinates are points, x right and y down; the default bond length is 14.4 points.
`get_context` lists every drawing open, oldest first, as text and in `structuredContent.documents`:
@@ -153,4 +177,4 @@ Every tool call, from any transport or from the window's own chat, is logged by
## Skills
-`formchem-harness` (using FormChem: drawing with the tools, checking with render and get_structure, names, NMR prediction and spectra, 3D, commands, reactions, analysis, handoff) and `formchem-skillset` (developing FormChem), in `.claude/skills` and mirrored to `.agents/skills`. The harness's `references/tools.md` is generated from the server and lists every argument.
+`formchem-harness` (using FormChem: drawing with the tools, checking with render and get_structure, names, NMR prediction and spectra, 3D and xtb, databases and the notebook, the structure library and HELM, commands, reactions, analysis, handoff) and `formchem-skillset` (developing FormChem), in `.claude/skills` and mirrored to `.agents/skills`. The harness's `references/tools.md` is generated from the server and lists every argument of all 77 tools.
diff --git a/.docs/wiki/Architecture.md b/.docs/wiki/Architecture.md
index 2a1226aa..80f6d973 100644
--- a/.docs/wiki/Architecture.md
+++ b/.docs/wiki/Architecture.md
@@ -2,18 +2,27 @@
```
frontend/ vanilla TypeScript and Vite: engine/ (model, ops, document client, session, reactions-api, names-api, nmr-api, spectra-api,
- three-api, stale), chem/ (valence, rings, formula, stoich, spectrum-ops, elements3d, geom3d, conformer-mol), canvas/ (view, hit
+ three-api, stale, database-api), chem/ (valence, rings, formula, stoich, spectrum-ops, elements3d, geom3d, conformer-mol), canvas/ (view, hit
testing, tools, spectrum-links, render/ with one module per object kind, spectrum and its data cache and model3d included),
app/ (menus, shell, canvas, object and reaction commands, documents, window tools, agent-window, agent-calls, agent-activity,
- name, nmr, spectrum and 3D commands), ui/ (shell, menus, Home, Preferences, tool rail, Analysis and Stoichiometry panels,
+ name, nmr, spectrum, 3D, database, live structure, HELM and xtb commands), canvas/a11y/ (keyboard focus, spoken atoms
+ and bonds, palettes), ui/ (shell, menus, Home, Preferences, tool rail, Analysis and Stoichiometry panels, Structure
+ Library, file changed bar, announcer, Structure Summary, HELM and xtb dialogs,
template library, Agent activity panel, agent chip, name dialog, Spectrum editor, 3D View panel with its viewer, lazy 3Dmol.js
- loader and dialogs), io/ (glb), dock/, extensions/, styles/
+ loader and dialogs, database/ (the database workspace, table, gallery, form and dialogs), database-find/ (search, query
+ builder, hit lists, saved queries, import, export, plot), notebook/ (the notebook view and entry editor)), io/ (glb), dock/,
+ extensions/, styles/
backend/ FastAPI engine: core/ (config, guard, window key, seal, agent token), routers/ (system, live, library, commands, documents, chem, reactions,
- templates, terminal, chat, extensions, mcp, agent_activity, names, nmr, spectra, three_d), services/ (model, ops, store, history,
- package, importers, templates, agent_out, agent_draw, agent_edits, agent_convert, agent_log, chem/ on RDKit and Indigo, names/ (the
- name engines), nmr/ (the increment predictor), spectra/ (the JCAMP-DX reader and spectrum service), three_d/ (3D building,
- conformers, force fields, scans, PDB and mmCIF readers, ligands, the stale-conformer rule)), data/templates/, data/names/
-src-tauri/ the desktop shell; the frozen engine runs from a folder inside the app on macOS and as a sidecar elsewhere
+ templates, terminal, chat, extensions, mcp, agent_activity, names, nmr, spectra, three_d, databases, db_search, notebook,
+ structures, describe, helm, xtb), services/ (model, ops, store, history, package, importers, templates, agent_out, agent_draw,
+ agent_edits, agent_convert, agent_log, agent_db, agent_notebook, agent_library, agent_helm, agent_xtb, live_structures,
+ file_watch, describe, helm/ (HELM reader, writer, monomers), xtb/ (finding and running xtb and CREST), chem/ on RDKit and Indigo, names/ (the name engines), nmr/ (the increment predictor),
+ spectra/ (the JCAMP-DX reader and spectrum service), three_d/ (3D building, conformers, force fields, scans, PDB and mmCIF
+ readers, ligands, the stale-conformer rule), database/ (the .fcdb store, registration, fields, import, export, search, hit
+ lists, the command line), notebook/ (entries, the content hash, schemes, export)), data/templates/, data/names/,
+ data/helm_monomers.json
+src-tauri/ the desktop shell; the frozen engine runs from a folder inside the app on macOS and as a sidecar elsewhere; the deep link
+ plugin registers formai://
```
## The engine owns the document
@@ -64,6 +73,30 @@ From 0.10.0 the engine's `services/three_d/` (routes under `/api/documents/{id}/
- **Structure files stay as files.** A PDB or mmCIF file read by FormChem's own readers becomes a `model3d` object over the bytes kept as media, so saving, exporting and pasting carry the original file. 3D SD and MOL records become structures whose file coordinates are their conformer.
- **The window shows, the engine computes.** The 3D View panel loads 3Dmol.js on first use (its own chunk, so startup is unaffected), reads a structure as a molfile with an atom map from the engine (or writes one locally from the stored conformer), and measures in the window with the engine's formulas. A `model3d` on the page is drawn as a PNG snapshot of the view; the panel writes a new snapshot, the camera and the style in one coalesced transaction after the person changes the view, and the renderer keeps the old picture until the new one has loaded, so the page never flashes. Exports and print use the snapshot and need no 3D renderer.
+## Databases and the notebook
+
+From 0.11.0 the engine's `services/database/` and `services/notebook/` (routes under `/api/databases`) keep structure databases and lab notebook entries. They live beside the document store, not in it: a database is not a drawing, has no undo stack and is not sent as transactions. ([`docs/DATABASE.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/DATABASE.md), [`docs/DATABASES.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/DATABASES.md))
+
+- **One file, one connection, one lock.** Each open `.fcdb` is a handle (`g` and eight characters) with one SQLite connection and a lock; every write is one `BEGIN IMMEDIATE ... COMMIT` and one audit row, and reads take the same lock. A lock file beside the database makes a second FormChem or the command line open it read-only.
+- **Chemistry enters through one function.** `database/chem.py` `register_values` computes the keys, formula, masses and both fingerprints of every stored structure and of every exact query, so they always agree.
+- **Search screens in memory.** `database/search.py` keeps each database's fingerprints as numpy arrays, refreshed only when the record count, the newest id or the newest audit row moves; substructure hits are screened there and confirmed by an RDKit SubstructLibrary, similarity is computed for every row at once, and every query term is a mask. Every search is stored as a hit list.
+- **Long work runs as jobs.** Imports and large exports run on worker threads in batches of 250 records, each its own transaction, with a report of failed records the window polls.
+- **Everyone hears about it, after the commit.** Each write broadcasts `{t: "database", db, change, uids?}` on the live channel once committed. The window's workspace refetches only the rows or lists the message names; rows are paged in blocks of 100, pooled and keyed by uid, so a 10,000 record table never rebuilds.
+- **The notebook reuses the chemistry.** An entry's scheme is a one-page FormChem document; its stoichiometry is computed on every read by the reaction services, and its content hash covers the scheme, text, products, tags and file hashes, so signing can tell when it changed.
+- **Pictures have their own key.** Database reads need the window key; thumbnails and attachments, loaded by image and link tags, take a second view key that opens only those two routes.
+
+## Family integration
+
+From 0.12.0 FormChem shares structures with the other Form apps and runs outside programs, without changing the document flow. ([`docs/LIVE_STRUCTURES.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/LIVE_STRUCTURES.md), [`docs/HELM.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/HELM.md), [`docs/3D.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/3D.md))
+
+- **The library is plain files.** `services/live_structures.py` writes `Library/library.json` and an SVG, PNG and molfile per item, each through a temporary file and a rename, the index last, so sibling apps read it without FormChem running.
+- **A live drawing is an ordinary drawing with a link.** Opening an item makes a normal session from the drawing inside its SVG and keeps `{id, rev, from}` beside it in memory; Save rewrites the item and raises its revision instead of writing a `.fchem`, and the engine broadcasts `live-structure`. Nothing is written into the drawing, so Save As copies are ordinary.
+- **Three ways in.** The window's commands, `./formchem edit-live` (which posts with the agent token, the one thing that token may write outside `/mcp`) and the `formai://formchem/edit` deep link, which the desktop shell receives through tauri-plugin-deep-link and the main window alone handles.
+- **The file watch polls.** Once a second the engine compares the size and time of each open drawing's file and broadcasts `file-changed` when another program moved it; FormChem's own saves are recognised by the `modified` time inside the file.
+- **Accessibility sits in front of the canvas.** The keyboard route in `canvas/a11y/` is installed before the canvas's own key handler, moves the view's keyboard cursor, and speaks through one shared live region; `POST /api/describe` gives the summary with the method of each part.
+- **HELM becomes atoms.** `services/helm/` reads HELM against FormChem's own monomer data and joins monomers into one RDKit molecule, which enters the drawing as an ordinary fragment through the template placement path, one transaction.
+- **xtb and CREST run outside.** `services/xtb/` finds the programs the person installed, runs one job at a time as a separate process in its own folder, and writes the result back as one 3D transaction with the stale-conformer check, as the 0.10.0 3D routes do.
+
## Guarding the engine
The engine binds to 127.0.0.1. A local guard refuses requests whose Host or Origin is not local, and a window key made at each start lets only the FormChem window change settings, use the terminal dock or answer an agent's question. Saved agent choices are sealed with a key in the system keychain. From 0.8.0 the MCP endpoint also needs the agent token (`core/agent_token.py`, the file `agent-token` in the data folder), which the stdio relay and the agent configs send.
diff --git a/.docs/wiki/Biopolymers.md b/.docs/wiki/Biopolymers.md
new file mode 100644
index 00000000..35081f16
--- /dev/null
+++ b/.docs/wiki/Biopolymers.md
@@ -0,0 +1,27 @@
+# Biopolymers
+
+From 0.12.0 FormChem reads peptides and nucleic acids written in HELM and writes structures back to HELM. The full guide is [`docs/HELM.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/HELM.md).
+
+## From HELM
+
+Insert > Biopolymer from HELM... reads as you type: the structure, the number of monomers, the formula and the masses with their method, or the character where reading stopped. Insert places it as atoms, one undo step.
+
+| Try | What it is |
+| --- | --- |
+| `PEPTIDE1{G.G}$$$$` | glycylglycine |
+| `PEPTIDE1{C.Y.I.Q.N.C.P.L.G.[am]}$PEPTIDE1,PEPTIDE1,1:R3-6:R3$$$V2.0` | oxytocin with its disulfide |
+| `RNA1{R(A)P.R(U)}$$$$` | the dinucleotide ApU |
+
+Read: PEPTIDE, RNA and CHEM simple polymers, RNA branches such as `R(A)P`, whole repeat counts, inline SMILES monomers and connections (disulfides, lactam bridges, rings). Refused, with the reason: mixtures, BLOBs, repeat ranges, hydrogen-bond pairs and unknown attachment points.
+
+## To HELM
+
+Edit > Copy As > Copy as HELM writes a peptide or nucleic acid drawn as atoms back to HELM, with its connections. FormChem copies it only when the HELM reads back to the same structure; otherwise it tells you which piece it could not match.
+
+## The monomers
+
+55 monomers written for FormChem from textbook structures: the 20 amino acids and their 19 D forms (`[dA]` and so on), Aib, Nle, Orn, Sar, Hyp and pyroglutamate (`[pE]`), the caps `[ac]` and `[am]`, ribose `R` and deoxyribose `[dR]`, phosphate `P`, and the bases A, C, G, U and T. No HELM monomer library was copied. Anything else can be written as inline SMILES.
+
+## Agents
+
+`draw_from_helm` draws a HELM string in a drawing as one undo step; see [Agents](Agents).
diff --git a/.docs/wiki/Command-Line.md b/.docs/wiki/Command-Line.md
index 90f45f8c..81857234 100644
--- a/.docs/wiki/Command-Line.md
+++ b/.docs/wiki/Command-Line.md
@@ -1,6 +1,6 @@
# Command Line
-From 0.7.0 four commands work on whole files of structures without the window: convert between formats, convert a folder, write properties to a CSV file and draw every record as a picture. They run from the source tree with the engine's Python; the full reference with timings is [`docs/CLI.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/CLI.md).
+From 0.7.0 four commands work on whole files of structures without the window (and from 0.11.0 `./formchem db` works on databases, and from 0.12.0 `./formchem edit-live` opens a live structure in the running FormChem, both below): convert between formats, convert a folder, write properties to a CSV file and draw every record as a picture. They run from the source tree with the engine's Python; the full reference with timings is [`docs/CLI.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/CLI.md).
## The four commands
@@ -35,6 +35,44 @@ A record that cannot be read never stops the run. The first 20 failures are prin
On a two-core machine, 10,000 SD records convert to SMILES in about 1.4 seconds, to InChIKey in about 4 seconds, and with standardising in about 22 seconds. `--jobs N` (0 for one per CPU) uses several processes for large files and folders, with the output always in input order.
+## Databases
+
+From 0.11.0 `./formchem db` works on structure databases ([Databases](Databases)) without the window:
+
+| Command | What it does |
+| --- | --- |
+| `./formchem db create TITLE [--path FILE.fcdb]` | makes a database (in the `Databases` folder of the data folder unless `--path` says otherwise) |
+| `./formchem db info DB` | title, record and entry counts, duplicate rules and fields |
+| `./formchem db import DB FILE` | imports SD, RD, SMILES, CSV, TSV, `.fchem`, molfile or InChI files; `--mode` new, append or merge, `--key`, `--dry-run`, `--errors failed.csv` |
+| `./formchem db search DB --substructure SMILES` | also `--similarity SMILES --threshold 0.7`, `--exact`, `--formula C6-8N1` or `--query JSON`; prints the first 20 hits (`--show N`) and keeps the hit list for the window |
+| `./formchem db export DB OUT` | the whole database or `--hitlist ID` to SD (`--v3000`), SMILES or CSV (`--inchi`), `--fields a,b` |
+
+```
+./formchem db create Demo
+./formchem db import ~/formchem/Databases/Demo.fcdb big.sdf --errors failed.csv
+./formchem db search ~/formchem/Databases/Demo.fcdb --substructure c1ccccc1
+./formchem db export ~/formchem/Databases/Demo.fcdb hits.sdf --hitlist 1
+```
+
+Every subcommand takes `--json`. The command ends with 0 on success, 1 when an import did not finish and 2 when it was refused. A database open in the app opens read-only here, and the other way round.
+
+## Editing a live structure
+
+From 0.12.0 `./formchem edit-live` asks the FormChem that is running to open a structure from the shared structure library for editing ([Live Structures](Live-Structures)). Sibling Form apps use it; so can a script.
+
+| Command | What it does |
+| --- | --- |
+| `./formchem edit-live ID` | opens library item `ID` (or the path of its `Library/items/ID.svg`) as a live drawing |
+| `./formchem edit-live --object FILE` | opens the live structure object saved in `FILE`, adding it to the library first when it is new or newer |
+| `--from APP` | names the app asking; the title bar shows "Live structure from APP" |
+
+```
+$ ./formchem edit-live s7jkf0w3t10 --from FormTxt
+Opened Phenol for editing in FormChem (live structure s7jkf0w3t10, rev 1).
+```
+
+It ends with 0 when the structure opened, 1 when FormChem is not running or refused, and 2 when the argument could not be read.
+
## Pictures from the command line
`render` draws with RDKit, close to the journal style (14.4 pt bonds, 0.6 pt lines, 10 pt Arimo labels, black on white), not with the window's own drawing code, so labels, wedges and double bonds can sit a little differently. For pictures exactly as the window shows them, with the drawing kept inside, use File > Export ([Formats and Export](Formats-and-Export)).
diff --git a/.docs/wiki/Databases.md b/.docs/wiki/Databases.md
new file mode 100644
index 00000000..30ccdee6
--- /dev/null
+++ b/.docs/wiki/Databases.md
@@ -0,0 +1,59 @@
+# Databases
+
+From 0.11.0 FormChem keeps compounds in structure databases. A database is one `.fcdb` file (a SQLite file any SQLite browser opens), so copying the file copies everything: records, your fields, files, hit lists, saved queries, forms and the [lab notebook](Lab-Notebook). The full guide is [`docs/DATABASES.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/DATABASES.md); the file and its routes are defined in [`docs/DATABASE.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/DATABASE.md).
+
+## A database in three steps
+
+1. File > New Database..., give it a title (it goes to the `Databases` folder of the data folder unless you choose one).
+2. Database > Import Records..., pick an SD, SMILES, CSV or TSV file, check the column mapping, press Check to see the counts, then Import.
+3. Click Structure beside the search bar with a ring drawn in a drawing, choose Substructure, and the hits appear as a hit list. Database > Export Records... writes them to SD.
+
+## The workspace
+
+| Part | What it does |
+| --- | --- |
+| Left column | open databases, hit lists (newest first, with counts) and saved queries in folders |
+| Search bar | names, ids, formulas (`C6-8N1`) and SMILES; Structure searches with your drawing |
+| Views | Table, Gallery, Form, Plot and Notebook, sharing one selection |
+| Toolbar buttons | Import, Export, Add Structure, Advanced Search and the gear menu (settings, fields, Save Query, Combine Hit Lists, New Notebook Entry) |
+
+File > Databases (`Ctrl+Shift+D`, `Cmd+Shift+D` on a Mac) shows and hides the workspace; Home's Databases list opens one. In a browser window, File > Open of an `.fcdb` file or a drop on Home copies it into the Databases folder and opens it.
+
+## Records and fields
+
+- The table sorts by any column, resizes, hides and freezes columns, and edits a field in place (double-click; Enter saves, Escape cancels). It loads rows as you scroll, so 10,000 records scroll at once.
+- Database > Fields... adds your own fields: text, numbers with units, dates, yes or no, choices, structures, files, links to other records, and computed descriptors (cLogP, TPSA and others) that follow the structure and name their method.
+- Structure > Add to Database registers a structure from a drawing. The rules in Database > Database Settings... decide what a duplicate is (stereo matched or ignored, salts stripped or kept); a dialog then offers Open Existing, Add as New Batch or Add Anyway. Registration numbers are never reused.
+- Enter on a record shows its details and files; Open in Drawing opens it as a drawing.
+
+## Searching
+
+| Search | How |
+| --- | --- |
+| Exact | the same compound, stereo, salts, charges and tautomers matched or ignored |
+| Substructure | contains the drawn structure (or a SMARTS in Advanced Search) |
+| Similarity | Tanimoto on Morgan fingerprints at or above a threshold (0.7), each hit with its score |
+| Formula | element counts or ranges, `C6-8H*N1O0-2` |
+| Fields | text, numbers, dates, choices, empty or not |
+
+Advanced Search... combines terms in All of, Any of and None of groups and can search within the current hit list. Every search becomes a hit list: keep it, rename it, export it, or combine two by union, intersection or difference. Save Query... keeps a query in a folder to run again.
+
+## Plot
+
+The Plot view draws a histogram of one field or a scatter of two with a least-squares line and R squared, coloured by a third field if you like. Drag a rectangle or lasso and choose Hit List from Selection.
+
+## Import and export
+
+Import reads SD (V2000 and V3000), RD, SMILES, CSV and TSV files and `.fchem` drawings, maps columns to fields (or new fields), and runs as new records, appended records or a merge that updates matching records. Check counts what would happen first. A bad record never stops an import; the report lists each one with its number and a plain reason. Export writes SD (every field as a data item), SMILES or CSV; an SD file exported and imported again keeps every InChIKey and field value.
+
+## When a database is read-only
+
+A database another FormChem (or the command line) has open opens read-only and says why; you can browse, search and export, but not change it.
+
+## Not yet
+
+- The desktop app's file choosers, Link File and dropping an `.fcdb` file on the desktop window were not tried for 0.11.0.
+- The workspace covers the in-window menu bar while it is open; its toolbar and gear menu carry the commands.
+- Record values, hit list names, saved query names and entry titles show as typed in every language; RDKit's own messages stay in English.
+
+See also [Lab Notebook](Lab-Notebook), [Command Line](Command-Line) for `./formchem db`, and [Agents](Agents) for the database tools.
diff --git a/.docs/wiki/Getting-Started.md b/.docs/wiki/Getting-Started.md
index f0961efa..64d6d0e6 100644
--- a/.docs/wiki/Getting-Started.md
+++ b/.docs/wiki/Getting-Started.md
@@ -26,6 +26,18 @@ Aspirin, with the mouse and a few keys:
Faster: copy `CC(=O)Oc1ccccc1C(=O)O` and press `Ctrl+V` on the canvas, or use Insert > Structure from SMILES. Molfile, SDF, RXN, SMILES, InChI, CML, CDXML and CDX files open from File > Open or by dropping them on Home, PDB and mmCIF files open there as 3D objects, and Ctrl+3 shows a structure in 3D after 3D > Build 3D from 2D ([3D](3D)), and File > Export saves PNG, SVG, PDF and EPS pictures that open again as the drawing ([Formats and Export](Formats-and-Export)). The page is dark by default; View > Dark Page turns it off ([Grid and Page](Grid-and-Page)). [Drawing](Drawing) lists every tool and hover key, and how to draw with the keyboard alone.
+## A database in three steps
+
+1. File > New Database..., type a title and press Create. The database workspace opens with the empty database (an `.fcdb` file in the `Databases` folder of the data folder).
+2. Database > Import Records..., choose an SD, SMILES, CSV or TSV file, look over the column mapping, press Check for the counts, then Import. When it ends, the report lists any bad records with their reasons.
+3. Draw a benzene ring in a drawing (File > Databases, `Ctrl+Shift+D`, switches back and forth), select it, then click Structure beside the search bar and choose Substructure. The hits become a hit list in the left column; Database > Export Records... writes them to an SD file.
+
+[Databases](Databases) covers fields, duplicates, the plot and saved queries, and [Lab Notebook](Lab-Notebook) the notebook entries that live in the same file.
+
+## Without a mouse
+
+`Alt+Ctrl+A` (`Option+Cmd+A` on macOS) puts the keyboard focus on the drawing. On an empty drawing press Enter for a carbon, then Enter and an arrow key for each new bond, and type `O` on an atom to make it oxygen; every step is spoken by your screen reader. `Alt+Ctrl+S` (`Option+Cmd+S`) describes the whole structure. [Accessibility](Accessibility) has the keys and the element colours.
+
## Connect an agent
Claude Code, Codex, Cursor, Antigravity or any MCP client can draw in the window you have open:
@@ -49,6 +61,8 @@ An agent you connected to 0.7.0 over HTTP needs the token from 0.8.0 on: run `./
| `./formchem install-desktop`, `./formchem desktop dev`, `./formchem desktop build` | the Tauri desktop app |
| `./formchem freeze` | freeze the engine for the desktop app (a folder in `src-tauri/engine` on macOS, a one-file sidecar elsewhere) |
| `./formchem convert`, `batch`, `descriptors`, `render` | convert structure files and folders, write properties to CSV, draw every record ([Command Line](Command-Line)) |
+| `./formchem db create`, `info`, `import`, `search`, `export` | structure databases without the window ([Command Line](Command-Line)) |
+| `./formchem edit-live ID` | open a live structure from the shared library in the running FormChem ([Command Line](Command-Line)) |
| `./formchem i18n check`, `scan`, `export`, `import` | the interface languages: gaps, new strings, CSV out and in |
| `./formchem counts` | lines of code per language |
| `./formchem doctor`, `./formchem clean` | checks, cleanup |
@@ -61,4 +75,4 @@ Each command has a `formchem.bat` twin on Windows.
## Ports and folders
-The engine listens on 127.0.0.1:8220 (`FORMCHEM_PORT`), the Vite app on localhost:5220. The desktop shell starts the engine on a free port and prefers 8221. The data folder is `~/formchem` (`FORMCHEM_DATA_DIR`); it holds `settings.json`, `library.json` (Home's lists), `commands-catalogue.json`, `agent-token` (0.8.0), the `Agent log` folder (0.8.0) and, while the engine runs, `engine.json`.
+The engine listens on 127.0.0.1:8220 (`FORMCHEM_PORT`), the Vite app on localhost:5220. The desktop shell starts the engine on a free port and prefers 8221. The data folder is `~/formchem` (`FORMCHEM_DATA_DIR`); it holds `settings.json`, `library.json` (Home's lists), `commands-catalogue.json`, `agent-token` (0.8.0), the `Agent log` folder (0.8.0), the `Databases` folder (0.11.0; new databases, and the short-lived `.uploads` and `.exports` copies of a browser window), the `Library` folder (0.12.0; the shared structure library other Form apps read, [Live Structures](Live-Structures)) and, while the engine runs, `engine.json`.
diff --git a/.docs/wiki/Home.md b/.docs/wiki/Home.md
index 44d0170a..7025a9f0 100644
--- a/.docs/wiki/Home.md
+++ b/.docs/wiki/Home.md
@@ -2,7 +2,7 @@
FormChem is the chemical structure drawing suite of the FormAI family: local-first, no account, on macOS, Windows and Linux. It runs in the browser or as a Tauri desktop app, with a local engine that holds every document, and an MCP server so Claude Code, Codex, Cursor or Antigravity can work in the same window you see.
-FormChem is in development. 0.1.0 is the family skeleton (dispatcher, engine, window, desktop shell, CI) and 0.2.0 the family shell (title bar, menus, Home, Preferences, the terminal and agent dock, extensions, Help and updates). 0.3.0 added documents and the RDKit chemistry engine, 0.4.0 the drawing canvas, its tools and hover keys, and the Analysis panel, 0.5.0 reactions and annotations: arrows and the other drawn objects, reaction perception, atom mapping, balance and stoichiometry, the template library, Find and rulers, and 0.6.0 stereo, queries and analysis: CIP labels and enhanced stereo, abbreviations, query structures and R-groups, calculated properties with their methods, the structure check and the isotope pattern. 0.7.0 is formats and exchange: chemistry files in and out with a report of what each format loses, pictures (PNG, SVG, PDF, EPS) that open again as the drawing, printing, the clipboard, Standardise and a command line for whole files, plus what the first desktop test asked for: a fast start on macOS, a clearer 2D layout, the dark page, resizing on the sheet and grids. 0.8.0 is agents: 42 MCP tools with which an agent makes and opens drawings, draws structures and reaction schemes from SMILES or molfiles, edits them atom by atom by id, reads them back and checks its work with a picture from the window's own renderer, each change one undo step, plus Agent Activity with undo and Stop, and an agent token for the HTTP endpoint. 0.9.0 is names, predictions and spectra: chemical names read into structures and written for them, offline with FormChem's own dictionary, systematic parser and round-trip-checked namer; 1H and 13C NMR spectra predicted by FormChem's own increment method, each value with its method and version; JCAMP-DX spectra opened as spectrum objects with peaks, integrals and multiplets linked to atoms in the Spectrum editor; and ten more agent tools (52). 0.10.0 is 3D: structures built in 3D from the drawing with their stereo checked, conformer searches, minimisation and dihedral scans with the force field and version beside each energy, measurements, surfaces with ESP, a 3D View panel and 3D views placed on the page, PDB and mmCIF files opened as proteins with their ligands, ligands extracted as structures, PNG, glTF and 3D structure exports, and eight more agent tools (60). A structure database comes next.
+FormChem is in development. 0.1.0 is the family skeleton (dispatcher, engine, window, desktop shell, CI) and 0.2.0 the family shell (title bar, menus, Home, Preferences, the terminal and agent dock, extensions, Help and updates). 0.3.0 added documents and the RDKit chemistry engine, 0.4.0 the drawing canvas, its tools and hover keys, and the Analysis panel, 0.5.0 reactions and annotations: arrows and the other drawn objects, reaction perception, atom mapping, balance and stoichiometry, the template library, Find and rulers, and 0.6.0 stereo, queries and analysis: CIP labels and enhanced stereo, abbreviations, query structures and R-groups, calculated properties with their methods, the structure check and the isotope pattern. 0.7.0 is formats and exchange: chemistry files in and out with a report of what each format loses, pictures (PNG, SVG, PDF, EPS) that open again as the drawing, printing, the clipboard, Standardise and a command line for whole files, plus what the first desktop test asked for: a fast start on macOS, a clearer 2D layout, the dark page, resizing on the sheet and grids. 0.8.0 is agents: 42 MCP tools with which an agent makes and opens drawings, draws structures and reaction schemes from SMILES or molfiles, edits them atom by atom by id, reads them back and checks its work with a picture from the window's own renderer, each change one undo step, plus Agent Activity with undo and Stop, and an agent token for the HTTP endpoint. 0.9.0 is names, predictions and spectra: chemical names read into structures and written for them, offline with FormChem's own dictionary, systematic parser and round-trip-checked namer; 1H and 13C NMR spectra predicted by FormChem's own increment method, each value with its method and version; JCAMP-DX spectra opened as spectrum objects with peaks, integrals and multiplets linked to atoms in the Spectrum editor; and ten more agent tools (52). 0.10.0 is 3D: structures built in 3D from the drawing with their stereo checked, conformer searches, minimisation and dihedral scans with the force field and version beside each energy, measurements, surfaces with ESP, a 3D View panel and 3D views placed on the page, PDB and mmCIF files opened as proteins with their ligands, ligands extracted as structures, PNG, glTF and 3D structure exports, and eight more agent tools (60). 0.11.0 is databases and the lab notebook: structure databases in one `.fcdb` SQLite file with your own fields, registration with duplicate rules, exact, substructure, similarity, formula and field search, hit lists and saved queries, table, gallery, form and plot views, SD, SMILES and CSV import and export, notebook entries with schemes, stoichiometry, products and signing, `./formchem db`, eleven more agent tools (71), and a new app icon. 0.12.0 is family integration: live structures that keep their drawing inside when copied into other Form apps and come back editable, a shared structure library every Form app reads, a bar when a file changes on disk, keyboard and screen reader access with spoken atoms and a structure summary, high-contrast and colour-blind safe element colours, peptides and nucleic acids in HELM, xtb and CREST run when you have installed them, `./formchem edit-live`, and six more agent tools (77). Desktop builds, file associations, demos and the manual come next.
| Page | What it covers |
| --- | --- |
@@ -15,11 +15,16 @@ FormChem is in development. 0.1.0 is the family skeleton (dispatcher, engine, wi
| [Analysis](Analysis) | Calculated properties with their methods, the isotope pattern, Copy Analysis and Check Structure |
| [Names](Names) | Structure from Name, pasting a name, the Name section and Copy Name, what names are read and refused |
| [Spectra and NMR](Spectra-and-NMR) | JCAMP-DX spectra, the Spectrum editor, peaks, integrals and links to atoms, predicted 1H and 13C NMR |
-| [3D](3D) | The 3D View, Build 3D from 2D, conformers, minimising, dihedral scans, measuring, surfaces, 3D views on the page, PDB and mmCIF files, ligands and 3D exports |
+| [3D](3D) | The 3D View, Build 3D from 2D, conformers, minimising, dihedral scans, measuring, surfaces, 3D views on the page, PDB and mmCIF files, ligands, 3D exports, and xtb and CREST |
+| [Databases](Databases) | Structure databases: the workspace, fields, Add to Database and duplicates, search, hit lists, saved queries, the plot, import and export |
+| [Lab Notebook](Lab-Notebook) | Notebook entries with scheme, stoichiometry, procedure, products and files; search, signing and export |
+| [Biopolymers](Biopolymers) | Peptides and nucleic acids from HELM and back, and FormChem's own monomers |
+| [Live Structures](Live-Structures) | Copy as Live Structure, the shared Structure Library, editing again from a sibling app, and the file changed bar |
+| [Accessibility](Accessibility) | Keyboard focus on atoms and bonds, what is spoken, Describe Structure, element colours |
| [Formats and Export](Formats-and-Export) | Opening chemistry files and the import report, File > Import, exporting pictures that keep the drawing inside, exporting chemistry files, printing |
| [Clipboard](Clipboard) | Copy, Cut, Paste and Paste Special, Copy As, what goes on the clipboard and what each platform can do |
-| [Command Line](Command-Line) | Converting files and folders, properties to CSV and pictures of every record, with standardising and the failure report |
-| [Agents](Agents) | The MCP server and its 60 tools, drawing directly and from names, NMR, spectrum and 3D tools, agent configs, the agent token, skills, consent and Stop |
+| [Command Line](Command-Line) | Converting files and folders, properties to CSV and pictures of every record, with standardising and the failure report, `./formchem db` for databases and `./formchem edit-live` |
+| [Agents](Agents) | The MCP server and its 77 tools, drawing directly and from names and HELM, NMR, spectrum, 3D and xtb, database, notebook and library tools, agent configs, the agent token, skills, consent and Stop |
| [Agent Activity](Agent-Activity) | Every call agents made with undo for the latest one, the editing chip with Stop, and the call log |
| [Terminal](Terminal) | The terminal and agent dock |
| [Extensions](Extensions) | Form extensions in FormChem |
diff --git a/.docs/wiki/Lab-Notebook.md b/.docs/wiki/Lab-Notebook.md
new file mode 100644
index 00000000..890af340
--- /dev/null
+++ b/.docs/wiki/Lab-Notebook.md
@@ -0,0 +1,42 @@
+# Lab Notebook
+
+From 0.11.0 every [database](Databases) holds a lab notebook: one entry per experiment, with its reaction scheme, stoichiometry, procedure, observations, products and files, kept in the same `.fcdb` file as the compounds. The full guide is [`docs/DATABASES.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/DATABASES.md).
+
+## An entry in four steps
+
+1. Open a database and choose Database > Notebook > New Notebook Entry... (or New Entry in the Notebook view). Give a title, the experiment date and your name, and pick a template: Blank, Reaction, Analysis or Purification.
+2. Draw the reaction in a drawing and press New Scheme from Drawing; the stoichiometry table fills in from the scheme.
+3. Write the procedure and observations, add products with their sample id, mass, yield and purity, and link each to its record in the database.
+4. Sign Notebook Entry... when the experiment is written up.
+
+## What an entry holds
+
+| Part | Notes |
+| --- | --- |
+| Scheme | the first page of a drawing; Edit Scheme opens it on the canvas with a Save to Entry bar |
+| Stoichiometry | computed from the scheme every time (formula, MW, role, amount, equivalents) with its method; never typed |
+| Procedure, Observations | paragraphs separated by blank lines, `- ` bullets, `**bold**` and `*italic*`, with a preview |
+| Products | name, sample, mass, yield, purity, notes, and a link to the product's record |
+| Tags | separated by commas |
+| Files | stored up to 50 MB, or linked by path in the desktop app, each with its SHA-256 |
+
+Text saves a moment after you stop typing; other fields save when they change.
+
+## Finding entries
+
+The Notebook view lists entries newest first. The search box finds words in the title, procedure, observations, tags and sample ids (every word must appear); the substructure search finds entries whose scheme contains a structure, for example `NC=O` for amide couplings.
+
+## Signing
+
+Sign records your name, the time and a SHA-256 hash of the entry's content, including the hashes of its files, and keeps that content as a signed version. A change after signing marks the entry "Modified after signing"; the signed version stays as it was and opens read-only from the versions list. Sign Again records a new signed version. Agents can add entries but never sign them.
+
+## Exporting
+
+Export Notebook Entry... writes a self-contained HTML page (scheme picture, stoichiometry, text, products, files with their hashes, the signature and any "Modified after signing" banner; it needs no network and prints as shown) or JSON with the content, its hash and every version, so the hashes can be checked later.
+
+## Not yet
+
+- Entries hold no spectra or grid of their own; attach spectra as files.
+- Printing the HTML export, Link File and the save dialog in the desktop app were not tried for 0.11.0.
+
+See also [Databases](Databases) and [Agents](Agents) (`nb_add_entry`, `nb_search`).
diff --git a/.docs/wiki/Live-Structures.md b/.docs/wiki/Live-Structures.md
new file mode 100644
index 00000000..7458ba26
--- /dev/null
+++ b/.docs/wiki/Live-Structures.md
@@ -0,0 +1,43 @@
+# Live Structures
+
+From 0.12.0 a structure you copy from FormChem into another Form app (FormDeck, FormTxt, form.md) stays a FormChem drawing: the picture carries the drawing inside, and FormChem opens it again for editing. The full guide is [`docs/LIVE-STRUCTURES.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/LIVE-STRUCTURES.md); the contract sibling apps follow is [`docs/LIVE_STRUCTURES.md`](https://github.com/nodemode-dev/formchem/blob/main/docs/LIVE_STRUCTURES.md).
+
+## A live structure in three steps
+
+1. Select a structure and choose Edit > Copy As > Copy as Live Structure.
+2. Paste it into the other Form app. It shows the picture.
+3. To change it, the other app opens it in FormChem (a `formai://formchem/edit` link, `./formchem edit-live`, or opening its picture). Edit, then press `Mod+S`: the picture is rewritten with a higher revision and the other app shows the new one.
+
+## The Structure Library
+
+Window > Structure Library... shows every structure you starred, copied, saved as a template or placed as a live structure:
+
+| Tab | How a structure gets there |
+| --- | --- |
+| Favourites | Structure > Star Structure |
+| Recent | Copy as Live Structure, or inserting from the library (newest 50 kept) |
+| Templates | File > Save as Template to Library... |
+| Live | Copy as Live Structure |
+
+Search by name, formula or SMILES; Insert, Open, Copy as Live Structure, Unstar and Delete work on the chosen tile. The library is plain files in `~/formchem/Library/` (a `library.json`, and an SVG, PNG and molfile per item), so other Form apps read it without FormChem running.
+
+## A live drawing
+
+- The title bar shows "Live structure from [app]".
+- Save asks for no path; it saves to the library item. Closing with unsaved changes and choosing Save does the same.
+- Save As makes an ordinary `.fchem` copy.
+- A live structure from another computer joins your library with its own id; an older copy never overwrites a newer edit.
+
+## Dropping and pasting
+
+Drop a FormChem picture or a live structure on the canvas to insert it there; hold Alt, or drop with no drawing open, to open it as its own drawing. Pasting one inserts the drawing inside it.
+
+## When a file changes outside FormChem
+
+If the file of an open drawing changes on disk, a bar over the canvas offers Reload (undoable) or Keep Mine (your next save wins). FormChem's own saves never show it.
+
+## Not yet
+
+- No sibling app was run against this for 0.12.0; the files and the clipboard were checked against the contract.
+- The desktop app's own clipboard and a real `formai://` link were not tried; from a browser window other apps get the HTML picture and the images.
+- Dragging a structure out of FormChem does not carry a live structure yet.
diff --git a/.docs/wiki/_Sidebar.md b/.docs/wiki/_Sidebar.md
index aef50456..868989a9 100644
--- a/.docs/wiki/_Sidebar.md
+++ b/.docs/wiki/_Sidebar.md
@@ -11,6 +11,11 @@
- [Names](Names)
- [Spectra and NMR](Spectra-and-NMR)
- [3D](3D)
+- [Databases](Databases)
+- [Lab Notebook](Lab-Notebook)
+- [Biopolymers](Biopolymers)
+- [Live Structures](Live-Structures)
+- [Accessibility](Accessibility)
- [Formats and Export](Formats-and-Export)
- [Clipboard](Clipboard)
- [Command Line](Command-Line)
diff --git a/AGENTS.md b/AGENTS.md
index 0bced17a..5f8fe7dc 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -2,7 +2,7 @@
FormChem exposes an MCP server at http://127.0.0.1:8220/mcp (stdio: `./formchem mcp`, which runs `setup/mcp_stdio.py`). Configs: .codex/config.toml, .cursor/mcp.json, .mcp.json, and for Antigravity ~/.gemini/config/mcp_config.json. Run `./formchem agents install` to install them and the skills for your home folder too.
-HTTP requests need the agent token (`./formchem agents token`; `agents install` writes it into the configs; the stdio transport sends it itself). FormChem has 60 tools. Reading is open; changing tools make the window ask the person the first time, and the person can Stop an agent. Since 0.8.0 agents draw directly: get_context or list_open_documents first; draw_from_smiles and draw_from_molfile place a structure as one undo step and answer with ids, SMILES, InChIKey, formula and a picture; get_atoms names atoms and bonds for the edit tools (add_atom, add_bond, set_charge, set_atom, set_stereo, replace_substructure, delete, move, scale, align, clean_layout, add_arrow, add_text, add_reaction), one undo step each; render, get_structure and validate check the result; convert and batch_convert match the CLI. Since 0.9.0 draw_from_name and name_structure read and write names offline, predict_nmr and predict_spectrum predict 1H and 13C NMR, and the spectrum tools open, read, pick, integrate and export JCAMP-DX spectra. Since 0.10.0 build_3d builds a structure in 3D and reports whether every stereo label was kept, conformers_3d, minimise_3d, scan_dihedral and measure_3d work on its conformers with the force field and version beside each number, open_3d_structure opens PDB, mmCIF, SDF and MOL files, extract_ligand turns a bound ligand into a structure, and export_3d writes MOL, SDF, PDB or XYZ. Reaction and analysis tools, list_commands and run_command for the window's commands, Form extensions and handoff to the person (question when you need their input) are there too. The skill packs live in .agents/skills: formchem-harness (using FormChem) and formchem-skillset (developing FormChem). The document contract is docs/FORMAT.md.
+HTTP requests need the agent token (`./formchem agents token`; `agents install` writes it into the configs; the stdio transport sends it itself). FormChem has 77 tools. Reading is open; changing tools make the window ask the person the first time, and the person can Stop an agent. Since 0.8.0 agents draw directly: get_context or list_open_documents first; draw_from_smiles and draw_from_molfile place a structure as one undo step and answer with ids, SMILES, InChIKey, formula and a picture; get_atoms names atoms and bonds for the edit tools (add_atom, add_bond, set_charge, set_atom, set_stereo, replace_substructure, delete, move, scale, align, clean_layout, add_arrow, add_text, add_reaction), one undo step each; render, get_structure and validate check the result; convert and batch_convert match the CLI. Since 0.9.0 draw_from_name and name_structure read and write names offline, predict_nmr and predict_spectrum predict 1H and 13C NMR, and the spectrum tools open, read, pick, integrate and export JCAMP-DX spectra. Since 0.10.0 build_3d builds a structure in 3D and reports whether every stereo label was kept, conformers_3d, minimise_3d, scan_dihedral and measure_3d work on its conformers with the force field and version beside each number, open_3d_structure opens PDB, mmCIF, SDF and MOL files, extract_ligand turns a bound ligand into a structure, and export_3d writes MOL, SDF, PDB or XYZ. Since 0.11.0 db_list, db_create and db_open reach structure databases (.fcdb files), db_import fills one (dry_run first; read the failed-record report), db_search searches by substructure, similarity (read each score), exact match or a query node and leaves a hit list the person sees, db_get_record, db_add_record (a duplicate is refused until you choose on_duplicate) and db_update_record work on records, db_export writes SD, SMILES or CSV, and nb_add_entry and nb_search keep lab notebook entries, which only the person signs. Since 0.12.0 library_list, library_add and live_structure_object reach the shared structure library every Form app reads, draw_from_helm draws a peptide or nucleic acid from HELM, and xtb_optimise and crest_conformers run xtb and CREST only when the person installed them (never shipped; quote program, version, method and solvent with each energy). Reaction and analysis tools, list_commands and run_command for the window's commands, Form extensions and handoff to the person (question when you need their input) are there too. The skill packs live in .agents/skills: formchem-harness (using FormChem) and formchem-skillset (developing FormChem). The document contract is docs/FORMAT.md; the database and notebook contract is docs/DATABASE.md; the structure library and live structure contract is docs/LIVE_STRUCTURES.md.
Clean room (details in CLAUDE.md): FormChem is written only from the owner's clean-room specifications. Never open, run, decompile or read the private documentation of the commercial suite it replaces, and never copy its names, icons, templates or text. Vendor names appear only to name file formats.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9da2bab..2b1de3a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,122 @@
Versions follow `v*.*.*` with dots. Dates are US Eastern.
+## 0.12.0 · 2026-12-05
+
+Family integration: a structure you copy out of FormChem into another Form app stays a FormChem drawing, and comes back editable. Copy as Live Structure puts the structure on the clipboard with its drawing inside and keeps it in a shared structure library that every Form app can read; a sibling app asks FormChem to edit it again with a `formai://formchem/edit` link or `./formchem edit-live`, and saving writes the new picture back for the sibling. FormChem can now be used from the keyboard alone, speaks every atom and bond it focuses, describes a whole structure in words, and offers high-contrast and colour-blind safe element colours. Peptides and nucleic acids written in HELM become structures and go back to HELM, and xtb and CREST run as programs you install yourself. Agents reach the library, HELM and xtb through six new MCP tools.
+
+### New
+
+- Edit > Copy As > Copy as Live Structure copies the selection (or the page) as a live structure: the clipboard holds the picture as SVG and PNG with the FormChem drawing inside, an HTML picture carrying the live structure object, the SMILES and FormChem's own drawing, and the structure joins the shared structure library with the Live and Recent kinds. Pasting it back into FormChem gives the editable structure.
+- The shared structure library is a plain folder, `Library/` in FormChem's data folder (by default `~/formchem/Library/`), with `library.json`, an SVG, a PNG and a molfile per item, so other Form apps read it without FormChem running. Its layout, the live structure object and the clipboard flavour are written down for sibling app authors in `docs/LIVE_STRUCTURES.md`.
+- Window > Structure Library... shows the library in four tabs (Favourites, Recent, Templates and Live) with a search box. Insert places an item on the page, Open opens it in its own drawing, and Unstar, Delete and Copy as Live Structure work on the item. Structure > Star Structure adds the selection to Favourites, and File > Save as Template to Library... adds it to Templates; a structure already in the library gains the new kind instead of a second copy. Recent keeps the newest 50.
+- Editing a live structure: a sibling app opens it with the link `formai://formchem/edit?id=...` (the desktop app registers the `formai` scheme), with `./formchem edit-live ID`, or by opening the item's SVG. FormChem opens it in a drawing marked "Live structure from" the sibling beside the title. Save (`Mod+S`) asks for no path: it writes the item's picture and molfile and raises its revision, so the sibling can show the new picture. Save As makes an ordinary copy, and closing an unsaved live drawing saves the item. A live structure from another computer is added to the library with its own id and revision.
+- Dropping a FormChem picture or a live structure onto the canvas inserts it at the drop point; with Alt held, or with no drawing open, it opens as a drawing of its own.
+- When the file of an open drawing changes on disk outside FormChem, a bar over the canvas says so and offers Reload (one undoable step) or Keep Mine (the next save writes over the outside change). FormChem's own saves never show it, and the canvas does not move when it appears.
+- Keyboard navigation: View > Focus Structure (`Alt+Mod+A`) puts the keyboard focus on the drawing. Tab and Shift+Tab walk the atoms in reading order, an arrow key moves along the bond nearest its direction, Ctrl, Cmd or Alt with an arrow walks bonds, Space selects, and Enter followed by an arrow draws a new bond, so a structure can be built without a mouse. View > Next Atom and Previous Atom (`Alt+Mod+]` and `Alt+Mod+[`) do the same from the menu. A ring around the focused atom or bond stays readable at any zoom.
+- Every move is spoken through the screen reader: the element by name, its charge, hydrogens, isotope, bonds and neighbours, ring size, its R or S label and its place, for example "Oxygen. 1 hydrogen. Single bond to Carbon. Not in a ring. Atom 3 of 3."
+- View > Describe Structure (`Alt+Mod+S`) speaks and shows a summary of the drawing: formula, name, charge, ring systems by name (benzene, pyridine, piperidine, purine and 47 others), functional groups from FormChem's own table of 42, and stereocentres with their R or S labels, each with the method that found it. Copy copies the summary.
+- Element colours: Standard, High contrast (every element at 7.38:1 or more against white) and Colour-blind safe (Okabe-Ito blue, vermillion, bluish green and reddish purple), chosen in Preferences > Interface or under View > Element Colours. The choice applies before the first drawing appears and to pictures and the clipboard, and switching repaints only the atom colours.
+- Insert > Biopolymer from HELM... reads HELM version 2 as you type, marks the character where reading stopped, and shows the structure, the number of monomers, the formula and the average and monoisotopic masses with their method; Insert places it as one undo step. Simple polymers, RNA branches such as `R(A)P`, whole repeat counts, inline SMILES monomers and connections (disulfides, lactam bridges, head-to-tail rings) are read. Oxytocin reads and is laid out in about a tenth of a second.
+- Edit > Copy As > Copy as HELM writes peptides and nucleic acids drawn as atoms back to HELM, with their disulfide, lactam and ring connections. HELM is copied only when it reads back to the same structure; anything FormChem cannot match is refused with the reason and the piece's formula.
+- HELM monomers are FormChem's own data, written from textbook structures: the 20 amino acids and 19 D forms, Aib, Nle, Orn, Sar, Hyp and pyroglutamate, the acetyl and amide caps, ribose, deoxyribose, phosphate and the five bases (55 in all).
+- 3D > Optimise with xtb... and 3D > Conformer Search with CREST... run xtb and CREST on the selected structure when you have installed them: GFN2-xTB or GFN-FF, charge, unpaired electrons, an ALPB implicit solvent from 24, the optimisation level or the energy window, threads and a time limit, with progress, Cancel Job and the program's last lines when a run fails. Results become the structure's conformers as one undo step, with the energy in hartree and kcal/mol, the HOMO-LUMO gap and a label naming the program, its version, the method and the solvent; CREST conformers that lost the drawn stereo are dropped and counted.
+- Preferences > 3D > Tight-Binding Programs sets where xtb and CREST are and how many threads they use, and shows what FormChem found: the version and path, a path that does not work, or where to get the program.
+- `./formchem edit-live ID`, `--object FILE` and `--from APP` open a live structure in the running FormChem from a terminal or a sibling app. See `docs/CLI.md`.
+- The MCP server has 77 tools, 6 of them new: `library_list`, `library_add` and `live_structure_object` for the shared library, `draw_from_helm` for biopolymers, and `xtb_optimise` and `crest_conformers` for tight-binding results. See `docs/AGENTS.md`.
+
+### Exit criteria
+
+Checked in the built window under 4x CPU throttling:
+
+- Aspirin, Copy as Live Structure: the library item (C9H8O4, 180.159) was on disk 0.59 s after the command, with the SVG and PNG flavours, the HTML picture and the live structure object on the clipboard. Pasted into a new drawing it came back as the same 13-atom structure, also when only the live structure flavour was on the clipboard. Opened from the Live tab it showed the Live structure badge; water added and `Mod+S` raised the revision from 1 to 2 in 0.47 s. Pass for FormChem's side; no sibling app was run (see Known issues).
+- Keyboard only: ethanol built with Focus Structure, Enter and the arrow keys, every atom spoken, and Describe Structure read "Formula C2H6O. Name: ethanol. Neutral overall. No rings. Functional groups: alcohol. No stereocentres." Pass with the spoken text read from the window; no real screen reader was run.
+- Oxytocin from HELM: C43H66N12O12S2, 1007.207 average and 1006.436458 monoisotopic, and Copy as HELM gave back the identical string with its disulfide. Eleven further HELM strings round-tripped to the same InChIKey.
+- Zero flash: switching element colours changed only fills (no node added or removed, layout shift 0); the file changed bar left the canvas where it was (layout shift 0); the xtb dialog kept its height and its log in place on every progress update.
+
+### Changed
+
+- The Edit > Copy As submenu gains Copy as HELM and Copy as Live Structure; Insert gains Biopolymer from HELM...; File gains Save as Template to Library...; Structure gains Star Structure; Window gains Structure Library...; 3D gains the xtb and CREST rows; View gains Focus Structure, Describe Structure, Next Atom, Previous Atom and an Element Colours submenu.
+- Dialog colour swatches and the custom accent button are 24 pixels, and every dialog control shows a 2 pixel focus outline from the keyboard.
+- The engine watches the files of open drawings once a second from the moment it starts.
+- The MCP instructions and the workflow describe the library, HELM and xtb tools.
+
+### Known issues
+
+- No sibling app was run: the clipboard, the library folder and the live structure object were checked against `docs/LIVE_STRUCTURES.md` only. Browsers write the live structure flavour under a `web ` prefix and drop the molfile flavour, so other apps read the HTML picture and the images; the desktop app's native clipboard was not tried.
+- The `formai://` link was not opened on a real desktop: the deep link plugin was fetched and its code lines checked against its source, but the desktop shell was not compiled on this machine.
+- Not verified with a real screen reader (VoiceOver, NVDA or Orca): only the spoken text was read back from the window. Alt with the square brackets may not be typeable where Ctrl+Alt is AltGr; the commands are also in View and the command palette.
+- xtb and CREST were not run for real here: FormChem neither includes nor downloads them, and the dialogs, jobs and results were checked with stand-in programs writing the documented files. The Windows process stop and the Windows install folders were not tried.
+- HELM: mixtures, BLOBs, hydrogen-bond pairs, repeat ranges and unknown attachment points are refused; inline SMILES in RNA and linker pieces are not written back; inputs near the 2,000 monomer and 20,000 atom limits were not timed.
+- Not verified: dropping from Finder or another app onto the desktop window; reaction items in the library; the native menus for the new rows.
+
+### Under the hood
+
+- New engine services: `live_structures` (the library folder, items, pictures, live drawings and `edit-live`), `file_watch`, `describe` (with its ring and functional group tables), the `helm` package (parser, monomers, assembly, writer) and the `xtb` package (discovery, inputs, runner, jobs, output readers, write-back), with routes in `routers/structures.py`, `describe.py`, `helm.py` and `xtb.py`. The agent token may write to `/api/structures` and nothing else.
+- The window gains the live structure client and drops, the Structure Library dialog, the file changed bar, the accessibility modules under `canvas/a11y/` with the shared announcer and the Structure Summary, the HELM dialog and commands, and the xtb and CREST dialogs and Preferences section.
+- `docs/FORMAT.md` records the program that made an xtb or CREST conformer. New desktop dependency `tauri-plugin-deep-link` 2.6.3 (Apache-2.0 OR MIT) with the crates it brings, listed in `NOTICE.md` and `THIRD-PARTY-NOTICES.txt`.
+- Translations of the new strings into all 25 languages. A translated pattern with more fixed words now wins over a more general one (`Could not read the HELM: ...` over `Could not read ...: ...`).
+- `./formchem agents sync` reads the agent modules' tools by importing them with the engine's Python, so the generated tool reference and `agents/manifest.json` list all 77 tools.
+
+## 0.11.0 · 2026-12-05
+
+Databases and the lab notebook: FormChem keeps your compounds in structure databases you can search by structure, formula, mass and your own fields, and keeps your experiments in a notebook beside them. A database is one `.fcdb` file (a SQLite file any SQLite browser opens), so moving the file moves everything. Import 10,000 SD records, find the benzene rings among them in a fraction of a second, plot two fields against each other, and export the hits back to SD. Notebook entries hold a reaction scheme with its stoichiometry, the procedure, products linked to their records and files, and can be signed. Agents reach all of it through eleven new MCP tools. FormChem also has a new app icon.
+
+### New
+
+- File > New Database and Open Database, and Home's Databases list, open a full-window database workspace (File > Databases or `Shift+Mod+D` shows and hides it). The left column lists the open databases, the hit lists and the saved queries; the toolbar holds the search bar and the views.
+- Views: Table, Gallery, Form, Plot and Notebook, all showing the same records and the same selection. The table pages records in as you scroll, so a 10,000 record database scrolls without waiting; sort by any column, resize, hide and freeze columns, and edit a field value in place (double-click, Enter or Tab saves, Escape cancels). The gallery shows structure tiles with two captions you choose. The form view shows one record at a time on a form laid out for you (Generate Form: single column, two columns or cards).
+- Fields are your own columns: text, rich text, whole and real numbers with a unit and significant figures, dates, yes or no, choices, structures, reactions, pictures, files, links to another record, and computed descriptors (cLogP, TPSA, hydrogen bond donors and acceptors, rotatable bonds, rings, fraction sp3 and others) that follow the structure and name their method. Database > Fields... adds, renames, orders, hides and deletes them.
+- Structure > Add to Database registers the selected structure (or the page). Duplicates are found by the database's rules (stereo matched or ignored, salts stripped or kept): a dialog shows the matching records and lets you open one, add a new batch of it or register the structure anyway. Registration numbers are never reused.
+- Search: type in the search bar for names, ids, formulas and SMILES, or use Structure to search with what you drew: exact (with stereo, salts, charges and tautomers matched or ignored), substructure, or similarity with a Tanimoto threshold (0.7 by default) and a score for every hit. Formula search reads ranges such as `C6-8H*N1O0-2`; mass, number, text, date, choice and empty searches work on every field. Advanced Search builds queries with All of, Any of and None of groups and can search within the current hit list.
+- Hit lists: every search becomes a hit list in the left column, named from its query ("Substructure c1ccccc1 and mw <= 300"). Keep the ones you want (the newest 20 others are kept), rename them, export them, and combine two by union, intersection or difference. Saved queries live in folders, show their last count and run again with one click.
+- Database > Import Records... reads SD (V2000 and V3000), RD, SMILES, CSV and TSV files (a SMILES or InChI column, found by its header or its contents) and `.fchem` drawings. You see the columns with their detected types, map each to a field or a new field, run a check that counts what would be added, updated and failed, then import as new records, appended records or a merge that updates matching records. A bad record never stops an import: the report lists each one with its number and a plain reason, and Copy Report copies it. Stop ends an import part way.
+- Database > Export Records... writes the hit list, the selection or the whole database to SD (V2000 or V3000, every field as a data item), SMILES or CSV (structures as SMILES or InChI). An SD file exported and imported into a new database keeps every InChIKey and every field value.
+- The Plot view draws a histogram of one field or a scatter of two, with a least-squares line and its R squared, colour by a third field, and a rectangle or lasso selection that becomes a hit list.
+- Record details (Enter or a double-click) show the picture, the identifiers with copy buttons, every field and the record's files: attach files up to 50 MB, or link larger ones by path in the desktop app. Open in Drawing opens the record as a new drawing.
+- Database > Database Settings... sets the title, the description and the duplicate rules.
+- The lab notebook (Database > Notebook, or the Notebook view) lists entries with text search (title, procedure, observations, tags and sample ids) and substructure search over each entry's scheme. New Notebook Entry... starts from a blank, reaction, analysis or purification template.
+- An entry holds a reaction scheme (New Scheme from Drawing, or Edit Scheme to change it on the canvas and Save to Entry), the stoichiometry computed from the scheme with its method, the procedure and observations in a simple markup (paragraphs, bullets, bold, italic) with a preview, products with their sample, mass, yield and purity and a link to the product's record, tags and files.
+- Sign Notebook Entry... records the signer, the time and a SHA-256 hash of the entry's content. A change after signing marks the entry "Modified after signing" and keeps the signed version, which opens read-only from the versions list.
+- Export Notebook Entry... writes a self-contained HTML file (scheme as a picture, stoichiometry, files listed with their hashes, ready to print) or JSON with the content, the hash and every version, so the hashes can be checked later.
+- Databases open by File > Open (desktop and browser) or by dropping an `.fcdb` file on Home. A database another FormChem already has open opens read-only and says why.
+- `./formchem db create`, `info`, `import`, `search` and `export` work on databases from the command line, with `--errors` writing the failed records of an import to a CSV file. See `docs/CLI.md`.
+- The MCP server has 71 tools, 11 of them new: `db_list`, `db_create`, `db_open`, `db_import`, `db_search`, `db_get_record`, `db_add_record`, `db_update_record` and `db_export` for databases, and `nb_add_entry` and `nb_search` for the notebook. Every write by an agent is recorded with the agent's name, and agents never sign entries. See `docs/AGENTS.md` and `docs/DATABASES.md`.
+
+### Exit criteria
+
+Checked in the built window under 4x CPU throttling:
+
+- 10,000 SD records (3 of them deliberately broken) imported through Import Records... in 34.4 s: 9,997 added, records 1500, 5000 and 8500 reported with plain reasons. Pass.
+- A benzene substructure search found 2,218 of the 9,997 records in 145 ms. Pass.
+- The hit list exported to SD wrote 2,218 records, and imported into a new database gave 2,218 records. Pass.
+- Zero flash: scrolling the table 16,000 pixels reused 25 pooled rows (layout shift 0.0001, from loading rows filling in), the gallery and a 9,997 point scatter plot showed no layout shift. Pass.
+- On a 100,000 record database (measured in the engine): benzene substructure in 0.45 to 0.54 s once the structure cache is built (30,769 hits), a similarity search in 0.12 to 0.15 s, a formula range in 6 ms.
+
+### Changed
+
+- New app icon: the macOS, Windows and Linux icons, the title bar mark, Home, About, the favicon and the splash screen all show the new FormChem card.
+- The File > Open dialogs and Home's Open list `.fcdb`. File gains New Database, Open Database and Databases; Structure gains Add to Database; a new Database menu holds search, import, export, the views, the notebook, fields and settings. Home's Databases page offers New and Open.
+- The MCP instructions and the workflow describe the database and notebook tools.
+
+### Known issues
+
+- Record values, hit list names, saved query names and entry titles are shown as typed, never translated; the engine's value-format errors and RDKit's own messages stay in English.
+- The notebook does not hold spectra or a grid yet; an entry carries spectra as attached files.
+- Variable attachment and link nodes, moved to this phase, are not drawn yet.
+- While the database workspace is open it covers the in-window menu bar; its toolbar and gear menu carry the commands instead.
+- Two databases with the same title look alike in the Open Database list; the path shows in its tooltip.
+- Not verified: the desktop app's folder and file choosers, Link File and dropping an `.fcdb` on the desktop window (the desktop app has no drop handler; Home's drop area in the browser works); the consent prompt for `db_add_record` and `nb_add_entry` with a window open; live updates between two windows; a read-only database held by a second engine, in the window; scrolling 100,000 records in the window; printing the HTML entry export.
+- Search speeds were measured on a small shared machine and not on the reference laptop.
+
+### Under the hood
+
+- New engine packages `services/database/` (schema, store with one transaction per write, registration and keys, fields, forms, records, attachments, thumbnails, jobs, import, export, query, search, hit lists, saved queries, plot, command line) and `services/notebook/` (templates, content hash, scheme, products, entries, attachments, markup, export), with routes in `routers/databases.py`, `routers/db_search.py` and `routers/notebook.py`.
+- The window gains the database workspace (`ui/database/`), search, hit lists, import, export and plot (`ui/database-find/`), the notebook (`ui/notebook/`) and one client for the database routes (`engine/database-api.ts`).
+- Every database read needs the window key; pictures and files load with a separate view key that opens only those two routes.
+- `docs/DATABASE.md` is the contract for the `.fcdb` file, the query language and the routes. The new icon set is sized from the owner's masters in `assets/icon_src/masters`, so `cairosvg` is no longer used. No new dependency.
+- Translations of the new strings into all 25 languages. `./formchem agents sync` now lists the tools of the agent modules too, so the generated tool reference has 71 tools.
+
## 0.10.0 · 2026-12-03
3D: a structure you drew becomes a molecule you can turn. Build 3D from 2D keeps every wedge and double bond as drawn, the 3D View shows it in five styles with surfaces and measurements, conformer searches, minimisation and dihedral scans report energies with their force field and version, and a 3D view placed on the page keeps its angle and style in the drawing. PDB and mmCIF files open as proteins in cartoon with the ligand in focus, and a ligand comes out as an editable structure. Agents reach all of it through eight new MCP tools.
diff --git a/CLAUDE.md b/CLAUDE.md
index 47e0cc49..e24f1cf5 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -4,11 +4,11 @@ Two jobs happen in this repo: drawing chemistry with FormChem, and developing Fo
## Drawing with FormChem
-The FormChem MCP server runs at http://127.0.0.1:8220/mcp, configured in .mcp.json; HTTP requests need the agent token (`./formchem agents token`; `./formchem agents install` writes it into the configs, and the stdio transport `./formchem mcp` sends it itself). Start the app with `./formchem` so changes appear live in the window. It has 60 tools. Changing tools make the window ask the person the first time unless you were started from FormChem's own dock, and the person can Stop an agent from the title bar.
+The FormChem MCP server runs at http://127.0.0.1:8220/mcp, configured in .mcp.json; HTTP requests need the agent token (`./formchem agents token`; `./formchem agents install` writes it into the configs, and the stdio transport `./formchem mcp` sends it itself). Start the app with `./formchem` so changes appear live in the window. It has 77 tools. Changing tools make the window ask the person the first time unless you were started from FormChem's own dock, and the person can Stop an agent from the title bar.
-Since 0.8.0 agents draw directly: `get_context` or `list_open_documents` first; `draw_from_smiles` (reaction SMILES draws a scheme) and `draw_from_molfile` place a structure in free space as one undo step and answer with ids, SMILES, InChIKey, formula and a picture; `get_atoms` names atoms and bonds by id for the edit tools (`add_atom`, `add_bond`, `set_charge`, `set_atom`, `set_stereo`, `replace_substructure`, `delete`, `move`, `scale`, `align`, `clean_layout`, `add_arrow`, `add_text`, `add_reaction`), each one undo step; check your work with `render`, `get_structure` and `validate`; `convert` and `batch_convert` match `./formchem convert` and `batch`. Since 0.9.0 `draw_from_name` and `name_structure` read and write names offline, `predict_nmr` and `predict_spectrum` predict 1H and 13C NMR, and `open_spectrum`, `spectrum_data`, `spectrum_peaks`, `spectrum_pick_peaks`, `spectrum_integrate` and `spectrum_export` work with JCAMP-DX spectra. Since 0.10.0 `build_3d` builds a structure in 3D (check that its answer says every stereo label was kept), `conformers_3d`, `minimise_3d`, `scan_dihedral` and `measure_3d` work on its conformers with the force field and version beside each number, `open_3d_structure` opens PDB, mmCIF, SDF and MOL files, `extract_ligand` turns a bound ligand into a structure, and `export_3d` writes MOL, SDF, PDB or XYZ; an edit to a structure's atoms or bonds drops its conformers. Reaction tools, analysis tools, the window's own commands (`list_commands`, `run_command`), Form extensions and `handoff` (with `question` when you need the person's input) are there too. Every call shows in the window's Agent activity panel.
+Since 0.8.0 agents draw directly: `get_context` or `list_open_documents` first; `draw_from_smiles` (reaction SMILES draws a scheme) and `draw_from_molfile` place a structure in free space as one undo step and answer with ids, SMILES, InChIKey, formula and a picture; `get_atoms` names atoms and bonds by id for the edit tools (`add_atom`, `add_bond`, `set_charge`, `set_atom`, `set_stereo`, `replace_substructure`, `delete`, `move`, `scale`, `align`, `clean_layout`, `add_arrow`, `add_text`, `add_reaction`), each one undo step; check your work with `render`, `get_structure` and `validate`; `convert` and `batch_convert` match `./formchem convert` and `batch`. Since 0.9.0 `draw_from_name` and `name_structure` read and write names offline, `predict_nmr` and `predict_spectrum` predict 1H and 13C NMR, and `open_spectrum`, `spectrum_data`, `spectrum_peaks`, `spectrum_pick_peaks`, `spectrum_integrate` and `spectrum_export` work with JCAMP-DX spectra. Since 0.10.0 `build_3d` builds a structure in 3D (check that its answer says every stereo label was kept), `conformers_3d`, `minimise_3d`, `scan_dihedral` and `measure_3d` work on its conformers with the force field and version beside each number, `open_3d_structure` opens PDB, mmCIF, SDF and MOL files, `extract_ligand` turns a bound ligand into a structure, and `export_3d` writes MOL, SDF, PDB or XYZ; an edit to a structure's atoms or bonds drops its conformers. Since 0.11.0 `db_list`, `db_create` and `db_open` reach structure databases (`.fcdb` files), `db_import` fills one (try `dry_run` first and read the failed-record report), `db_search` searches by substructure, similarity (read each hit's score), exact match or a query node and leaves a hit list the person sees, `db_get_record`, `db_add_record` (a duplicate is refused until you choose `on_duplicate`) and `db_update_record` work on records, `db_export` writes SD, SMILES or CSV, and `nb_add_entry` and `nb_search` keep lab notebook entries, which only the person signs. Since 0.12.0 `library_list`, `library_add` and `live_structure_object` reach the shared structure library that every Form app reads, `draw_from_helm` draws a peptide or nucleic acid from HELM (bad HELM is refused with the character where reading stopped), and `xtb_optimise` and `crest_conformers` run xtb and CREST only when the person has installed them (FormChem never ships them; quote the program, version, method and solvent with every energy). Reaction tools, analysis tools, the window's own commands (`list_commands`, `run_command`), Form extensions and `handoff` (with `question` when you need the person's input) are there too. Every call shows in the window's Agent activity panel.
-Load the skill `.claude/skills/formchem-harness` for using the app. For work on the codebase itself, load `.claude/skills/formchem-skillset`. The document format is `docs/FORMAT.md`.
+Load the skill `.claude/skills/formchem-harness` for using the app. For work on the codebase itself, load `.claude/skills/formchem-skillset`. The document format is `docs/FORMAT.md`; the database and notebook contract is `docs/DATABASE.md`; the shared structure library and live structure contract for sibling apps is `docs/LIVE_STRUCTURES.md`.
## Developing FormChem
diff --git a/NOTICE.md b/NOTICE.md
index 5c681435..75d243a3 100644
--- a/NOTICE.md
+++ b/NOTICE.md
@@ -36,6 +36,8 @@ This file is the human list, with the reason each work is there. The full licenc
| fontTools 4.69.1 (fonttools) | MIT | engine, embeds subsets of the label fonts in exported SVG and draws label outlines in PDF and EPS |
| Other Python packages frozen into the engine | listed with their licences in `THIRD-PARTY-NOTICES.txt` | read from the installed metadata of `backend/requirements.txt` |
| @tauri-apps/api 2.12.1; tauri, tauri-plugin-shell, tauri-plugin-dialog, tauri-plugin-updater, tauri-plugin-single-instance, serde, serde_json, regex | MIT or Apache-2.0 | desktop shell |
+| tauri-plugin-deep-link 2.6.3 (from 0.12.0) | Apache-2.0 OR MIT | desktop shell, registers the `formai://` scheme so sibling apps open a live structure with `formai://formchem/edit` |
+| rust-ini 0.21.3, ordered-multimap 0.7.3, crunchy 0.2.4; dlv-list 0.5.2, const-random 0.1.20, const-random-macro 0.1.18, hashbrown 0.14.5 | MIT; MIT OR Apache-2.0 | desktop shell, brought by tauri-plugin-deep-link through rust-ini, its INI file reader |
| fontdb 0.24 | MIT | desktop shell, lists installed font families |
| objc2-foundation 0.3 (macOS shell) | MIT | desktop shell, window geometry for the traffic-light placement |
| Arimo (Copyright 2020-2026 The Arimo Project Authors; googlefonts/arimo 4a6255f, through google/fonts 659809e), variable weight, roman and italic | SIL OFL-1.1 | app, atom labels and captions standing in for Arial and Helvetica so output measures the same everywhere; `frontend/public/fonts/Arimo-*.ttf` with `Arimo-OFL.txt` beside them |
@@ -61,6 +63,7 @@ Tauri links these crates unedited (no `[patch]` and no vendored copy):
| ring | Apache-2.0 AND ISC | TLS for the updater (rustls) |
| webpki-root-certs | CDLA-Permissive-2.0 | root certificates for the updater's TLS |
| r-efi | MIT OR Apache-2.0 OR LGPL-2.1-or-later | used under MIT |
+| tiny-keccak 2.0.2 | CC0-1.0 | hashing at build time for const-random, through tauri-plugin-deep-link (from 0.12.0) |
The Linux AppImage also carries the build machine's WebKitGTK, GTK and GLib (LGPL-2.1-or-later) as separate shared libraries. This notice, `THIRD-PARTY-NOTICES.txt` and LICENSE ship inside every installer.
@@ -69,15 +72,29 @@ The Linux AppImage also carries the build machine's WebKitGTK, GTK and GLib (LGP
| Tool | License |
| --- | --- |
| TypeScript 7.0.2, Vite 8.3.5, @tauri-apps/cli | Apache-2.0, MIT, MIT or Apache-2.0 |
-| cairosvg, Pillow (run by `assets/icon_src/build.py` in a throwaway environment to draw the icon set; the icons are shipped, the tools are not) | LGPL-3.0-or-later, MIT-CMU |
+| Pillow (run by `assets/icon_src/build.py` in a throwaway environment to size the icon set from the owner's masters in `assets/icon_src/masters`; the icons are shipped, the tool is not) | MIT-CMU |
| PyInstaller | GPL-2.0 with the bootloader exception, which permits distributing the frozen engine; the bootloader is inside the engine, so its licence text is in `THIRD-PARTY-NOTICES.txt` |
+## Programs FormChem runs but never ships
+
+From 0.12.0 FormChem can run these programs when the person has installed them and set their path (or put them on PATH). They are separate programs under their own licences: FormChem does not include them, does not download them, does not link to them, and only starts them as separate processes and reads the files they write.
+
+| Program | License | What FormChem uses it for |
+| --- | --- | --- |
+| xtb (https://github.com/grimme-lab/xtb) | LGPL-3.0 | 3D > Optimise with xtb and the `xtb_optimise` agent tool: GFN2-xTB and GFN-FF optimisations and single points with ALPB implicit solvent |
+| CREST (https://github.com/crest-lab/crest) | LGPL-3.0 | 3D > Conformer Search with CREST and the `crest_conformers` agent tool |
+
+The list of 24 ALPB solvent names in `backend/app/services/xtb/solvents.py` names the solvents xtb documents; no xtb code or parameter file is in FormChem.
+
## FormChem's own data
These ship with the engine and are FormChem's own work under Apache-2.0; no third-party database or list was copied to make them:
- The names dictionary in `backend/app/data/names/` (common names with SMILES written for FormChem and InChIKeys computed with RDKit), read by the offline name engine.
- The NMR increments in `backend/app/services/nmr/` (rounded base values and substituent terms of textbook additive methods), and the reference shifts in `backend/app/services/nmr/reference.py`, approximate typical values used only to measure the predictor's error. NMRShiftDB2 data is not used.
+- The HELM monomer data in `backend/app/data/helm_monomers.json` (from 0.12.0): 55 monomers (the 20 amino acids, 19 D forms, six non-standard residues, two caps, two sugars, phosphate and five bases) written for FormChem from textbook structures. No HELM monomer library (including the Pistoia Alliance's) was consulted or copied; the file says so in its `source` fields.
+- The functional group table (42 SMARTS patterns) and the ring system names (51 ring skeletons) in `backend/app/services/describe.py` (from 0.12.0), written for FormChem for the spoken Structure Summary.
+- The high-contrast and colour-blind safe element palettes in `frontend/src/canvas/render/atom.ts` (from 0.12.0). The colour-blind palette uses four colour values of the Okabe-Ito palette (Okabe and Ito, Color Universal Design), a published colour recommendation; no code or file was copied.
## Trademarks
diff --git a/README.md b/README.md
index 05e62146..b8dade95 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-
+
FormChem
@@ -8,7 +8,7 @@
with an MCP server so an agent works in the same window you see. Local-first, no account.
-
+
@@ -28,7 +28,7 @@
## Features
-FormChem draws structures and reactions: draw on the canvas with the mouse or the keyboard, annotate with arrows, brackets, shapes, tables and TLC plates, and the chemistry engine checks every change, reads reaction schemes, maps their atoms, works out the amounts, labels stereochemistry and computes properties with the method behind each number. Drawings go out as chemistry files and as pictures that open again as the drawing, through the clipboard to other programs, and whole files convert on the command line. Names turn into structures and structures into names, offline; 1H and 13C NMR spectra are predicted with the method and version beside every number; and measured spectra open from JCAMP-DX files with their peaks linked to atoms. Structures turn in 3D: built from the drawing with their stereo checked, with conformers, minimisation, dihedral scans, measurements and surfaces, placed on the page as 3D views, and proteins open from PDB and mmCIF files with their ligands. Agents draw in the same window: they draw and edit structures and reactions, from names too, predict and read spectra and build in 3D through 60 MCP tools, check their work with a picture of what you see, and every call is one undo step you can review, undo or stop.
+FormChem draws structures and reactions: draw on the canvas with the mouse or the keyboard, annotate with arrows, brackets, shapes, tables and TLC plates, and the chemistry engine checks every change, reads reaction schemes, maps their atoms, works out the amounts, labels stereochemistry and computes properties with the method behind each number. Drawings go out as chemistry files and as pictures that open again as the drawing, through the clipboard to other programs, and whole files convert on the command line. Names turn into structures and structures into names, offline; 1H and 13C NMR spectra are predicted with the method and version beside every number; and measured spectra open from JCAMP-DX files with their peaks linked to atoms. Structures turn in 3D: built from the drawing with their stereo checked, with conformers, minimisation, dihedral scans, measurements and surfaces, placed on the page as 3D views, and proteins open from PDB and mmCIF files with their ligands. Compounds live in structure databases (one `.fcdb` file each) that you search by structure, formula and your own fields, browse as a table, gallery, form or plot, and fill from or write to SD, SMILES and CSV files, with a lab notebook of signed experiment entries beside them. A structure copied into another Form app stays a FormChem drawing and comes back editable, through a shared structure library every Form app reads. Everything can be drawn and read from the keyboard, with each atom spoken and the whole structure summarised, in element colours that stay apart for low vision and colour blindness. Peptides and nucleic acids come in and go out as HELM, and xtb and CREST run when you have installed them. Agents draw in the same window: they draw and edit structures and reactions, from names and HELM too, predict and read spectra, build in 3D, run xtb, search and fill databases and keep the structure library through 77 MCP tools, check their work with a picture of what you see, and every call is one undo step you can review, undo or stop.
@@ -57,7 +57,7 @@ FormChem draws structures and reactions: draw on the canvas with the mouse or th
Clipboard
Copy puts the drawing, SMILES and a picture on the clipboard at once; Copy As picks SMILES, CXSMILES, Molfile, InChI, InChIKey, SMARTS, SVG, PNG or CDXML; Paste reads all of them back, and Paste Special lets you choose.
-
Command line
./formchem convert, batch, descriptors and render work on whole files and folders (10,000 SD records to SMILES in about a second and a half), with optional standardising and a report of every record that failed.
+
Command line
./formchem convert, batch, descriptors and render work on whole files and folders (10,000 SD records to SMILES in about a second and a half), with optional standardising and a report of every record that failed; ./formchem db creates, fills, searches and exports databases.
Dark page and grids
A dark drawing page, on by default, that keeps element colours readable and never reaches exports. Line, dot, cross, isometric and hexagonal grids with their own spacing, kept per drawing, and Snap to Grid.
Size on the sheet
Drag a corner handle, or use Arrange > Scale, Scale Up and Scale Down, to make structures larger or smaller on the page by percent or bond length, with their labels and line widths or without.
@@ -72,7 +72,22 @@ FormChem draws structures and reactions: draw on the canvas with the mouse or th
Proteins and ligands
PDB and mmCIF files open as cartoon with the ligand in focus and waters hidden, the file kept byte for byte in the drawing. Extract Ligand turns a ligand into an editable structure with its coordinates; 3D SD files keep theirs. Export as MOL, SD, PDB or XYZ with every hydrogen.
-
MCP server
60 tools over HTTP (with an agent token) and stdio: agents open and save drawings, draw from SMILES, reaction SMILES, molfiles or names, build and edit atom by atom by id, read structures back as SMILES, InChIKey, molfiles and names, render what you see, validate, predict NMR, open spectra and pick their peaks, build 3D conformers, scan and measure them, open PDB files and extract ligands, convert files as the command line does, and run every menu command. Agent Activity lists each call with undo and Stop.
+
Databases
Structure databases in one SQLite file (.fcdb) that any SQLite browser opens: your own fields (numbers with units, dates, choices, files, links and computed descriptors), Add to Database with duplicate rules for stereo and salts, and table, gallery, form and plot views that scroll 10,000 records without a stall. Import SD, RD, SMILES, CSV and TSV with a preview and a report of every bad record; export to SD, SMILES or CSV.
+
Search and hit lists
Exact (stereo, salts, charges and tautomers matched or ignored), substructure, Tanimoto similarity with scores, formula ranges such as C6-8N1, and every field, combined in All of, Any of and None of groups. Each search is a hit list to keep, export or combine; saved queries live in folders. Benzene among 9,997 records in 145 ms.
+
Lab notebook
Experiment entries in the same database: a reaction scheme with its stoichiometry computed, procedure and observations, products linked to their records, files and tags, searchable by words and by substructure. Sign an entry with a SHA-256 hash of its content; a later change shows "Modified after signing" and keeps the signed version. Export as self-contained HTML or JSON.
+
+
+
Live structures
Copy as Live Structure puts a structure into FormDeck, FormTxt or form.md as a picture with the FormChem drawing inside. The sibling app opens it in FormChem again with a formai://formchem/edit link or ./formchem edit-live; Save writes the new picture back with a higher revision, no path asked.
+
Structure library
Favourites, Recent, Templates and Live structures in a plain folder of SVG, PNG and molfiles that every Form app reads without FormChem running. Star a structure, save a template, insert or open from Window > Structure Library. A bar offers Reload or Keep Mine when a drawing's file changes on disk.
+
Biopolymers
Insert > Biopolymer from HELM reads peptides and nucleic acids as you type, disulfides and rings included, and Copy as HELM writes them back only when the HELM reads back to the same structure. 55 monomers written for FormChem from textbook structures.
+
+
+
Keyboard and screen readers
Focus Structure puts the focus on the drawing: Tab walks atoms, arrows follow bonds, Enter and an arrow draw a new bond. Every move is spoken ("Oxygen. 1 hydrogen. Single bond to Carbon."), and Describe Structure reads the formula, name, rings, functional groups and stereocentres.
+
Element colours
Standard, High contrast (every element at 7:1 or more on white) and Colour-blind safe (Okabe-Ito blue, vermillion, bluish green and reddish purple), applied to the canvas, pictures and the clipboard, switched without a flash.
+
xtb and CREST
GFN2-xTB or GFN-FF optimisations and single points with ALPB solvents, and CREST conformer searches, when you have installed the programs: energies in hartree and kcal/mol with the gap and the program's version. FormChem never ships or downloads them.
+
+
+
MCP server
77 tools over HTTP (with an agent token) and stdio: agents open and save drawings, draw from SMILES, reaction SMILES, molfiles or names, build and edit atom by atom by id, read structures back as SMILES, InChIKey, molfiles and names, render what you see, validate, predict NMR, open spectra and pick their peaks, build 3D conformers, scan and measure them, open PDB files and extract ligands, create, import into, search and export databases, add and find notebook entries, keep the structure library, draw from HELM, run xtb and CREST, convert files as the command line does, and run every menu command. Agent Activity lists each call with undo and Stop.
The family shell
Home, Preferences, twelve menus with full keyboard use (those that do not fit fold into More menus), Find a Command, the terminal and agent dock, Help and updates, in 26 interface languages.
Form extensions
Extensions installed by FormPortal run in a sandboxed frame from the Extensions menu and panel, and ask before they read or change a drawing.