|
| 1 | +# Put LRV in repository guardrails |
| 2 | + |
| 3 | +Read this when adding or changing automated validation. Routine evidence |
| 4 | +correction should use the project's existing commands. |
| 5 | + |
| 6 | +## Establish one repository contract |
| 7 | + |
| 8 | +Inspect existing task runners, dependency locks, schema annotations, wrappers, |
| 9 | +hooks, and CI before adding another entry point. Record the selected files, |
| 10 | +target class, explicit config, cache location, and which findings block each |
| 11 | +stage. Keep these decisions in version control so humans and agents run the |
| 12 | +same checks. |
| 13 | + |
| 14 | +If LRV is absent from a uv project, add it with |
| 15 | +`uv add linkml-reference-validator linkml` and commit the dependency and lockfile |
| 16 | +changes as part of setup. `validate data` needs `linkml` and exits 2 without it; |
| 17 | +the text, lookup, and repair commands do not. Skill installation alone does not |
| 18 | +supply the runtime. Check the locked release's subcommand help when |
| 19 | +integrating or upgrading: repository wrappers can target an older release than |
| 20 | +upstream documentation. |
| 21 | + |
| 22 | +For a project with `schema.yaml`, an evidence-bearing class `Statement`, and |
| 23 | +`conf/reference-validator.yaml`, a validation command is: |
| 24 | + |
| 25 | +```bash |
| 26 | +uv run --locked linkml-reference-validator validate data data.yaml \ |
| 27 | + --schema schema.yaml --target-class Statement \ |
| 28 | + --config conf/reference-validator.yaml --cache-dir references_cache |
| 29 | +``` |
| 30 | + |
| 31 | +Adapt those paths/class to the actual project and wrap the command in its task |
| 32 | +runner. Use the same wrapper from CI and hooks. Include structural LinkML |
| 33 | +validation separately: source matching is not schema validation. Check that |
| 34 | +file selection and schema extraction actually produce comparisons. |
| 35 | + |
| 36 | +## Separate retrieval from the frequent check |
| 37 | + |
| 38 | +Matching is deterministic for fixed inputs, config, tool version, and source |
| 39 | +content. Live retrieval and changing caches affect what can be compared. |
| 40 | +Define how references enter the cache, how source provenance is retained, and |
| 41 | +how unavailable content is reported. Prepare newly cited references before |
| 42 | +expecting cached checks to cover them. |
| 43 | + |
| 44 | +Keep expensive enrichment and cache normalization out of every edit. Where |
| 45 | +supported, `--no-full-text` disables full-text fetching; it is **not an offline |
| 46 | +switch** and new references may still be fetched and cached. Test both a cache |
| 47 | +hit and a cache miss before describing a hook as offline or non-mutating. |
| 48 | +Do not silently treat unavailable content as verified evidence. |
| 49 | + |
| 50 | +## Add a hook appropriate to the editing stage |
| 51 | + |
| 52 | +Use a command hook that invokes the deterministic checker. Configure the event |
| 53 | +using the installed Claude Code version's |
| 54 | +[hook protocol](https://code.claude.com/docs/en/hooks), preserving existing hooks. |
| 55 | + |
| 56 | +- A `PreToolUse` edit hook must validate the **proposed content** in a temporary |
| 57 | + file, faithfully implementing the tool's edit semantics, including repeated |
| 58 | + replacements. Checking the old file cannot reject a bad proposed edit. |
| 59 | +- Resolve paths against the checkout containing the edited file. A hook's |
| 60 | + script or launch directory can belong to the main checkout while the agent |
| 61 | + edits a worktree. Preserve the real schema/config/cache context for temporary |
| 62 | + files, including relative reference paths. |
| 63 | +- Map a blocking validation failure to hook exit 2 with an actionable stderr |
| 64 | + diagnostic. Do not merely forward CLI exit 1 and assume it blocks. Bound |
| 65 | + subprocess runtime so the hook can report failure before its own timeout. |
| 66 | +- A `PostToolUse` hook can report on the saved result; it cannot undo the write. |
| 67 | + A tool-specific hook also misses edits by other tools or humans. CI provides |
| 68 | + the common check for all changes. |
| 69 | + |
| 70 | +Decide explicitly whether incomplete retrieval should interrupt editing or be |
| 71 | +reported for resolution before merge. Preserve the project's chosen distinction |
| 72 | +between advisory feedback and required validation. |
| 73 | + |
| 74 | +## Wire CI and verify the integration |
| 75 | + |
| 76 | +Install locked dependencies, prepare the intended cache, and call the repository |
| 77 | +recipe. Cover changes to data, schema, validation config, wrappers, dependencies, |
| 78 | +and cache policy. Schema/config changes can affect the whole corpus even when |
| 79 | +no data file changed. Handle deleted files and an intentionally empty selection |
| 80 | +explicitly; accidental selection of zero files must not look like successful QC. |
| 81 | + |
| 82 | +Exercise a matching quote, a mismatch, a wrong title, a missing source, and an |
| 83 | +input with no extractable evidence. Verify the actual wrapper/hook/CI outcomes, |
| 84 | +not just the standalone CLI. Confirm that failures remain failures through |
| 85 | +shell pipelines and that advisory results stay visible. Inspect cache changes |
| 86 | +and runtime on representative files. Retain logs with comparison coverage and |
| 87 | +the source/tool/config versions needed to reproduce findings. |
| 88 | + |
| 89 | +## Example: dismech's two stages |
| 90 | + |
| 91 | +At [dismech's inspected revision](https://github.com/monarch-initiative/dismech/tree/6bd2810f2f896fd9aa05f8223f7f50caebe457b3), |
| 92 | +the [pre-edit hook](https://github.com/monarch-initiative/dismech/blob/6bd2810f2f896fd9aa05f8223f7f50caebe457b3/.claude/hooks/validate_disorder_hook.py) |
| 93 | +finds the edited file's worktree and calls `just validate-pre-edit` on candidate |
| 94 | +content. The [recipes](https://github.com/monarch-initiative/dismech/blob/6bd2810f2f896fd9aa05f8223f7f50caebe457b3/project.justfile) |
| 95 | +block schema and term failures at this stage, but report reference findings as |
| 96 | +advisory with `--no-full-text`. Broader validation runs before merge. |
| 97 | + |
| 98 | +The [reference wrapper](https://github.com/monarch-initiative/dismech/blob/6bd2810f2f896fd9aa05f8223f7f50caebe457b3/scripts/run_reference_validator.sh) |
| 99 | +implements project-specific warning handling and appends a separate, advisory |
| 100 | +snippet audit. Recipes explicitly select `conf/reference_validator_config.yaml`; |
| 101 | +reading only the root dotfile would describe the wrong effective policy. |
| 102 | +These are design examples, not a universal configuration to copy wholesale. |
0 commit comments