archivo del paquete→ .shtukbase/packages/quality/checks/q08_agent_correctness.ts
checks/q08_agent_correctness.ts
32 líneas, 2.2 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // QLT-R08. Every live professional agent of the product (layer "Product", type ProductAgent; agents with
- // `kind: professional`, or every agent when the schema has no such kind) has a correctness indicator that is not
- // retired, has a cadence and has at least one dataset (a dataset whose `indicators` names it). Without the agents
- // collection there is nothing to check and the norm holds.
- import type { Project, Result } from '../../collections/checks/lib/speclib.ts';
- import { main } from '../../collections/checks/lib/runner.ts';
- import { addr, fld, has, live, refs } from './lib/qlib.ts';
- export const RULE = { id: 'qlt-r08', title: 'A professional agent has a correctness indicator with a dataset and a cadence', scope: 'professional agents of the product' };
- export function check(p: Project, res: Result): void {
- if (!res.part('product agents', p.need('AGENT'))) return;
- const hasKind = JSON.stringify(p.schema('AGENT').kind ?? {}).includes('professional');
- const agents = p.records('AGENT').filter((a) => live(p, a, 'AGENT') && (!hasKind || String(a.fm.kind ?? '') === 'professional'));
- res.scope = agents.map((a) => addr(a.id));
- const fAgent = fld(p, 'IND', 'AGENT', 'agent');
- const fDsInd = fld(p, 'DS', 'IND', 'indicators');
- const withData = new Set(p.records('DS').filter((d) => p.category(d, 'DS') !== 'dropped').flatMap((d) => refs(p, d, fDsInd, 'IND')));
- const inds = p.records('IND').filter((i) => p.category(i, 'IND') !== 'dropped' && String(i.fm.kind ?? '') === 'correctness');
- for (const a of agents) {
- const mine = inds.filter((i) => refs(p, i, fAgent, 'AGENT').includes(a.id));
- if (!mine.length) {
- res.hole(addr(a.id), `${p.label(a, 'AGENT')}: no correctness indicator`, 'create an indicator kind: correctness with agent pointing to this agent', 'no-correctness');
- continue;
- }
- if (!mine.some((i) => has(i, 'cadence') && withData.has(i.id)))
- res.hole(addr(a.id), `${p.label(a, 'AGENT')}: the correctness indicator has no dataset or cadence (${mine.map((i) => p.label(i, 'IND')).join(', ')})`,
- 'write cadence and create a dataset that refers to the indicator', 'no-dataset');
- }
- }
- if (import.meta.main) main({ RULE, check });