From b252a7096898a894c485e8582dc8786a6032be39 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 14:20:31 +0000 Subject: [PATCH 01/16] Docs: tighten the protocol reference Remove history, spec section numbers and the release-sandbox matrix (in TESTING.md), group the rules by subject, keep every rule and exact sentence. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WX6rdRdA72nsUjZvTXFSbP --- docs/PROTOCOL.md | 296 +++++++++++++++++++++++------------------------ 1 file changed, 144 insertions(+), 152 deletions(-) diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md index f08e458..e3c19d1 100644 --- a/docs/PROTOCOL.md +++ b/docs/PROTOCOL.md @@ -1,4 +1,6 @@ -# Protocol reference (version 1) +# Protocol reference + +The contract between a host plugin (napari, Fiji, QuPath) and an app's tools: the schema a host reads, the registry where it finds apps, and the messages it exchanges with the worker. This is protocol version 1. Every field marked additive below was added within version 1: a host that does not know it can ignore it. A change that is not additive would be protocol 2. ## Schema (what hosts read) `/.schema.json`, generated by `labconstrictor-tools describe` without running any tool: @@ -10,87 +12,97 @@ "minimum"?, "maximum"?, "unit"?, "axes"?, "pixel_size_of"?, "nullable"?, "group"?, "advanced"?, "enabled_when"?, "group_collapsed"?, "clear_after_run"?, "choices_from"?, "pick_channel"? } ], "outputs": [ { "name", "type", "axes"?, "display"?: {"apply_to", "relative_to"?}, "replace"? } ] } ] } ``` -An input's `description` is optional in the protocol but recommended for every input: it is the input's help, which hosts show on hover and, as each host adopts it, with an ⓘ after the label ([HOST_FEATURES.md](HOST_FEATURES.md)). `labconstrictor-tools check` and `test` warn about inputs without one; nothing refuses them. - -Value rules (enforced by the worker, each violation is a `FAILURE` with code `invalid_parameter` or a declaration error at registration): -* `boolean` must be a JSON `true`/`false` (never text or numbers); `choice` values must match a choice in type and value; a `float` is never a boolean. -* A parameter given as `null` is treated as not given: it takes its default, or (when `nullable`) the tool receives `None`. `Optional[...]` with a non-None default is refused when the app is registered (a host can only leave it at the default or unset). -* A default must be valid for its declared type (checked when the schema is generated, not when a host omits the value). -* A `choice` declared with an `Enum` annotation reaches the tool as the Enum member. -* An image/labels input with no pixels is refused (`empty_image`), from a file or from shared memory. -* Table inputs (a CSV file, UTF-8, first line is the header) reach the tool as a DataFrame exactly as written: floating point cells are read with every digit (`float_precision="round_trip"`, about twice as slow as pandas' default on very large tables); column names are kept as written, duplicates (`a,a`) and empty names included (pandas' renaming to `a.1` / `Unnamed: 0` is switched off, so a tool must address such columns by position); an empty cell is missing (NaN); the spellings `NaN`, `nan`, `NAN` mean a missing number (a column of numbers, `NaN` and empty cells, or of only `NaN` and empty cells, is a float column with NaN), and the other words pandas calls missing (`NA`, `N/A`, `NULL`, `None`, `null`, ...) stay text, except in a column whose other cells are all numbers, where they are missing numbers; a text column that happens to contain `nan` keeps it as text. A table file that does not exist is refused with `file_not_found`; one that is empty or not a UTF-8 CSV with `unreadable_table`; both messages name the file. -* `integer` and `float` values must be JSON numbers: text (even "3"), lists, objects, NaN and infinity give `invalid_parameter` (`'N' must be an integer, got text`, `'N' must be a number, got a list`, `'N' must be a finite number`); an integer-valued float such as `3.0` is accepted for an `integer`. A number beyond the float range is refused for a `float`. -* `file`, `folder` and `image`/`labels` values must be text paths: anything else gives `invalid_parameter` (`'N' must be a path (text), got a list: the host must send the file or folder path as text`). -* A shared-memory image descriptor must be `{"appose_type": "ndarray", "shm": {"name"}, "shape", "dtype"}` (optionally `"order"`, see below) and the block must still exist and be large enough, with a numeric dtype; a stale or malformed one gives `unreadable_image` (`the shared-memory image for 'N' is gone or malformed (...): the host must keep the block alive until the task ends and send {...}`). -* What a tool returns must match its declaration, otherwise the task fails with `bad_return` and a message of the form `the output '' must be , got ` (an array of numbers for image/labels, a DataFrame / dict of lists / list of dicts for table and points, a dict for values, a path for file, text for message, a 3x3 matrix of numbers for affine). A tool with several outputs must return a tuple with one value per output (`tool returned N values, declared M`). An affine with NaN or infinity is refused (`bad_return`). -* Table and points outputs are written as UTF-8 CSV. A NUL character (`\\0`) in a column name or a text cell is refused with `bad_return` (`the table output 'X' has a NUL character in a cell of column 'c': remove it`), identically on every Python version; a lone surrogate or other character that is not UTF-8 is refused with `bad_return` (`... cannot be written as a UTF-8 CSV ...`). Line breaks, quotes and commas in cells and names are quoted and arrive unchanged. -* Image outputs: an empty array is `bad_return` (`image is empty (shape ...)`); complex, object, text and bytes arrays are `unsupported_dtype`; an integer image beyond 16 bits that float32 cannot hold exactly (more than 24 significant bits, for example a uint64 2**64-1) is refused with `unsupported_dtype` on every machine, never stored rounded or kept as 64-bit. -* Image outputs: integers are never changed in value (wide integers that fit 16 bits are stored as 16-bit; others must be exact as 32-bit float or the result fails with `unsupported_dtype`); floating point values are stored as float32 (about 7 significant digits); float values outside the float32 range fail. - -Input `type`: `string integer float boolean choice image labels table file folder`. -`nullable: true` (additive, protocol 1): the parameter is optional AND has no default value (`= None` / `Optional[...]`). A host must let the -user leave it unset and then omit it from the request (the tool receives `None`); showing 0 or an empty string instead is a bug. -The notebook form does this with a "set" check box beside each nullable number, text, choice or yes/no (unchecked = greyed out and left out). -Number limits: the protocol, the command line and snippets carry integers of any size and floats up to the double range. A number box -never clamps silently. The notebook form has no made-up bound; because the page exchanges JSON numbers, an integer beyond +-(2**53 - 1) -(`notebook.MAX_FORM_INTEGER`) is refused with an `invalid_parameter` message, and the limit is in the control's tooltip. Declared `Min`/`Max` are enforced. -A value beyond a limit (declared, or the form's default) is refused, never clamped, with the worker's sentence naming the field and the limit: `'L' must be <= 9007199254740991` or `'L' must be >= -9007199254740991`. Every host uses these two sentences. -`group` (heading), `advanced: true` (listed under collapsed "Advanced settings") and `enabled_when: {"param", "equals"?}` (the parameter only applies when `param` is set/true, or equals one of the listed values) are presentation hints, additive within protocol 1: a host that ignores them shows the flat form, so a tool must accept every parameter whether or not it is "enabled". Group names are shown where they first appear. -Interaction hints (additive within protocol 1; a host that ignores them shows a plain form, so the tool must work either way): -* `group_collapsed: true` (with `group`): the group is an accordion section that starts folded. -* `clear_after_run: true`: after a successful run, hosts that keep form values between runs put the parameter back to its default (or unset). Fiji does this too: after a run, the tool's form comes back with the values just used. -* `choices_from: {"tool", "depends", "field"}` (string parameters): the options come from another tool of the app. The host runs `tool` with the current values of the parameters named in `depends` and reads the list under `field` of its `values` result; it shows a dropdown, and falls back to a text field when the call cannot be answered. The value stays a free string for the tool. Fiji builds its dialog before the user types anything, so it asks with the values used by the previous run of the same app (kept in `/state`) and falls back to the text field the first time. -* `pick_channel: true` (image inputs, `axes` YX or absent): the host lets the person choose a channel of the chosen image (names where the host has them, numbers otherwise) and sends the tool that channel only, as a 2D image. A host that cannot list channels sends the image as it is. -* output `replace: true` (image, labels, table, affine: the overlay): a new run replaces the previous result of the same output (same layer / window name) instead of adding "name [1]". -A GeoJSON dict returned for a `shapes` output is checked before anything is written: a `FeatureCollection` whose features are Polygon or MultiPolygon with non-empty coordinates (a Polygon is a list of rings, outer boundary first then holes; a MultiPolygon a non-empty list of polygons), every ring a list of at least 4 `[x, y]` positions (exactly two finite numbers), closed (last position equals the first) and with at least 3 distinct vertices, the same contract `_ring` gives to polygons built from `(y, x)` vertex lists. Anything else is `bad_return` naming the feature, polygon and ring. An empty result is a FeatureCollection with no features, never a feature with empty coordinates. - -Output names are file names (`.tif`, `.csv`, `.geojson` in the result folder), so `Name(...)` must be one portable file name: no `/`, `\`, `:`, `<>"|?*`, control characters or NUL, no `.`/`..`, no leading space or trailing space/dot, and not a Windows device name (`CON`, `NUL`, `COM1`, ...). Anything else is a `DeclarationError` when the tool is described; the writers also refuse (`bad_return`) a path that would leave the result folder. - -`axes` (an input or an image/labels output) is a string of distinct labels from `T C Z Y X S`, one per array dimension, otherwise a `DeclarationError`. A declared output `axes` is a promise: an array with another number of dimensions is `bad_return` and nothing is written; without `axes` the host gets `YX`, `ZYX` or `CZYX` for 2, 3 or 4 dimensions and no `axes` claim otherwise. - -A tool whose output axes depend on its input states them when it runs: it returns `WithAxes(array, "TZYX")` for that output (same letters; a declared `axes` must be the same, otherwise `bad_return`), and the result's `axes` are the returned ones. An image/labels result whose axes are known, declared or returned, with more than two dimensions and none of size 1 (ImageJ cannot record a T, Z or C of size 1), its axes a subsequence of `T Z C Y X` ending in `Y X`, a pixel type ImageJ stores (uint8, uint16, int16, float32) and less than 4 GiB is written as an ImageJ hyperstack TIFF: Fiji opens it with its time points, slices and channels. The array is never reordered, so `tifffile.imread` gives the same array as without the hyperstack metadata. Every other result, including one whose axes are only the default guess above, is written as before (feature `result_axes_v1`). - -`folder` is a directory path (the worker checks it exists); hosts show a folder chooser. Output `type`: `image labels table values affine file message points shapes`. `message`: `{text}` (plain text, short). `points`: `{path, n, columns, apply_to?}`, a CSV whose first two columns are `y` and `x` (finite pixel coordinates in the frame of the image named by `apply_to`, else of the first image); other columns are properties of each point. `shapes`: `{path, n, apply_to?}`, a GeoJSON FeatureCollection file (`.geojson`) of Polygon / MultiPolygon features, `[x, y]` coordinates in the same frame and with pixel centres at integers; feature properties are kept (a `label` property links an outline to its label). A host that does not know `shapes` lists the file. -Hosts must skip (and report) a schema whose `protocol` they do not support. + +A host must skip, and report, a schema whose `protocol` it does not support. + +Input `type`: `string integer float boolean choice image labels table file folder`. Output `type`: `image labels table values affine file message points shapes`. + +### Inputs + +* `description`: optional but recommended; the input's help, which hosts show on hover with an ⓘ after the label. `check` and `test` warn when it is missing. +* `nullable: true` (additive): the parameter is optional and has no default (`= None` or `Optional[...]`). A host lets the person leave it unset and then omits it from the request; the tool receives `None`. Showing 0 or an empty string instead is a bug. +* `folder`: a directory path; the worker checks that it exists. Hosts show a folder chooser. +* `axes` (an input, or an image/labels output): a string of distinct labels from `T C Z Y X S`, one per array dimension. Anything else is a `DeclarationError`. + +Presentation and interaction hints (all additive). A host that ignores them shows a plain form, so a tool must accept every parameter whether or not it is "enabled": + +* `group`: a heading, shown where the group first appears. `advanced: true`: listed under a collapsed "Advanced settings". `group_collapsed: true` (with `group`): the group is an accordion section that starts folded. +* `enabled_when: {"param", "equals"?}`: the parameter applies only when `param` is set or true, or equals one of the listed values. +* `clear_after_run: true`: after a successful run, a host that keeps form values between runs puts the parameter back to its default (or unset). +* `choices_from: {"tool", "depends", "field"}` (string parameters): the host runs `tool` with the current values of the parameters named in `depends`, reads the list under `field` of its `values` result and shows a dropdown. When the call cannot be answered it falls back to a text field. The value stays a free string for the tool. A host that builds its form before the person types anything (Fiji) asks with the values of the previous run of the same app, kept in `/state`, and shows the text field the first time. +* `pick_channel: true` (image inputs whose `axes` are `YX` or absent): the host lets the person choose a channel of the chosen image (by name where the host has names, by number otherwise) and sends only that channel, as a 2D image. A host that cannot list channels sends the image as it is. +* output `replace: true` (image, labels, table, affine overlay): a new run replaces the previous result of the same output (same layer or window name) instead of adding "name [1]". + +### Value rules (enforced by the worker) +Each violation is a `FAILURE` with code `invalid_parameter`, unless another code is named, or a `DeclarationError` when the app is registered. + +* `boolean` must be JSON `true` or `false`, never text or a number. A `choice` value must match a choice in type and value. A `float` is never a boolean. +* `integer` and `float` must be JSON numbers. Text (even `"3"`), lists, objects, NaN and infinity are refused: `'N' must be an integer, got text`, `'N' must be a number, got a list`, `'N' must be a finite number`. An integer-valued float such as `3.0` is accepted for an `integer`. A number beyond the float range is refused for a `float`. +* `file`, `folder`, `image` and `labels` values must be text paths: `'N' must be a path (text), got a list: the host must send the file or folder path as text`. An image may also be a shared-memory descriptor (see [Shared-memory images](#shared-memory-images)). +* `null` means "not given": the parameter takes its default or, when `nullable`, the tool receives `None`. `Optional[...]` with a default other than `None` is refused at registration. +* A default must be valid for its declared type (checked when the schema is generated). +* A `choice` declared with an `Enum` reaches the tool as the Enum member. +* An image or labels input with no pixels is refused with `empty_image`. +* A table input is a UTF-8 CSV file with a header line. The tool gets a DataFrame exactly as written: floats keep every digit (`float_precision="round_trip"`); column names stay as written, duplicates and empty names included (address those by position); an empty cell is missing; `NaN`, `nan` and `NAN` are missing numbers, but a text column keeps them as text; the other words pandas calls missing (`NA`, `None`, `null`, ...) stay text, except in a column whose other cells are all numbers. A missing file is `file_not_found`; an empty file or one that is not a UTF-8 CSV is `unreadable_table`. +* Integers of any size and floats up to the double range are carried. A value beyond a declared `Min`/`Max` (or the notebook form's ±(2**53 - 1), `notebook.MAX_FORM_INTEGER`) is refused, never clamped, with the sentence every host uses: `'L' must be <= 9007199254740991` or `'L' must be >= -9007199254740991`. + +### Results and what the tool must return +A tool returns one value, or a tuple with one value per declared output (`tool returned N values, declared M`). A value that does not match its declaration fails the task with `bad_return`: `the output '' must be , got `. The expected values are an array of numbers (image, labels), a DataFrame, dict of lists or list of dicts (table, points), a dict (values), a path (file), text (message) and a finite 3x3 matrix of numbers (affine). + +Output names are file names (`.tif`, `.csv`, `.geojson` in the result folder), so `Name(...)` must be one portable file name: no `/`, `\`, `:`, `<>"|?*`, control characters or NUL, not `.` or `..`, no leading space or trailing space or dot, and not a Windows device name (`CON`, `NUL`, `COM1`, ...). Anything else is a `DeclarationError`; the writers also refuse (`bad_return`) a path that would leave the result folder. + +**Images and labels** + +* An empty array is `bad_return` (`image is empty (shape ...)`). Complex, object, text and bytes arrays are `unsupported_dtype`. +* Integer values never change. Wide integers that fit 16 bits are stored as 16-bit; others must be exact as float32, otherwise `unsupported_dtype` (for example a uint64 of 2**64-1). Floats are stored as float32 (about 7 significant digits); values outside the float32 range fail. +* A declared `axes` is a promise: an array with another number of dimensions is `bad_return` and nothing is written. Without `axes`, the host gets `YX`, `ZYX` or `CZYX` for 2, 3 or 4 dimensions, and no `axes` otherwise. +* A tool whose output axes depend on the input returns `WithAxes(array, "TZYX")`; a declared `axes` must agree, otherwise `bad_return`. The result's `axes` are the returned ones. +* Hyperstacks (feature `result_axes_v1`): a result with known axes (declared or returned) that are a subsequence of `T Z C Y X` ending in `Y X`, more than two dimensions and none of size 1, a pixel type ImageJ stores (uint8, uint16, int16, float32) and less than 4 GiB is written as an ImageJ hyperstack TIFF, which Fiji opens with its dimensions. The array is never reordered. Any other result is a plain TIFF. + +**Tables and points.** Written as UTF-8 CSV. Line breaks, quotes and commas in cells and names are quoted and arrive unchanged. A NUL character in a column name or cell is refused with `bad_return` (`the table output 'X' has a NUL character in a cell of column 'c': remove it`); a lone surrogate or other text that is not UTF-8 is refused with `bad_return` (`... cannot be written as a UTF-8 CSV ...`). A `points` result is `{path, n, columns, apply_to?}`: a CSV whose first two columns are `y` and `x`, finite pixel coordinates in the frame of the image named by `apply_to` (else of the first image); other columns are properties of each point. + +**Shapes.** `{path, n, apply_to?}`: a GeoJSON FeatureCollection file of Polygon and MultiPolygon features, `[x, y]` coordinates in the same frame, pixel centres at integers. Feature properties are kept; a `label` property links an outline to its label. A GeoJSON dict returned by a tool is checked before anything is written: a Polygon is a list of rings (outer boundary first, then holes), a MultiPolygon a non-empty list of polygons, every ring at least 4 `[x, y]` positions of two finite numbers, closed, with at least 3 distinct vertices. Anything else is `bad_return` naming the feature, polygon and ring. An empty result is a FeatureCollection with no features. A host that does not know `shapes` lists the file. + +**Message.** `{text}`: short plain text. ## Tools version and features -Additive within protocol 1 (an old host ignores both fields; a protocol change would be a new major version). Two fields say what produced a schema: -* `tools_version`: the `labconstrictor-tools` version that ran `describe` in the app's own interpreter (`labconstrictor_tools.__version__`, for example `0.3.0a1`; tags are `v0.3.0-alpha.1`, see [OPERATIONS.md](OPERATIONS.md#releases-and-tags)). -* `features`: sorted list of stable feature ids (`labconstrictor_tools.features.FEATURES`). An id means "this Tools implements that rule"; it is added in the change that implements it, never renamed, never reused. +Two additive fields say what produced a schema: -Both are also written into the registry entry `.json` by `register` (`tools_version`, `features`), read from the schema it just generated. **A missing field means unknown/old**: Tools before 0.2 wrote neither. `describe` prints them, and `doctor` shows them per app (`Tools 0.3.0a1, features: ...`, or `Tools version unknown` for an old schema). The cached schema is not "stale" just because Tools was upgraded: `doctor` compares tools, not these two fields. +* `tools_version`: the `labconstrictor-tools` version that ran `describe` in the app's interpreter (`labconstrictor_tools.__version__`, for example `0.3.0a1` for tag `v0.3.0-alpha.1`; see [OPERATIONS.md](OPERATIONS.md#releases-and-tags)). +* `features`: the sorted list of feature ids (`labconstrictor_tools.features.FEATURES`). An id means "this Tools implements that rule". It is added in the change that implements it and is never renamed or reused. -Feature ids (the implemented ones are in `FEATURES`; a planned id appears there with the change that implements it): +`register` copies both into the registry entry; `describe` and `doctor` print them. **A missing field means unknown/old.** -| Id | Meaning | Status | +| Id | Meaning | Since | |---|---|---| -| `reserved_inputs_v1` | the worker accepts and ignores reserved underscore inputs it does not know (`_job_dir`, `_calibration`, `_axes`, and any future `_name`) | in 0.2.0rc1 | -| `calibration_per_axis` | the worker copies the per-axis `_calibration` into the run record ([SPEC_WRONG_SCIENCE.md](SPEC_WRONG_SCIENCE.md) 2.3.4) | planned | -| `retention_prune` | the CLI command `labconstrictor-tools prune [--root results\|runs\|all] [--dry-run] [--json]` and `labconstrictor_tools.retention`: only folders carrying a valid `.lc-owner.json` and a `.lc-done.json` are ever removed ([SPEC_WRONG_SCIENCE.md](SPEC_WRONG_SCIENCE.md) section 3; hosts only mark a run finished, then start `prune`) | in 0.2.0rc1 (tag `v0.2.0-rc.1`) and every later version | -| `shm_order_v1` | a shared-memory image descriptor's `order` is honoured: `C` / `C_ORDER` (or no `order`) and `F` / `F_ORDER` read the block in the order it was written, the tool always gets a C-ordered copy; any other value is refused with `unreadable_image` and a message naming `'C' or 'F'` (a block read in the wrong order would give the transposed image with no error) | in 0.3.0a1 (the one id added after its behaviour: older versions behave the same but cannot be told apart). A host that sends `F` blocks requires it | -| `app_hosts_v1` | `register` records the app's declared `hosts` (a list of `notebook`, `napari`, `fiji`, `qupath`) in the registry entry, and every host lists an app only for a host named in that list ([App hosts](#app-hosts-which-host-lists-an-app) below); an entry without `hosts` stays listed in every host and says so | in 0.3.0a1. Napari, Fiji and QuPath honour the rule and require it | -| `host_requirements_v1` | `register --app-manifest` records the app's `host_requirements` (the oldest napari, Fiji or QuPath plugin it needs, and host feature ids) in the registry entry; `host_requirements.check` gives every host the same verdict and sentence ([Host requirements](#host-requirements-which-plugin-an-app-needs) below) | in 0.3.0a2 (tag `v0.3.0-alpha.2`); applied by napari `v0.1.0-alpha.5`, Fiji `v0.1.0-alpha.7` and QuPath `v0.1.0-alpha.7` and later | -| `result_axes_v1` | an image/labels result whose axes are known (declared `axes`, or returned with `WithAxes`) and in ImageJ order is written as an ImageJ hyperstack TIFF, so Fiji opens it with its dimensions; the array is never reordered, and the result's `axes` are the returned ones ([Schema](#schema-what-hosts-read) above) | in 0.3.0a4. Hosts need nothing new: Fiji's TIFF reader reads the hyperstack, other readers get the same array | +| `reserved_inputs_v1` | the worker accepts and ignores reserved underscore inputs it does not know ([Reserved inputs](#reserved-inputs)) | 0.2.0rc1 | +| `retention_prune` | the command `labconstrictor-tools prune [--root results\|runs\|all] [--dry-run] [--json]` and `labconstrictor_tools.retention` exist; only folders with a valid `.lc-owner.json` and `.lc-done.json` are removed ([Result folders and run records](#result-folders-and-run-records-retention)) | 0.2.0rc1 | +| `shm_order_v1` | a shared-memory descriptor's `order` is honoured ([Shared-memory images](#shared-memory-images)). A host that sends `F` blocks requires it | 0.3.0a1; the one id added after its behaviour: older versions behave the same but cannot be told apart | +| `app_hosts_v1` | `register` records the app's `hosts`, and a host lists an app only if it is named there ([App hosts](#app-hosts-which-host-lists-an-app)) | 0.3.0a1 | +| `host_requirements_v1` | `register --app-manifest` records the app's `host_requirements`, and `host_requirements.check` gives every host the same verdict ([Host requirements](#host-requirements-which-plugin-an-app-needs)) | 0.3.0a2 | +| `result_axes_v1` | a result with known axes in ImageJ order is written as an ImageJ hyperstack TIFF ([Images and labels](#results-and-what-the-tool-must-return)). Hosts need nothing new | 0.3.0a4 | + +Some behaviour has a version but no id. **Tools >= 0.3.0a1 maps big TIFF files** (see [TIFF files](#tiff-files)); a host can observe it only as speed, memory use and the Windows file lock. The run-record helpers of the `runs` module also need 0.3.0a1. ### Compatibility rules for hosts -A host that needs a minimum states it as `(min_tools_version, required_features)` and applies the rules below to every schema it loads, with `labconstrictor_tools.compat.check_schema` (Python hosts: Napari, notebooks) or the same rules written in its own language (Fiji, QuPath; the data is in `conformance.json`, [CONFORMANCE.md](CONFORMANCE.md), `compat` section). The result is `ok`, `warn` or `refuse`, with one sentence for the person: -1. `protocol` not supported by the host: `refuse` (as today). -2. A required feature missing from `features` (or no `features` list at all): `refuse`, "needs ; update the app's labconstrictor-tools". -3. `tools_version` missing (unknown/old) while a minimum is set: `refuse`; with no minimum set: `warn`, "Tools version unknown". -4. `tools_version` below the minimum: `refuse`. Below the optional `warn_below` version but not below the minimum: `warn`. -5. Otherwise `ok`. A `tools_version` the host cannot parse is `warn` (never a crash). -6. A host that starts `prune` after a run lists `retention_prune` in its required features, or checks the feature before it starts the subprocess: a Tools without it has no `prune` command. If the feature is missing the host starts nothing and never deletes a folder itself (SPEC_WRONG_SCIENCE 3.1.4); the folders then accumulate until Tools is updated. -7. A host that applies the per-host listing rule ([App hosts](#app-hosts-which-host-lists-an-app)) lists `app_hosts_v1` in its required features (with `min_tools_version` `0.3.0a1`): an app whose Tools lacks it is refused by rule 2, with the sentence "lacks app_hosts_v1: update it" (`conformance.json`, `app_hosts.compat_cases`). -Version order is PEP 440 for the forms used here: `0.2.0a1 < 0.2.0b1 < 0.2.0rc1 < 0.2.0 < 0.2.1`. A host in the release-candidate phase writes the minimum as `0.2.0rc1`; the first alpha is `0.3.0a1` (tag `v0.3.0-alpha.1`), and `0.2.0rc1 < 0.3.0a1 < 0.3.0`. - -**Which Tools is which.** `v0.2.0-rc.1`, `v0.2.0-rc.2` and `main` until `0.3.0a1` all reported `__version__` `0.2.0rc1` and `features` `[reserved_inputs_v1, retention_prune]` although their code differs; `0.3.0a1` is the first number that tells them apart. Differences a host can rely on, by number: `shm_order_v1` and `app_hosts_v1` (feature ids) and the three `runs` functions below need `0.3.0a1`. Not an id, because it has no behavioural contract: **Tools >= 0.3.0a1 maps big TIFF files** (uncompressed, contiguous files of at least 8 MiB are opened as a copy-on-write memory map, so loading is faster and uses less memory; `LC_TIFF_MEMMAP=0` reads them the plain way). A host can only observe it as speed and memory use, and as the Windows file lock described in [OPERATIONS.md](OPERATIONS.md#troubleshooting). +A host that needs a minimum states it as `(min_tools_version, required_features)` and applies these rules to every schema it loads, with `labconstrictor_tools.compat.check_schema` (Python hosts) or the same rules in its own language (Fiji and QuPath read the cases from `conformance.json`, section `compat`; see [CONFORMANCE.md](CONFORMANCE.md)). The result is `ok`, `warn` or `refuse`, with one sentence for the person: + +1. `protocol` not supported: `refuse`. +2. A required feature missing from `features`, or no `features` list: `refuse`, "needs ; update the app's labconstrictor-tools". +3. `tools_version` missing (unknown/old): `refuse` when a minimum is set, otherwise `warn`, "Tools version unknown". +4. `tools_version` below the minimum: `refuse`. Below the optional `warn_below` but not below the minimum: `warn`. +5. Otherwise `ok`. A `tools_version` the host cannot parse is `warn`, never a crash. +6. A host that starts `prune` after a run requires `retention_prune`, or checks for it before starting the subprocess. Without it the host starts nothing and never deletes a folder itself. +7. A host that applies the per-host listing rule requires `app_hosts_v1` (with `min_tools_version` `0.3.0a1`). An app whose Tools lacks it is refused by rule 2 with "lacks app_hosts_v1: update it" (`conformance.json`, `app_hosts.compat_cases`). + +Versions compare as PEP 440: `0.2.0a1 < 0.2.0b1 < 0.2.0rc1 < 0.2.0 < 0.2.1`, and `0.2.0rc1 < 0.3.0a1 < 0.3.0`. Tags `v0.2.0-rc.1` and `v0.2.0-rc.2` both report `0.2.0rc1` with different code, so a host that needs anything from 0.3.0a1 sets that as its minimum. ## App hosts (which host lists an app) -**The per-host discovery matrix is enforced by Tools and honoured by every host.** An app declares which hosts may list it; a host never lists an app whose declaration excludes it. Feature id `app_hosts_v1`; reference: `labconstrictor_tools.app_hosts` (`listed_for`), vectors: `conformance.json`, section `app_hosts`. +An app declares which hosts may list it, and a host never lists an app whose declaration excludes it. Feature id `app_hosts_v1`; reference: `labconstrictor_tools.app_hosts.listed_for`; test vectors: `conformance.json`, section `app_hosts`. -**Where the declaration comes from.** The app's `labconstrictor-app.yaml` (App Centre metadata; its schema is `.tools/schema/labconstrictor-app.schema.json` in the **template repository** (LabConstrictor), not in this one, and it already allows `hosts:` as a unique list of the four names) has `hosts: [notebook, napari, fiji, qupath]`. The installer passes it to registration (template 0.1.18 and later; apps sync to it): `labconstrictor-tools register ... --app-manifest ` (reads that one key, which may be quoted, with a flow or a block list, and a UTF-8 byte order mark is accepted; the file must be bundled with the installer) or `--hosts notebook,napari` (the same list typed out; the two are exclusive). `register` validates the list and writes it into the registry entry `.json` as `hosts` (a list, in the order declared). `labconstrictor-tools check --module M --app-manifest ` shows the same line to an author before release. The cached schema is not changed: the field is in the entry only. A manifest file with no `hosts` key still registers (exit 0, no declaration, so every host lists the app) but `register` says so on stderr with the sentence above: the installers pass `--app-manifest` for every app whose yaml exists, with or without a `hosts:` line, so a refusal would leave such an app unregistered. A key written in a form the reader does not understand is refused, never read as absent. +**Where the declaration comes from.** The `hosts:` line of the app's `labconstrictor-app.yaml` ([Tool markers](MANIFEST.md#hosts-which-hosts-list-the-app)), which the installer passes to `register --app-manifest `; `--hosts notebook,napari` is the command-line equivalent (the two are exclusive). The reader accepts a quoted key, a flow or block list and a UTF-8 byte order mark; a form it does not understand is refused, never read as absent. `register` validates the list and writes it into the registry entry as `hosts`. A manifest with no `hosts` key still registers, and `register` prints the "declares no hosts" sentence below on stderr. -**The rule, for every host.** For each registered app the host calls `listed_for(entry, "")` (`napari`, `fiji` or `qupath`; Fiji and QuPath write the same rule in their language) and acts on the pair `(listed, sentence)`: +**The rule.** For each registered app, a host calls `listed_for(entry, "")` (`napari`, `fiji` or `qupath`; Fiji and QuPath implement the same rule) and acts on `(listed, sentence)`: | Entry `hosts` | listed | sentence (exact; `{app}` is the entry's `name`, the list is written as declared, separated by `, `) | |---|---|---| @@ -99,24 +111,16 @@ Version order is PEP 440 for the forms used here: `0.2.0a1 < 0.2.0b1 < 0.2.0rc1 | absent (older installers) | yes, **in every host** | `'{app}' declares no hosts, so it is listed in every host; register it with --app-manifest (or --hosts) to choose` | | present but not valid: not a list, empty, a non-text item, an unknown or repeated name, a name in capitals | **no**, in no host | `'{app}' is not listed in {host}: its hosts declaration is not valid ({problem}); register the app again with a valid one` | -The problems are: `hosts must be a list of host names`, `hosts is empty; write at least notebook`, `hosts must contain only text`, `unknown host name 'x' (known: notebook, napari, fiji, qupath)`, `host name 'x' appears twice`. The manifest reader and `--hosts` (not `listed_for`, which no host ports) also refuse `hosts has an empty item (a trailing or doubled comma, or a bare '-')`. An unknown name for the asking host is a bug in the host, not an answer: the function raises ValueError (the vectors expect an error). - -**Not silent.** A host writes every non-empty sentence to the Tools log (a skipped app, a listing by the compatibility rule); it shows the skip sentence wherever it already reports apps it leaves out. The absent-field case is the backward-compatibility rule: it exists so that an app installed by an older installer keeps working, and it is logged each time so nobody believes the app made a choice. +The problems are: `hosts must be a list of host names`, `hosts is empty; write at least notebook`, `hosts must contain only text`, `unknown host name 'x' (known: notebook, napari, fiji, qupath)`, `host name 'x' appears twice`. The manifest reader and `--hosts` also refuse `hosts has an empty item (a trailing or doubled comma, or a bare '-')`. An unknown name for the asking host is a bug in the host: `listed_for` raises `ValueError`. -**What is not filtered.** The command line (`labconstrictor-tools list|run|check|test`), notebooks (`%%lc_tool`, `run_once`) and the worker are never filtered: `hosts` decides what Napari, Fiji and QuPath offer, nothing else. `labconstrictor-tools list` prints the declaration of every app (`hosts: notebook, fiji`, `not declared (listed in every host)`, or `INVALID (...)`), and `list --json` adds `"hosts": {app: [...] | null}` (null: not declared, or present but not a list) and `"hosts_status": {app: "declared" | "absent" | "invalid"}` to tell those apart. An app that declares only `notebook` (CellTracksColab) is registered, usable from the command line and hidden from all three hosts. +A host writes every non-empty sentence to the Tools log, the absent case included, and shows the skip sentence wherever it reports apps it leaves out. -**The matrix for the apps of the release sandbox** (the sandbox reads it from `tests/release_sandbox/expected_hosts.json`, [tests/release_sandbox/README.md](https://github.com/CellMigrationLab/LabConstrictor-Tools/blob/main/tests/release_sandbox/README.md)): - -| App | `hosts:` | Napari | Fiji | QuPath | -|---|---|---|---|---| -| CellTracksColab | `[notebook]` | no | no | no | -| GuessTheCondition, Playground, NucleiSky | `[notebook, napari, fiji, qupath]` | yes | yes | yes | -| VLab4Mic | `[notebook, napari, fiji]` | yes | yes | no | +**What is not filtered.** The command line (`labconstrictor-tools list|run|check|test`), notebooks (`%%lc_tool`, `run_once`) and the worker. `labconstrictor-tools list` prints each app's declaration (`hosts: notebook, fiji`, `not declared (listed in every host)` or `INVALID (...)`); `list --json` adds `"hosts": {app: [...] | null}` (null: not declared, or not a list) and `"hosts_status": {app: "declared" | "absent" | "invalid"}`. An app that declares only `notebook` is registered, usable from the command line and hidden from all three hosts. ## Host requirements (which plugin an app needs) -The compatibility rules above let a **host** require a minimum Tools inside the app. This is the other direction: an **app** says which host plugin it needs, so that a person with an old LabConstrictor-Fiji, -napari or -QuPath is told to update instead of silently getting the old behaviour. Feature id `host_requirements_v1`; reference: `labconstrictor_tools.host_requirements` (`check`); vectors: `conformance.json`, section `host_requirements`. +The compatibility rules let a host require a minimum Tools in the app. This is the other direction: an app says which host plugin it needs, so that a person with an old plugin is told to update. Feature id `host_requirements_v1`; reference: `labconstrictor_tools.host_requirements.check`; test vectors: `conformance.json`, section `host_requirements`. -**Where the declaration comes from.** The app's `labconstrictor-app.yaml` (see [MANIFEST.md](MANIFEST.md#6-which-plugin-version-the-app-needs-host_requirements-app-manifest-not-a-tool-marker)): +**Where the declaration comes from.** The app's `labconstrictor-app.yaml` ([Tool markers](MANIFEST.md#host_requirements-which-plugin-version-the-app-needs)): ```yaml host_requirements: @@ -127,9 +131,9 @@ host_requirements: required: false # optional; true refuses instead of warning ``` -`register --app-manifest` validates it and copies it into the registry entry (field `host_requirements`); an invalid one is refused and nothing is registered. Only `napari`, `fiji` and `qupath` can be named: the notebook ships with the app. Tools has no YAML parser: the reader understands this block form only (two levels of `key: value`, a flow list on one line, quoted or plain text, `true`/`false`); `check --app-manifest` prints what it read. +`register --app-manifest` validates the block and copies it into the registry entry; an invalid block is refused and nothing is registered. Only `napari`, `fiji` and `qupath` can be named. The reader understands this block form only (two levels of `key: value`, a flow list on one line, quoted or plain text, `true`/`false`). -**The rule, for every host.** For each registered app the host calls `check(entry, "", , )` (Fiji and QuPath write the same rule in Groovy and test it against the vectors) and acts on `(status, sentence)`: +**The rule.** For each registered app, a host calls `check(entry, "", , )` and acts on `(status, sentence)`: | Situation | status | sentence (exact; `{app}` is the entry's `display_name`, `{why}` is ` ()` or empty, `{url}` is `https://github.com/CellMigrationLab/LabConstrictor-{plugin}/releases/latest`) | |---|---|---| @@ -139,90 +143,78 @@ host_requirements: | the host's version is unknown or unreadable (Fiji's loose script) while `min_version` is set | always `warn` | `{app} needs LabConstrictor-{plugin} {min_version} or newer{why}; the version of this plugin is unknown. Update the plugin if the app misbehaves: {url}` | | the declaration is not valid (hand-edited entry) | `warn` | `{app} has a host_requirements declaration that is not valid ({problem}); register the app again with a valid one` | -`{plugin}` is `napari`, `Fiji` or `QuPath`. Versions compare as PEP 440 after dropping a leading `v` (`v0.1.0-alpha.6` = `0.1.0a6`; `0.1.0a6.dev0 < 0.1.0a6 < 0.1.0rc1 < 0.1.0`); `version_order` in the vectors pins the order. An unknown asking host is a programming error (an exception). +`{plugin}` is `napari`, `Fiji` or `QuPath`. Versions compare as PEP 440 after dropping a leading `v` (`v0.1.0-alpha.6` = `0.1.0a6`; `0.1.0a6.dev0 < 0.1.0a6 < 0.1.0rc1 < 0.1.0`); `version_order` in the vectors pins the order. An unknown asking host raises an exception. -**What a host does with it.** `ok`: nothing. `warn`: the app stays listed and the sentence is shown where the person picks the app (a status line, tooltip or one dialog per session) and written to the Tools log. `refuse`: its tools do not start, and the sentence says why: napari keeps the app listed and refuses Run with the sentence; Fiji and QuPath leave it out of their list with the sentence where they say what they skipped (the Log window, the dialog's status line). A host that does not implement `host_requirements_v1` ignores the field, as hosts did before it existed, so the field is backward-compatible. The command line and notebooks are never checked. +**What a host does.** `ok`: nothing. `warn`: the app stays listed; the sentence is shown where the person picks the app (a status line, a tooltip or one dialog per session) and written to the Tools log. `refuse`: the app's tools do not start. napari keeps the app listed and refuses Run with the sentence; Fiji and QuPath leave the app out of their list and show the sentence where they report skipped apps. A host without `host_requirements_v1` ignores the field. The command line and notebooks are never checked. -**Where a host gets its version.** napari: the installed package version (`importlib.metadata`). Fiji: the jar manifest's version (set from the release tag); the loose script has none, so it is unknown. QuPath: the jar's `Implementation-Version`. Their feature ids are in [HOST_FEATURES.md](HOST_FEATURES.md#host-feature-ids-for-host_requirements). +Each host's version source and feature ids are in [HOST_FEATURES.md](HOST_FEATURES.md#host-feature-ids-for-host_requirements). ## Result folders and run records (retention) -Under `` two folders hold what runs leave behind: `results/_<6 hex>__` (the files of a run) and `runs/