archivo del paquete→ .shtukbase/packages/norms-core/checks/context.ts
checks/context.ts
29 líneas, 1.5 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // Prints the project's rules in force (status: active) as a Markdown list for an agent's context: number, level,
- // and the rail (the short line for an agent) or else the requirement. Not a check: always exits 0.
- import { records, status } from './pagelib.ts';
- import { pystr, truthy } from '../../collections/checks/lib/pages.ts';
- const ORDER: Record<string, number> = { MUST: 0, SHOULD: 1, MAY: 2 };
- export const RULE = { id: 'ns-context', title: 'Active rules as a list for the agent context' };
- const text = (v: unknown): string => (truthy(v) ? pystr(v) : '');
- /** The lines to print: a heading and one list item per active rule, MUST first, then by number. */
- export function check(): string[] {
- const rows: [number, string, string, string][] = [];
- for (const [addr, head] of records('norms/rules')) {
- if (status(head) !== 'active') continue;
- const level = text(head.level).trim();
- const body = (truthy(head.rail) ? text(head.rail) : truthy(head.requirement) ? text(head.requirement) : text(head.title)).trim();
- rows.push([Object.hasOwn(ORDER, level) ? ORDER[level] : 3, truthy(head.ruleId) ? text(head.ruleId) : addr, level, body]);
- }
- const cmp = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
- rows.sort((a, b) => a[0] - b[0] || cmp(a[1], b[1]) || cmp(a[2], b[2]) || cmp(a[3], b[3]));
- return ['# Active rules of the project', ...rows.map(([, rid, level, body]) => `- ${rid} (${level || '?'}): ${body}`)];
- }
- if (import.meta.main) {
- console.log(check().join('\n'));
- process.exitCode = 0;
- }