// The key and the value of a finding a part writes into its own state `findings`, as the condition keeper reads it // (kept apart from catalog.ts, which loads the catalog seat's contract, so a part that only writes a finding loads nothing else). import type { Finding } from "@novox/mesh-sdk/views"; /** The key of a finding about a module: scope, the id's dotted parts, and the kind, each part made safe (mesh-sdk health.Key). */ export function findingKey(scope: string, id: string, kind: string): string { return [scope, ...id.split("."), kind].map((p) => p.trim().replace(/[^A-Za-z0-9_=/-]/g, "_") || "_").join("."); } /** A finding as the condition keeper reads it from the module's state `findings`: its key and its value. */ export function findingValue(f: Finding): { key: string; value: Record } { const key = findingKey("module", f.id, f.kind); return { key, value: { v: 1, key, kind: f.kind, subject: { scope: "module", id: f.id }, severity: "warning", summary: f.summary, headline: f.headline, explanation: f.explanation, resolved: "", evidence: [{ at: f.at, said: f.summary }], source: `${f.observer}.${f.kind}`, observer: f.observer, at: f.at, } }; }