ShtukbaseStandard
файл пакета→ .shtukbase/packages/content/lib/content.ts

lib/content.ts

40 строк, 2.3 КБ.

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. // Shared bits of the content checks: the records of the four content collections and a tiny finding runner.
  2. // Works from the project root (the working directory of an action) on the installed copy.
  3. import { existsSync, readdirSync } from 'node:fs';
  4. import { join } from 'node:path';
  5. import { type Rec, loadCollection, normPath, pystr, readPage } from '../../collections/checks/lib/pages.ts';
  6. export type { Rec };
  7. export const ROOT = process.cwd();
  8. export const FOLDERS = { topics: 'content/topics', platforms: 'content/platforms', ideas: 'content/ideas', drafts: 'content/drafts' };
  9. export const records = (folder: string): Rec[] => loadCollection(ROOT, folder.split('/').pop()!, folder);
  10. export const text = (v: unknown): string => (v === null || v === undefined ? '' : pystr(v).trim());
  11. /** The phase name of a status (`/content/contours/drafts/review` → `review`). */
  12. export const phase = (v: unknown): string => text(v).replace(/^\/+|\/+$/g, '').split('/').pop()!.replace(/\.md$/, '').toLowerCase();
  13. /** A relation value → project path `/a/b.md`, or null. */
  14. export const ref = (v: unknown, own?: string): string | null => normPath(v, null, own ?? null);
  15. export const exists = (path: string | null): boolean => !!path && existsSync(join(ROOT, path.replace(/^\/+/, '')));
  16. export const page = (path: string) => readPage(join(ROOT, path.replace(/^\/+/, '')));
  17. /** Names that point at an agent rather than a person: agent page paths and titles, harness and model names. */
  18. export function agentNames(): Set<string> {
  19. const out = new Set(['agent', 'claude', 'codex', 'opencode', 'dsh', 'hermes', 'haiku', 'sonnet', 'opus', 'gpt', 'ai', 'bot']);
  20. const dir = join(ROOT, 'agents');
  21. if (existsSync(dir))
  22. for (const f of readdirSync(dir).filter((n) => n.endsWith('.md'))) {
  23. const id = f.slice(0, -3);
  24. out.add(id.toLowerCase());
  25. out.add(`/agents/${id}`);
  26. const t = text(readPage(join(dir, f)).fm.title).toLowerCase();
  27. if (t) out.add(t);
  28. }
  29. return out;
  30. }
  31. /** Prints findings (`record: what → fix [code]`), one per line; exit 1 when there are any. */
  32. export function report(findings: string[], scope: string): void {
  33. if (findings.length) console.log(findings.join('\n'));
  34. else console.log(`holds: ${scope}`);
  35. process.exitCode = findings.length ? 1 : 0;
  36. }